Peano
Loading...
Searching...
No Matches
ReadjustTimeStepSizeForOptimisticGlobalTimestepping.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 .AbstractFVActionSet import AbstractFVActionSet
4
5import peano4.api
6
7
9 """!
10
11 Validate the estimated time step size of an optimistic patch interior update
12
13 The second entry of solver._max_eigenvalue_and_time_step_sizes holds the
14 time step size the patch interior has been updated with optimistically
15 (@see exahype2.api.fv.actionsets.SpawnTaskToUpdateCellInterior). The
16 action set compares it to the admissible time step size, i.e. the time
17 step size the solver would use if it had not been enforced to use a
18 smaller one (@see exahype2::Solver::getAdmissibleTimeStepSize()):
19
20 - If the admissible time step size is zero, i.e. in the very first time
21 step, there is no estimate yet. The action set sets the fourth entry
22 to zero and does not read the second entry.
23 - If the estimate is bigger than the admissible time step size, we have
24 overestimated the admissible time step size. The action set
25 invalidates the estimate, i.e. sets it to the maximum double value.
26 - If the estimate is smaller than or equal to the admissible time step
27 size, subject to floating point accuracy (tarch::la::equals()), the
28 action set enforces the estimate as the solver's minimum and maximum
29 time step size (@see exahype2::Solver::enforceTimeStepSize()).
30
31 In the latter two cases, the action set stores the admissible time step
32 size in the fourth entry. It is the time step size the solver could have
33 chosen, whether or not the estimate is enforced.
34
35 """
36
37 def __init__(self, solver, guard):
38 """!
39
40 @param solver: exahype2.api.Solver
41 Has to have solver._max_eigenvalue_and_time_step_sizes set - @see
42 exahype2.api.fv.RusanovWithOptimisticExplicitEuler.
43
44 @param guard: str
45 C++ boolean expression, evaluated per cell in touchCellFirstTime,
46 guarding whether that cell's estimate is checked.
47
48 """
49 AbstractFVActionSet.__init__(self, solver)
50 self.guard = guard
51
52 def get_body_of_operation(self, operation_name):
53 result = ""
54 if operation_name == peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
55 solver = f"repositories::{self._solver.get_name_of_global_instance()}"
56 data = f"fineGridCell{self._solver._max_eigenvalue_and_time_step_sizes.name}"
57 result = f"""
58 const double admissibleTimeStepSize = {solver}.getAdmissibleTimeStepSize();
59 if ( tarch::la::equals(admissibleTimeStepSize, 0.0) ) {{
60 {data}.setMaxEigenvalue(3, 0.0);
61 }}
62 else {{
63 const double estimatedTimeStepSize = {data}.getMaxEigenvalue(1);
64 if (estimatedTimeStepSize < admissibleTimeStepSize or tarch::la::equals(estimatedTimeStepSize, admissibleTimeStepSize)) {{
65 {solver}.enforceTimeStepSize(estimatedTimeStepSize);
66 }}
67 else {{
68 {data}.setMaxEigenvalue(1, std::numeric_limits<double>::max());
69 }}
70 {data}.setMaxEigenvalue(3, admissibleTimeStepSize);
71 }}
72"""
73 return result
74
75 def get_guard_of_operation(self, operation_name):
76 if operation_name == peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
77 return self.guard
78 return "true"
79
81 """!
82
83 Never spawn this action set as a task
84
85 The check is a handful of floating point comparisons per cell, i.e.
86 far too cheap to justify the overhead of a task. Task graph compilers
87 such as @ref peano4.api.taskgraph.compiler.CellTaskProducerConsumer
88 therefore keep it within the mesh traversal. It does not touch the
89 patch data, so it does not depend on the reconstruction task which
90 the producer spawns before.
91
92 """
93 return False
94
95 def get_includes(self):
96 return super().get_includes() + """
97#include <limits>
98#include "tarch/la/ScalarOperations.h"
99"""
100
102 return __name__.replace(".py", "").replace(".", "_")
get_action_set_name(self)
You should replicate this function in each subclass, so you get meaningful action set names (otherwis...