Peano
Loading...
Searching...
No Matches
Euler.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
6
7from ..FOCCZ4Solver import FOCCZ4Solver
8from . import initialvalues
9
10
12 """!
13
14 Compressible Euler equations of an ideal gas
15
16 The solver evolves the five conserved quantities density, momentum and
17 total energy,
18
19 @f$
20 \\partial_t \\begin{pmatrix} \\rho \\\\ j \\\\ E \\end{pmatrix}
21 + \\nabla \\cdot \\begin{pmatrix} j \\\\ j \\otimes j / \\rho + p I \\\\ (E+p) j / \\rho \\end{pmatrix} = 0,
22 \\qquad p = (\\gamma-1) \\left(E - \\frac{|j|^2}{2\\rho}\\right),
23 @f$
24
25 in three dimensions. It has a flux, a maximum eigenvalue, a source term and an initial
26 condition, all of them stateless. The source term is zero.
27 Flux, source and eigenvalue see the CCZ4 fields, even though they ignore
28 them at the moment. The solver always holds a
29 set of auxiliary variables with the 58 entries of first-order CCZ4,
30 which the user attaches (add_auxiliary_variables()); generating the
31 solver without it fails. By default, the
32 initial condition is a density wave which the fluid advects with
33 constant velocity (initialvalues.smooth_wave()).
34
35 The solver is deliberately plain. Its purpose within ExaGRyPE is to be
36 the matter ingredient which one couples to exagrype.api.FOCCZ4Solver. The
37 assembly of such a coupled system is not part of this class, but done by
38 the user (see benchmarks/exagrype/gauge-wave-with-Euler), who typically
39 attaches auxiliary variables (@ref exahype2.api.AuxiliaryVariables) with
40 the spacetime to the solver, and replaces the flux and the source term
41 through the hooks _flux_implementation() and _source_implementation().
42
43 ## Shortcomings
44
45 - The equations are those of flat-space hydrodynamics, i.e. the solver
46 knows nothing about general relativity on its own.
47 - Only ideal gases are supported, and there is no positivity limiter.
48
49 """
50
51 Unknowns = {
52 "rho": 1,
53 "j": 3,
54 "E": 1,
55 }
56 """! The five conserved quantities in the order the flux expects them """
57
59 self,
60 name: str,
61 gamma: float = 1.4,
62 initial_condition: exahype2.api.InitPointWisely = None,
63 ):
64 """!
65
66 Create an Euler solver
67
68 @param name: str
69 Name of the solver, @ref exahype2.api.Solver.
70
71 @param gamma: float
72 Adiabatic index of the ideal gas. Has to be greater than one.
73
74 @param initial_condition: exahype2.api.InitPointWisely
75 Initial condition. Defaults to exagrype.api.euler.initialvalues.smooth_wave().
76
77 """
78 if gamma <= 1.0:
79 raise ValueError(f"Solver {name}: gamma has to be greater than one")
80 super().__init__(name, unknowns=self.Unknowns)
81 self._gamma = gamma
82
84 '#include "exagrype/euler/EulerKernels.h"\n'
85 '#include "exagrype/euler/initialvalues/InitialValues.h"\n'
86 )
88 'static_assert(Dimensions == 3, "The Euler solver of ExaGRyPE is three-dimensional only");'
89 )
91 f"static constexpr double Gamma = {gamma!r};"
92 )
93
94 self._flux = exahype2.api.Flux(implementation="", stateless=True)
95 self._source = exahype2.api.VolumetricSource(implementation="", stateless=True)
97 implementation="", stateless=True
98 )
99 self.add_pde_term(self._flux)
100 self.add_pde_term(self._source)
102 self.add_pde_term(
103 initial_condition if initial_condition is not None else initialvalues.smooth_wave()
104 )
105
106 def add_auxiliary_variables(self, auxiliary: exahype2.api.AuxiliaryVariables):
107 """!
108
109 Attach a set of auxiliary variables and hand it to flux, source and eigenvalue
110
111 The sets are not known when the constructor creates the PDE terms, so
112 the terms are (re)built from the hooks whenever a set arrives. They
113 stay empty until the first set has been attached.
114
115 @param auxiliary: exahype2.api.AuxiliaryVariables
116 The set, @ref exahype2.api.Solver.add_auxiliary_variables().
117
118 """
119 super().add_auxiliary_variables(auxiliary)
120 self._refresh_pde_terms()
121
122 def generate_solver_realisation(self, *args, **kwargs):
123 """!
124
125 Reject solvers that do not see the CCZ4 fields
126
127 The Euler solver is the matter part of a coupled system with
128 first-order CCZ4. Hence, it always holds a set of auxiliary variables
129 with as many entries as FOCCZ4Solver has unknowns. Flux, source and
130 eigenvalue rely on this and do not handle solvers without
131 auxiliary variables. The check runs at generation time, as the sets
132 are attached after the constructor.
133
134 """
135 size = sum(FOCCZ4Solver.Unknowns.values())
136 if self._ccz4_fields_set() is None:
137 raise ValueError(
138 f"Solver {self.name}: the Euler solver needs a set of auxiliary variables "
139 f"with the {size} entries of first-order CCZ4, but has "
140 f"{[(a.name, a.size) for a in self.auxiliary_variables]}"
141 )
142 return super().generate_solver_realisation(*args, **kwargs)
143
145 """!
146
147 Rebuild the implementations of flux, source and eigenvalue from the hooks
148
149 Nothing happens before the set with the CCZ4 fields has been attached,
150 as the kernels need it.
151
152 """
153 if self._ccz4_fields_set() is None:
154 return
155 self._flux.implementation = self._flux_implementation()
156 self._source.implementation = self._source_implementation()
157 self._max_eigenvalue.implementation = self._max_eigenvalue_implementation()
158
160 """!
161
162 The set of auxiliary variables which holds the CCZ4 fields
163
164 It is the set with as many entries as FOCCZ4Solver has unknowns. Other
165 sets (such as the lapse of a toy coupling) are not handed to the kernels.
166
167 @return exahype2.api.AuxiliaryVariables
168 The set, or None if it has not been attached yet.
169
170 """
171 size = sum(FOCCZ4Solver.Unknowns.values())
172 candidates = [a for a in self.auxiliary_variables if a.size == size]
173 if len(candidates) > 1:
174 raise ValueError(
175 f"Solver {self.name}: more than one set of auxiliary variables has the {size} entries of CCZ4: "
176 f"{[a.name for a in candidates]}"
177 )
178 return candidates[0] if candidates else None
179
180 def _ccz4_fields(self) -> str:
181 """!
182
183 C++ expression of the pointer to the CCZ4 fields in a PDE term
184
185 The kernels of exagrype::euler take it as ccz4Fields.
186
187 """
188 return self._ccz4_fields_set().argument_name
189
190 @property
191 def gamma(self) -> float:
192 """! Adiabatic index of the gas"""
193 return self._gamma
194
195 def _flux_implementation(self) -> str:
196 """!
197
198 C++ of the flux along normal
199
200 Hook for subclasses, which can scale or modify the flux, e.g. by the
201 lapse of a spacetime they hold as auxiliary variables. The code has
202 the variables Q, x, normal and F at hand, plus one pointer per set of
203 auxiliary variables (the CCZ4 fields: _ccz4_fields()). The default
204 calls exagrype::euler::flux().
205
206 """
207 return f"""
208 ::exagrype::euler::flux( Q, {self._ccz4_fields()}, normal, Gamma, F );
209"""
210
211 def _source_implementation(self) -> str:
212 """!
213
214 C++ of the volumetric source
215
216 Hook for subclasses. The code has Q, x, t and S at hand, plus the
217 arguments of _flux_implementation(). The default calls
218 exagrype::euler::source(), which yields zero.
219
220 """
221 return f"""
222 ::exagrype::euler::source( Q, {self._ccz4_fields()}, Gamma, S );
223"""
224
226 return f"""
227 *lambdaMax = ::exagrype::euler::maxEigenvalue( Q, {self._ccz4_fields()}, normal, Gamma );
228"""
Compressible Euler equations of an ideal gas.
Definition Euler.py:11
_refresh_pde_terms(self)
Rebuild the implementations of flux, source and eigenvalue from the hooks.
Definition Euler.py:144
__init__(self, str name, float gamma=1.4, exahype2.api.InitPointWisely initial_condition=None)
Create an Euler solver.
Definition Euler.py:63
float gamma(self)
Adiabatic index of the gas.
Definition Euler.py:191
str _max_eigenvalue_implementation(self)
Definition Euler.py:225
_ccz4_fields_set(self)
The set of auxiliary variables which holds the CCZ4 fields.
Definition Euler.py:159
str _source_implementation(self)
C++ of the volumetric source.
Definition Euler.py:211
add_auxiliary_variables(self, exahype2.api.AuxiliaryVariables auxiliary)
Attach a set of auxiliary variables and hand it to flux, source and eigenvalue.
Definition Euler.py:106
generate_solver_realisation(self, *args, **kwargs)
Reject solvers that do not see the CCZ4 fields.
Definition Euler.py:122
str _flux_implementation(self)
C++ of the flux along normal.
Definition Euler.py:195
str _ccz4_fields(self)
C++ expression of the pointer to the CCZ4 fields in a PDE term.
Definition Euler.py:180
A set of auxiliary variables of a solver.
The conservative flux F(Q) of a hyperbolic PDE.
Definition Flux.py:8
Point-wise initial condition: given the physical position of a single degree of freedom,...
The maximum absolute eigenvalue of the flux Jacobian in a given direction, i.e.
Abstract base class for all ExaHyPE 2 solvers.
Definition Solver.py:17
add_abstract_solver_attribute(self, str declaration)
Add a raw C++ member attribute declaration to the generated Abstract<SolverName> class (.
Definition Solver.py:947
add_pde_term(self, PDETerm term)
Register a PDE term with this solver, or replace the one already registered under the same name and s...
Definition Solver.py:916
add_user_solver_includes(self, str value)
Add further includes to this property, if your solver requires some additional routines from other he...
Definition Solver.py:825
List["AuxiliaryVariables"] auxiliary_variables(self)
All sets of auxiliary variables in the order they have been attached.
Definition Solver.py:754
The algebraic, volume-distributed source term S(Q) of a hyperbolic PDE - as opposed to PointSource,...