Peano
Loading...
Searching...
No Matches
AdaptiveTimeSteppingCodeSnippets.py
Go to the documentation of this file.
1# This file is part of the ExaHyPE2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from .SolverCodeSnippets import SolverCodeSnippets
4
5
7 """
8
9 Code snippet generator for all fixed time stepping solvers
10
11 """
12
14 return """
15protected:
16 double _maxEigenvalue;
17 double _admissibleTimeStepSize;
18 double _previousTimeStepSize;
19public:
20 void setMaxEigenvalue( double eigenvalue );
21 /**
22 * @return Admissible time step size for the current sweep, i.e.
23 * return _admissibleTimeStepSize. This value always refers
24 * to the minimum mesh volume size. If you use subcycling,
25 * you have to scale it for cells that are not on the finest
26 * mesh resolution.
27 */
28 virtual double getAdmissibleTimeStepSize() const;
29 """
30
31
33 return """
34void {{FULL_QUALIFIED_NAMESPACE}}::{{CLASSNAME}}::setMaxEigenvalue( double eigenvalue ) {
35 if ( tarch::la::greater( eigenvalue, 0.0 ) ) {
36 tarch::multicore::Lock lock(_semaphore);
37 _maxEigenvalue = std::max(_maxEigenvalue,eigenvalue);
38 }
39}
40
41
42double {{FULL_QUALIFIED_NAMESPACE}}::{{CLASSNAME}}::getAdmissibleTimeStepSize() const {
43 return _admissibleTimeStepSize;
44}
45 """
46
47
49 return """
50 _admissibleTimeStepSize = 0.0;
51 _previousTimeStepSize = 0.0;
52"""
53
54
56 return """
57 double timeStepSize = repositories::{{SOLVER_INSTANCE}}.getAdmissibleTimeStepSize();
58"""
59
60
62 """
63
64 This is global, fixed time stepping, i.e. the new time step size will likely
65 be the same as the previous one, unless the mesh changes, as we work with
66 normalised time step sizes, i.e. in this case the time step size might change.
67 Anyway, the new time step size is only for stats anyway, as we'll pick a
68 global one when we determine timeStepSize the next time step.
69
70 """
71 return """
72 repositories::{{SOLVER_INSTANCE}}.setMaxEigenvalue( maxEigenvalue );
73
74 // This is a value set for stats reasons. We'll ignore it later as we
75 // ask for a new valid time step size from getAdmissibleTimeStepSize().
76 const double newTimeStepSize = repositories::{{SOLVER_INSTANCE}}.getAdmissibleTimeStepSize();
77"""
78
79
81 """
82 This routine is inserted after we have reduced all global quantities. These
83 are the quantities with the postfix ThisTimeStep.
84 """
85 return """
86 if ( isLastGridSweepOfTimeStep() ) {
87 #ifdef Parallel
88 double newMaxEigenvalue = _maxEigenvalue;
89 tarch::mpi::Rank::getInstance().allReduce(
90 &newMaxEigenvalue,
91 &_maxEigenvalue,
92 1,
93 MPI_DOUBLE,
94 MPI_MAX,
95 [&]() -> void { tarch::services::ServiceRepository::getInstance().receiveDanglingMessages(); }
96 );
97 #endif
98
99 if (tarch::la::smaller(_maxEigenvalue, 0.0)) {
100 ::tarch::triggerNonCriticalAssertion(__FILE__, __LINE__, "_maxEigenvalue >= 0", "invalid max eigenvalue: " + std::to_string(_maxEigenvalue));
101 // Keep time step size invariant
102 // _admissibleTimeStepSize = _admissibleTimeStepSize;
103 } else if (tarch::la::equals(_maxEigenvalue, 0.0)) {
104 ::tarch::triggerNonCriticalAssertion(__FILE__, __LINE__, "_maxEigenvalue > 0", "max eigenvalue has reached zero, which means that the simulation cannot successfully continue: " + std::to_string(_maxEigenvalue));
105 _admissibleTimeStepSize = 0.0;
106 }
107 }
108"""
create_finish_time_step_implementation(self)
This routine is inserted after we have reduced all global quantities.
Interface for all solvers' code snippets.
create_compute_new_time_step_size()
Very similar to create_compute_time_step_size(), this routine should return a code snippet which crea...
create_compute_time_step_size()
Within the actual compute kernels, the kernels ask the solver variant how to determine a new field.