Peano
Loading...
Searching...
No Matches
DynamicAMR.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
4import exahype2
5import jinja2
6
7
8from .AbstractRungeKuttaDGActionSet import AbstractRungeKuttaDGActionSet
9from .ProjectLinearCombinationOfEstimatesOntoFaces import FaceProjections
10from .ProjectLinearCombinationOfEstimatesOntoFaces import compute_number_of_face_projection_quantities
11
12
14 """
15
16 Default DG interpolation/restriction action set
17
18 There is a detailed description of the DG AMR semantics in the exahype2 C++
19 directory. Logically, any AMR mesh transition translates into a Riemann
20 problem. The documentation hence is stored in the Riemann.h file.
21
22 """
23
24
25 def __init__(self,
26 solver,
27 face_projections: FaceProjections):
28 """
29
30 The guards are those for the projection onto the faces.
31
32 """
33 super(DynamicAMR,self).__init__(solver)
35 self.face_projections = face_projections
36
37
39 return __name__.replace(".py", "").replace(".", "_")
40
41
42 def get_includes(self):
43 return super(DynamicAMR,self).get_includes() + """
44#include <cstring>
45"""
46
47
48 __Template_TouchFaceFirstTime = """
49 {% for PREDICATE_NO in range(0,PREDICATES|length) %}
50 if ( {{PREDICATES[PREDICATE_NO]}} ) {
51 ::exahype2::dg::clearSolutionProjection(
52 {{ORDER}},
53 {{NUMBER_OF_UNKNOWNS}},
54 {{NUMBER_OF_AUXILIARY_VARIABLES}},
55 {{NUMBER_OF_PROJECTED_QUANTITIES}},
56 fineGridFace{{UNKNOWN_IDENTIFIER}}EstimateProjection.value
57 );
58 }
59 {% endfor %}
60"""
61
62
63 __Template_CreateHangingFace = """
64 ::exahype2::dg::interpolateRiemannSolution(
65 marker,
66 {{ORDER}},
67 {{NUMBER_OF_UNKNOWNS}},
68 repositories::{{SOLVER_INSTANCE}}.InterpolationMatrix1d,
69 coarseGridFaces{{UNKNOWN_IDENTIFIER}}RiemannSolution(marker.getSelectedFaceNumber()).value,
70 fineGridFace{{UNKNOWN_IDENTIFIER}}RiemannSolution.value
71 );
72
73 fineGridFace{{FACE_LABEL}}.setNewTimeStamp(0, std::max( coarseGridFaces{{FACE_LABEL}}(marker.getSelectedFaceNumber()).getNewTimeStamp(0), fineGridFace{{FACE_LABEL}}.getNewTimeStamp(0)) );
74 fineGridFace{{FACE_LABEL}}.setNewTimeStamp(1, std::max( coarseGridFaces{{FACE_LABEL}}(marker.getSelectedFaceNumber()).getNewTimeStamp(1), fineGridFace{{FACE_LABEL}}.getNewTimeStamp(1)) );
75 fineGridFace{{FACE_LABEL}}.setOldTimeStamp(0, std::max( coarseGridFaces{{FACE_LABEL}}(marker.getSelectedFaceNumber()).getOldTimeStamp(0), fineGridFace{{FACE_LABEL}}.getOldTimeStamp(0)) );
76 fineGridFace{{FACE_LABEL}}.setOldTimeStamp(1, std::max( coarseGridFaces{{FACE_LABEL}}(marker.getSelectedFaceNumber()).getOldTimeStamp(1), fineGridFace{{FACE_LABEL}}.getOldTimeStamp(1)) );
77"""
78
79
80 __Template_DestroyHangingFace = """
81 {% for PREDICATE_NO in range(0,PREDICATES|length) %}
82 if ( {{PREDICATES[PREDICATE_NO]}} ) {
83 ::exahype2::dg::restrictAndAccumulateProjectedFacePolynomial(
84 marker,
85 {{ORDER}},
86 {{NUMBER_OF_PROJECTED_QUANTITIES}},
87 {{NUMBER_OF_UNKNOWNS}},
88 {{NUMBER_OF_AUXILIARY_VARIABLES}},
89 repositories::{{SOLVER_INSTANCE}}.RestrictionMatrix1d,
90 fineGridFace{{UNKNOWN_IDENTIFIER}}EstimateProjection.value,
91 coarseGridFaces{{UNKNOWN_IDENTIFIER}}EstimateProjection(marker.getSelectedFaceNumber()).value
92 );
93
94 bool isLeftEntryOnCoarseFaceLabel = marker.getSelectedFaceNumber() >= Dimensions;
95 coarseGridFaces{{FACE_LABEL}}(marker.getSelectedFaceNumber()).setUpdated( isLeftEntryOnCoarseFaceLabel ? 0 : 1,true);
96 coarseGridFaces{{FACE_LABEL}}(marker.getSelectedFaceNumber()).setUpdatedTimeStamp(
97 isLeftEntryOnCoarseFaceLabel ? 0 : 1,
98 std::max(
99 coarseGridFaces{{FACE_LABEL}}(marker.getSelectedFaceNumber()).getUpdatedTimeStamp( isLeftEntryOnCoarseFaceLabel ? 0 : 1 ),
100 fineGridFace{{FACE_LABEL}}.getUpdatedTimeStamp( isLeftEntryOnCoarseFaceLabel ? 0 : 1 )
101 )
102 );
103 }
104 {% endfor %}
105"""
106
107
108 def get_body_of_operation(self,operation_name):
109 d = {}
110 self._solver._init_dictionary_with_default_parameters(d)
111 self._solver.add_entries_to_text_replacement_dictionary(d)
112 d[ "PREDICATES" ] = self.guardsguardsguards
113 d[ "FACE_LABEL" ] = self._solver._face_label.name
114 d[ "NUMBER_OF_PROJECTED_QUANTITIES" ] = compute_number_of_face_projection_quantities( self.face_projections )
115
116 result = "\n"
117 if operation_name==peano4.solversteps.ActionSet.OPERATION_CREATE_HANGING_FACE:
118 result = jinja2.Template(self.__Template_CreateHangingFace).render(**d)
119 pass
120# if operation_name==ActionSet.OPERATION_CREATE_PERSISTENT_FACE:
121# result = jinja2.Template(self.__Template_CreatePersistentFace_Prologue).render(**self.d)
122# result += jinja2.Template(self.__Template_CreatePersistentFace_Core).render(**self.d)
123# result += jinja2.Template(self.__Template_CreatePersistentFace_Epilogue).render(**self.d)
124# pass
125 if operation_name==peano4.solversteps.ActionSet.OPERATION_DESTROY_HANGING_FACE:
126 result = jinja2.Template(self.__Template_DestroyHangingFace).render(**d)
127 pass
128# if operation_name==ActionSet.OPERATION_DESTROY_PERSISTENT_FACE:
129# result = jinja2.Template(self.__Template_TouchFaceFirstTime).render(**d)
130# pass
131# if operation_name==ActionSet.OPERATION_CREATE_CELL:
132# result = jinja2.Template(self.__Template_CreateCell_Prologue).render(**self.d)
133# result += jinja2.Template(self.__Template_CreateCell_Core).render(**self.d)
134# result += jinja2.Template(self.__Template_CreateCell_Epilogue).render(**self.d)
135# pass
136# if operation_name==ActionSet.OPERATION_DESTROY_CELL:
137# result = jinja2.Template(self.__Template_DestroyCell_Prologue).render(**self.d)
138# result += jinja2.Template(self.__Template_DestroyCell_Core).render(**self.d)
139# result += jinja2.Template(self.__Template_DestroyCell_Epilogue).render(**self.d)
140# pass
141 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_FACE_FIRST_TIME:
142 result = jinja2.Template(self.__Template_TouchFaceFirstTime).render(**d)
143 pass
144# if operation_name==ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
145# result = jinja2.Template(self.__Template_TouchCellFirstTime).render(**self.d)
146# pass
147 return result
148
149
150 @property
151 def guards(self):
152 if self._guards==[]:
153 raise Exception( "Guards are not initialised" )
154 return self._guards
155
156
157 @guards.setter
158 def guards(self,new_guards):
159 if new_guards!=[] and len(new_guards)!=self._solver.number_of_Runge_Kutta_steps():
160 raise Exception( "Expect one guard per Runge Kutta step. Have {} steps but got guards {}".format(solver.number_of_Runge_Kutta_steps(),guards) )
161 self._guards = new_guards
162
Default DG interpolation/restriction action set.
Definition DynamicAMR.py:13
get_action_set_name(self)
You should replicate this function in each subclass, so you get meaningful action set names (otherwis...
Definition DynamicAMR.py:38
__init__(self, solver, FaceProjections face_projections)
The guards are those for the projection onto the faces.
Definition DynamicAMR.py:27
get_includes(self)
Return include statements that you need.
Definition DynamicAMR.py:42
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.