rsvs3D  0.0.0
Codes for the c++ implementation of the 3D RSVS
arraystructures_test.cpp
1 #include <functional>
2 #include <iostream>
3 #include <sstream>
4 #include <stdexcept>
5 
6 #include "mesh.hpp"
7 #include "postprocessing.hpp"
8 // Test code
9 
10 using namespace std;
11 
12 int Test_ArrayStructures()
13 {
14  // Test the functionality provided by arraystructures
15 
16  int errFlag, errTest;
17 
18  errFlag = 0;
19 
20  cout << "--------------------------------------------" << endl;
21  cout << " testing volu" << endl;
22  cout << "--------------------------------------------" << endl;
23  errTest = Test_Volu();
24  errFlag = errFlag | (errTest != 0);
25 
26  cout << "--------------------------------------------" << endl;
27  cout << " testing surf" << endl;
28  cout << "--------------------------------------------" << endl;
29  errTest = Test_Surf();
30  errFlag = errFlag | (errTest != 0);
31 
32  cout << "--------------------------------------------" << endl;
33  cout << " testing vert" << endl;
34  cout << "--------------------------------------------" << endl;
35  errTest = Test_Vert();
36  errFlag = errFlag | (errTest != 0);
37 
38  cout << "--------------------------------------------" << endl;
39  cout << " testing edge" << endl;
40  cout << "--------------------------------------------" << endl;
41  errTest = Test_Edge();
42  errFlag = errFlag | (errTest != 0);
43 
44  cout << "--------------------------------------------" << endl;
45  cout << " testing Mesh" << endl;
46  cout << "--------------------------------------------" << endl;
47  errTest = Test_Mesh();
48  errFlag = errFlag | (errTest != 0);
49 
50  errFlag = errFlag | (errTest != 0);
51 
52  return (errFlag);
53 }
54 
55 int Test_Volu()
56 {
57  int i;
58 
59  voluarray cellStack; // stack of ints
60  volu singleCell;
61  const volu *cellPtr;
62 
63  try
64  {
65 
66  singleCell.surfind.push_back(3);
67  singleCell.surfind.push_back(4);
68 
69  cout << "assign 3 in cellStack" << endl;
70  cellStack.assign(3, singleCell);
71 
72  singleCell.index = 1;
73  cout << "push_back in cellStack" << endl;
74  cellStack.push_back(singleCell);
75 
76  // manipulate int stack
77 
78  cout << "Calls to display" << endl;
79  cout << "Display each volu in stack" << endl;
80 
81  for (i = 0; i < 4; ++i)
82  {
83  cellStack[i].index = i;
84  cellStack[i].surfind[0] = i;
85  cellStack[i].disp();
86  }
87 
88  cout << "Assign last volu to first volu" << endl;
89  cellStack[0] = cellStack[i - 1];
90  cellStack.disp();
91  cellStack[0] = cellStack(i - 2);
92  cellPtr = cellStack(i - 2);
93  cellStack.disp();
94  cout << "output cellptr" << endl;
95  cellPtr->disp();
96  cout << "Display each volu in stack" << endl;
97 
98  cout << cellStack.capacity() << endl;
99 
100  cout << "HashCellArrayStack" << endl;
101  cellStack.HashArray();
102  cellStack.SetMaxIndex();
103  cout << "Max Index in Array: " << cellStack.GetMaxIndex() << endl;
104 
105  cellStack.Concatenate(cellStack);
106  cellStack.disp();
107  }
108  catch (exception const &ex)
109  {
110  cerr << "Exception: " << ex.what() << endl;
111  return -1;
112  }
113  return (0);
114 }
115 
116 int Test_Surf()
117 {
118  int i;
119 
120  surfarray cellStack; // stack of ints
121  surf singleCell;
122 
123  try
124  {
125 
126  for (i = 0; i < 5; i++)
127  {
128  singleCell.edgeind.push_back(rand() % 100 + 1);
129  }
130 
131  for (i = 0; i < 2; i++)
132  {
133  singleCell.voluind.push_back(rand() % 100 + 1);
134  }
135 
136  cout << "assign 3 in cellStack" << endl;
137  cellStack.assign(3, singleCell);
138 
139  singleCell.index = 1;
140  cout << "push_back in cellStack" << endl;
141  cellStack.push_back(singleCell);
142 
143  // manipulate int stack
144 
145  cout << "Calls to display" << endl;
146  cout << "Display each volu in stack" << endl;
147 
148  for (i = 0; i < 4; ++i)
149  {
150  cellStack[i].index = i;
151  cellStack[i].edgeind[0] = i;
152  cellStack[i].disp();
153  }
154 
155  cout << "Assign last volu to first volu" << endl;
156  cellStack[0] = cellStack[i - 1];
157 
158  cout << "Display each volu in stack" << endl;
159 
160  cellStack.disp();
161 
162  cout << "HashCellArrayStack" << endl;
163  cellStack.HashArray();
164  }
165  catch (exception const &ex)
166  {
167  cerr << "Exception: " << ex.what() << endl;
168  return -1;
169  }
170  return (0);
171 }
172 int Test_Edge()
173 {
174  int i;
175 
176  edgearray cellStack; // stack of ints
177  edge singleCell;
178 
179  try
180  {
181 
182  for (i = 0; i < 5; i++)
183  {
184  singleCell.surfind.push_back(rand() % 100 + 1);
185  }
186 
187  for (i = 0; i < 2; i++)
188  {
189  singleCell.vertind.push_back(rand() % 100 + 1);
190  }
191 
192  cout << "assign 3 in cellStack" << endl;
193  cellStack.assign(3, singleCell);
194 
195  singleCell.index = 1;
196  cout << "push_back in cellStack" << endl;
197  cellStack.push_back(singleCell);
198 
199  // manipulate int stack
200 
201  cout << "Calls to display" << endl;
202  cout << "Display each volu in stack" << endl;
203 
204  for (i = 0; i < 4; ++i)
205  {
206  cellStack[i].index = i;
207  cellStack[i].surfind[0] = i;
208  cellStack[i].disp();
209  }
210 
211  cout << "Assign last volu to first volu" << endl;
212  cellStack[0] = cellStack[i - 1];
213 
214  cout << "Display each volu in stack" << endl;
215 
216  cellStack.disp();
217 
218  cout << "HashCellArrayStack" << endl;
219  cellStack.HashArray();
220  }
221  catch (exception const &ex)
222  {
223  cerr << "Exception: " << ex.what() << endl;
224  return -1;
225  }
226  return (0);
227 }
228 
229 int Test_Vert()
230 {
231  int i;
232 
233  vertarray cellStack; // stack of ints
234  vert singleCell;
235 
236  try
237  {
238 
239  for (i = 0; i < 5; i++)
240  {
241  singleCell.edgeind.push_back(rand() % 100 + 1);
242  }
243 
244  for (i = 0; i < 2; i++)
245  {
246  singleCell.coord.push_back(double(rand() % 100 + 1) / 100.0);
247  }
248 
249  cout << "assign 3 in cellStack" << endl;
250  cellStack.assign(3, singleCell);
251  singleCell.index = 1;
252  cout << "push_back in cellStack" << endl;
253  cellStack.push_back(singleCell);
254 
255  // manipulate int stack
256 
257  cout << "Calls to display" << endl;
258  cout << "Display each volu in stack" << endl;
259 
260  for (i = 0; i < 4; ++i)
261  {
262  cellStack[i].index = i;
263  cellStack[i].edgeind[0] = i;
264  cellStack[i].disp();
265  }
266 
267  cout << "Assign last volu to first volu" << endl;
268  cellStack[0] = cellStack[i - 1];
269 
270  cout << "Display each volu in stack" << endl;
271 
272  cellStack.disp();
273 
274  cout << "HashCellArrayStack" << endl;
275  cellStack.HashArray();
276 
277  cout << "Test Find " << cellStack.find(1) << endl;
278  }
279  catch (exception const &ex)
280  {
281  cerr << "Exception: " << ex.what() << endl;
282  return -1;
283  }
284  return (0);
285 }
286 
287 int Test_Mesh()
288 {
289  mesh mesh1, mesh2, mesh3;
290  int errFlag = 0;
291  bool test1;
292 
293  try
294  {
295 
296  mesh1.Init(8, 12, 6, 1);
297  mesh2.Init(14, 20, 11, 2);
298 
299  mesh1.PopulateIndices();
300  mesh2.PopulateIndices();
301  mesh3 = mesh1.MakeCompatible(mesh2);
302 #ifdef TEST_ARRAYSTRUCT_MESH
303  cout << "mesh1 " << endl;
304  mesh1.disp();
305  cout << "Compatible mesh #3 generated displaying ";
306  cout << "mesh2 " << endl;
307  mesh2.disp();
308 #endif
309 
310  mesh1.MakeCompatible_inplace(mesh2);
311 
312 #ifdef TEST_ARRAYSTRUCT_MESH
313  cout << "mesh2 made compatible inplace: ";
314  cout << "mesh2 " << endl;
315 
316  cout << "mesh3 " << endl;
317  mesh2.disp();
318  mesh3.disp();
319 #endif
320  test1 = CompareDisp(mesh2, mesh3);
321  errFlag = errFlag || (!test1);
322  cout << "Result of Comparison 2&3: " << test1 << endl;
323  test1 = CompareDisp(mesh1, mesh2);
324  cout << "Result of Comparison 1&2: " << test1 << endl;
325  errFlag = errFlag || (test1);
326 
327  cout << "Result of Comparison Test_Volu&Test_Volu: " << CompareFuncOut(Test_Volu, Test_Volu) << endl;
328 
329  cout << "Concatenate mesh 1 and 2" << endl;
330  mesh1.Concatenate(mesh2);
331  mesh1.disp();
332  }
333  catch (exception const &ex)
334  {
335  cerr << "Exception: " << ex.what() << endl;
336  errFlag = -1;
337  }
338  return (errFlag);
339 }
340 
341 int Test_Crop()
342 {
343  mesh meshin;
344  tecplotfile tecout;
345  std::vector<double> lb, ub;
346 
347  try
348  {
349  meshin.read("../TESTOUT/mesh234.dat");
350  tecout.OpenFile("../TESTOUT/meshcrop.plt");
351 
352  lb = {0.1, 0.1, 0.1};
353  ub = {0.9, 0.9, 0.9};
354  meshin.PrepareForUse();
355  tecout.PrintMesh(meshin);
356  tecout.PrintMesh(meshin, 0, 0, rsvs3d::constants::tecplot::line);
357  auto verts = meshin.AddBoundary(lb, ub);
358  tecout.PrintMesh(meshin, 0, 0, rsvs3d::constants::tecplot::line);
359  tecout.PrintMesh(meshin);
360  meshin.Crop(verts, 1);
361  tecout.PrintMesh(meshin);
362  }
363  catch (exception const &ex)
364  {
365  cerr << "Exception: " << ex.what() << endl;
366  return (-1);
367  }
368 
369  return (0);
370 }
Class for an edge object in a mesh.
Definition: mesh.hpp:353
Class for mesh handling.
Definition: mesh.hpp:592
std::vector< int > AddBoundary(const std::vector< double > &lb, const std::vector< double > &ub)
Adds boundaries alond max and min xyz planes.
Definition: mesh.cpp:5357
Class for surface object in a mesh.
Definition: mesh.hpp:267
Class for a vertex in a mesh.
Definition: mesh.hpp:448
Class for volume cell objects in a mesh.
Definition: mesh.hpp:197
Provides all the mesh tools used for the generation of 3D grids and geometries.
Provide tecplot file formating for mesh and snake outputs.