From: Jean-Paul Pelteret Date: Thu, 7 May 2020 06:23:05 +0000 (+0200) Subject: Convert step-44 to use FEValues range based loops X-Git-Tag: v9.2.0-rc1~99^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F10056%2Fhead;p=dealii.git Convert step-44 to use FEValues range based loops --- diff --git a/examples/step-44/step-44.cc b/examples/step-44/step-44.cc index 7b48067891..55f13a7b20 100644 --- a/examples/step-44/step-44.cc +++ b/examples/step-44/step-44.cc @@ -1,6 +1,6 @@ /* --------------------------------------------------------------------- * - * Copyright (C) 2010 - 2019 by the deal.II authors and + * Copyright (C) 2010 - 2020 by the deal.II authors and * & Jean-Paul Pelteret and Andrew McBride * * This file is part of the deal.II library. @@ -1726,7 +1726,8 @@ namespace Step44 scratch.fe_values[J_fe].get_function_values( scratch.solution_total, scratch.solution_values_J_total); - for (unsigned int q_point = 0; q_point < n_q_points; ++q_point) + for (const unsigned int q_point : + scratch.fe_values.quadrature_point_indices()) lqph[q_point]->update_values(scratch.solution_grads_u_total[q_point], scratch.solution_values_p_total[q_point], scratch.solution_values_J_total[q_point]); @@ -1914,7 +1915,7 @@ namespace Step44 quadrature_point_history.get_data(cell); Assert(lqph.size() == n_q_points, ExcInternalError()); - for (unsigned int q_point = 0; q_point < n_q_points; ++q_point) + for (const unsigned int q_point : fe_values.quadrature_point_indices()) { const double det_F_qp = lqph[q_point]->get_det_F(); const double JxW = fe_values.JxW(q_point); @@ -1948,7 +1949,7 @@ namespace Step44 quadrature_point_history.get_data(cell); Assert(lqph.size() == n_q_points, ExcInternalError()); - for (unsigned int q_point = 0; q_point < n_q_points; ++q_point) + for (const unsigned int q_point : fe_values.quadrature_point_indices()) { const double det_F_qp = lqph[q_point]->get_det_F(); const double J_tilde_qp = lqph[q_point]->get_J_tilde(); @@ -2099,10 +2100,11 @@ namespace Step44 quadrature_point_history.get_data(cell); Assert(lqph.size() == n_q_points, ExcInternalError()); - for (unsigned int q_point = 0; q_point < n_q_points; ++q_point) + for (const unsigned int q_point : + scratch.fe_values.quadrature_point_indices()) { const Tensor<2, dim> F_inv = lqph[q_point]->get_F_inv(); - for (unsigned int k = 0; k < dofs_per_cell; ++k) + for (const unsigned int k : scratch.fe_values.dof_indices()) { const unsigned int k_group = fe.system_to_base_index(k).first.first; @@ -2137,7 +2139,8 @@ namespace Step44 // // In doing so, we first extract some configuration dependent variables // from our quadrature history objects for the current quadrature point. - for (unsigned int q_point = 0; q_point < n_q_points; ++q_point) + for (const unsigned int q_point : + scratch.fe_values.quadrature_point_indices()) { const Tensor<2, dim> tau = lqph[q_point]->get_tau(); const SymmetricTensor<4, dim> Jc = lqph[q_point]->get_Jc(); @@ -2154,13 +2157,14 @@ namespace Step44 const std::vector> &grad_Nx = scratch.grad_Nx[q_point]; const double JxW = scratch.fe_values.JxW(q_point); - for (unsigned int i = 0; i < dofs_per_cell; ++i) + for (const unsigned int i : scratch.fe_values.dof_indices()) { const unsigned int component_i = fe.system_to_component_index(i).first; const unsigned int i_group = fe.system_to_base_index(i).first.first; - for (unsigned int j = 0; j <= i; ++j) + for (const unsigned int j : + scratch.fe_values.dof_indices_ending_at(i)) { const unsigned int component_j = fe.system_to_component_index(j).first; @@ -2205,8 +2209,9 @@ namespace Step44 // Finally, we need to copy the lower half of the local matrix into the // upper half: - for (unsigned int i = 0; i < dofs_per_cell; ++i) - for (unsigned int j = i + 1; j < dofs_per_cell; ++j) + for (const unsigned int i : scratch.fe_values.dof_indices()) + for (const unsigned int j : + scratch.fe_values.dof_indices_starting_at(i + 1)) data.cell_matrix(i, j) = data.cell_matrix(j, i); } @@ -2274,11 +2279,12 @@ namespace Step44 quadrature_point_history.get_data(cell); Assert(lqph.size() == n_q_points, ExcInternalError()); - for (unsigned int q_point = 0; q_point < n_q_points; ++q_point) + for (const unsigned int q_point : + scratch.fe_values.quadrature_point_indices()) { const Tensor<2, dim> F_inv = lqph[q_point]->get_F_inv(); - for (unsigned int k = 0; k < dofs_per_cell; ++k) + for (const unsigned int k : scratch.fe_values.dof_indices()) { const unsigned int k_group = fe.system_to_base_index(k).first.first; @@ -2296,7 +2302,8 @@ namespace Step44 } } - for (unsigned int q_point = 0; q_point < n_q_points; ++q_point) + for (const unsigned int q_point : + scratch.fe_values.quadrature_point_indices()) { const SymmetricTensor<2, dim> tau = lqph[q_point]->get_tau(); const double det_F = lqph[q_point]->get_det_F(); @@ -2314,7 +2321,7 @@ namespace Step44 // definition of the rhs as the negative // of the residual, these contributions // are subtracted. - for (unsigned int i = 0; i < dofs_per_cell; ++i) + for (const unsigned int i : scratch.fe_values.dof_indices()) { const unsigned int i_group = fe.system_to_base_index(i).first.first; @@ -2337,8 +2344,8 @@ namespace Step44 { scratch.fe_face_values.reinit(cell, face); - for (unsigned int f_q_point = 0; f_q_point < n_q_points_f; - ++f_q_point) + for (const unsigned int f_q_point : + scratch.fe_face_values.quadrature_point_indices()) { const Tensor<1, dim> &N = scratch.fe_face_values.normal_vector(f_q_point); @@ -2362,7 +2369,7 @@ namespace Step44 const double pressure = p0 * parameters.p_p0 * time_ramp; const Tensor<1, dim> traction = pressure * N; - for (unsigned int i = 0; i < dofs_per_cell; ++i) + for (const unsigned int i : scratch.fe_values.dof_indices()) { const unsigned int i_group = fe.system_to_base_index(i).first.first; diff --git a/tests/physics/step-44-standard_tensors-material_push_forward.cc b/tests/physics/step-44-standard_tensors-material_push_forward.cc index f8c4189312..1a7f3d4b78 100644 --- a/tests/physics/step-44-standard_tensors-material_push_forward.cc +++ b/tests/physics/step-44-standard_tensors-material_push_forward.cc @@ -1665,7 +1665,7 @@ namespace Step44 scratch.fe_values_ref.quadrature_point_indices()) { const Tensor<2, dim> F_inv = lqph[q_point]->get_F_inv(); - for (unsigned int k = 0; k < dofs_per_cell; ++k) + for (const unsigned int k : scratch.fe_values_ref.dof_indices()) { const unsigned int k_group = fe.system_to_base_index(k).first.first; if (k_group == u_dof) diff --git a/tests/physics/step-44-standard_tensors-spatial.cc b/tests/physics/step-44-standard_tensors-spatial.cc index b5799bbf95..b65c69f6d8 100644 --- a/tests/physics/step-44-standard_tensors-spatial.cc +++ b/tests/physics/step-44-standard_tensors-spatial.cc @@ -1465,7 +1465,7 @@ namespace Step44 scratch.fe_values_ref.quadrature_point_indices()) { const Tensor<2, dim> F_inv = lqph[q_point]->get_F_inv(); - for (unsigned int k = 0; k < dofs_per_cell; ++k) + for (const unsigned int k : scratch.fe_values_ref.dof_indices()) { const unsigned int k_group = fe.system_to_base_index(k).first.first; if (k_group == u_dof) diff --git a/tests/physics/step-44.cc b/tests/physics/step-44.cc index 9c1dd702d8..4bc8d78980 100644 --- a/tests/physics/step-44.cc +++ b/tests/physics/step-44.cc @@ -1478,7 +1478,7 @@ namespace Step44 scratch.fe_values_ref.quadrature_point_indices()) { const Tensor<2, dim> F_inv = lqph[q_point]->get_F_inv(); - for (unsigned int k = 0; k < dofs_per_cell; ++k) + for (const unsigned int k : scratch.fe_values_ref.dof_indices()) { const unsigned int k_group = fe.system_to_base_index(k).first.first; if (k_group == u_dof) @@ -1605,7 +1605,7 @@ namespace Step44 scratch.fe_values_ref.quadrature_point_indices()) { const Tensor<2, dim> F_inv = lqph[q_point]->get_F_inv(); - for (unsigned int k = 0; k < dofs_per_cell; ++k) + for (const unsigned int k : scratch.fe_values_ref.dof_indices()) { const unsigned int k_group = fe.system_to_base_index(k).first.first; if (k_group == u_dof)