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.EvaluateRungeKuttaRightHandSide, 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 TASK_NAME = "Add lopsided advection"
25 """! Name of the task which hosts the action set (@ref exahype2.api.rkfd4.CentralDifferencesWithRungeKutta) """
26
27 def __init__(self, solver, stage, velocity, quantities, guard):
28 """!
29
30 @param solver: exahype2.api.Solver
31 Has to have an exahype2.api.rkfd4.CentralDifferencesWithRungeKutta
32 as numerical scheme.
33
34 @param stage: int
35 Number of the Runge-Kutta stage, starting with zero.
36
37 @param velocity: List[int]
38 Indices of the entries of Q which hold the velocity, one per
39 dimension.
40
41 @param quantities: List[int]
42 Indices of the unknowns which are advected.
43
44 @param guard: str
45 C++ boolean expression, evaluated per cell in touchCellFirstTime.
46
47 """
48 super().__init__(solver)
49 self.stage = stage
50 self.velocity = velocity
51 self.quantities = quantities
52 self.guard = guard
53
54 def get_body_of_operation(self, operation_name):
55 if (
56 operation_name
57 != peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
58 ):
59 return ""
60 scheme = self._solver.numerical_scheme
61 n = scheme.patch_size
62 unknowns = self._solver.unknowns
63 velocity = ", ".join(str(index) for index in self.velocity)
64 quantities = ", ".join(str(quantity) for quantity in self.quantities)
65 return f"""
66 constexpr int advectionVelocity[] = {{ {velocity} }};
67 constexpr int advectedQuantities[] = {{ {quantities} }};
68 static_assert(sizeof(advectionVelocity) / sizeof(int) == Dimensions, "The advection velocity needs one entry per dimension");
69 #if Dimensions==2
70 double* estimate = fineGridCell{self._solver._rhs_estimates.name}.value + {self.stage * unknowns * n * n};
71 #else
72 double* estimate = fineGridCell{self._solver._rhs_estimates.name}.value + {self.stage * unknowns * n * n * n};
73 #endif
74 ::exahype2::fd::addLopsidedAdvection(
75 fineGridCell{self._solver._patch_with_halo.name}.value,
76 estimate,
77 marker.h(),
78 {n},
79 {scheme.overlap},
80 {unknowns},
81 {0},
82 advectionVelocity,
83 advectedQuantities,
84 {len(self.quantities)}
85 );
86"""
87
88 def get_guard_of_operation(self, operation_name):
89 if (
90 operation_name
91 == peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
92 ):
93 return self.guard
94 return "true"
95
96 def get_includes(self):
97 return super().get_includes() + '\n#include "exahype2/fd/LopsidedAdvection.h"\n'
98
100 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....