Peano
Loading...
Searching...
No Matches
SeparateSweepsAbstract.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
90void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::suspendSolversForOneGridSweep() {}
91
92
93void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::update(double timeStepSize, double timeStamp, double patchSize) {
94 tarch::multicore::Lock lock(_semaphore);
95
96 if ( tarch::la::greater(timeStepSize,0.0) ) {
97 assertion1(timeStepSize<std::numeric_limits<double>::max()/10.0,timeStepSize);
98 assertion1(timeStepSize>=0.0,timeStepSize);
102
104
105 _localMinTimeStampThisTimeStep = std::min(_localMinTimeStampThisTimeStep, timeStamp);
106 _localMaxTimeStampThisTimeStep = std::max(_localMaxTimeStampThisTimeStep, timeStamp);
107 }
108
109 assertion1(timeStamp<std::numeric_limits<double>::max()/10.0,timeStamp);
110 assertion1(timeStamp>=0.0,timeStamp);
113 // This assertion makes sense, but if we reset the time stamp size (in couple systems) then
114 // it is valid.
115 // assertion6( tarch::la::smallerEquals(_minTimeStamp,_maxTimeStampThisTimeStep), _minTimeStamp, _minTimeStampThisTimeStep, _maxTimeStampThisTimeStep, timeStepSize, timeStamp, patchSize );
116
117 assertion1(patchSize<std::numeric_limits<double>::max()/NumberOfGridCellsPerPatchPerAxis,patchSize);
118 assertion1(patchSize>0.0,patchSize);
119 _maxGridCellHThisTimeStep = std::max(_maxGridCellHThisTimeStep,patchSize / NumberOfGridCellsPerPatchPerAxis);
120 _minGridCellHThisTimeStep = std::min(_minGridCellHThisTimeStep,patchSize / NumberOfGridCellsPerPatchPerAxis);
121
122 logDebug( "update(double,double,double)", "updated with dt=" << timeStepSize << ", t=" << timeStamp << ", h=" << patchSize << ": t(new)=" << _minTimeStampThisTimeStep );
123}
124
125
126{{NAMESPACE | join("::")}}::{{CLASSNAME}}::SolverState {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getSolverState() const {
127 return _solverState;
128}
129
130
131{% if REFINEMENT_CRITERION_IMPLEMENTATION!="<user-defined>" %}
132::exahype2::RefinementCommand {{NAMESPACE | join("::")}}::{{CLASSNAME}}::refinementCriterion(
133 const double * __restrict__ Q, // Q[{{NUMBER_OF_UNKNOWNS}}+{{NUMBER_OF_AUXILIARY_VARIABLES}}],
134 const tarch::la::Vector<Dimensions,double>& meshCellCentre,
136 double t
137) {
138 {% if REFINEMENT_CRITERION_IMPLEMENTATION=="<empty>" %}
140
141
142 return result;
143 {% else %}
144 {{REFINEMENT_CRITERION_IMPLEMENTATION}}
145 {% endif %}
146}
147{% endif %}
148
149
150{% if INITIAL_CONDITIONS_IMPLEMENTATION!="<user-defined>" %}
151void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::initialCondition(
152 double * __restrict__ Q,
153 const tarch::la::Vector<Dimensions,double>& meshCellCentre,
155 bool gridIsConstructed
156) {
157 {{INITIAL_CONDITIONS_IMPLEMENTATION}}
158}
159{% endif %}
160
161
162{% if BOUNDARY_CONDITIONS_IMPLEMENTATION!="<user-defined>" and BOUNDARY_CONDITIONS_IMPLEMENTATION!="<none>" %}
163void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::boundaryConditions(
164 const double * __restrict__ Qinside, // Qinside[{{NUMBER_OF_UNKNOWNS}}+{{NUMBER_OF_AUXILIARY_VARIABLES}}]
165 double * __restrict__ Qoutside, // Qoutside[{{NUMBER_OF_UNKNOWNS}}+{{NUMBER_OF_AUXILIARY_VARIABLES}}]
166 const tarch::la::Vector<Dimensions,double>& faceCentre,
168 double t,
169 int normal
170) {
171 {% if BOUNDARY_CONDITIONS_IMPLEMENTATION!="<empty>" %}
172 {{BOUNDARY_CONDITIONS_IMPLEMENTATION}}
173 {% endif %}
174}
175{% endif %}
176
177
178void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startGridConstructionStep() {
179 assertion( _solverState == SolverState::GridConstruction );
180}
181
182
183void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishGridConstructionStep() {
184}
185
186
187void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startGridInitialisationStep() {
188 _solverState = SolverState::GridInitialisation;
189}
190
191
192void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishGridInitialisationStep() {
193}
194
195
196void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startTimeStep(
197 double globalMinTimeStamp,
198 double globalMaxTimeStamp,
199 double globalMinTimeStepSize,
200 double globalMaxTimeStepSize
201) {
202 switch (_solverState) {
203 case SolverState::GridConstruction:
204 _solverState = SolverState::GridInitialisation;
205 break;
206 {% if RECONSTRUCTION_STAGES==0 %}
207 {% for item in range(RK_STEPS-1) %}
208 case SolverState::RungeKuttaSubStep{{item}}:
209 _solverState = SolverState::RungeKuttaSubStep{{item+1}};
210 break;
211 {% endfor %}
212 {% else %}
213 {% for item in range(RK_STEPS-1) %}
214 case SolverState::ReconstructionSubStep{{item}}:
215 _solverState = SolverState::RungeKuttaSubStep{{item}};
216 break;
217 case SolverState::RungeKuttaSubStep{{item}}:
218 _solverState = SolverState::ReconstructionSubStep{{item+1}};
219 break;
220 {% endfor %}
221 case SolverState::ReconstructionSubStep{{RK_STEPS-1}}:
222 _solverState = SolverState::RungeKuttaSubStep{{RK_STEPS-1}};
223 break;
224 {% endif %}
225 case SolverState::Suspended:
226 case SolverState::Plotting:
227 case SolverState::PlottingAfterGridInitialisation:
228 case SolverState::GridInitialisation:
229 case SolverState::RungeKuttaSubStep{{RK_STEPS-1}}:
230 {% if RECONSTRUCTION_STAGES==0 %}
231 _solverState = SolverState::RungeKuttaSubStep0;
232 {% else %}
233 _solverState = SolverState::ReconstructionSubStep0;
234 {% endif %}
235 break;
236 {% if RK_STEPS>1 %}
237 case SolverState::RungeKuttaSubStep0AfterGridInitialisation:
238 {% if RECONSTRUCTION_STAGES==0 %}
239 _solverState = SolverState::RungeKuttaSubStep1;
240 {% else %}
241 _solverState = SolverState::ReconstructionSubStep1;
242 {% endif %}
243 break;
244 {% else %}
245 case SolverState::RungeKuttaSubStep0AfterGridInitialisation:
246 {% if RECONSTRUCTION_STAGES==0 %}
247 _solverState = SolverState::RungeKuttaSubStep0;
248 {% else %}
249 _solverState = SolverState::ReconstructionSubStep0;
250 {% endif %}
251 break;
252 {% endif %}
253 }
254
255 {{START_TIME_STEP_IMPLEMENTATION}}
256
257 if ( isFirstGridSweepOfTimeStep() ) {
260
261 _minTimeStampThisTimeStep = std::numeric_limits<double>::max();
262 _maxTimeStampThisTimeStep = std::numeric_limits<double>::min();
263
266
267 _minTimeStepSizeThisTimeStep = std::numeric_limits<double>::max();
268 _maxTimeStepSizeThisTimeStep = std::numeric_limits<double>::min();
269
272
274 _minGridCellHThisTimeStep = std::numeric_limits<double>::max()/NumberOfGridCellsPerPatchPerAxis/2.0;
275
276 _localMinTimeStampThisTimeStep = std::numeric_limits<double>::max();
277 _localMaxTimeStampThisTimeStep = std::numeric_limits<double>::min();
278
279 _patchUpdates = 0;
280 }
281}
282
283
284void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishTimeStep() {
285 if ( isLastGridSweepOfTimeStep() ) {
286
287 #ifdef Parallel
288 double newMinTimeStamp = _minTimeStampThisTimeStep;
289 double newMaxTimeStamp = _maxTimeStampThisTimeStep;
290 double newMinGridCellH = _minGridCellHThisTimeStep;
291 double newMaxGridCellH = _maxGridCellHThisTimeStep;
292 double newMinTimeStepSize = _minTimeStepSizeThisTimeStep;
293 double newMaxTimeStepSize = _maxTimeStepSizeThisTimeStep;
294
295 double newLocalMinTimeStamp = _localMinTimeStampThisTimeStep;
296 double newLocalMaxTimeStamp = _localMaxTimeStampThisTimeStep;
297
298 int newPatchUpdates = _patchUpdates;
299
301 &newMinTimeStamp,
303 1, MPI_DOUBLE,
304 MPI_MIN,
306 );
308 &newMaxTimeStamp,
310 1, MPI_DOUBLE,
311 MPI_MAX,
313 );
314
316 &newMinGridCellH,
318 1, MPI_DOUBLE,
319 MPI_MIN,
321 );
323 &newMaxGridCellH,
325 1, MPI_DOUBLE,
326 MPI_MAX,
328 );
329
331 &newMinTimeStepSize,
333 1, MPI_DOUBLE,
334 MPI_MIN,
336 );
338 &newMaxTimeStepSize,
340 1, MPI_DOUBLE,
341 MPI_MAX,
343 );
344
346 &newLocalMinTimeStamp,
347 &_localMinTimeStampThisTimeStep,
348 1, MPI_DOUBLE,
349 MPI_MIN,
351 );
353 &newLocalMaxTimeStamp,
354 &_localMaxTimeStampThisTimeStep,
355 1, MPI_DOUBLE,
356 MPI_MAX,
358 );
359
361 &newPatchUpdates,
363 1, MPI_INT,
364 MPI_SUM,
366 );
367 #endif
368
369 if ( _minTimeStampThisTimeStep>=std::numeric_limits<double>::max()/10.0) {
371 }
372 if ( _maxTimeStampThisTimeStep>=std::numeric_limits<double>::max()/10.0 ) {
374 }
375 }
376
377 {{FINISH_TIME_STEP_IMPLEMENTATION}}
378}
379
380
381void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startPlottingStep(
382 double globalMinTimeStamp,
383 double globalMaxTimeStamp,
384 double globalMinTimeStepSize,
385 double globalMaxTimeStepSize
386) {
387 if ( _solverState==SolverState::GridInitialisation ) {
388 _solverState = SolverState::PlottingAfterGridInitialisation;
389 }
390 else {
391 _solverState = SolverState::Plotting;
392 }
393}
394
395
396void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishPlottingStep() {
397}
398
399
400std::string {{NAMESPACE | join("::")}}::{{CLASSNAME}}::toString(SolverState state) {
401 switch (state) {
402 case SolverState::GridConstruction:
403 return "grid-construction";
404 case SolverState::GridInitialisation:
405 return "grid-initialisation";
406 case SolverState::Plotting:
407 return "plotting";
408 case SolverState::Suspended:
409 return "suspended";
410 case SolverState::PlottingAfterGridInitialisation:
411 return "plotting-after-grid-initialisation";
412 case SolverState::RungeKuttaSubStep0AfterGridInitialisation:
413 return "runge-kutta-step-0-after-grid-initialisation";
414 {% for item in range(RK_STEPS) %}
415 case SolverState::RungeKuttaSubStep{{item}}:
416 return "runge-kutta-step-{{item}}";
417 break;
418 {%- endfor %}
419 {% if RECONSTRUCTION_STAGES!=0 %}
420 {% for item in range(RECONSTRUCTION_STAGES) %}
421 case SolverState::ReconstructionSubStep{{item}}:
422 return "reconstruction-step-{{item}}";
423 break;
424 {%- endfor %}
425 {% endif %}
426 }
427 return "<undef>";
428}
429
430
431bool {{NAMESPACE | join("::")}}::{{CLASSNAME}}::mayPlot() const {
432 return isLastGridSweepOfTimeStep()
433 or _solverState==SolverState::GridInitialisation
434 or _solverState==SolverState::Plotting;
435}
436
437
438bool {{NAMESPACE | join("::")}}::{{CLASSNAME}}::isFirstGridSweepOfTimeStep() const {
439 {% if RECONSTRUCTION_STAGES!=0 %}
440 return _solverState==SolverState::ReconstructionSubStep0
441 or _solverState==SolverState::RungeKuttaSubStep0AfterGridInitialisation;
442 {% else %}
443 return _solverState==SolverState::RungeKuttaSubStep0
444 or _solverState==SolverState::RungeKuttaSubStep0AfterGridInitialisation;
445 {% endif %}
446}
447
448
449bool {{NAMESPACE | join("::")}}::{{CLASSNAME}}::isLastGridSweepOfTimeStep() const {
450 return _solverState==SolverState::RungeKuttaSubStep{{RK_STEPS-1}};
451}
452
453
454{{ABSTRACT_SOLVER_USER_DEFINITIONS}}
455
456
457
458void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startSimulation() {
459
460}
461
462
463void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishSimulation() {
464
465}
466
467
#define assertion2(expr, param0, param1)
#define assertion1(expr, param)
#define assertion(expr)
AutomatonState state
#define logDebug(methodName, logMacroMessageStream)
Definition Log.h:50
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)
_minTimeStepSizeThisTimeStep(0.0)
_maxTimeStampThisTimeStep(0.0)
_minTimeStamp(0.0)
_maxTimeStepSizeThisTimeStep(0.0)
_maxTimeStamp(0.0)
_minTimeStepSize(0.0)
_minTimeStampThisTimeStep(0.0)
_maxTimeStepSize(0.0)
_minGridCellHThisTimeStep(std::numeric_limits< double >::max()/NumberOfGridCellsPerPatchPerAxis/2.0)
_maxGridCellHThisTimeStep(0.0)
_minGridCellH(std::numeric_limits< double >::max()/NumberOfGridCellsPerPatchPerAxis/2.0)
_maxGridCellH(0.0)
Simple vector class.
Definition Vector.h:150