Molecular Dynamics Simulation
1.0
|
Extension of the ParticleContainer
class using a linked cells data structure for improved performance over the direct sum approach.
More...
#include <LinkedCellsContainer.h>
Public Types | |
enum class | BoundaryCondition { OUTFLOW , REFLECTIVE , PERIODIC } |
Boundary type enum for labeling the sides of the domain. More... | |
enum class | BoundarySide { LEFT , RIGHT , BOTTOM , TOP , BACK , FRONT } |
Boundary side enum for labeling the sides of the domain. More... | |
Public Member Functions | |
LinkedCellsContainer (const std::array< double, 3 > &domain_size, double cutoff_radius, const std::array< BoundaryCondition, 6 > &boundary_types={BoundaryCondition::OUTFLOW, BoundaryCondition::OUTFLOW, BoundaryCondition::OUTFLOW, BoundaryCondition::OUTFLOW, BoundaryCondition::OUTFLOW, BoundaryCondition::OUTFLOW}, int n=0) | |
Construct a new Linked Cells Particle Container object. More... | |
void | addParticle (const Particle &p) override |
Adds a particle to the container. More... | |
void | addParticle (Particle &&p) override |
Adds a particle to the container. More... | |
void | prepareForceCalculation () override |
Prepares everything for the force calculations (must be called before applySimpleForces and applyPairwiseForces) More... | |
void | applySimpleForces (const std::vector< std::shared_ptr< SimpleForceSource >> &simple_force_sources) override |
Applies the given simple force sources to the particles. More... | |
void | applyPairwiseForces (const std::vector< std::shared_ptr< PairwiseForceSource >> &force_sources) override |
Applies the given force sources to the particles. More... | |
void | applyTargettedForces (const std::vector< std::shared_ptr< TargettedForceSource >> &targetted_force_sources, double curr_simulation_time) override |
Applies the given targetted force sources to the particles. More... | |
void | reserve (size_t n) override |
Reserves space for n particles. This is useful if the number of particles is known in advance and prevents reallocation of memory for the internal dynamic array of particles, when inserting new particles. More... | |
size_t | size () const override |
Returns the number of particles in the container. More... | |
Particle & | operator[] (int i) override |
Overload of the [] operator to access the particles in the container. More... | |
std::vector< Particle >::iterator | begin () override |
The begin iterator for the internal data structure. More... | |
std::vector< Particle >::iterator | end () override |
The end iterator for the internal data structure. More... | |
std::vector< Particle >::const_iterator | begin () const override |
The begin const iterator for the internal data structure. More... | |
std::vector< Particle >::const_iterator | end () const override |
The end const iterator for the internal data structure. More... | |
const std::vector< Particle > & | getParticles () const override |
Returns a vector of all particles in the container. More... | |
const std::array< double, 3 > & | getDomainSize () const |
Returns the domain size. More... | |
double | getCutoffRadius () const |
Returns the cutoff radius. More... | |
const std::vector< Cell > & | getCells () |
Returns the cells. More... | |
const std::vector< Cell * > & | getBoundaryCells () const |
Returns the pointers of the boundary cells. More... | |
const std::array< double, 3 > & | getCellSize () const |
Returns the cell size. More... | |
const std::array< int, 3 > & | getDomainNumCells () const |
Returns the number of cells in each dimension. More... | |
int | cellCoordToCellIndex (int cx, int cy, int cz) const |
Maps the cell coordinates to the corresponding index in the internal cell vector. More... | |
Cell * | particlePosToCell (const std::array< double, 3 > &pos) |
Maps the particle position to the corresponding cell index in the internal cell vector. More... | |
Cell * | particlePosToCell (double x, double y, double z) |
Maps the particle position to the corresponding cell index in the internal cell vector. More... | |
Public Member Functions inherited from ParticleContainer | |
virtual | ~ParticleContainer ()=default |
Virtual destructor for correct deconstruction of inheriting classes. More... | |
Static Public Member Functions | |
static std::string | boundaryConditionToString (const BoundaryCondition &bc) |
Returns a string description of a boundary condition. More... | |
Private Member Functions | |
void | initCells () |
Populates the cell vector and sets the cells types. More... | |
void | initCellNeighbourReferences () |
Sets the neighbour references for each cell in the cell vector. More... | |
void | initIterationOrders () |
Sets the iteration orders for parallel execution. More... | |
void | updateCellsParticleReferences () |
Updates the particle references in the cells. This is necessary after a reallocation of the internal particle vector. More... | |
void | deleteHaloParticles () |
Removes all particles in the halo cells from the particles vector. ATTENTION: A particle reference update must be triggered manually after this operation! More... | |
Private Attributes | |
std::vector< std::vector< Cell * > > | iteration_orders |
std::vector< Particle > | particles |
Internal data structure for the particles. More... | |
std::array< double, 3 > | domain_size |
Domain size in each dimension. More... | |
double | cutoff_radius |
Cutoff radius for the force calculation. More... | |
std::array< BoundaryCondition, 6 > | boundary_types |
The boundary types for each side of the domain (order in array: left, right, bottom, top, back, front) More... | |
std::array< double, 3 > | cell_size |
Cell size in each dimension. More... | |
std::array< int, 3 > | domain_num_cells |
Number of cells in each dimension. More... | |
std::vector< Cell > | cells |
Internal data structure for the cells. More... | |
std::vector< Cell * > | domain_cell_references |
References to the domain cells. More... | |
std::vector< Cell * > | boundary_cell_references |
References to the boundary cells. More... | |
std::vector< Cell * > | halo_cell_references |
References to the halo cells. More... | |
std::vector< Cell * > | left_boundary_cell_references |
References to the boundary cells on the left (x = 0) More... | |
std::vector< Cell * > | right_boundary_cell_references |
References to the boundary cells on the right (x = domain_num_cells[0]-1) More... | |
std::vector< Cell * > | bottom_boundary_cell_references |
References to the boundary cells on the bottom (y = 0) More... | |
std::vector< Cell * > | top_boundary_cell_references |
References to the boundary cells on the top (y = domain_num_cells[1]-1) More... | |
std::vector< Cell * > | back_boundary_cell_references |
References to the boundary cells on the back (z = 0) More... | |
std::vector< Cell * > | front_boundary_cell_references |
References to the boundary cells on the front (z = domain_num_cells[2]-1) More... | |
std::vector< Cell * > | left_halo_cell_references |
References to the halo cells on the left (x = -1) More... | |
std::vector< Cell * > | right_halo_cell_references |
References to the halo cells on the right (x = domain_num_cells[0]) More... | |
std::vector< Cell * > | bottom_halo_cell_references |
References to the halo cells on the bottom (y = -1) More... | |
std::vector< Cell * > | top_halo_cell_references |
References to the halo cells on the top (y = domain_num_cells[1]) More... | |
std::vector< Cell * > | back_halo_cell_references |
References to the halo cells on the back (z = -1) More... | |
std::vector< Cell * > | front_halo_cell_references |
References to the halo cells on the front (z = domain_num_cells[2]) More... | |
Friends | |
class | ReflectiveBoundaryType |
Friend class to allow access to the internal data structures. More... | |
class | OutflowBoundaryType |
Friend class to allow access to the internal data structures. More... | |
class | PeriodicBoundaryType |
Friend class to allow access to the internal data structures. More... | |
Extension of the ParticleContainer
class using a linked cells data structure for improved performance over the direct sum approach.
Definition at line 14 of file LinkedCellsContainer.h.
|
strong |
Boundary type enum for labeling the sides of the domain.
Enumerator | |
---|---|
OUTFLOW | |
REFLECTIVE | |
PERIODIC |
Definition at line 21 of file LinkedCellsContainer.h.
|
strong |
Boundary side enum for labeling the sides of the domain.
Enumerator | |
---|---|
LEFT | |
RIGHT | |
BOTTOM | |
TOP | |
BACK | |
FRONT |
Definition at line 26 of file LinkedCellsContainer.h.
LinkedCellsContainer::LinkedCellsContainer | ( | const std::array< double, 3 > & | domain_size, |
double | cutoff_radius, | ||
const std::array< BoundaryCondition, 6 > & | boundary_types = {BoundaryCondition::OUTFLOW, BoundaryCondition::OUTFLOW, BoundaryCondition::OUTFLOW, BoundaryCondition::OUTFLOW, BoundaryCondition::OUTFLOW, BoundaryCondition::OUTFLOW} , |
||
int | n = 0 |
||
) |
Construct a new Linked Cells Particle Container object.
domain_size | the size of the domain |
cutoff_radius | the cutoff radius for the force calculation |
boundary_types | the boundary types for each side of the domain (order in array: left, right, bottom, top, back, front) |
n | the expected number of particles (for preallocation of memory) |
Constructs a new Linked Cells Particle Container object using the specified domain size and cutoff radius. The expected number of particles is used to preallocate memory for the particle vector, which is highly recommended for known amounts of particles (improves performance as no std::vector resize is needed on inserts). The origin (left lower front corner of the boundary) is assumed to be at (0, 0, 0). The cutoff radius is used to determine the number of cells in each dimension, where the cell size is bigger or equal then the cutoff radius but adjusted to divide the domain size evenly into a whole number of cells. Ideally the domain size is a multiple of the cutoff and cube shaped. Internally, the domain is extended by one cell in each direction to allow for so called 'ghost' or 'halo' cells that are used for boundary condition handling. Therefore the valid cell coordinates range from -1 to domain_num_cells[i] in each dimension (i = 0 -> x; i = 1 -> y; i = 2 -> z).
Definition at line 18 of file LinkedCellsContainer.cpp.
|
overridevirtual |
Adds a particle to the container.
p | Particle to be added |
Adds a particle to the container and correctly inserts it into the cell structure.
Implements ParticleContainer.
Definition at line 50 of file LinkedCellsContainer.cpp.
|
overridevirtual |
Adds a particle to the container.
p | Particle to be added |
Adds a particle to the container and correctly inserts it into the cell structure.
Implements ParticleContainer.
Definition at line 72 of file LinkedCellsContainer.cpp.
|
overridevirtual |
Applies the given force sources to the particles.
force_sources | List of force sources to be applied |
Applies the given force sources to the particles in the container. Uses newton's third law to calculate the forces between the particles in an optimized way. Additionally to the functionality of the ParticleContainer
class, this method uses the internal cell structure to reduce the number of force calculations necessary, depending on the cutoff radius.
Implements ParticleContainer.
Definition at line 117 of file LinkedCellsContainer.cpp.
|
overridevirtual |
Applies the given simple force sources to the particles.
simple_force_sources | List of simple force sources to be applied |
Applies the given simple force sources to the particles in the container.
Implements ParticleContainer.
Definition at line 108 of file LinkedCellsContainer.cpp.
|
overridevirtual |
Applies the given targetted force sources to the particles.
targetted_force_sources | List of targetted force sources to be applied |
curr_simulation_time | Current simulation time |
Applies the given targetted force sources to the particles in the container.
Implements ParticleContainer.
Definition at line 173 of file LinkedCellsContainer.cpp.
|
overridevirtual |
The begin const iterator for the internal data structure.
Implements ParticleContainer.
Definition at line 199 of file LinkedCellsContainer.cpp.
|
overridevirtual |
The begin iterator for the internal data structure.
Implements ParticleContainer.
Definition at line 195 of file LinkedCellsContainer.cpp.
|
static |
Returns a string description of a boundary condition.
Definition at line 240 of file LinkedCellsContainer.cpp.
int LinkedCellsContainer::cellCoordToCellIndex | ( | int | cx, |
int | cy, | ||
int | cz | ||
) | const |
Maps the cell coordinates to the corresponding index in the internal cell vector.
cx | x coordinate of the cell (valid range: -1 to domain_num_cells[0]) |
cy | y coordinate of the cell (valid range: -1 to domain_num_cells[1]) |
cz | z coordinate of the cell (valid range: -1 to domain_num_cells[2]) |
Definition at line 217 of file LinkedCellsContainer.cpp.
|
private |
Removes all particles in the halo cells from the particles vector. ATTENTION: A particle reference update must be triggered manually after this operation!
Definition at line 410 of file LinkedCellsContainer.cpp.
|
overridevirtual |
The end const iterator for the internal data structure.
Implements ParticleContainer.
Definition at line 201 of file LinkedCellsContainer.cpp.
|
overridevirtual |
The end iterator for the internal data structure.
Implements ParticleContainer.
Definition at line 197 of file LinkedCellsContainer.cpp.
const std::vector< Cell * > & LinkedCellsContainer::getBoundaryCells | ( | ) | const |
Returns the pointers of the boundary cells.
Returns the pointers of the boundary cells in a vector.
Definition at line 211 of file LinkedCellsContainer.cpp.
const std::vector< Cell > & LinkedCellsContainer::getCells | ( | ) |
Returns the cells.
Returns the cells as a vector of Cell
objects.
Definition at line 209 of file LinkedCellsContainer.cpp.
const std::array< double, 3 > & LinkedCellsContainer::getCellSize | ( | ) | const |
Returns the cell size.
Returns the cell size as a 3D array.
Definition at line 213 of file LinkedCellsContainer.cpp.
double LinkedCellsContainer::getCutoffRadius | ( | ) | const |
Returns the cutoff radius.
Returns the cutoff radius used for the force calculation.
Definition at line 207 of file LinkedCellsContainer.cpp.
const std::array< int, 3 > & LinkedCellsContainer::getDomainNumCells | ( | ) | const |
Returns the number of cells in each dimension.
Returns the number of cells in each dimension as a 3D array.
Definition at line 215 of file LinkedCellsContainer.cpp.
const std::array< double, 3 > & LinkedCellsContainer::getDomainSize | ( | ) | const |
Returns the domain size.
Returns the domain size as a 3D array.
Definition at line 205 of file LinkedCellsContainer.cpp.
|
overridevirtual |
Returns a vector of all particles in the container.
Implements ParticleContainer.
Definition at line 203 of file LinkedCellsContainer.cpp.
|
private |
Sets the neighbour references for each cell in the cell vector.
Definition at line 316 of file LinkedCellsContainer.cpp.
|
private |
Populates the cell vector and sets the cells types.
Definition at line 257 of file LinkedCellsContainer.cpp.
|
private |
Sets the iteration orders for parallel execution.
Definition at line 347 of file LinkedCellsContainer.cpp.
|
overridevirtual |
Overload of the [] operator to access the particles in the container.
i | Index of the particle |
Implements ParticleContainer.
Definition at line 193 of file LinkedCellsContainer.cpp.
Cell * LinkedCellsContainer::particlePosToCell | ( | const std::array< double, 3 > & | pos | ) |
Maps the particle position to the corresponding cell index in the internal cell vector.
pos | Position of the particle |
Definition at line 224 of file LinkedCellsContainer.cpp.
Cell * LinkedCellsContainer::particlePosToCell | ( | double | x, |
double | y, | ||
double | z | ||
) |
Maps the particle position to the corresponding cell index in the internal cell vector.
x | x coordinate of the particle |
y | y coordinate of the particle |
z | z coordinate of the particle |
Definition at line 226 of file LinkedCellsContainer.cpp.
|
overridevirtual |
Prepares everything for the force calculations (must be called before applySimpleForces and applyPairwiseForces)
Implements ParticleContainer.
Definition at line 94 of file LinkedCellsContainer.cpp.
|
overridevirtual |
Reserves space for n particles. This is useful if the number of particles is known in advance and prevents reallocation of memory for the internal dynamic array of particles, when inserting new particles.
n | Total amount of particles expected to store in the container |
Implements ParticleContainer.
Definition at line 180 of file LinkedCellsContainer.cpp.
|
overridevirtual |
Returns the number of particles in the container.
Implements ParticleContainer.
Definition at line 191 of file LinkedCellsContainer.cpp.
|
private |
Updates the particle references in the cells. This is necessary after a reallocation of the internal particle vector.
Definition at line 396 of file LinkedCellsContainer.cpp.
|
friend |
Friend class to allow access to the internal data structures.
Definition at line 287 of file LinkedCellsContainer.h.
|
friend |
Friend class to allow access to the internal data structures.
Definition at line 292 of file LinkedCellsContainer.h.
|
friend |
Friend class to allow access to the internal data structures.
Definition at line 282 of file LinkedCellsContainer.h.
|
private |
References to the boundary cells on the back (z = 0)
Definition at line 370 of file LinkedCellsContainer.h.
|
private |
References to the halo cells on the back (z = -1)
Definition at line 402 of file LinkedCellsContainer.h.
|
private |
References to the boundary cells on the bottom (y = 0)
Definition at line 360 of file LinkedCellsContainer.h.
|
private |
References to the halo cells on the bottom (y = -1)
Definition at line 392 of file LinkedCellsContainer.h.
|
private |
References to the boundary cells.
Definition at line 338 of file LinkedCellsContainer.h.
|
private |
The boundary types for each side of the domain (order in array: left, right, bottom, top, back, front)
Definition at line 313 of file LinkedCellsContainer.h.
|
private |
Cell size in each dimension.
Definition at line 318 of file LinkedCellsContainer.h.
|
private |
Internal data structure for the cells.
Definition at line 328 of file LinkedCellsContainer.h.
|
private |
Cutoff radius for the force calculation.
Definition at line 308 of file LinkedCellsContainer.h.
|
private |
References to the domain cells.
Definition at line 333 of file LinkedCellsContainer.h.
|
private |
Number of cells in each dimension.
Definition at line 323 of file LinkedCellsContainer.h.
|
private |
Domain size in each dimension.
Definition at line 303 of file LinkedCellsContainer.h.
|
private |
References to the boundary cells on the front (z = domain_num_cells[2]-1)
Definition at line 375 of file LinkedCellsContainer.h.
|
private |
References to the halo cells on the front (z = domain_num_cells[2])
Definition at line 407 of file LinkedCellsContainer.h.
|
private |
References to the halo cells.
Definition at line 343 of file LinkedCellsContainer.h.
|
private |
Definition at line 15 of file LinkedCellsContainer.h.
|
private |
References to the boundary cells on the left (x = 0)
Definition at line 350 of file LinkedCellsContainer.h.
|
private |
References to the halo cells on the left (x = -1)
Definition at line 382 of file LinkedCellsContainer.h.
|
private |
Internal data structure for the particles.
Definition at line 298 of file LinkedCellsContainer.h.
|
private |
References to the boundary cells on the right (x = domain_num_cells[0]-1)
Definition at line 355 of file LinkedCellsContainer.h.
|
private |
References to the halo cells on the right (x = domain_num_cells[0])
Definition at line 387 of file LinkedCellsContainer.h.
|
private |
References to the boundary cells on the top (y = domain_num_cells[1]-1)
Definition at line 365 of file LinkedCellsContainer.h.
|
private |
References to the halo cells on the top (y = domain_num_cells[1])
Definition at line 397 of file LinkedCellsContainer.h.