|
Molecular Dynamics
v0.4
Project for the Practical hosted by the Scientific Computing Chair
|
Container to store the particles for simulation using the linked cells algorithm. More...
#include <LinkedCellsContainer.h>


Public Member Functions | |
| LinkedCellsContainer (std::array< double, 3 > domainSize, double rCutOff, BoundarySet boundarySet) | |
| Constructor of the LinkedCellsContainer class. More... | |
| int | calcCellIndex (const std::array< double, 3 > &position) |
| Calculate the index of the cell to which a particle decided by its position belongs. More... | |
| void | add (Particle &p) override |
| Add a particle to this container. More... | |
| int | threeDToOneD (int x, int y, int z) const |
| Convert 3 dimensional coordinates to one dimensional coordinates. More... | |
| int | threeDToOneDDomain (int x, int y, int z) const |
| std::array< int, 3 > | oneDToThreeD (int index) const |
| Convert a one dimensional coordinate to three dimensional coordinates. More... | |
| void | updateCells () |
| Assign each particle to its correct cell after there positions have been changed. More... | |
| void | clearHaloCells (Side side) |
| Delete all particles in all halo cells being part of a specific size. More... | |
| void | applyToEachParticle (const std::function< void(Particle &)> &function) override |
| Iterate over all particles in this container and apply a lambda function to them. More... | |
| void | applyToEachParticleInDomain (const std::function< void(Particle &)> &function) override |
| Iterate over all particles that are part of the domain and apply a lambda function to them. More... | |
| void | applyToAllUniquePairsInDomain (const std::function< void(Particle &, Particle &)> &function) override |
| Iterate over all unique pairs of particles being part of the simulation domain and apply a lambda function to them. More... | |
| void | applyToAllUniquePairsInDomainOptimized (const std::function< void(Particle &, Particle &, std::array< double, 3 >, double)> &function) |
| Implements the optimization we presented as our second idea. At the moment this is dead code, because we did not have time yet to make it compatible with our current program structure and only integrated it once when doing the time measurements. More... | |
| void | applyToAllBoundaryParticles (const std::function< void(Particle &, std::array< double, 3 > &)> &function, Side boundary) |
| Iterate over all particles in the boundary cells of a specific side which have a distance to that side that is smaller or equal than the threshold. More... | |
| size_t | size () const override |
| Get the number of particles stored in this container. More... | |
| std::array< double, 3 > | fromLowToHigh (const std::array< double, 3 > &position, int dimension) |
| Move a particle along a certain dimension that underflows the domain int that dimension to the opposite side of the domain in that dimension. More... | |
| std::array< double, 3 > | fromHighToLow (const std::array< double, 3 > &position, int dimension) |
| Move a particle along a certain dimension that overflows the domain int that dimension to the opposite side of the domain in that dimension. More... | |
| void | teleportParticlesToOppositeSide (Side sideStart) |
| Moves particles along a certain dimension from the halo cells back into the simulation domain. More... | |
| void | applyForcesFromOppositeSide (Side side) |
| Used for periodic boundaries to calculate the force that all particles from the opposite edge exert on the particles on the specified cell on the specified side. More... | |
| std::vector< std::vector< Particle > > & | getCells () |
| std::array< std::vector< int >, 6 > & | getHaloCells () |
| std::array< std::vector< int >, 6 > & | getBoundaries () |
| std::vector< std::vector< int > > & | getDomainCellIterationScheme () |
| int | getNX () const |
| int | getNY () const |
| int | getNZ () const |
| double | getCellSizeX () const |
| double | getCellSizeY () const |
| double | getCellSizeZ () const |
| double | getRCutOff () const |
| bool | isTwoD () const |
| std::array< double, 3 > | getDomainSize () const |
Public Member Functions inherited from ParticleContainer | |
| virtual | ~ParticleContainer ()=default |
| Virtual default constructor to guarantee appropriate memory clean up. More... | |
Private Member Functions | |
| void | calculateHaloCellIndices () |
| Pre-calculation of all halo cell indices. More... | |
| void | calculateBoundaryCellIndices () |
| Pre-calculation of all boundary cell indices. More... | |
| void | calculateDomainCellsIterationScheme () |
| Pre-calculation of the indices defining the processing order of cells. More... | |
| void | calculateScheduleParallelSophisticatedHelper (int xStart, int yStart, int zStart) |
| void | calculateScheduleNaive () |
| void | calculateScheduleParallelSophisticated () |
| double | calcDistanceFromBoundary (Particle &p, Side side) |
| Calculate the distance that a particle has to a specific side of the domain. In 2D the distance to sides top and bottom is always 0. More... | |
| std::array< double, 3 > | calcGhostParticle (Particle &p, Side side) |
| Calculate the position of the ghost particle with respect to a specific side used for reflective boundaries. More... | |
| void | teleportParticlesToOppositeSideHelper (Side sideStart, int dimension, int modus) |
| Moves particles along a certain dimension from the halo cells back into the simulation domain. More... | |
| void | applyForceToOppositeCellsHelper (Side side, std::array< int, 3 > cellToProcess) |
| Used for periodic boundaries to calculate the force that all particles from the opposite edge exert on the particles on the specified cell on the specified side. More... | |
| void | applyForceToOppositeEdgeHelper (std::array< int, 3 > cellToProcess, std::array< int, 3 > offsetCell, std::array< double, 3 > offsetPosition, int dim) |
| Used for periodic boundaries to calculate the force that all particles from the opposite edge exert on the particles of the specified cell. More... | |
| bool | isCellInDomain (std::array< int, 3 > cell) const |
| Checks, if the specified cell is part of the domain. More... | |
| bool | isParticleInDomain (const std::array< double, 3 > &position) const |
| Checks, if the specified particle is inside the domain. More... | |
| void | applyForcesBetweenTwoCells (int cellTarget, int cellSource, std::array< double, 3 > offsetSource) |
| Calculates the forces that particles in the cell source apply to the particles in cell target. More... | |
Private Attributes | |
| std::vector< std::vector< Particle > > | cells |
| size_t | currentSize |
| std::array< std::vector< int >, 6 > | haloCells |
| std::array< std::vector< int >, 6 > | boundaries |
| std::vector< std::vector< int > > | domainCellIterationScheme |
| std::vector< int > | scheduleParallelNaive |
| std::vector< int > | scheduleParallelSophisticated |
| int | nX |
| int | nY |
| int | nZ |
| int | baseY |
| int | baseZ |
| int | baseYDomain |
| int | baseZDomain |
| double | cellSizeX |
| double | cellSizeY |
| double | cellSizeZ |
| double | rCutOff |
| bool | twoD |
| std::array< double, 3 > | domainSize |
| outputWriter::VTKWriter | vtk_writer |
| LennardJonesForce | lJF |
| BoundarySet | boundariesSet |
Container to store the particles for simulation using the linked cells algorithm.
| LinkedCellsContainer::LinkedCellsContainer | ( | std::array< double, 3 > | domainSize, |
| double | rCutOff, | ||
| BoundarySet | boundarySet | ||
| ) |
Constructor of the LinkedCellsContainer class.
Constructor and methods
| domainSize | Size of the simulation domain. Syntax {x, y, z}. Front lower left corner is by definition (0,0,0). |
| rCutOff | The cut-off radius |

