From: Rene Gassmoeller Date: Wed, 9 Jun 2021 05:10:36 +0000 (-0400) Subject: sort property pool X-Git-Tag: v9.4.0-rc1~1222^2~6 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1bb18ea7989ee2cb522346eaeaf80f274a6c5b21;p=dealii.git sort property pool --- diff --git a/include/deal.II/particles/property_pool.h b/include/deal.II/particles/property_pool.h index f2282e43b7..26da5e373e 100644 --- a/include/deal.II/particles/property_pool.h +++ b/include/deal.II/particles/property_pool.h @@ -211,6 +211,9 @@ namespace Particles unsigned int n_properties_per_slot() const; + void + sort_memory_slots(std::vector> &sorted_handles); + private: /** * The number of properties that are reserved per particle. diff --git a/source/particles/particle_handler.cc b/source/particles/particle_handler.cc index 78ae3a3816..52d47fc513 100644 --- a/source/particles/particle_handler.cc +++ b/source/particles/particle_handler.cc @@ -1291,6 +1291,7 @@ namespace Particles // remove_particles also calls update_cached_numbers() remove_particles(particles_out_of_cell); + property_pool->sort_memory_slots(particles); } // namespace Particles diff --git a/source/particles/property_pool.cc b/source/particles/property_pool.cc index cd0bffc73a..94a1906964 100644 --- a/source/particles/property_pool.cc +++ b/source/particles/property_pool.cc @@ -167,6 +167,60 @@ namespace Particles return n_properties; } + template + void + PropertyPool::sort_memory_slots( + std::vector> &sorted_handles) + { + std::vector> sorted_locations(locations.size()); + std::vector> sorted_reference_locations( + reference_locations.size()); + std::vector sorted_ids(ids.size()); + std::vector sorted_properties(properties.size()); + + unsigned int i = 0; + for (auto &handles_in_cell : sorted_handles) + for (auto &handle : handles_in_cell) + { + Assert(handle != invalid_handle, + ExcMessage( + "Invalid handle detected during sorting particle memory.")); + + sorted_locations[i] = locations[handle]; + sorted_reference_locations[i] = reference_locations[handle]; + sorted_ids[i] = ids[handle]; + + for (unsigned int j = 0; j < n_properties; ++j) + sorted_properties[i * n_properties + j] = + properties[handle * n_properties + j]; + + handle = i; + ++i; + } + + Assert(i == locations.size() - currently_available_handles.size(), + ExcMessage( + "Number of sorted property handles is not equal to number " + "of currently registered handles.")); + + locations.swap(sorted_locations); + reference_locations.swap(sorted_reference_locations); + ids.swap(sorted_ids); + properties.swap(sorted_properties); + + // Now update the available handles + for (auto &available_handle : currently_available_handles) + { + available_handle = i; + ++i; + } + + Assert(i == locations.size(), + ExcMessage("Number of allocated handles does not match number " + "of registered handles plus number of unregistered " + "but available handles.")); + } + // Instantiate the class for all reasonable template arguments template class PropertyPool<1, 1>; diff --git a/tests/particles/generators_05.cc b/tests/particles/generators_05.cc index 9b3c6e75fc..74fd9f3516 100644 --- a/tests/particles/generators_05.cc +++ b/tests/particles/generators_05.cc @@ -94,7 +94,7 @@ main(int argc, char *argv[]) { Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); - initlog(); + MPILogInitAll(); { deallog.push("2d/2d"); diff --git a/tests/particles/generators_05.with_p4est=true.mpirun=2.output b/tests/particles/generators_05.with_p4est=true.mpirun=2.output index 75c03152ba..dde7d5edd0 100644 --- a/tests/particles/generators_05.with_p4est=true.mpirun=2.output +++ b/tests/particles/generators_05.with_p4est=true.mpirun=2.output @@ -1,11 +1,9 @@ -DEAL:2d/2d::OK -DEAL:2d/3d::OK -DEAL:3d/3d::OK -DEAL:2d/2d::OK -DEAL:2d/3d::OK -DEAL:3d/3d::OK -l 1.0 has 4 particles. + + +DEAL:2d/2d::Locally owned active cells: 4 +DEAL:2d/2d::Global particles: 16 +DEAL:2d/2d::Cell 1.0 has 4 particles. DEAL:2d/2d::Cell 1.1 has 4 particles. DEAL:2d/2d::Cell 1.2 has 4 particles. DEAL:2d/2d::Cell 1.3 has 4 particles.