3from .AbstractRKFD4ActionSet
import AbstractRKFD4ActionSet
11 Determine the time step size of the next Runge-Kutta step and advance
12 the solver's time stamp
14 The action set supports two modes:
16 - Fixed time step sizes: the next time step size is the one passed to
18 - Adaptive time step sizes: exahype2.api.rkfd4.actionsets.ComputeMaxEigenvalue
19 reduces the maximum eigenvalue of every patch into the solver. The
20 action set reads and resets it (getAndResetMaxEigenvalue()), takes the
21 maximum over all ranks, and derives the next time step size from it
22 through the CFL condition
23 @f$ \\Delta t = C h / (d \\lambda _{max}) @f$, with h the minimal grid
24 cell size, d the dimension and C the CFL constant.
26 In both modes, unprepareTraversal() feeds the next time step size into
27 ::exahype2::Solver's own time step bookkeeping
28 (updateCell()/finishTimeStep()/startTimeStep()). The time stamp
29 advances by the time step size the Runge-Kutta step has just used. The
30 last time step is not truncated: it may overshoot MaxTerminalTime, and
31 the simulation stops afterwards, i.e. MaxTerminalTime is a lower bound
32 on the final time. The solver starts with a time step size of zero, so
33 the very first Runge-Kutta step does not alter the solution: it only
34 yields the first time step size.
36 Global time stepping: all cells share one time stamp and time step size.
37 As getMinTimeStamp()==getMaxTimeStamp() and
38 getMinTimeStepSize()==getMaxTimeStepSize() always hold, a single
39 updateCell() call per time step is enough.
41 The action set only acts in unprepareTraversal() and touches no mesh data.
42 The task that hosts it hence is a GLOBAL_END_OF_STEP task
43 (@ref peano4.api.taskgraph.Task.Task.GridEntity), which the task graph
44 compiler fuses into the last traversal of the time step instead of
45 spending a traversal on it. Why the reduction over the cells happens
46 elsewhere: a task that touches cells could not be of this kind.
48 The class is derived from exahype2.api.fv.actionsets.ComputeGlobalCFLCondition,
49 as rkfd4 does not depend on the Finite Volume package. Consult the
50 latter for details on the reduction over ranks.
54 def __init__(self, solver, patch_size, cfl_constant=None, time_step_size=None):
57 @param solver: exahype2.api.Solver
58 With adaptive time stepping, the solver has to host the reduction of
59 the maximum eigenvalue (@ref exahype2.api.rkfd4.CentralDifferencesWithRungeKutta).
61 @param patch_size: int
62 Number of grid cells per patch and axis. The CFL condition is
63 evaluated over the grid cell size, i.e. the mesh cell size divided
66 @param cfl_constant: float or None
67 CFL constant for adaptive time stepping.
69 @param time_step_size: float or None
70 Time step size for fixed time stepping. Exactly one of
71 cfl_constant and time_step_size has to be set.
74 AbstractRKFD4ActionSet.__init__(self, solver)
75 if (cfl_constant
is None) == (time_step_size
is None):
76 raise ValueError(
"Set exactly one of cfl_constant and time_step_size")
86 instance =
"repositories::" + self.
_solver.get_name_of_global_instance()
88 admissible_time_step_size = f
"""
89 const peano4::grid::GridStatistics globalStatistics = peano4::parallel::SpacetreeSet::getInstance().getGridStatistics();
90 const double globalMinGridCellH = tarch::la::max( globalStatistics.getMinH() ) / {self.patch_size};
92 double localMaxEigenvalue = {instance}.getAndResetMaxEigenvalue();
93 double globalMaxEigenvalue = localMaxEigenvalue;
95 tarch::mpi::Rank::getInstance().allReduce(
96 &localMaxEigenvalue, &globalMaxEigenvalue, 1, MPI_DOUBLE, MPI_MAX,
97 [&]() -> void {{ tarch::services::ServiceRepository::getInstance().receiveDanglingMessages(); }}
100 const double admissibleTimeStepSize = {self.cfl_constant!r} * globalMinGridCellH / globalMaxEigenvalue / Dimensions;
103 admissible_time_step_size = f
"""
104 const double admissibleTimeStepSize = {self.time_step_size!r};
107 admissible_time_step_size
109 // The time stamp advances by the time step size the update used,
110 // newTimeStepSize is the one the next update will use
111 const double usedTimeStepSize = {instance}.getMaxTimeStepSize();
112 const double newTimeStamp = {instance}.getMaxTimeStamp() + usedTimeStepSize;
113 // The last time step is not truncated, i.e. it may overshoot MaxTerminalTime
114 const double newTimeStepSize = admissibleTimeStepSize;
116 {instance}.updateCell( newTimeStepSize, newTimeStamp );
117 {instance}.finishTimeStep();
118 {instance}.startTimeStep(
119 {instance}.getMinTimeStamp(),
120 {instance}.getMaxTimeStamp(),
121 {instance}.getMinTimeStepSize(),
122 {instance}.getMaxTimeStepSize()
124 logInfo( "unprepareTraversal()", "t=" << {instance}.getMaxTimeStamp() << ", new dt=" << newTimeStepSize );
130 AbstractRKFD4ActionSet.get_includes(self)
133#include "tarch/mpi/Rank.h"
134#include "tarch/services/ServiceRepository.h"
135#include "tarch/la/VectorOperations.h"
136#include "peano4/parallel/SpacetreeSet.h"
137#include "peano4/grid/grid.h"
142 return __name__.replace(
".py",
"").replace(
".",
"_")
Base class of the action sets of exahype2.api.rkfd4 which work against the solver.
Determine the time step size of the next Runge-Kutta step and advance the solver's time stamp.
get_body_of_unprepareTraversal(self)
get_action_set_name(self)
You should replicate this function in each subclass, so you get meaningful action set names (otherwis...
get_includes(self)
The includes cover the kernels the numerical scheme generates (exahype2.api.rkfd4....
__init__(self, solver, patch_size, cfl_constant=None, time_step_size=None)