]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Clear any properties already set when calling Particle::set_property_pool().
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 20 Oct 2020 02:43:44 +0000 (20:43 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 20 Oct 2020 02:44:36 +0000 (20:44 -0600)
include/deal.II/particles/particle.h

index 81b31978270c44a0c2ba83198743ce89e37049f4..20eefd3af95eea437fc5fc214dac26b3a8c806ed 100644 (file)
@@ -334,6 +334,11 @@ namespace Particles
      * since the particle does not know about the properties,
      * we want to do it not at construction time. Another use for this
      * function is after particle transfer to a new process.
+     *
+     * If a particle already stores properties in a property pool, then
+     * these are released and the particle will not store any properties
+     * after this call (though new properties can be assigned to it using
+     * the set_properties() call).
      */
     void
     set_property_pool(PropertyPool &property_pool);
@@ -549,7 +554,15 @@ namespace Particles
   inline void
   Particle<dim, spacedim>::set_property_pool(PropertyPool &new_property_pool)
   {
+    // If the particle currently has a reference to properties, then
+    // release those
+    if (property_pool != nullptr && properties != PropertyPool::invalid_handle)
+      property_pool->deallocate_properties_array(properties);
+
+    // Then start from scratch, with no properties associated with the current
+    // particle
     property_pool = &new_property_pool;
+    properties    = PropertyPool::invalid_handle;
   }
 
 

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.