1""" This file is part of the ExaGRyPE project. For conditions of distribution and
2 use, please see the copyright notice at www.peano-framework.org
11 Copy the data of one patch into another patch, with a different number of volumes per axis
13 The two patches hold the same entries per volume, but they may resolve the
14 mesh cell with a different number of volumes per axis, e.g. 8 Finite
15 Difference points and 17 Finite Volumes. The action set hooks into
16 touchCellFirstTime() and fills each volume of the target with the
17 piecewise (tri)linear interpolant of the source, which is evaluated at the
18 centre of the target volume. Both patches discretise the same mesh cell,
19 and the values sit in the centres of their volumes.
21 The interpolation uses the source patch only, i.e. it does not look into
22 neighbouring cells. Targets in the outermost half source volume are
23 extrapolated linearly from the two outermost source volumes. The result is
24 second-order accurate for smooth data, but it is not conservative, and it
25 is not continuous across cell boundaries. If both patches have the same
26 size, the action set copies the data (the weights are 0 and 1).
35 additional_includes: str =
"",
39 @param source_patch: peano4.api.datamodel.Patch
40 The cell-associated patch the action set reads. Has to be
41 cubic, without halo, with at least two volumes per axis.
43 @param target_patch: peano4.api.datamodel.Patch
44 The cell-associated patch the action set writes. Has to be cubic,
45 without halo, and has to hold as many entries per volume as the source.
48 C++ boolean expression, evaluated per cell in touchCellFirstTime.
50 @param additional_includes: str
51 Includes that the generated code needs.
54 super().
__init__(descend_invocation_order=1, parallel=
False)
55 if source_patch.no_of_unknowns != target_patch.no_of_unknowns:
57 f
"Source patch {source_patch.name} holds {source_patch.no_of_unknowns} entries per volume, "
58 f
"but target patch {target_patch.name} holds {target_patch.no_of_unknowns}"
60 if source_patch.dim[0] < 2:
61 raise ValueError(
"The source patch needs at least two volumes per axis")
74 return " return std::vector< peano4::grid::GridControlEvent >();\n"
77 return __name__.replace(
".py",
"").replace(
".",
"_")
83 if operation_name != ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
85 source_size = self.
_source.dim[0]
86 target_size = self.
_target.dim[0]
87 entries = self.
_source.no_of_unknowns
89 constexpr int SourceSize = {source_size};
90 constexpr int TargetSize = {target_size};
91 constexpr int Entries = {entries};
92 const ::exahype2::enumerator::AoSLexicographicEnumerator sourceEnumerator(1,SourceSize,0,Entries,0);
93 const ::exahype2::enumerator::AoSLexicographicEnumerator targetEnumerator(1,TargetSize,0,Entries,0);
94 const double* __restrict__ source = fineGridCell{self._source.name}.value;
95 double* __restrict__ target = fineGridCell{self._target.name}.value;
97 // Index of the lower source volume and the weight of the upper one. The weight
98 // is outside [0,1] for the outermost target volumes (linear extrapolation).
99 auto locate = [](int targetIndex, int& lower, double& upperWeight) -> void {{
100 const double position = (targetIndex + 0.5) * SourceSize / TargetSize - 0.5;
101 lower = std::min( std::max( static_cast<int>( std::floor(position) ), 0 ), SourceSize - 2 );
102 upperWeight = position - lower;
105 for (int z=0; z<TargetSize; z++) {{
109 for (int y=0; y<TargetSize; y++) {{
113 for (int x=0; x<TargetSize; x++) {{
117 tarch::la::Vector<Dimensions,int> targetVolume = {{x, y, z}};
118 for (int entry=0; entry<Entries; entry++) {{
120 for (int dz=0; dz<2; dz++)
121 for (int dy=0; dy<2; dy++)
122 for (int dx=0; dx<2; dx++) {{
123 tarch::la::Vector<Dimensions,int> sourceVolume = {{x0+dx, y0+dy, z0+dz}};
124 const double weight = (dx==0 ? 1.0-wx : wx) * (dy==0 ? 1.0-wy : wy) * (dz==0 ? 1.0-wz : wz);
125 value += weight * source[ sourceEnumerator(0, sourceVolume, entry) ];
127 target[ targetEnumerator(0, targetVolume, entry) ] = value;
135 if operation_name == ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
148#include "exahype2/enumerator/AoSLexicographicEnumerator.h"
Copy the data of one patch into another patch, with a different number of volumes per axis.
get_body_of_createGridControlEventsForNextTraversal(self)
Return the grid control events that this action set wants to trigger.
get_attributes(self)
Return attributes as copied and pasted into the generated class.
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.
__init__(self, source_patch, target_patch, str guard="true", str additional_includes="")
get_destructor_body(self)
get_includes(self)
Return include statements that you need.
get_action_set_name(self)
Return unique action set name.
get_constructor_body(self)
Define a tailored constructor body.
get_guard_of_operation(self, operation_name)
Return the guard of an operation.
Action set (reactions to events).