|
overridevirtual |
Add a particle to this container.
| p | Particle to be added. |
If the simulation environment is 2D, only particles living in 2D space are accepted. Try adding particles living in 3D space to 2D simulation environment will lead to the termination of the program.
Implements ParticleContainer.

|
private |
Calculates the forces that particles in the cell source apply to the particles in cell target.
| cellTarget | Index of the cell containing the particles to which the force is applied. |
| cellSource | Index of the cell containing the particles which exert the force. |
| offsetSource | Offset to move the particles of the cell source in the right position for force calculations. |


| void LinkedCellsContainer::applyForcesFromOppositeSide | ( | Side | side | ) |
Used for periodic boundaries to calculate the force that all particles from the opposite edge exert on the particles on the specified cell on the specified side.
| side | Side on which the force is exerted. |


|
private |
Used for periodic boundaries to calculate the force that all particles from the opposite edge exert on the particles on the specified cell on the specified side.
| side | Side on which the force is exerted. |
| cellToProcess | Specific cell of that side. |

|
private |
Used for periodic boundaries to calculate the force that all particles from the opposite edge exert on the particles of the specified cell.
| cellToProcess | Cell on which particles the force is exerted. |
| offsetCell | Offset to reach the cell of the opposite edge. |
| offsetPosition | Offset to move the particles of the opposite edge to the current edge for proper force calculation. |
| dim | Dimension in which the edge is living. |

| void LinkedCellsContainer::applyToAllBoundaryParticles | ( | const std::function< void(Particle &, std::array< double, 3 > &)> & | function, |
| Side | boundary | ||
| ) |
Iterate over all particles in the boundary cells of a specific side which have a distance to that side that is smaller or equal than the threshold.
| function | Lambda function that is applied to each particle fulfilling the requirements. |
| boundary | Side to which the boundary cells belong. |
Additionally, the position of the corresponding ghost particle of each particle is calculated and passed in the lambda function as second input. This information makes the implementation of reflective boundaries a lot easier.


|
overridevirtual |
Iterate over all unique pairs of particles being part of the simulation domain and apply a lambda function to them.
| function | Lambda function that is applied to each unique pair of particles. |
The purpose of this function is provide an easy way of calculating the force between all particles by using Newton's third law of motion.
Implements ParticleContainer.


| void LinkedCellsContainer::applyToAllUniquePairsInDomainOptimized | ( | const std::function< void(Particle &, Particle &, std::array< double, 3 >, double)> & | function | ) |
Implements the optimization we presented as our second idea. At the moment this is dead code, because we did not have time yet to make it compatible with our current program structure and only integrated it once when doing the time measurements.


|
overridevirtual |
Iterate over all particles in this container and apply a lambda function to them.
| function | Lambda function that is applied to each particle. |
Implements ParticleContainer.
|
overridevirtual |
Iterate over all particles that are part of the domain and apply a lambda function to them.
| function | Lambda function that is applied to each particle. |
Implements ParticleContainer.

