]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add particle update data function to overwrite particle information without recreatin... 11199/head
authorBruno <blais.bruno@gmail.com>
Wed, 18 Nov 2020 02:07:02 +0000 (21:07 -0500)
committerBruno <blais.bruno@gmail.com>
Thu, 19 Nov 2020 01:32:16 +0000 (20:32 -0500)
Added documentation and fixed indentation
Added out to documentation

Co-authored-by: Martin Kronbichler <kronbichler@lnm.mw.tum.de>
include/deal.II/particles/particle.h
source/particles/particle.cc
source/particles/particle_handler.cc

index a79617d2238443374dfcef7148a335b30fe3ae1b..e43dc03b3197650a1ff4fb0da216d2488a206dc1 100644 (file)
@@ -235,6 +235,25 @@ namespace Particles
     void
     write_data(void *&data) const;
 
+
+    /**
+     * Update all of the data associated with a particle : id,
+     * location, reference location and, if any, properties by using a
+     * data array. The array is expected to be large enough to take the data,
+     * and the void pointer should point to the first entry of the array to
+     * which the data should be written. This function is meant for
+     * de-serializing the particle data without requiring that a new Particle
+     * class be built. This is used in the ParticleHandler to update the
+     * ghost particles without de-allocating and re-allocating memory.
+     *
+     * @param[in,out] data A pointer to a memory location from which
+     * to read the information that completely describes a particle. This
+     * class then de-serializes its data from this memory location and
+     * advance the pointer accordingly.
+     */
+    void
+    update_particle_data(const void *&data);
+
     /**
      * Set the location of this particle. Note that this does not check
      * whether this is a valid location in the simulation domain.
index 2befeec29c6f61f2ae72e9b9f37db027cc35f420..0a68480dc1382eb50aafd9bdff3ad9bb52b1ea4b 100644 (file)
@@ -220,6 +220,34 @@ namespace Particles
   }
 
 
+  template <int dim, int spacedim>
+  void
+  Particle<dim, spacedim>::update_particle_data(const void *&data)
+  {
+    const types::particle_index *id_data =
+      static_cast<const types::particle_index *>(data);
+    id                  = *id_data++;
+    const double *pdata = reinterpret_cast<const double *>(id_data);
+
+    for (unsigned int i = 0; i < spacedim; ++i)
+      location(i) = *pdata++;
+
+    for (unsigned int i = 0; i < dim; ++i)
+      reference_location(i) = *pdata++;
+
+    // See if there are properties to load
+    if (has_properties())
+      {
+        const ArrayView<double> particle_properties =
+          property_pool->get_properties(properties);
+        const unsigned int size = particle_properties.size();
+        for (unsigned int i = 0; i < size; ++i)
+          particle_properties[i] = *pdata++;
+      }
+
+    data = static_cast<const void *>(pdata);
+  }
+
 
   template <int dim, int spacedim>
   std::size_t
index 783bd95091a5a503ca664ec9308afb28b285087d..fd3fc0387439c9773c62f389d31f465217e85f51 100644 (file)
@@ -1649,9 +1649,9 @@ namespace Particles
 
     for (auto &recv_particle : ghost_particles_iterators)
       {
-        recv_particle->second.free_properties();
-        recv_particle->second =
-          Particle<dim, spacedim>(recv_data_it, property_pool.get());
+        // Update particle data using previously allocated memory space
+        // for efficiency reasons
+        recv_particle->second.update_particle_data(recv_data_it);
 
         if (load_callback)
           recv_data_it =

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.