ls1-MarDyn
ls1-MarDyn molecular dynamics code
ParticleCellBase.h
1/*
2 * ParticleCellBase.h
3 *
4 * Created on: 20 Jan 2017
5 * Author: tchipevn
6 */
7
8#ifndef SRC_PARTICLECONTAINER_PARTICLECELLBASE_H_
9#define SRC_PARTICLECONTAINER_PARTICLECELLBASE_H_
10
11#include "Cell.h"
12#include "molecules/Molecule.h"
13#include "CellBorderAndFlagManager.h"
14
15#ifdef QUICKSCHED
16#include <quicksched.h>
17#endif
18
19class Random;
20
23class ParticleCellBase: public Cell {
24public:
26 virtual ~~ParticleCellBase();
27
28 virtual void deallocateAllParticles() = 0;
29
35 virtual bool addParticle(Molecule& particle, bool checkWhetherDuplicate = false) = 0;
36
40 virtual bool isEmpty() const = 0;
44 bool isNotEmpty() const {return not isEmpty();}
45
50 bool deleteMoleculeByID(unsigned long molid);
51
52 virtual bool deleteMoleculeByIndex(size_t index) = 0;
53
54 virtual int getMoleculeCount() const = 0;
55
56 virtual void preUpdateLeavingMolecules() = 0;
57
58 virtual void updateLeavingMoleculesBase(ParticleCellBase& otherCell) = 0;
59
60 virtual void postUpdateLeavingMolecules() = 0;
61
62 virtual void getRegion(double lowCorner[3], double highCorner[3], std::vector<Molecule*> &particlePtrs, bool removeFromContainer = false) = 0;
63
64 virtual void buildSoACaches() = 0;
65
66 virtual void increaseMoleculeStorage(size_t numMols) = 0;
67
68 virtual bool testPointInCell(const double point[3]) const {
69 double boxMin[3] = {getBoxMin(0), getBoxMin(1), getBoxMin(2)};
70 double boxMax[3] = {getBoxMax(0), getBoxMax(1), getBoxMax(2)};
71 return boxMin[0] <= point[0] && boxMin[1] <= point[1] && boxMin[2] <= point[2] &&
72 point[0] < boxMax[0] && point[1] < boxMax[1] && point[2] < boxMax[2];
73 }
74
75 virtual bool testInBox(const Molecule& particle) const {
76 double boxMin[3] = {getBoxMin(0), getBoxMin(1), getBoxMin(2)};
77 double boxMax[3] = {getBoxMax(0), getBoxMax(1), getBoxMax(2)};
78 return particle.inBox(boxMin, boxMax);
79 }
80
81 virtual size_t getMoleculeVectorDynamicSize() const = 0;
82
83 virtual void prefetchForForce() const {/*TODO*/}
84
85 unsigned long initCubicGrid(std::array<unsigned long, 3> numMoleculesPerDimension, std::array<double, 3> simBoxLength, Random & RNG);
86
87//protected: Do not use! use SingleCellIterator instead!
88 // multipurpose:
89 // in FullParticleCell, this is set to point to one of the molecules in _molecules
90 // in ParticleCellRMM, this points to an existing molecule, into which the correct data is written.
91 virtual void moleculesAtNew(size_t i, Molecule *& multipurposePointer) = 0;
92 virtual void moleculesAtConstNew(size_t i, Molecule *& multipurposePointer) const = 0;
93
94 virtual void getLeavingMolecules(std::vector<Molecule> & appendBuffer) {
95 // TODO: implement for FullParticleCell
96 }
97
98
99 static CellBorderAndFlagManager _cellBorderAndFlagManager;
100 bool isHaloCell() const final {
101 return _cellBorderAndFlagManager.isHaloCell(_cellIndex);
102 }
103 bool isBoundaryCell() const final {
104 return _cellBorderAndFlagManager.isBoundaryCell(_cellIndex);
105 }
106 bool isInnerCell() const final {
107 return _cellBorderAndFlagManager.isInnerCell(_cellIndex);
108 }
109 bool isInnerMostCell() const final {
110 return _cellBorderAndFlagManager.isInnerMostCell(_cellIndex);
111 }
112
113 void assignCellToHaloRegion() { mardyn_assert(isHaloCell()); }
114 void assignCellToBoundaryRegion() { mardyn_assert(isBoundaryCell()); }
115 void assignCellToInnerRegion() { mardyn_assert(isInnerCell()); }
116 void assignCellToInnerMostAndInnerRegion() { mardyn_assert(isInnerMostCell() and isInnerCell()); }
117
118 void skipCellFromHaloRegion() { mardyn_assert(not isHaloCell()); }
119 void skipCellFromBoundaryRegion() { mardyn_assert(not isBoundaryCell()); }
120 void skipCellFromInnerRegion() { mardyn_assert(not isInnerCell()); }
121 void skipCellFromInnerMostRegion() { mardyn_assert(not isInnerMostCell()); }
122
123 double getBoxMin(int d) const {
124 return _cellBorderAndFlagManager.getBoundingBoxMin(_cellIndex, d);
125 }
126 double getBoxMax(int d) const {
127 return _cellBorderAndFlagManager.getBoundingBoxMax(_cellIndex, d);
128 }
129
130 std::array<double, 3> getBoxMinArray() const {
131 std::array<double, 3> ret{getBoxMin(0), getBoxMin(1), getBoxMin(2)};
132 return ret;
133 }
134
135 std::array<double, 3> getBoxMaxArray() const {
136 std::array<double, 3> ret{getBoxMax(0), getBoxMax(1), getBoxMax(2)};
137 return ret;
138 }
139
140 void setBoxMin(const double b[3]) {
141 for (int d = 0; d < 3; ++d) {
142 mardyn_assert(getBoxMin(d) == b[d]);
143 }
144 }
145 void setBoxMax(const double b[3]) {
146 for (int d = 0; d < 3; ++d) {
147 mardyn_assert(getBoxMax(d) == b[d]);
148 }
149 }
150
151#ifdef QUICKSCHED
152 qsched_res_t getRescourceId() const {
153 return _resourceId;
154 }
155
156 void setResourceId(qsched_res_t resourceId){
157 _resourceId = resourceId;
158 }
159
160 qsched_task_t getTaskId() const {
161 return _taskId;
162 }
163
164 void setTaskId(qsched_task_t taskId){
165 _taskId = taskId;
166 }
167#endif // QUICKSCHED
168
169protected:
175 virtual bool findMoleculeByID(size_t& index, unsigned long molid) const = 0;
176
177#ifdef QUICKSCHED
178 qsched_res_t _resourceId;
179 qsched_task_t _taskId;
180#endif // QUICKSCHED
181};
182
183#endif /* SRC_PARTICLECONTAINER_PARTICLECELLBASE_H_ */
Definition: CellBorderAndFlagManager.h:19
Definition: Cell.h:4
unsigned long _cellIndex
the index of a cell. On one process every index must be unique.
Definition: Cell.h:35
FullMolecule modeled as LJ sphere with point polarities.
Definition: FullMolecule.h:18
virtual bool inBox(const double l[3], const double u[3]) const
test whether molecule is inside a cuboid region
Definition: MoleculeInterface.h:300
ParticleCellBase defines the interface for cells used by the LinkedCells data structure to store mole...
Definition: ParticleCellBase.h:23
virtual bool findMoleculeByID(size_t &index, unsigned long molid) const =0
Find the index of a molecule in a cell based on its molecule ID.
virtual bool isEmpty() const =0
Check if current cell contains no molecules.
virtual bool addParticle(Molecule &particle, bool checkWhetherDuplicate=false)=0
Add a particle to the cell.
bool isNotEmpty() const
Check if current cell contains molecules.
Definition: ParticleCellBase.h:44
bool deleteMoleculeByID(unsigned long molid)
Remove moleulce from the cell based on molecule ID.
Definition: ParticleCellBase.cpp:23
Definition: Random.h:12