From: Martin Kronbichler Date: Mon, 28 Aug 2023 14:03:51 +0000 (+0200) Subject: Use range-based for loop for FEEvaluation's quadrature point loop X-Git-Tag: relicensing~544^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F15936%2Fhead;p=dealii.git Use range-based for loop for FEEvaluation's quadrature point loop --- diff --git a/examples/step-37/doc/results.dox b/examples/step-37/doc/results.dox index d09c6ffe97..3dfc7770cb 100644 --- a/examples/step-37/doc/results.dox +++ b/examples/step-37/doc/results.dox @@ -574,7 +574,7 @@ void LaplaceProblem::assemble_rhs() phi.reinit(cell); phi.read_dof_values_plain(solution); phi.evaluate(EvaluationFlags::gradients); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) { phi.submit_gradient(-coefficient(cell, q) * phi.get_gradient(q), q); phi.submit_value(make_vectorized_array(1.0), q); @@ -659,7 +659,7 @@ void LaplaceProblem::assemble_rhs() ++cell) { phi.reinit(cell); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) phi.submit_value(make_vectorized_array(1.0), q); phi.integrate(EvaluationFlags::values); phi.distribute_local_to_global(system_rhs); diff --git a/examples/step-37/step-37.cc b/examples/step-37/step-37.cc index e9bd5a3aa0..0ac0ca5aca 100644 --- a/examples/step-37/step-37.cc +++ b/examples/step-37/step-37.cc @@ -289,7 +289,7 @@ namespace Step37 for (unsigned int cell = 0; cell < n_cells; ++cell) { phi.reinit(cell); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) coefficient(cell, q) = coefficient_function.value(phi.quadrature_point(q)); } @@ -405,7 +405,7 @@ namespace Step37 phi.reinit(cell); phi.read_dof_values(src); phi.evaluate(EvaluationFlags::gradients); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) phi.submit_gradient(coefficient(cell, q) * phi.get_gradient(q), q); phi.integrate(EvaluationFlags::gradients); phi.distribute_local_to_global(dst); @@ -633,7 +633,7 @@ namespace Step37 phi.submit_dof_value(make_vectorized_array(1.), i); phi.evaluate(EvaluationFlags::gradients); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) phi.submit_gradient(coefficient(cell, q) * phi.get_gradient(q), q); phi.integrate(EvaluationFlags::gradients); @@ -907,7 +907,7 @@ namespace Step37 ++cell) { phi.reinit(cell); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) phi.submit_value(make_vectorized_array(1.0), q); phi.integrate(EvaluationFlags::values); phi.distribute_local_to_global(system_rhs); diff --git a/examples/step-48/step-48.cc b/examples/step-48/step-48.cc index 9d27a84018..1f6092f991 100644 --- a/examples/step-48/step-48.cc +++ b/examples/step-48/step-48.cc @@ -127,12 +127,11 @@ namespace Step48 data.initialize_dof_vector(inv_mass_matrix); FEEvaluation fe_eval(data); - const unsigned int n_q_points = fe_eval.n_q_points; for (unsigned int cell = 0; cell < data.n_cell_batches(); ++cell) { fe_eval.reinit(cell); - for (unsigned int q = 0; q < n_q_points; ++q) + for (const unsigned int q : fe_eval.quadrature_point_indices()) fe_eval.submit_value(make_vectorized_array(1.), q); fe_eval.integrate(EvaluationFlags::values); fe_eval.distribute_local_to_global(inv_mass_matrix); @@ -203,7 +202,7 @@ namespace Step48 current.evaluate(EvaluationFlags::values | EvaluationFlags::gradients); old.evaluate(EvaluationFlags::values); - for (unsigned int q = 0; q < current.n_q_points; ++q) + for (const unsigned int q : current.quadrature_point_indices()) { const VectorizedArray current_value = current.get_value(q); const VectorizedArray old_value = old.get_value(q); diff --git a/examples/step-50/step-50.cc b/examples/step-50/step-50.cc index 3a011521ee..8a3a180566 100644 --- a/examples/step-50/step-50.cc +++ b/examples/step-50/step-50.cc @@ -249,8 +249,7 @@ Coefficient::make_coefficient_table( FEEvaluation fe_eval(mf_storage); - const unsigned int n_cells = mf_storage.n_cell_batches(); - const unsigned int n_q_points = fe_eval.n_q_points; + const unsigned int n_cells = mf_storage.n_cell_batches(); coefficient_table->reinit(n_cells, 1); @@ -259,9 +258,9 @@ Coefficient::make_coefficient_table( fe_eval.reinit(cell); VectorizedArray average_value = 0.; - for (unsigned int q = 0; q < n_q_points; ++q) + for (const unsigned int q : fe_eval.quadrature_point_indices()) average_value += value(fe_eval.quadrature_point(q)); - average_value /= n_q_points; + average_value /= fe_eval.n_q_points; (*coefficient_table)(cell, 0) = average_value; } @@ -948,7 +947,7 @@ void LaplaceProblem::assemble_rhs() phi.read_dof_values_plain(solution_copy); phi.evaluate(EvaluationFlags::gradients); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) { phi.submit_gradient(-1.0 * (coefficient(cell, 0) * phi.get_gradient(q)), diff --git a/examples/step-59/step-59.cc b/examples/step-59/step-59.cc index 32a4d8f971..426d61a217 100644 --- a/examples/step-59/step-59.cc +++ b/examples/step-59/step-59.cc @@ -484,7 +484,7 @@ namespace Step59 { phi.reinit(cell); phi.gather_evaluate(src, EvaluationFlags::gradients); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) phi.submit_gradient(phi.get_gradient(q), q); phi.integrate_scatter(EvaluationFlags::gradients, dst); } @@ -600,7 +600,7 @@ namespace Step59 // accordance with its relation to the primal consistency term that // gets the factor of one half due to the average in the test function // slot. - for (unsigned int q = 0; q < phi_inner.n_q_points; ++q) + for (const unsigned int q : phi_inner.quadrature_point_indices()) { const VectorizedArray solution_jump = (phi_inner.get_value(q) - phi_outer.get_value(q)); @@ -687,7 +687,7 @@ namespace Step59 const bool is_dirichlet = (data.get_boundary_id(face) == 0); - for (unsigned int q = 0; q < phi_inner.n_q_points; ++q) + for (const unsigned int q : phi_inner.quadrature_point_indices()) { const VectorizedArray u_inner = phi_inner.get_value(q); const VectorizedArray u_outer = @@ -1085,7 +1085,7 @@ namespace Step59 for (unsigned int cell = 0; cell < data.n_cell_batches(); ++cell) { phi.reinit(cell); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) { VectorizedArray rhs_val = VectorizedArray(); Point> point_batch = @@ -1138,7 +1138,7 @@ namespace Step59 const VectorizedArray sigma = inverse_length_normal_to_face * system_matrix.get_penalty_factor(); - for (unsigned int q = 0; q < phi_face.n_q_points; ++q) + for (const unsigned int q : phi_face.quadrature_point_indices()) { VectorizedArray test_value = VectorizedArray(), test_normal_derivative = diff --git a/examples/step-66/doc/intro.dox b/examples/step-66/doc/intro.dox index 5536ac0101..e0026d4671 100644 --- a/examples/step-66/doc/intro.dox +++ b/examples/step-66/doc/intro.dox @@ -265,7 +265,7 @@ void JacobianOperator::evaluate_newton_step( phi.read_dof_values_plain(newton_step); phi.evaluate(EvaluationFlags::values); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) { nonlinear_values(cell, q) = std::exp(phi.get_value(q)); } diff --git a/examples/step-66/step-66.cc b/examples/step-66/step-66.cc index fca5ca204e..e407742ed4 100644 --- a/examples/step-66/step-66.cc +++ b/examples/step-66/step-66.cc @@ -208,7 +208,7 @@ namespace Step66 phi.read_dof_values_plain(newton_step); phi.evaluate(EvaluationFlags::values); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) { nonlinear_values(cell, q) = std::exp(phi.get_value(q)); } @@ -250,7 +250,7 @@ namespace Step66 EvaluationFlags::values | EvaluationFlags::gradients); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) { phi.submit_value(-nonlinear_values(cell, q) * phi.get_value(q), q); phi.submit_gradient(phi.get_gradient(q), q); @@ -295,7 +295,7 @@ namespace Step66 phi.evaluate(EvaluationFlags::values | EvaluationFlags::gradients); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) { phi.submit_value(-nonlinear_values(cell, q) * phi.get_value(q), q); phi.submit_gradient(phi.get_gradient(q), q); @@ -687,7 +687,7 @@ namespace Step66 phi.read_dof_values_plain(src); phi.evaluate(EvaluationFlags::values | EvaluationFlags::gradients); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) { phi.submit_value(-std::exp(phi.get_value(q)), q); phi.submit_gradient(phi.get_gradient(q), q); diff --git a/examples/step-67/step-67.cc b/examples/step-67/step-67.cc index a85d7ddc11..fce6cada78 100644 --- a/examples/step-67/step-67.cc +++ b/examples/step-67/step-67.cc @@ -1031,7 +1031,7 @@ namespace Euler_DG phi.reinit(cell); phi.gather_evaluate(src, EvaluationFlags::values); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) { const auto w_q = phi.get_value(q); phi.submit_gradient(euler_flux(w_q), q); @@ -1120,7 +1120,7 @@ namespace Euler_DG phi_m.reinit(face); phi_m.gather_evaluate(src, EvaluationFlags::values); - for (unsigned int q = 0; q < phi_m.n_q_points; ++q) + for (const unsigned int q : phi_m.quadrature_point_indices()) { const auto numerical_flux = euler_numerical_flux(phi_m.get_value(q), @@ -1202,7 +1202,7 @@ namespace Euler_DG phi.reinit(face); phi.gather_evaluate(src, EvaluationFlags::values); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) { const auto w_m = phi.get_value(q); const auto normal = phi.normal_vector(q); @@ -1546,7 +1546,7 @@ namespace Euler_DG for (unsigned int cell = 0; cell < data.n_cell_batches(); ++cell) { phi.reinit(cell); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) phi.submit_dof_value(evaluate_function(function, phi.quadrature_point(q)), q); @@ -1596,7 +1596,7 @@ namespace Euler_DG phi.reinit(cell); phi.gather_evaluate(solution, EvaluationFlags::values); VectorizedArray local_errors_squared[3] = {}; - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) { const auto error = evaluate_function(function, phi.quadrature_point(q)) - @@ -1678,7 +1678,7 @@ namespace Euler_DG phi.reinit(cell); phi.gather_evaluate(solution, EvaluationFlags::values); VectorizedArray local_max = 0.; - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) { const auto solution = phi.get_value(q); const auto velocity = euler_velocity(solution); diff --git a/examples/step-75/step-75.cc b/examples/step-75/step-75.cc index f4e3fc794b..0700a382c8 100644 --- a/examples/step-75/step-75.cc +++ b/examples/step-75/step-75.cc @@ -490,7 +490,7 @@ namespace Step75 { integrator.evaluate(EvaluationFlags::gradients); - for (unsigned int q = 0; q < integrator.n_q_points; ++q) + for (const unsigned int q : integrator.quadrature_point_indices()) integrator.submit_gradient(integrator.get_gradient(q), q); integrator.integrate(EvaluationFlags::gradients); @@ -507,7 +507,7 @@ namespace Step75 { integrator.gather_evaluate(src, EvaluationFlags::gradients); - for (unsigned int q = 0; q < integrator.n_q_points; ++q) + for (const unsigned int q : integrator.quadrature_point_indices()) integrator.submit_gradient(integrator.get_gradient(q), q); integrator.integrate_scatter(EvaluationFlags::gradients, dst); diff --git a/examples/step-76/step-76.cc b/examples/step-76/step-76.cc index 333c8c245e..f08dfd4c14 100644 --- a/examples/step-76/step-76.cc +++ b/examples/step-76/step-76.cc @@ -709,7 +709,7 @@ namespace Euler_DG // Apply the cell integral at the cell quadrature points. See also // the function EulerOperator::local_apply_cell() from // step-67: - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) { const auto w_q = phi.get_value(q); phi.submit_gradient(euler_flux(w_q), q); @@ -807,7 +807,8 @@ namespace Euler_DG phi_p.reinit(cell, face); phi_p.gather_evaluate(src, EvaluationFlags::values); - for (unsigned int q = 0; q < phi_m.n_q_points; ++q) + for (const unsigned int q : + phi_m.quadrature_point_indices()) { const auto numerical_flux = euler_numerical_flux(phi_m.get_value(q), @@ -822,7 +823,8 @@ namespace Euler_DG // are a copy of the function // EulerDG::EulerOperator::local_apply_boundary_face // from step-67: - for (unsigned int q = 0; q < phi_m.n_q_points; ++q) + for (const unsigned int q : + phi_m.quadrature_point_indices()) { const auto w_m = phi_m.get_value(q); const auto normal = phi_m.normal_vector(q); @@ -1057,7 +1059,7 @@ namespace Euler_DG for (unsigned int cell = 0; cell < data.n_cell_batches(); ++cell) { phi.reinit(cell); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) phi.submit_dof_value(evaluate_function(function, phi.quadrature_point(q)), q); @@ -1085,7 +1087,7 @@ namespace Euler_DG phi.reinit(cell); phi.gather_evaluate(solution, EvaluationFlags::values); VectorizedArrayType local_errors_squared[3] = {}; - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) { const auto error = evaluate_function(function, phi.quadrature_point(q)) - @@ -1128,7 +1130,7 @@ namespace Euler_DG phi.reinit(cell); phi.gather_evaluate(solution, EvaluationFlags::values); VectorizedArrayType local_max = 0.; - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) { const auto solution = phi.get_value(q); const auto velocity = euler_velocity(solution); diff --git a/tests/performance/timing_mg_glob_coarsen.cc b/tests/performance/timing_mg_glob_coarsen.cc index b7bea87b8e..255edc3cf0 100644 --- a/tests/performance/timing_mg_glob_coarsen.cc +++ b/tests/performance/timing_mg_glob_coarsen.cc @@ -195,7 +195,7 @@ public: compute_diagonal>( data, inverse_diagonal_entries->get_vector(), [](auto &eval) { eval.evaluate(EvaluationFlags::gradients); - for (unsigned int q = 0; q < eval.n_q_points; ++q) + for (const unsigned int q : eval.quadrature_point_indices()) eval.submit_gradient(eval.get_gradient(q), q); eval.integrate(EvaluationFlags::gradients); }); @@ -232,7 +232,7 @@ private: { eval.reinit(cell); eval.gather_evaluate(src, EvaluationFlags::gradients); - for (unsigned int q = 0; q < eval.n_q_points; ++q) + for (const unsigned int q : eval.quadrature_point_indices()) eval.submit_gradient(eval.get_gradient(q), q); eval.integrate_scatter(EvaluationFlags::gradients, dst); } @@ -462,8 +462,8 @@ LaplaceProblem::create_coarse_triangulations() { coarse_triangulations = MGTransferGlobalCoarseningTools::create_geometric_coarsening_sequence( - triangulation/*, - RepartitioningPolicyTools::MinimalGranularityPolicy(16)*/); + triangulation, + RepartitioningPolicyTools::MinimalGranularityPolicy(16)); } @@ -662,7 +662,7 @@ LaplaceProblem::compute_rhs() eval.reinit(cell); dg_eval.reinit(cell); dg_eval.gather_evaluate(dg_rhs, EvaluationFlags::values); - for (unsigned int q = 0; q < eval.n_q_points; ++q) + for (const unsigned int q : eval.quadrature_point_indices()) eval.submit_value(dg_eval.get_value(q), q); eval.integrate_scatter(EvaluationFlags::values, rhs); } diff --git a/tests/performance/timing_navier_stokes.cc b/tests/performance/timing_navier_stokes.cc index 8050242eaa..6eaee3aeaa 100644 --- a/tests/performance/timing_navier_stokes.cc +++ b/tests/performance/timing_navier_stokes.cc @@ -723,7 +723,7 @@ namespace NavierStokes_DG for (unsigned int i = 0; i < phi.static_n_q_points * (dim + 2); ++i) buffer[i] = phi.begin_values()[i]; - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) { const auto w_q = phi.get_value(q); const auto grad_w_q = phi.get_gradient(q); @@ -854,7 +854,7 @@ namespace NavierStokes_DG phi_p.inverse_jacobian(0))[dim - 1])) * Number(viscosity * (degree + 1) * (degree + 1)); - for (unsigned int q = 0; q < phi_m.n_q_points; ++q) + for (const unsigned int q : phi_m.quadrature_point_indices()) { const auto w_m = phi_m.get_value(q); const auto w_p = phi_p.get_value(q); @@ -889,7 +889,7 @@ namespace NavierStokes_DG phi_m.inverse_jacobian(0))[dim - 1]) * Number(2. * viscosity * (degree + 1) * (degree + 1)); - for (unsigned int q = 0; q < phi_m.n_q_points; ++q) + for (const unsigned int q : phi_m.quadrature_point_indices()) { const auto w_m = phi_m.get_value(q); const auto normal = phi_m.normal_vector(q); @@ -1163,7 +1163,7 @@ namespace NavierStokes_DG EvaluationFlags::values | EvaluationFlags::gradients); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : quadrature_point_indices()) { const auto w_q = phi.get_value(q); const auto grad_w_q = phi.get_gradient(q); @@ -1234,7 +1234,7 @@ namespace NavierStokes_DG phi_p.inverse_jacobian(0))[dim - 1])) * Number(viscosity * (degree + 1) * (degree + 1)); - for (unsigned int q = 0; q < phi_m.n_q_points; ++q) + for (const unsigned int q : phi_m.quadrature_point_indices()) { const auto w_m = phi_m.get_value(q); const auto w_p = phi_p.get_value(q); @@ -1302,7 +1302,7 @@ namespace NavierStokes_DG const auto boundary_id = data.get_boundary_id(face); - for (unsigned int q = 0; q < phi_m.n_q_points; ++q) + for (const unsigned int q : phi_m.quadrature_point_indices()) { const auto w_m = phi_m.get_value(q); const auto normal = phi_m.normal_vector(q); @@ -1507,7 +1507,7 @@ namespace NavierStokes_DG for (unsigned int cell = 0; cell < data.n_cell_batches(); ++cell) { phi.reinit(cell); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) phi.submit_dof_value(evaluate_function(function, phi.quadrature_point(q)), q); @@ -1535,7 +1535,7 @@ namespace NavierStokes_DG phi.reinit(cell); phi.gather_evaluate(solution, EvaluationFlags::values); VectorizedArrayType local_errors_squared[3] = {}; - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) { const auto error = evaluate_function(function, phi.quadrature_point(q)) - @@ -1580,7 +1580,7 @@ namespace NavierStokes_DG EvaluationFlags::values | EvaluationFlags::gradients); VectorizedArrayType local_squared[2] = {}; - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) { const auto JxW = phi.JxW(q); const auto w_q = phi.get_value(q); @@ -1622,7 +1622,7 @@ namespace NavierStokes_DG phi.reinit(cell); phi.gather_evaluate(solution, EvaluationFlags::values); VectorizedArrayType local_max = 0.; - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) { const auto solution = phi.get_value(q); const auto velocity = fluid_velocity(solution); diff --git a/tests/performance/timing_step_37.cc b/tests/performance/timing_step_37.cc index 49e00d6895..4fffa02e32 100644 --- a/tests/performance/timing_step_37.cc +++ b/tests/performance/timing_step_37.cc @@ -147,7 +147,7 @@ LaplaceOperator::local_apply( { phi.reinit(cell); phi.gather_evaluate(src, EvaluationFlags::gradients); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) phi.submit_gradient(phi.get_gradient(q), q); phi.integrate_scatter(EvaluationFlags::gradients, dst); } @@ -252,7 +252,7 @@ LaplaceOperator::local_compute_diagonal( phi.submit_dof_value(make_vectorized_array(1.), i); phi.evaluate(EvaluationFlags::gradients); - for (unsigned int q = 0; q < phi.n_q_points; ++q) + for (const unsigned int q : phi.quadrature_point_indices()) phi.submit_gradient(phi.get_gradient(q), q); phi.integrate(EvaluationFlags::gradients); diagonal[i] = phi.get_dof_value(i);