From 1f7b6c0d72c52e69f2325e295b6dd77b1ea18000 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Sat, 12 Dec 2020 11:34:59 -0700 Subject: [PATCH] Rename a member variable to more clearly express its purpose. --- include/deal.II/particles/particle.h | 19 ++++---- source/particles/particle.cc | 69 +++++++++++++++------------- 2 files changed, 46 insertions(+), 42 deletions(-) diff --git a/include/deal.II/particles/particle.h b/include/deal.II/particles/particle.h index fb6b87e571..eabe5a3df7 100644 --- a/include/deal.II/particles/particle.h +++ b/include/deal.II/particles/particle.h @@ -483,7 +483,7 @@ namespace Particles /** * A handle to all particle properties */ - typename PropertyPool::Handle properties; + typename PropertyPool::Handle property_pool_handle; }; /* ---------------------- inline and template functions ------------------ */ @@ -523,7 +523,7 @@ namespace Particles { unsigned int n_properties = 0; if ((property_pool != nullptr) && - (properties != PropertyPool::invalid_handle)) + (property_pool_handle != PropertyPool::invalid_handle)) n_properties = get_properties().size(); ar &location &reference_location &id &n_properties; @@ -600,7 +600,7 @@ namespace Particles typename PropertyPool::Handle new_handle = PropertyPool::invalid_handle; if (property_pool != nullptr && - properties != PropertyPool::invalid_handle) + property_pool_handle != PropertyPool::invalid_handle) { new_handle = new_property_pool.register_particle(); @@ -615,14 +615,14 @@ namespace Particles // If the particle currently has a reference to properties, then // release those. if (property_pool != nullptr && - properties != PropertyPool::invalid_handle) - property_pool->deregister_particle(properties); + property_pool_handle != PropertyPool::invalid_handle) + property_pool->deregister_particle(property_pool_handle); // 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. - property_pool = &new_property_pool; - properties = new_handle; + property_pool = &new_property_pool; + property_pool_handle = new_handle; } @@ -633,7 +633,7 @@ namespace Particles { Assert(has_properties(), ExcInternalError()); - return property_pool->get_properties(properties); + return property_pool->get_properties(property_pool_handle); } @@ -643,7 +643,8 @@ namespace Particles Particle::has_properties() const { return (property_pool != nullptr) && - (properties != PropertyPool::invalid_handle); + (property_pool_handle != + PropertyPool::invalid_handle); } } // namespace Particles diff --git a/source/particles/particle.cc b/source/particles/particle.cc index db9c53e601..933cc9a1c6 100644 --- a/source/particles/particle.cc +++ b/source/particles/particle.cc @@ -27,7 +27,7 @@ namespace Particles , reference_location(numbers::signaling_nan>()) , id(0) , property_pool(nullptr) - , properties(PropertyPool::invalid_handle) + , property_pool_handle(PropertyPool::invalid_handle) {} @@ -40,7 +40,7 @@ namespace Particles , reference_location(reference_location) , id(id) , property_pool(nullptr) - , properties(PropertyPool::invalid_handle) + , property_pool_handle(PropertyPool::invalid_handle) {} @@ -51,13 +51,13 @@ namespace Particles , reference_location(particle.get_reference_location()) , id(particle.get_id()) , property_pool(particle.property_pool) - , properties(PropertyPool::invalid_handle) + , property_pool_handle(PropertyPool::invalid_handle) { if (particle.has_properties()) { - properties = property_pool->register_particle(); + property_pool_handle = property_pool->register_particle(); const ArrayView my_properties = - property_pool->get_properties(properties); + property_pool->get_properties(property_pool_handle); const ArrayView their_properties = particle.get_properties(); @@ -87,15 +87,15 @@ namespace Particles property_pool = new_property_pool; if (property_pool != nullptr) - properties = property_pool->register_particle(); + property_pool_handle = property_pool->register_particle(); else - properties = PropertyPool::invalid_handle; + property_pool_handle = PropertyPool::invalid_handle; // See if there are properties to load if (has_properties()) { const ArrayView particle_properties = - property_pool->get_properties(properties); + property_pool->get_properties(property_pool_handle); const unsigned int size = particle_properties.size(); for (unsigned int i = 0; i < size; ++i) particle_properties[i] = *pdata++; @@ -112,9 +112,9 @@ namespace Particles , reference_location(std::move(particle.reference_location)) , id(std::move(particle.id)) , property_pool(std::move(particle.property_pool)) - , properties(std::move(particle.properties)) + , property_pool_handle(std::move(particle.property_pool_handle)) { - particle.properties = PropertyPool::invalid_handle; + particle.property_pool_handle = PropertyPool::invalid_handle; } @@ -132,18 +132,18 @@ namespace Particles if (particle.has_properties()) { - properties = property_pool->register_particle(); + property_pool_handle = property_pool->register_particle(); const ArrayView their_properties = particle.get_properties(); const ArrayView my_properties = - property_pool->get_properties(properties); + property_pool->get_properties(property_pool_handle); std::copy(their_properties.begin(), their_properties.end(), my_properties.begin()); } else - properties = PropertyPool::invalid_handle; + property_pool_handle = PropertyPool::invalid_handle; } return *this; } @@ -157,16 +157,17 @@ namespace Particles { if (this != &particle) { - location = particle.location; - reference_location = particle.reference_location; - id = particle.id; - property_pool = particle.property_pool; - properties = particle.properties; + location = particle.location; + reference_location = particle.reference_location; + id = particle.id; + property_pool = particle.property_pool; + property_pool_handle = particle.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 // we still reference here. - particle.properties = PropertyPool::invalid_handle; + particle.property_pool_handle = + PropertyPool::invalid_handle; } return *this; } @@ -177,17 +178,19 @@ namespace Particles Particle::~Particle() { if (property_pool != nullptr && - properties != PropertyPool::invalid_handle) - property_pool->deregister_particle(properties); + property_pool_handle != PropertyPool::invalid_handle) + property_pool->deregister_particle(property_pool_handle); } + + template void Particle::free_properties() { if (property_pool != nullptr && - properties != PropertyPool::invalid_handle) - property_pool->deregister_particle(properties); + property_pool_handle != PropertyPool::invalid_handle) + property_pool->deregister_particle(property_pool_handle); } @@ -213,7 +216,7 @@ namespace Particles if (has_properties()) { const ArrayView particle_properties = - property_pool->get_properties(properties); + property_pool->get_properties(property_pool_handle); for (unsigned int i = 0; i < particle_properties.size(); ++i, ++pdata) *pdata = particle_properties[i]; } @@ -241,7 +244,7 @@ namespace Particles if (has_properties()) { const ArrayView particle_properties = - property_pool->get_properties(properties); + property_pool->get_properties(property_pool_handle); const unsigned int size = particle_properties.size(); for (unsigned int i = 0; i < size; ++i) particle_properties[i] = *pdata++; @@ -261,7 +264,7 @@ namespace Particles if (has_properties()) { const ArrayView particle_properties = - property_pool->get_properties(properties); + property_pool->get_properties(property_pool_handle); size += sizeof(double) * particle_properties.size(); } return size; @@ -277,11 +280,11 @@ namespace Particles Assert(property_pool != nullptr, ExcInternalError()); // If we haven't allocated memory yet, do so now - if (properties == PropertyPool::invalid_handle) - properties = property_pool->register_particle(); + if (property_pool_handle == PropertyPool::invalid_handle) + property_pool_handle = property_pool->register_particle(); const ArrayView property_values = - property_pool->get_properties(properties); + property_pool->get_properties(property_pool_handle); Assert(new_properties.size() == property_values.size(), ExcMessage( @@ -307,17 +310,17 @@ namespace Particles Assert(property_pool != nullptr, ExcInternalError()); // If this particle has no properties yet, allocate and initialize them. - if (properties == PropertyPool::invalid_handle) + if (property_pool_handle == PropertyPool::invalid_handle) { - properties = property_pool->register_particle(); + property_pool_handle = property_pool->register_particle(); ArrayView my_properties = - property_pool->get_properties(properties); + property_pool->get_properties(property_pool_handle); std::fill(my_properties.begin(), my_properties.end(), 0.0); } - return property_pool->get_properties(properties); + return property_pool->get_properties(property_pool_handle); } } // namespace Particles -- 2.39.5