MolSim
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Types | Private Attributes | List of all members
CellContainer Class Reference

Cell encapsulation class for implementing the linked cell method. More...

#include <CellContainer.h>

Classes

class  SpecialParticleIterator
 A special iterator for iterating over the boundary and halo cell containers. More...
 

Public Member Functions

 CellContainer (const std::array< double, 3 > &domainSize, const std::array< BoundaryCondition, 6 > &conditions, double cutoff, ParticleContainer &particles, size_t dim=3)
 Constructs a new CellContainer and initializes all Cell objects and locks.
 
 ~CellContainer ()
 Destroys the CellContainer object and frees the reserved locks.
 
ContainerType::iterator begin ()
 Standard library iterator function for marking the beginning of the iteration process.
 
ContainerType::iterator end ()
 Standard library iterator function for marking the end of the iteration process.
 
ParticleContainer::PairIterator beginPairs ()
 Direct access to the beginning of the ParticleContainer's PairIterator.
 
ParticleContainer::PairIterator endPairs ()
 Direct access to the end of the ParticleContainer's PairIterator.
 
ContainerType::const_iterator begin () const
 Standard library iterator function for marking the beginning of the iteration process of a const CellContainer.
 
ContainerType::const_iterator end () const
 Standard library iterator function for marking the end of the iteration process of a const CellContainer.
 
SpecialParticleIterator boundaryBegin ()
 Gets a SpecialParticleIterator pointing to the beginning of the boundary Cell pointer container.
 
SpecialParticleIterator boundaryEnd ()
 Gets a SpecialParticleIterator pointing to the end of the boundary Cell pointer container.
 
SpecialParticleIterator haloBegin ()
 Gets a SpecialParticleIterator pointing to the beginning of the halo Cell pointer container.
 
SpecialParticleIterator haloEnd ()
 Gets a SpecialParticleIterator pointing to the end of the halo Cell pointer container.
 
Celloperator[] (size_t index)
 Dereference of the [] operator.
 
const Celloperator[] (size_t index) const
 Dereference of the [] operator (const).
 
std::vector< Cell > & getCells ()
 Gets a reference to the Cell container.
 
const std::vector< Cell > & getCells () const
 Gets a const reference to the Cell container.
 
std::vector< std::reference_wrapper< Cell > > & getBorderCells ()
 Gets a reference to the border Cell container.
 
const std::vector< std::reference_wrapper< Cell > > & getBorderCells () const
 Gets a const reference to the border Cell container.
 
std::vector< std::reference_wrapper< Cell > > & getHaloCells ()
 Gets a reference to the halo Cell container.
 
const std::vector< std::reference_wrapper< Cell > > & getHaloCells () const
 Gets a const reference to the halo Cell container.
 
std::vector< std::reference_wrapper< Cell > > & getIterableCells ()
 Gets a reference to the iterable Cell container.
 
const std::vector< std::reference_wrapper< Cell > > & getIterableCells () const
 Gets a const reference to the iterable Cell container.
 
void removeHaloCellParticles ()
 Removes the active halo Cell Particle objects.
 
int getCellIndex (const std::array< double, 3 > &position)
 Gets the 1D index in the Cell container based on the given position.
 
void deleteParticle (Particle &p)
 Removes a Particle from a Cell and marks it inactive.
 
bool addParticle (Particle &p)
 Adds a Particle to the Cell container.
 
bool moveParticle (Particle &p)
 Moves a particle from one Cell to another.
 
std::array< int, 3 > getVirtualCellCoordinates (int index) const
 Gets the coordinates of a Cell from its index.
 
std::array< double, 3 > getMirrorPosition (const std::array< double, 3 > &position, const Cell &from, const Cell &to, int direction) const
 Mirrors a position from a source Cell to a destination Cell.
 
int getOppositeNeighbor (int cellIndex, HaloLocation direction) const
 Gets the index of the opposing Cell in the specified direction.
 
void calculateNeighbors (int cellIndex)
 Computes the vector of neighbouring Cell indices, including the Cell itself.
 
const std::vector< int > & getNeighbors (int cellIndex) const
 Gets a vector of neighbouring Cell indices, including the Cell itself.
 
std::vector< std::reference_wrapper< Cell > > getNeighborCells (int cellIndex)
 
int getOppositeOfHalo (const Cell &from, HaloLocation location)
 For a halo cell returns the index of the border cell on the opposite side of the domain.
 
