Reference documentation for deal.II version 9.6.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
Particles::PropertyPool< dim, spacedim > Class Template Reference

#include <deal.II/particles/property_pool.h>

Inheritance diagram for Particles::PropertyPool< dim, spacedim >:

Public Types

using Handle = unsigned int
 

Public Member Functions

 PropertyPool (const unsigned int n_properties_per_slot)
 
 ~PropertyPool ()
 
void clear ()
 
Handle register_particle ()
 
void deregister_particle (Handle &handle)
 
const Point< spacedim > & get_location (const Handle handle) const
 
Point< spacedim > & get_location (const Handle handle)
 
void set_location (const Handle handle, const Point< spacedim > &new_location)
 
const Point< dim > & get_reference_location (const Handle handle) const
 
void set_reference_location (const Handle handle, const Point< dim > &new_reference_location)
 
types::particle_index get_id (const Handle handle) const
 
void set_id (const Handle handle, const types::particle_index &new_id)
 
ArrayView< double, ::MemorySpace::Hostget_properties (const Handle handle)
 
void reserve (const std::size_t size)
 
unsigned int n_properties_per_slot () const
 
unsigned int n_slots () const
 
unsigned int n_registered_slots () const
 
void sort_memory_slots (const std::vector< Handle > &handles_to_sort)
 

Static Public Attributes

static const Handle invalid_handle = static_cast<Handle>(-1)
 

Private Attributes

const unsigned int n_properties
 
std::vector< Point< spacedim > > locations
 
std::vector< Point< dim > > reference_locations
 
std::vector< types::particle_indexids
 
std::vector< double > properties
 
std::vector< Handlecurrently_available_handles
 

Detailed Description

template<int dim, int spacedim = dim>
class Particles::PropertyPool< dim, spacedim >

This class manages a memory space in which all particles associated with a ParticleHandler store their properties. It also stores the locations and reference locations of particles.

The rationale for this class is that because typically every particle stores the same number of properties, and because algorithms generally traverse over all particles doing the same operation on all particles' properties, it is more efficient to let the memory used for properties be handled by a central manager. Particles then do not store a pointer to a memory area in which they store their properties, but instead a "handle" that the PropertyPool class then translates into a pointer to concrete memory.

All this said, the current implementation only provides this kind of interface, but still uses simple new/delete allocation for every set of properties requested by a particle. Additionally, the current implementation assumes the same number of properties per particle, but of course the PropertyType could contain a pointer to dynamically allocated memory with varying sizes per particle (this memory would not be managed by this class).

Definition at line 101 of file property_pool.h.

Member Typedef Documentation

◆ Handle

template<int dim, int spacedim = dim>
using Particles::PropertyPool< dim, spacedim >::Handle = unsigned int

Typedef for the handle that is returned to the particles, and that uniquely identifies the slot of memory that is reserved for this particle.

Definition at line 109 of file property_pool.h.

Constructor & Destructor Documentation

◆ PropertyPool()

template<int dim, int spacedim>
Particles::PropertyPool< dim, spacedim >::PropertyPool ( const unsigned int n_properties_per_slot)

Constructor. Stores the number of properties per reserved slot.

Definition at line 31 of file property_pool.cc.

◆ ~PropertyPool()

template<int dim, int spacedim>
Particles::PropertyPool< dim, spacedim >::~PropertyPool ( )

Destructor. This function ensures that all memory that had previously been allocated using allocate_properties_array() has also been returned via deallocate_properties_array().

Definition at line 39 of file property_pool.cc.

Member Function Documentation

◆ clear()

template<int dim, int spacedim>
void Particles::PropertyPool< dim, spacedim >::clear ( )

Clear the dynamic memory allocated by this class. This function ensures that all memory that had previously been allocated using allocate_properties_array() has also been returned via deallocate_properties_array().

Definition at line 48 of file property_pool.cc.

◆ register_particle()

template<int dim, int spacedim>
PropertyPool< dim, spacedim >::Handle Particles::PropertyPool< dim, spacedim >::register_particle ( )

Return a new handle that allows a particle to store information such as properties and locations. This also allocates memory in this PropertyPool variable.

Definition at line 82 of file property_pool.cc.

◆ deregister_particle()

template<int dim, int spacedim>
void Particles::PropertyPool< dim, spacedim >::deregister_particle ( Handle & handle)

Return a handle obtained by register_particle() and mark the memory allocated for storing the particle's data as free for re-use.

Definition at line 115 of file property_pool.cc.

◆ get_location() [1/2]

template<int dim, int spacedim>
const Point< spacedim > & Particles::PropertyPool< dim, spacedim >::get_location ( const Handle handle) const
inline

Return a read-only reference to the location of a particle identified by the given handle.

Definition at line 323 of file property_pool.h.

◆ get_location() [2/2]

template<int dim, int spacedim>
Point< spacedim > & Particles::PropertyPool< dim, spacedim >::get_location ( const Handle handle)
inline

Return a writeable reference to the location of a particle identified by the given handle.

Definition at line 346 of file property_pool.h.

◆ set_location()

template<int dim, int spacedim>
void Particles::PropertyPool< dim, spacedim >::set_location ( const Handle handle,
const Point< spacedim > & new_location )
inline

Set the location of a particle identified by the given handle.

