OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
se_class3_vector_unit_tests.hpp
1 /*
2  * se_class3_vector_unit_tests.hpp
3  *
4  * Created on: Feb 12, 2017
5  * Author: i-bird
6  */
7 
8 #ifndef SRC_VECTOR_SE_CLASS3_VECTOR_UNIT_TESTS_HPP_
9 #define SRC_VECTOR_SE_CLASS3_VECTOR_UNIT_TESTS_HPP_
10 
11 #ifdef SE_CLASS3
12 
13 BOOST_AUTO_TEST_SUITE( vector_dist_class3 )
14 
15 BOOST_AUTO_TEST_CASE( vector_dist_class3_check )
16 {
17  Box<2,float> domain({0.0,0.0},{1.0,1.0});
18 
19  // Here we define the boundary conditions of our problem
20  size_t bc[2]={PERIODIC,PERIODIC};
21 
22  // extended boundary around the domain, and the processor domain
23  Ghost<2,float> g(0.05);
24 
26 
27  bool error = false;
28 
29  {
30  auto it = vd.getDomainIterator();
31  try
32  {
33  while (it.isNext())
34  {
35  auto p = it.get();
36 
37  // Read something not initialized ERROR
38  Point<2,float> a = vd.getPosRead(p);
39 
40  // Suppress compiler error
41  a.get(0) = 0;
42 
43  ++it;
44  }
45  }
46  catch (std::exception & e)
47  {
48  error = true;
49  }
50  }
51 
52  BOOST_REQUIRE_EQUAL(error,true);
53  error = false;
54 
55  // Initialize
56 
57  {
58  auto it = vd.getDomainIterator();
59 
60  while (it.isNext())
61  {
62  auto p = it.get();
63 
64  // Read something not initialized ERROR
65  vd.getPosWrite(p)[0] = (double)rand()/RAND_MAX;
66  vd.getPosWrite(p)[1] = (double)rand()/RAND_MAX;
67 
68  ++it;
69  }
70 
71  }
72 
73  {
74  auto it = vd.getDomainIterator();
75  try
76  {
77  while (it.isNext())
78  {
79  auto p = it.get();
80 
81  // Now has bee initialized so not error should be reported
82  Point<2,float> a = vd.getPosRead(p);
83 
84  // Suppress compiler error
85  a.get(0) = 0;
86 
87  ++it;
88  }
89  }
90  catch (std::exception & e)
91  {
92  error = true;
93  }
94  }
95 
96  BOOST_REQUIRE_EQUAL(error,false);
97  error = false;
98 
99  // we redistribute the particle
100 
101  vd.map();
102 
103  try
104  {
105  // Error we are getting the cell list from ghost out of sync in position
106  vd.getCellList(0.05);
107  }
108  catch (std::exception & e)
109  {
110  error = true;
111  }
112 
113  BOOST_REQUIRE_EQUAL(error,true);
114  error = false;
115 
116  try
117  {
118  // Error we are getting the cell list from ghost out of sync in position
119  vd.getVerlet(0.1);
120  }
121  catch (std::exception & e)
122  {
123  error = true;
124  }
125 
126  BOOST_REQUIRE_EQUAL(error,true);
127  error = false;
128 
129  try
130  {
131  // Error we are getting the cell list from ghost out of sync in position
132  vd.getCellListSym(0.05);
133  }
134  catch (std::exception & e)
135  {
136  error = true;
137  }
138 
139  BOOST_REQUIRE_EQUAL(error,true);
140  error = false;
141 
142  vd.ghost_get<0>();
143 
144  try
145  {
146  // OK
147  vd.getCellList(0.05);
148  }
149  catch (std::exception & e)
150  {
151  error = true;
152  }
153 
154  BOOST_REQUIRE_EQUAL(error,false);
155  error = false;
156 
157  // We make dirty a ghost particle
158  vd.template getPropWrite<0>(vd.size_local()) = 0.5;
159 
160  try
161  {
162  // Error we are destroying information
163  vd.ghost_get<0>();
164  }
165  catch (std::exception & e)
166  {
167  error = true;
168  }
169 
170  BOOST_REQUIRE_EQUAL(error,true);
171  error = false;
172 
173  // We make dirty a ghost particle
174  vd.template getPropWrite<0>(vd.size_local()) = 0.5;
175 
176  try
177  {
178  // Also error we are also destroying information
179  vd.ghost_get<1>();
180  }
181  catch (std::exception & e)
182  {
183  error = true;
184  }
185 
186  BOOST_REQUIRE_EQUAL(error,true);
187  error = false;
188 
189  // We make dirty a ghost particle
190  vd.template getPropWrite<0>(vd.size_local()) = 0.5;
191 
192  try
193  {
194  // OK we are not destroying information
195  vd.ghost_get<1>(KEEP_PROPERTIES);
196  }
197  catch (std::exception & e)
198  {
199  error = true;
200  }
201 
202  BOOST_REQUIRE_EQUAL(error,false);
203  error = false;
204 
205  // We make dirty a ghost particle
206  vd.template getPropWrite<0>(vd.size_local()) = 0.5;
207 
208  try
209  {
210  // Error we are destroying information
211  vd.ghost_get<0>(KEEP_PROPERTIES);
212  }
213  catch (std::exception & e)
214  {
215  error = true;
216  }
217 
218  BOOST_REQUIRE_EQUAL(error,true);
219  error = false;
220 
221  try
222  {
223  // error property 0 has never been initialized
224  vd.ghost_put<add_,0>();
225  }
226  catch (std::exception & e)
227  {
228  error = true;
229  }
230 
231  BOOST_REQUIRE_EQUAL(error,true);
232  error = false;
233 
234  {
235  auto it = vd.getDomainIterator();
236  try
237  {
238  while (it.isNext())
239  {
240  auto p = it.get();
241 
242  vd.getPropWrite<0>(p) = 2.0;
243 
244  ++it;
245  }
246 
247  // OK Property 0 has been initialized
248  vd.ghost_put<add_,0>();
249  }
250  catch (std::exception & e)
251  {
252  error = true;
253  }
254  }
255 
256  BOOST_REQUIRE_EQUAL(error,false);
257  error = false;
258 
259  try
260  {
261  // OK we are not destroying information
262  vd.ghost_get<0>();
263  }
264  catch (std::exception & e)
265  {
266  error = true;
267  }
268 
269  BOOST_REQUIRE_EQUAL(error,false);
270  error = false;
271 
272  try
273  {
274  // Error we are getting the cell list from ghost out of sync in position
275  vd.getCellList(0.05);
276  }
277  catch (std::exception & e)
278  {
279  error = true;
280  }
281 
282  BOOST_REQUIRE_EQUAL(error,false);
283  error = false;
284 
285  BOOST_REQUIRE_EQUAL(vd.get_se_class3().isGhostSync<1>(),NOTSYNC);
286 
287  vd.ghost_put<add_,0>();
288  vd.ghost_get<1>();
289 
290  auto NN = vd.getCellList(0.05);
291 
292  BOOST_REQUIRE_EQUAL(vd.get_se_class3().isGhostSync<1>(),SYNC);
293 
294 
295  auto it = vd.getDomainIterator();
296 
297  while (it.isNext())
298  {
299  auto p = it.get();
300 
301  // we set property 1
302  vd.getPropWrite<1>(p)[0] = 1.0;
303  vd.getPropWrite<1>(p)[1] = 1.0;
304  vd.getPropWrite<1>(p)[2] = 1.0;
305 
306  ++it;
307  }
308 
309  BOOST_REQUIRE_EQUAL(vd.get_se_class3().isGhostSync<1>(),NOTSYNC);
310 
311  {
312  auto it = vd.getDomainIterator();
313  try
314  {
315  while (it.isNext())
316  {
317  auto p = it.get();
318 
319  Point<2,float> xp = vd.getPosRead(p);
320 
321  auto NNp = NN.template getNNIterator<NO_CHECK>(NN.getCell(xp));
322 
323  while (NNp.isNext())
324  {
325  auto q = NNp.get();
326 
327  // Error ghost is not initialized
328  Point<3,float> xq = vd.template getPropRead<1>(q);
329 
330  xq.get(0) = 0.0;
331 
332  ++NNp;
333  }
334 
335  ++it;
336  }
337  }
338  catch (std::exception & e)
339  {
340  error = true;
341  }
342  }
343 
344  BOOST_REQUIRE_EQUAL(error,true);
345  error = false;
346 
347  vd.ghost_get<1>();
348 
349  {
350  auto it = vd.getDomainIterator();
351 
352  while (it.isNext())
353  {
354  auto p = it.get();
355 
356  // we set property 1
357  vd.getPropWrite<1>(p)[0] = 1.0;
358  vd.getPropWrite<1>(p)[1] = 1.0;
359  vd.getPropWrite<1>(p)[2] = 1.0;
360 
361  ++it;
362  }
363  }
364 
365  BOOST_REQUIRE_EQUAL(vd.get_se_class3().isGhostSync<1>(),NOTSYNC);
366 
367  {
368  auto it = vd.getDomainIterator();
369  try
370  {
371  while (it.isNext())
372  {
373  auto p = it.get();
374 
375  Point<2,float> xp = vd.getPosRead(p);
376 
377  auto NNp = NN.template getNNIterator<NO_CHECK>(NN.getCell(xp));
378 
379  while (NNp.isNext())
380  {
381  auto q = NNp.get();
382 
383  // Error ghost is not initialized
384  Point<3,float> xq = vd.template getPropRead<1>(q);
385 
386  xq.get(0) = 0.0;
387 
388  ++NNp;
389  }
390 
391  ++it;
392  }
393  }
394  catch (std::exception & e)
395  {
396  error = true;
397  }
398  }
399 
400  BOOST_REQUIRE_EQUAL(error,true);
401  error = false;
402 
403  vd.ghost_get<1>();
404 
405  {
406  auto it = vd.getDomainIterator();
407  try
408  {
409  while (it.isNext())
410  {
411  auto p = it.get();
412 
413  Point<2,float> xp = vd.getPosRead(p);
414 
415  auto NNp = NN.template getNNIterator<NO_CHECK>(NN.getCell(xp));
416 
417  while (NNp.isNext())
418  {
419  auto q = NNp.get();
420 
421  // Error we forgot ghost_get
422  Point<3,float> xq = vd.template getPropRead<1>(q);
423 
424  xq.get(0) = 0.0;
425 
426  ++NNp;
427  }
428 
429  ++it;
430  }
431  }
432  catch (std::exception & e)
433  {
434  error = true;
435  }
436  }
437 
438  BOOST_REQUIRE_EQUAL(error,false);
439 }
440 
441 
442 
444 
445 
446 BOOST_AUTO_TEST_CASE( vector_dist_class3_check_add )
447 {
448  Box<2,float> domain({0.0,0.0},{1.0,1.0});
449 
450  // Here we define the boundary conditions of our problem
451  size_t bc[2]={PERIODIC,PERIODIC};
452 
453  // extended boundary around the domain, and the processor domain
454  Ghost<2,float> g(0.05);
455 
457 
458  bool error = false;
459 
460  // Initialize
461 
462  {
463  for (size_t i = 0 ; i < 1200 ; i++)
464  {
465  vd.add();
466 
467  // Read something not initialized ERROR
468  vd.getLastPos()[0] = (double)rand()/RAND_MAX;
469  vd.getLastPos()[1] = (double)rand()/RAND_MAX;
470  }
471  }
472 
473  {
474  auto it = vd.getDomainIterator();
475  try
476  {
477  while (it.isNext())
478  {
479  auto p = it.get();
480 
481  // Now has bee initialized so not error should be reported
482  Point<2,float> a = vd.getPosRead(p);
483 
484  //Suppress warnings
485  a.get(0) = 0.0;
486 
487  ++it;
488  }
489  }
490  catch (std::exception & e)
491  {
492  error = true;
493  }
494  }
495 
496  BOOST_REQUIRE_EQUAL(error,true);
497  error = false;
498 
499  vd.map();
500 
501  {
502  auto it = vd.getDomainIterator();
503  try
504  {
505  while (it.isNext())
506  {
507  auto p = it.get();
508 
509  // Now has bee initialized so not error should be reported
510  float a = vd.getPropRead<0>(p);
511 
512  // Suppress warnings
513  a = 0;
514  a++;
515 
516  ++it;
517  }
518  }
519  catch (std::exception & e)
520  {
521  error = true;
522  }
523  }
524 
525  BOOST_REQUIRE_EQUAL(error,true);
526 }
527 
528 #if defined(CHECKFOR_POSNAN) && defined(CHECKFOR_PROPNAN) && defined(CHECKFOR_POSINF) && defined(CHECKFOR_PROPINF)
529 
530 
531 BOOST_AUTO_TEST_CASE( vector_dist_class3_check_nan_inf )
532 {
533  Box<2,float> domain({0.0,0.0},{1.0,1.0});
534 
535  // Here we define the boundary conditions of our problem
536  size_t bc[2]={PERIODIC,PERIODIC};
537 
538  // extended boundary around the domain, and the processor domain
539  Ghost<2,float> g(0.05);
540 
542 
543  bool error = false;
544 
545  // Initialize
546 
547  {
548  for (size_t i = 0 ; i < 1200 ; i++)
549  {
550  vd.add();
551 
552  // Read something not initialized ERROR
553  vd.getLastPos()[0] = 0.0/0.0;
554  vd.getLastPos()[1] = 0.0/0.0;
555  }
556  }
557 
558  {
559  try
560  {
561  vd.getPosRead(0);
562  }
563  catch (std::exception & e)
564  {
565  error = true;
566  }
567  }
568 
569  BOOST_REQUIRE_EQUAL(error,true);
570  error = false;
571 
573 
574  {
575  for (size_t i = 0 ; i < 1200 ; i++)
576  {
577  vd2.add();
578 
579  // Read something not initialized ERROR
580  vd2.getLastPos()[0] = 5.0/0.0;
581  vd2.getLastPos()[1] = 5.0/0.0;
582  }
583  }
584 
585  {
586  try
587  {
588  vd2.getLastPosRead();
589  }
590  catch (std::exception & e)
591  {
592  error = true;
593  }
594  }
595 
596  BOOST_REQUIRE_EQUAL(error,true);
597 }
598 
599 #endif
600 
601 BOOST_AUTO_TEST_SUITE_END()
602 
603 #endif
604 
605 #endif /* SRC_VECTOR_SE_CLASS3_VECTOR_UNIT_TESTS_HPP_ */
This structure define the operation add to use with copy general.
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:22
Definition: Ghost.hpp:39
const T & get(size_t i) const
Get coordinate.
Definition: Point.hpp:142
This class represent an N-dimensional box.
Definition: Box.hpp:56
Distributed vector.