Peano 4
Loading...
Searching...
No Matches
PeanoCurve.cpp
Go to the documentation of this file.
1#include "PeanoCurve.h"
2#include "AutomatonState.h"
3
4
7
8
10 const AutomatonState& state,
11 int axis
12) {
13 assertion( axis >= 0 );
14 assertion( axis < Dimensions );
15
16 std::bitset<Dimensions> influencingEvenFlags = state.getEvenFlags();
17 influencingEvenFlags.set(axis,false);
18
19 bool result = ( influencingEvenFlags.count() % 2) == 0;
20 return result ^ state.getInverted();
21}
22
23
26) {
28 for (int i=0; i<Dimensions; i++) {
29 result[i] = isTraversePositiveAlongAxis(state,i);
30 }
31 return result;
32}
33
34
36 if ( isTraversePositiveAlongAxis(cell, axis) ) {
37 removeFaceAccessNumber( cell, axis+Dimensions );
38 setFaceAccessNumber( cell, axis+Dimensions, 1 );
39 }
40 else {
41 removeFaceAccessNumber( cell, axis );
42 setFaceAccessNumber( cell, axis, 1 );
43 }
44}
45
46
48 if ( isTraversePositiveAlongAxis(cell, axis) ) {
49 removeFaceAccessNumber( cell, axis );
50 setFaceAccessNumber( cell, axis, -1 );
51 }
52 else {
53 removeFaceAccessNumber( cell, axis+Dimensions );
54 setFaceAccessNumber( cell, axis+Dimensions, -1 );
55 }
56}
57
58
60 assertion( axis >= 0 );
61 assertion( axis < Dimensions );
62 cell.flipEvenFlags( axis );
63}
64
65
67 assertion( face >= 0 );
68 assertion( face < 2*Dimensions );
69
70 // use auto here as I tend to change the type of the access flags
71 auto accessNumber = cell.getAccessNumber();
72 int oldFaceNumber = accessNumber(face);
73
74 if (accessNumber(face)>0) {
75 for (int i=0; i<2*Dimensions; i++)
76 if ( accessNumber(i) >= oldFaceNumber ) accessNumber(i)--;
77 }
78 if (accessNumber(face)<0) {
79 for (int i=0; i<2*Dimensions; i++)
80 if ( accessNumber(i) <= oldFaceNumber ) accessNumber(i)++;
81 }
82
83 accessNumber(face) = 0;
84 cell.setAccessNumber(accessNumber);
85}
86
87
89 std::bitset<Dimensions> result;
90 std::bitset<Dimensions> currentMask;
91
92 for (int i=0; i<Dimensions; i++) {
93 if ( cell.getEvenFlags(i) ) {
94 currentMask[i] = true;
95 currentMask.flip();
96
97 result ^= currentMask;
98
99 currentMask.flip();
100 currentMask[i] = false;
101 }
102 }
103
104 if (cell.getInverted()) {
105 result.flip();
106 }
107
108 return result;
109}
110
111
113 assertion( face >= 0 );
114 assertion( face < 2*Dimensions );
115 assertion( value != 0 );
116 assertion( cell.getAccessNumber()(face) == 0 );
117
118 // use auto here as I tend to change the type of the access flags
119 auto accessNumber = cell.getAccessNumber();
120
121 if (value > 0 ) {
122 for (int i=0; i<2*Dimensions; i++)
123 if ( accessNumber(i) >= value ) accessNumber(i)++;
124 }
125 else {
126 for (int i=0; i<2*Dimensions; i++)
127 if ( accessNumber(i) <= value ) accessNumber(i)--;
128 }
129
130 accessNumber(face) = static_cast<short int>(value);
131 cell.setAccessNumber(accessNumber);
132}
133
134
136 return NumberOfBaseStacks + (state.getInverted() ? -1 : -2);
137}
138
139
141 return NumberOfBaseStacks + (state.getInverted() ? -2 : -1);
142}
143
144
145int peano4::grid::PeanoCurve::getVertexReadStackNumber(const AutomatonState& state, const std::bitset<Dimensions>& vertex ) {
146 int smallestValue = -2*Dimensions-1;
147 int result = getInputStackNumber(state);
148 int direction = -1;
149
150 for (int d=0; d<Dimensions; d++) {
151 const int face = vertex[d]==0 ? d : d+Dimensions;
152 const int faceAccessNumber = state.getAccessNumber(face);
153 if (faceAccessNumber<0 && faceAccessNumber>smallestValue) {
154 result = face + NumberOfBaseStacks;
155 smallestValue = faceAccessNumber;
156 direction = d;
157 }
158 }
159
160 if ( direction>=0 and state.getEvenFlags(direction) ) {
161 result = (result-NumberOfBaseStacks)<Dimensions ? result+Dimensions : result-Dimensions;
162 }
163
164 assertion1( result>CallStack, result);
165 return result;
166}
167
168
170 return number>CallStack and number < NumberOfBaseStacks;
171}
172
173
175 return number >= NumberOfBaseStacks;
176}
177
178
179int peano4::grid::PeanoCurve::getVertexWriteStackNumber(const AutomatonState& cell, const std::bitset<Dimensions>& vertex ) {
180 int biggestValue = 2*Dimensions+1;
181 int result = getOutputStackNumber(cell);
182 int direction = -1;
183
184 for (int d=0; d<Dimensions; d++) {
185 const int face = vertex[d]==0 ? d : d+Dimensions;
186 const int faceAccessNumber = cell.getAccessNumber(face);
187 if (faceAccessNumber>0 && faceAccessNumber<biggestValue) {
188 result = face + NumberOfBaseStacks;
189 biggestValue = faceAccessNumber;
190 direction = d;
191 }
192 }
193
194 if ( direction>=0 and cell.getEvenFlags(direction) ) {
195 result = (result-NumberOfBaseStacks)<Dimensions ? result+Dimensions : result-Dimensions;
196 }
197
198 assertion1( result>CallStack, result);
199 return result;
200}
201
202
204 if (cell.getInverted()) {
205 face = 2*Dimensions - 1 - face;
206 }
207 int normal = face % Dimensions;
208 int result = face;
209 for (int d=0; d<Dimensions; d++) {
210 if (d!=normal) {
211 if (cell.getEvenFlags(d) and not cell.getInverted()) {
212 result += Dimensions;
213 }
214 else if (cell.getEvenFlags(d) and cell.getInverted()) {
215 result += Dimensions;
216 }
217 }
218 }
219
220 result = result % (2*Dimensions);
221 return result;
222}
223
224
226 int result = getInputStackNumber(state);
227 int direction = face % Dimensions;
228
229 if (state.getAccessNumber(face)<0) {
230 int newResult = face;
231 if (state.getInverted()) newResult += Dimensions;
232 if (state.getEvenFlags(direction)) newResult += Dimensions;
233 newResult = newResult % (2*Dimensions);
234 result = newResult + NumberOfBaseStacks;
235 }
236
237 assertion1( result>CallStack, result);
238 return result;
239}
240
241
243 int result = getOutputStackNumber(cell);
244 int direction = face % Dimensions;
245
246 if (cell.getAccessNumber(face)>0) {
247 int newResult = face;
248 if (cell.getInverted()) newResult += Dimensions;
249 if (cell.getEvenFlags(direction)) newResult += Dimensions;
250 newResult = newResult % (2*Dimensions);
251 result = newResult + NumberOfBaseStacks;
252 }
253
254 assertion1( result>CallStack, result);
255 return result;
256}
257
258
260 return getInputStackNumber(state);
261}
262
263
265 return getOutputStackNumber(state);
266}
#define assertion1(expr, param)
#define assertion(expr)
<!-- WE COMMENT THIS OUT. I DON 'T THINK IT 'S READY YET Now we are working on a cell-by-cell basis, let us examine the @f$ 1^{st} @f$ cell. We note that only @f$ \phi_0 @f$ and @f$ \phi_1 @f$ are non-zero here, so our original equation reduces to:\f{eqnarray *}{ u_1 \ \sum_{k=1, 2} \int_{c_k}(\nabla \phi_0, \ \phi_0) \+dx \=\ \int_{c_0}(f, \ \phi_0) dx \f} and we drop the @f$ \forall \phi @f$ requirement since only @f$ \phi_0 @f$ is non-zero here. In effect, this @f$ \int_{c_0}(\nabla \phi_0, \ \phi_0) dx \=\ \int_{c_0}(f, \ \phi_0) dx @f$ will become our matrix element, as we shall see shortly. --> The basis of functions that we use in this example are piecewise linear defined in each cell(which is an interval of width @f$ h @f$)
AutomatonState state
static int getVertexWriteStackNumber(const AutomatonState &state, const std::bitset< Dimensions > &vertex)
static constexpr int CallStack
Definition PeanoCurve.h:27
static int getInputStackNumber(const AutomatonState &state)
static int getCellReadStackNumber(const AutomatonState &state)
static int getFaceWriteStackNumber(const AutomatonState &state, int face)
static int getFaceNumberAlongCurve(const AutomatonState &state, int logicalFaceNumber)
Faces are enumerated following the same paradigm as the vertices.
static void invertEvenFlag(AutomatonState &cell, int axis)
static void removeFaceAccessNumber(AutomatonState &cell, int face)
static bool isInOutStack(int number)
static int getVertexReadStackNumber(const AutomatonState &state, const std::bitset< Dimensions > &vertex)
static int getOutputStackNumber(const AutomatonState &state)
static peano4::utils::LoopDirection getLoopDirection(const AutomatonState &state)
Holds a set bit for each dimension along which the traversal is positive.
static void setFaceAccessNumber(AutomatonState &cell, int face, int value)
static void setEntryFace(AutomatonState &cell, int axis)
static int getCellWriteStackNumber(const AutomatonState &state)
static bool isTraversePositiveAlongAxis(const AutomatonState &state, int axis)
Definition PeanoCurve.cpp:9
static bool isTemporaryStack(int number)
static constexpr int NumberOfBaseStacks
By setting the value to something bigger than 2, we effectively reserve NumberOfBaseStacks - 2 as cal...
Definition PeanoCurve.h:33
static int getFaceReadStackNumber(const AutomatonState &state, int face)
It is important to get the input/output stack ordering per stack type consistent among all grid entit...
static std::bitset< Dimensions > getFirstVertexIndex(const AutomatonState &cell)
Looks into a cell of the spacetree and gives the index of the first local vertex.
static void setExitFace(AutomatonState &cell, int axis)
std::bitset< Dimensions > LoopDirection
Is used by the z-loop.
Definition Loop.h:65
std::bitset< Dimensions > getEvenFlags() const
tarch::la::Vector< DimensionsTimesTwo, int > getAccessNumber() const