]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Implement pack_particles functions
authorRene Gassmoeller <rene.gassmoeller@mailbox.org>
Thu, 8 Aug 2019 18:10:45 +0000 (12:10 -0600)
committerRene Gassmoeller <rene.gassmoeller@mailbox.org>
Thu, 8 Aug 2019 20:50:53 +0000 (14:50 -0600)
include/deal.II/particles/particle_handler.h
source/particles/particle_handler.cc
source/particles/particle_handler.inst.in

index cac550d4e0148ebb50a51c9119dfee69c07e076f..75797dd875e34843b93c5103c807fe34450d5245 100644 (file)
@@ -38,6 +38,20 @@ DEAL_II_NAMESPACE_OPEN
 
 namespace Particles
 {
+  namespace internal
+  {
+    template <int dim, int spacedim>
+    std::vector<char>
+    pack_particles(std::vector<Particle<dim, spacedim>> &particles);
+
+    template <int dim, int spacedim>
+    std::vector<Particle<dim, spacedim>>
+    unpack_particles(
+      const boost::iterator_range<std::vector<char>::const_iterator>
+        &           data_range,
+      PropertyPool &property_pool = PropertyPool(0));
+  } // namespace internal
+
   /**
    * This class manages the storage and handling of particles. It provides
    * the data structures necessary to store particles efficiently, accessor
index 98a9f046fa1fc9711c4999a907e1d8c25e480fa2..27f101d6f6efb729ff9e6c95616726d1a933a43e 100644 (file)
@@ -28,6 +28,65 @@ DEAL_II_NAMESPACE_OPEN
 
 namespace Particles
 {
+  namespace internal
+  {
+    template <int dim, int spacedim>
+    std::vector<char>
+    pack_particles(std::vector<Particle<dim, spacedim>> &particles)
+    {
+      std::vector<char> buffer;
+
+      if (particles.size() == 0)
+        return buffer;
+
+      buffer.resize(particles.size() *
+                    particles.front().serialized_size_in_bytes());
+      void *current_data = buffer.data();
+
+      for (const auto &particle : particles)
+        {
+          particle.write_data(current_data);
+        }
+
+      return buffer;
+    }
+
+    template <int dim, int spacedim>
+    std::vector<Particle<dim, spacedim>>
+    unpack_particles(
+      const boost::iterator_range<std::vector<char>::const_iterator>
+        &           data_range,
+      PropertyPool &property_pool)
+    {
+      std::vector<Particle<dim, spacedim>> particles;
+
+      if (data_range.empty())
+        return particles;
+
+      Particle<dim, spacedim> particle;
+      particle.set_property_pool(property_pool);
+      const unsigned int particle_size = particle.serialized_size_in_bytes();
+
+      particles.reserve(data_range.size() / particle_size);
+
+      const void *data = static_cast<const void *>(&(*data_range.begin()));
+
+      while (data < &(*data_range.end()))
+        {
+          particles.push_back(Particle<dim, spacedim>(data, &property_pool));
+        }
+
+      Assert(
+        data == &(*data_range.end()),
+        ExcMessage(
+          "The particle data could not be deserialized successfully. "
+          "Check that when deserializing the particles you expect the same "
+          "number of properties that were serialized."));
+
+      return particles;
+    }
+  } // namespace internal
+
   template <int dim, int spacedim>
   ParticleHandler<dim, spacedim>::ParticleHandler()
     : triangulation()
@@ -1182,8 +1241,7 @@ namespace Particles
           break;
       }
 
-    return Utilities::pack(stored_particles_on_cell,
-                           /*allow_compression=*/true);
+    return internal::pack_particles(stored_particles_on_cell);
   }
 
   template <int dim, int spacedim>
@@ -1196,10 +1254,7 @@ namespace Particles
     // We leave this container non-const to be able to `std::move`
     // its contents directly into the particles multimap later.
     std::vector<Particle<dim, spacedim>> loaded_particles_on_cell =
-      Utilities::unpack<std::vector<Particle<dim, spacedim>>>(
-        data_range.begin(),
-        data_range.end(),
-        /*allow_compression=*/true);
+      internal::unpack_particles<dim, spacedim>(data_range, *property_pool);
 
     // Update the reference to the current property pool for all particles.
     // This was not stored, because they might be transported across process
index 022b8568d2513f14ab614812208990fa763784cf..8973ca70e949ce67a40167f0e33aff8ae1f52ac9 100644 (file)
@@ -19,6 +19,21 @@ for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS)
 #if deal_II_dimension <= deal_II_space_dimension
     namespace Particles
     \{
+      namespace internal
+      \{
+        template std::vector<char>
+        pack_particles(
+          std::vector<Particle<deal_II_dimension, deal_II_space_dimension>>
+            &particles);
+
+        template std::vector<
+          Particle<deal_II_dimension, deal_II_space_dimension>>
+        unpack_particles(
+          const boost::iterator_range<std::vector<char>::const_iterator>
+            &           data_range,
+          PropertyPool &property_pool);
+      \}
+
       template class ParticleHandler<deal_II_dimension,
                                      deal_II_space_dimension>;
     \}

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.