Peano
Loading...
Searching...
No Matches
SynchroniseTimeStepSizes.py
Go to the documentation of this file.
1""" This file is part of the ExaGRyPE project. For conditions of distribution and
2 use, please see the copyright notice at www.peano-framework.org
3"""
4
5from peano4.api.solversteps.ActionSet import ActionSet
6
7
9 """!
10
11 Make several solvers advance with the same time step size
12
13 The action set acts in unprepareTraversal() only. After the solvers have
14 computed their next time step size, it takes the minimum of them and
15 enforces it on all solvers (::exahype2::Solver::enforceTimeStepSize()).
16 The task that hosts the action set is a GLOBAL_END_OF_STEP task, which
17 depends on the last tasks of all solvers.
18
19 """
20
21 def __init__(self, solvers):
22 """!
23
24 @param solvers: List[exahype2.api.Solver]
25 The solvers whose time step sizes are synchronised.
26
27 """
28 super().__init__(descend_invocation_order=1, parallel=False)
29 self._solvers = list(solvers)
30
32 return __name__.replace(".py", "").replace(".", "_")
33
35 return False
36
37 def get_includes(self):
38 return '#include "repositories/SolverRepository.h"\n#include <algorithm>\n#include <limits>\n'
39
41 instances = [
42 f"repositories::{solver.get_name_of_global_instance()}"
43 for solver in self._solvers
44 ]
45 minimum = "std::numeric_limits<double>::max()"
46 for instance in instances:
47 minimum = f"std::min( {instance}.getMaxTimeStepSize(), {minimum} )"
48 enforce = "\n".join(
49 f" {instance}.enforceTimeStepSize(timeStepSize);" for instance in instances
50 )
51 return f"""
52 const double timeStepSize = {minimum};
53{enforce}
54"""
Make several solvers advance with the same time step size.
Action set (reactions to events).
Definition ActionSet.py:6