Peano
Loading...
Searching...
No Matches
CCZ4WithScalarField_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
8
9from ..FOCCZ4Solver import FOCCZ4Solver
10from ..actionsets import SynchroniseTimeStepSizes
11from .ScalarField import ScalarField
12from .create_copy_task import create_copy_task
13
14
16 """!
17
18 First-order CCZ4 and an advected scalar field, run one after the other within each time step
19
20 The class is the sibling of exagrype.api.euler.CCZ4WithEuler_OuterMultiplicativeCoupling,
21 but the coupling is one-directional (fake coupling): The scalar field sees
22 the spacetime, CCZ4 does not see the field. We get one copy task only:
23
24 graph of CCZ4 -> copy (CCZ4 into scalar field) -> graph of scalar field -> synchronise
25
26 i.e. the scalar field sees the CCZ4 fields after CCZ4 has completed its step.
27 Each solver brings its own numerical scheme, assigned to the solvers
28 (@ref exahype2.api.rkfd4.CentralDifferencesWithRungeKutta, ...), and
29 the solvers do not exchange data within their Runge-Kutta stages. The
30 spacetime is hence frozen at the end of the time step while the scalar field
31 performs its whole step, and the coupling is first order in the time step
32 size, however high the order of the time integrators is. An inner coupling
33 (@ref exagrype.api.scalarfield.CCZ4WithScalarField_InnerCoupling) yields the order of the integrators.
34
35 The graphs are chained with peano4.api.taskgraph.Graph.append(). Each solver graph
36 ends in a GLOBAL_END_OF_STEP task that computes the next time step size.
37 A final GLOBAL_END_OF_STEP task enforces the minimum of both time step sizes.
38
39 """
40
41 COPY_TASK_NAME = "Copy CCZ4 fields into {}"
42 """! Name of the task that fills the auxiliary variables; the argument is the name of the scalar field solver """
43 SYNCHRONISE_TASK_NAME = "Synchronise time step sizes"
44 """! Name of the final task """
45
46 def __init__(self, ccz4_name: str = "CCZ4", scalar_field_name: str = "ScalarField"):
47 """!
48
49 @param ccz4_name: str
50 Name of the CCZ4 solver.
51
52 @param scalar_field_name: str
53 Name of the scalar field solver.
54
55 """
56 self.ccz4 = FOCCZ4Solver(ccz4_name)
58 "CCZ4Fields",
59 dict(FOCCZ4Solver.Unknowns),
60 mode=exahype2.api.AuxiliaryVariables.Mode.STATIONARY_THROUGHOUT_TIME_STEPS_ON_FACES,
61 data_name="CCZ4FieldsForScalarField",
62 )
63 self.scalar_field = ScalarField(scalar_field_name, self.ccz4_auxiliary_copies)
64 self._name = f"{ccz4_name}With{scalar_field_name}"
65
66 @property
67 def name(self) -> str:
68 return self._name
69
70 @property
71 def solvers(self):
72 """ The solvers the project has to register; exahype2.api.Project.add_solver() asks for them """
73 return [self.ccz4, self.scalar_field]
74
76 self,
77 exahype2_project,
78 peano_project,
79 setup_simulation,
80 time_step,
81 plot,
82 mesh_adaptation,
83 ):
84 """!
85
86 Realise both solvers, chain their time stepping graphs, and add the outcome to the project's graphs
87
88 The arguments are those of exahype2.api.Solver.generate_solver_realisation().
89 Both solvers are realised without global tasks. The load balancing and the dynamic
90 mesh refinement wrap the chained time step graph afterwards, through the scheme of CCZ4.
91
92 """
93 peano4.api.Logger().new_section("Host " + self.name)
94 Entity = peano4.api.taskgraph.Task.GridEntity
95
96 ccz4_time_step = peano4.api.taskgraph.Graph()
97 scalar_field_time_step = peano4.api.taskgraph.Graph()
98 for solver, graph in [
99 (self.ccz4, ccz4_time_step),
100 (self.scalar_field, scalar_field_time_step),
101 ]:
102 solver.generate_solver_realisation(
103 exahype2_project,
104 peano_project,
105 setup_simulation,
106 graph,
107 plot,
108 mesh_adaptation,
109 add_global_tasks=False,
110 )
111
113 copy.add_task(
114 create_copy_task(
115 self.COPY_TASK_NAME.format(self.scalar_field.name),
116 self.ccz4._patch,
117 self.scalar_field,
119 )
120 )
121
122
123 coupled_time_step = peano4.api.taskgraph.Graph()
124 coupled_time_step.append(ccz4_time_step)
125 coupled_time_step.append(copy)
126 coupled_time_step.append(scalar_field_time_step)
127
128
129 synchronise = peano4.api.taskgraph.Task(
130 name=self.SYNCHRONISE_TASK_NAME, entity=Entity.GLOBAL_END_OF_STEP
131 )
132 for task in coupled_time_step.sink_tasks():
133 synchronise.add_dependency(task)
134 synchronise.add_action_set(
135 SynchroniseTimeStepSizes([self.ccz4, self.scalar_field])
136 )
137 coupled_time_step.add_task(synchronise)
138
139 self.ccz4.numerical_scheme.wrap_task_graph_in_load_balancing_and_amr_tasks(
140 coupled_time_step
141 )
142 if self.ccz4.mesh_adaptation is not None:
143 self.ccz4.mesh_adaptation.construct_output(
144 exahype2_project, peano_project, mesh_adaptation
145 )
146
147 title = f"Time stepping task graph for host {self.name}"
148 if peano4.api.Logger().is_visualisation:
149 coupled_time_step.visualise(title=title)
150 if peano4.api.Logger().is_text:
151 coupled_time_step.log_as_text(title=title)
152 time_step.merge(coupled_time_step)
Solver for the Einstein equations in the first-order CCZ4 formulation.
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.
Four scalar fields which a spacetime advects.
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