int getOppositeOfBorder (const Cell &from, BorderLocation location)
 For a border cell returns the index of the halo cell on the opposite side of the domain.
 
std::vector< int > getOppositeOfBorderCorner (const Cell &from, std::vector< BorderLocation > &locations)
 For a border cell returns the indices of the corner cells on the opposite sides of the domain.
 
std::vector< std::vector< BorderLocation > > getBorderCombinations (std::vector< BorderLocation > &locations)
 For a collection of border locations, returns all unique pairs.
 
const std::array< double, 3 > & getDomainSize () const
 Gets a const reference to the CellContainer's domain size.
 
const std::array< double, 3 > & getCellSize () const
 Gets a const reference to the CellContainer's cell size.
 
const std::array< size_t, 3 > & getNumCells () const
 Gets a const reference to the CellContainer's cell count in each dimension.
 
const std::array< BoundaryCondition, 6 > & getConditions () const
 Gets the boundary conditions at each boundary.
 
double getCutoff () const
 Gets the cutoff radius used for calculating the cell size.
 
size_t getDim () const
 Gets the number of dimensions of the linked cells.
 
bool getAnyPeriodic () const
 Checks if any boundary condition is periodic.
 
ParticleContainergetParticles ()
 Gets a reference to the primary ParticleContainer.
 
const ParticleContainergetParticles () const
 Gets a const reference to the primary ParticleContainer.
 
size_t size () const
 Gets the size of the ParticleContainer, including all inactive Cells.
 
size_t activeSize () const
 Gets the amount of active Particle objects in the ParticleContainer.
 
void printCellIndices () const
 Debug function to print the indices of all cells for a 2D container.
 
void printCellContents () const
 Debug function to print the contents of each cell.
 

Private Types

using ContainerType = std::vector< Cell >
 Typedef for the underlying Cell container type.
 

Private Attributes

ContainerType cells
 The container of Cell objects itself.
 
std::vector< omp_lock_tcellLocks
 Container of mutual exclusion locks for each cell.
 
std::vector< std::reference_wrapper< Cell > > borderCells
 Container of references to border cells.
 
std::vector< std::reference_wrapper< Cell > > haloCells
 Container of references to halo cells.
 
std::vector< std::reference_wrapper< Cell > > iterableCells
 Container of references to cells to iterate over when calculating the forces between particles.
 
std::array< double, 3 > domainSize
 The size of the domain in each dimension.
 
std::array< double, 3 > cellSize {0, 0, 0}
 The size of each cell in each dimension (default: 0, 0, 0).
 
std::array< size_t, 3 > numCells {1, 1, 1}
 The number of cells in each dimension (default: 1, 1, 1).
 
std::array< BoundaryCondition, 6 > conditions
 An array of boundary conditions to be applied at each boundary (North, South, West, East, Above, Below).
 
double cutoff
 The cutoff radius.
 
size_t dim
 The number of dimensions (2/3)
 
bool anyPeriodic {false}
 Determines if there are any periodic halo cells.
 
ParticleContainerparticles
 A reference to the overarching ParticleContainer.
 

Detailed Description

Cell encapsulation class for implementing the linked cell method.

Member Typedef Documentation

◆ ContainerType

using CellContainer::ContainerType = std::vector<Cell>
private

Typedef for the underlying Cell container type.

Constructor & Destructor Documentation

◆ CellContainer()

CellContainer::CellContainer ( const std::array< double, 3 > &  domainSize,
const std::array< BoundaryCondition, 6 > &  conditions,
double  cutoff,
ParticleContainer particles,
size_t  dim = 3 
)

Constructs a new CellContainer and initializes all Cell objects and locks.

Parameters
domainSizeThe size of the domain.
conditionsThe boundary conditions to be applied at each boundary.
cutoffThe cutoff radius.
particlesThe main ParticleContainer.
dimThe dimension of the container. May either be two- (2) or three-dimensional (3).

◆ ~CellContainer()

CellContainer::~CellContainer ( )

Destroys the CellContainer object and frees the reserved locks.

Member Function Documentation

◆ activeSize()

size_t CellContainer::activeSize ( ) const

Gets the amount of active Particle objects in the ParticleContainer.

Returns
The total number of active Particle objects.

◆ addParticle()

bool CellContainer::addParticle ( Particle p)

Adds a Particle to the Cell container.

The 1D container index is computed from the Particle's current position. If the index is valid, the Particle is added there, otherwise nothing happens.

