*/
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.
*/
inline void
Particle<dim, spacedim>::set_location(const Point<spacedim> &new_loc)
{
- location = new_loc;
+ property_pool->set_location(property_pool_handle, new_loc);
}
inline const Point<spacedim> &
Particle<dim, spacedim>::get_location() const
{
- return location;
+ return property_pool->get_location(property_pool_handle);
}
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);
}
inline const Point<dim> &
Particle<dim, spacedim>::get_reference_location() const
{
- return reference_location;
+ return property_pool->get_reference_location(property_pool_handle);
}
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();
// 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);
}
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())
{}
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 =
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())
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.
{
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 =
{
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
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())
{