Peano
Loading...
Searching...
No Matches
OneSweepPerRungeKuttaStepAbstract.template.cpp
Go to the documentation of this file.
1// **********************************************************************************************
2// *** !!!WARNING!!! ***
3// *** WARNING: AUTO GENERATED FILE! DO NOT MODIFY BY HAND! YOUR CHANGES WILL BE OVERWRITTEN! ***
4// *** !!!WARNING!!! ***
5// *** Generated by Peano's Python API: www.peano-framework.org ***
6// **********************************************************************************************
7#include "{{CLASSNAME}}.h"
8#include "Constants.h"
9
10#include <algorithm>
11
14
15
16tarch::logging::Log {{NAMESPACE | join("::")}}::{{CLASSNAME}}::{{CLASSNAME}}::_log( "{{NAMESPACE | join("::")}}::{{CLASSNAME}}::{{CLASSNAME}}" );
17
18std::bitset<Dimensions> {{NAMESPACE | join("::")}}::{{CLASSNAME}}::{{CLASSNAME}}::PeriodicBC = {{NAMESPACE | join("::")}}::PeriodicBC;
19
20
21{{NAMESPACE | join("::")}}::{{CLASSNAME}}::{{CLASSNAME}}():
22 _solverState(SolverState::GridConstruction),
27 // This way, we still compute the patch size without an overflow
28 _minGridCellH(std::numeric_limits<double>::max()/NumberOfGridCellsPerPatchPerAxis/2.0),
30 _minGridCellHThisTimeStep(std::numeric_limits<double>::max()/NumberOfGridCellsPerPatchPerAxis/2.0),
32 _minTimeStepSize(std::numeric_limits<double>::max()),
34 _minTimeStepSizeThisTimeStep(std::numeric_limits<double>::max()),
37 {{CONSTRUCTOR_IMPLEMENTATION}}
38}
39
40
41double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMaxMeshSize() const {
42 return getMaxPatchSize();
43}
44
45
46double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMinMeshSize() const {
47 return getMinPatchSize();
48}
49
50
51double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMinPatchSize(bool ofCurrentlyRunningGridSweep) const {
52 return getMinGridCellSize(ofCurrentlyRunningGridSweep) * NumberOfGridCellsPerPatchPerAxis;
53}
54
55
56double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMaxPatchSize(bool ofCurrentlyRunningGridSweep) const {
57 return getMaxGridCellSize(ofCurrentlyRunningGridSweep) * NumberOfGridCellsPerPatchPerAxis;
58}
59
60
61double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMinGridCellSize(bool ofCurrentlyRunningGridSweep) const {
62 return ofCurrentlyRunningGridSweep ? _minGridCellHThisTimeStep : _minGridCellH;
63}
64
65
66double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMaxGridCellSize(bool ofCurrentlyRunningGridSweep) const {
67 return ofCurrentlyRunningGridSweep ? _maxGridCellHThisTimeStep : _maxGridCellH;
68}
69
70
71double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMinTimeStamp(bool ofCurrentlyRunningGridSweep) const {
72 return ofCurrentlyRunningGridSweep ? _minTimeStampThisTimeStep : _minTimeStamp;
73}
74
75
76double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMaxTimeStamp(bool ofCurrentlyRunningGridSweep) const {
77 return ofCurrentlyRunningGridSweep ? _maxTimeStampThisTimeStep : _maxTimeStamp;
78}
79
80
81double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMinTimeStepSize() const {
82 return _minTimeStepSize;
83}
84
85
86double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMaxTimeStepSize() const {
87 return _maxTimeStepSize;
88}
89
90
91void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::suspendSolversForOneGridSweep() {
92 _solverState = SolverState::Suspended;
93}
94
95
96void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::update(double timeStepSize, double timeStamp, double patchSize) {
97 tarch::multicore::Lock lock(_semaphore);
98
99 if ( tarch::la::greater(timeStepSize,0.0) ) {
100 assertion1(timeStepSize<std::numeric_limits<double>::max()/10.0,timeStepSize);
101 assertion1(timeStepSize>=0.0,timeStepSize);
105
107
108 _localMinTimeStampThisTimeStep = std::min(_localMinTimeStampThisTimeStep, timeStamp);
109 _localMaxTimeStampThisTimeStep = std::max(_localMaxTimeStampThisTimeStep, timeStamp);
110 }
111
112 assertion1(timeStamp<std::numeric_limits<double>::max()/10.0,timeStamp);
113 assertion1(timeStamp>=0.0,timeStamp);
116 // This assertion makes sense, but if we reset the time stamp size (in couple systems) then
117 // it is valid.
118 // assertion6( tarch::la::smallerEquals(_minTimeStamp,_maxTimeStampThisTimeStep), _minTimeStamp, _minTimeStampThisTimeStep, _maxTimeStampThisTimeStep, timeStepSize, timeStamp, patchSize );
119
120 assertion1(patchSize<std::numeric_limits<double>::max()/NumberOfGridCellsPerPatchPerAxis,patchSize);
121 assertion1(patchSize>0.0,patchSize);
122 _maxGridCellHThisTimeStep = std::max(_maxGridCellHThisTimeStep,patchSize / NumberOfGridCellsPerPatchPerAxis);
123 _minGridCellHThisTimeStep = std::min(_minGridCellHThisTimeStep,patchSize / NumberOfGridCellsPerPatchPerAxis);
124
125 logDebug( "update(double,double,double)", "updated with dt=" << timeStepSize << ", t=" << timeStamp << ", h=" << patchSize << ": t(new)=" << _minTimeStampThisTimeStep );
126}
127
128
129{{NAMESPACE | join("::")}}::{{CLASSNAME}}::SolverState {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getSolverState() const {
130 return _solverState;
131}
132
133
134{% if REFINEMENT_CRITERION_IMPLEMENTATION!="<user-defined>" %}
135::exahype2::RefinementCommand {{NAMESPACE | join("::")}}::{{CLASSNAME}}::refinementCriterion(
136 const double * __restrict__ Q, // Q[{{NUMBER_OF_UNKNOWNS}}+{{NUMBER_OF_AUXILIARY_VARIABLES}}],
137 const tarch::la::Vector<Dimensions,double>& meshCellCentre,
139 double t
140) {
141 {% if REFINEMENT_CRITERION_IMPLEMENTATION=="<empty>" %}
143
144
145 return result;
146 {% else %}
147 {{REFINEMENT_CRITERION_IMPLEMENTATION}}
148 {% endif %}
149}
150{% endif %}
151
152
153{% if INITIAL_CONDITIONS_IMPLEMENTATION!="<user-defined>" %}
154void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::initialCondition(
155 double * __restrict__ Q,
156 const tarch::la::Vector<Dimensions,double>& meshCellCentre,
158 bool gridIsConstructed
159) {
160 {{INITIAL_CONDITIONS_IMPLEMENTATION}}
161}
162{% endif %}
163
164
165{% if BOUNDARY_CONDITIONS_IMPLEMENTATION!="<user-defined>" and BOUNDARY_CONDITIONS_IMPLEMENTATION!="<none>" %}
166void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::boundaryConditions(
167 const double * __restrict__ Qinside, // Qinside[{{NUMBER_OF_UNKNOWNS}}+{{NUMBER_OF_AUXILIARY_VARIABLES}}]
168 double * __restrict__ Qoutside, // Qoutside[{{NUMBER_OF_UNKNOWNS}}+{{NUMBER_OF_AUXILIARY_VARIABLES}}]
169 const tarch::la::Vector<Dimensions,double>& faceCentre,
171 double t,
172 int normal
173) {
174 {% if BOUNDARY_CONDITIONS_IMPLEMENTATION!="<empty>" %}
175 {{BOUNDARY_CONDITIONS_IMPLEMENTATION}}
176 {% endif %}
177}
178{% endif %}
179
180
181void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startGridConstructionStep() {
182 assertion( _solverState == SolverState::GridConstruction );
183}
184
185
186void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishGridConstructionStep() {
187}
188
189
190void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startGridInitialisationStep() {
191 _solverState = SolverState::GridInitialisation;
192}
193
194
195void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishGridInitialisationStep() {
196}
197
198
199void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startTimeStep(
200 double globalMinTimeStamp,
201 double globalMaxTimeStamp,
202 double globalMinTimeStepSize,
203 double globalMaxTimeStepSize
204) {
205 switch (_solverState) {
206 case SolverState::GridConstruction:
207 _solverState = SolverState::GridInitialisation;
208 break;
209 {% for item in range(RK_STEPS-1) %}
210 case SolverState::RungeKuttaSubStep{{item}}:
211 _solverState = SolverState::RungeKuttaSubStep{{item+1}};
212 break;
213 {% endfor %}
214 case SolverState::Suspended:
215 case SolverState::Plotting:
216 case SolverState::PlottingAfterGridInitialisation:
217 case SolverState::GridInitialisation:
218 case SolverState::RungeKuttaSubStep{{RK_STEPS-1}}:
219 _solverState = SolverState::RungeKuttaSubStep0;
220 break;
221 {% if RK_STEPS>1 %}
222 case SolverState::RungeKuttaSubStep0AfterGridInitialisation:
223 _solverState = SolverState::RungeKuttaSubStep1;
224 break;
225 {% else %}
226 case SolverState::RungeKuttaSubStep0AfterGridInitialisation:
227 _solverState = SolverState::RungeKuttaSubStep0;
228 break;
229 {% endif %}
230 }
231
232 {{START_TIME_STEP_IMPLEMENTATION}}
233
234 if ( isFirstGridSweepOfTimeStep() ) {
237
238 _minTimeStampThisTimeStep = std::numeric_limits<double>::max();
239 _maxTimeStampThisTimeStep = std::numeric_limits<double>::min();
240
243
244 _minTimeStepSizeThisTimeStep = std::numeric_limits<double>::max();
245 _maxTimeStepSizeThisTimeStep = std::numeric_limits<double>::min();
246
249
251 _minGridCellHThisTimeStep = std::numeric_limits<double>::max()/NumberOfGridCellsPerPatchPerAxis/2.0;
252
253 _localMinTimeStampThisTimeStep = std::numeric_limits<double>::max();
254 _localMaxTimeStampThisTimeStep = std::numeric_limits<double>::min();
255
256 _patchUpdates = 0;
257 }
258}
259
260
261void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishTimeStep() {
262 if ( isLastGridSweepOfTimeStep() ) {
263
264 #ifdef Parallel
265 double newMinTimeStamp = _minTimeStampThisTimeStep;
266 double newMaxTimeStamp = _maxTimeStampThisTimeStep;
267 double newMinGridCellH = _minGridCellHThisTimeStep;
268 double newMaxGridCellH = _maxGridCellHThisTimeStep;
269 double newMinTimeStepSize = _minTimeStepSizeThisTimeStep;
270 double newMaxTimeStepSize = _maxTimeStepSizeThisTimeStep;
271
272 double newLocalMinTimeStamp = _localMinTimeStampThisTimeStep;
273 double newLocalMaxTimeStamp = _localMaxTimeStampThisTimeStep;
274
275 int newPatchUpdates = _patchUpdates;
276
278 &newMinTimeStamp,
280 1, MPI_DOUBLE,
281 MPI_MIN,
283 );
285 &newMaxTimeStamp,
287 1, MPI_DOUBLE,
288 MPI_MAX,
290 );
291
293 &newMinGridCellH,
295 1, MPI_DOUBLE,
296 MPI_MIN,
298 );
300 &newMaxGridCellH,
302 1, MPI_DOUBLE,
303 MPI_MAX,
305 );
306
308 &newMinTimeStepSize,
310 1, MPI_DOUBLE,
311 MPI_MIN,
313 );
315 &newMaxTimeStepSize,
317 1, MPI_DOUBLE,
318 MPI_MAX,
320 );
321
323 &newLocalMinTimeStamp,
324 &_localMinTimeStampThisTimeStep,
325 1, MPI_DOUBLE,
326 MPI_MIN,
328 );
330 &newLocalMaxTimeStamp,
331 &_localMaxTimeStampThisTimeStep,
332 1, MPI_DOUBLE,
333 MPI_MAX,
335 );
336
338 &newPatchUpdates,
340 1, MPI_INT,
341 MPI_SUM,
343 );
344 #endif
345
346 if ( _minTimeStampThisTimeStep>=std::numeric_limits<double>::max()/10.0) {
348 }
349 if ( _maxTimeStampThisTimeStep>=std::numeric_limits<double>::max()/10.0 ) {
351 }
352 }
353
354 {{FINISH_TIME_STEP_IMPLEMENTATION}}
355}
356
357
358void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startPlottingStep(
359 double globalMinTimeStamp,
360 double globalMaxTimeStamp,
361 double globalMinTimeStepSize,
362 double globalMaxTimeStepSize
363) {
364 if ( _solverState==SolverState::GridInitialisation ) {
365 _solverState = SolverState::PlottingAfterGridInitialisation;
366 }
367 else {
368 _solverState = SolverState::Plotting;
369 }
370}
371
372
373void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishPlottingStep() {
374}
375
376
377std::string {{NAMESPACE | join("::")}}::{{CLASSNAME}}::toString(SolverState state) {
378 switch (state) {
379 case SolverState::GridConstruction:
380 return "grid-construction";
381 case SolverState::Suspended:
382 return "suspended";
383 case SolverState::GridInitialisation:
384 return "grid-initialisation";
385 case SolverState::Plotting:
386 return "plotting";
387 case SolverState::PlottingAfterGridInitialisation:
388 return "plotting-after-grid-initialisation";
389 case SolverState::RungeKuttaSubStep0AfterGridInitialisation:
390 return "runge-kutta-step-0-after-grid-initialisation";
391 {% for item in range(RK_STEPS) %}
392 case SolverState::RungeKuttaSubStep{{item}}:
393 return "runge-kutta-step-{{item}}";
394 break;
395 {%- endfor %}
396 }
397 return "<undef>";
398}
399
400
401bool {{NAMESPACE | join("::")}}::{{CLASSNAME}}::mayPlot() const {
402 return isLastGridSweepOfTimeStep()
403 or _solverState==SolverState::GridInitialisation
404 or _solverState==SolverState::Plotting;
405}
406
407
408bool {{NAMESPACE | join("::")}}::{{CLASSNAME}}::isFirstGridSweepOfTimeStep() const {
409 return _solverState==SolverState::RungeKuttaSubStep0
410 or _solverState==SolverState::RungeKuttaSubStep0AfterGridInitialisation;
411}
412
413
414bool {{NAMESPACE | join("::")}}::{{CLASSNAME}}::isLastGridSweepOfTimeStep() const {
415 return _solverState==SolverState::RungeKuttaSubStep{{RK_STEPS-1}};
416}
417
418
419{{ABSTRACT_SOLVER_USER_DEFINITIONS}}
420
421
422
423void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startSimulation() {
424
425}
426
427
428void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishSimulation() {
429
430}
431
432
#define assertion2(expr, param0, param1)
#define assertion1(expr, param)
#define assertion(expr)
AutomatonState state
#define logDebug(methodName, logMacroMessageStream)
Definition Log.h:50
_maxTimeStampThisTimeStep(0.0)
_minTimeStepSize(std::numeric_limits< double >::max())
_minGridCellHThisTimeStep(std::numeric_limits< double >::max()/NumberOfGridCellsPerPatchPerAxis/2.0)
_minTimeStamp(0.0)
_maxTimeStepSizeThisTimeStep(0.0)
_maxTimeStamp(0.0)
_maxGridCellHThisTimeStep(0.0)
_minTimeStampThisTimeStep(0.0)
_minTimeStepSizeThisTimeStep(std::numeric_limits< double >::max())
_maxTimeStepSize(0.0)
_minGridCellH(std::numeric_limits< double >::max()/NumberOfGridCellsPerPatchPerAxis/2.0)
_maxGridCellH(0.0)
Log Device.
Definition Log.h:516
static Rank & getInstance()
This operation returns the singleton instance.
Definition Rank.cpp:539
void allReduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, std::function< void()> waitor=[]() -> void {})
Definition Rank.cpp:284
Create a lock around a boolean semaphore region.
Definition Lock.h:19
virtual void receiveDanglingMessages() override
Answer to MPI Messages.
static ServiceRepository & getInstance()
std::string toString(Filter filter)
Definition convert.cpp:170
tarch::logging::Log _log("exahype2::fv")
STL namespace.
bool greater(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
Simple vector class.
Definition Vector.h:150