Peano
Loading...
Searching...
No Matches
ParticleSpecies.h
Go to the documentation of this file.
1// This file is part of the ExaParty project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3#pragma once
4
5#include "tarch/logging/Log.h"
7
8#ifdef Parallel
9#include "tarch/mpi/mpi.h"
10#include "tarch/mpi/Rank.h"
13#endif
14
15namespace exaparty {
16 class ParticleSpecies;
17} // namespace exaparty
18
34private:
37
40
43
46
49
51
52public:
61 inline ParticleSpecies() : _minTimeStepSize(std::numeric_limits<double>::max()),
63 _minTimeStamp(0.0), // std::numeric_limits<double>::max()
64 _maxTimeStamp(0.0),
65 _minSearchRadius(std::numeric_limits<double>::max()),
67 _minVelocity(std::numeric_limits<double>::max()),
68 _maxVelocity(0.0),
70
71 ParticleSpecies(const ParticleSpecies& copy) = delete;
72
73 inline double getMinTimeStepSize() const {
74 return _minTimeStepSize;
75 }
76
77 inline double getMaxTimeStepSize() const {
78 return _maxTimeStepSize;
79 }
80
81 inline double getMinTimeStamp() const {
82 return _minTimeStamp;
83 }
84
85 inline double getMaxTimeStamp() const {
86 return _maxTimeStamp;
87 }
88
89 inline double getMinSearchRadius() const {
90 return _minSearchRadius;
91 }
92
93 inline double getMaxSearchRadius() const {
94 return _maxSearchRadius;
95 }
96
97 inline double getMinVelocity() const {
98 return _minVelocity;
99 }
100
101 inline double getMaxVelocity() const {
102 return _maxVelocity;
103 }
104
109 inline bool rerunPreviousGridSweep() const { return _rerunPreviousGridSweep; }
110
120
142
146 inline void setTimeStamp(double t, bool reduceInsteadOfOverwrite = true) {
147 setTimeStamp(t, t, reduceInsteadOfOverwrite);
148 }
149
150 inline void setTimeStamp(double tMin, double tMax, bool reduceInsteadOfOverwrite = true) {
152 if (reduceInsteadOfOverwrite) {
153 _minTimeStamp = std::min(_minTimeStamp, tMin);
154 _maxTimeStamp = std::max(_maxTimeStamp, tMax);
155 } else {
156 _minTimeStamp = tMin;
157 _maxTimeStamp = tMax;
158 }
159 }
160
161 inline void setTimeStepSize(double dt, bool reduceInsteadOfOverwrite = true) {
162 setTimeStepSize(dt, dt, reduceInsteadOfOverwrite);
163 }
164
165 inline void setTimeStepSize(double dtMin, double dtMax, bool reduceInsteadOfOverwrite = true) {
167 if (reduceInsteadOfOverwrite) {
168 _minTimeStepSize = std::min(_minTimeStepSize, dtMin);
169 _maxTimeStepSize = std::max(_maxTimeStepSize, dtMax);
170 } else {
171 _minTimeStepSize = dtMin;
172 _maxTimeStepSize = dtMax;
173 }
174 }
175
183 inline void setVelocity(double vMin, double vMax, double rMin, double rMax) {
185 _minVelocity = std::min(_minVelocity, vMin);
186 _maxVelocity = std::max(_maxVelocity, vMax);
187 _minSearchRadius = std::min(_minSearchRadius, rMin);
188 _maxSearchRadius = std::max(_maxSearchRadius, rMax);
189 logDebug("setVelocity()", vMin << "x" << vMax);
190 }
191
196 inline void startTimeStep() {}
197
203 inline void finishTimeStep() {}
204
205 inline void clearSearchRadius() {
206 _minSearchRadius = std::numeric_limits<double>::max();
207 _maxSearchRadius = 0.0;
208 }
209
210 inline void clearVelocity() {
211 _minVelocity = std::numeric_limits<double>::max();
212 _maxVelocity = 0.0;
213 }
214
227 _minTimeStepSize = std::numeric_limits<double>::max();
228 _maxTimeStepSize = 0.0;
229
230 _minTimeStamp = std::numeric_limits<double>::max();
231 _maxTimeStamp = 0.0;
232 }
233
234 inline void allReduce() {
235#ifdef Parallel
236
237 double localMinTimeStepSize = _minTimeStepSize;
238 double localMaxTimeStepSize = _maxTimeStepSize;
239
240 double localMinTimeStamp = _minTimeStamp;
241 double localMaxTimeStamp = _maxTimeStamp;
242
243 double localMinSearchRadius = _minSearchRadius;
244 double localMaxSearchRadius = _maxSearchRadius;
245
246 double localMinVelocity = _minVelocity;
247 double localMaxVelocity = _maxVelocity;
248
249 int localRerunPreviousGridSweep = _rerunPreviousGridSweep ? 1 : 0;
250 int globalRerunPreviousGridSweep = 0;
251
253 .allReduce(&localMinTimeStepSize, &_minTimeStepSize, 1, MPI_DOUBLE, MPI_MIN, [&]() -> void {
255 });
257 .allReduce(&localMaxTimeStepSize, &_maxTimeStepSize, 1, MPI_DOUBLE, MPI_MAX, [&]() -> void {
259 });
260 tarch::mpi::Rank::getInstance().allReduce(&localMinTimeStamp, &_minTimeStamp, 1, MPI_DOUBLE, MPI_MIN, [&]() -> void {
262 });
263 tarch::mpi::Rank::getInstance().allReduce(&localMaxTimeStamp, &_maxTimeStamp, 1, MPI_DOUBLE, MPI_MAX, [&]() -> void {
265 });
267 .allReduce(&localMinSearchRadius, &_minSearchRadius, 1, MPI_DOUBLE, MPI_MIN, [&]() -> void {
269 });
271 .allReduce(&localMaxSearchRadius, &_maxSearchRadius, 1, MPI_DOUBLE, MPI_MAX, [&]() -> void {
273 });
274 tarch::mpi::Rank::getInstance().allReduce(&localMinVelocity, &_minVelocity, 1, MPI_DOUBLE, MPI_MIN, [&]() -> void {
276 });
277 tarch::mpi::Rank::getInstance().allReduce(&localMaxVelocity, &_maxVelocity, 1, MPI_DOUBLE, MPI_MAX, [&]() -> void {
279 });
281 .allReduce(&localRerunPreviousGridSweep, &globalRerunPreviousGridSweep, 1, MPI_INT, MPI_SUM, [&]() -> void {
283 });
284 _rerunPreviousGridSweep = globalRerunPreviousGridSweep > 0;
285
286#endif
287 }
288};
#define logDebug(methodName, logMacroMessageStream)
Definition Log.h:51
Represent one type (species) of particles.
void clearRerunPreviousGridSweepFlag()
Set the rerun flag back to false.
ParticleSpecies()
Initialise all data with the data corresponding to a clear, i.e.
void startTimeStep()
This routine is automatically called for each and every species by the GlobalState object.
void clearTimeStampAndTimeStepSize()
Clear all the time step sizes and time stamps.
void setTimeStepSize(double dtMin, double dtMax, bool reduceInsteadOfOverwrite=true)
static tarch::logging::Log _log
double getMinSearchRadius() const
static tarch::multicore::BooleanSemaphore _semaphore
void setRerunPreviousGridSweep()
Tell Peano to run through mesh with same action sets again.
double getMaxSearchRadius() const
void setTimeStamp(double tMin, double tMax, bool reduceInsteadOfOverwrite=true)
void finishTimeStep()
This routine is automatically called for each and every species by the GlobalState object.
double getMinTimeStepSize() const
double getMaxTimeStepSize() const
void setTimeStamp(double t, bool reduceInsteadOfOverwrite=true)
Set both min and max time stamp.
bool rerunPreviousGridSweep() const
Query species whether the last grid sweep/update sweep has to be repeated.
void setTimeStepSize(double dt, bool reduceInsteadOfOverwrite=true)
void setVelocity(double vMin, double vMax, double rMin, double rMax)
Set the maximum velocity that has been observed in a cell.
ParticleSpecies(const ParticleSpecies &copy)=delete
Log Device.
Definition Log.h:517
static Rank & getInstance()
This operation returns the singleton instance.
void allReduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, std::function< void()> waitor=[]() -> void {})
Create a lock around a boolean semaphore region.
Definition Lock.h:19
static ServiceRepository & getInstance()
virtual void receiveDanglingMessages() override
Answer to MPI Messages.
This file is part of the ExaParty project.
Definition __init__.py:1