ls1-MarDyn
ls1-MarDyn molecular dynamics code
GeneralDomainDecomposition.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <optional>
10
11#include "DomainDecompMPIBase.h"
12#include "LoadBalancer.h"
13
18public:
25 GeneralDomainDecomposition(double interactionLength, Domain* domain, bool forceGrid);
26
27 // documentation see father class (DomainDecompBase.h)
29
48 void readXML(XMLfileUnits& xmlconfig) override;
49
50 // documentation see father class (DomainDecompBase.h)
51 double getBoundingBoxMin(int dimension, Domain* domain) override;
52
53 // documentation see father class (DomainDecompBase.h)
54 double getBoundingBoxMax(int dimension, Domain* domain) override;
55
56 void balanceAndExchange(double lastTraversalTime, bool forceRebalancing, ParticleContainer* moleculeContainer,
57 Domain* domain) override;
58
59 // returns a vector of the neighbour ranks in x y and z direction (only neighbours connected by an area to local
60 // area)
61 std::vector<int> getNeighbourRanks() override {
62 throw std::runtime_error("GeneralDomainDecomposition::getNeighbourRanks() not yet implemented");
63 }
64
65 // returns a vector of all 26 neighbour ranks in x y and z direction
66 std::vector<int> getNeighbourRanksFullShell() override {
67 throw std::runtime_error("GeneralDomainDecomposition::getNeighbourRanksFullShell() not yet implemented");
68 }
69
70 // documentation in base class
71 void prepareNonBlockingStage(bool forceRebalancing, ParticleContainer* moleculeContainer, Domain* domain,
72 unsigned int stageNumber) override {
73 throw std::runtime_error("GeneralDomainDecomposition::prepareNonBlockingStage() not yet implemented");
74 }
75
76 // documentation in base class
77 void finishNonBlockingStage(bool forceRebalancing, ParticleContainer* moleculeContainer, Domain* domain,
78 unsigned int stageNumber) override {
79 throw std::runtime_error("GeneralDomainDecomposition::prepareNonBlockingStage() not yet implemented");
80 }
81
82 // documentation in base class
83 bool queryBalanceAndExchangeNonBlocking(bool forceRebalancing, ParticleContainer* moleculeContainer, Domain* domain,
84 double etime) override {
85 throw std::runtime_error(
86 "GeneralDomainDecomposition::queryBalanceAndExchangeNonBlocking() not yet implemented");
87 }
88
89 std::vector<CommunicationPartner> getNeighboursFromHaloRegion(Domain* domain, const HaloRegion& haloRegion,
90 double cutoff) override {
91 throw std::runtime_error("GeneralDomainDecomposition::getNeighboursFromHaloRegion() not yet implemented");
92 }
93
94private:
98 void initializeALL();
99
109 static std::array<size_t, 3> getOptimalGrid(const std::array<double, 3>& domainLength, int numProcs);
110
118 static std::array<size_t, 3> getCoordsFromRank(const std::array<size_t, 3>& gridSize, int rank);
119
127 static std::tuple<std::array<double, 3>, std::array<double, 3>> initializeRegularGrid(
128 const std::array<double, 3>& domainLength, const std::array<size_t, 3>& gridSize,
129 const std::array<size_t, 3>& gridCoords);
130
141 static bool queryRebalancing(size_t step, size_t updateFrequency, size_t initPhase, size_t initUpdateFrequency,
142 double lastTraversalTime);
143
149 void initCommPartners(ParticleContainer* moleculeContainer, Domain* domain);
150
159 void migrateParticles(Domain* domain, ParticleContainer* particleContainer, std::array<double, 3> newMin,
160 std::array<double, 3> newMax);
161
169 std::pair<std::array<double, 3>, std::array<double, 3>> latchToGridSize(std::array<double, 3> boxMin,
170 std::array<double, 3> boxMax) {
171 for (size_t ind = 0; ind < 3; ++ind) {
172 double currentGridSize = (*_gridSize)[ind];
173 // For boxmin, the lower domain boundary is 0, so that's always fine!
174 boxMin[ind] = std::round(boxMin[ind] / currentGridSize) * currentGridSize;
175 // update boxmax only if it isn't at the very top of the domain!
176 if (boxMax[ind] != _domainLength[ind]) {
177 boxMax[ind] = std::round(boxMax[ind] / currentGridSize) * currentGridSize;
178 }
179 }
180 return {boxMin, boxMax};
181 }
182
183 // variables
184 std::array<double, 3> _boxMin;
185 std::array<double, 3> _boxMax;
186
187 std::array<double, 3> _domainLength;
188 double _interactionLength;
189
190 size_t _steps{0};
191 size_t _rebuildFrequency{10000};
192
193 size_t _initPhase{0};
194 size_t _initFrequency{500};
195
200 std::optional<std::array<double, 3>> _gridSize{};
201
205 bool _forceLatchingToLinkedCellsGrid{false};
206
207 std::unique_ptr<LoadBalancer> _loadBalancer{nullptr};
208
209 friend class GeneralDomainDecompositionTest;
210};
Definition: DomainDecompMPIBase.h:30
This class is used to read in the phasespace and to handle macroscopic values.
Definition: Domain.h:47
Definition: GeneralDomainDecomposition.h:17
void readXML(XMLfileUnits &xmlconfig) override
Read in XML configuration for DomainDecomposition and all its included objects.
Definition: GeneralDomainDecomposition.cpp:241
void finishNonBlockingStage(bool forceRebalancing, ParticleContainer *moleculeContainer, Domain *domain, unsigned int stageNumber) override
Definition: GeneralDomainDecomposition.h:77
double getBoundingBoxMin(int dimension, Domain *domain) override
get the minimum of the bounding box of this process' domain in the given dimension (0,...
Definition: GeneralDomainDecomposition.cpp:59
bool queryBalanceAndExchangeNonBlocking(bool forceRebalancing, ParticleContainer *moleculeContainer, Domain *domain, double etime) override
Checks whether the balance and exchange step can be performed non-blocking.
Definition: GeneralDomainDecomposition.h:83
GeneralDomainDecomposition(double interactionLength, Domain *domain, bool forceGrid)
Definition: GeneralDomainDecomposition.cpp:15
double getBoundingBoxMax(int dimension, Domain *domain) override
get the maximum of the bounding box of this process' domain in the given dimension (0,...
Definition: GeneralDomainDecomposition.cpp:63
void balanceAndExchange(double lastTraversalTime, bool forceRebalancing, ParticleContainer *moleculeContainer, Domain *domain) override
balance the load (and optimize communication) and exchange boundary particles
Definition: GeneralDomainDecomposition.cpp:70
void prepareNonBlockingStage(bool forceRebalancing, ParticleContainer *moleculeContainer, Domain *domain, unsigned int stageNumber) override
Definition: GeneralDomainDecomposition.h:71
This Interface is used to get access to particles and pairs of particles.
Definition: ParticleContainer.h:69
XML file with unit attributes abstraction.
Definition: xmlfileUnits.h:25
Definition: HaloRegion.h:10