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
5from typing
import Dict, List, Union
11from .FOSOCCZ4Solver
import FOSOCCZ4Solver
12from .FOSOReconstructionSolver
import FOSOReconstructionSolver
18 The numerical scheme of the reconstruction solver
20 The solver has no scheme of its own, but the generic parts of the solver
21 still query one for patch size, halo and so forth. The hosted scheme
22 forwards all such queries to the scheme of the CCZ4 solver. Its
23 construct_output() asks the reconstruction solver for its task graph once
24 per Runge-Kutta stage of CCZ4
25 (@ref exahype2.api.Solver.Solver.create_task_graph()) and puts the graphs
26 into the time stepping graph. The graphs are not connected: wiring them is
27 the job of FOSOSolver._couple(). The scheme remembers the graphs in
36 """! The graph that the solver returned for each stage, filled by construct_output() """
40 if name.startswith(
"_"):
41 raise AttributeError(name)
42 return getattr(self.
_ccz4.numerical_scheme, name)
45 """! FOSOSolver wraps the concatenated graph through the scheme of CCZ4"""
48 self, exahype2_project, peano_project, time_step, add_global_tasks=True
51 stages = getattr(self._ccz4.numerical_scheme,
"rk_order", 1)
52 self.stage_graphs = []
53 for stage
in range(stages):
54 graph = solver.create_task_graph(
55 exahype2_project, peano_project, stage, stages
57 time_step.merge(graph)
58 self.stage_graphs.append(graph)
59 title = f
"Time stepping task graph for {solver.name}"
61 time_step.visualise(title=title)
63 time_step.log_as_text(title=title)
69 CCZ4 in the first-/second-order reconstructed formulation as a coupled pair
71 The object hosts two solvers, which take turns in the time stepping task
72 graph (@ref page_exagrype_fo_so_ccz4, @ref page_exahype_programmers_guide_coupling):
74 - ccz4 (exagrype.api.FOSOCCZ4Solver) evolves the 25 primary unknowns of
75 CCZ4. It holds the 33 derivatives as auxiliary variables. It is the
76 the one which owns the global tasks: Both solvers are
77 realised as intermediate steps, and after concatenation and coupling, the
78 host wraps the whole graph into the load balancing and dynamic mesh
79 refinement tasks through the scheme of ccz4
80 (wrap_task_graph_in_load_balancing_and_amr_tasks()).
81 - reconstruction (exagrype.api.FOSOReconstructionSolver) evolves the
82 derivatives, i.e. it recomputes them from the primary unknowns in
83 front of each Runge-Kutta stage of ccz4.
85 The host holds the numerical scheme: Build it for ccz4 and assign it to
86 the host. The reconstruction solver receives a scheme that forwards to it. Configure ccz4 otherwise as any other solver (grid
87 construction, plotter, constraint enforcement, ...), and then add the
88 host to the project with exahype2.api.Project.add_solver(). The
89 reconstruction needs no configuration: it takes patch size and halo from
92 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93 solver = exagrype.api.FOSOSolver("SO")
94 solver.numerical_scheme = exahype2.api.rkfd4.CentralDifferencesWithRungeKutta(solver.ccz4, patch_size, rk_order=4, ...)
96 project.add_solver(solver)
97 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101 Both solvers build a task graph of their own, and report it: the scheme of the host
102 builds the graph of ccz4, and asks the reconstruction solver for its graph
103 once per stage (exagrype.api.FOSOReconstructionSolver.create_task_graph()). The reconstruction
104 solver's graph is a chain per stage (see @ref exagrype.api.FOSOReconstructionSolver),
105 and the chains of different stages are not connected.
106 The host concatenates the graphs and wires them (_couple()): The first tasks of
107 each stage's chain take over the dependencies of the CCZ4 solver's reconstruction
108 of this stage, and the latter depends on the last task of the chain. The host
116 parameters: Dict[str, Union[int, float]] =
None,
118 reconstruction_name: str =
None,
123 Name of the CCZ4 solver, @see exahype2.api.Solver.
125 @param parameters: Dict[str, Union[int, float]]
126 CCZ4 parameters, @see exagrype.api.FOSOCCZ4Solver.
128 @param initial_condition: exahype2.api.InitPointWisely
129 Initial condition, @see exagrype.api.FOSOCCZ4Solver.
131 @param reconstruction_name: str
132 Name of the reconstruction solver. Defaults to name plus
137 """! The solver that evolves the primary unknowns """
140 if reconstruction_name
is not None
141 else name +
"Reconstruction",
144 """! The solver that reconstructs the derivatives """
154 """! The solvers in the order of their realisation: CCZ4 first, as the reconstruction needs its data """
159 """! The scheme of ccz4. Assigning it hands a forwarding scheme to the reconstruction solver """
162 @numerical_scheme.setter
164 self.
ccz4.numerical_scheme = value
181 Realise both solvers, couple their time stepping graphs, and add the outcome to the project's graphs
183 The arguments are those of exahype2.api.Solver.generate_solver_realisation().
184 Both solvers are realised without global tasks. The load balancing and the dynamic
185 mesh refinement wrap the coupled time step graph afterwards, through the scheme of CCZ4.
191 f
"Host {self.name} has no numerical_scheme. Assign one to the host."
196 solver.generate_solver_realisation(
203 add_global_tasks=
False,
205 coupled_time_step.merge(own_time_step)
206 self.
_couple(exahype2_project, peano_project, coupled_time_step)
208 self.
ccz4.numerical_scheme.wrap_task_graph_in_load_balancing_and_amr_tasks(
211 if self.
ccz4.mesh_adaptation
is not None:
212 self.
ccz4.mesh_adaptation.construct_output(
213 exahype2_project, peano_project, mesh_adaptation
216 title = f
"Time stepping task graph for host {self.name}"
218 coupled_time_step.visualise(title=title)
220 coupled_time_step.log_as_text(title=title)
221 time_step.merge(coupled_time_step)
223 def _couple(self, exahype2_project, peano_project, time_step):
226 Let each stage of the CCZ4 solver use the freshly reconstructed derivatives
228 In each stage, the CCZ4 solver interpolates the unknowns and the
229 derivatives onto the hanging faces, reconstructs their halos, and
230 evaluates the right-hand side. The reconstruction solver recomputes
231 the derivatives from the unknowns in between, i.e.
233 - the first reconstruction tasks of the stage wait for whatever the
234 CCZ4 solver's interpolation of the derivatives waits for,
235 - the interpolation of the primary variables also waits for the
236 CCZ4 solver's interpolation of the unknowns, as both write the same
238 - the CCZ4 solver's interpolation of the derivatives and its
239 reconstruction of the unknowns wait for the last reconstruction task.
241 The chain is hence a block within the stage: The maximum concurrency of
242 the merged graph does not exceed the one of the two graphs.
244 @param exahype2_project: exahype2.api.Project
245 The project that hosts the pair (unused).
247 @param peano_project: peano4.api.Project
248 The Peano project that the exahype2 project assembles (unused).
250 @param time_step: peano4.api.taskgraph.Graph
251 The concatenated time stepping graphs of both solvers. It receives the dependencies.
255 def find(task_name, stage):
256 found = [t
for t
in time_step.tasks
if t.name == task_name]
259 f
"Host {self.name}: cannot find the task {task_name} "
260 f
"of stage {stage} of solver {self.ccz4.name} in its time stepping task graph"
265 for stage, graph
in enumerate(
268 first_tasks = graph.source_tasks()
269 (last_task,) = graph.sink_tasks()
275 unknowns_interpolation = find(unknowns_name, stage)
276 derivatives_interpolation = find(derivatives_name, stage)
277 for dependency
in derivatives_interpolation.dependencies:
278 for first_task
in first_tasks:
279 first_task.add_dependency(dependency)
280 first_tasks[0].add_dependency(unknowns_interpolation)
281 derivatives_interpolation.add_dependency(last_task)
282 find(reconstruction_name, stage).add_dependency(last_task)
Solver for the Einstein equations in the first-/second-order reconstructed CCZ4 formulation.
Reconstructs the first derivatives which exagrype.api.FOSOCCZ4Solver needs.
CCZ4 in the first-/second-order reconstructed formulation as a coupled pair.
exahype2.api.Solver.NumericalScheme numerical_scheme(self)
The scheme of ccz4.
generate_solver_realisation(self, exahype2_project, peano_project, setup_simulation, time_step, plot, mesh_adaptation)
Realise both solvers, couple their time stepping graphs, and add the outcome to the project's graphs.
__init__(self, str name, Dict[str, Union[int, float]] parameters=None, exahype2.api.InitPointWisely initial_condition=None, str reconstruction_name=None)
_couple(self, exahype2_project, peano_project, time_step)
Let each stage of the CCZ4 solver use the freshly reconstructed derivatives.
The numerical scheme of the reconstruction solver.
__init__(self, solver, ccz4)
wrap_task_graph_in_load_balancing_and_amr_tasks(self, time_step)
FOSOSolver wraps the concatenated graph through the scheme of CCZ4.
construct_output(self, exahype2_project, peano_project, time_step, add_global_tasks=True)
Point-wise initial condition: given the physical position of a single degree of freedom,...
Singleton logger for the Peano 4 Python API.
Holds a sequence of Task instances.
The task graph abstraction allows users to formalise their solver steps over small task graphs which ...