Peano
Loading...
Searching...
No Matches
PreprocessSolution.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
3
4from .AbstractRungeKuttaDGActionSet import AbstractRungeKuttaDGActionSet
5
6
7import peano4
8import jinja2
9
10
12 """
13
14 PreprocessSolution differs from other action sets, as I only create it once. See
15 FV.create_action_sets(). Once the instance does exist, you can tailor it. But you
16 can also completely overwrite it.
17
18 """
19 def __init__(self,solver):
20 super(EmptyPreprocessSolution,self).__init__(solver)
21 # Is there for compatibility reasons
22 self.guard = "true"
24
25
26 def get_body_of_operation(self,operation_name):
27 result = ""
28 return result
29
30
32 return __name__.replace(".py", "").replace(".", "_")
33
34
35
36
37
39 """
40
41 PreprocessSolution differs from other action sets, as I only create it once. See
42 FV.create_action_sets(). Once the instance does exist, you can tailor it. But you
43 can also completely overwrite it.
44
45 The postprocessing plugs into touch cell last time. It is the last action set added
46 by the default implementation. Therefore, it is the first action set of which
47 touchCellLastTime() is called. The reason why I plug into the leaving of the cell
48 is that some solvers may add further action sets to the solve. Enclave tasking for
49 example adds the merger as additional action set. These action sets plug into
50 touchCellFirstTime() - and consequently their first time is called after the
51 postprocessing's first time. By making the postprocessing use touchCellLastTime(),
52 I ensure that any additional action set added by a subclass can still precede the
53 postprocessing.
54
55 """
56 def __init__(self,solver):
57 super(DoFWisePreprocessSolution,self).__init__(solver)
58 self.guard = "true"
61
62
63 def add_postprocessing_kernel(self, operation_per_point):
64 """
65
66 Add a code snippet which is applied to each and every point. You have the following
67 variables which are well-defined:
68
69 - value: Is a pointer to the current finite volume's data
70 - x: A tarch::la::Vector over doubles
71 - marker.h(): A tarch::la::Vector over doubles
72
73
74 operation_per_point: String
75 C/C++ code snippet
76
77 """
78 self._compute_kernel += """
79{
80 {{COMPUTE_TIME_STEP_SIZE}}
81 const double timeStamp = fineGridCell{{SOLVER_NAME}}CellLabel.getTimeStamp();
82
83 if (
84 not marker.hasBeenRefined()
85 and
86 {{PREDICATE}}
87 ) {
88 logTraceIn( "touchCellFirstTime(...)" );
89
90 ::exahype2::enumerator::AoSLexicographicEnumerator enumerator(
91 1, // only one patch
92 {{DG_ORDER}}+1,
93 0, // int haloSize,
94 {{NUMBER_OF_UNKNOWNS}},
95 {{NUMBER_OF_AUXILIARY_VARIABLES}}
96 );
97 dfor( index, {{DG_ORDER}}+1 ) {
98 double* values = fineGridCell{{UNKNOWN_IDENTIFIER}}.value + enumerator(0,index,0);
99 auto x = ::exahype2::dg::getQuadraturePoint(
100 marker.x(), marker.h(), index, repositories::{{SOLVER_INSTANCE}}.DGOrder, repositories::{{SOLVER_INSTANCE}}.QuadraturePoints1d
101 );
102 """ + operation_per_point + """
103 }
104 logTraceOut( "touchCellFirstTime(...)" );
105 }
106}
107"""
108
109
110
111 def get_body_of_operation(self,operation_name):
112 result = ""
113 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_CELL_LAST_TIME:
114 d = {}
115 self._solver._init_dictionary_with_default_parameters(d)
116 self._solver.add_entries_to_text_replacement_dictionary(d)
117 d[ "PREDICATE" ] = jinja2.Template(self.guard, undefined=jinja2.DebugUndefined).render(**d)
118 result = jinja2.Template(self._compute_kernel, undefined=jinja2.DebugUndefined).render(**d)
119 pass
120 return result
121
122
124 return __name__.replace(".py", "").replace(".", "_")
125
126
127 def get_includes(self):
128 return super(DoFWisePreprocessSolution,self).get_includes() + """
129#include "exahype2/enumerator/AoSLexicographicEnumerator.h"
130"""
131
132
133
135 """
136
137
138 """
139 def __init__(self,solver):
140 super(CellWisePreprocessSolution,self).__init__(solver)
141 self.guard = "true"
143
144
145 def add_postprocessing_kernel(self, operation_per_cell):
146 """
147
148 Add a code snippet which is applied to each and every point. You have the following
149 variables which are well-defined:
150
151 - value: Is a pointer to the current finite volume's data
152 - x: A tarch::la::Vector over doubles
153 - marker.h(): A tarch::la::Vector over doubles
154
155
156 operation_per_point: String
157 C/C++ code snippet
158
159 """
160 self._compute_kernel += """
161{
162 {{COMPUTE_TIME_STEP_SIZE}}
163 const double timeStamp = fineGridCell{{SOLVER_NAME}}CellLabel.getTimeStamp();
164
165 if (
166 not marker.hasBeenRefined()
167 and
168 {{PREDICATE}}
169 ) {
170 logTraceIn( "touchCellFirstTime(...)" );
171
172 """ + operation_per_cell + """
173
174 logTraceOut( "touchCellFirstTime(...)" );
175 }
176}
177"""
178
179
180
181 def get_body_of_operation(self,operation_name):
182 result = ""
183 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_CELL_LAST_TIME:
184 d = {}
185 self._solver._init_dictionary_with_default_parameters(d)
186 self._solver.add_entries_to_text_replacement_dictionary(d)
187 d[ "PREDICATE" ] = jinja2.Template(self.guard, undefined=jinja2.DebugUndefined).render(**d)
188 result = jinja2.Template(self._compute_kernel, undefined=jinja2.DebugUndefined).render(**d)
189 pass
190 return result
191
192
194 return __name__.replace(".py", "").replace(".", "_")
195
get_action_set_name(self)
You should replicate this function in each subclass, so you get meaningful action set names (otherwis...
add_postprocessing_kernel(self, operation_per_cell)
Add a code snippet which is applied to each and every point.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
__init__(self, solver)
solver: RungeKuttaDG Reference to creating class
PreprocessSolution differs from other action sets, as I only create it once.
get_action_set_name(self)
You should replicate this function in each subclass, so you get meaningful action set names (otherwis...
__init__(self, solver)
solver: RungeKuttaDG Reference to creating class
add_postprocessing_kernel(self, operation_per_point)
Add a code snippet which is applied to each and every point.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
PreprocessSolution differs from other action sets, as I only create it once.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
__init__(self, solver)
solver: RungeKuttaDG Reference to creating class
get_action_set_name(self)
You should replicate this function in each subclass, so you get meaningful action set names (otherwis...