PlasCom2  1.0
XPACC Multi-physics simluation application
TestIntervals.C
Go to the documentation of this file.
1 #include "Testing.H"
2 #include "Simulation.H"
3 
9 void TestIntervalBasic(ix::test::results &serialUnitResults) {
10 
11  size_t Nx = 100;
12  size_t Ny = 100;
13  size_t Nz = 100;
14 
15 
16  std::vector<size_t> NX(3,100);
17  pcpp::IndexIntervalType globalExtent;
18  globalExtent.InitSimple(NX);
19 
20  bool initSimple(globalExtent[0].first == 0 &&
21  globalExtent[1].first == 0 &&
22  globalExtent[2].first == 0 &&
23  globalExtent[0].second == 99 &&
24  globalExtent[1].second == 99 &&
25  globalExtent[2].second == 99 &&
26  globalExtent.NNodes() == 1000000);
27 
28  serialUnitResults.UpdateResult("PCPP:Interval:SimpleInit",initSimple);
29 
30  size_t numX = 10;
31  size_t numLeftOver = 0;
32 
33  size_t firstXIndex = 0;
34  size_t lastXIndex = 9;
35 
36  size_t numNodesLocal = 100000;
37  size_t numNodesGlobal = 1000000;
38 
39  std::vector<size_t> flatExtent;
40  flatExtent.resize(6,0);
41  flatExtent[0] = firstXIndex;
42  flatExtent[1] = lastXIndex;
43  flatExtent[3] = flatExtent[5] = 99;
44 
45  pcpp::IndexIntervalType localExtent(flatExtent);
46 
47  bool flatConstructor = true;
48  if(localExtent.size() != 3)
49  flatConstructor = false;
50  if(!(localExtent[0].first == firstXIndex &&
51  localExtent[0].second == lastXIndex &&
52  localExtent[1].first == 0 &&
53  localExtent[2].first == 0 &&
54  localExtent[1].second == 99 &&
55  localExtent[2].second == 99))
56  flatConstructor = false;
57 
58  bool copyConstructor = true;
59  pcpp::IndexIntervalType copyExtent(localExtent);
60  if(copyExtent != localExtent)
61  copyConstructor = false;
62 
63  bool nodeCount = true;
64  if(copyExtent.NNodes() != numNodesLocal)
65  nodeCount = false;
66 
67 
68  bool overlapWorks = true;
69  pcpp::IndexIntervalType overlapExtent(localExtent.Overlap(copyExtent));
70  if(overlapExtent != copyExtent)
71  overlapWorks = false;
72 
73  std::vector<size_t> disparateStart(3,100);
74  std::vector<size_t> disparateNum(3,100);
75  bool startSizeConstructor = true;
76  pcpp::IndexIntervalType disparateExtent(disparateStart,disparateNum);
77  if(!(disparateExtent[0].first == 100 &&
78  disparateExtent[1].first == 100 &&
79  disparateExtent[2].first == 100 &&
80  disparateExtent[0].second == 199 &&
81  disparateExtent[1].second == 199 &&
82  disparateExtent[2].second == 199))
83  startSizeConstructor = false;
84 
85  bool noOverlapWorks = true;
86  pcpp::IndexIntervalType zeroOverlapExtent(localExtent.Overlap(disparateExtent));
87  if(!zeroOverlapExtent.empty())
88  noOverlapWorks = false;
89 
90  std::vector<size_t> simpleSizes(3,10);
91  simpleSizes[1] = 1000;
92  simpleSizes[2] = 1000;
93  zeroOverlapExtent.InitSimple(simpleSizes);
94 
95  pcpp::IndexIntervalType overlapExtent2(localExtent.Overlap(zeroOverlapExtent));
96  if(overlapExtent2 != localExtent)
97  overlapWorks = false;
98 
99 
100  simpleSizes[1] = 10;
101  simpleSizes[2] = 10;
102  zeroOverlapExtent.InitSimple(simpleSizes);
103  overlapExtent2.Copy(localExtent.Overlap(zeroOverlapExtent));
104  bool copyWorks(overlapExtent2 == localExtent.Overlap(zeroOverlapExtent));
105 
106  if(overlapExtent2.NNodes() != 1000)
107  overlapWorks = false;
108  if(overlapExtent2 != zeroOverlapExtent)
109  overlapWorks = false;
110 
111  std::vector<size_t> overlapIndices;
112  globalExtent.GetFlatIndices(overlapExtent2,overlapIndices);
113  bool overlapFlatIndices(overlapIndices.size() == 1000);
114  if(!(overlapIndices[0] == 0 &&
115  overlapIndices[9] == 9 &&
116  overlapIndices[10] == 100 &&
117  overlapIndices[19] == 109 &&
118  overlapIndices[999] == 90909))
119  overlapFlatIndices = false;
120 
121 
122 
123  std::vector<size_t> testSize(3,10);
124  std::vector<size_t> testStart1(3,10);
125  pcpp::IndexIntervalType smallCube1(testStart1,testSize);
126  std::vector<size_t> testStart2(3,15);
127  pcpp::IndexIntervalType smallCube2(testStart2,testSize);
128  pcpp::IndexIntervalType cubeOverlap12(smallCube1.Overlap(smallCube2));
129  pcpp::IndexIntervalType cubeOverlap21(smallCube2.Overlap(smallCube1));
130  if(cubeOverlap12 != cubeOverlap21)
131  overlapWorks = false;
132  if(!(cubeOverlap12[0].first == 15 &&
133  cubeOverlap12[1].first == 15 &&
134  cubeOverlap12[2].first == 15 &&
135  cubeOverlap12[0].second == 19 &&
136  cubeOverlap12[1].second == 19 &&
137  cubeOverlap12[2].second == 19))
138  overlapWorks = false;
139  std::vector<size_t> flatIndices1;
140  std::vector<size_t> flatIndices2;
141  smallCube1.GetFlatIndices(cubeOverlap12,flatIndices1);
142  smallCube2.GetFlatIndices(cubeOverlap12,flatIndices2);
143  if(flatIndices1.size() != 125 ||
144  flatIndices2.size() != 125)
145  overlapFlatIndices = false;
146  std::vector<size_t>::iterator f1It = flatIndices1.begin();
147  for(size_t k = 15;k < 20;k++){
148  size_t zInd = k - 10;
149  for(size_t j = 15;j < 20;j++){
150  size_t yInd = j - 10;
151  for(size_t i = 15;i < 20;i++){
152  size_t xInd = i - 10;
153  size_t linearIndex = zInd*100 + yInd*10 + xInd;
154  if(*f1It++ != linearIndex)
155  overlapFlatIndices = false;
156  }
157  }
158  }
159  std::vector<size_t>::iterator f2It = flatIndices2.begin();
160  for(size_t k = 15;k < 20;k++){
161  size_t zInd = k - 15;
162  for(size_t j = 15;j < 20;j++){
163  size_t yInd = j - 15;
164  for(size_t i = 15;i < 20;i++){
165  size_t xInd = i - 15;
166  size_t linearIndex = zInd*100 + yInd*10 + xInd;
167  if(*f2It++ != linearIndex)
168  overlapFlatIndices = false;
169  }
170  }
171  }
172 
173  std::vector<size_t> tinySize(3,4);
174  std::vector<size_t> tinyStart1(3,0);
175  pcpp::IndexIntervalType tinyCube1(tinyStart1,tinySize);
176 
177  std::vector<size_t> tinyStart2(3,10);
178  tinyStart2[0] = 0;
179  pcpp::IndexIntervalType tinyCube2(tinyStart2,tinySize);
180  pcpp::IndexIntervalType tinyOverlap(tinyCube1.Overlap(tinyCube2));
181  if(!tinyOverlap.empty())
182  overlapWorks = false;
183 
184  bool overlap2DWorks = true;
185  std::vector<size_t> tinyStart3(3,0);
186  tinyStart3[0] = 3;
187  pcpp::IndexIntervalType tinyCube3(tinyStart3,tinySize);
188  pcpp::IndexIntervalType overlap2D(tinyCube1.Overlap(tinyCube3));
189  std::vector<size_t> flatIndices2D;
190  tinyCube1.GetFlatIndices(overlap2D,flatIndices2D);
191  if(flatIndices2D.size() != 16)
192  overlap2DWorks = false;
193  std::vector<size_t>::iterator ind2DIt = flatIndices2D.begin();
194  for(size_t k = 0;k < 4;k++){
195  size_t zInd = k * 16;
196  for(size_t j = 0;j < 4;j++){
197  size_t yInd = j * 4;
198  size_t linearIndex = zInd + yInd + 3;
199  if(*ind2DIt++ != linearIndex)
200  overlap2DWorks = false;
201  }
202  }
203 
204  bool overlap1DWorks = true;
205  std::vector<size_t> tinyStart4(3,3);
206  tinyStart4[2] = 0;
207  pcpp::IndexIntervalType tinyCube4(tinyStart4,tinySize);
208  pcpp::IndexIntervalType overlap1D(tinyCube1.Overlap(tinyCube4));
209  std::vector<size_t> flatIndices1D;
210  tinyCube1.GetFlatIndices(overlap1D,flatIndices1D);
211  std::vector<size_t>::iterator ind1DIt = flatIndices1D.begin();
212  if(flatIndices1D.size() != 4)
213  overlap1DWorks = false;
214  for(size_t k = 0;k < 4;k++){
215  size_t zInd = k * 16;
216  size_t linearIndex = zInd + 15;
217  if(*ind1DIt++ != linearIndex)
218  overlap1DWorks = false;
219  }
220 
221 
222  bool overlap0DWorks = true;
223  std::vector<size_t> tinyStart5(3,3);
224  pcpp::IndexIntervalType tinyCube5(tinyStart5,tinySize);
225  pcpp::IndexIntervalType overlap0D(tinyCube1.Overlap(tinyCube5));
226  std::vector<size_t> flatIndices0D;
227  tinyCube1.GetFlatIndices(overlap0D,flatIndices0D);
228  if(flatIndices0D.size() != 1)
229  overlap0DWorks = false;
230  if(flatIndices0D[0] != 63)
231  overlap0DWorks = false;
232 
233  serialUnitResults.UpdateResult("PCPP:Interval:FlatConstructor",flatConstructor);
234  serialUnitResults.UpdateResult("PCPP:Interval:CopyConstructor",copyConstructor);
235  serialUnitResults.UpdateResult("PCPP:Interval:StartSizeConstructor",startSizeConstructor);
236  serialUnitResults.UpdateResult("PCPP:Interval:Copy",copyWorks);
237  serialUnitResults.UpdateResult("PCPP:Interval:NodeCount",nodeCount);
238  serialUnitResults.UpdateResult("PCPP:Interval:Overlap",overlapWorks);
239  serialUnitResults.UpdateResult("PCPP:Interval:2DOverlap",overlap2DWorks);
240  serialUnitResults.UpdateResult("PCPP:Interval:1DOverlap",overlap1DWorks);
241  serialUnitResults.UpdateResult("PCPP:Interval:0DOverlap",overlap0DWorks);
242  serialUnitResults.UpdateResult("PCPP:Interval:NoOverlap",noOverlapWorks);
243  serialUnitResults.UpdateResult("PCPP:Interval:FlatIndices",overlapFlatIndices);
244 
245  std::vector<size_t> part1Start(3,0);
246  std::vector<size_t> part1Size(3,8);
247  part1Size[2] = 1;
248  pcpp::IndexIntervalType part1Extent(part1Start,part1Size);
249  std::vector<size_t> part2Start(3,8);
250  part2Start[2] = 0;
251  pcpp::IndexIntervalType part4Extent(part2Start,part1Size);
252  part2Start[1] = 0;
253  pcpp::IndexIntervalType part2Extent(part2Start,part1Size);
254  part1Size[1] = 3;
255  pcpp::IndexIntervalType part6Extent(part2Start,part1Size);
256  part2Start[0] = 0;
257  part2Start[1] = 8;
258  pcpp::IndexIntervalType part3Extent(part2Start,part1Size);
259  part2Start[1] = 16;
260  pcpp::IndexIntervalType part5Extent(part2Start,part1Size);
261  std::cout << "Part1: ";
262  part1Extent.PrettyPrint(std::cout);
263  std::cout << std::endl << "Part2: ";
264  part2Extent.PrettyPrint(std::cout);
265  std::cout << std::endl << "Part3: ";
266  part3Extent.PrettyPrint(std::cout);
267  std::cout << std::endl << "Part4: ";
268  part4Extent.PrettyPrint(std::cout);
269  std::cout << std::endl << "Part5: ";
270  part5Extent.PrettyPrint(std::cout);
271  std::cout << std::endl;
272 
273  bool neighborWorks = true;
274  pcpp::IndexIntervalType nbrExtent;
275  nbrExtent = part1Extent.Neighboring(part2Extent,1);
276  std::cout << "Nbr(1,2): ";
277  nbrExtent.PrettyPrint(std::cout);
278  std::cout << std::endl;
279  if(nbrExtent != part2Extent)
280  neighborWorks = false;
281  nbrExtent = part1Extent.Neighboring(part3Extent,1);
282  if(nbrExtent != part3Extent)
283  neighborWorks = false;
284  std::cout << "Nbr(1,3): ";
285  nbrExtent.PrettyPrint(std::cout);
286  std::cout << std::endl;
287  nbrExtent = part1Extent.Neighboring(part4Extent,1);
288  if(!nbrExtent.empty())
289  neighborWorks = false;
290  nbrExtent = part1Extent.Neighboring(part5Extent,1);
291  if(!nbrExtent.empty())
292  neighborWorks = false;
293  nbrExtent = part1Extent.Neighboring(part1Extent,1);
294  if(!nbrExtent.empty())
295  neighborWorks = false;
296  nbrExtent = part1Extent.Neighboring(part6Extent,1);
297  if(nbrExtent != part6Extent)
298  neighborWorks = false;
299 
300  serialUnitResults.UpdateResult("PCPP:Interval::Neighboring",neighborWorks);
301 }
void GetFlatIndices(const sizeextent &extent, ContainerType &indices) const
Definition: IndexUtil.H:302
size_t NNodes() const
Definition: IndexUtil.H:254
Encapsulating class for collections of test results.
Definition: Testing.H:18
Testing constructs for unit testing.
void Overlap(const sizeextent &inextent, sizeextent &outextent) const
Definition: IndexUtil.H:324
void UpdateResult(const std::string &name, const ValueType &result)
Updates an existing test result.
Definition: Testing.H:55
std::ostream & PrettyPrint(std::ostream &outStream) const
Definition: IndexUtil.C:6
void TestIntervalBasic(ix::test::results &serialUnitResults)
Serial unit tests for some primitive PlasCom2 stuff.
Definition: TestIntervals.C:9
Simple Block Structured Mesh object.
Definition: IndexUtil.H:21
void InitSimple(const ContainerType &inSize)
Definition: IndexUtil.H:169
sizeextent Neighboring(const sizeextent &inextent, int nbrDim) const
Definition: IndexUtil.H:351