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 grid cells along the domain
18 boundary through exahype2.api.SommerfeldBoundaryConditions first
19
20 The action set replaces exahype2.api.rkfd4.actionsets.RollOverUpdatedFace
21 if the solver uses Sommerfeld boundary conditions. Such a solver has no
22 separate boundary task (exahype2.api.rkfd4.actionsets.ApplyDirichletBoundaryConditions).
23 In touchFaceLastTime(), the action set first writes the ghost grid cells
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 grid cells
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 projection of every Runge-Kutta stage uses
34 this variant: It advances the ghost grid cells from the time stamp of
35 the stage to the one of the next stage, i.e. time_step_size is
36 @f$ (c_{k+1}-c_k) \\Delta t @f$, or @f$ (1-c_{s-1}) \\Delta t @f$ after
37 the last stage (@ref
38 exahype2.api.rkfd4.CentralDifferencesWithRungeKutta).
39 - Without a time_step_size, the action set initialises the ghost grid cells
40 with the initial condition, i.e. it evaluates the solver's
41 initPointWisely() at their centres through
42 @ref exahype2::blockstructured::applyDirichletBoundaryConditions().
43 The grid construction uses this variant, so the first time step finds
44 valid ghost grid cells.
45
46 The C++ header documents the conditions, their discretisation and why
47 they replace the roll over. The class mirrors
48 exahype2.api.fv.actionsets.RollOverUpdatedFaceWithSommerfeldBoundaryConditions,
49 as rkfd4 does not depend on the Finite Volume package.
50
51 """
52
53 TemplateSommerfeldBoundaryConditions = jinja2.Template(
54 """
55 ::exahype2::blockstructured::applySommerfeldBoundaryConditions(
56 [](
57 const double* Q,
58 const tarch::la::Vector<Dimensions, double>& x,
59 int normal
60 ) -> double {
61 double lambdaMax;
62 repositories::{{SOLVER_INSTANCE}}.maxEigenvalue(Q, x, normal, &lambdaMax{{STATELESS_TAG}});
63 return lambdaMax;
64 },
65 [](const tarch::la::Vector<Dimensions, double>& x, double* Q) -> void {
66 repositories::{{SOLVER_INSTANCE}}.sommerfeldFarFieldSolution(x, Q);
67 },
68 marker,
69 DomainOffset,
70 DomainSize,
71 PeriodicBC,
72 {{DOFS_PER_AXIS}},
73 {{OVERLAP}},
74 {{NUMBER_OF_UNKNOWNS}},
75 {{NUMBER_OF_AUXILIARY_VARIABLES}},
76 tarch::la::Vector<Dimensions, double>({{ORIGIN}}),
77 {{TIME_STEP_SIZE}},
78 {{CURRENT_TIME_STEP_ACCESSOR}}.value,
79 {{UPDATE_ACCESSOR}}.value
80 );
81"""
82 )
83
84 TemplateInitialGhostCells = jinja2.Template(
85 """
86 ::exahype2::blockstructured::applyDirichletBoundaryConditions(
87 [](const tarch::la::Vector<Dimensions, double>& x, double t, double* Q) -> void {
88 repositories::{{SOLVER_INSTANCE}}.initPointWisely(x, Q);
89 },
90 marker,
91 DomainOffset,
92 DomainSize,
93 PeriodicBC,
94 {{DOFS_PER_AXIS}},
95 {{OVERLAP}},
96 {{NUMBER_OF_UNKNOWNS}} + {{NUMBER_OF_AUXILIARY_VARIABLES}},
97 repositories::{{SOLVER_INSTANCE}}.getMinTimeStamp(),
98 {{UPDATE_ACCESSOR}}.value
99 );
100"""
101 )
102
104 self,
105 solver,
106 patch_overlap_current_time_step,
107 patch_overlap_update,
108 guard,
109 includes,
110 origin,
111 time_step_size=None,
112 ):
113 """!
114
115 @param solver: exahype2.api.Solver
116 The solver whose maxEigenvalue(), sommerfeldFarFieldSolution() and
117 initPointWisely() are invoked.
118
119 @param patch_overlap_current_time_step: peano4.api.datamodel.Patch
120 @see RollOverUpdatedFace.
121
122 @param patch_overlap_update: peano4.api.datamodel.Patch
123 @see RollOverUpdatedFace.
124
125 @param guard: str
126 @see RollOverUpdatedFace.
127
128 @param includes: str
129 @see RollOverUpdatedFace.
130
131 @param origin: List[float]
132 Centre of the system, one entry per dimension, @ref
133 exahype2.api.blockstructured.SommerfeldBoundaryConditions.SommerfeldBoundaryConditions.get_origin().
134
135 @param time_step_size: str
136 C++ expression for the time step size by which the ghost grid cells
137 are advanced, or None to initialise the ghost grid cells with the
138 initial condition instead.
139
140 """
141 super().__init__(
142 patch_overlap_current_time_step, patch_overlap_update, guard, includes
143 )
144 self._time_step_size = time_step_size
145 self.d["SOLVER_INSTANCE"] = solver.get_name_of_global_instance()
146 self.d["NUMBER_OF_UNKNOWNS"] = str(solver.unknowns)
147 self.d["NUMBER_OF_AUXILIARY_VARIABLES"] = "0"
148 # The stateless eigenvalue variant is static and takes a dummy tag (@see PDETerm)
149 self.d["STATELESS_TAG"] = (
150 ", ::exahype2::Solver::Offloadable::Yes"
151 if get_max_eigenvalue_term_for_sommerfeld(solver).stateless
152 else ""
153 )
154 self.d["ORIGIN"] = "{" + ", ".join(repr(float(x)) for x in origin) + "}"
155 self.d["TIME_STEP_SIZE"] = time_step_size
156
157 def get_body_of_operation(self, operation_name):
158 result = super().get_body_of_operation(operation_name)
159 if (
160 operation_name
161 == peano4.api.solversteps.ActionSet.OPERATION_TOUCH_FACE_LAST_TIME
162 ):
163 template = (
165 if self._time_step_size is None
167 )
168 result = template.render(**self.d) + result
169 return result
170
172 return __name__.replace(".py", "").replace(".", "_")
173
174 def get_includes(self):
175 return (
176 """
177#include "exahype2/blockstructured/DirichletBoundaryConditions.h"
178#include "exahype2/blockstructured/SommerfeldBoundaryConditions.h"
179"""
180 + super().get_includes()
181 )
182
183 @staticmethod
185 solver,
186 exahype2_project,
187 guard,
188 includes,
189 time_step_size=None,
190 ):
191 """!
192
193 Create the roll over of the solver's face data
194
195 @return RollOverUpdatedFace
196 RollOverUpdatedFaceWithSommerfeldBoundaryConditions if the solver
197 uses exahype2.api.SommerfeldBoundaryConditions, and a plain
198 RollOverUpdatedFace otherwise, i.e. for Dirichlet boundary
199 conditions or a domain without boundary.
200
201 @param solver: exahype2.api.Solver
202 The solver whose solver._patch_overlap_update is rolled over into
203 solver._patch_overlap_current_time_step. Its boundary condition
204 terms have to be consistent with the domain, @ref
205 exahype2.api.blockstructured.BoundaryConditions.get_boundary_conditions().
206
207 @param exahype2_project: exahype2.api.Project
208 Provides the periodic boundary conditions.
209
210 @param guard: str
211 @see RollOverUpdatedFace.
212
213 @param includes: str
214 @see RollOverUpdatedFace.
215
216 @param time_step_size: str
217 @see the constructor. Ignored for a plain RollOverUpdatedFace.
218
219 """
220 term = get_boundary_conditions(solver, exahype2_project)
221 if isinstance(term, SommerfeldBoundaryConditions):
223 solver,
224 solver._patch_overlap_current_time_step,
225 solver._patch_overlap_update,
226 guard=guard,
227 includes=includes,
228 origin=term.get_origin(len(exahype2_project.periodic_BC)),
229 time_step_size=time_step_size,
230 )
231 return RollOverUpdatedFace(
232 solver._patch_overlap_current_time_step,
233 solver._patch_overlap_update,
234 guard=guard,
235 includes=includes,
236 )
Sommerfeld (radiative, outgoing) boundary conditions: waves leave the domain with little reflection,...
__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.rkfd4.actionsets.ProjectPatchOntoFaces has ...