Peano
Loading...
Searching...
No Matches
CCZ4WithEuler_OuterMultiplicativeCoupling.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
5import exahype2.api
6import peano4.api
9
10from .Euler import Euler
11from ..FOCCZ4Solver import FOCCZ4Solver
12from ..actionsets import CopyPatchWithLinearInterpolation, SynchroniseTimeStepSizes
13
14
16 """!
17
18 First-order CCZ4 and an Euler fluid, run one after the other within each time step
19
20 The host is the sibling of exagrype.api.CCZ4WithEuler_OuterAdditiveCoupling, and
21 deliberately repeats what the two have in common (solvers, auxiliary
22 variables, prep tasks, realisation of the solvers), so that each class can be
23 read on its own. It only wires the task graphs differently
24 (@ref page_exahype_programmers_guide_coupling). Per time step, we get
25
26 prep (from Euler) -> graph of CCZ4 -> prep (from CCZ4) -> graph of Euler -> synchronise
27
28 i.e. CCZ4 sees the Euler fields of the begin of the time step, and Euler sees the CCZ4
29 fields after CCZ4 has completed its step. Each solver brings its own numerical scheme,
30 assigned to the solvers. They do not exchange data within
31 their Runge-Kutta stages.
32
33 The graphs are chained with peano4.api.taskgraph.Graph.append(): Each graph waits for all sinks of the
34 graph built so far. Each solver graph ends in a GLOBAL_END_OF_STEP task that
35 computes the next time step size. The next graph depends on it, too, and
36 the task compiler therefore does not run it in the mesh sweep of that
37 task (@ref peano4.api.taskgraph.compiler.FuseSteps.translate()).
38 A final GLOBAL_END_OF_STEP task enforces the minimum of both time step sizes.
39
40 """
41
42 EULER_AUXILIARY_COPIES_NAME = "EulerFields"
43 """! Name of the auxiliary variables of CCZ4 which hold the Euler fields """
44 CCZ4_AUXILIARY_COPIES_NAME = "CCZ4Fields"
45 """! Name of the auxiliary variables of Euler which hold the CCZ4 fields """
46 PREP_TASK_NAME = "Prepare auxiliary variables from {}"
47 """! Name of the tasks that fill the auxiliary variables; the argument is the name of the solver that provides the data """
48 SYNCHRONISE_TASK_NAME = "Synchronise time step sizes"
49 """! Name of the final task """
50
51 def __init__(self, ccz4_name: str = "CCZ4", euler_name: str = "Euler"):
52 """!
53
54 Create the two solvers and the auxiliary variables through which they see each other
55
56 The solvers exchange data once per time step only, so the numerical
57 schemes of the solvers remain flexible.
58
59 @param ccz4_name: str
60 Name of the CCZ4 solver.
61
62 @param euler_name: str
63 Name of the Euler solver.
64
65 """
66 self.ccz4 = FOCCZ4Solver(ccz4_name)
67 self.euler = Euler(euler_name)
68 Mode = exahype2.api.AuxiliaryVariables.Mode
71 dict(Euler.Unknowns),
72 mode=Mode.STATIONARY_THROUGHOUT_TIME_STEPS_ON_FACES,
73 data_name="EulerFieldsForCCZ4",
74 )
77 dict(FOCCZ4Solver.Unknowns),
78 mode=Mode.STATIONARY_THROUGHOUT_TIME_STEPS_ON_FACES,
79 data_name="CCZ4FieldsForEuler",
80 )
81 self.ccz4.add_auxiliary_variables(self.euler_auxiliary_copies)
82 self.euler.add_auxiliary_variables(self.ccz4_auxiliary_copies)
83 self._name = f"{ccz4_name}With{euler_name}"
84
85 @property
86 def name(self) -> str:
87 return self._name
88
89 @property
90 def solvers(self):
91 """ The solvers the project has to register; exahype2.api.Project.add_solver() asks for them """
92 return [self.ccz4, self.euler]
93
95 self,
96 exahype2_project,
97 peano_project,
98 setup_simulation,
99 time_step,
100 plot,
101 mesh_adaptation,
102 ):
103 """!
104
105 Realise both solvers, chain their time stepping graphs, and add the outcome to the project's graphs
106
107 The arguments are those of exahype2.api.Solver.generate_solver_realisation().
108 Both solvers are realised without global tasks. The load balancing and the dynamic
109 mesh refinement wrap the chained time step graph afterwards, through the scheme of CCZ4.
110
111 """
112 peano4.api.Logger().new_section("Host " + self.name)
113 Entity = peano4.api.taskgraph.Task.GridEntity
114
115 ccz4_time_step = peano4.api.taskgraph.Graph()
117 exahype2_project,
118 peano_project,
119 setup_simulation,
120 ccz4_time_step,
121 plot,
122 mesh_adaptation,
123 add_global_tasks=False,
124 )
125 euler_time_step = peano4.api.taskgraph.Graph()
127 exahype2_project,
128 peano_project,
129 setup_simulation,
130 euler_time_step,
131 plot,
132 mesh_adaptation,
133 add_global_tasks=False,
134 )
135
136 euler_into_ccz4 = peano4.api.taskgraph.Graph()
138 euler_into_ccz4, self.euler, self.ccz4, self.euler_auxiliary_copies
139 )
140 ccz4_into_euler = peano4.api.taskgraph.Graph()
142 ccz4_into_euler, self.ccz4, self.euler, self.ccz4_auxiliary_copies
143 )
144
145
146 coupled_time_step = peano4.api.taskgraph.Graph()
147 coupled_time_step.append(euler_into_ccz4)
148 coupled_time_step.append(ccz4_time_step)
149 coupled_time_step.append(ccz4_into_euler)
150 coupled_time_step.append(euler_time_step)
151
152
153 synchronise = peano4.api.taskgraph.Task(
154 name=self.SYNCHRONISE_TASK_NAME, entity=Entity.GLOBAL_END_OF_STEP
155 )
156 for task in coupled_time_step.sink_tasks():
157 synchronise.add_dependency(task)
158 synchronise.add_action_set(SynchroniseTimeStepSizes([self.ccz4, self.euler]))
159 coupled_time_step.add_task(synchronise)
160
161 self.ccz4.numerical_scheme.wrap_task_graph_in_load_balancing_and_amr_tasks(
162 coupled_time_step
163 )
164 if self.ccz4.mesh_adaptation is not None:
165 self.ccz4.mesh_adaptation.construct_output(
166 exahype2_project, peano_project, mesh_adaptation
167 )
168
169 title = f"Time stepping task graph for host {self.name}"
170 if peano4.api.Logger().is_visualisation:
171 coupled_time_step.visualise(title=title)
172 if peano4.api.Logger().is_text:
173 coupled_time_step.log_as_text(title=title)
174 time_step.merge(coupled_time_step)
175
177 self, time_step, source_solver, target_solver, auxiliary_copies
178 ):
179 """!
180
181 Create the task that fills the auxiliary variables of one solver with the solution of the other one
182
183 auxiliary copies (auxiliary_copies) of the target solver (copy, with
184 auxiliary variables auxiliary_copies of the target solver (copy, with
185 interpolation if the patches differ in size), projects them onto the
186 faces, restricts them on hanging faces, and rolls the faces over. It is
187 added to time_step, but no dependencies are set: the caller wires it.
188 It is the one place that writes new face data.
189
190 @param time_step: peano4.api.taskgraph.Graph
191 Receives the task.
192
193 @param source_solver: exahype2.api.Solver
194 Provides the data.
195
196 @param target_solver: exahype2.api.Solver
197 Holds the auxiliary variables.
198
199 @param auxiliary_copies: exahype2.api.AuxiliaryVariables
200 The auxiliary variables of the target solver.
201
202 @return peano4.api.taskgraph.Task
203 The new task.
204
205 """
206 Access = peano4.api.taskgraph.Task.DataAccess
207 Entity = peano4.api.taskgraph.Task.GridEntity
209 includes = (
210 target_solver._get_default_includes() + target_solver.user_solver_includes
211 )
213 name=self.PREP_TASK_NAME.format(source_solver.name),
214 entity=Entity.CELL,
215 )
216 prep.use_cell(source_solver._patch, Access.READ_AND_WRITE)
217 prep.use_cell(auxiliary_copies.patch, Access.READ_AND_WRITE)
218 prep.use_face(auxiliary_copies.patch_overlap_update, Access.TEMPORARY)
219 prep.use_face(auxiliary_copies.patch_overlap_current_time_step, Access.READ_AND_WRITE)
220 prep.add_action_set(
221 CopyPatchWithLinearInterpolation(
222 source_patch=source_solver._patch,
223 target_patch=auxiliary_copies.patch,
224 guard=target_solver.grid_selector.createCellGuard(),
225 additional_includes=includes,
226 )
227 )
228 prep.add_action_set(
229 actionsets.ProjectPatchOntoFaces(
230 auxiliary_copies.patch,
231 auxiliary_copies.patch_overlap_update,
232 guard=target_solver.grid_selector.createCellGuard(),
233 includes=includes,
234 )
235 )
236 prep.add_action_set(
237 toolbox.blockstructured.api.RestrictHangingFaces(
238 auxiliary_copies.patch_overlap_update,
239 scheme=target_solver.numerical_scheme.restriction,
240 clear_guard=target_solver.grid_selector.createFaceGuard(),
241 additional_includes=includes,
242 )
243 )
244 prep.add_action_set(
245 actionsets.RollOverUpdatedFace(
246 auxiliary_copies.patch_overlap_current_time_step,
247 auxiliary_copies.patch_overlap_update,
248 guard=target_solver.grid_selector.createFaceGuard(),
249 includes=includes,
250 )
251 )
252 time_step.add_task(prep)
253 return prep
Solver for the Einstein equations in the first-order CCZ4 formulation.
__init__(self, str ccz4_name="CCZ4", str euler_name="Euler")
Create the two solvers and the auxiliary variables through which they see each other.
_create_prep_task(self, time_step, source_solver, target_solver, auxiliary_copies)
Create the task that fills the auxiliary variables of one solver with the solution of the other one.
generate_solver_realisation(self, exahype2_project, peano_project, setup_simulation, time_step, plot, mesh_adaptation)
Realise both solvers, chain their time stepping graphs, and add the outcome to the project's graphs.
Compressible Euler equations of an ideal gas.
Definition Euler.py:11
A set of auxiliary variables of a solver.
Singleton logger for the Peano 4 Python API.
Definition Logger.py:37
Holds a sequence of Task instances.
Definition Graph.py:9
One task within a peano4.api.taskgraph.Graph.
Definition Task.py:8
The task graph abstraction allows users to formalise their solver steps over small task graphs which ...
Definition __init__.py:1
This file is part of the multigrid project within Peano 4.
Definition __init__.py:1