Definition at line 369 of file property_pool.h.

◆ get_reference_location()

template<int dim, int spacedim>
const Point< dim > & Particles::PropertyPool< dim, spacedim >::get_reference_location ( const Handle handle) const
inline

Return a read-only reference to the reference location of a particle identified by the given handle.

Definition at line 393 of file property_pool.h.

◆ set_reference_location()

template<int dim, int spacedim>
void Particles::PropertyPool< dim, spacedim >::set_reference_location ( const Handle handle,
const Point< dim > & new_reference_location )
inline

Set the reference location of a particle identified by the given handle.

Definition at line 416 of file property_pool.h.

◆ get_id()

template<int dim, int spacedim>
types::particle_index Particles::PropertyPool< dim, spacedim >::get_id ( const Handle handle) const
inline

Return the ID number of this particle identified by the given handle.

Definition at line 441 of file property_pool.h.

◆ set_id()

template<int dim, int spacedim>
void Particles::PropertyPool< dim, spacedim >::set_id ( const Handle handle,
const types::particle_index & new_id )
inline

Set the ID number of this particle identified by the given handle.

Definition at line 464 of file property_pool.h.

◆ get_properties()

template<int dim, int spacedim = dim>
ArrayView< double, ::MemorySpace::Host > Particles::PropertyPool< dim, spacedim >::get_properties ( const Handle handle)
inline

Return an ArrayView to the properties that correspond to the given handle handle.

Definition at line 206 of file property_pool.h.

◆ reserve()

template<int dim, int spacedim>
void Particles::PropertyPool< dim, spacedim >::reserve ( const std::size_t size)

Reserve the dynamic memory needed for storing the properties of size particles.

Definition at line 149 of file property_pool.cc.

◆ n_properties_per_slot()

template<int dim, int spacedim>
unsigned int Particles::PropertyPool< dim, spacedim >::n_properties_per_slot ( ) const

Return how many properties are stored per slot in the pool.

Definition at line 161 of file property_pool.cc.

◆ n_slots()

template<int dim, int spacedim>
unsigned int Particles::PropertyPool< dim, spacedim >::n_slots ( ) const
inline

Return the total number of slots in the pool, including both registered and unregistered ones.

Definition at line 494 of file property_pool.h.

◆ n_registered_slots()

template<int dim, int spacedim>
unsigned int Particles::PropertyPool< dim, spacedim >::n_registered_slots ( ) const

Return how many slots are currently registered in the pool.

Definition at line 170 of file property_pool.cc.

◆ sort_memory_slots()

template<int dim, int spacedim>
void Particles::PropertyPool< dim, spacedim >::sort_memory_slots ( const std::vector< Handle > & handles_to_sort)

This function makes sure that all internally stored memory blocks are sorted in the same order as one would loop over the handles_to_sort container. This makes sure memory access is contiguous with actual memory location. Because the ordering is given in the input argument the complexity of this function is \(O(N)\) where \(N\) is the number of elements in the input argument.

Definition at line 191 of file property_pool.cc.

Member Data Documentation

◆ invalid_handle

template<int dim, int spacedim>
const PropertyPool< dim, spacedim >::Handle Particles::PropertyPool< dim, spacedim >::invalid_handle = static_cast<Handle>(-1)
static

Define a default (invalid) value for handles.

Definition at line 114 of file property_pool.h.

◆ n_properties

template<int dim, int spacedim = dim>
const unsigned int Particles::PropertyPool< dim, spacedim >::n_properties
private

The number of properties that are reserved per particle.

Definition at line 277 of file property_pool.h.

◆ locations

template<int dim, int spacedim = dim>
std::vector<Point<spacedim> > Particles::PropertyPool< dim, spacedim >::locations
private

A vector that stores the locations of particles. It is indexed in the same way as the reference_locations and properties arrays, i.e., via handles.

Definition at line 284 of file property_pool.h.

◆ reference_locations

template<int dim, int spacedim = dim>
std::vector<Point<dim> > Particles::PropertyPool< dim, spacedim >::reference_locations
private

A vector that stores the reference locations of particles. It is indexed in the same way as the locations and properties arrays, i.e., via handles.

Definition at line 291 of file property_pool.h.

◆ ids

template<int dim, int spacedim = dim>
std::vector<types::particle_index> Particles::PropertyPool< dim, spacedim >::ids
private

A vector that stores the unique identifiers of particles. It is indexed in the same way as the locations and properties arrays, i.e., via handles.

Definition at line 298 of file property_pool.h.

◆ properties

template<int dim, int spacedim = dim>
std::vector<double> Particles::PropertyPool< dim, spacedim >::properties
private

The currently allocated properties (whether assigned to a particle or available for assignment). It is indexed the same way as the locations and reference_locations arrays via handles.

Definition at line 305 of file property_pool.h.

◆ currently_available_handles

template<int dim, int spacedim = dim>
std::vector<Handle> Particles::PropertyPool< dim, spacedim >::currently_available_handles
private

A collection of handles that have been created by allocate_properties_array() and have been destroyed by deallocate_properties_array(). Since the memory is still allocated these handles can be reused for new particles to avoid memory allocation.

Definition at line 314 of file property_pool.h.


The documentation for this class was generated from the following files: