From: Rene Gassmoeller Date: Thu, 28 Apr 2022 15:30:29 +0000 (-0400) Subject: Fix bug in particle list sort X-Git-Tag: v9.4.0-rc1~293^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=206be1f10767cc826abb85aafed7d65a95712541;p=dealii.git Fix bug in particle list sort --- diff --git a/source/particles/particle_handler.cc b/source/particles/particle_handler.cc index e699ac108b..1aaed11693 100644 --- a/source/particles/particle_handler.cc +++ b/source/particles/particle_handler.cc @@ -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());