| int LinkedCellsContainer::calcCellIndex | ( | const std::array< double, 3 > & | position | ) |
Calculate the index of the cell to which a particle decided by its position belongs.
| position | Position of the particle to calculate the cell index of. |


Calculate the distance that a particle has to a specific side of the domain. In 2D the distance to sides top and bottom is always 0.
| p | Particle used for distance calculation |
| side | Side of the domain to which the distance is calculated |


Calculate the position of the ghost particle with respect to a specific side used for reflective boundaries.
| p | Particle to calculate the corresponding ghost particle of. |
| side | Side of the domain at which the particle is mirrored. |


|
private |
Pre-calculation of all boundary cell indices.

|
private |
Pre-calculation of the indices defining the processing order of cells.

|
private |
Pre-calculation of all halo cell indices.

|
private |

|
private |

|
private |
| void LinkedCellsContainer::clearHaloCells | ( | Side | side | ) |
Delete all particles in all halo cells being part of a specific size.
| side | Side at which all halo cells are cleared. |

| std::array< double, 3 > LinkedCellsContainer::fromHighToLow | ( | const std::array< double, 3 > & | position, |
| int | dimension | ||
| ) |
Move a particle along a certain dimension that overflows the domain int that dimension to the opposite side of the domain in that dimension.
| position | Current position of the particle. |
| dimension | Dimension along the particle is moved. |
| std::array< double, 3 > LinkedCellsContainer::fromLowToHigh | ( | const std::array< double, 3 > & | position, |
| int | dimension | ||
| ) |
Move a particle along a certain dimension that underflows the domain int that dimension to the opposite side of the domain in that dimension.
| position | Current position of the particle. |
| dimension | Dimension along the particle is moved. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
private |
Checks, if the specified cell is part of the domain.
| cell | Cell to check. |
|
private |
Checks, if the specified particle is inside the domain.
| position | Position of the particle. |
|
inline |

| std::array< int, 3 > LinkedCellsContainer::oneDToThreeD | ( | int | index | ) | const |
Convert a one dimensional coordinate to three dimensional coordinates.
| index | One dimensional coordinate |
|
overridevirtual |
Get the number of particles stored in this container.
Implements ParticleContainer.
| void LinkedCellsContainer::teleportParticlesToOppositeSide | ( | Side | sideStart | ) |
Moves particles along a certain dimension from the halo cells back into the simulation domain.
| sideStart | Side from which the particles will be teleported to the opposite side. |
Only updates the cell of the particle, if the particle is back into the domain in all three dimensions.


|
private |
Moves particles along a certain dimension from the halo cells back into the simulation domain.
| sideStart | Side from which the particles will be teleported to the opposite side. |
| dimension | Dimension along which the particles are moved (x := 0, y := 1, z := 2) |
| modus | Specify if the particles are moved up or down along the dimension (down := 0, up := 1) |
Only updates the cell of the particle, if the particle is back into the domain in all three dimensions.

| int LinkedCellsContainer::threeDToOneD | ( | int | x, |
| int | y, | ||
| int | z | ||
| ) | const |
Convert 3 dimensional coordinates to one dimensional coordinates.
| x | x coordinate |
| y | y coordinate |
| z | z coordinate |

| int LinkedCellsContainer::threeDToOneDDomain | ( | int | x, |
| int | y, | ||
| int | z | ||
| ) | const |
| void LinkedCellsContainer::updateCells | ( | ) |
Assign each particle to its correct cell after there positions have been changed.


|
private |
Number of cells in one row (nX many).
|
private |
Number of cells in one layer halo cells excluded (nX - 2 many).
|
private |
Number of cells in one layer (nX * nY many).
|
private |
Number of cells in one layer halo cells excluded ((nX - 2) * (nY - 2) many).
|
private |
The indices of all boundary cells belonging to one or more of the 6 sides
|
private |
|
private |
We use an 1D vector to store the flattened 3D cell structure being an essential property of the linked cells algorithm. Each cell is represented itself by an 1D vector of particles.
|
private |
Size of each cell in dimension x.
|
private |
Size of each cell in dimension y.
|
private |
Size of each cell in dimension z.
|
private |
The current number of particles that is contained in this container is tracked by the attribute currentSize and kept up-to-date through every operation.
|
private |
The indices of the order in which all cells within the domain are processed to process each pair of particles only ones
|
private |
Size of the domain {x, y , z}. The front lower left corner of the domain is set to (0,0,0) by definition.
|
private |
The indices of all halo cells belonging to one or more of the 6 sides,
|
private |
|
private |
Number of cells in dimension x (halo cells inclusive).
|
private |
Number of cells in dimension y (halo cells inclusive).
|
private |
Number of cells in dimension z (halo cells inclusive).
|
private |
Cut-off radius.
|
private |
|
private |
|
private |
Specifies, if the simulation only uses 2 of 3 dimensions. If this is the case, resources can be saved.
|
private |