Peano
Loading...
Searching...
No Matches
RollOverUpdatedFace.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 This action set takes the updated data per face and writes it into
13 new. So it takes the outcome from ProjectPatchOntoFaces and writes
14 it onto the (persistent) face data. Before it does so, the action
15 set also rolls over the new data to the old one.
16
17 We may not roll over data if no data has been written onto the
18 face. So we check the updated flag. It is reset by the UpdateFaceLabel
19 action set in the grid subpackage and set again by either the face
20 projection or the dynamic amr handling.
21
22 """
23 TemplateHandleFace = jinja2.Template( """
24 if ( {{GUARD}} ) {
25 const int normal = marker.getSelectedFaceNumber() % Dimensions;
26
27 logTraceInWith3Arguments( "touchFaceLastTime(...)", fineGridFace{{SOLVER_NAME}}FaceLabel.toString(), marker.toString(), normal );
28
29 // Left half
30 if ({{FACE_METADATA_ACCESSOR}}.getUpdated(0)) {
31 logTraceInWith1Argument( "touchFaceLastTime(...)", "left half of face" );
32
33 ::exahype2::fv::copyHalfOfHalo(
34 {{UNKNOWNS}},
35 {{DOFS_PER_AXIS}},
36 {{OVERLAP}},
37 normal,
38 false, // it is the left layer, i.e. not right
39 {{NEW_ACCESSOR}}.value,
40 {{OLD_ACCESSOR}}.value
41 );
42 ::exahype2::fv::copyHalfOfHalo(
43 {{UNKNOWNS}},
44 {{DOFS_PER_AXIS}},
45 {{OVERLAP}},
46 normal,
47 false, // it is the left layer, i.e. not right
48 {{UPDATE_ACCESSOR}}.value,
49 {{NEW_ACCESSOR}}.value
50 );
51
52 /*
53
54 Is now done via a function
55
56 dfore(k,{{DOFS_PER_AXIS}},normal,0) {
57 for (int i=0; i<{{OVERLAP}}; i++) {
58 tarch::la::Vector<Dimensions,int> overlapCell = k;
59 overlapCell(normal) = i;
60 const int index = toolbox::blockstructured::serialiseVoxelIndexInOverlap(overlapCell,{{DOFS_PER_AXIS}},{{OVERLAP}},normal);
61 logDebug( "touchFaceLastTime(...)", "normal=" << normal << ",{{NEW_ACCESSOR}}[" << index << "]->{{OLD_ACCESSOR}}[" << index << "]" );
62 logDebug( "touchFaceLastTime(...)", "normal=" << normal << ",{{UPDATE_ACCESSOR}}[" << index << "]->{{NEW_ACCESSOR}}[" << index << "]" );
63 for (int j=0; j<{{UNKNOWNS}}; j++) {
64 // The initialisation mapping has an epilogue which then copies this
65 // updated new solution over into the old one
66 {{OLD_ACCESSOR}}.value[index*{{UNKNOWNS}}+j] = {{NEW_ACCESSOR}}.value[index*{{UNKNOWNS}}+j];
67 {{NEW_ACCESSOR}}.value[index*{{UNKNOWNS}}+j] = {{UPDATE_ACCESSOR}}.value[index*{{UNKNOWNS}}+j];
68 }
69 }
70 }
71 */
72
73 {{FACE_METADATA_ACCESSOR}}.setOldTimeStamp(0, {{FACE_METADATA_ACCESSOR}}.getNewTimeStamp(0) );
74 {{FACE_METADATA_ACCESSOR}}.setNewTimeStamp(0, {{FACE_METADATA_ACCESSOR}}.getUpdatedTimeStamp(0) );
75
76 logTraceOut( "touchFaceLastTime(...)" );
77 }
78 else {
79 logTraceIn( "touchFaceLastTime(...) (skip left part of face)" );
80 logTraceOut( "touchFaceLastTime(...) (skip left part of face)" );
81 }
82
83 // Right half
84 if ({{FACE_METADATA_ACCESSOR}}.getUpdated(1)) {
85 logTraceInWith1Argument( "touchFaceLastTime(...)", "right half of face" );
86
87 ::exahype2::fv::copyHalfOfHalo(
88 {{UNKNOWNS}},
89 {{DOFS_PER_AXIS}},
90 {{OVERLAP}},
91 normal,
92 true, // it is the left layer, i.e. not right
93 {{NEW_ACCESSOR}}.value,
94 {{OLD_ACCESSOR}}.value
95 );
96 ::exahype2::fv::copyHalfOfHalo(
97 {{UNKNOWNS}},
98 {{DOFS_PER_AXIS}},
99 {{OVERLAP}},
100 normal,
101 true, // it is the left layer, i.e. not right
102 {{UPDATE_ACCESSOR}}.value,
103 {{NEW_ACCESSOR}}.value
104 );
105
106 /*
107 See above: Now done via function
108 dfore(k,{{DOFS_PER_AXIS}},normal,0) {
109 for (int i={{OVERLAP}}; i<2*{{OVERLAP}}; i++) {
110 tarch::la::Vector<Dimensions,int> overlapCell = k;
111 overlapCell(normal) = i;
112 const int index = toolbox::blockstructured::serialiseVoxelIndexInOverlap(overlapCell,{{DOFS_PER_AXIS}},{{OVERLAP}},normal);
113 logDebug( "touchFaceLastTime(...)", "normal=" << normal << ",{{NEW_ACCESSOR}}[" << index << "]->{{OLD_ACCESSOR}}[" << index << "]" );
114 logDebug( "touchFaceLastTime(...)", "normal=" << normal << ",{{UPDATE_ACCESSOR}}[" << index << "]->{{NEW_ACCESSOR}}[" << index << "]" );
115 for (int j=0; j<{{UNKNOWNS}}; j++) {
116 // The initialisation mapping has an epilogue which then copies this
117 // updated new solution over into the old one
118 {{OLD_ACCESSOR}}.value[index*{{UNKNOWNS}}+j] = {{NEW_ACCESSOR}}.value[index*{{UNKNOWNS}}+j];
119 {{NEW_ACCESSOR}}.value[index*{{UNKNOWNS}}+j] = {{UPDATE_ACCESSOR}}.value[index*{{UNKNOWNS}}+j];
120 }
121 }
122 }
123 */
124
125 {{FACE_METADATA_ACCESSOR}}.setOldTimeStamp(1, {{FACE_METADATA_ACCESSOR}}.getNewTimeStamp(1) );
126 {{FACE_METADATA_ACCESSOR}}.setNewTimeStamp(1, {{FACE_METADATA_ACCESSOR}}.getUpdatedTimeStamp(1) );
127
128 logTraceOut( "touchFaceLastTime(...)" );
129 }
130 else {
131 logTraceIn( "touchFaceLastTime(...) (skip right part of face)" );
132 logTraceOut( "touchFaceLastTime(...) (skip right part of face)" );
133 }
134
135 int index = 0;
136 logTraceOut( "touchFaceLastTime(...)" );
137 }
138""" )
139
140
141 def __init__(self,solver,guard):
142 """
143
144 ## Attributes
145
146 overwrite_old_and_new_solution_with_update: Boolean
147 This flag should be set if you use the action set throughout the
148 initialisation, where you determine an update on the face and
149 this update should then be used for old and new face data (as
150 they are the same). If it is set to false, then the new solution
151 is backuped in old, and the update overwrites the new data field.
152
153 """
154 AbstractFVActionSet.__init__(self,solver)
155 self.d = {}
156 self.d[ "GUARD" ] = guard
157 self.d[ "UNKNOWNS" ] = str(solver._patch_overlap_update.no_of_unknowns)
158 self.d[ "DOFS_PER_AXIS" ] = str(solver._patch.dim[0])
159 self.d[ "OVERLAP" ] = str(int(solver._patch_overlap_update.dim[0]/2))
160 self.d[ "UPDATE_ACCESSOR" ] = "fineGridFace" + solver._patch_overlap_update.name
161 self.d[ "OLD_ACCESSOR" ] = "fineGridFace" + solver._patch_overlap_old.name
162 self.d[ "NEW_ACCESSOR" ] = "fineGridFace" + solver._patch_overlap_new.name
163 self.d[ "FACE_METADATA_ACCESSOR" ] = "fineGridFace" + solver._face_label.name
164
165
166 def get_body_of_operation(self,operation_name):
167 result = ""
168 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_FACE_LAST_TIME:
169 self._solver._init_dictionary_with_default_parameters(self.d)
170 self._solver.add_entries_to_text_replacement_dictionary(self.d)
171 result = self.TemplateHandleFace.render(**self.d)
172 pass
173 return result
174
175
176 def get_includes(self):
177 return """
178#include "peano4/utils/Loop.h"
179#include "toolbox/blockstructured/Enumeration.h"
180""" + AbstractFVActionSet.get_includes(self)
181
182
184 return __name__.replace(".py", "").replace(".", "_")
This action set takes the updated data per face and writes it into new.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_action_set_name(self)
You should replicate this function in each subclass, so you get meaningful action set names (otherwis...