Peano
Loading...
Searching...
No Matches
SeparateSweepsWithEnclaveTaskingAbstract.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
12#if defined(UseSmartMPI)
13#include "tasks/{{SOLVER_NAME}}EnclaveTask.h"
15#endif
16
19
20
21tarch::logging::Log {{NAMESPACE | join("::")}}::{{CLASSNAME}}::{{CLASSNAME}}::_log( "{{NAMESPACE | join("::")}}::{{CLASSNAME}}::{{CLASSNAME}}" );
22
23std::bitset<Dimensions> {{NAMESPACE | join("::")}}::{{CLASSNAME}}::{{CLASSNAME}}::PeriodicBC = {{NAMESPACE | join("::")}}::PeriodicBC;
24
25
26{{NAMESPACE | join("::")}}::{{CLASSNAME}}::{{CLASSNAME}}():
27 _solverState(SolverState::GridConstruction),
32 // This way, we still compute the patch size without an overflow
33 _minGridCellH(std::numeric_limits<double>::max()/NumberOfGridCellsPerPatchPerAxis/2.0),
35 _minGridCellHThisTimeStep(std::numeric_limits<double>::max()/NumberOfGridCellsPerPatchPerAxis/2.0),
37 _minTimeStepSize(std::numeric_limits<double>::max()),
39 _minTimeStepSizeThisTimeStep(std::numeric_limits<double>::max()),
42 {{CONSTRUCTOR_IMPLEMENTATION}}
43}
44
45
46double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMaxMeshSize() const {
47 return getMaxPatchSize();
48}
49
50
51double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMinMeshSize() const {
52 return getMinPatchSize();
53}
54
55
56double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMinPatchSize(bool ofCurrentlyRunningGridSweep) const {
57 return getMinGridCellSize(ofCurrentlyRunningGridSweep) * NumberOfGridCellsPerPatchPerAxis;
58}
59
60
61double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMaxPatchSize(bool ofCurrentlyRunningGridSweep) const {
62 return getMaxGridCellSize(ofCurrentlyRunningGridSweep) * NumberOfGridCellsPerPatchPerAxis;
63}
64
65
66double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMinGridCellSize(bool ofCurrentlyRunningGridSweep) const {
67 return ofCurrentlyRunningGridSweep ? _minGridCellHThisTimeStep : _minGridCellH;
68}
69
70
71double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMaxGridCellSize(bool ofCurrentlyRunningGridSweep) const {
72 return ofCurrentlyRunningGridSweep ? _maxGridCellHThisTimeStep : _maxGridCellH;
73}
74
75
76double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMinTimeStamp(bool ofCurrentlyRunningGridSweep) const {
77 return ofCurrentlyRunningGridSweep ? _minTimeStampThisTimeStep : _minTimeStamp;
78}
79
80
81double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMaxTimeStamp(bool ofCurrentlyRunningGridSweep) const {
82 return ofCurrentlyRunningGridSweep ? _maxTimeStampThisTimeStep : _maxTimeStamp;
83}
84
85
86double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMinTimeStepSize() const {
87 return _minTimeStepSize;
88}
89
90
91double {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getMaxTimeStepSize() const {
92 return _maxTimeStepSize;
93}
94
95
96void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::suspendSolversForOneGridSweep() {
97 _solverState = SolverState::Suspended;
98}
99
100
101void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::update(double timeStepSize, double timeStamp, double patchSize) {
102 tarch::multicore::Lock lock(_semaphore);
103
104 if ( tarch::la::greater(timeStepSize,0.0) ) {
105 assertion1(timeStepSize<std::numeric_limits<double>::max()/10.0,timeStepSize);
106 assertion1(timeStepSize>=0.0,timeStepSize);
110
112
113 _localMinTimeStampThisTimeStep = std::min(_localMinTimeStampThisTimeStep, timeStamp);
114 _localMaxTimeStampThisTimeStep = std::max(_localMaxTimeStampThisTimeStep, timeStamp);
115 }
116
117 assertion1(timeStamp<std::numeric_limits<double>::max()/10.0,timeStamp);
118 assertion1(timeStamp>=0.0,timeStamp);
121 // This assertion makes sense, but if we reset the time stamp size (in couple systems) then
122 // it is valid.
123 // assertion6( tarch::la::smallerEquals(_minTimeStamp,_maxTimeStampThisTimeStep), _minTimeStamp, _minTimeStampThisTimeStep, _maxTimeStampThisTimeStep, timeStepSize, timeStamp, patchSize );
124
125 assertion1(patchSize<std::numeric_limits<double>::max()/NumberOfGridCellsPerPatchPerAxis,patchSize);
126 assertion1(patchSize>0.0,patchSize);
127 _maxGridCellHThisTimeStep = std::max(_maxGridCellHThisTimeStep,patchSize / NumberOfGridCellsPerPatchPerAxis);
128 _minGridCellHThisTimeStep = std::min(_minGridCellHThisTimeStep,patchSize / NumberOfGridCellsPerPatchPerAxis);
129
130 logDebug( "update(double,double,double)", "updated with dt=" << timeStepSize << ", t=" << timeStamp << ", h=" << patchSize << ": t(new)=" << _minTimeStampThisTimeStep );
131}
132
133
134{{NAMESPACE | join("::")}}::{{CLASSNAME}}::SolverState {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getSolverState() const {
135 return _solverState;
136}
137
138
139{% if REFINEMENT_CRITERION_IMPLEMENTATION!="<user-defined>" %}
140::exahype2::RefinementCommand {{NAMESPACE | join("::")}}::{{CLASSNAME}}::refinementCriterion(
141 const double * __restrict__ Q, // Q[{{NUMBER_OF_UNKNOWNS}}+{{NUMBER_OF_AUXILIARY_VARIABLES}}],
142 const tarch::la::Vector<Dimensions,double>& meshCellCentre,
144 double t
145) {
146 {% if REFINEMENT_CRITERION_IMPLEMENTATION=="<empty>" %}
148
149
150 return result;
151 {% else %}
152 {{REFINEMENT_CRITERION_IMPLEMENTATION}}
153 {% endif %}
154}
155{% endif %}
156
157
158{% if INITIAL_CONDITIONS_IMPLEMENTATION!="<user-defined>" %}
159void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::initialCondition(
160 double * __restrict__ Q,
161 const tarch::la::Vector<Dimensions,double>& meshCellCentre,
163 bool gridIsConstructed
164) {
165 {{INITIAL_CONDITIONS_IMPLEMENTATION}}
166}
167{% endif %}
168
169
170{% if BOUNDARY_CONDITIONS_IMPLEMENTATION!="<user-defined>" and BOUNDARY_CONDITIONS_IMPLEMENTATION!="<none>" %}
171void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::boundaryConditions(
172 const double * __restrict__ Qinside, // Qinside[{{NUMBER_OF_UNKNOWNS}}+{{NUMBER_OF_AUXILIARY_VARIABLES}}]
173 double * __restrict__ Qoutside, // Qoutside[{{NUMBER_OF_UNKNOWNS}}+{{NUMBER_OF_AUXILIARY_VARIABLES}}]
174 const tarch::la::Vector<Dimensions,double>& faceCentre,
176 double t,
177 int normal
178) {
179 {% if BOUNDARY_CONDITIONS_IMPLEMENTATION!="<empty>" %}
180 {{BOUNDARY_CONDITIONS_IMPLEMENTATION}}
181 {% endif %}
182}
183{% endif %}
184
185
186void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startGridConstructionStep() {
187 assertion( _solverState == SolverState::GridConstruction );
188}
189
190
191void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishGridConstructionStep() {
192}
193
194
195void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startGridInitialisationStep() {
196 _solverState = SolverState::GridInitialisation;
197}
198
199
200void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishGridInitialisationStep() {
201}
202
203
204void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startTimeStep(
205 double globalMinTimeStamp,
206 double globalMaxTimeStamp,
207 double globalMinTimeStepSize,
208 double globalMaxTimeStepSize
209) {
210 switch (_solverState) {
211 case SolverState::GridConstruction:
212 assertionMsg(false, "grid construction should lead into initialisation and not time stepping" );
213 break;
214 {% for item in range(RK_STEPS-1) %}
215 case SolverState::RungeKuttaPrimarySubStep{{item}}:
216 _solverState = SolverState::RungeKuttaSecondarySubStep{{item}};
217 break;
218 case SolverState::RungeKuttaSecondarySubStep{{item}}:
219 _solverState = SolverState::RungeKuttaPrimarySubStep{{item+1}};
220 break;
221 {% endfor %}
222 case SolverState::Suspended:
223 case SolverState::Plotting:
224 case SolverState::PlottingAfterGridInitialisation:
225 _solverState = SolverState::RungeKuttaPrimarySubStep0;
226 break;
227 case SolverState::GridInitialisation:
228 _solverState = SolverState::RungeKuttaPrimarySubStep0AfterGridInitialisation;
229 break;
230 case SolverState::RungeKuttaPrimarySubStep{{RK_STEPS-1}}:
231 _solverState = SolverState::RungeKuttaSecondarySubStep{{RK_STEPS-1}};
232 break;
233 case SolverState::RungeKuttaSecondarySubStep{{RK_STEPS-1}}:
234 _solverState = SolverState::RungeKuttaPrimarySubStep0;
235 break;
236 case SolverState::RungeKuttaPrimarySubStep0AfterGridInitialisation:
237 _solverState = SolverState::RungeKuttaSecondarySubStep0;
238 break;
239 }
240
241 {{START_TIME_STEP_IMPLEMENTATION}}
242
243 if ( isFirstGridSweepOfTimeStep() ) {
246
247 _minTimeStampThisTimeStep = std::numeric_limits<double>::max();
248 _maxTimeStampThisTimeStep = std::numeric_limits<double>::min();
249
252
253 _minTimeStepSizeThisTimeStep = std::numeric_limits<double>::max();
254 _maxTimeStepSizeThisTimeStep = std::numeric_limits<double>::min();
255
258
260 _minGridCellHThisTimeStep = std::numeric_limits<double>::max()/NumberOfGridCellsPerPatchPerAxis/2.0;
261
262 _localMinTimeStampThisTimeStep = std::numeric_limits<double>::max();
263 _localMaxTimeStampThisTimeStep = std::numeric_limits<double>::min();
264
265 _patchUpdates = 0;
266 }
267}
268
269
270void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishTimeStep() {
271 if ( isLastGridSweepOfTimeStep() ) {
272 #ifdef Parallel
273 double newMinTimeStamp = _minTimeStampThisTimeStep;
274 double newMaxTimeStamp = _maxTimeStampThisTimeStep;
275 double newMinGridCellH = _minGridCellHThisTimeStep;
276 double newMaxGridCellH = _maxGridCellHThisTimeStep;
277 double newMinTimeStepSize = _minTimeStepSizeThisTimeStep;
278 double newMaxTimeStepSize = _maxTimeStepSizeThisTimeStep;
279
280 double newLocalMinTimeStamp = _localMinTimeStampThisTimeStep;
281 double newLocalMaxTimeStamp = _localMaxTimeStampThisTimeStep;
282
283 int newPatchUpdates = _patchUpdates;
284
286 &newMinTimeStamp,
288 1, MPI_DOUBLE,
289 MPI_MIN,
291 );
293 &newMaxTimeStamp,
295 1, MPI_DOUBLE,
296 MPI_MAX,
298 );
299
301 &newMinGridCellH,
303 1, MPI_DOUBLE,
304 MPI_MIN,
306 );
308 &newMaxGridCellH,
310 1, MPI_DOUBLE,
311 MPI_MAX,
313 );
314
316 &newMinTimeStepSize,
318 1, MPI_DOUBLE,
319 MPI_MIN,
321 );
323 &newMaxTimeStepSize,
325 1, MPI_DOUBLE,
326 MPI_MAX,
328 );
329
331 &newLocalMinTimeStamp,
332 &_localMinTimeStampThisTimeStep,
333 1, MPI_DOUBLE,
334 MPI_MIN,
336 );
338 &newLocalMaxTimeStamp,
339 &_localMaxTimeStampThisTimeStep,
340 1, MPI_DOUBLE,
341 MPI_MAX,
343 );
344
346 &newPatchUpdates,
348 1, MPI_INT,
349 MPI_SUM,
351 );
352 #endif
353
354 if ( _minTimeStampThisTimeStep>=std::numeric_limits<double>::max()/10.0) {
356 }
357 if ( _maxTimeStampThisTimeStep>=std::numeric_limits<double>::max()/10.0 ) {
359 }
360 }
361
362 {{FINISH_TIME_STEP_IMPLEMENTATION}}
363}
364
365
366void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startPlottingStep(
367 double globalMinTimeStamp,
368 double globalMaxTimeStamp,
369 double globalMinTimeStepSize,
370 double globalMaxTimeStepSize
371) {
372 if ( _solverState==SolverState::GridInitialisation ) {
373 _solverState = SolverState::PlottingAfterGridInitialisation;
374 }
375 else {
376 _solverState = SolverState::Plotting;
377 }
378}
379
380
381void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishPlottingStep() {
382}
383
384
385std::string {{NAMESPACE | join("::")}}::{{CLASSNAME}}::toString(SolverState state) {
386 switch (state) {
387 case SolverState::GridConstruction:
388 return "grid-construction";
389 case SolverState::GridInitialisation:
390 return "grid-initialisation";
391 case SolverState::Plotting:
392 return "plotting";
393 case SolverState::Suspended:
394 return "suspended";
395 case SolverState::PlottingAfterGridInitialisation:
396 return "plotting-after-grid-initialisation";
397 case SolverState::RungeKuttaPrimarySubStep0AfterGridInitialisation:
398 return "runge-kutta-primary-step-0-after-grid-initialisation";
399 {% for item in range(RK_STEPS) %}
400 case SolverState::RungeKuttaPrimarySubStep{{item}}:
401 return "runge-kutta-primary-step-{{item}}";
402 break;
403 case SolverState::RungeKuttaSecondarySubStep{{item}}:
404 return "runge-kutta-secondary-step-{{item}}";
405 break;
406 {%- endfor %}
407 }
408 return "<undef>";
409}
410
411
412bool {{NAMESPACE | join("::")}}::{{CLASSNAME}}::mayPlot() const {
413 return isLastGridSweepOfTimeStep() or _solverState==SolverState::Suspended
414 or _solverState==SolverState::GridInitialisation
415 or _solverState==SolverState::Plotting;
416}
417
418
419bool {{NAMESPACE | join("::")}}::{{CLASSNAME}}::isFirstGridSweepOfTimeStep() const {
420 return _solverState==SolverState::RungeKuttaPrimarySubStep0
421 or _solverState==SolverState::RungeKuttaPrimarySubStep0AfterGridInitialisation;
422}
423
424
425bool {{NAMESPACE | join("::")}}::{{CLASSNAME}}::isLastGridSweepOfTimeStep() const {
426 return _solverState==SolverState::RungeKuttaSecondarySubStep{{RK_STEPS-1}} or _solverState==SolverState::Suspended;
427}
428
429
430{{ABSTRACT_SOLVER_USER_DEFINITIONS}}
431
432
433
434void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::startSimulation() {
435
436}
437
438
439void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::finishSimulation() {
440
441}
442
443
444bool {{NAMESPACE | join("::")}}::{{CLASSNAME}}::patchCanUseStatelessPDETerms(
445 const tarch::la::Vector<Dimensions,double>& patchCentre,
447 double t,
448 double dt
449) const {
450 return true;
451}
#define assertion2(expr, param0, param1)
#define assertion1(expr, param)
#define assertionMsg(expr, message)
#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