Peano
Loading...
Searching...
No Matches
AddLopsidedAdvection.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 peano4.api
4
5from .AbstractRKFD4ActionSet import AbstractRKFD4ActionSet
6
7
9 """!
10
11 Add advection terms with lopsided stencils to the right-hand side of one Runge-Kutta stage
12
13 The action set reads the input of the stage with its halo
14 (solver._patch_with_halo) and adds the advection terms to the stage's
15 slot of solver._rhs_estimates via
16 exahype2::fd::addLopsidedAdvection(). It has to run after
17 exahype2.api.rkfd4.actionsets.EvaluateRightHandSide, which overwrites
18 the slot, within the same task. @ref
19 exahype2.api.rkfd4.CentralDifferencesWithRungeKutta arranges this if
20 the user selects the kernel CentralDifferencesWithLopsidedAdvection.
21
22 """
23
24 def __init__(self, solver, stage, velocity, quantities, guard):
25 """!
26
27 @param solver: exahype2.api.Solver
28 Has to have an exahype2.api.rkfd4.CentralDifferencesWithRungeKutta
29 as numerical scheme.
30
31 @param stage: int
32 Number of the Runge-Kutta stage, starting with zero.
33
34 @param velocity: List[int]
35 Indices of the entries of Q which hold the velocity, one per
36 dimension.
37
38 @param quantities: List[int]
39 Indices of the unknowns which are advected.
40
41 @param guard: str
42 C++ boolean expression, evaluated per cell in touchCellFirstTime.
43
44 """
45 super().__init__(solver)
46 self.stage = stage
47 self.velocity = velocity
48 self.quantities = quantities
49 self.guard = guard
50
51 def get_body_of_operation(self, operation_name):
52 if (
53 operation_name
54 != peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
55 ):
56 return ""
57 scheme = self._solver.numerical_scheme
58 n = scheme.patch_size
59 unknowns = self._solver.unknowns
60 velocity = ", ".join(str(index) for index in self.velocity)
61 quantities = ", ".join(str(quantity) for quantity in self.quantities)
62 return f"""
63 constexpr int advectionVelocity[] = {{ {velocity} }};
64 constexpr int advectedQuantities[] = {{ {quantities} }};
65 static_assert(sizeof(advectionVelocity) / sizeof(int) == Dimensions, "The advection velocity needs one entry per dimension");
66 #if Dimensions==2
67 double* estimate = fineGridCell{self._solver._rhs_estimates.name}.value + {self.stage * unknowns * n * n};
68 #else
69 double* estimate = fineGridCell{self._solver._rhs_estimates.name}.value + {self.stage * unknowns * n * n * n};
70 #endif
71 ::exahype2::fd::addLopsidedAdvection(
72 fineGridCell{self._solver._patch_with_halo.name}.value,
73 estimate,
74 marker.h(),
75 {n},
76 {scheme.overlap},
77 {unknowns},
78 {self._solver.auxiliary_variables},
79 advectionVelocity,
80 advectedQuantities,
81 {len(self.quantities)}
82 );
83"""
84
85 def get_guard_of_operation(self, operation_name):
86 if (
87 operation_name
88 == peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
89 ):
90 return self.guard
91 return "true"
92
93 def get_includes(self):
94 return super().get_includes() + '\n#include "exahype2/fd/LopsidedAdvection.h"\n'
95
97 return __name__.replace(".py", "").replace(".", "_")
Base class of the action sets of exahype2.api.rkfd4 which work against the solver.
Add advection terms with lopsided stencils to the right-hand side of one Runge-Kutta stage.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_guard_of_operation(self, operation_name)
Return the guard of an operation.
get_action_set_name(self)
You should replicate this function in each subclass, so you get meaningful action set names (otherwis...
get_includes(self)
The includes cover the kernels the numerical scheme generates (exahype2.api.rkfd4....