]> https://gitweb.dealii.org/ - dealii.git/commitdiff
sort property pool
authorRene Gassmoeller <rene.gassmoeller@mailbox.org>
Wed, 9 Jun 2021 05:10:36 +0000 (01:10 -0400)
committerRene Gassmoeller <rene.gassmoeller@mailbox.org>
Sat, 12 Jun 2021 03:28:17 +0000 (23:28 -0400)
include/deal.II/particles/property_pool.h
source/particles/particle_handler.cc
source/particles/property_pool.cc
tests/particles/generators_05.cc
tests/particles/generators_05.with_p4est=true.mpirun=2.output

index f2282e43b73cadc153d6067af0e54695d620bc0e..26da5e373e803062ee809159ad6b54d7f8e410f0 100644 (file)
@@ -211,6 +211,9 @@ namespace Particles
     unsigned int
     n_properties_per_slot() const;
 
+    void
+    sort_memory_slots(std::vector<std::vector<Handle>> &sorted_handles);
+
   private:
     /**
      * The number of properties that are reserved per particle.
index 78ae3a3816c3159d1b35e1aaaa65f6c3f30035ad..52d47fc513d2a782fa143275092352273c2fd6a7 100644 (file)
@@ -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
 
 
index cd0bffc73ad11b27917ca265ed61179c6b484f49..94a1906964452aa08c5f30c44c6db34c0a43e96f 100644 (file)
@@ -167,6 +167,60 @@ namespace Particles
     return n_properties;
   }
 
+  template <int dim, int spacedim>
+  void
+  PropertyPool<dim, spacedim>::sort_memory_slots(
+    std::vector<std::vector<Handle>> &sorted_handles)
+  {
+    std::vector<Point<spacedim>> sorted_locations(locations.size());
+    std::vector<Point<dim>>      sorted_reference_locations(
+      reference_locations.size());
+    std::vector<types::particle_index> sorted_ids(ids.size());
+    std::vector<double>                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>;
index 9b3c6e75fc99d7ed7272ff6ea6801bd0e4b569eb..74fd9f351668b675c2c1e417e6dc0778235d2d4c 100644 (file)
@@ -94,7 +94,7 @@ main(int argc, char *argv[])
 {
   Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
 
-  initlog();
+  MPILogInitAll();
 
   {
     deallog.push("2d/2d");
index 75c03152bafa9a0a20884fb1a4c95e60c00f42aa..dde7d5edd05b26b859ceec56a2eac42f347a22d9 100644 (file)
@@ -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.

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.