Parameters
p
Returns
true if the Particle was successfully added.
false if the Particle could not be added.

◆ begin() [1/2]

ContainerType::iterator CellContainer::begin ( )

Standard library iterator function for marking the beginning of the iteration process.

Returns
An iterator pointing to the first element of cells.

◆ begin() [2/2]

ContainerType::const_iterator CellContainer::begin ( ) const

Standard library iterator function for marking the beginning of the iteration process of a const CellContainer.

Returns
An iterator pointing to the first element of cells.

◆ beginPairs()

ParticleContainer::PairIterator CellContainer::beginPairs ( )

Direct access to the beginning of the ParticleContainer's PairIterator.

Use this to iterate over all distinct pairs of Particle objects in the domain.

Returns
The beginning of the ParticleContainer's PairIterator.

◆ boundaryBegin()

SpecialParticleIterator CellContainer::boundaryBegin ( )

Gets a SpecialParticleIterator pointing to the beginning of the boundary Cell pointer container.

Returns
A SpecialParticleIterator pointing to the beginning of the boundary Cell pointer container.

◆ boundaryEnd()

SpecialParticleIterator CellContainer::boundaryEnd ( )

Gets a SpecialParticleIterator pointing to the end of the boundary Cell pointer container.

Returns
A SpecialParticleIterator pointing to the end of the boundary Cell pointer container.

◆ calculateNeighbors()

void CellContainer::calculateNeighbors ( int  cellIndex)

Computes the vector of neighbouring Cell indices, including the Cell itself.

Parameters
cellIndexThe index of the Cell for which the neighbours should be determined.

◆ deleteParticle()

void CellContainer::deleteParticle ( Particle p)

Removes a Particle from a Cell and marks it inactive.

First, the function finds the 1D index of the Particle's Cell. From there, it is removed, then marked as inactive. Note that, in order for this function to work, the Particle must have its correct index stored, and the index must be valid (i.e. not -1).

Parameters
pThe Particle to remove.

◆ end() [1/2]

ContainerType::iterator CellContainer::end ( )

Standard library iterator function for marking the end of the iteration process.

Returns
An iterator pointing to the last element of cells.

◆ end() [2/2]

ContainerType::const_iterator CellContainer::end ( ) const

Standard library iterator function for marking the end of the iteration process of a const CellContainer.

Returns
An iterator pointing to the last element of cells.

◆ endPairs()

ParticleContainer::PairIterator CellContainer::endPairs ( )

Direct access to the end of the ParticleContainer's PairIterator.

Use this to iterate over all distinct pairs of Particle objects in the domain.

Returns
The end of the ParticleContainer's PairIterator.

◆ getAnyPeriodic()

bool CellContainer::getAnyPeriodic ( ) const

Checks if any boundary condition is periodic.

Returns
true if at least one boundary condition is periodic.
false if there are no periodic boundary conditions.

◆ getBorderCells() [1/2]

std::vector< std::reference_wrapper< Cell > > & CellContainer::getBorderCells ( )

Gets a reference to the border Cell container.

Returns
A reference to the border Cell container.

◆ getBorderCells() [2/2]

const std::vector< std::reference_wrapper< Cell > > & CellContainer::getBorderCells ( ) const

Gets a const reference to the border Cell container.

Returns
A const reference to the border Cell container.

◆ getBorderCombinations()

std::vector< std::vector< BorderLocation > > CellContainer::getBorderCombinations ( std::vector< BorderLocation > &  locations)

For a collection of border locations, returns all unique pairs.

Parameters
locationsThe border locations/directions which form the pairs
Returns
A vector of vectors representing the unique pairs

◆ getCellIndex()

int CellContainer::getCellIndex ( const std::array< double, 3 > &  position)

Gets the 1D index in the Cell container based on the given position.

Parameters
positionThe position from which to compute the corresponding 1D index.
Returns
The 1D index in the Cell container.

◆ getCells() [1/2]

std::vector< Cell > & CellContainer::getCells ( )

Gets a reference to the Cell container.

Returns
A reference to the Cell container.

◆ getCells() [2/2]

const std::vector< Cell > & CellContainer::getCells ( ) const

Gets a const reference to the Cell container.

Returns
A const reference to the Cell container.

◆ getCellSize()

const std::array< double, 3 > & CellContainer::getCellSize ( ) const

Gets a const reference to the CellContainer's cell size.

Returns
A const reference to the CellContainer's cell size.

◆ getConditions()

