Peano 4
Loading...
Searching...
No Matches
GridTraversalEventGeneratorTest.cpp
Go to the documentation of this file.
3
5#include "peano4/utils/Loop.h"
6
7#include "tarch/la/Vector.h"
8
9
10tarch::logging::Log peano4::grid::tests::GridTraversalEventGeneratorTest::_log("peano4::grid::tests::GridTraversalEventGeneratorTest");
11
12
13#ifdef UseTestSpecificCompilerSettings
14#pragma optimize("",off)
15#endif
16
17
19 TestCase( "peano4::grid::tests::GridTraversalEventGeneratorTest" ) {
20}
21
22
23
25 #if Dimensions==2
26 GridTraversalEventGenerator generator0(0);
27 GridTraversalEventGenerator generator1(1);
28
29 GridVertex vertices[TwoPowerD];
30
32 vertices[0].setAdjacentRanks( { 0, 1, 0, 1 } );
33 vertices[0].setBackupOfAdjacentRanks( { 0, 1, 0, 1 } );
34
36 vertices[1].setAdjacentRanks( { 1, 1, 1, 1 } );
37 vertices[1].setBackupOfAdjacentRanks( { 1, 1, 1, 1 } );
38
40 vertices[2].setAdjacentRanks( { 0, 1, 0, 1 } );
41 vertices[2].setBackupOfAdjacentRanks( { 0, 1, 0, 1 } );
42
44 vertices[3].setAdjacentRanks( { 1, 1, 1, 1 } );
45 vertices[3].setBackupOfAdjacentRanks( { 1, 1, 1, 1 } );
46
47 std::bitset<TwoTimesD> result0 = generator0.areFacesLocal(
48 vertices,
50 std::set<int>(),
51 std::set<int>(),
52 std::set<int>()
53 );
54
55 validateWithParams1( not result0[0], result0 );
56 validateWithParams1( not result0[1], result0 );
57 validateWithParams1( not result0[2], result0 );
58 validateWithParams1( not result0[3], result0 );
59
60 std::bitset<TwoTimesD> result1 = generator1.areFacesLocal(
61 vertices,
63 std::set<int>(),
64 std::set<int>(),
65 std::set<int>()
66 );
67
68 validateWithParams1( result1[0], result1 );
69 validateWithParams1( result1[1], result1 );
70 validateWithParams1( result1[2], result1 );
71 validateWithParams1( result1[3], result1 );
72 #endif
73}
74
75
77 #if Dimensions==2
78 GridTraversalEventGenerator generator(1);
79
81 GridVertex vertices[TwoPowerD];
82
84 vertices[0].setAdjacentRanks( { 0, 0, 1, 1 } );
85 vertices[0].setBackupOfAdjacentRanks( { 0, 0, 1, 1 } );
87 vertices[1].setAdjacentRanks( { 0, InvalidRank, 1, InvalidRank } );
88 vertices[1].setBackupOfAdjacentRanks( { 0, InvalidRank, 1, InvalidRank } );
90 vertices[2].setAdjacentRanks( { 1, 1, InvalidRank, InvalidRank } );
91 vertices[2].setBackupOfAdjacentRanks( { 1, 1, InvalidRank, InvalidRank } );
95
96 std::bitset<TwoTimesD> result = generator.areFacesLocal( vertices, SplitSpecification(), std::set<int>(), std::set<int>(), std::set<int>() );
97
98 validateWithParams1( result[0], result );
99 validateWithParams1( result[1], result );
100 validateWithParams1( result[2], result );
101 validateWithParams1( result[3], result );
102 #endif
103}
104
105
107 #if Dimensions==2
108 GridTraversalEventGenerator generator( 2 );
109
110 GridVertex coarseGridVertices[TwoPowerD];
111
112 coarseGridVertices[0].setState( GridVertex::State::Refining );
113 coarseGridVertices[1].setState( GridVertex::State::Refining );
114 coarseGridVertices[2].setState( GridVertex::State::Refining );
115 coarseGridVertices[3].setState( GridVertex::State::Refining );
116
117 auto result = generator.getFaceType( coarseGridVertices, {2,2}, 0 );
118 validateWithParams1( result==FaceType::New, toString(result) );
119
120 result = generator.getFaceType( coarseGridVertices, {2,2}, 1 );
121 validateWithParams1( result==FaceType::New, toString(result) );
122
123 result = generator.getFaceType( coarseGridVertices, {2,2}, 2 );
124 validateWithParams1( result==FaceType::New, toString(result) );
125
126 result = generator.getFaceType( coarseGridVertices, {2,2}, 3 );
127 validateWithParams1( result==FaceType::New, toString(result) );
128 #endif
129}
130
131
133 GridVertex vertices[TwoPowerD];
134 dfor2(k)
135 vertices[kScalar].setState( GridVertex::State::Refined );
139 #if PeanoDebug>0
140 vertices[kScalar].setX(tarch::la::convertScalar<double>(k));
141 #endif
142 vertices[kScalar].setLevel(0);
143 }
144
145 // AutomatonState(const int& level, const tarch::la::Vector<Dimensions,double>& x, const tarch::la::Vector<Dimensions,double>& h, const bool& inverted, const std::bitset<Dimensions>& evenFlags, const tarch::la::Vector<DimensionsTimesTwo,short int>& accessNumber);
146 AutomatonState state;
147 state.setLevel( 0 );
148 state.setX( 0.0 );
149 state.setH( 1.0 );
150 state.setInverted( false );
151 state.setEvenFlags( 0 );
152
153/*
154 observer.enterCell(createLeaveCellTraversalEvent(
155 vertices, fineGridVertices, fineGridStates[peano4::utils::dLinearised(k,3)], k
156 ));
157*/
158}
159
160
161/*
162void peano4::grid::tests::GridTraversalEventGeneratorTest::testCreateNeighbourExchangeLists() {
163 #if Dimensions==2
164 GridTraversalEventGenerator generator(1);
165
166 GridTraversalEvent event;
167 GridVertex vertices[TwoPowerD];
168
169 vertices[0].setState( GridVertex::State::Unrefined );
170 vertices[0].setAdjacentRanks( { InvalidRank, 1, InvalidRank, 0 } );
171 vertices[0].setBackupOfAdjacentRanks( { InvalidRank, 1, InvalidRank, 0 } );
172 vertices[1].setState( GridVertex::State::Unrefined );
173 vertices[1].setAdjacentRanks( { 1, 1, 0, 1 } );
174 vertices[1].setBackupOfAdjacentRanks( { 1, 1, 0, 1 } );
175 vertices[2].setState( GridVertex::State::Unrefined );
176 vertices[2].setAdjacentRanks( { InvalidRank, 0, InvalidRank, 0 } );
177 vertices[2].setBackupOfAdjacentRanks( { InvalidRank, 0, InvalidRank, 0 } );
178 vertices[3].setState( GridVertex::State::Unrefined );
179 vertices[3].setAdjacentRanks( { 0, 1, 0, 0 } );
180 vertices[3].setBackupOfAdjacentRanks( { 0, 1, 0, 0 } );
181
182 event.setIsVertexLocal( 0, true );
183 event.setIsVertexLocal( 1, true );
184 event.setIsVertexLocal( 2, true );
185 event.setIsVertexLocal( 3, true );
186 event.setIsFaceLocal( 0, true );
187 event.setIsFaceLocal( 1, true );
188 event.setIsFaceLocal( 2, true );
189 event.setIsFaceLocal( 3, true );
190
191 // enter cell; no load balancing going on
192 generator.createNeighbourExchangeLists( vertices, event, true );
193
194 validateEqualsWithParams1( event.getExchangeFaceData(0), TraversalObserver::NoData, event.toString() );
195 validateEqualsWithParams1( event.getExchangeFaceData(1), 1, event.toString() );
196 validateEqualsWithParams1( event.getExchangeFaceData(2), 1, event.toString() );
197 validateEqualsWithParams1( event.getExchangeFaceData(3), TraversalObserver::NoData, event.toString() );
198
199 vertices[0].setState( GridVertex::State::Unrefined );
200 vertices[0].setAdjacentRanks( { InvalidRank, 0, InvalidRank, 1 } );
201 vertices[0].setBackupOfAdjacentRanks( { InvalidRank, 0, InvalidRank, 1 } );
202 vertices[1].setState( GridVertex::State::Unrefined );
203 vertices[1].setAdjacentRanks( { 0, 0, 1, 0 } );
204 vertices[1].setBackupOfAdjacentRanks( { 0, 0, 1, 0 } );
205 vertices[2].setState( GridVertex::State::Unrefined );
206 vertices[2].setAdjacentRanks( { InvalidRank, 1, InvalidRank, 1 } );
207 vertices[2].setBackupOfAdjacentRanks( { InvalidRank, 1, InvalidRank, 1 } );
208 vertices[3].setState( GridVertex::State::Unrefined );
209 vertices[3].setAdjacentRanks( { 1, 0, 1, 1 } );
210 vertices[3].setBackupOfAdjacentRanks( { 1, 0, 1, 1 } );
211
212 event.setIsVertexLocal( 0, true );
213 event.setIsVertexLocal( 1, true );
214 event.setIsVertexLocal( 2, false );
215 event.setIsVertexLocal( 3, true );
216 event.setIsFaceLocal( 0, false );
217 event.setIsFaceLocal( 1, true );
218 event.setIsFaceLocal( 2, true );
219 event.setIsFaceLocal( 3, false );
220
221 // enter cell; just triggered the split
222 generator._splitTriggered.insert( std::pair<int,int>(1,1) );
223 generator.createNeighbourExchangeLists( vertices, event, true );
224
225 validateEqualsWithParams1( event.getExchangeFaceData(0), TraversalObserver::NoData, event.toString() );
226 validateEqualsWithParams1( event.getExchangeFaceData(1), TraversalObserver::NoData, event.toString() );
227 validateEqualsWithParams1( event.getExchangeFaceData(2), TraversalObserver::NoData, event.toString() );
228 validateEqualsWithParams1( event.getExchangeFaceData(3), TraversalObserver::NoData, event.toString() );
229
230 generator.createNeighbourExchangeLists( vertices, event, false );
231
232 validateEqualsWithParams1( event.getExchangeFaceData(0), TraversalObserver::NoData, event.toString() );
233 validateEqualsWithParams1( event.getExchangeFaceData(1), TraversalObserver::NoData, event.toString() );
234 validateEqualsWithParams1( event.getExchangeFaceData(2), TraversalObserver::NoData, event.toString() );
235 validateEqualsWithParams1( event.getExchangeFaceData(3), TraversalObserver::NoData, event.toString() );
236
237 // enter cell; just triggered the split
238 generator._splitTriggered.clear();
239 generator._splitting.insert( 1 );
240 generator.createNeighbourExchangeLists( vertices, event, true );
241
242 validateEqualsWithParams1( event.getExchangeFaceData(0), TraversalObserver::NoData, event.toString() );
243 validateEqualsWithParams1( event.getExchangeFaceData(1), TraversalObserver::NoData, event.toString() );
244 validateEqualsWithParams1( event.getExchangeFaceData(2), TraversalObserver::NoData, event.toString() );
245 validateEqualsWithParams1( event.getExchangeFaceData(3), TraversalObserver::NoData, event.toString() );
246
247 generator.createNeighbourExchangeLists( vertices, event, false );
248
249 validateEqualsWithParams1( event.getExchangeFaceData(0), TraversalObserver::NoData, event.toString() );
250 validateEqualsWithParams1( event.getExchangeFaceData(1), 1, event.toString() );
251 validateEqualsWithParams1( event.getExchangeFaceData(2), 1, event.toString() );
252 validateEqualsWithParams1( event.getExchangeFaceData(3), TraversalObserver::NoData, event.toString() );
253 #endif
254}
255*/
256
257
259/*
260 #if Dimensions==2
261 Spacetree tree( {0.0,0.0}, {1.0,1.0} );
262 tree._id = 2;
263
264 GridVertex coarseGridVertices[TwoPowerD];
265 GridVertex fineGridVertices[TwoPowerD];
266
267 coarseGridVertices[0].setState( GridVertex::State::Refined );
268 coarseGridVertices[1].setState( GridVertex::State::Refined );
269 coarseGridVertices[2].setState( GridVertex::State::Refined );
270 coarseGridVertices[3].setState( GridVertex::State::Refined );
271
272 fineGridVertices[0].setState( GridVertex::State::Unrefined );
273 fineGridVertices[0].setAdjacentRanks( { 3, 3, 3, 3 } );
274 fineGridVertices[0].setBackupOfAdjacentRanks( { 3, 3, 3, 3 } );
275 fineGridVertices[0].setX( {0.62963,0.407407} );
276
277 fineGridVertices[1].setState( GridVertex::State::Unrefined );
278 fineGridVertices[1].setAdjacentRanks( { 3, 2, 3, 2 } );
279 fineGridVertices[1].setBackupOfAdjacentRanks( { 3, 2, 3, 2 } );
280 fineGridVertices[1].setX( {0.666667,0.407407} );
281
282 fineGridVertices[2].setState( GridVertex::State::New );
283 fineGridVertices[2].setAdjacentRanks( { 3, 3, 3, 3 } );
284 fineGridVertices[2].setBackupOfAdjacentRanks( { 0, 0, 0, 0 } );
285 fineGridVertices[2].setX( {0.62963,0.444444} );
286
287 fineGridVertices[3].setState( GridVertex::State::New );
288 fineGridVertices[3].setAdjacentRanks( { 3, 2, 3, 2 } );
289 fineGridVertices[3].setBackupOfAdjacentRanks( { 0, 0, 0, 0 } );
290 fineGridVertices[3].setX( {0.666667,0.444444} );
291
292 coarseGridVertices[0].setState( GridVertex::State::Refining );
293 coarseGridVertices[0].setAdjacentRanks( { 3, 3, 3, 3 } );
294
295 coarseGridVertices[1].setState( GridVertex::State::Refining );
296 coarseGridVertices[1].setAdjacentRanks( { 3, 2, 3, 2 } );
297
298 coarseGridVertices[2].setState( GridVertex::State::Refining );
299 coarseGridVertices[2].setAdjacentRanks( { 3, 3, 3, 3 } );
300
301 coarseGridVertices[3].setState( GridVertex::State::Refining );
302 coarseGridVertices[3].setAdjacentRanks( { 3, 2, 3, 2 } );
303
304 AutomatonState state(
305 3, // level,
306 {0.62963,0.407407}, // x
307 {0.037037,0.037037}, // h
308 true, // inverted
309 std::bitset<Dimensions>(3), // even flags = 11
310 {-1,-2,2,1}
311 );
312 tarch::la::Vector<Dimensions,int> relativePositionToFather = {2,2};
313
314 GridTraversalEvent event = tree.createEnterCellTraversalEvent(coarseGridVertices,fineGridVertices,state,relativePositionToFather);
315
316 validateEqualsWithParams1( event.getFaceDataFrom(0), 4, event.toString() );
317 validateEqualsWithParams1( event.getFaceDataFrom(1), 3, event.toString() );
318 validateEqualsWithParams1( event.getFaceDataFrom(2), TraversalObserver::CreateOrDestroyPersistentGridEntity, event.toString() );
319 validateEqualsWithParams1( event.getFaceDataFrom(3), TraversalObserver::CreateOrDestroyPersistentGridEntity, event.toString() );
320 #endif
321*/
322}
323
324
326 #if Dimensions==2
327 GridTraversalEventGenerator generator(0);
328
329 GridVertex coarseGridVertices[TwoPowerD];
330 GridVertex fineGridVertices[TwoPowerD];
331
332 fineGridVertices[0].setState( GridVertex::State::HangingVertex );
333 fineGridVertices[0].setAdjacentRanks( { 0,0,0,0 } );
334 fineGridVertices[0].setBackupOfAdjacentRanks( { 0,0,0,0 } );
335
336 fineGridVertices[1].setState( GridVertex::State::Unrefined );
337 fineGridVertices[1].setAdjacentRanks( { 0,0,0,0 } );
338 fineGridVertices[1].setBackupOfAdjacentRanks( { 0,0,0,0 } );
339
340 fineGridVertices[2].setState( GridVertex::State::HangingVertex );
341 fineGridVertices[2].setAdjacentRanks( { 0,0,0,0 } );
342 fineGridVertices[2].setBackupOfAdjacentRanks( { 0,0,0,0 } );
343
344 fineGridVertices[3].setState( GridVertex::State::Unrefined );
345 fineGridVertices[3].setAdjacentRanks( { 0,0,0,0 } );
346 fineGridVertices[3].setBackupOfAdjacentRanks( { 0,0,0,0 } );
347
348 coarseGridVertices[0].setState( GridVertex::State::Unrefined );
349 coarseGridVertices[0].setAdjacentRanks( { 0,0,0,0 } );
350 coarseGridVertices[0].setBackupOfAdjacentRanks( { 0,0,0,0 } );
351
352 coarseGridVertices[1].setState( GridVertex::State::Refined );
353 coarseGridVertices[1].setAdjacentRanks( { 0,0,0,0 } );
354 coarseGridVertices[1].setBackupOfAdjacentRanks( { 0,0,0,0 } );
355
356 coarseGridVertices[2].setState( GridVertex::State::Unrefined );
357 coarseGridVertices[2].setAdjacentRanks( { 0,0,0,0 } );
358 coarseGridVertices[2].setBackupOfAdjacentRanks( { 0,0,0,0 } );
359
360 coarseGridVertices[3].setState( GridVertex::State::Refined );
361 coarseGridVertices[3].setAdjacentRanks( { 0,0,0,0 } );
362 coarseGridVertices[3].setBackupOfAdjacentRanks( { 0,0,0,0 } );
363
365 4, // level,
366 {0.37037,0.358025}, // x
367 {0.0123457,0.0123457}, // h
368 true, // inverted
369 std::bitset<Dimensions>(2), // even flags = 10
370 {-1,2,1,3}
371 );
372 tarch::la::Vector<Dimensions,int> relativePositionToFather = {0,2};
373
374 GridTraversalEvent event = generator.createGenericCellTraversalEvent(
375 coarseGridVertices,
376 fineGridVertices,
377 state,
379 std::set<int>(), std::set<int>(), std::set<int>(),
380 relativePositionToFather, true
381 );
382
383 validateEqualsWithParams1( event.getIsVertexLocal(0), true, event.toString() );
384 validateEqualsWithParams1( event.getIsVertexLocal(1), true, event.toString() );
385 validateEqualsWithParams1( event.getIsVertexLocal(2), true, event.toString() );
386 validateEqualsWithParams1( event.getIsVertexLocal(3), true, event.toString() );
387
388 validateEqualsWithParams1( event.getIsFaceLocal(0), true, event.toString() );
389 validateEqualsWithParams1( event.getIsFaceLocal(1), true, event.toString() );
390 validateEqualsWithParams1( event.getIsFaceLocal(2), true, event.toString() );
391 validateEqualsWithParams1( event.getIsFaceLocal(3), true, event.toString() );
392 #endif
393}
394
395
397 testMethod( testCreateGenericCellTraversalEvent1 );
398 testMethod( testAreFacesLocal1 );
399 testMethod( testAreFacesLocal2 );
400 testMethod( testGetFaceType );
401 testMethod( testCreateEnterCellTraversalEvent1 );
402 testMethod( testCreateLeaveCellTraversalEvent1 );
403}
404
405
406#ifdef UseTestSpecificCompilerSettings
407#pragma optimize("",on)
408#endif
409
we integrate over each cell and then take the sum across each of the cells We also consider the terms that enter the f$ k
#define TwoPowerD
Definition Globals.h:19
AutomatonState state
#define dfor2(counter)
Shortcut For dfor(counter,2)
Definition Loop.h:906
#define validateEqualsWithParams1(actualValue, validValue, param0)
Definition TestMacros.h:318
#define testMethod(name)
Run a test method and check for errors.
Definition TestMacros.h:24
#define validateWithParams1(booleanExpr, param0)
Definition TestMacros.h:59
Translate grid traversal automaton's transitions into user events.
std::bitset< TwoTimesD > areFacesLocal(GridVertex vertices[TwoPowerD], const SplitSpecification &splitTriggered, const std::set< int > &splitting, const std::set< int > &joinTriggered, const std::set< int > &joining) const
Identifies for the faces whether they are local or not.
virtual void run() override
This routine is triggered by the TestCaseCollection.
void testAreFacesLocal2()
A simple setup that I extracted from a bug in the code:
Log Device.
Definition Log.h:516
std::string toString(VertexType type)
Definition grid.cpp:277
constexpr int InvalidRank(-1)
std::map< int, SplitInstruction > SplitSpecification
Definition grid.h:44
void setBackupOfAdjacentRanks(const tarch::la::Vector< TwoPowerD, int > &value)
void setIsAntecessorOfRefinedVertexInCurrentTreeSweep(bool value)
void setLevel(int value)
void setHasBeenAntecessorOfRefinedVertexInPreviousTreeSweep(bool value)
void setState(State value)
void setAdjacentRanks(const tarch::la::Vector< TwoPowerD, int > &value)
Simple vector class.
Definition Vector.h:134