Peano
Loading...
Searching...
No Matches
InterpolateHangingFaces.py
Go to the documentation of this file.
1# This file is part of the Peano project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3import enum
4
5import jinja2
6
7from peano4.api.solversteps.ActionSet import ActionSet
8
9
11 """!
12
13 Initialise the overlap data on hanging faces from the coarser mesh
14
15 A hanging face is a face of a fine cell which sits on the face of a
16 coarser, unrefined cell. Peano does not store hanging faces. It creates
17 them whenever a mesh sweep enters an adjacent fine cell and destroys them
18 once the sweep leaves this cell again. The action set plugs into
19 createHangingFace(): It takes the overlap data of the coarse face which
20 the hanging face is part of and interpolates them onto the hanging face
21 (::toolbox::blockstructured::interpolateHaloLayer_AoS_...). Afterwards,
22 the half of the hanging face which belongs to the coarse cell holds
23 interpolated coarse data, so the fine cell can reconstruct its halo as
24 if its neighbour were a fine cell, too.
25
26 The face overlap has to be a 2MxNxN patch: M is the overlap, N the
27 number of volumes per patch axis.
28
29 """
30
31 class Scheme(enum.Enum):
32 """!
33
34 Interpolation schemes
35
36 The value of each entry is the suffix of the C++ routine
37 ::toolbox::blockstructured::interpolateHaloLayer_AoS_<suffix>().
38
39 - PiecewiseConstant copies the coarse value into all fine volumes
40 which it covers.
41 - Linear interpolates linearly along the face. As the coarse face
42 does not hold the coarse volumes beyond its two ends, the scheme
43 extrapolates constantly there. Linear extrapolation would be more
44 accurate, but it can produce unphysical values such as negative
45 densities next to steep gradients
46 (@ref toolbox::blockstructured::internal::createLinearInterpolationMatrix()).
47
48 """
49
50 PiecewiseConstant = "piecewise_constant"
51 Linear = "linear_with_constant_extrapolation"
52
53 TemplateCreateHangingFace = jinja2.Template(
54 """
55 logTraceInWith1Argument( "createHangingFace(...)---InterpolateHangingFaces", marker.toString() );
56 ::toolbox::blockstructured::interpolateHaloLayer_AoS_{{SCHEME}}(
57 marker,
58 {{DOFS_PER_AXIS}},
59 {{OVERLAP}},
60 {{UNKNOWNS}},
61 coarseGridFaces{{FACE_NAME}}(marker.getSelectedFaceNumber()).value,
62 fineGridFace{{FACE_NAME}}.value
63 );
64 logTraceOut( "createHangingFace(...)---InterpolateHangingFaces" );
65"""
66 )
67
69 self,
70 patch_overlap,
71 scheme: "InterpolateHangingFaces.Scheme" = None,
72 guard: str = "true",
73 additional_includes: str = "",
74 ):
75 """!
76
77 @param patch_overlap: peano4.api.datamodel.Patch
78 The face data which the action set interpolates. The data of the
79 coarse face are read, the data of the hanging face are written.
80
81 @param scheme: InterpolateHangingFaces.Scheme
82 Interpolation scheme. Defaults to Scheme.Linear.
83
84 @param guard: str
85 C++ boolean expression over the hanging face's
86 peano4::datamanagement::FaceMarker marker.
87
88 @param additional_includes: str
89 Further include statements, e.g. required by the guard.
90
91 """
92 super().__init__(descend_invocation_order=1, parallel=False)
93 assert patch_overlap.dim[0] % 2 == 0, (
94 "Patch associated to face has to have even number of volumes along "
95 "the normal. Otherwise, it is not a symmetric overlap."
96 )
97 self.scheme = (
98 InterpolateHangingFaces.Scheme.Linear if scheme is None else scheme
99 )
100 assert isinstance(self.scheme, InterpolateHangingFaces.Scheme), self.scheme
101 self.d = {
102 "UNKNOWNS": patch_overlap.no_of_unknowns,
103 "DOFS_PER_AXIS": patch_overlap.dim[1],
104 "OVERLAP": patch_overlap.dim[0] // 2,
105 "FACE_NAME": patch_overlap.name,
106 "SCHEME": self.scheme.value,
107 }
108 self.guard = guard
109 self.additional_includes = additional_includes
110
112 return ""
113
115 return ""
116
118 return " return std::vector< peano4::grid::GridControlEvent >();\n"
119
121 return "\n"
122
124 return "\n"
125
126 def get_body_of_operation(self, operation_name):
127 if operation_name == ActionSet.OPERATION_CREATE_HANGING_FACE:
128 return self.TemplateCreateHangingFace.render(**self.d)
129 return ""
130
131 def get_guard_of_operation(self, operation_name):
132 if operation_name == ActionSet.OPERATION_CREATE_HANGING_FACE:
133 return self.guard
134 return "true"
135
137 return __name__.replace(".py", "").replace(".", "_")
138
140 return False
141
142 def get_attributes(self):
143 return ""
144
145 def get_includes(self):
146 return (
147 """
148#include "toolbox/blockstructured/Interpolation.h"
149"""
151 )
Initialise the overlap data on hanging faces from the coarser mesh.
get_includes(self)
Return include statements that you need.
__init__(self, patch_overlap, "InterpolateHangingFaces.Scheme" scheme=None, str guard="true", str additional_includes="")
user_should_modify_template(self)
Is the user allowed to modify the output.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_attributes(self)
Return attributes as copied and pasted into the generated class.
get_constructor_body(self)
Define a tailored constructor body.
get_guard_of_operation(self, operation_name)
Return the guard of an operation.
get_body_of_createGridControlEventsForNextTraversal(self)
Return the grid control events that this action set wants to trigger.
Action set (reactions to events)
Definition ActionSet.py:6