Peano
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 .AbstractFVActionSet import AbstractFVActionSet
5
6import peano4
7import jinja2
8
10 """
11
12 The global periodic boundary conditions are set in the Constants.h.
13
14 There is no need to update QOld along the faces. QOld is always rolled
15 over from QNew, i.e. we may assume it is already set correctly. It is
16 not correctly set in the very first time step (after InitGrid, we haven't
17 yet set QOld), so apply the boundary conditions here would even confuse
18 the assertions.
19
20 """
21 TemplateHandleBoundary_Prologue = """
22 if (
23 {{PREDICATE}}
24 and
25 not repositories::{{SOLVER_INSTANCE}}.PeriodicBC[marker.getSelectedFaceNumber()%Dimensions]
26 and
27 not marker.hasBeenRefined()
28 and
29 fineGridFace{{SOLVER_NAME}}FaceLabel.getBoundary()
30 ) {
31 logTraceInWith3Arguments( "touchFaceFirstTime(...)", fineGridFace{{SOLVER_NAME}}FaceLabel.toString(), (repositories::{{SOLVER_INSTANCE}}.PeriodicBC[marker.getSelectedFaceNumber()%Dimensions]), marker.toString() );
32
33"""
34
35
36 TemplateHandleBoundary_KernelCalls = """
37 ::exahype2::fv::applyBoundaryConditions(
38 [&](
39 const double * __restrict__ Qinside,
40 double * __restrict__ Qoutside,
41 const tarch::la::Vector<Dimensions,double>& faceCentre,
42 const tarch::la::Vector<Dimensions,double>& volumeH,
43 double t,
44 double dt,
45 int normal
46 ) -> void {
47 repositories::{{SOLVER_INSTANCE}}.boundaryConditions( Qinside, Qoutside, faceCentre, volumeH, t, normal );
48 },
49 marker.x(),
50 marker.h(),
51 {{FACE_METADATA_ACCESSOR}}.getNewTimeStamp(marker.getSelectedFaceNumber()<Dimensions ? 1 : 0),
52 repositories::{{SOLVER_INSTANCE}}.getMinTimeStepSize(),
53 {{NUMBER_OF_VOLUMES_PER_AXIS}},
54 {{OVERLAP}},
55 {{NUMBER_OF_UNKNOWNS}}+{{NUMBER_OF_AUXILIARY_VARIABLES}},
56 marker.getSelectedFaceNumber(),
57 fineGridFace{{UNKNOWN_IDENTIFIER}}New.value
58 );
59 ::exahype2::fv::applyBoundaryConditions(
60 [&](
61 const double * __restrict__ Qinside,
62 double * __restrict__ Qoutside,
63 const tarch::la::Vector<Dimensions,double>& faceCentre,
64 const tarch::la::Vector<Dimensions,double>& volumeH,
65 double t,
66 double dt,
67 int normal
68 ) -> void {
69 repositories::{{SOLVER_INSTANCE}}.boundaryConditions( Qinside, Qoutside, faceCentre, volumeH, t, normal );
70 },
71 marker.x(),
72 marker.h(),
73 {{FACE_METADATA_ACCESSOR}}.getOldTimeStamp(marker.getSelectedFaceNumber()<Dimensions ? 1 : 0),
74 repositories::{{SOLVER_INSTANCE}}.getMinTimeStepSize(),
75 {{NUMBER_OF_VOLUMES_PER_AXIS}},
76 {{OVERLAP}},
77 {{NUMBER_OF_UNKNOWNS}}+{{NUMBER_OF_AUXILIARY_VARIABLES}},
78 marker.getSelectedFaceNumber(),
79 fineGridFace{{UNKNOWN_IDENTIFIER}}Old.value
80 );
81"""
82
83
84 TemplateHandleBoundary_Epilogue = """
85
86 bool isLeftEntryOutside = marker.getSelectedFaceNumber() < Dimensions;
87 double innerTimeStamp;
88
89 innerTimeStamp = {{FACE_METADATA_ACCESSOR}}.getUpdatedTimeStamp( isLeftEntryOutside ? 1 : 0 );
90 {{FACE_METADATA_ACCESSOR}}.setUpdatedTimeStamp( isLeftEntryOutside ? 0 : 1, innerTimeStamp );
91
92 innerTimeStamp = {{FACE_METADATA_ACCESSOR}}.getNewTimeStamp( isLeftEntryOutside ? 1 : 0 );
93 {{FACE_METADATA_ACCESSOR}}.setNewTimeStamp( isLeftEntryOutside ? 0 : 1, innerTimeStamp );
94
95 innerTimeStamp = {{FACE_METADATA_ACCESSOR}}.getOldTimeStamp( isLeftEntryOutside ? 1 : 0 );
96 {{FACE_METADATA_ACCESSOR}}.setOldTimeStamp( isLeftEntryOutside ? 0 : 1, innerTimeStamp );
97
98 logTraceOut( "touchFaceFirstTime(...)" );
99 }
100 else {
101 logDebug( "touchFaceFirstTime(...)", "skip face " << marker.toString() );
102 }
103"""
104
105 def __init__(self,solver,guard):
106 AbstractFVActionSet.__init__(self,solver)
107 self.guard = guard
108
109
110 def get_body_of_operation(self,operation_name):
111 result = ""
112 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_FACE_FIRST_TIME:
113 self.d = {}
114 self._solver._init_dictionary_with_default_parameters(self.d)
115 self._solver.add_entries_to_text_replacement_dictionary(self.d)
116 self.d[ "PREDICATE" ] = self.guard
117 self.d[ "FACE_METADATA_ACCESSOR" ] = "fineGridFace" + self._solver._face_label.name
118 result = jinja2.Template(self.TemplateHandleBoundary_Prologue).render(**self.d)
119 result += jinja2.Template(self.TemplateHandleBoundary_KernelCalls).render(**self.d)
120 result += jinja2.Template(self.TemplateHandleBoundary_Epilogue).render(**self.d)
121 pass
122 return result
123
124
125 def get_includes(self):
126 return """
127#include "exahype2/fv/BoundaryConditions.h"
128""" + AbstractFVActionSet.get_includes(self)
129
130
132 return __name__.replace(".py", "").replace(".", "_")
The global periodic boundary conditions are set in the Constants.h.
get_action_set_name(self)
You should replicate this function in each subclass, so you get meaningful action set names (otherwis...
__init__(self, solver, guard)
solver: ADERDG Reference to creating class
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_includes(self)
Return include statements that you need.