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 {{BASIS_INITIALIZERS | indent(2,True) }}
23 _solverState(SolverState::GridConstruction),
37 {{CONSTRUCTOR_IMPLEMENTATION}}
38}
39
40
41double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMaxMeshSize() const {
42 return getMaxCellSize();
43}
44
45
46double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMinMeshSize() const {
47 return getMinCellSize();
48}
49
50
51void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::suspendSolversForOneGridSweep() {
52 _solverState = SolverState::Suspended;
53}
54
55
56double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMinCellSize(bool ofCurrentlyRunningGridSweep) const {
57 return ofCurrentlyRunningGridSweep ? _minCellHThisTimeStep : _minCellH;
58}
59
60
61double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMaxCellSize(bool ofCurrentlyRunningGridSweep) const {
62 return ofCurrentlyRunningGridSweep ? _maxCellHThisTimeStep : _maxCellH;
63}
64
65
66double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMinTimeStamp(bool ofCurrentlyRunningGridSweep) const {
67 return ofCurrentlyRunningGridSweep ? _minTimeStampThisTimeStep : _minTimeStamp;
68}
69
70
71double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMaxTimeStamp(bool ofCurrentlyRunningGridSweep) const {
72 return ofCurrentlyRunningGridSweep ? _maxTimeStampThisTimeStep : _maxTimeStamp;
73}
74
75
76double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMinTimeStepSize() const {
77 return _minTimeStepSize;
78}
79
80
81double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMaxTimeStepSize() const {
82 return _maxTimeStepSize;
83}
84
85
86void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::update(double timeStepSize, double timeStamp, double cellSize) {
87 tarch::multicore::Lock lock(_semaphore);
88
89 if ( tarch::la::greater(timeStepSize,0.0) ) {
90 assertion1(timeStepSize<std::numeric_limits<double>::max()/10.0,timeStepSize);
91 assertion1(timeStepSize>=0.0,timeStepSize);
95
97
98 _localMinTimeStampThisTimeStep = std::min(_localMinTimeStampThisTimeStep, timeStamp);
99 _localMaxTimeStampThisTimeStep = std::max(_localMaxTimeStampThisTimeStep, timeStamp);
100 }
101
102 assertion1(timeStamp<std::numeric_limits<double>::max()/10.0,timeStamp);
103 assertion1(timeStamp>=0.0,timeStamp);
107
108 assertion1(cellSize<std::numeric_limits<double>::max()/10.0,cellSize);
109 assertion1(cellSize>0.0,cellSize);
110 _maxCellHThisTimeStep = std::max(_maxCellHThisTimeStep,cellSize);
111 _minCellHThisTimeStep = std::min(_minCellHThisTimeStep,cellSize);
112
113 logDebug( "update(double,double,double)", "updated with dt=" << timeStepSize << ", t=" << timeStamp << ", h=" << cellSize << ": t(new)=" << _minTimeStampThisTimeStep );
114}
115
116
117{{NAMESPACE | join("::")}}::{{CLASSNAME}}::SolverState {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getSolverState() const {
118 return _solverState;
119}
120
121
122{% if REFINEMENT_CRITERION_IMPLEMENTATION!="<user-defined>" %}
123::exahype2::RefinementCommand {{NAMESPACE | join("::")}}::{{CLASSNAME}}::refinementCriterion(
124 const double * __restrict__ Q, // Q[{{NUMBER_OF_UNKNOWNS}}+{{NUMBER_OF_AUXILIARY_VARIABLES}}],
125 const tarch::la::Vector<Dimensions,double>& volumeCentre,
127 double t
128) {
129 {% if REFINEMENT_CRITERION_IMPLEMENTATION=="<empty>" %}
131
132
133 return result;
134 {% else %}
135 {{REFINEMENT_CRITERION_IMPLEMENTATION}}
136 {% endif %}
137}
138{% endif %}
139
140
141{% if INITIAL_CONDITIONS_IMPLEMENTATION!="<user-defined>" %}
142void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::initialCondition(
143 double * __restrict__ Q, // Q[{{NUMBER_OF_UNKNOWNS}}+{{NUMBER_OF_AUXILIARY_VARIABLES}}]
147 bool gridIsConstructed
148) {
149 {{INITIAL_CONDITIONS_IMPLEMENTATION}}
150}
151{% endif %}
152
153
154{% if BOUNDARY_CONDITIONS_IMPLEMENTATION!="<user-defined>" and BOUNDARY_CONDITIONS_IMPLEMENTATION!="<none>" %}
155void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::boundaryConditions(
156 const double * __restrict__ Qinside, // Qinside[{{NUMBER_OF_UNKNOWNS}}+{{NUMBER_OF_AUXILIARY_VARIABLES}}]
157 double * __restrict__ Qoutside, // Qoutside[{{NUMBER_OF_UNKNOWNS}}+{{NUMBER_OF_AUXILIARY_VARIABLES}}]
158 const tarch::la::Vector<Dimensions,double>& faceCentre,
159 double t,
160 int normal
161) {
162 {% if BOUNDARY_CONDITIONS_IMPLEMENTATION!="<empty>" %}
163 {{BOUNDARY_CONDITIONS_IMPLEMENTATION}}
164 {% endif %}
165}
166{% endif %}
167
168
169void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startGridConstructionStep() {
170 assertion( _solverState == SolverState::GridConstruction );
171}
172
173
174void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishGridConstructionStep() {
175}
176
177
178void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startGridInitialisationStep() {
179 _solverState = SolverState::GridInitialisation;
180}
181
182
183void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishGridInitialisationStep() {
184}
185
186
187void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startTimeStep(
188 double globalMinTimeStamp,
189 double globalMaxTimeStamp,
190 double globalMinTimeStepSize,
191 double globalMaxTimeStepSize
192) {
193 switch (_solverState) {
194 case SolverState::GridConstruction:
195 _solverState = SolverState::GridInitialisation;
196 break;
197 case SolverState::GridInitialisation:
198 _solverState = SolverState::ProjectOnFacesAndComputeVolumeIntegralOfStep0;
199 break;
200 case SolverState::Suspended:
201 _solverState = SolverState::ProjectOnFacesAndComputeVolumeIntegralOfStep0;
202 break;
203 case SolverState::Plotting:
204 _solverState = SolverState::ProjectOnFacesAndComputeVolumeIntegralOfStep0;
205 break;
206 {% for item in range(RK_STEPS-1) %}
207 case SolverState::ProjectOnFacesAndComputeVolumeIntegralOfStep{{item}}:
208 _solverState = SolverState::SolveRiemannProblemAndAddToVolumeIntegralOfStep{{item}};
209 break;
210 case SolverState::SolveRiemannProblemAndAddToVolumeIntegralOfStep{{item}}:
211 _solverState = SolverState::ProjectOnFacesAndComputeVolumeIntegralOfStep{{item+1}};
212 break;
213 {%- endfor %}
214 case SolverState::ProjectOnFacesAndComputeVolumeIntegralOfStep{{RK_STEPS-1}}:
215 _solverState = SolverState::SolveRiemannProblemAndAddToVolumeIntegralOfStep{{RK_STEPS-1}};
216 break;
217 case SolverState::SolveRiemannProblemAndAddToVolumeIntegralOfStep{{RK_STEPS-1}}:
218 _solverState = SolverState::ProjectOnFacesAndComputeVolumeIntegralOfStep0;
219 break;
220 }
221
222 {{START_TIME_STEP_IMPLEMENTATION}}
223
224 if ( isFirstGridSweepOfTimeStep() ) {
227
228 _minTimeStampThisTimeStep = std::numeric_limits<double>::max();
229 _maxTimeStampThisTimeStep = std::numeric_limits<double>::min();
230
233
234 _minTimeStepSizeThisTimeStep = std::numeric_limits<double>::max();
235 _maxTimeStepSizeThisTimeStep = std::numeric_limits<double>::min();
236
239
241 _minCellHThisTimeStep = std::numeric_limits<double>::max();
242
243 _localMinTimeStampThisTimeStep = std::numeric_limits<double>::max();
244 _localMaxTimeStampThisTimeStep = std::numeric_limits<double>::min();
245
246 _cellUpdates = 0;
247 }
248
249 if (tarch::mpi::Rank::getInstance().isGlobalMaster()) {
250 logInfo("startTimeStep()", "phase " + toString(_solverState));
251 }
252}
253
254
255void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishTimeStep() {
256 if ( isLastGridSweepOfTimeStep() ) {
257
258 #ifdef Parallel
259 double newMinTimeStamp = _minTimeStampThisTimeStep;
260 double newMaxTimeStamp = _maxTimeStampThisTimeStep;
261 double newMinCellH = _minCellHThisTimeStep;
262 double newMaxCellH = _maxCellHThisTimeStep;
263 double newMinTimeStepSize = _minTimeStepSizeThisTimeStep;
264 double newMaxTimeStepSize = _maxTimeStepSizeThisTimeStep;
265
266 double newLocalMinTimeStamp = _localMinTimeStampThisTimeStep;
267 double newLocalMaxTimeStamp = _localMaxTimeStampThisTimeStep;
268
269 int newCellUpdates = _cellUpdates;
270
272 &newMinTimeStamp,
274 1, MPI_DOUBLE,
275 MPI_MIN,
277 );
279 &newMaxTimeStamp,
281 1, MPI_DOUBLE,
282 MPI_MAX,
284 );
285
287 &newMinCellH,
289 1, MPI_DOUBLE,
290 MPI_MIN,
292 );
294 &newMaxCellH,
296 1, MPI_DOUBLE,
297 MPI_MAX,
299 );
300
302 &newMinTimeStepSize,
304 1, MPI_DOUBLE,
305 MPI_MIN,
307 );
309 &newMaxTimeStepSize,
311 1, MPI_DOUBLE,
312 MPI_MAX,
314 );
315
317 &newLocalMinTimeStamp,
318 &_localMinTimeStampThisTimeStep,
319 1, MPI_DOUBLE,
320 MPI_MIN,
322 );
324 &newLocalMaxTimeStamp,
325 &_localMaxTimeStampThisTimeStep,
326 1, MPI_DOUBLE,
327 MPI_MAX,
329 );
330
332 &newCellUpdates,
334 1, MPI_INT,
335 MPI_SUM,
337 );
338 #endif
339
340 if ( _minTimeStampThisTimeStep>=std::numeric_limits<double>::max()/10.0) {
342 }
343 if ( _maxTimeStampThisTimeStep>=std::numeric_limits<double>::max()/10.0 ) {
345 }
346 }
347
348 {{FINISH_TIME_STEP_IMPLEMENTATION}}
349}
350
351
352void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startPlottingStep(
353 double globalMinTimeStamp,
354 double globalMaxTimeStamp,
355 double globalMinTimeStepSize,
356 double globalMaxTimeStepSize
357) {
358 assertion( mayPlot() or ::tarch::hasNonCriticalAssertionBeenViolated() );
359 _solverState = SolverState::Plotting;
360}
361
362
363void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishPlottingStep() {
364}
365
366
367std::string {{NAMESPACE | join("::")}}::{{CLASSNAME}}::toString(SolverState state) {
368 switch (state) {
369 case SolverState::GridConstruction:
370 return "grid-construction";
371 case SolverState::GridInitialisation:
372 return "grid-initialisation";
373 case SolverState::Plotting:
374 return "plotting";
375 {% for item in range(RK_STEPS) %}
376 case SolverState::ProjectOnFacesAndComputeVolumeIntegralOfStep{{item}}:
377 return "project-on-faces-and-compute-volume-integral-of-step-{{item}}";
378 break;
379 case SolverState::SolveRiemannProblemAndAddToVolumeIntegralOfStep{{item}}:
380 return "solve-Riemann-problem-and-add-to-volume-integral-of-step-{{item}}";
381 {%- endfor %}
382 }
383 return "<undef>";
384}
385
386
387bool {{NAMESPACE | join("::")}}::{{CLASSNAME}}::mayPlot() const {
388 return isLastGridSweepOfTimeStep()
389 or _solverState==SolverState::GridInitialisation
390 or _solverState==SolverState::Plotting;
391}
392
393
394bool {{NAMESPACE | join("::")}}::{{CLASSNAME}}::isFirstGridSweepOfTimeStep() const {
395 return _solverState==SolverState::ProjectOnFacesAndComputeVolumeIntegralOfStep0;
396}
397
398
399bool {{NAMESPACE | join("::")}}::{{CLASSNAME}}::isLastGridSweepOfTimeStep() const {
400 return _solverState==SolverState::SolveRiemannProblemAndAddToVolumeIntegralOfStep{{RK_STEPS-1}};
401}
402
403
404void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startSimulation() {
405
406}
407
408
409void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishSimulation() {
410
411}
412
413
414bool {{NAMESPACE | join("::")}}::{{CLASSNAME}}::cellCanUseStatelessPDETerms(
415 const tarch::la::Vector<Dimensions,double>& cellCentre,
417 double t,
418 double dt
419) const {
420 return true;
421}
422
423
424
425{{ABSTRACT_SOLVER_USER_DEFINITIONS}}
#define assertion2(expr, param0, param1)
#define assertion1(expr, param)
#define assertion(expr)
#define assertion6(expr, param0, param1, param2, param3, param4, param5)
AutomatonState state
#define logDebug(methodName, logMacroMessageStream)
Definition Log.h:50
#define logInfo(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:411
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")
bool greater(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool smallerEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
_minTimeStepSizeThisTimeStep(0.0)
_minCellH(0.0)
_maxCellHThisTimeStep(0.0)
_maxTimeStampThisTimeStep(0.0)
_minTimeStamp(0.0)
_maxTimeStepSizeThisTimeStep(0.0)
_maxTimeStamp(0.0)
_minTimeStepSize(0.0)
_maxCellH(0.0)
_minTimeStampThisTimeStep(0.0)
_minCellHThisTimeStep(0.0)
_maxTimeStepSize(0.0)
Simple vector class.
Definition Vector.h:150