deal.II version GIT relicensing-2287-g6548a49e0a 2024-12-20 18:30:00+00:00
|
#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 |
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::Host > | 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 101 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 109 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 31 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 39 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 48 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 82 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 115 of file property_pool.cc.
|
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.
|
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.
|
inline |
Set the location of a particle identified by the given handle
.
Definition at line 369 of file property_pool.h.
|
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.
|
inline |
Set the reference location of a particle identified by the given handle
.
Definition at line 416 of file property_pool.h.
|
inline |
Return the ID number of this particle identified by the given handle
.
Definition at line 441 of file property_pool.h.
|
inline |
Set the ID number of this particle identified by the given handle
.
Definition at line 464 of file property_pool.h.
|
inline |
Return an ArrayView to the properties that correspond to the given handle handle
.
Definition at line 206 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 149 of file property_pool.cc.
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.
|
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.
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.
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.
|
static |
Define a default (invalid) value for handles.
Definition at line 114 of file property_pool.h.
|
private |
The number of properties that are reserved per particle.
Definition at line 277 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 284 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 291 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 298 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 305 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 314 of file property_pool.h.