From: Rene Gassmoeller Date: Mon, 19 Feb 2024 21:32:30 +0000 (-0500) Subject: Add writeable particle location reference X-Git-Tag: relicensing~9^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70b8ace7fb61156aadb271d8901a799808091157;p=dealii.git Add writeable particle location reference --- diff --git a/include/deal.II/particles/particle.h b/include/deal.II/particles/particle.h index 776969dd99..600d671293 100644 --- a/include/deal.II/particles/particle.h +++ b/include/deal.II/particles/particle.h @@ -250,6 +250,14 @@ namespace Particles const Point & get_location() const; + /** + * Get the location of this particle. + * + * @return The location of this particle. + */ + Point & + get_location(); + /** * Set the reference location of this particle. * @@ -279,6 +287,12 @@ namespace Particles const Point & get_reference_location() const; + /** + * Return the reference location of this particle in its current cell. + */ + Point & + get_reference_location(); + /** * Return the ID number of this particle. The ID of a particle is intended * to be a property that is globally unique even in parallel computations @@ -537,6 +551,15 @@ namespace Particles + template + inline Point & + Particle::get_location() + { + return property_pool->get_location(property_pool_handle); + } + + + template inline void Particle::set_reference_location(const Point &new_loc) @@ -555,6 +578,15 @@ namespace Particles + template + inline Point & + Particle::get_reference_location() + { + return property_pool->get_reference_location(property_pool_handle); + } + + + template inline types::particle_index Particle::get_id() const diff --git a/include/deal.II/particles/particle_accessor.h b/include/deal.II/particles/particle_accessor.h index 67f3097842..1bce933fe6 100644 --- a/include/deal.II/particles/particle_accessor.h +++ b/include/deal.II/particles/particle_accessor.h @@ -156,6 +156,14 @@ namespace Particles const Point & get_location() const; + /** + * Get the location of this particle. + * + * @return The location of this particle. + */ + Point & + get_location(); + /** * Set the reference location of this particle. * @@ -185,6 +193,12 @@ namespace Particles const Point & get_reference_location() const; + /** + * Return the reference location of this particle in its current cell. + */ + Point & + get_reference_location(); + /** * Set the ID number of this particle. */ @@ -650,6 +664,17 @@ namespace Particles + template + inline Point & + ParticleAccessor::get_location() + { + Assert(state() == IteratorState::valid, ExcInternalError()); + + return property_pool->get_location(get_handle()); + } + + + template inline void ParticleAccessor::set_reference_location( @@ -673,6 +698,17 @@ namespace Particles + template + inline Point & + ParticleAccessor::get_reference_location() + { + Assert(state() == IteratorState::valid, ExcInternalError()); + + return property_pool->get_reference_location(get_handle()); + } + + + template inline types::particle_index ParticleAccessor::get_id() const diff --git a/include/deal.II/particles/property_pool.h b/include/deal.II/particles/property_pool.h index 5d3fd350a9..7131149956 100644 --- a/include/deal.II/particles/property_pool.h +++ b/include/deal.II/particles/property_pool.h @@ -151,11 +151,19 @@ namespace Particles deregister_particle(Handle &handle); /** - * Return the location of a particle identified by the given `handle`. + * Return a read-only reference to the location of a particle + * identified by the given `handle`. */ const Point & get_location(const Handle handle) const; + /** + * Return a writeable reference to the location of a particle + * identified by the given `handle`. + */ + Point & + get_location(const Handle handle); + /** * Set the location of a particle identified by the given `handle`. */ @@ -163,12 +171,19 @@ namespace Particles set_location(const Handle handle, const Point &new_location); /** - * Return the reference_location of a particle identified by the given - * `handle`. + * Return a read-only reference to the reference location of a particle + * identified by the given `handle`. */ const Point & get_reference_location(const Handle handle) const; + /** + * Return a writeable reference to the reference location of a particle + * identified by the given `handle`. + */ + Point & + get_reference_location(const Handle handle); + /** * Set the reference location of a particle identified by the given * `handle`. @@ -306,6 +321,29 @@ namespace Particles + template + inline Point & + PropertyPool::get_location(const Handle handle) + { + const std::vector::size_type data_index = + (handle != invalid_handle) ? handle : 0; + + // Ideally we would need to assert that 'handle' has not been deallocated + // by searching through 'currently_available_handles'. However, this + // is expensive and this function is performance critical, so instead + // just check against the array range, and rely on the fact + // that handles are invalidated when handed over to + // deallocate_properties_array(). + Assert(data_index <= locations.size() - 1, + ExcMessage("Invalid location handle. This can happen if the " + "handle was duplicated and then one copy was deallocated " + "before trying to access the properties.")); + + return locations[data_index]; + } + + + template inline void PropertyPool::set_location(const Handle handle, @@ -353,6 +391,29 @@ namespace Particles + template + inline Point & + PropertyPool::get_reference_location(const Handle handle) + { + const std::vector::size_type data_index = + (handle != invalid_handle) ? handle : 0; + + // Ideally we would need to assert that 'handle' has not been deallocated + // by searching through 'currently_available_handles'. However, this + // is expensive and this function is performance critical, so instead + // just check against the array range, and rely on the fact + // that handles are invalidated when handed over to + // deallocate_properties_array(). + Assert(data_index <= reference_locations.size() - 1, + ExcMessage("Invalid location handle. This can happen if the " + "handle was duplicated and then one copy was deallocated " + "before trying to access the properties.")); + + return reference_locations[data_index]; + } + + + template inline void PropertyPool::set_reference_location(