]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Store (reference) locations in the PropertyPool. 11443/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 31 Dec 2020 00:14:47 +0000 (17:14 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Thu, 14 Jan 2021 17:46:30 +0000 (10:46 -0700)
include/deal.II/particles/particle.h
source/particles/particle.cc

index 05780de7113c4860e956dd45b3488f938742e8b3..d676baf9c5607f2bb8724328617aacbb3730c55f 100644 (file)
@@ -479,16 +479,6 @@ namespace Particles
      */
     static PropertyPool<dim, spacedim> global_property_pool;
 
-    /**
-     * Current particle location.
-     */
-    Point<spacedim> location;
-
-    /**
-     * Current particle location in the reference cell.
-     */
-    Point<dim> reference_location;
-
     /**
      * Globally unique ID of particle.
      */
@@ -568,7 +558,7 @@ namespace Particles
   inline void
   Particle<dim, spacedim>::set_location(const Point<spacedim> &new_loc)
   {
-    location = new_loc;
+    property_pool->set_location(property_pool_handle, new_loc);
   }
 
 
@@ -577,7 +567,7 @@ namespace Particles
   inline const Point<spacedim> &
   Particle<dim, spacedim>::get_location() const
   {
-    return location;
+    return property_pool->get_location(property_pool_handle);
   }
 
 
@@ -586,7 +576,7 @@ namespace Particles
   inline void
   Particle<dim, spacedim>::set_reference_location(const Point<dim> &new_loc)
   {
-    reference_location = new_loc;
+    property_pool->set_reference_location(property_pool_handle, new_loc);
   }
 
 
@@ -595,7 +585,7 @@ namespace Particles
   inline const Point<dim> &
   Particle<dim, spacedim>::get_reference_location() const
   {
-    return reference_location;
+    return property_pool->get_reference_location(property_pool_handle);
   }
 
 
@@ -637,6 +627,9 @@ namespace Particles
     const typename PropertyPool<dim, spacedim>::Handle new_handle =
       new_property_pool.register_particle();
 
+    const Point<spacedim> location           = get_location();
+    const Point<dim>      reference_location = get_reference_location();
+
     if (/* old pool */ has_properties())
       {
         ArrayView<const double> old_properties = this->get_properties();
@@ -652,9 +645,13 @@ namespace Particles
 
 
     // Then set the pointer to the property pool we want to use. Also set the
-    // handle to any properties, if we have copied any above.
+    // handle to any properties.
     property_pool        = &new_property_pool;
     property_pool_handle = new_handle;
+
+    // Now also store the saved locations
+    set_location(location);
+    set_reference_location(reference_location);
   }
 
 
index 602a513f0dafab050e31f1296ddb9bbfc7bfc3d8..d94efaa0cf655305ff15412993b51fddd69aae12 100644 (file)
@@ -28,9 +28,7 @@ namespace Particles
 
   template <int dim, int spacedim>
   Particle<dim, spacedim>::Particle()
-    : location(numbers::signaling_nan<Point<spacedim>>())
-    , reference_location(numbers::signaling_nan<Point<dim>>())
-    , id(0)
+    : id(0)
     , property_pool(&global_property_pool)
     , property_pool_handle(property_pool->register_particle())
   {}
@@ -41,23 +39,25 @@ namespace Particles
   Particle<dim, spacedim>::Particle(const Point<spacedim> &location,
                                     const Point<dim> &     reference_location,
                                     const types::particle_index id)
-    : location(location)
-    , reference_location(reference_location)
-    , id(id)
+    : id(id)
     , property_pool(&global_property_pool)
     , property_pool_handle(property_pool->register_particle())
-  {}
+  {
+    set_location(location);
+    set_reference_location(reference_location);
+  }
 
 
 
   template <int dim, int spacedim>
   Particle<dim, spacedim>::Particle(const Particle<dim, spacedim> &particle)
-    : location(particle.get_location())
-    , reference_location(particle.get_reference_location())
-    , id(particle.get_id())
+    : id(particle.get_id())
     , property_pool(particle.property_pool)
     , property_pool_handle(property_pool->register_particle())
   {
+    set_location(particle.get_location());
+    set_reference_location(particle.get_reference_location());
+
     if (particle.has_properties())
       {
         const ArrayView<const double> their_properties =
@@ -77,9 +77,7 @@ namespace Particles
   Particle<dim, spacedim>::Particle(
     const void *&                      data,
     PropertyPool<dim, spacedim> *const new_property_pool)
-    : location(numbers::signaling_nan<Point<spacedim>>())
-    , reference_location(numbers::signaling_nan<Point<dim>>())
-    , id(0)
+    : id(0)
     , property_pool(new_property_pool != nullptr ? new_property_pool :
                                                    &global_property_pool)
     , property_pool_handle(property_pool->register_particle())
@@ -115,12 +113,13 @@ namespace Particles
 
   template <int dim, int spacedim>
   Particle<dim, spacedim>::Particle(Particle<dim, spacedim> &&particle) noexcept
-    : location(std::move(particle.location))
-    , reference_location(std::move(particle.reference_location))
-    , id(std::move(particle.id))
+    : id(std::move(particle.id))
     , property_pool(std::move(particle.property_pool))
     , property_pool_handle(std::move(particle.property_pool_handle))
   {
+    // There is no need to copy locations and properties -- we simply
+    // inherit them from the object we move from.
+
     // We stole the rhs's properties, so we need to invalidate
     // the handle the rhs holds lest it releases the memory that
     // we still reference here.
@@ -135,15 +134,15 @@ namespace Particles
   {
     if (this != &particle)
       {
-        location           = particle.location;
-        reference_location = particle.reference_location;
-        id                 = particle.id;
-        property_pool      = particle.property_pool;
+        id = particle.id;
 
         Assert(this->property_pool->n_properties_per_slot() ==
                  particle.property_pool->n_properties_per_slot(),
                ExcInternalError());
 
+        set_location(particle.get_location());
+        set_reference_location(particle.get_reference_location());
+
         if (particle.has_properties())
           {
             const ArrayView<const double> their_properties =
@@ -169,11 +168,18 @@ namespace Particles
   {
     if (this != &particle)
       {
-        location             = particle.location;
-        reference_location   = particle.reference_location;
-        id                   = particle.id;
-        property_pool        = particle.property_pool;
-        property_pool_handle = particle.property_pool_handle;
+        // If we currently hold a handle, release the memory. (The only way a
+        // particle can end up not holding a valid handle is if it has been
+        // moved from.)
+        if (property_pool_handle != PropertyPool<dim, spacedim>::invalid_handle)
+          property_pool->deregister_particle(property_pool_handle);
+
+        id                   = std::move(particle.id);
+        property_pool        = std::move(particle.property_pool);
+        property_pool_handle = std::move(particle.property_pool_handle);
+
+        // No need to copy locations and properties -- we just get them
+        // by taking over the property pool handle.
 
         // We stole the rhs's properties, so we need to invalidate
         // the handle the rhs holds lest it releases the memory that
@@ -282,8 +288,8 @@ namespace Particles
   std::size_t
   Particle<dim, spacedim>::serialized_size_in_bytes() const
   {
-    std::size_t size = sizeof(types::particle_index) + sizeof(location) +
-                       sizeof(reference_location);
+    std::size_t size = sizeof(get_id()) + sizeof(get_location()) +
+                       sizeof(get_reference_location());
 
     if (has_properties())
       {

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.