Reference documentation for deal.II version 9.5.0
|
#include <deal.II/particles/property_pool.h>
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 |
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 > | get_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_index > | ids |
std::vector< double > | properties |
std::vector< Handle > | currently_available_handles |
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 102 of file property_pool.h.
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 110 of file property_pool.h.
Particles::PropertyPool< dim, spacedim >::PropertyPool | ( | const unsigned int | n_properties_per_slot | ) |
Constructor. Stores the number of properties per reserved slot.
Definition at line 32 of file property_pool.cc.
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 40 of file property_pool.cc.
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 49 of file property_pool.cc.
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 86 of file property_pool.cc.
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 119 of file property_pool.cc.
|
inline |
Return the location of a particle identified by the given handle
.
Definition at line 288 of file property_pool.h.
|
inline |
Set the location of a particle identified by the given handle
.
Definition at line 311 of file property_pool.h.
|
inline |
Return the reference_location of a particle identified by the given handle
.
Definition at line 335 of file property_pool.h.
|
inline |
Set the reference location of a particle identified by the given handle
.
Definition at line 358 of file property_pool.h.
|
inline |
Return the ID number of this particle identified by the given handle
.
Definition at line 383 of file property_pool.h.
|
inline |
Set the ID number of this particle identified by the given handle
.
Definition at line 406 of file property_pool.h.
|
inline |
Return an ArrayView to the properties that correspond to the given handle handle
.
Definition at line 430 of file property_pool.h.
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 153 of file property_pool.cc.
unsigned int Particles::PropertyPool< dim, spacedim >::n_properties_per_slot |
Return how many properties are stored per slot in the pool.
Definition at line 165 of file property_pool.cc.
|
inline |
Return the total number of slots in the pool, including both registered and unregistered ones.
Definition at line 453 of file property_pool.h.
unsigned int Particles::PropertyPool< dim, spacedim >::n_registered_slots |
Return how many slots are currently registered in the pool.
Definition at line 174 of file property_pool.cc.
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 195 of file property_pool.cc.
|
static |
Define a default (invalid) value for handles.
Definition at line 115 of file property_pool.h.
|
private |
The number of properties that are reserved per particle.
Definition at line 242 of file property_pool.h.
|
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 249 of file property_pool.h.
|
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 256 of file property_pool.h.
|
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 263 of file property_pool.h.
|
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 270 of file property_pool.h.
|
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 279 of file property_pool.h.