Peano
Loading...
Searching...
No Matches
SingleSweep.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
3from .FV import FV
4from exahype2.solvers.PDETerms import PDETerms
5
6import peano4
7import exahype2
8
9import jinja2
10
11from peano4.toolbox.blockstructured.ReconstructPatchAndApplyFunctor import ReconstructPatchAndApplyFunctor
12
13
15 SolveRiemannProblemsOverPatch = jinja2.Template("""
16 double timeStamp = fineGridCell{{SOLVER_NAME}}CellLabel.getTimeStamp();
17
18 // Set the variable
19 // double timeStepSize
20 {{COMPUTE_TIME_STEP_SIZE}}
21
22 {{PREPROCESS_RECONSTRUCTED_PATCH}}
23
24 assertion2(tarch::la::greaterEquals(timeStamp, 0.0), timeStamp, timeStepSize);
25 assertion2(tarch::la::greaterEquals(timeStepSize, 0.0), timeStamp, timeStepSize);
26
27 ::exahype2::fv::validatePatch(
28 oldQWithHalo,
29 {{NUMBER_OF_UNKNOWNS}},
30 {{NUMBER_OF_AUXILIARY_VARIABLES}},
31 {{NUMBER_OF_VOLUMES_PER_AXIS}},
32 1, // Halo size
33 std::string(__FILE__) + "(" + std::to_string(__LINE__) + "): " + marker.toString()
34 ); // Previous time step has to be valid
35
36 ::exahype2::CellData patchData(oldQWithHalo, marker.x(), marker.h(), timeStamp, timeStepSize, newQ);
37
38 {% if STATELESS_PDE_TERMS %}
39 if (repositories::{{SOLVER_INSTANCE}}.patchCanUseStatelessPDETerms(
40 marker.x(),
41 marker.h(),
42 timeStamp,
43 timeStepSize
44 )) {
45 ::exahype2::fv::{{KERNEL_NAMESPACE}}::{{COMPUTE_KERNEL_CALL_STATELESS}}
46 } else
47 {% endif %}
48
49 ::exahype2::fv::{{KERNEL_NAMESPACE}}::{{COMPUTE_KERNEL_CALL}}
50
51 {{POSTPROCESS_UPDATED_PATCH}}
52
53 ::exahype2::fv::validatePatch(
54 newQ,
55 {{NUMBER_OF_UNKNOWNS}},
56 {{NUMBER_OF_AUXILIARY_VARIABLES}},
57 {{NUMBER_OF_VOLUMES_PER_AXIS}},
58 0, // Halo size
59 std::string(__FILE__) + "(" + std::to_string(__LINE__) + "): " + marker.toString()
60 ); // Outcome has to be valid
61
62 {% if COMPUTE_MAX_EIGENVALUE %}
63 const double maxEigenvalue = patchData.maxEigenvalue[0];
64 {% endif %}
65
66 // Set the variable
67 // double newTimeStepSize
68 {{COMPUTE_NEW_TIME_STEP_SIZE}}
69
70 fineGridCell{{SOLVER_NAME}}CellLabel.setTimeStamp(timeStamp+timeStepSize);
71 fineGridCell{{SOLVER_NAME}}CellLabel.setTimeStepSize(newTimeStepSize);
72 fineGridCell{{SOLVER_NAME}}CellLabel.setHasUpdated(true);
73
74 repositories::{{SOLVER_INSTANCE}}.update(newTimeStepSize, timeStamp+timeStepSize, marker.h()(0));
75 """)
76
77
78 def __init__(self, solver):
79 """
80 """
81 ReconstructPatchAndApplyFunctor.__init__(self,
82 patch = solver._patch,
83 patch_overlap = solver._patch_overlap_new,
84 functor_implementation = """
85#error Please switch to your Riemann solver of choice
86""",
87 reconstructed_array_memory_location = solver._reconstructed_array_memory_location,
88 guard = "not marker.willBeRefined() and not marker.hasBeenRefined()",
89 add_assertions_to_halo_exchange = False
90 )
91 self._solver = solver
92
94 else if (not marker.willBeRefined() and not marker.hasBeenRefined()) {{
95 const double timeStamp = fineGridCell{SOLVER_NAME}CellLabel.getTimeStamp();
96 const double timeStepSize = fineGridCell{SOLVER_NAME}CellLabel.getTimeStepSize();
97
98 assertion2(tarch::la::greaterEquals( timeStepSize, 0.0 ), timeStepSize, timeStamp);
99 assertion2(tarch::la::greaterEquals( timeStamp, 0.0 ), timeStepSize, timeStamp);
100
101 repositories::{SOLVER_INSTANCE}.update(0.0, timeStamp, marker.h()(0) );
102 }}
103"""
104
106 fineGridCell""" + solver._name + """CellLabel.setHasUpdated(false);
108
109
111 """
112 This is our plug-in point to alter the underlying dictionary
113 """
114 super(UpdateCell,self)._add_action_set_entries_to_dictionary(d)
115
116 self._solver._init_dictionary_with_default_parameters(d)
117 self._solver.add_entries_to_text_replacement_dictionary(d)
118
119 d["CELL_FUNCTOR_IMPLEMENTATION"] = self.SolveRiemannProblemsOverPatch.render(**d)
120
121
122 def get_includes(self):
123 return """
124#include "exahype2/fv/BoundaryConditions.h"
125#include "tarch/NonCriticalAssertions.h"
126""" + self._solver._get_default_includes() + self._solver.user_action_set_includes
127
128
130 """
131 Probably the simplest solver you could think off.
132
133 :: Write your own specialisation ::
134
135 self._preprocess_reconstructed_patch
136 Has to hold any preprocessing, but it also has to set the doubles
137 timeStepSize and timeStamp to valid data.
138
139 self._postprocess_updated_patch
140 You don't have to redefine this one, but if you want to alter the
141 time step size, then this is the right place to do so. If you don't
142 alter timeStepSize, the code will automatically continue with
143 the current one subject to a preprocessing in the next step.
144 """
145
146
147 def __init__(self,
148 name,
149 patch_size,
150 overlap,
151 unknowns,
152 auxiliary_variables,
153 min_volume_h,
154 max_volume_h,
155 pde_terms_without_state: bool,
156 plot_grid_properties: bool,
157 kernel_namespace):
158 """
159 Instantiate a generic FV scheme with an overlap of 1.
160 """
161 super(SingleSweep, self).__init__(name,
162 patch_size,
163 overlap,
164 unknowns,
165 auxiliary_variables,
166 min_volume_h,
167 max_volume_h,
168 pde_terms_without_state,
169 plot_grid_properties,
170 kernel_namespace)
171
173
174
176 """
177 Call the superclass' create_data_structures() to ensure that all the data
178 structures are in place, i.e., each cell can host a patch, that each face hosts
179 patch overlaps, and so forth. These quantities are all set to defaults. See
180 FV.create_data_structures().
181
182 After that, take the patch overlap (that's the data stored within the faces)
183 and ensure that these are sent and received via MPI whenever they are also
184 stored persistently. The default in FV is that no domain boundary data exchange
185 is active. Finally, ensure that the old data is only exchanged between the
186 initialisation sweep and the first first grid run-through.
187 """
188 super(SingleSweep, self).create_data_structures()
189
190 initialisation_sweep_guard = "(" + \
191 "repositories::" + self.get_name_of_global_instance() + ".getSolverState()==" + self._name + "::SolverState::GridInitialisation" + \
192 ")"
193 first_iteration_after_initialisation_guard = "(" + \
194 "repositories::" + self.get_name_of_global_instance() + ".getSolverState()==" + self._name + "::SolverState::TimeStepAfterGridInitialisation or " + \
195 "repositories::" + self.get_name_of_global_instance() + ".getSolverState()==" + self._name + "::SolverState::PlottingAfterGridInitialisation" + \
196 ")"
197
198 self._patch_overlap_new.generator.send_condition = "true"
199 self._patch_overlap_new.generator.receive_and_merge_condition = "true"
200
201 self._patch_overlap_old.generator.send_condition = initialisation_sweep_guard
202 self._patch_overlap_old.generator.receive_and_merge_condition = first_iteration_after_initialisation_guard
203
204
206 """
207 Call superclass routine and then reconfigure the update cell call.
208 Only the UpdateCell action set is specific to a single sweep.
209
210 This operation is implicitly called via the superconstructor.
211 """
212 super(SingleSweep, self).create_action_sets()
214
215
216 @property
218 return """
219#include "exahype2/CellData.h"
220""" + super(SingleSweep, self).user_action_set_includes
221
222
224 self,
225 boundary_conditions,
226 refinement_criterion,
227 initial_conditions,
228 memory_location,
229 use_split_loop,
230 additional_action_set_includes,
231 additional_user_includes
232 ):
233 """
234 If you pass in User_Defined, then the generator will create C++ stubs
235 that you have to befill manually. If you pass in None_Implementation, it
236 will create nop, i.e., no implementation or defaults. Any other string
237 is copied 1:1 into the implementation. If you pass in None, then the
238 set value so far won't be overwritten.
239 """
240 if boundary_conditions is not None: self._boundary_conditions_implementation_boundary_conditions_implementation = boundary_conditions
241 if refinement_criterion is not None: self._refinement_criterion_implementation_refinement_criterion_implementation = refinement_criterion
242 if initial_conditions is not None: self._initial_conditions_implementation_initial_conditions_implementation = initial_conditions
243 if memory_location is not None: self._reconstructed_array_memory_location_reconstructed_array_memory_location = memory_location
244 if use_split_loop : self._use_split_loop = use_split_loop
245
246 if refinement_criterion==exahype2.solvers.PDETerms.None_Implementation:
247 assert False, "Refinement criterion cannot be none"
248 if initial_conditions==exahype2.solvers.PDETerms.None_Implementation:
249 assert False, "Initial conditions cannot be none"
250
251 if self._reconstructed_array_memory_location_reconstructed_array_memory_location==peano4.toolbox.blockstructured.ReconstructedArrayMemoryLocation.HeapThroughTarchWithoutDelete or \
252 self._reconstructed_array_memory_location_reconstructed_array_memory_location==peano4.toolbox.blockstructured.ReconstructedArrayMemoryLocation.HeapWithoutDelete or \
253 self._reconstructed_array_memory_location_reconstructed_array_memory_location==peano4.toolbox.blockstructured.ReconstructedArrayMemoryLocation.ManagedSharedAcceleratorDeviceMemoryThroughTarchWithoutDelete:
254 raise Exception("Memory mode without appropriate delete chosen, i.e. this will lead to a memory leak" )
255
256 self._user_action_set_includes += additional_action_set_includes
257 self._user_solver_includes += additional_user_includes
258
260
261
263 """
264 d: Dictionary of string to string
265 in/out argument
266 """
267 pass
Abstract finite volume solver step sizes that works on patch-based AMR with a halo layer of one.
Definition FV.py:18
create_action_sets(self)
Create all the action sets.
Definition FV.py:730
get_name_of_global_instance(self)
Definition FV.py:986
Probably the simplest solver you could think off.
create_data_structures(self)
Call the superclass' create_data_structures() to ensure that all the data structures are in place,...
__init__(self, name, patch_size, overlap, unknowns, auxiliary_variables, min_volume_h, max_volume_h, bool pde_terms_without_state, bool plot_grid_properties, kernel_namespace)
Instantiate a generic FV scheme with an overlap of 1.
set_implementation(self, boundary_conditions, refinement_criterion, initial_conditions, memory_location, use_split_loop, additional_action_set_includes, additional_user_includes)
If you pass in User_Defined, then the generator will create C++ stubs that you have to befill manuall...
user_action_set_includes(self)
Add further includes to this property, if your action sets require some additional routines from othe...
add_entries_to_text_replacement_dictionary(self, d)
d: Dictionary of string to string in/out argument
create_action_sets(self)
Call superclass routine and then reconfigure the update cell call.
__init__(self, solver)
patch: peano4.datamodel.Patch Patch which is to be used
get_includes(self)
Return include statements that you need.
_add_action_set_entries_to_dictionary(self, d)
This is our plug-in point to alter the underlying dictionary.