Peano 4
Loading...
Searching...
No Matches
HandleBoundary.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
6from exahype2.solvers.ButcherTableau import ButcherTableau
7
8import peano4
9import jinja2
10
11
13 """
14
15 The linear combination of the Runge Kutta trials has to be projected onto
16 the faces, so we can then solve the Riemann problems. So the projection
17 happens in one grid sweep, the corresponding Riemann solve in the next one.
18
19 ## Time step/time stamp handling
20
21 We rely on ProjectLinearCombinationOfEstimatesOntoFaces to project the
22 current solution onto the faces.
23
24
25 """
26
27 TemplateHandleBoundary_Prologue = """
28 {% for PREDICATE_NO in range(0,PREDICATES|length) %}
29 if (
30 {{PREDICATES[PREDICATE_NO]}}
31 and
32 not repositories::{{SOLVER_INSTANCE}}.PeriodicBC[marker.getSelectedFaceNumber()%Dimensions]
33 and
34 not marker.hasBeenRefined()
35 and
36 fineGridFace{{SOLVER_NAME}}FaceLabel.getBoundary()
37 ) {
38 const double timeStampOldSolution = fineGridFace{{SOLVER_NAME}}FaceLabel.getOldTimeStamp()(0);
39
40 // Set the variable
41 // double timeStepSize
42 {{COMPUTE_TIME_STEP_SIZE}}
43
44 const double timeStamp = timeStampOldSolution + {{BUTCHER_TABLEAU_RELATIVE_TIME_STEP_SIZES[PREDICATE_NO]}} * timeStepSize;
45
46 assertion5( tarch::la::greaterEquals( timeStepSize, 0.0 ), timeStamp, timeStepSize, timeStampOldSolution, marker.toString(), fineGridFace{{SOLVER_NAME}}FaceLabel.toString() );
47 assertion5( tarch::la::greaterEquals( timeStamp, 0.0 ), timeStamp, timeStepSize, timeStampOldSolution, marker.toString(), fineGridFace{{SOLVER_NAME}}FaceLabel.toString() );
48
49"""
50
51 TemplateHandleBoundary_KernelCalls = """
52 ::exahype2::dg::applyBoundaryConditions(
53 [&](
54 const double * __restrict__ Qinside,
55 double * __restrict__ Qoutside,
56 const tarch::la::Vector<Dimensions,double>& x,
57 double t,
58 double dt,
59 int normal
60 ) -> void {
61 repositories::{{SOLVER_INSTANCE}}.boundaryConditions( Qinside, Qoutside, x, t, normal );
62 },
63 marker.x(),
64 marker.h(),
65 timeStamp,
66 repositories::{{SOLVER_INSTANCE}}.getMinTimeStepSize(),
67 {{ORDER}},
68 {{NUMBER_OF_UNKNOWNS}},
69 {{NUMBER_OF_AUXILIARY_VARIABLES}},
70 marker.getSelectedFaceNumber(),
71 repositories::{{SOLVER_INSTANCE}}.QuadraturePoints1d,
72 fineGridFace{{UNKNOWN_IDENTIFIER}}EstimateProjection.value
73 );
74"""
75
76 TemplateHandleBoundary_Epilogue = """
77
78 if (marker.getSelectedFaceNumber()<Dimensions) {
79 fineGridFace{{SOLVER_NAME}}FaceLabel.setUpdatedTimeStamp(0, fineGridFace{{SOLVER_NAME}}FaceLabel.getUpdatedTimeStamp(1) );
80 fineGridFace{{SOLVER_NAME}}FaceLabel.setNewTimeStamp (0, fineGridFace{{SOLVER_NAME}}FaceLabel.getNewTimeStamp(1) );
81 fineGridFace{{SOLVER_NAME}}FaceLabel.setOldTimeStamp (0, fineGridFace{{SOLVER_NAME}}FaceLabel.getOldTimeStamp(1) );
82 }
83 else {
84 fineGridFace{{SOLVER_NAME}}FaceLabel.setUpdatedTimeStamp(1, fineGridFace{{SOLVER_NAME}}FaceLabel.getUpdatedTimeStamp(0) );
85 fineGridFace{{SOLVER_NAME}}FaceLabel.setNewTimeStamp( 1, fineGridFace{{SOLVER_NAME}}FaceLabel.getNewTimeStamp(0) );
86 fineGridFace{{SOLVER_NAME}}FaceLabel.setOldTimeStamp( 1, fineGridFace{{SOLVER_NAME}}FaceLabel.getOldTimeStamp(0) );
87 }
88 }
89 {% endfor %}
90"""
91
92 def __init__(self, solver, guard):
93 """
94
95 guard_project: String (C++ code)
96 Predicate which controls if the solution is actually projected
97
98 guard_safe_old_time_step: String (C++ code)
99 Predicate which controls if the projection should be copied into
100 the old solution and the time step should also be moved over
101
102 """
103 super(HandleBoundary, self).__init__(solver)
106
107 @property
108 def guards(self):
109 if self._guards == []:
110 raise Exception("Guards are not initialised")
111 return self._guards
112
113 @guards.setter
114 def guards(self, new_guards):
115 if (
116 new_guards != []
117 and len(new_guards) != self._solver.number_of_Runge_Kutta_steps()
118 ):
119 raise Exception(
120 "Expect one guard per Runge Kutta step. Have {} steps but got guards {}".format(
121 solver.number_of_Runge_Kutta_steps(), guards
122 )
123 )
124 self._guards = new_guards
125
126 def get_body_of_operation(self, operation_name):
127 result = ""
128 if (
129 operation_name
130 == peano4.solversteps.ActionSet.OPERATION_TOUCH_FACE_FIRST_TIME
131 ):
132 d = {}
133 self._solver._init_dictionary_with_default_parameters(d)
134 self._solver.add_entries_to_text_replacement_dictionary(d)
135 d["PREDICATES"] = self.guardsguardsguards
136 d[
137 "BUTCHER_TABLEAU_RELATIVE_TIME_STEP_SIZES"
138 ] = self._butcher_tableau.time_step_sizes()
139 result = jinja2.Template(
143 ).render(**d)
144 pass
145 return result
146
148 return __name__.replace(".py", "").replace(".", "_")
The linear combination of the Runge Kutta trials has to be projected onto the faces,...
__init__(self, solver, guard)
guard_project: String (C++ code) Predicate which controls if the solution is actually projected
get_action_set_name(self)
You should replicate this function in each subclass, so you get meaningful action set names (otherwis...
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.