ls1-MarDyn
ls1-MarDyn molecular dynamics code
LinkedCells.h
1#pragma once
2
3#ifndef MARDYN_AUTOPAS
4
5#include <vector>
6#include <array>
7#include <memory>
8
9#include "particleContainer/ParticleContainer.h"
10#include "particleContainer/ParticleIterator.h"
11#include "particleContainer/RegionParticleIterator.h"
12#include "particleContainer/ParticleCell.h"
13
14#include "WrapOpenMP.h"
15
16template<class CellTemplate>
18template<class CellTemplate>
19class TraversalTuner;
20
22
50
52
53 friend class LinkedCellsTest;
54#ifdef VTK
55 friend class VTKGridWriter;
56#endif
57
58
59public:
93 double bBoxMin[3], double bBoxMax[3], double cutoffRadius
94 );
95
100
132 void readXML(XMLfileUnits& xmlconfig) override;
133
134 int getHaloWidthNumCells() override {
135 return _haloWidthInNumCells[0];
136 }
137
138 // documentation see father class (ParticleContainer.h)
139 bool rebuild(double bBoxMin[3], double bBoxMax[3]) override;
140
148 void update() override;
149
150 void update_via_copies();
151 void update_via_coloring();
152 void update_via_traversal();
153 void update_via_sliced_traversal();
154
155 bool addParticle(Molecule& particle, bool inBoxCheckedAlready = false, bool checkWhetherDuplicate = false, const bool& rebuildCaches=false) override;
156
157 void addParticles(std::vector<Molecule>& particles, bool checkWhetherDuplicate=false) override;
158
171// void traversePairs(ParticlePairsHandler* particlePairsHandler);
172
173 void traverseCells(CellProcessor& cellProcessor) override;
174
175 void traverseNonInnermostCells(CellProcessor& cellProcessor) override;
176
177 void traversePartialInnermostCells(CellProcessor& cellProcessor, unsigned int stage, int stageCount) override;
178
180 unsigned long getNumberOfParticles() override;
181
182 // @todo: where is this function called?
183 void clear() override;
184
186 void deleteOuterParticles() override;
187
191 double get_halo_L(int index) const override;
192
193 double getCutoff() const override { return _cutoffRadius; }
194 void setCutoff(double rc) override { _cutoffRadius = rc; }
195
196 void deleteMolecule(ParticleIterator &moleculeIter, const bool& rebuildCaches) override;
197 /* TODO: The particle container should not contain any physics, search a new place for this. */
198 double getEnergy(ParticlePairsHandler* particlePairsHandler, Molecule* m1, CellProcessor& cellProcessor) override;
199
200 int* getBoxWidthInNumCells() {
201 return _boxWidthInNumCells;
202 }
203
204 double* getCellLength() override {
205 return _cellLength;
206 }
207
214 std::variant<ParticleIterator, SingleCellIterator<ParticleCell>> getMoleculeAtPosition(const double pos[3]) override;
215
223 unsigned long int getCellIndexOfMolecule(Molecule* molecule) const;
224
232 unsigned long int getCellIndexOfPoint(const double point[3]) const;
233
234 ParticleCell& getCellReference(int idx){ return _cells[idx];}
235
236 // documentation in base class
237 virtual void updateInnerMoleculeCaches() override;
238
239 // documentation in base class
240 virtual void updateBoundaryAndHaloMoleculeCaches() override;
241
242 // documentation in base class
243 virtual void updateMoleculeCaches() override;
244
245 ParticleIterator iterator (ParticleIterator::Type t) override {
246 ParticleIterator :: CellIndex_T offset = mardyn_get_thread_num();
247 ParticleIterator :: CellIndex_T stride = mardyn_get_num_threads();
248
249 return ParticleIterator(t, &_cells, offset, stride);
250 }
251 RegionParticleIterator regionIterator(const double startRegion[3], const double endRegion[3],
252 ParticleIterator::Type type) override;
253
254 size_t getTotalSize() override;
255 void printSubInfo(int offset) override;
256 std::string getName() override;
257
258 bool requiresForceExchange() const override; // new
259
260 unsigned long initCubicGrid(std::array<unsigned long, 3> numMoleculesPerDimension,
261 std::array<double, 3> simBoxLength, size_t seed_offset) override;
262
263 std::vector<unsigned long> getParticleCellStatistics() override;
264
266
267private:
268 //####################################
269 //######### PRIVATE METHODS ##########
270 //####################################
271
273 void check_molecules_in_box();
274
279 void initializeCells();
280
281 void initializeTraversal();
282
302 void calculateNeighbourIndices(std::vector<long>& forward, std::vector<long>& backward) const;
303
305 std::array<std::pair<unsigned long, unsigned long>, 14> calculateCellPairOffsets() const;
306
315 long int cellIndexOf3DIndex(long int xIndex, long int yIndex, long int zIndex) const;
316
318 void threeDIndexOfCellIndex(int ind, int r[3], const int dim[3]) const;
319
325 void deleteParticlesOutsideBox(double boxMin[3], double boxMax[3]);
326
327 void getCellIndicesOfRegion(const double startRegion[3], const double endRegion[3], unsigned int &startRegionCellIndex, unsigned int &endRegionCellIndex);
328
329 RegionParticleIterator getRegionParticleIterator(
330 const double startRegion[3], const double endRegion[3],
331 const unsigned int startRegionCellIndex,
332 const unsigned int endRegionCellIndex, ParticleIterator::Type type);
333
334 //####################################
335 //##### PRIVATE MEMBER VARIABLES #####
336 //####################################
337
338 std::vector<ParticleCell> _cells;
339
340 std::vector<unsigned long> _haloCellIndices;
341
342 std::unique_ptr<TraversalTuner<ParticleCell>> _traversalTuner; // new
343
344 double _haloBoundingBoxMin[3];
345 double _haloBoundingBoxMax[3];
346
347 int _cellsPerDimension[3];
348 int _haloWidthInNumCells[3];
349 int _boxWidthInNumCells[3];
350 double _haloLength[3];
351 double _cellLength[3];
352 double _cellLengthReciprocal[3];
353 double _cutoffRadius;
354 unsigned _cellsInCutoff = 1;
355
368 bool _cellsValid;
369
370 ResortCellProcessorSliced * _resortCellProcessorSliced;
371};
372
373#endif // MARDYN_AUTOPAS
Definition: CellPairTraversals.h:21
Definition: CellProcessor.h:29
FullMolecule modeled as LJ sphere with point polarities.
Definition: FullMolecule.h:18
FullParticleCell data structure. Renamed from ParticleCell.
Definition: FullParticleCell.h:49
Linked Cell Data Structure.
Definition: LinkedCells.h:51
void clear() override
Delete all molecules in container.
Definition: LinkedCells.cpp:590
unsigned long int getCellIndexOfMolecule(Molecule *molecule) const
Get the index in the cell vector to which this Molecule belongs.
Definition: LinkedCells.cpp:791
unsigned long getNumberOfParticles() override
Definition: LinkedCells.cpp:577
bool rebuild(double bBoxMin[3], double bBoxMax[3]) override
rebuild the datastructure
Definition: LinkedCells.cpp:136
~LinkedCells()
Destructor.
Definition: LinkedCells.cpp:111
void deleteOuterParticles() override
delete all Particles which are not within the bounding box
Definition: LinkedCells.cpp:611
void setCutoff(double rc) override
Definition: LinkedCells.h:194
virtual void updateMoleculeCaches() override
Update the caches of the molecules.
Definition: LinkedCells.cpp:1076
void traverseCells(CellProcessor &cellProcessor) override
calculate the forces between the molecules.
Definition: LinkedCells.cpp:564
void readXML(XMLfileUnits &xmlconfig) override
Read in XML configuration for LinkedCells and all its included objects.
Definition: LinkedCells.cpp:128
virtual void updateBoundaryAndHaloMoleculeCaches() override
Update the caches of the molecules, that lie in the boundary or halo cells. The caches of boundary an...
Definition: LinkedCells.cpp:1065
bool addParticle(Molecule &particle, bool inBoxCheckedAlready=false, bool checkWhetherDuplicate=false, const bool &rebuildCaches=false) override
add a single Molecule to the ParticleContainer.
Definition: LinkedCells.cpp:445
LinkedCells()
Default constructor.
Definition: LinkedCells.cpp:39
virtual void updateInnerMoleculeCaches() override
Update the caches of the molecules, that lie in inner cells. The caches of boundary and halo cells is...
Definition: LinkedCells.cpp:1054
unsigned long int getCellIndexOfPoint(const double point[3]) const
Get the index in the cell vector to which the point belongs.
Definition: LinkedCells.cpp:830
std::variant< ParticleIterator, SingleCellIterator< ParticleCell > > getMoleculeAtPosition(const double pos[3]) override
Gets a molecule by its position.
Definition: LinkedCells.cpp:1123
void update() override
Definition: LinkedCells.cpp:243
std::vector< unsigned long > getParticleCellStatistics() override
Definition: LinkedCells.cpp:1146
void addParticles(std::vector< Molecule > &particles, bool checkWhetherDuplicate=false) override
adds a whole vector of particles
Definition: LinkedCells.cpp:458
double get_halo_L(int index) const override
gets the width of the halo region in dimension index
Definition: LinkedCells.cpp:630
std::string getConfigurationAsString() override
Definition: LinkedCells.cpp:1163
This Interface is used to get access to particles and pairs of particles.
Definition: ParticleContainer.h:69
Definition: ParticleIterator.h:50
interface for defining the action performed when processing a pair
Definition: ParticlePairsHandler.h:38
Definition: RegionParticleIterator.h:33
Definition: ResortCellProcessorSliced.h:17
Definition: TraversalTuner.h:23
Definition: VTKGridWriter.h:24
XML file with unit attributes abstraction.
Definition: xmlfileUnits.h:25
Enumeration class corresponding to the type schema type.
Definition: vtk-unstructured.h:1746
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.
Definition: vtk-punstructured.h:270
Definition: FakedOptFFT.h:23