MolSim
Loading...
Searching...
No Matches
Cell.h
Go to the documentation of this file.
1
9#pragma once
10
11#include "Particle.h"
12#include "utils/CellUtils.h"
13#include <algorithm>
14#include <array>
15#include <bitset>
16#include <forward_list>
17#include <sstream>
18#include <string>
19#include <vector>
20#define VEC_CONTAINS(vec, el) ((std::find((vec).begin(), (vec).end(), (el)) != (vec).end()))
21
23class Cell {
25 using ContainerType = std::forward_list<std::reference_wrapper<Particle>>;
26
27 private:
31 std::array<double, 3> m_size;
33 std::array<double, 3> m_position;
36 std::vector<HaloLocation> m_haloLocation;
39 std::vector<BorderLocation> m_borderLocation;
41 std::vector<int> m_neighbors;
46
47 public:
48 /* constructor */
61 Cell(const std::array<double, 3> &size, const std::array<double, 3> &position, CellType type, int index,
62 const std::vector<HaloLocation> &haloLocation, const std::vector<BorderLocation> &borderLocation);
63
64 /* iterator */
70 ContainerType::iterator begin();
71
77 ContainerType::iterator end();
78
79 /* corner cells */
86 std::array<double, 3> getRelativePosition(const Particle &p) const;
87
95 void validatePosition(const std::array<double, 3> &relPos) const;
96
107 bool isCorner(HaloLocation loc1, HaloLocation loc2) const;
108
120 HaloLocation handle2DCorner(const std::array<double, 3> &relPos) const;
121
133 HaloLocation handle3DCorner(const std::array<double, 3> &relPos) const;
134
146 HaloLocation handle3DDiagonal(const std::array<double, 3> &relPos) const;
147
160 HaloLocation handle3DTripleCorner(const std::array<double, 3> &relPos) const;
161
162 /* main functionality */
168 void addParticle(Particle &particle);
169
175 void removeParticle(Particle &particle);
176
187
193 const std::array<double, 3> &getX() const;
194
200 const std::array<double, 3> &getSize() const;
201
207 const std::vector<HaloLocation> &getHaloLocation() const;
208
214 const std::vector<BorderLocation> &getBorderLocation() const;
215
221 std::vector<int> &getNeighbors();
222
228 const std::vector<int> &getNeighbors() const;
229
235 std::forward_list<std::reference_wrapper<Particle>> &getParticles();
236
242 const std::forward_list<std::reference_wrapper<Particle>> &getParticles() const;
243
250
256 int getIndex() const;
257
263 std::string toString() const;
264};
Utility functions for Cell and CellContainer objects.
CellType
Enum containing the possible types of cells.
Definition CellUtils.h:20
HaloLocation
Enum containing the possible corner and edge directions of halo cells.
Definition CellUtils.h:22
Model of a single particle.
Class for storing data of a single Cell in a domain split into cells.
Definition Cell.h:23
int m_index
The index of this Cell in the overarching CellContainer.
Definition Cell.h:45
ContainerType::iterator begin()
Gets an iterator to the beginning of the Particle* forward list.
HaloLocation getCornerRegion(const Particle &p) const
Dispatch function to handle a corner cell.
void validatePosition(const std::array< double, 3 > &relPos) const
Validates if the provided relative position is within the bounds of the current cell (debug).
const std::array< double, 3 > & getSize() const
Gets a const reference to the size array of this Cell.
const std::array< double, 3 > & getX() const
Gets a const reference to the position array of this Cell.
const std::vector< int > & getNeighbors() const
Gets a const reference to the Cell's neighbors.
CellType getType() const
Gets the type of this Cell.
std::forward_list< std::reference_wrapper< Particle > > & getParticles()
Gets a reference to the Cell's Particle pointer forward list.
std::forward_list< std::reference_wrapper< Particle > > ContainerType
Typedef for the container type used to store pointers to a Cell's Particle objects.
Definition Cell.h:25
std::array< double, 3 > m_position
The lower-left coordinates of the Cell.
Definition Cell.h:33
HaloLocation handle3DDiagonal(const std::array< double, 3 > &relPos) const
Handles the logic for determining the 3D diagonal region.
HaloLocation handle3DCorner(const std::array< double, 3 > &relPos) const
Handles the logic for 3D corner cell handling.
std::vector< HaloLocation > m_haloLocation
If this is a halo cell, the locations of this cell (North, South, West, East, Above,...
Definition Cell.h:36
CellType m_type
The type of this Cell. May be INNER, BORDER or HALO.
Definition Cell.h:43
std::vector< int > & getNeighbors()
Gets a reference to the Cell's neighbors.
int getIndex() const
Gets the index of this Cell in its CellContainer.
std::vector< BorderLocation > m_borderLocation
If this is a border cell, the locations of this cell (North, South, West, East, Above,...
Definition Cell.h:39
std::vector< int > m_neighbors
The neighboring Cell indices.
Definition Cell.h:41
HaloLocation handle2DCorner(const std::array< double, 3 > &relPos) const
Handles the logic for 2D corner cell handling.
ContainerType::iterator end()
Gets an iterator to one past the end of the Particle* forward list.
const std::vector< BorderLocation > & getBorderLocation() const
Gets a const reference to the border location (cardinal direction) vector of this Cell.
const std::forward_list< std::reference_wrapper< Particle > > & getParticles() const
Gets a const reference to the Cell's Particle pointer forward list.
void removeParticle(Particle &particle)
Removes a Particle reference from the forward list.
std::array< double, 3 > getRelativePosition(const Particle &p) const
Calculates the relative position of a particle within the current cell.
void addParticle(Particle &particle)
Adds a Particle reference to the front of the forward list.
bool isCorner(HaloLocation loc1, HaloLocation loc2) const
Checks if two HaloLocation values correspond to a corner.
std::string toString() const
Gets a string representation of this Cell.
const std::vector< HaloLocation > & getHaloLocation() const
Gets a const reference to the halo location (cardinal direction) vector of this Cell.
HaloLocation handle3DTripleCorner(const std::array< double, 3 > &relPos) const
Handles the logic for determining the 3D triple corner region.
std::array< double, 3 > m_size
The size of the Cell in each dimension.
Definition Cell.h:31
Cell(const std::array< double, 3 > &size, const std::array< double, 3 > &position, CellType type, int index, const std::vector< HaloLocation > &haloLocation, const std::vector< BorderLocation > &borderLocation)
Constructs a new Cell object.
ContainerType m_particles
A forward list of pointers to Particle objects contained within the current Cell.
Definition Cell.h:29
Particle class modeling a particle's position, velocity, force, mass and type.
Definition Particle.h:46
Enumeration class corresponding to the type schema type.
Definition vtk-unstructured.h:2125