From 1664ceec4415c77d617c40f7f7e401516551eefb Mon Sep 17 00:00:00 2001 From: blaisb Date: Fri, 22 May 2020 12:51:22 -0400 Subject: [PATCH] Addresses the first comments of Peter --- examples/step-x/step-x.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/examples/step-x/step-x.cc b/examples/step-x/step-x.cc index 54c30fa8ac..e4bac1f9f4 100644 --- a/examples/step-x/step-x.cc +++ b/examples/step-x/step-x.cc @@ -330,8 +330,11 @@ namespace Stepx { std::vector dof_indices(fluid_fe.dofs_per_cell); + Vector dof_data_per_cell(fluid_fe.dofs_per_cell); + Tensor<1, dim> particle_velocity; + auto particle = particle_handler.begin(); while (particle != particle_handler.end()) { @@ -340,9 +343,16 @@ namespace Stepx const auto &dh_cell = typename DoFHandler::cell_iterator(*cell, &fluid_dh); dh_cell->get_dof_indices(dof_indices); - const auto pic = particle_handler.particles_in_cell(cell); - for (unsigned int i = 0; particle != pic.end(); ++particle, ++i) + // Gather the DOF information in a local vector to prevent dynamically + // re-accessing everything when there are multiple particles in a cell + for (unsigned int j = 0; j < fluid_fe.dofs_per_cell; ++j) + { + dof_data_per_cell[j] = field_relevant(dof_indices[j]); + } + + const auto pic = particle_handler.particles_in_cell(cell); + for (; particle != pic.end(); ++particle) { const auto &reference_location = particle->get_reference_location(); particle_velocity = 0.; @@ -352,7 +362,7 @@ namespace Stepx particle_velocity[comp_j.first] += fluid_fe.shape_value(j, reference_location) * - field_relevant(dof_indices[j]); + dof_data_per_cell[j]; } Point particle_location = particle->get_location(); -- 2.39.5