Peano
Loading...
Searching...
No Matches
CCZ4WithScalarField_InnerCoupling.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
7
8from ..FOCCZ4Solver import FOCCZ4Solver
9from .ScalarField import ScalarField
10
11
13 """!
14
15 First-order CCZ4 and an advected scalar field with one numerical scheme for both
16
17 In an inner coupling, the numerical scheme sits in the coupled solver, i.e.
18 in this class. The two aggregated solvers hold no numerical scheme of
19 their own, and the user must not assign one to them. Instead, the user
20 attaches a "generator" (a numerical scheme of the coupled system) to the
21 coupled solver:
22
23 coupled = exagrype.api.scalarfield.CCZ4WithScalarField_InnerCoupling()
24 coupled.numerical_scheme = exagrype.api.scalarfield.RungeKuttaFD4InnerAdditive(patch_size=9, rk_order=4)
25
26 There are four generators, one for each combination of Finite Volumes
27 (explicit Euler) or Runge-Kutta with fourth-order Finite Differences, and
28 of multiplicative or additive coupling. They exchange the data in each
29 stage of the time integrator, i.e. both solvers advance the same stage,
30 and the solvers see each other's data of the same time level. This gives
31 the time integration order of the scheme: the lapse that the scalar field
32 sees in stage k is the lapse of the stage input of CCZ4.
33 The generators build the whole task graph of the combination, see
34 @ref exagrype.api.scalarfield.InnerCouplingGenerator.
35
36 Grid construction and plotters are not part of a generator, they are
37 assigned to the solvers (host.ccz4, host.scalar_field) as always. The
38 coupling is one-directional (fake coupling): CCZ4 does not see the field.
39 The auxiliary variables of the scalar field hold the CCZ4 fields and change
40 in each stage (exahype2.api.AuxiliaryVariables.Mode.CHANGING_ON_FACES).
41
42 """
43
44 def __init__(self, ccz4_name: str = "CCZ4", scalar_field_name: str = "ScalarField"):
45 """!
46
47 @param ccz4_name: str
48 Name of the CCZ4 solver.
49
50 @param scalar_field_name: str
51 Name of the scalar field solver.
52
53 """
54 self.ccz4 = FOCCZ4Solver(ccz4_name)
56 "CCZ4Fields",
57 dict(FOCCZ4Solver.Unknowns),
58 mode=exahype2.api.AuxiliaryVariables.Mode.CHANGING_ON_FACES,
59 data_name="CCZ4FieldsForScalarField",
60 )
61 self.scalar_field = ScalarField(scalar_field_name, self.ccz4_auxiliary_copies)
62 self._name = f"{ccz4_name}With{scalar_field_name}"
64
65 @property
66 def name(self) -> str:
67 return self._name
68
69 @property
70 def solvers(self):
71 """ The solvers the project has to register; exahype2.api.Project.add_solver() asks for them """
72 return [self.ccz4, self.scalar_field]
73
74 @property
76 """! The generator, i.e. the numerical scheme of the coupled system """
77 return self._numerical_scheme
78
79 @numerical_scheme.setter
80 def numerical_scheme(self, generator):
81 """!
82
83 Attach the generator of the coupled system
84
85 The aggregated solvers must not hold a numerical scheme of their own yet: the
86 generator installs the building blocks on the solvers itself.
87
88 """
89 for solver in self.solvers:
90 if solver.numerical_scheme is not None:
91 raise ValueError(
92 f"Solver {solver.name} holds a numerical scheme of its own. "
93 f"In an inner coupling, assign the numerical scheme to the coupled solver {self.name} only"
94 )
95 generator.attach_to(self)
96 self._numerical_scheme = generator
97
99 self,
100 exahype2_project,
101 peano_project,
102 setup_simulation,
103 time_step,
104 plot,
105 mesh_adaptation,
106 ):
107 """!
108
109 Let the generator build the task graph of the coupled system and add it to the project's graphs
110
111 The arguments are those of exahype2.api.Solver.generate_solver_realisation().
112
113 """
114 peano4.api.Logger().new_section("Host " + self.name)
115 assert self.numerical_scheme is not None, (
116 f"Coupled solver {self.name} has no numerical_scheme set. Assign a generator, "
117 "e.g. exagrype.api.scalarfield.RungeKuttaFD4InnerAdditive, to numerical_scheme."
118 )
119 self.numerical_scheme.construct_output(
120 exahype2_project,
121 peano_project,
122 setup_simulation,
123 time_step,
124 plot,
125 mesh_adaptation,
126 )
Solver for the Einstein equations in the first-order CCZ4 formulation.
First-order CCZ4 and an advected scalar field with one numerical scheme for both.
generate_solver_realisation(self, exahype2_project, peano_project, setup_simulation, time_step, plot, mesh_adaptation)
Let the generator build the task graph of the coupled system and add it 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