From: Wolfgang Bangerth Date: Thu, 31 Dec 2020 00:14:47 +0000 (-0700) Subject: Store (reference) locations in the PropertyPool. X-Git-Tag: v9.3.0-rc1~625^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=119e085eb4b1260f09df1aa7ce7215cf1f7472bd;p=dealii.git Store (reference) locations in the PropertyPool. --- diff --git a/include/deal.II/particles/particle.h b/include/deal.II/particles/particle.h index 05780de711..d676baf9c5 100644 --- a/include/deal.II/particles/particle.h +++ b/include/deal.II/particles/particle.h @@ -479,16 +479,6 @@ namespace Particles */ static PropertyPool global_property_pool; - /** - * Current particle location. - */ - Point location; - - /** - * Current particle location in the reference cell. - */ - Point reference_location; - /** * Globally unique ID of particle. */ @@ -568,7 +558,7 @@ namespace Particles inline void Particle::set_location(const Point &new_loc) { - location = new_loc; + property_pool->set_location(property_pool_handle, new_loc); } @@ -577,7 +567,7 @@ namespace Particles inline const Point & Particle::get_location() const { - return location; + return property_pool->get_location(property_pool_handle); } @@ -586,7 +576,7 @@ namespace Particles inline void Particle::set_reference_location(const Point &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 & Particle::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::Handle new_handle = new_property_pool.register_particle(); + const Point location = get_location(); + const Point reference_location = get_reference_location(); + if (/* old pool */ has_properties()) { ArrayView 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); } diff --git a/source/particles/particle.cc b/source/particles/particle.cc index 602a513f0d..d94efaa0cf 100644 --- a/source/particles/particle.cc +++ b/source/particles/particle.cc @@ -28,9 +28,7 @@ namespace Particles template Particle::Particle() - : location(numbers::signaling_nan>()) - , reference_location(numbers::signaling_nan>()) - , id(0) + : id(0) , property_pool(&global_property_pool) , property_pool_handle(property_pool->register_particle()) {} @@ -41,23 +39,25 @@ namespace Particles Particle::Particle(const Point &location, const Point & 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 Particle::Particle(const Particle &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 their_properties = @@ -77,9 +77,7 @@ namespace Particles Particle::Particle( const void *& data, PropertyPool *const new_property_pool) - : location(numbers::signaling_nan>()) - , reference_location(numbers::signaling_nan>()) - , 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 Particle::Particle(Particle &&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 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::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::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()) {