const std::array< BoundaryCondition, 6 > & CellContainer::getConditions ( ) const

Gets the boundary conditions at each boundary.

Returns
A reference to the array containing the boundary conditions at each boundary.

◆ getCutoff()

double CellContainer::getCutoff ( ) const

Gets the cutoff radius used for calculating the cell size.

Returns
The cutoff radius.

◆ getDim()

size_t CellContainer::getDim ( ) const

Gets the number of dimensions of the linked cells.

Returns
The number of dimensions

◆ getDomainSize()

const std::array< double, 3 > & CellContainer::getDomainSize ( ) const

Gets a const reference to the CellContainer's domain size.

Returns
A const reference to the CellContainer's domain size.

◆ getHaloCells() [1/2]

std::vector< std::reference_wrapper< Cell > > & CellContainer::getHaloCells ( )

Gets a reference to the halo Cell container.

Returns
A reference to the halo Cell container.

◆ getHaloCells() [2/2]

const std::vector< std::reference_wrapper< Cell > > & CellContainer::getHaloCells ( ) const

Gets a const reference to the halo Cell container.

Returns
A const reference to the halo Cell container.

◆ getIterableCells() [1/2]

std::vector< std::reference_wrapper< Cell > > & CellContainer::getIterableCells ( )

Gets a reference to the iterable Cell container.

Returns
A reference to the iterable Cell container.

◆ getIterableCells() [2/2]

const std::vector< std::reference_wrapper< Cell > > & CellContainer::getIterableCells ( ) const

Gets a const reference to the iterable Cell container.

Returns
A const reference to the iterable Cell container.

◆ getMirrorPosition()

std::array< double, 3 > CellContainer::getMirrorPosition ( const std::array< double, 3 > &  position,
const Cell from,
const Cell to,
int  direction 
) const

Mirrors a position from a source Cell to a destination Cell.

To be used primarily when incorporating reflective boundaries.

Parameters
positionThe position in the source Cell.
fromThe source Cell.
toThe destination Cell.
directionThe direction(s) in which to mirror the coordinates.
Returns
The mirrored position inside the destination Cell.

◆ getNeighborCells()

std::vector< std::reference_wrapper< Cell > > CellContainer::getNeighborCells ( int  cellIndex)

◆ getNeighbors()

const std::vector< int > & CellContainer::getNeighbors ( int  cellIndex) const

Gets a vector of neighbouring Cell indices, including the Cell itself.

Parameters
cellIndexThe index of the Cell for which the neighbours should be determined.
Returns
A vector of neighbouring Cell indices, including the Cell itself.

◆ getNumCells()

const std::array< size_t, 3 > & CellContainer::getNumCells ( ) const

Gets a const reference to the CellContainer's cell count in each dimension.

Returns
A const reference to the CellContainer's cell count in each dimension.

◆ getOppositeNeighbor()

int CellContainer::getOppositeNeighbor ( int  cellIndex,
HaloLocation  direction 
) const

Gets the index of the opposing Cell in the specified direction.

For example, if the direction is NORTH, this function will return the southern neighbor.

Parameters
cellIndexThe Cell from which to get the opposing Cell index.
directionThe opposite direction of the desired neighbor Cell.
Returns
The index of the opposing Cell in the specified direction.

◆ getOppositeOfBorder()

int CellContainer::getOppositeOfBorder ( const Cell from,
BorderLocation  location 
)

For a border cell returns the index of the halo cell on the opposite side of the domain.

Parameters
fromThe Cell for which the opposite halo cell should be determined
locationThe orientation of the Border Cell
Returns
The index of the opposite halo cell

◆ getOppositeOfBorderCorner()

std::vector< int > CellContainer::getOppositeOfBorderCorner ( const Cell from,
std::vector< BorderLocation > &  locations 
)

For a border cell returns the indices of the corner cells on the opposite sides of the domain.

Parameters
fromThe Cell for which the opposite halo cell should be determined
locationsThe orientations of the Border Cell
Returns
The indices of the opposite halo cells

◆ getOppositeOfHalo()

int CellContainer::getOppositeOfHalo ( const Cell from,
HaloLocation  location 
)

For a halo cell returns the index of the border cell on the opposite side of the domain.

Parameters
fromThe Cell for which the opposite border cell should be determined
locationThe orientation of the Halo Cell
Returns
The index of the opposite border cell

◆ getParticles() [1/2]

ParticleContainer & CellContainer::getParticles ( )

Gets a reference to the primary ParticleContainer.

