]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix bug in particle list sort
authorRene Gassmoeller <rene.gassmoeller@mailbox.org>
Thu, 28 Apr 2022 15:30:29 +0000 (11:30 -0400)
committerRene Gassmoeller <rene.gassmoeller@mailbox.org>
Thu, 28 Apr 2022 15:30:29 +0000 (11:30 -0400)
source/particles/particle_handler.cc

index e699ac108b7b471ca8a124a53c2742c4662a95d9..1aaed11693b78d14c8ce2a76febbedb03a340e64 100644 (file)
@@ -287,6 +287,10 @@ namespace Particles
         // into a new one (keeping alive the possibly large vectors with
         // particles on cells) into a new container.
         particle_container sorted_particles;
+
+        // note that this call updates owned_particles_end, so that
+        // particle_container_owned_end() below already points to the
+        // new container
         reset_particle_container(sorted_particles);
 
         // iterate over cells and insert the entries in the new order
@@ -295,9 +299,12 @@ namespace Particles
             if (cells_to_particle_cache[cell->active_cell_index()] !=
                 particles.end())
               {
+                // before we move the sorted_particles into particles
+                // particle_container_ghost_end() still points to the
+                // old particles container. Therefore this condition looks quirky.
                 typename particle_container::iterator insert_position =
                   cell->is_locally_owned() ? particle_container_owned_end() :
-                                             particle_container_ghost_end();
+                                             --sorted_particles.end();
                 typename particle_container::iterator new_entry =
                   sorted_particles.insert(
                     insert_position, typename particle_container::value_type());

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.