]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Addresses the first comments of Peter
authorblaisb <blais.bruno@gmail.com>
Fri, 22 May 2020 16:51:22 +0000 (12:51 -0400)
committerBruno Blais <blais.bruno@gmail.com>
Tue, 15 Sep 2020 19:47:34 +0000 (15:47 -0400)
examples/step-x/step-x.cc

index 54c30fa8ac5ac0950fbd53848ffdaae4992b1a3d..e4bac1f9f41093f68b343527ac1bcd3880b68f0a 100644 (file)
@@ -330,8 +330,11 @@ namespace Stepx
   {
     std::vector<types::global_dof_index> dof_indices(fluid_fe.dofs_per_cell);
 
+    Vector<double> 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<dim>::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<dim> particle_location = particle->get_location();

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.