Peano 4
Loading...
Searching...
No Matches
ParticleSpecies.cpp
Go to the documentation of this file.
1#include "ParticleSpecies.h"
2
3#include <limits>
4
5#include "tarch/Assertions.h"
6#include "tarch/mpi/Rank.h"
9
11tarch::logging::Log swift2::ParticleSpecies::_log("swift2::ParticleSpecies");
12
14 _minTimeStepSize(std::numeric_limits<double>::max()),
16 _minTimeStamp(0.0), // std::numeric_limits<double>::max()
17 _maxTimeStamp(0.0),
18 _minSearchRadius(std::numeric_limits<double>::max()),
19 _maxSearchRadius(0.0),
20 _minVelocity(std::numeric_limits<double>::max()),
21 _maxVelocity(0.0),
22 _rerunPreviousGridSweep(false) {}
23
24void swift2::ParticleSpecies::setTimeStamp(double t, bool reduceInsteadOfOverwrite) {
25 setTimeStamp(t, t, reduceInsteadOfOverwrite);
26}
27
28void swift2::ParticleSpecies::setTimeStamp(double tMin, double tMax, bool reduceInsteadOfOverwrite) {
29 tarch::multicore::Lock lock(_semaphore);
30 if (reduceInsteadOfOverwrite) {
31 _minTimeStamp = std::min(_minTimeStamp, tMin);
32 _maxTimeStamp = std::max(_maxTimeStamp, tMax);
33 } else {
34 _minTimeStamp = tMin;
35 _maxTimeStamp = tMax;
36 }
37}
38
39void swift2::ParticleSpecies::setTimeStepSize(double dt, bool reduceInsteadOfOverwrite) {
40 setTimeStepSize(dt, dt, reduceInsteadOfOverwrite);
41}
42
43bool swift2::ParticleSpecies::rerunPreviousGridSweep() const { return _rerunPreviousGridSweep; }
44
45void swift2::ParticleSpecies::clearRerunPreviousGridSweepFlag() { _rerunPreviousGridSweep = false; }
46
48 tarch::multicore::Lock lock(_semaphore);
49 _rerunPreviousGridSweep = true;
50}
51
52void swift2::ParticleSpecies::setTimeStepSize(double dtMin, double dtMax, bool reduceInsteadOfOverwrite) {
53 tarch::multicore::Lock lock(_semaphore);
54 if (reduceInsteadOfOverwrite) {
55 _minTimeStepSize = std::min(_minTimeStepSize, dtMin);
56 _maxTimeStepSize = std::max(_maxTimeStepSize, dtMax);
57 } else {
58 _minTimeStepSize = dtMin;
59 _maxTimeStepSize = dtMax;
60 }
61}
62
64
66
68
70
71double swift2::ParticleSpecies::getMinSearchRadius() const { return _minSearchRadius; }
72
73double swift2::ParticleSpecies::getMaxSearchRadius() const { return _maxSearchRadius; }
74
75double swift2::ParticleSpecies::getMinVelocity() const { return _minVelocity; }
76
77double swift2::ParticleSpecies::getMaxVelocity() const { return _maxVelocity; }
78
79void swift2::ParticleSpecies::setVelocity(double vMin, double vMax, double rMin, double rMax) {
80 tarch::multicore::Lock lock(_semaphore);
81 _minVelocity = std::min(_minVelocity, vMin);
82 _maxVelocity = std::max(_maxVelocity, vMax);
83 _minSearchRadius = std::min(_minSearchRadius, rMin);
84 _maxSearchRadius = std::max(_maxSearchRadius, rMax);
85 logDebug("setVelocity()", vMin << "x" << vMax);
86}
87
89 _minSearchRadius = std::numeric_limits<double>::max();
90 _maxSearchRadius = 0.0;
91}
92
94 _minVelocity = std::numeric_limits<double>::max();
95 _maxVelocity = 0.0;
96}
97
99 _minTimeStepSize = std::numeric_limits<double>::max();
100 _maxTimeStepSize = 0.0;
101
102 _minTimeStamp = std::numeric_limits<double>::max();
103 _maxTimeStamp = 0.0;
104}
105
107
109
111#ifdef Parallel
112
113 double localMinTimeStepSize = _minTimeStepSize;
114 double localMaxTimeStepSize = _maxTimeStepSize;
115
116 double localMinTimeStamp = _minTimeStamp;
117 double localMaxTimeStamp = _maxTimeStamp;
118
119 double localMinSearchRadius = _minSearchRadius;
120 double localMaxSearchRadius = _maxSearchRadius;
121
122 double localMinVelocity = _minVelocity;
123 double localMaxVelocity = _maxVelocity;
124
125 int localRerunPreviousGridSweep = _rerunPreviousGridSweep ? 1 : 0;
126 int globalRerunPreviousGridSweep = 0;
127
129 .allReduce(&localMinTimeStepSize, &_minTimeStepSize, 1, MPI_DOUBLE, MPI_MIN, [&]() -> void {
131 });
133 .allReduce(&localMaxTimeStepSize, &_maxTimeStepSize, 1, MPI_DOUBLE, MPI_MAX, [&]() -> void {
135 });
136 tarch::mpi::Rank::getInstance().allReduce(&localMinTimeStamp, &_minTimeStamp, 1, MPI_DOUBLE, MPI_MIN, [&]() -> void {
138 });
139 tarch::mpi::Rank::getInstance().allReduce(&localMaxTimeStamp, &_maxTimeStamp, 1, MPI_DOUBLE, MPI_MAX, [&]() -> void {
141 });
143 .allReduce(&localMinSearchRadius, &_minSearchRadius, 1, MPI_DOUBLE, MPI_MIN, [&]() -> void {
145 });
147 .allReduce(&localMaxSearchRadius, &_maxSearchRadius, 1, MPI_DOUBLE, MPI_MAX, [&]() -> void {
149 });
150 tarch::mpi::Rank::getInstance().allReduce(&localMinVelocity, &_minVelocity, 1, MPI_DOUBLE, MPI_MIN, [&]() -> void {
152 });
153 tarch::mpi::Rank::getInstance().allReduce(&localMaxVelocity, &_maxVelocity, 1, MPI_DOUBLE, MPI_MAX, [&]() -> void {
155 });
157 .allReduce(&localRerunPreviousGridSweep, &globalRerunPreviousGridSweep, 1, MPI_INT, MPI_SUM, [&]() -> void {
159 });
160 _rerunPreviousGridSweep = globalRerunPreviousGridSweep > 0;
161
162#endif
163}
#define logDebug(methodName, logMacroMessageStream)
Definition Log.h:50
_minTimeStepSize(std::numeric_limits< double >::max())
_minTimeStamp(0.0)
_maxTimeStamp(0.0)
_maxTimeStepSize(0.0)
void finishTimeStep()
This routine is automatically called for each and every species by the GlobalState object.
bool rerunPreviousGridSweep() const
Query species whether the last grid sweep/update sweep has to be repeated.
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 setTimeStamp(double t, bool reduceInsteadOfOverwrite=true)
Set both min and max time stamp.
static tarch::multicore::BooleanSemaphore _semaphore
static tarch::logging::Log _log
double getMinSearchRadius() const
double getMinTimeStepSize() const
void setVelocity(double vMin, double vMax, double rMin, double rMax)
Set the maximum velocity that has been observed in a cell.
void clearRerunPreviousGridSweepFlag()
Set the rerun flag back to false.
void setTimeStepSize(double dt, bool reduceInsteadOfOverwrite=true)
void setRerunPreviousGridSweep()
Tell Peano to run through mesh with same action sets again.
double getMaxTimeStepSize() const
double getMaxSearchRadius() const
Log Device.
Definition Log.h:516
static Rank & getInstance()
This operation returns the singleton instance.
Definition Rank.cpp:538
void allReduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, std::function< void()> waitor=[]() -> void {})
Definition Rank.cpp:279
Create a lock around a boolean semaphore region.
Definition Lock.h:19
virtual void receiveDanglingMessages() override
Answer to MPI Messages.
static ServiceRepository & getInstance()
STL namespace.