Peano
Loading...
Searching...
No Matches
RollOverUpdatedFaceWithSommerfeldBoundaryConditions.py
Go to the documentation of this file.
1# This file is part of the ExaHyPE2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3import jinja2
4import peano4.api
5
6from .RollOverUpdatedFace import RollOverUpdatedFace
7from ...blockstructured.BoundaryConditions import (
8 get_boundary_conditions,
9 get_max_eigenvalue_term_for_sommerfeld,
10)
11from ...blockstructured.SommerfeldBoundaryConditions import SommerfeldBoundaryConditions
12
13
15 """!
16
17 Roll over the face data, and set the ghost volumes along the domain
18 boundary through exahype2.api.SommerfeldBoundaryConditions first
19
20 The action set replaces exahype2.api.fv.actionsets.RollOverUpdatedFace
21 if the solver uses Sommerfeld boundary conditions. Such a solver has no
22 separate boundary task (exahype2.api.fv.actionsets.ApplyDirichletBoundaryConditions).
23 In touchFaceLastTime(), the action set first writes the ghost volumes
24 into the ghost half of patch_overlap_update, and then rolls over both
25 halves into patch_overlap_current_time_step like RollOverUpdatedFace.
26 Faces within the domain and faces along periodic axes are rolled over
27 unchanged. There are two variants:
28
29 - With a time_step_size, the action set advances the ghost volumes
30 through @ref exahype2::blockstructured::applySommerfeldBoundaryConditions().
31 patch_overlap_current_time_step still holds the old solution, i.e.
32 both its halves are valid, and patch_overlap_update holds the new
33 interior solution. The time step uses this variant.
34 - Without a time_step_size, the action set initialises the ghost volumes
35 with the initial condition, i.e. it evaluates the solver's
36 initPointWisely() at their centres through
37 @ref exahype2::blockstructured::applyDirichletBoundaryConditions().
38 The grid construction uses this variant, so the first time step finds
39 valid ghost volumes.
40
41 The C++ header documents the conditions, their discretisation and why
42 they replace the roll over.
43
44 """
45
46 TemplateSommerfeldBoundaryConditions = jinja2.Template(
47 """
48 ::exahype2::blockstructured::applySommerfeldBoundaryConditions(
49 [](
50 const double* Q,
51 const tarch::la::Vector<Dimensions, double>& x,
52 int normal
53 ) -> double {
54 double lambdaMax;
55 repositories::{{SOLVER_INSTANCE}}.maxEigenvalue(Q, x, normal, &lambdaMax{{STATELESS_TAG}});
56 return lambdaMax;
57 },
58 [](const tarch::la::Vector<Dimensions, double>& x, double* Q) -> void {
59 repositories::{{SOLVER_INSTANCE}}.sommerfeldFarFieldSolution(x, Q);
60 },
61 marker,
62 DomainOffset,
63 DomainSize,
64 PeriodicBC,
65 {{DOFS_PER_AXIS}},
66 {{OVERLAP}},
67 {{NUMBER_OF_UNKNOWNS}},
68 {{NUMBER_OF_AUXILIARY_VARIABLES}},
69 tarch::la::Vector<Dimensions, double>({{ORIGIN}}),
70 {{TIME_STEP_SIZE}},
71 {{CURRENT_TIME_STEP_ACCESSOR}}.value,
72 {{UPDATE_ACCESSOR}}.value
73 );
74"""
75 )
76
77 TemplateInitialGhostCells = jinja2.Template(
78 """
79 ::exahype2::blockstructured::applyDirichletBoundaryConditions(
80 [](const tarch::la::Vector<Dimensions, double>& x, double t, double* Q) -> void {
81 repositories::{{SOLVER_INSTANCE}}.initPointWisely(x, Q);
82 },
83 marker,
84 DomainOffset,
85 DomainSize,
86 PeriodicBC,
87 {{DOFS_PER_AXIS}},
88 {{OVERLAP}},
89 {{NUMBER_OF_UNKNOWNS}} + {{NUMBER_OF_AUXILIARY_VARIABLES}},
90 repositories::{{SOLVER_INSTANCE}}.getMinTimeStamp(),
91 {{UPDATE_ACCESSOR}}.value
92 );
93"""
94 )
95
97 self,
98 solver,
99 patch_overlap_current_time_step,
100 patch_overlap_update,
101 guard,
102 includes,
103 origin,
104 time_step_size=None,
105 ):
106 """!
107
108 @param solver: exahype2.api.Solver
109 The solver whose maxEigenvalue(), sommerfeldFarFieldSolution() and
110 initPointWisely() are invoked.
111
112 @param patch_overlap_current_time_step: peano4.api.datamodel.Patch
113 @see RollOverUpdatedFace.
114
115 @param patch_overlap_update: peano4.api.datamodel.Patch
116 @see RollOverUpdatedFace.
117
118 @param guard: str
119 @see RollOverUpdatedFace.
120
121 @param includes: str
122 @see RollOverUpdatedFace.
123
124 @param origin: List[float]
125 Centre of the system, one entry per dimension, @ref
126 exahype2.api.blockstructured.SommerfeldBoundaryConditions.SommerfeldBoundaryConditions.get_origin().
127
128 @param time_step_size: str
129 C++ expression for the time step size by which the ghost volumes
130 are advanced, or None to initialise the ghost volumes with the
131 initial condition instead.
132
133 """
134 super().__init__(
135 patch_overlap_current_time_step, patch_overlap_update, guard, includes
136 )
137 self._time_step_size = time_step_size
138 self.d["SOLVER_INSTANCE"] = solver.get_name_of_global_instance()
139 self.d["NUMBER_OF_UNKNOWNS"] = str(solver.unknowns)
140 self.d["NUMBER_OF_AUXILIARY_VARIABLES"] = "0"
141 # The stateless eigenvalue variant is static and takes a dummy tag (@see PDETerm)
142 self.d["STATELESS_TAG"] = (
143 ", ::exahype2::Solver::Offloadable::Yes"
144 if get_max_eigenvalue_term_for_sommerfeld(solver).stateless
145 else ""
146 )
147 self.d["ORIGIN"] = "{" + ", ".join(repr(float(x)) for x in origin) + "}"
148 self.d["TIME_STEP_SIZE"] = time_step_size
149
150 def get_body_of_operation(self, operation_name):
151 result = super().get_body_of_operation(operation_name)
152 if (
153 operation_name
154 == peano4.api.solversteps.ActionSet.OPERATION_TOUCH_FACE_LAST_TIME
155 ):
156 template = (
158 if self._time_step_size is None
160 )
161 result = template.render(**self.d) + result
162 return result
163
165 return __name__.replace(".py", "").replace(".", "_")
166
167 def get_includes(self):
168 return (
169 """
170#include "exahype2/blockstructured/DirichletBoundaryConditions.h"
171#include "exahype2/blockstructured/SommerfeldBoundaryConditions.h"
172"""
173 + super().get_includes()
174 )
175
176 @staticmethod
178 solver,
179 exahype2_project,
180 guard,
181 includes,
182 time_step_size=None,
183 ):
184 """!
185
186 Create the roll over of the solver's face data
187
188 @return RollOverUpdatedFace
189 RollOverUpdatedFaceWithSommerfeldBoundaryConditions if the solver
190 uses exahype2.api.SommerfeldBoundaryConditions, and a plain
191 RollOverUpdatedFace otherwise, i.e. for Dirichlet boundary
192 conditions or a domain without boundary.
193
194 @param solver: exahype2.api.Solver
195 The solver whose solver._patch_overlap_update is rolled over into
196 solver._patch_overlap_current_time_step. Its boundary condition
197 terms have to be consistent with the domain, @ref
198 exahype2.api.blockstructured.BoundaryConditions.get_boundary_conditions().
199
200 @param exahype2_project: exahype2.api.Project
201 Provides the periodic boundary conditions.
202
203 @param guard: str
204 @see RollOverUpdatedFace.
205
206 @param includes: str
207 @see RollOverUpdatedFace.
208
209 @param time_step_size: str
210 @see the constructor. Ignored for a plain RollOverUpdatedFace.
211
212 """
213 term = get_boundary_conditions(solver, exahype2_project)
214 if isinstance(term, SommerfeldBoundaryConditions):
216 solver,
217 solver._patch_overlap_current_time_step,
218 solver._patch_overlap_update,
219 guard=guard,
220 includes=includes,
221 origin=term.get_origin(len(exahype2_project.periodic_BC)),
222 time_step_size=time_step_size,
223 )
224 return RollOverUpdatedFace(
225 solver._patch_overlap_current_time_step,
226 solver._patch_overlap_update,
227 guard=guard,
228 includes=includes,
229 )
Sommerfeld (radiative, outgoing) boundary conditions: waves leave the domain with little reflection,...
create_roll_over(solver, exahype2_project, guard, includes, time_step_size=None)
Create the roll over of the solver's face data.
__init__(self, solver, patch_overlap_current_time_step, patch_overlap_update, guard, includes, origin, time_step_size=None)
Copy patch_overlap_update - the face overlap exahype2.api.fv.actionsets.ProjectPatchOntoFaces has jus...