Returns
A reference to the overarching ParticleContainer.

◆ getParticles() [2/2]

const ParticleContainer & CellContainer::getParticles ( ) const

Gets a const reference to the primary ParticleContainer.

Returns
A const reference to the overarching ParticleContainer.

◆ getVirtualCellCoordinates()

std::array< int, 3 > CellContainer::getVirtualCellCoordinates ( int  index) const

Gets the coordinates of a Cell from its index.

Parameters
indexThe index of the Cell in the container.
Returns
The lower-left origin coordinates of the corresponding Cell.

◆ haloBegin()

SpecialParticleIterator CellContainer::haloBegin ( )

Gets a SpecialParticleIterator pointing to the beginning of the halo Cell pointer container.

Returns
A SpecialParticleIterator pointing to the beginning of the halo Cell pointer container.

◆ haloEnd()

SpecialParticleIterator CellContainer::haloEnd ( )

Gets a SpecialParticleIterator pointing to the end of the halo Cell pointer container.

Returns
A SpecialParticleIterator pointing to the end of the halo Cell pointer container.

◆ moveParticle()

bool CellContainer::moveParticle ( Particle p)

Moves a particle from one Cell to another.

The Particle is first deleted, then added again. The source and destionation cells may be the same. Even if the Particle might not have moved, it will definitely be removed, even if something goes wrong.

Parameters
p
Returns
true if the Particle was successfully moved.
false if the Particle could not be moved. Here, the Particle is removed from the Cell container.

◆ operator[]() [1/2]

Cell & CellContainer::operator[] ( size_t  index)

Dereference of the [] operator.

Gets a Cell by index. Does NOT perform bounds checking.

Parameters
indexThe index of the Cell to get.
Returns
A reference to the Cell at the specified index.

◆ operator[]() [2/2]

const Cell & CellContainer::operator[] ( size_t  index) const

Dereference of the [] operator (const).

Gets a Cell by index. Does NOT perform bounds checking.

Parameters
indexThe index of the Cell to get.
Returns
A const reference to the Cell at the specified index.

◆ printCellContents()

void CellContainer::printCellContents ( ) const

Debug function to print the contents of each cell.

◆ printCellIndices()

void CellContainer::printCellIndices ( ) const

Debug function to print the indices of all cells for a 2D container.

Halo cells are marked red, border cells are marked yellow, inner cells are marked green.

◆ removeHaloCellParticles()

void CellContainer::removeHaloCellParticles ( )

Removes the active halo Cell Particle objects.

For each halo Cell particle, if the Particle is active, it is removed from the Cell's linked list and is marked inactive.

◆ size()

size_t CellContainer::size ( ) const

Gets the size of the ParticleContainer, including all inactive Cells.

Returns
The total size of the ParticleContainer.

Member Data Documentation

◆ anyPeriodic

bool CellContainer::anyPeriodic {false}
private

Determines if there are any periodic halo cells.

◆ borderCells

std::vector<std::reference_wrapper<Cell> > CellContainer::borderCells
private

Container of references to border cells.

◆ cellLocks

std::vector<omp_lock_t> CellContainer::cellLocks
private

Container of mutual exclusion locks for each cell.

◆ cells

ContainerType CellContainer::cells
private

The container of Cell objects itself.

◆ cellSize

std::array<double, 3> CellContainer::cellSize {0, 0, 0}
private

The size of each cell in each dimension (default: 0, 0, 0).

◆ conditions

std::array<BoundaryCondition, 6> CellContainer::conditions
private

An array of boundary conditions to be applied at each boundary (North, South, West, East, Above, Below).

◆ cutoff

double CellContainer::cutoff
private

The cutoff radius.

◆ dim

size_t CellContainer::dim
private

The number of dimensions (2/3)

◆ domainSize

std::array<double, 3> CellContainer::domainSize
private

The size of the domain in each dimension.

◆ haloCells

std::vector<std::reference_wrapper<Cell> > CellContainer::haloCells
private

Container of references to halo cells.

◆ iterableCells

std::vector<std::reference_wrapper<Cell> > CellContainer::iterableCells
private

Container of references to cells to iterate over when calculating the forces between particles.

◆ numCells

std::array<size_t, 3> CellContainer::numCells {1, 1, 1}
private

The number of cells in each dimension (default: 1, 1, 1).

◆ particles

ParticleContainer& CellContainer::particles
private

A reference to the overarching ParticleContainer.


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