OpenFPM  5.2.0
Project that contain the implementation of distributed structures
vector_dist_NN_tests.cpp
1 /*
2  * vector_dist_NN_tests.hpp
3  *
4  * Created on: Aug 20, 2016
5  * Author: i-bird
6  */
7 
8 #define BOOST_TEST_DYN_LINK
9 #include <boost/test/unit_test.hpp>
10 
11 #include "VCluster/VCluster.hpp"
12 #include "Vector/vector_dist.hpp"
13 #include "Vector/vector_dist_subset.hpp"
14 
15 extern void print_test_v(std::string test, size_t sz);
16 
17 template<unsigned int opt> using VERLET_MEMFAST_OPT = VERLET_MEMFAST<3,float,opt>;
18 template<unsigned int opt> using VERLET_MEMBAL_OPT = VERLET_MEMBAL<3,float,opt>;
19 template<unsigned int opt> using VERLET_MEMMW_OPT = VERLET_MEMMW<3,float,opt>;
20 
21 template<template <unsigned int> class VerletList>
22 void test_full_nn_subset(long int k)
23 {
24  Vcluster<> & v_cl = create_vcluster();
25 
26  if (v_cl.getProcessingUnits() > 12)
27  return;
28 
29  // set the seed
30  // create the random generator engine
31  std::srand(v_cl.getProcessUnitID());
32  std::default_random_engine eg;
33  std::uniform_real_distribution<float> ud(0.0f, 1.0f);
34 
35  long int big_step = k / 4;
36  big_step = (big_step == 0)?1:big_step;
37 
38  print_test_v("Testing 3D full NN search k=",k);
39  BOOST_TEST_CHECKPOINT( "Testing 3D full NN search k=" << k );
40 
41  Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});
42 
43  // Boundary conditions
44  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
45 
46  for (double r_cut = 0.1 ; r_cut < 1.0; r_cut += 0.1)
47  {
48  // ghost
49  Ghost<3,float> ghost(r_cut*1.001);
50 
51  typedef aggregate<float> part_prop;
52 
53  // Distributed vector
54  vector_dist_ws<3,float, part_prop > vd(k,box,bc,ghost);
55 
56  auto it = vd.getIterator();
57 
58  while (it.isNext())
59  {
60  auto key = it.get();
61 
62  vd.getPos(key)[0] = ud(eg);
63  vd.getPos(key)[1] = ud(eg);
64  vd.getPos(key)[2] = ud(eg);
65 
66  // Fill some properties randomly
67 
68  vd.getProp<0>(key) = 0.0;
69 
70  if (ud(eg) < 0.5)
71  vd.setSubset(key, 0);
72  else
73  vd.setSubset(key, 1);
74 
75  ++it;
76  }
77 
78  vd.map();
79 
80  // sync the ghost
81  vd.ghost_get<0>();
82 
83  vector_dist_subset<3,float, part_prop> Particles_subset0(vd,0);
84  vector_dist_subset<3,float, part_prop> Particles_subset1(vd,1);
85 
88  bool ret;
89 
90  list_idx.resize(vd.size_local());
91  list_idx2.resize(vd.size_local());
92 
93  for (size_t i = 0 ; i < vd.size_local() ; i++)
94  {
95  Point<3,float> p = vd.getPos(i);
96 
97  for (size_t j = 0 ; j < vd.size_local_with_ghost(); j++)
98  {
99  Point<3,float> q = vd.getPos(j);
100 
101  if (vd.getSubset(i) == 0 && vd.getSubset(j) == 0)
102  if (p.distance2(q) < r_cut * r_cut)
103  list_idx.get(i).add(j);
104  }
105 
106  list_idx.get(i).sort();
107  }
108 
109  auto NNv = Particles_subset0.getVerlet(r_cut*1.0001);
110 
111  it = vd.getDomainIterator();
112 
113  while (it.isNext())
114  {
115  Point<3,float> xp = vd.getPos(it.get());
116  auto Np = NNv.getNNIterator(it.get().getKey());
117 
118  list_idx2.get(it.get().getKey()).clear();
119 
120  while (Np.isNext())
121  {
122  auto q = Np.get();
123 
124  Point<3,float> xq = vd.getPos(q);
125 
126  if (xp.distance2(xq) < r_cut * r_cut)
127  list_idx2.get(it.get().getKey()).add(q);
128 
129  ++Np;
130  }
131 
132  list_idx2.get(it.get().getKey()).sort();
133 
134  ++it;
135  }
136 
137  BOOST_REQUIRE_EQUAL(list_idx.size(),list_idx2.size());
138 
139  for (size_t i = 0 ; i < list_idx.size() ; i++)
140  {
141  BOOST_REQUIRE_EQUAL(list_idx.get(i).size(),list_idx2.get(i).size());
142 
143  ret = true;
144  for (size_t j = 0 ; j < list_idx.get(i).size() ; j++)
145  ret &= list_idx.get(i).get(j) == list_idx2.get(i).get(j);
146 
147  BOOST_REQUIRE_EQUAL(ret,true);
148  }
149 
150  list_idx.clear(); list_idx.resize(vd.size_local());
151  list_idx2.clear(); list_idx2.resize(vd.size_local());
152 
153  for (size_t i = 0 ; i < vd.size_local() ; i++)
154  {
155  Point<3,float> p = vd.getPos(i);
156 
157  for (size_t j = 0 ; j < vd.size_local_with_ghost(); j++)
158  {
159  Point<3,float> q = vd.getPos(j);
160 
161  if (vd.getSubset(i) == 1 && vd.getSubset(j) == 1)
162  if (p.distance2(q) < r_cut * r_cut)
163  list_idx.get(i).add(j);
164  }
165 
166  list_idx.get(i).sort();
167  }
168 
169  NNv = Particles_subset1.getVerlet(r_cut*1.0001);
170 
171  it = vd.getDomainIterator();
172 
173  while (it.isNext())
174  {
175  Point<3,float> xp = vd.getPos(it.get());
176  auto Np = NNv.getNNIterator(it.get().getKey());
177 
178  list_idx2.get(it.get().getKey()).clear();
179 
180  while (Np.isNext())
181  {
182  auto q = Np.get();
183 
184  Point<3,float> xq = vd.getPos(q);
185 
186  if (xp.distance2(xq) < r_cut * r_cut)
187  list_idx2.get(it.get().getKey()).add(q);
188 
189  ++Np;
190  }
191 
192  list_idx2.get(it.get().getKey()).sort();
193 
194  ++it;
195  }
196 
197  BOOST_REQUIRE_EQUAL(list_idx.size(),list_idx2.size());
198 
199  for (size_t i = 0 ; i < list_idx.size() ; i++)
200  {
201  BOOST_REQUIRE_EQUAL(list_idx.get(i).size(),list_idx2.get(i).size());
202 
203  ret = true;
204  for (size_t j = 0 ; j < list_idx.get(i).size() ; j++)
205  ret &= list_idx.get(i).get(j) == list_idx2.get(i).get(j);
206 
207  BOOST_REQUIRE_EQUAL(ret,true);
208  }
209 
210  }
211 }
212 
213 template<template <unsigned int> class VerletList>
214 void test_full_nn(long int k)
215 {
216  Vcluster<> & v_cl = create_vcluster();
217 
218  if (v_cl.getProcessingUnits() > 12)
219  return;
220 
221  // set the seed
222  // create the random generator engine
223  std::srand(v_cl.getProcessUnitID());
224  std::default_random_engine eg;
225  std::uniform_real_distribution<float> ud(0.0f, 1.0f);
226 
227  long int big_step = k / 4;
228  big_step = (big_step == 0)?1:big_step;
229 
230  print_test_v("Testing 3D full NN search k=",k);
231  BOOST_TEST_CHECKPOINT( "Testing 3D full NN search k=" << k );
232 
233  Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});
234 
235  // Boundary conditions
236  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
237 
238  for (double r_cut = 0.1 ; r_cut < 1.0; r_cut += 0.1)
239  {
240  // ghost
241  Ghost<3,float> ghost(r_cut*1.001);
242 
243  typedef aggregate<float> part_prop;
244 
245  // Distributed vector
246  vector_dist<3,float, part_prop > vd(k,box,bc,ghost);
247 
248  auto it = vd.getIterator();
249 
250  while (it.isNext())
251  {
252  auto key = it.get();
253 
254  vd.getPos(key)[0] = ud(eg);
255  vd.getPos(key)[1] = ud(eg);
256  vd.getPos(key)[2] = ud(eg);
257 
258  // Fill some properties randomly
259 
260  vd.getProp<0>(key) = 0.0;
261 
262  ++it;
263  }
264 
265  vd.map();
266 
267  // sync the ghost
268  vd.ghost_get<0>();
269 
272 
273  list_idx.resize(vd.size_local());
274  list_idx2.resize(vd.size_local());
275 
276  for (size_t i = 0 ; i < vd.size_local() ; i++)
277  {
278  Point<3,float> p = vd.getPos(i);
279 
280  for (size_t j = 0 ; j < vd.size_local_with_ghost(); j++)
281  {
282  Point<3,float> q = vd.getPos(j);
283 
284  if (p.distance2(q) < r_cut * r_cut)
285  list_idx.get(i).add(j);
286  }
287 
288  list_idx.get(i).sort();
289  }
290 
291  auto NN = vd.getCellList(r_cut);
292 
293  it = vd.getDomainIterator();
294 
295  while (it.isNext())
296  {
297  Point<3,float> xp = vd.getPos(it.get());
298  auto Np = NN.getNNIteratorBox(NN.getCell(xp));
299 
300  while (Np.isNext())
301  {
302  auto q = Np.get();
303 
304  Point<3,float> xq = vd.getPos(q);
305 
306  if (xp.distance2(xq) < r_cut * r_cut)
307  list_idx2.get(it.get().getKey()).add(q);
308 
309  ++Np;
310  }
311 
312  list_idx2.get(it.get().getKey()).sort();
313 
314  ++it;
315  }
316 
317  BOOST_REQUIRE_EQUAL(list_idx.size(),list_idx2.size());
318 
319  bool ret;
320  for (size_t i = 0 ; i < list_idx.size() ; i++)
321  {
322  BOOST_REQUIRE_EQUAL(list_idx.get(i).size(),list_idx2.get(i).size());
323 
324  ret = true;
325  for (size_t j = 0 ; j < list_idx.get(i).size() ; j++)
326  ret &= list_idx.get(i).get(j) == list_idx2.get(i).get(j);
327 
328  BOOST_REQUIRE_EQUAL(ret,true);
329  }
330 
332 
333  auto NNv = vd.template getVerlet<VL_NON_SYMMETRIC, VerletList<VL_NON_SYMMETRIC>>(r_cut*1.0001);
334 
335  it = vd.getDomainIterator();
336 
337  while (it.isNext())
338  {
339  Point<3,float> xp = vd.getPos(it.get());
340  auto Np = NNv.getNNIterator(it.get().getKey());
341 
342  list_idx2.get(it.get().getKey()).clear();
343 
344  while (Np.isNext())
345  {
346  auto q = Np.get();
347 
348  Point<3,float> xq = vd.getPos(q);
349 
350  if (xp.distance2(xq) < r_cut * r_cut)
351  list_idx2.get(it.get().getKey()).add(q);
352 
353  ++Np;
354  }
355 
356  list_idx2.get(it.get().getKey()).sort();
357 
358  ++it;
359  }
360 
361  BOOST_REQUIRE_EQUAL(list_idx.size(),list_idx2.size());
362 
363  for (size_t i = 0 ; i < list_idx.size() ; i++)
364  {
365  BOOST_REQUIRE_EQUAL(list_idx.get(i).size(),list_idx2.get(i).size());
366 
367  ret = true;
368  for (size_t j = 0 ; j < list_idx.get(i).size() ; j++)
369  ret &= list_idx.get(i).get(j) == list_idx2.get(i).get(j);
370 
371  BOOST_REQUIRE_EQUAL(ret,true);
372  }
373 
375 
376  NNv.clear();
377  vd.updateVerlet(NNv,r_cut*1.0001);
378 
379  it = vd.getDomainIterator();
380 
381  while (it.isNext())
382  {
383  Point<3,float> xp = vd.getPos(it.get());
384  auto Np = NNv.getNNIterator(it.get().getKey());
385 
386  list_idx2.get(it.get().getKey()).clear();
387 
388  while (Np.isNext())
389  {
390  auto q = Np.get();
391 
392  Point<3,float> xq = vd.getPos(q);
393 
394  if (xp.distance2(xq) < r_cut * r_cut)
395  list_idx2.get(it.get().getKey()).add(q);
396 
397  ++Np;
398  }
399 
400  list_idx2.get(it.get().getKey()).sort();
401 
402  ++it;
403  }
404 
405  BOOST_REQUIRE_EQUAL(list_idx.size(),list_idx2.size());
406 
407  for (size_t i = 0 ; i < list_idx.size() ; i++)
408  {
409  BOOST_REQUIRE_EQUAL(list_idx.get(i).size(),list_idx2.get(i).size());
410 
411  ret = true;
412  for (size_t j = 0 ; j < list_idx.get(i).size() ; j++)
413  ret &= list_idx.get(i).get(j) == list_idx2.get(i).get(j);
414 
415  BOOST_REQUIRE_EQUAL(ret,true);
416  }
417  }
418 }
419 
420 template<template <unsigned int> class VerletList>
421 void test_full_nn_adaptive(long int k)
422 {
423  Vcluster<> & v_cl = create_vcluster();
424 
425  if (v_cl.getProcessingUnits() > 12)
426  return;
427 
428  // set the seed
429  // create the random generator engine
430  std::srand(v_cl.getProcessUnitID());
431  std::default_random_engine eg;
432  std::uniform_real_distribution<float> ud(0.0f, 1.0f);
433 
434  long int big_step = k / 4;
435  big_step = (big_step == 0)?1:big_step;
436 
437  print_test_v("Testing 3D full NN search k=",k);
438  BOOST_TEST_CHECKPOINT( "Testing 3D full NN search k=" << k );
439 
440  Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});
441 
442  // Boundary conditions
443  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
444 
445  for (double r_cut = 0.1 ; r_cut < 1.0; r_cut += 0.1)
446  {
447  // ghost
448  Ghost<3,float> ghost(r_cut*1.001);
449 
450  typedef aggregate<float, float> part_prop;
451 
452  // Distributed vector
453  vector_dist<3,float, part_prop > vd(k,box,bc,ghost);
454 
455  auto it = vd.getIterator();
456 
457  while (it.isNext())
458  {
459  auto key = it.get();
460 
461  vd.getPos(key)[0] = ud(eg);
462  vd.getPos(key)[1] = ud(eg);
463  vd.getPos(key)[2] = ud(eg);
464 
465  // Fill some properties randomly
466 
467  vd.getProp<1>(key) = 0.0;
468 
469  ++it;
470  }
471 
472  vd.map();
473 
474  // sync the ghost
475  vd.ghost_get<1>();
476 
479 
480  list_idx.resize(vd.size_local());
481  list_idx2.resize(vd.size_local());
482 
483  for (size_t i = 0 ; i < vd.size_local() ; i++)
484  {
485  Point<3,float> p = vd.getPos(i);
486 
487  for (size_t j = 0 ; j < vd.size_local_with_ghost(); j++)
488  {
489  Point<3,float> q = vd.getPos(j);
490 
491  if (p.distance2(q) < r_cut * r_cut)
492  list_idx.get(i).add(j);
493  }
494 
495  list_idx.get(i).sort();
496  }
497 
498  auto NN = vd.getCellList(r_cut);
499 
500  it = vd.getDomainIterator();
501 
502  while (it.isNext())
503  {
504  Point<3,float> xp = vd.getPos(it.get());
505  auto Np = NN.getNNIteratorBox(NN.getCell(xp));
506 
507  while (Np.isNext())
508  {
509  auto q = Np.get();
510 
511  Point<3,float> xq = vd.getPos(q);
512 
513  if (xp.distance2(xq) < r_cut * r_cut)
514  list_idx2.get(it.get().getKey()).add(q);
515 
516  ++Np;
517  }
518 
519  list_idx2.get(it.get().getKey()).sort();
520 
521  ++it;
522  }
523 
524  BOOST_REQUIRE_EQUAL(list_idx.size(),list_idx2.size());
525 
526  bool ret;
527  for (size_t i = 0 ; i < list_idx.size() ; i++)
528  {
529  BOOST_REQUIRE_EQUAL(list_idx.get(i).size(),list_idx2.get(i).size());
530 
531  ret = true;
532  for (size_t j = 0 ; j < list_idx.get(i).size() ; j++)
533  ret &= list_idx.get(i).get(j) == list_idx2.get(i).get(j);
534 
535  BOOST_REQUIRE_EQUAL(ret,true);
536  }
537 
539  for (int i = 0; i < vd.size_local(); ++i)
540  {
541  // rCut is always stored in the first property
542  vd.getProp<0>(i) = r_cut*1.0001;
543  }
544 
545  auto NNv = vd.template getVerletAdaptRCut<VerletList<VL_ADAPTIVE_RCUT>>();
546 
547  it = vd.getDomainIterator();
548 
549  while (it.isNext())
550  {
551  Point<3,float> xp = vd.getPos(it.get());
552  auto Np = NNv.getNNIterator(it.get().getKey());
553 
554  list_idx2.get(it.get().getKey()).clear();
555 
556  while (Np.isNext())
557  {
558  auto q = Np.get();
559 
560  Point<3,float> xq = vd.getPos(q);
561 
562  if (xp.distance2(xq) < r_cut * r_cut)
563  list_idx2.get(it.get().getKey()).add(q);
564 
565  ++Np;
566  }
567 
568  list_idx2.get(it.get().getKey()).sort();
569 
570  ++it;
571  }
572 
573  BOOST_REQUIRE_EQUAL(list_idx.size(),list_idx2.size());
574 
575  for (size_t i = 0 ; i < list_idx.size() ; i++)
576  {
577  BOOST_REQUIRE_EQUAL(list_idx.get(i).size(),list_idx2.get(i).size());
578 
579  ret = true;
580  for (size_t j = 0 ; j < list_idx.get(i).size() ; j++)
581  ret &= list_idx.get(i).get(j) == list_idx2.get(i).get(j);
582 
583  BOOST_REQUIRE_EQUAL(ret,true);
584  }
585 
587 
588  NNv.clear();
589  vd.updateVerletAdaptRCut(NNv);
590 
591  it = vd.getDomainIterator();
592 
593  while (it.isNext())
594  {
595  Point<3,float> xp = vd.getPos(it.get());
596  auto Np = NNv.getNNIterator(it.get().getKey());
597 
598  list_idx2.get(it.get().getKey()).clear();
599 
600  while (Np.isNext())
601  {
602  auto q = Np.get();
603 
604  Point<3,float> xq = vd.getPos(q);
605 
606  if (xp.distance2(xq) < r_cut * r_cut)
607  list_idx2.get(it.get().getKey()).add(q);
608 
609  ++Np;
610  }
611 
612  list_idx2.get(it.get().getKey()).sort();
613 
614  ++it;
615  }
616 
617  BOOST_REQUIRE_EQUAL(list_idx.size(),list_idx2.size());
618 
619  for (size_t i = 0 ; i < list_idx.size() ; i++)
620  {
621  BOOST_REQUIRE_EQUAL(list_idx.get(i).size(),list_idx2.get(i).size());
622 
623  ret = true;
624  for (size_t j = 0 ; j < list_idx.get(i).size() ; j++)
625  ret &= list_idx.get(i).get(j) == list_idx2.get(i).get(j);
626 
627  BOOST_REQUIRE_EQUAL(ret,true);
628  }
629  }
630 }
631 
632 BOOST_AUTO_TEST_CASE( vector_dist_full_NN )
633 {
634  auto & v_cl = create_vcluster();
635 
636 #ifdef TEST_COVERAGE_MODE
637  long int k = 50 * v_cl.getProcessingUnits();
638 #else
639  long int k = 750 * v_cl.getProcessingUnits();
640 #endif
641 
642  test_full_nn<VERLET_MEMFAST_OPT>(k);
643 
644  k /= 2;
645  test_full_nn<VERLET_MEMBAL_OPT>(k);
646  k /= 2;
647  test_full_nn<VERLET_MEMMW_OPT>(k);
648 }
649 
650 BOOST_AUTO_TEST_CASE( vector_dist_full_NN_subset )
651 {
652  auto & v_cl = create_vcluster();
653 
654 #ifdef TEST_COVERAGE_MODE
655  long int k = 50 * v_cl.getProcessingUnits();
656 #else
657  long int k = 750 * v_cl.getProcessingUnits();
658 #endif
659 
660  test_full_nn_subset<VERLET_MEMFAST_OPT>(k);
661 
662  k /= 2;
663  test_full_nn_subset<VERLET_MEMBAL_OPT>(k);
664  k /= 2;
665  test_full_nn_subset<VERLET_MEMMW_OPT>(k);
666 }
667 
668 BOOST_AUTO_TEST_CASE( vector_dist_full_NN_adaptive )
669 {
670  auto & v_cl = create_vcluster();
671 
672 #ifdef TEST_COVERAGE_MODE
673  long int k = 50 * v_cl.getProcessingUnits();
674 #else
675  long int k = 750 * v_cl.getProcessingUnits();
676 #endif
677 
678  test_full_nn_adaptive<VERLET_MEMFAST_OPT>(k);
679 
680  k /= 2;
681  test_full_nn_adaptive<VERLET_MEMBAL_OPT>(k);
682  k /= 2;
683  test_full_nn_adaptive<VERLET_MEMMW_OPT>(k);
684 }
685 
686 BOOST_AUTO_TEST_CASE( vector_dist_particle_iteration )
687 {
688  Vcluster<> & v_cl = create_vcluster();
689 
690  if (v_cl.getProcessingUnits() > 12)
691  return;
692 
693  // set the seed
694  // create the random generator engine
695  std::srand(v_cl.getProcessUnitID());
696  std::default_random_engine eg;
697  std::uniform_real_distribution<float> ud(0.0f, 1.0f);
698 
699  long int k = 750 * v_cl.getProcessingUnits();
700 
701  print_test_v("Testing 3D particle cell iterator=",k);
702  BOOST_TEST_CHECKPOINT( "Testing 3D full NN search k=" << k );
703 
704  Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});
705 
706  // Boundary conditions
707  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
708 
709  float r_cut = 0.1;
710 
711  // ghost
712  Ghost<3,float> ghost(r_cut);
713 
714  typedef aggregate<float> part_prop;
715 
716  // Distributed vector
717  vector_dist<3,float, part_prop > vd(k,box,bc,ghost,BIND_DEC_TO_GHOST);
718 
719  auto it = vd.getIterator();
720 
721  while (it.isNext())
722  {
723  auto key = it.get();
724 
725  vd.getPos(key)[0] = ud(eg);
726  vd.getPos(key)[1] = ud(eg);
727  vd.getPos(key)[2] = ud(eg);
728 
729  // Fill some properties randomly
730 
731  vd.getProp<0>(key) = 0.0;
732 
733  ++it;
734  }
735 
736  vd.map();
737 
738  // sync the ghost
739  vd.ghost_get<0>();
740 
742  ids.resize(vd.size_local());
743 
744  auto NN = vd.getCellListSym(r_cut);
745 
746  auto it_pcell = vd.getDomainIteratorCells(NN);
747 
748  size_t count = 0;
749  while (it_pcell.isNext())
750  {
751  count++;
752 
753  size_t id = it_pcell.get();
754  ids.get(id) = 1;
755 
756  BOOST_REQUIRE(id < vd.size_local());
757 
758  ++it_pcell;
759  }
760 
761  v_cl.sum(count);
762  v_cl.execute();
763 
764  BOOST_REQUIRE_EQUAL((long int)count,k);
765 }
766 
767 BOOST_AUTO_TEST_CASE( vector_dist_particle_NN_update_with_limit )
768 {
769  Vcluster<> & v_cl = create_vcluster();
770 
771  if (v_cl.getProcessingUnits() > 12)
772  return;
773 
774  // set the seed
775  // create the random generator engine
776  std::srand(v_cl.getProcessUnitID());
777  std::default_random_engine eg;
778  std::uniform_real_distribution<float> ud(0.0f, 1.0f);
779 
780  long int k = 750 * v_cl.getProcessingUnits();
781 
782  print_test_v("Testing 3D particle cell-list with radius at limit= ",k);
783  BOOST_TEST_CHECKPOINT( "Testing 3D particle cell-list with radius at limit= " << k );
784 
785  Box<3,float> box({0.0,0.0,0.0},{0.1,0.39,0.39});
786 
787  // Boundary conditions
788  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
789 
790  float r_cut = 0.1;
791 
792  // ghost
793  Ghost<3,float> ghost(r_cut);
794 
795  typedef aggregate<float> part_prop;
796 
797  // Distributed vector
798  vector_dist<3,float, part_prop > vd(k,box,bc,ghost);
799 
800  auto it = vd.getIterator();
801 
802  while (it.isNext())
803  {
804  auto key = it.get();
805 
806  vd.getPos(key)[0] = ud(eg);
807  vd.getPos(key)[1] = ud(eg);
808  vd.getPos(key)[2] = ud(eg);
809 
810  // Fill some properties randomly
811 
812  vd.getProp<0>(key) = 0.0;
813 
814  ++it;
815  }
816 
817  vd.map();
818 
819  // sync the ghost
820  vd.ghost_get<0>();
821 
822  auto NN = vd.getCellListSym(r_cut);
823 
824  auto cell1 = NN.getCellBox();
825 
826  vd.getDecomposition().decompose();
827  vd.map();
828 
829  vd.updateCellList(NN);
830 
831  auto cell2 = NN.getCellBox();
832 
833  BOOST_REQUIRE_EQUAL(cell1.getHigh(0),cell2.getHigh(0));
834  BOOST_REQUIRE_EQUAL(cell1.getHigh(1),cell2.getHigh(1));
835  BOOST_REQUIRE_EQUAL(cell1.getHigh(2),cell2.getHigh(2));
836 }
837 
838 BOOST_AUTO_TEST_CASE( vector_dist_particle_getCellListSym_with_div )
839 {
840  Vcluster<> & v_cl = create_vcluster();
841 
842  if (v_cl.getProcessingUnits() > 12)
843  return;
844 
845  // set the seed
846  // create the random generator engine
847  std::srand(v_cl.getProcessUnitID());
848  std::default_random_engine eg;
849  std::uniform_real_distribution<float> ud(0.0f, 1.0f);
850 
851  long int k = 750 * v_cl.getProcessingUnits();
852 
853  print_test_v("Testing 3D particle getCellListSym with div =",k);
854  BOOST_TEST_CHECKPOINT( "Testing 3D particle getCellListSym with div = " << k );
855 
856  Box<3,float> box({0.0,0.0,0.0},{0.1,0.39,0.39});
857 
858  // Boundary conditions
859  size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
860 
861  float r_cut = 0.1;
862 
863  // ghost
864  Ghost<3,float> ghost(r_cut);
865 
866  typedef aggregate<float> part_prop;
867 
868  // Distributed vector
869  vector_dist<3,float, part_prop > vd(k,box,bc,ghost);
870 
871  auto it = vd.getIterator();
872 
873  while (it.isNext())
874  {
875  auto key = it.get();
876 
877  vd.getPos(key)[0] = ud(eg);
878  vd.getPos(key)[1] = ud(eg);
879  vd.getPos(key)[2] = ud(eg);
880 
881  // Fill some properties randomly
882 
883  vd.getProp<0>(key) = 0.0;
884 
885  ++it;
886  }
887 
888  vd.map();
889 
890  // sync the ghost
891  vd.ghost_get<0>();
892 
893  auto NN1 = vd.getCellListSym(r_cut);
894 
895  size_t div_wp[3] = {NN1.getDivWP()[0],NN1.getDivWP()[1],NN1.getDivWP()[2]};
896  size_t pad[3] = {NN1.getPadding()[0],NN1.getPadding()[1],NN1.getPadding()[2]};
897 
898  auto NN2 = vd.getCellListSym(div_wp,pad);
899 
900  // Check that the two Cell list are identical
901 
902  // grid info
903  size_t div[3] = {NN1.getInternalGrid().getSize()[0],
904  NN1.getInternalGrid().getSize()[1],
905  NN1.getInternalGrid().getSize()[2]};
906 
907  grid_sm<3,void> g_info(div);
908 
909  bool match = true;
910 
911  // Create a grid iterator
912  grid_key_dx_iterator<3> g_it(g_info);
913 
914  while (g_it.isNext())
915  {
916  size_t cell = g_info.LinId(g_it.get());
917  size_t n_ele1 = NN1.getNelements(cell);
918  size_t n_ele2 = NN2.getNelements(cell);
919 
920  match &= n_ele1 == n_ele2;
921 
922  ++g_it;
923  }
924 
925  BOOST_REQUIRE_EQUAL(match,true);
926 }
Point::distance2
T distance2(const Point< dim, T > &q) const
It calculate the square distance between 2 points.
Definition: Point.hpp:284
Vcluster_base< HeapMemory >::getProcessingUnits
size_t getProcessingUnits()
Get the total number of processors.
Definition: VCluster_base.hpp:501
grid_sm
Declaration grid_sm.
Definition: grid_sm.hpp:147
openfpm::vector::size
size_t size()
Stub size.
Definition: map_vector.hpp:212
aggregate
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Definition: aggregate.hpp:220
Point::get
__device__ const __host__ T & get(unsigned int i) const
Get coordinate.
Definition: Point.hpp:172
openfpm::vector
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:203
grid_key_dx_iterator
Definition: grid_key_dx_iterator.hpp:28
Vcluster_base< HeapMemory >::execute
void execute()
Execute all the requests.
Definition: VCluster_base.hpp:1779
Box< 3, float >
Vcluster_base< HeapMemory >::sum
void sum(T &num)
Sum the numbers across all processors and get the result.
Definition: VCluster_base.hpp:583
VerletList
Class for Verlet list implementation.
Definition: VerletList.hpp:268
vector_dist_ws
Definition: vector_dist_subset.hpp:16
vector_dist
Distributed vector.
Definition: vector_dist.hpp:170
Point< 3, float >
Vcluster_base< HeapMemory >::getProcessUnitID
size_t getProcessUnitID()
Get the process unit id.
Definition: VCluster_base.hpp:557
Ghost
Definition: Ghost.hpp:39
Vcluster
Implementation of VCluster class.
Definition: VCluster.hpp:58
vector_dist_subset
Definition: vector_dist_subset.hpp:83