]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Address comments
authorRene Gassmoeller <rene.gassmoeller@mailbox.org>
Fri, 11 Jun 2021 13:58:12 +0000 (09:58 -0400)
committerRene Gassmoeller <rene.gassmoeller@mailbox.org>
Sat, 12 Jun 2021 03:28:18 +0000 (23:28 -0400)
include/deal.II/particles/property_pool.h
source/particles/property_pool.cc

index 26da5e373e803062ee809159ad6b54d7f8e410f0..8d26b445e590729dde936b649b2f04c6e82c311f 100644 (file)
@@ -211,8 +211,17 @@ namespace Particles
     unsigned int
     n_properties_per_slot() const;
 
+    /**
+     * This function makes sure that all internally stored memory blocks
+     * are sorted in the same order as one would loop over the @p handles_to_sort
+     * container. This makes sure memory access is contiguous with actual
+     * memory location. Because the ordering is given in the input argumet
+     * the complexity of this function is $O(N)$ where N is the number of
+     * elements in the input argument. This function creates a temporary copy of
+     * all currently registered memory blocks.
+     */
     void
-    sort_memory_slots(std::vector<std::vector<Handle>> &sorted_handles);
+    sort_memory_slots(std::vector<std::vector<Handle>> &handles_to_sort);
 
   private:
     /**
index 94a1906964452aa08c5f30c44c6db34c0a43e96f..20e48d1f96ae571d7964e93d2d927633fc0a2692 100644 (file)
@@ -59,7 +59,7 @@ namespace Particles
                                " open handles to memory that was allocated "
                                "via allocate_properties_array() but that has "
                                "not been returned via "
-                               "deallocate_properties_array()."));
+                               "deregister_particle()."));
       }
 
     // Clear vectors and ensure deallocation of memory
@@ -170,35 +170,39 @@ namespace Particles
   template <int dim, int spacedim>
   void
   PropertyPool<dim, spacedim>::sort_memory_slots(
-    std::vector<std::vector<Handle>> &sorted_handles)
+    std::vector<std::vector<Handle>> &handles_to_sort)
   {
-    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)
+    std::vector<Point<spacedim>>       sorted_locations;
+    std::vector<Point<dim>>            sorted_reference_locations;
+    std::vector<types::particle_index> sorted_ids;
+    std::vector<double>                sorted_properties;
+
+    sorted_locations.reserve(locations.size());
+    sorted_reference_locations.reserve(reference_locations.size());
+    sorted_ids.reserve(ids.size());
+    sorted_properties.reserve(properties.size());
+
+    Handle i = 0;
+    for (auto &handles_in_cell : handles_to_sort)
       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];
+          sorted_locations.push_back(locations[handle]);
+          sorted_reference_locations.push_back(reference_locations[handle]);
+          sorted_ids.push_back(ids[handle]);
 
           for (unsigned int j = 0; j < n_properties; ++j)
-            sorted_properties[i * n_properties + j] =
-              properties[handle * n_properties + j];
+            sorted_properties.push_back(properties[handle * n_properties + j]);
 
           handle = i;
           ++i;
         }
 
-    Assert(i == locations.size() - currently_available_handles.size(),
+    Assert(sorted_locations.size() ==
+             locations.size() - currently_available_handles.size(),
            ExcMessage(
              "Number of sorted property handles is not equal to number "
              "of currently registered handles."));
@@ -208,17 +212,7 @@ namespace Particles
     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."));
+    currently_available_handles.clear();
   }
 
 

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.