* contains serialized data of the same length and type that is allocated
* by @p property_pool.
*/
- Particle(const void *& begin_data,
- PropertyPool *const property_pool = nullptr);
+ Particle(const void *& begin_data,
+ PropertyPool<dim, spacedim> *const property_pool = nullptr);
/**
* Move constructor for Particle, creates a particle from an existing
* allocated in the new property pool.
*/
void
- set_property_pool(PropertyPool &property_pool);
+ set_property_pool(PropertyPool<dim, spacedim> &property_pool);
/**
* Return whether this particle has a valid property pool and a valid
* A pointer to the property pool. Necessary to translate from the
* handle to the actual memory locations.
*/
- PropertyPool *property_pool;
+ PropertyPool<dim, spacedim> *property_pool;
/**
* A handle to all particle properties
*/
- PropertyPool::Handle properties;
+ typename PropertyPool<dim, spacedim>::Handle properties;
};
/* ---------------------- inline and template functions ------------------ */
{
unsigned int n_properties = 0;
if ((property_pool != nullptr) &&
- (properties != PropertyPool::invalid_handle))
+ (properties != PropertyPool<dim, spacedim>::invalid_handle))
n_properties = get_properties().size();
ar &location &reference_location &id &n_properties;
template <int dim, int spacedim>
inline void
- Particle<dim, spacedim>::set_property_pool(PropertyPool &new_property_pool)
+ Particle<dim, spacedim>::set_property_pool(
+ PropertyPool<dim, spacedim> &new_property_pool)
{
// First, we do want to save any properties that may
// have previously been set, and copy them over to the memory allocated
// on the new pool
- PropertyPool::Handle new_handle = PropertyPool::invalid_handle;
- if (property_pool != nullptr && properties != PropertyPool::invalid_handle)
+ typename PropertyPool<dim, spacedim>::Handle new_handle =
+ PropertyPool<dim, spacedim>::invalid_handle;
+ if (property_pool != nullptr &&
+ properties != PropertyPool<dim, spacedim>::invalid_handle)
{
new_handle = new_property_pool.allocate_properties_array();
// If the particle currently has a reference to properties, then
// release those.
- if (property_pool != nullptr && properties != PropertyPool::invalid_handle)
+ if (property_pool != nullptr &&
+ properties != PropertyPool<dim, spacedim>::invalid_handle)
property_pool->deallocate_properties_array(properties);
Particle<dim, spacedim>::has_properties() const
{
return (property_pool != nullptr) &&
- (properties != PropertyPool::invalid_handle);
+ (properties != PropertyPool<dim, spacedim>::invalid_handle);
}
} // namespace Particles
* function is after particle transfer to a new process.
*/
void
- set_property_pool(PropertyPool &property_pool);
+ set_property_pool(PropertyPool<dim, spacedim> &property_pool);
/**
* Return whether this particle has a valid property pool and a valid
template <int dim, int spacedim>
inline void
ParticleAccessor<dim, spacedim>::set_property_pool(
- PropertyPool &new_property_pool)
+ PropertyPool<dim, spacedim> &new_property_pool)
{
Assert(particle != map->end(), ExcInternalError());
* Return a reference to the property pool that owns all particle
* properties, and organizes them physically.
*/
- PropertyPool &
+ PropertyPool<dim, spacedim> &
get_property_pool() const;
/**
* precedes the declaration of the `particles` and `ghost_particles`
* members.
*/
- std::unique_ptr<PropertyPool> property_pool;
+ std::unique_ptr<PropertyPool<dim, spacedim>> property_pool;
/**
* Set of particles currently living in the local domain, organized by
* memory with varying sizes per particle (this memory would not be managed by
* this class).
*/
+ template <int dim, int spacedim = dim>
class PropertyPool
{
public:
std::vector<Handle> currently_available_handles;
};
+
+
/* ---------------------- inline and template functions ------------------ */
+ template <int dim, int spacedim>
inline ArrayView<double>
- PropertyPool::get_properties(const Handle handle)
+ PropertyPool<dim, spacedim>::get_properties(const Handle handle)
{
const std::vector<double>::size_type data_index =
(handle != invalid_handle) ? handle * n_properties : 0;
, reference_location(numbers::signaling_nan<Point<dim>>())
, id(0)
, property_pool(nullptr)
- , properties(PropertyPool::invalid_handle)
+ , properties(PropertyPool<dim, spacedim>::invalid_handle)
{}
, reference_location(reference_location)
, id(id)
, property_pool(nullptr)
- , properties(PropertyPool::invalid_handle)
+ , properties(PropertyPool<dim, spacedim>::invalid_handle)
{}
, reference_location(particle.get_reference_location())
, id(particle.get_id())
, property_pool(particle.property_pool)
- , properties(PropertyPool::invalid_handle)
+ , properties(PropertyPool<dim, spacedim>::invalid_handle)
{
if (particle.has_properties())
{
template <int dim, int spacedim>
- Particle<dim, spacedim>::Particle(const void *& data,
- PropertyPool *const new_property_pool)
+ Particle<dim, spacedim>::Particle(
+ const void *& data,
+ PropertyPool<dim, spacedim> *const new_property_pool)
{
const types::particle_index *id_data =
static_cast<const types::particle_index *>(data);
if (property_pool != nullptr)
properties = property_pool->allocate_properties_array();
else
- properties = PropertyPool::invalid_handle;
+ properties = PropertyPool<dim, spacedim>::invalid_handle;
// See if there are properties to load
if (has_properties())
, property_pool(std::move(particle.property_pool))
, properties(std::move(particle.properties))
{
- particle.properties = PropertyPool::invalid_handle;
+ particle.properties = PropertyPool<dim, spacedim>::invalid_handle;
}
my_properties.begin());
}
else
- properties = PropertyPool::invalid_handle;
+ properties = PropertyPool<dim, spacedim>::invalid_handle;
}
return *this;
}
// 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.properties = PropertyPool<dim, spacedim>::invalid_handle;
}
return *this;
}
template <int dim, int spacedim>
Particle<dim, spacedim>::~Particle()
{
- if (property_pool != nullptr && properties != PropertyPool::invalid_handle)
+ if (property_pool != nullptr &&
+ properties != PropertyPool<dim, spacedim>::invalid_handle)
property_pool->deallocate_properties_array(properties);
}
void
Particle<dim, spacedim>::free_properties()
{
- if (property_pool != nullptr && properties != PropertyPool::invalid_handle)
+ if (property_pool != nullptr &&
+ properties != PropertyPool<dim, spacedim>::invalid_handle)
property_pool->deallocate_properties_array(properties);
}
Assert(property_pool != nullptr, ExcInternalError());
// If we haven't allocated memory yet, do so now
- if (properties == PropertyPool::invalid_handle)
+ if (properties == PropertyPool<dim, spacedim>::invalid_handle)
properties = property_pool->allocate_properties_array();
const ArrayView<double> property_values =
Assert(property_pool != nullptr, ExcInternalError());
// If this particle has no properties yet, allocate and initialize them.
- if (properties == PropertyPool::invalid_handle)
+ if (properties == PropertyPool<dim, spacedim>::invalid_handle)
{
properties = property_pool->allocate_properties_array();
std::vector<Particle<dim, spacedim>>
unpack_particles(
const boost::iterator_range<std::vector<char>::const_iterator>
- & data_range,
- PropertyPool &property_pool)
+ & data_range,
+ PropertyPool<dim, spacedim> &property_pool)
{
std::vector<Particle<dim, spacedim>> particles;
ParticleHandler<dim, spacedim>::ParticleHandler()
: triangulation()
, mapping()
- , property_pool(std::make_unique<PropertyPool>(0))
+ , property_pool(std::make_unique<PropertyPool<dim, spacedim>>(0))
, particles()
, ghost_particles()
, global_number_of_particles(0)
const unsigned int n_properties)
: triangulation(&triangulation, typeid(*this).name())
, mapping(&mapping, typeid(*this).name())
- , property_pool(std::make_unique<PropertyPool>(n_properties))
+ , property_pool(std::make_unique<PropertyPool<dim, spacedim>>(n_properties))
, particles()
, ghost_particles()
, global_number_of_particles(0)
mapping = &new_mapping;
// Create the memory pool that will store all particle properties
- property_pool = std::make_unique<PropertyPool>(n_properties);
+ property_pool = std::make_unique<PropertyPool<dim, spacedim>>(n_properties);
// Create the grid cache to cache the information about the triangulation
// that is used to locate the particles into subdomains and cells
template <int dim, int spacedim>
- PropertyPool &
+ PropertyPool<dim, spacedim> &
ParticleHandler<dim, spacedim>::get_property_pool() const
{
return *property_pool;
namespace Particles
{
- const PropertyPool::Handle PropertyPool::invalid_handle =
- static_cast<Handle>(-1);
+ template <int dim, int spacedim>
+ const typename PropertyPool<dim, spacedim>::Handle
+ PropertyPool<dim, spacedim>::invalid_handle = static_cast<Handle>(-1);
- PropertyPool::PropertyPool(const unsigned int n_properties_per_slot)
+
+ template <int dim, int spacedim>
+ PropertyPool<dim, spacedim>::PropertyPool(
+ const unsigned int n_properties_per_slot)
: n_properties(n_properties_per_slot)
{}
- PropertyPool::~PropertyPool()
+
+ template <int dim, int spacedim>
+ PropertyPool<dim, spacedim>::~PropertyPool()
{
clear();
}
+ template <int dim, int spacedim>
void
- PropertyPool::clear()
+ PropertyPool<dim, spacedim>::clear()
{
if (n_properties > 0)
{
- PropertyPool::Handle
- PropertyPool::allocate_properties_array()
+ template <int dim, int spacedim>
+ typename PropertyPool<dim, spacedim>::Handle
+ PropertyPool<dim, spacedim>::allocate_properties_array()
{
Handle handle = invalid_handle;
if (n_properties > 0)
+ template <int dim, int spacedim>
void
- PropertyPool::deallocate_properties_array(Handle &handle)
+ PropertyPool<dim, spacedim>::deallocate_properties_array(Handle &handle)
{
Assert(
handle != invalid_handle,
+ template <int dim, int spacedim>
void
- PropertyPool::reserve(const std::size_t size)
+ PropertyPool<dim, spacedim>::reserve(const std::size_t size)
{
properties.reserve(size * n_properties);
}
+ template <int dim, int spacedim>
unsigned int
- PropertyPool::n_properties_per_slot() const
+ PropertyPool<dim, spacedim>::n_properties_per_slot() const
{
return n_properties;
}
+
+
+ // Instantiate the class for all reasonable template arguments
+ template class PropertyPool<1, 1>;
+ template class PropertyPool<1, 2>;
+ template class PropertyPool<1, 3>;
+ template class PropertyPool<2, 2>;
+ template class PropertyPool<2, 3>;
+ template class PropertyPool<3, 3>;
} // namespace Particles
DEAL_II_NAMESPACE_CLOSE