3from .AbstractFVActionSet
import AbstractFVActionSet
11 Derive the next global time step size from the CFL condition.
13 exahype2.api.fv.actionsets.ComputeMaxEigenvalue stores the maximum
14 eigenvalue of every patch per cell, and
15 exahype2.api.fv.actionsets.ReduceMaxEigenvalue reduces these values into
16 the solver. This action set acts in unprepareTraversal() only: it reads
17 and resets the solver's reduced maximum eigenvalue, turns it into the
18 next time step size, and feeds it into ::exahype2::Solver's own time
19 step bookkeeping (updateCell()/finishTimeStep()/startTimeStep()). There
20 is deliberately no separate, solver-level time stamp/time step size
21 state on top of ::exahype2::Solver.
23 The action set touches no mesh data. The task that hosts it hence is a
24 GLOBAL_END_OF_STEP task (@ref peano4.api.taskgraph.Task.Task.GridEntity),
25 which the task graph compiler fuses into the last traversal of the time
26 step instead of spending a traversal on it.
28 Global time stepping: all cells share one time stamp and time step
29 size, which are taken from the solver (getMinTimeStamp() and
30 getMinTimeStepSize()) rather than from per-cell bookkeeping.
32 The kernel updates all dimensions in one explicit Euler step, so the CFL
33 condition reads dt * sum_d lambda_d/h_d <= 1, i.e. the admissible time
34 step size is cfl_constant * h / (Dimensions * lambda_max), with h the
35 minimal volume size and lambda_max the maximum eigenvalue.
37 As this is global time stepping, getMinTimeStamp()==getMaxTimeStamp()
38 and getMinTimeStepSize()==getMaxTimeStepSize() always hold. Hence a
39 single updateCell() call per time step, not one per cell, is enough to
40 keep both the min and the max in sync.
44 def __init__(self, solver, cfl_constant, patch_size):
47 @param solver: exahype2.api.Solver
48 Has to host the reduction of the maximum eigenvalue (@ref
49 exahype2.api.fv.MaxEigenvalueReduction).
51 @param cfl_constant: float
52 Safety factor the admissible time step size is scaled down by,
53 relative to the theoretical CFL=1 stability limit (which already
54 accounts for the number of dimensions, see class docstring) - @see
55 exahype2.api.fv.RusanovWithExplicitEuler's own cfl_constant
56 parameter, which this is meant to be passed straight through
59 @param patch_size: int
60 Number of Finite Volumes per patch and dimension. The CFL
61 condition is evaluated over the volume size, i.e. the cell size
62 divided by patch_size.
65 AbstractFVActionSet.__init__(self, solver)
72 Called once per rank, after the sweep - the one safe place both to
73 read the solver's reduced maximum eigenvalue (nothing can still be
74 writing it) and to issue an MPI reduction:
75 tarch::mpi::Rank::allReduce()'s own documentation requires "only one
76 thread per rank" to ever call it, which a once-per-rank static method
79 This combines two different kinds of "global", reduced two different
82 - The mesh size comes out of peano4::grid::GridStatistics, which
83 peano4::parallel::SpacetreeSet reduces over all ranks at the end
84 of every traversal (@ref page_grid_statistics). Every rank hence
85 reads the same, global value. GridStatistics holds the cell size;
86 the CFL condition needs the volume size, i.e. the cell size
87 divided by the patch size.
88 - The solver's maximum eigenvalue is only a local, per-rank
89 accumulation - that one *is* reduced directly via
90 tarch::mpi::Rank::allReduce(..., MPI_MAX, ...).
92 Once newTimeStepSize is known, it folds it into the solver's own
93 time step bookkeeping (see this class' docstring for why a single
94 updateCell() call, not one per cell, is correct for this solver).
95 newTimeStepSize is not truncated by MaxTerminalTime: the last time
96 step may overshoot the end time, and the simulation stops afterwards,
97 i.e. MaxTerminalTime is a lower bound on the final time. The time
98 stamp is advanced by the time step size the update used
99 (getMaxTimeStepSize() before updateCell()), not by newTimeStepSize,
100 which only the next update uses. The very first time step therefore
101 runs with time step size 0 and leaves the time stamp at 0: it only
102 yields the first admissible time step size.
104 - updateCell(newTimeStepSize, newTimeStamp) folds the new values
105 into exahype2::Solver's ...UpdatedThisTimeStep accumulators.
106 - finishTimeStep() then MPI-all-reduces that accumulator across
107 ranks - a no-op given newTimeStepSize/newTimeStamp are already
108 identical on every rank, but calling it anyway keeps the full
109 ::exahype2::Solver lifecycle honest for any future override that
110 relies on it actually running.
111 - startTimeStep(...) immediately promotes that same accumulator into
112 the stable _minTimeStamp/_maxTimeStamp/_minTimeStepSize/
113 _maxTimeStepSize fields getMinTimeStamp()/.../getMaxTimeStepSize()
114 expose, so there is no one-phase lag: the very first TimeStep
115 phase must already leave a genuinely positive getMaxTimeStepSize()
116 behind for the generated main loop's
117 tarch::la::greater(maxTimeStepSize,0.0) guard to see, or the
118 simulation could never advance past its first iteration.
122 const peano4::grid::GridStatistics globalStatistics = peano4::parallel::SpacetreeSet::getInstance().getGridStatistics();
123 const double globalMinVolumeH = tarch::la::max( globalStatistics.getMinH() ) / {self.patch_size};
125 double localMaxEigenvalue = repositories::{self._solver.get_name_of_global_instance()}.getAndResetMaxEigenvalue();
126 double globalMaxEigenvalue = localMaxEigenvalue;
128 tarch::mpi::Rank::getInstance().allReduce(
129 &localMaxEigenvalue, &globalMaxEigenvalue, 1, MPI_DOUBLE, MPI_MAX,
130 [&]() -> void {{ tarch::services::ServiceRepository::getInstance().receiveDanglingMessages(); }}
134 // The time stamp advances by the time step size the update used,
135 // newTimeStepSize is the one the next update will use
136 const double usedTimeStepSize = repositories::{self._solver.get_name_of_global_instance()}.getMaxTimeStepSize();
137 const double newTimeStamp = repositories::{self._solver.get_name_of_global_instance()}.getMaxTimeStamp() + usedTimeStepSize;
138 // The last time step is not truncated, i.e. it may overshoot MaxTerminalTime
139 const double newTimeStepSize = {self.cfl_constant} * globalMinVolumeH / globalMaxEigenvalue / Dimensions;
141 repositories::{self._solver.get_name_of_global_instance()}.updateCell( newTimeStepSize, newTimeStamp );
142 repositories::{self._solver.get_name_of_global_instance()}.finishTimeStep();
143 repositories::{self._solver.get_name_of_global_instance()}.startTimeStep(
144 repositories::{self._solver.get_name_of_global_instance()}.getMinTimeStamp(),
145 repositories::{self._solver.get_name_of_global_instance()}.getMaxTimeStamp(),
146 repositories::{self._solver.get_name_of_global_instance()}.getMinTimeStepSize(),
147 repositories::{self._solver.get_name_of_global_instance()}.getMaxTimeStepSize()
149 logInfo( "unprepareTraversal()", "t=" << repositories::{self._solver.get_name_of_global_instance()}.getMaxTimeStamp() << ", new dt=" << newTimeStepSize );
154 AbstractFVActionSet.get_includes(self)
156#include "tarch/mpi/Rank.h"
157#include "tarch/services/ServiceRepository.h"
158#include "tarch/la/VectorOperations.h"
159#include "peano4/parallel/SpacetreeSet.h"
160#include "peano4/grid/grid.h"
165 return __name__.replace(
".py",
"").replace(
".",
"_")
Derive the next global time step size from the CFL condition.
__init__(self, solver, cfl_constant, patch_size)
get_action_set_name(self)
You should replicate this function in each subclass, so you get meaningful action set names (otherwis...
get_body_of_unprepareTraversal(self)
Called once per rank, after the sweep - the one safe place both to read the solver's reduced maximum ...
get_includes(self)
Return include statements that you need.