9#define BOOST_TEST_DYN_LINK
10#include <boost/test/unit_test.hpp>
11#include "Point_test.hpp"
12#include "Vector/performance/vector_dist_performance_common.hpp"
13#include "Vector/vector_dist.hpp"
15extern void print_test_v(std::string test,
size_t sz);
16extern long int decrement(
long int k,
long int step);
20void test_reorder_sfc(reorder_opt opt)
30 std::default_random_engine eg;
31 std::uniform_real_distribution<float> ud(0.0f, 1.0f);
33#ifdef TEST_COVERAGE_MODE
39 long int big_step = k / 4;
40 big_step = (big_step == 0)?1:big_step;
42 print_test_v(
"Testing 2D vector with sfc curve reordering k<=",k);
45 for ( ; k >= 2 ; k-= decrement(k,big_step) )
47 BOOST_TEST_CHECKPOINT(
"Testing 2D vector with sfc curve reordering k=" << k );
52 size_t bc[2]={NON_PERIODIC,NON_PERIODIC};
56 auto it = vd.getIterator();
62 vd.getPos(key)[0] = ud(eg);
63 vd.getPos(key)[1] = ud(eg);
74 auto NN1 = vd.getCellList(0.01,
true);
83 auto NN2 = vd.getCellList(0.01,
true);
86 for (
size_t i = 0 ; i < NN1.getGrid().size() ; i++)
88 size_t n1 = NN1.getNelements(i);
89 size_t n2 = NN2.getNelements(i);
91 BOOST_REQUIRE_EQUAL(n1,n2);
108 std::default_random_engine eg;
109 std::uniform_real_distribution<float> ud(0.0f, 1.0f);
111#ifdef TEST_COVERAGE_MODE
117 long int big_step = k / 4;
118 big_step = (big_step == 0)?1:big_step;
120 print_test_v(
"Testing 2D vector with sfc curve reordering k<=",k);
123 for ( ; k >= 2 ; k-= decrement(k,big_step) )
125 BOOST_TEST_CHECKPOINT(
"Testing 2D vector with sfc curve reordering k=" << k );
130 size_t bc[2]={NON_PERIODIC,NON_PERIODIC};
134 auto it = vd.getIterator();
140 vd.getPos(key)[0] = ud(eg);
141 vd.getPos(key)[1] = ud(eg);
152 auto NN1 = vd.getCellList(0.01,
true);
155 vd.reorder_rcut(0.01);
158 auto NN2 = vd.getCellList(0.01,
true);
161 for (
size_t i = 0 ; i < NN1.getGrid().size() ; i++)
163 size_t n1 = NN1.getNelements(i);
164 size_t n2 = NN2.getNelements(i);
166 BOOST_REQUIRE_EQUAL(n1,n2);
171BOOST_AUTO_TEST_SUITE( vector_dist_cell_list_test_suite )
173BOOST_AUTO_TEST_CASE( vector_dist_reorder_2d_test )
175 test_reorder_sfc(reorder_opt::HILBERT);
176 test_reorder_sfc(reorder_opt::LINEAR);
179BOOST_AUTO_TEST_CASE( vector_dist_reorder_cl_test )
184BOOST_AUTO_TEST_CASE( vector_dist_cl_random_vs_hilb_forces_test )
194 const size_t dim = 3;
198 size_t cl_k_start = 10000;
200 size_t cl_k_min = 1000;
202 double ghost_part = 0.05;
207 for (
size_t r = 0; r < cl_r_cutoff.size(); r++ )
210 float r_cut = cl_r_cutoff.get(r);
215 std::string str(
"Testing " + std::to_string(dim) +
"D vector's forces (random vs hilb celllist) k<=");
220 for (
size_t k_int = k ; k_int >= cl_k_min ; k_int/=2 )
222 BOOST_TEST_CHECKPOINT(
"Testing " << dim <<
"D vector's forces (random vs hilb celllist) k<=" << k_int );
226 for (
size_t i = 0; i < dim; i++)
235 for (
size_t i = 0; i < dim; i++)
243 vd_initialize_double<dim>(vd, vd2, v_cl, k_int);
250 auto NN = vd.getCellList(r_cut);
254 calc_forces<dim>(NN,vd,r_cut);
258 auto NN_hilb = vd2.getCellList_hilb(r_cut);
261 calc_forces_hilb<dim>(NN_hilb,vd2,r_cut);
266 for (
size_t i = 0 ; i < dim ; i++) {avg.
get(i) = 0.0;}
268 auto it_v2 = vd.getIterator();
269 while (it_v2.isNext())
274 for (
size_t i = 0; i < dim; i++)
275 {avg.
get(i) += fabs(vd.getProp<0>(key)[i]);}
281 for (
size_t i = 0 ; i < dim ; i++) {avg.
get(i) /= count;}
283 auto it_v = vd.getIterator();
284 while (it_v.isNext())
289 for (
size_t i = 0; i < dim; i++)
291 auto a1 = vd.getProp<0>(key)[i];
292 auto a2 = vd2.getProp<0>(key)[i];
297 per = fabs(0.1*avg.
get(i)/a1);
299 BOOST_REQUIRE_CLOSE((
float)a1,(
float)a2,per);
308BOOST_AUTO_TEST_CASE( vector_dist_cl_random_vs_reorder_forces_test )
318 const size_t dim = 3;
322 size_t cl_k_start = 10000;
324 size_t cl_k_min = 1000;
326 double ghost_part = 0.01;
331 for (
size_t r = 0; r < cl_r_cutoff.size(); r++ )
334 float r_cut = cl_r_cutoff.get(r);
339 std::string str(
"Testing " + std::to_string(dim) +
"D vector's forces (random vs reorder) k<=");
344 for (
size_t k_int = k ; k_int >= cl_k_min ; k_int/=2 )
346 BOOST_TEST_CHECKPOINT(
"Testing " << dim <<
"D vector's forces (random vs reorder) k<=" << k_int );
350 for (
size_t i = 0; i < dim; i++)
359 for (
size_t i = 0; i < dim; i++)
365 vd_initialize<dim,decltype(vd)>(vd, v_cl);
371 auto NN1 = vd.getCellList(r_cut);
375 calc_forces<dim>(NN1,vd,r_cut);
383 auto NN2 = vd.getCellList(r_cut);
386 calc_forces<dim,1>(NN2,vd,r_cut);
391 for (
size_t i = 0 ; i < dim ; i++) {avg.
get(i) = 0.0;}
393 auto it_v2 = vd.getIterator();
394 while (it_v2.isNext())
399 for (
size_t i = 0; i < dim; i++)
400 avg.
get(i) += fabs(vd.getProp<0>(key)[i]);
406 for (
size_t i = 0 ; i < dim ; i++) {avg.
get(i) /= count;}
409 auto it_v = vd.getDomainIterator();
411 while (it_v.isNext())
416 for (
size_t i = 0; i < dim; i++)
418 float a1 = vd.getProp<0>(key)[i];
419 float a2 = vd.getProp<1>(key)[i];
424 per = fabs(0.1*avg.
get(i)/a1);
426 BOOST_REQUIRE_CLOSE(a1,a2,per);
435BOOST_AUTO_TEST_CASE( vector_dist_symmetric_cell_list )
447 std::default_random_engine eg;
448 std::uniform_real_distribution<float> ud(-L,L);
452 long int big_step = k / 4;
453 big_step = (big_step == 0)?1:big_step;
455 print_test_v(
"Testing 3D periodic vector symmetric cell-list k=",k);
456 BOOST_TEST_CHECKPOINT(
"Testing 3D periodic vector symmetric cell-list k=" << k );
461 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
476 return (
id < pag.id);
484 size_t start = vd.init_size_accum(k);
486 auto it = vd.getIterator();
492 vd.getPosWrite(key)[0] = ud(eg);
493 vd.getPosWrite(key)[1] = ud(eg);
494 vd.getPosWrite(key)[2] = ud(eg);
498 vd.getPropWrite<0>(key) = 0;
499 vd.getPropWrite<1>(key) = 0;
500 vd.getPropWrite<2>(key) = key.
getKey() + start;
510 auto NN = vd.getCellList(r_cut);
511 auto p_it = vd.getDomainIterator();
513 while (p_it.isNext())
519 auto Np = NN.getNNIterator(NN.getCell(xp));
536 float distance = f.norm();
540 if (distance < r_cut )
542 vd.getPropWrite<0>(p)++;
543 vd.getPropWrite<3>(p).add();
544 vd.getPropWrite<3>(p).last().xq = xq;
545 vd.getPropWrite<3>(p).last().id = vd.getPropWrite<2>(q);
556 auto NN2 = vd.getCellListSym(r_cut);
558 auto p_it2 = vd.getDomainIterator();
560 while (p_it2.isNext())
562 auto p = p_it2.
get();
566 auto Np = NN2.getNNIteratorSym<NO_CHECK>(NN2.getCell(xp),p.getKey(),vd.getPosVector());
583 float distance = f.norm();
587 if (distance < r_cut )
589 vd.getPropWrite<1>(p)++;
590 vd.getPropWrite<1>(q)++;
592 vd.getPropWrite<4>(p).add();
593 vd.getPropWrite<4>(q).add();
595 vd.getPropWrite<4>(p).last().xq = xq;
596 vd.getPropWrite<4>(q).last().xq = xp;
597 vd.getPropWrite<4>(p).last().id = vd.getProp<2>(q);
598 vd.getPropWrite<4>(q).last().id = vd.getProp<2>(p);
607 vd.ghost_put<
add_,1>();
610 auto p_it3 = vd.getDomainIterator();
613 while (p_it3.isNext())
615 auto p = p_it3.get();
617 ret &= vd.getPropRead<1>(p) == vd.getPropRead<0>(p);
619 vd.getPropWrite<3>(p).sort();
620 vd.getPropWrite<4>(p).sort();
622 ret &= vd.getPropRead<3>(p).size() == vd.getPropRead<4>(p).size();
624 for (
size_t i = 0 ; i < vd.getPropRead<3>(p).size() ; i++)
625 ret &= vd.getPropRead<3>(p).get(i).id == vd.getPropRead<4>(p).get(i).id;
629 std::cout << vd.getPropRead<3>(p).size() <<
" " << vd.getPropRead<4>(p).size() << std::endl;
631 for (
size_t i = 0 ; i < vd.getPropRead<3>(p).size() ; i++)
632 std::cout << vd.getPropRead<3>(p).get(i).id <<
" " << vd.getPropRead<4>(p).get(i).id << std::endl;
634 std::cout << vd.getPropRead<1>(p) <<
" A " << vd.getPropRead<0>(p) << std::endl;
642 BOOST_REQUIRE_EQUAL(ret,
true);
645BOOST_AUTO_TEST_CASE( vector_dist_symmetric_crs_cell_list )
657 std::uniform_real_distribution<float> ud(-L,L);
661 long int big_step = k / 4;
662 big_step = (big_step == 0)?1:big_step;
664 print_test_v(
"Testing 3D periodic vector symmetric crs cell-list k=",k);
665 BOOST_TEST_CHECKPOINT(
"Testing 3D periodic vector symmetric crs cell-list k=" << k );
670 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
677 ghost2.setLow(0,0.0);
678 ghost2.setLow(1,0.0);
679 ghost2.setLow(2,0.0);
689 return (
id < pag.id);
698 size_t start = vd.init_size_accum(k);
700 auto it = vd.getIterator();
706 vd.getPosWrite(key)[0] = ud(eg);
707 vd.getPosWrite(key)[1] = ud(eg);
708 vd.getPosWrite(key)[2] = ud(eg);
710 vd2.getPosWrite(key)[0] = vd.getPosRead(key)[0];
711 vd2.getPosWrite(key)[1] = vd.getPosRead(key)[1];
712 vd2.getPosWrite(key)[2] = vd.getPosRead(key)[2];
716 vd.getPropWrite<0>(key) = 0;
717 vd.getPropWrite<1>(key) = 0;
718 vd.getPropWrite<2>(key) = key.
getKey() + start;
720 vd2.getPropWrite<0>(key) = 0;
721 vd2.getPropWrite<1>(key) = 0;
722 vd2.getPropWrite<2>(key) = key.
getKey() + start;
732 vd2.ghost_get<0,2>();
734 auto NN = vd.getCellList(r_cut);
735 auto p_it = vd.getDomainIterator();
737 while (p_it.isNext())
743 auto Np = NN.getNNIterator(NN.getCell(xp));
760 float distance = f.norm();
764 if (distance < r_cut )
766 vd.getPropWrite<0>(p)++;
767 vd.getPropWrite<3>(p).add();
768 vd.getPropWrite<3>(p).last().xq = xq;
769 vd.getPropWrite<3>(p).last().id = vd.getPropRead<2>(q);
780 auto NN2 = vd2.getCellListSym(r_cut);
784 auto p_it2 = vd2.getParticleIteratorCRS_Cell(NN2);
787 while (p_it2.isNext())
789 auto p = p_it2.
get();
793 auto Np = p_it2.getNNIteratorCSR(vd2.getPosVector());
810 float distance = f.norm();
814 if (distance < r_cut )
816 vd2.getPropWrite<1>(p)++;
817 vd2.getPropWrite<1>(q)++;
819 vd2.getPropWrite<4>(p).add();
820 vd2.getPropWrite<4>(q).add();
822 vd2.getPropWrite<4>(p).last().xq = xq;
823 vd2.getPropWrite<4>(q).last().xq = xp;
824 vd2.getPropWrite<4>(p).last().id = vd2.getPropRead<2>(q);
825 vd2.getPropWrite<4>(q).last().id = vd2.getPropRead<2>(p);
834 vd2.ghost_put<
add_,1>(NO_CHANGE_ELEMENTS);
835 vd2.ghost_put<
merge_,4>();
838 vd2.getDomainIterator();
841 auto p_it3 = vd.getDomainIterator();
844 while (p_it3.isNext())
846 auto p = p_it3.get();
848 ret &= vd2.getPropRead<1>(p) == vd.getPropRead<0>(p);
851 vd.getPropWrite<3>(p).sort();
852 vd2.getPropWrite<4>(p).sort();
854 ret &= vd.getPropRead<3>(p).size() == vd2.getPropRead<4>(p).size();
856 for (
size_t i = 0 ; i < vd.getPropRead<3>(p).size() ; i++)
857 ret &= vd.getPropRead<3>(p).get(i).id == vd2.getPropRead<4>(p).get(i).id;
865 BOOST_REQUIRE_EQUAL(ret,
true);
868template<
typename VerletList>
869void test_vd_symmetric_verlet_list()
881 std::default_random_engine eg;
882 std::uniform_real_distribution<float> ud(-L,L);
886 long int big_step = k / 4;
887 big_step = (big_step == 0)?1:big_step;
889 print_test_v(
"Testing 3D periodic vector symmetric cell-list k=",k);
890 BOOST_TEST_CHECKPOINT(
"Testing 3D periodic vector symmetric verlet-list k=" << k );
895 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
910 return (
id < pag.id);
918 size_t start = vd.init_size_accum(k);
920 auto it = vd.getIterator();
926 vd.getPosWrite(key)[0] = ud(eg);
927 vd.getPosWrite(key)[1] = ud(eg);
928 vd.getPosWrite(key)[2] = ud(eg);
932 vd.template getPropWrite<0>(key) = 0;
933 vd.template getPropWrite<1>(key) = 0;
934 vd.template getPropWrite<2>(key) = key.
getKey() + start;
942 vd.template ghost_get<0,2>();
944 auto NN = vd.template getVerlet<VerletList>(r_cut);
945 auto p_it = vd.getDomainIterator();
947 while (p_it.isNext())
953 auto Np = NN.getNNIterator(p.getKey());
970 float distance = f.norm();
974 if (distance < r_cut )
976 vd.template getPropWrite<0>(p)++;
977 vd.template getPropWrite<3>(p).add();
978 vd.template getPropWrite<3>(p).last().xq = xq;
979 vd.template getPropWrite<3>(p).last().id = vd.template getPropRead<2>(q);
990 auto NN2 = vd.template getVerletSym<VerletList>(r_cut);
992 auto p_it2 = vd.getDomainIterator();
994 while (p_it2.isNext())
996 auto p = p_it2.get();
1000 auto Np = NN2.template getNNIterator<NO_CHECK>(p.getKey());
1006 if (p.getKey() == q)
1017 float distance = f.norm();
1021 if (distance < r_cut )
1023 vd.template getPropWrite<1>(p)++;
1024 vd.template getPropWrite<1>(q)++;
1026 vd.template getPropWrite<4>(p).add();
1027 vd.template getPropWrite<4>(q).add();
1029 vd.template getPropWrite<4>(p).last().xq = xq;
1030 vd.template getPropWrite<4>(q).last().xq = xp;
1031 vd.template getPropWrite<4>(p).last().id = vd.template getPropRead<2>(q);
1032 vd.template getPropWrite<4>(q).last().id = vd.template getPropRead<2>(p);
1041 vd.template ghost_put<add_,1>();
1042 vd.template ghost_put<merge_,4>();
1044 auto p_it3 = vd.getDomainIterator();
1047 while (p_it3.isNext())
1049 auto p = p_it3.get();
1051 ret &= vd.template getPropRead<1>(p) == vd.template getPropRead<0>(p);
1053 vd.template getPropWrite<3>(p).sort();
1054 vd.template getPropWrite<4>(p).sort();
1056 ret &= vd.template getPropRead<3>(p).size() == vd.template getPropRead<4>(p).size();
1058 for (
size_t i = 0 ; i < vd.template getPropRead<3>(p).size() ; i++)
1059 ret &= vd.template getPropRead<3>(p).get(i).id == vd.template getPropRead<4>(p).get(i).id;
1067 BOOST_REQUIRE_EQUAL(ret,
true);
1070BOOST_AUTO_TEST_CASE( vector_dist_symmetric_verlet_list )
1072 test_vd_symmetric_verlet_list<VERLET_MEMFAST(3,float)>();
1073 test_vd_symmetric_verlet_list<VERLET_MEMBAL(3,float)>();
1074 test_vd_symmetric_verlet_list<VERLET_MEMMW(3,float)>();
1077template<
typename VerletList>
1078void vector_sym_verlet_list_nb()
1090 std::default_random_engine eg;
1091 std::uniform_real_distribution<float> ud(-L,L);
1095 long int big_step = k / 4;
1096 big_step = (big_step == 0)?1:big_step;
1098 print_test_v(
"Testing 3D periodic vector symmetric cell-list no bottom k=",k);
1099 BOOST_TEST_CHECKPOINT(
"Testing 3D periodic vector symmetric cell-list no bottom k=" << k );
1104 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
1106 float r_cut = 100.0;
1111 ghost2.setLow(2,0.0);
1121 return (
id < pag.id);
1128 for (
size_t s = 0 ; s < 8 ; s++)
1134 size_t start = vd.init_size_accum(k);
1136 auto it = vd.getIterator();
1140 auto key = it.get();
1142 vd.getPosWrite(key)[0] = ud(eg);
1143 vd.getPosWrite(key)[1] = ud(eg);
1144 vd.getPosWrite(key)[2] = ud(eg);
1146 vd2.getPosWrite(key)[0] = vd.getPosRead(key)[0];
1147 vd2.getPosWrite(key)[1] = vd.getPosRead(key)[1];
1148 vd2.getPosWrite(key)[2] = vd.getPosRead(key)[2];
1152 vd.template getPropWrite<0>(key) = 0;
1153 vd.template getPropWrite<1>(key) = 0;
1154 vd.template getPropWrite<2>(key) = key.
getKey() + start;
1156 vd2.template getPropWrite<0>(key) = 0;
1157 vd2.template getPropWrite<1>(key) = 0;
1158 vd2.template getPropWrite<2>(key) = key.
getKey() + start;
1167 vd.template ghost_get<0,2>();
1168 vd2.template ghost_get<0,2>();
1170 auto NN = vd.template getVerlet<VerletList>(r_cut);
1171 auto p_it = vd.getDomainIterator();
1173 while (p_it.isNext())
1175 auto p = p_it.get();
1179 auto Np = NN.getNNIterator(p.getKey());
1185 if (p.getKey() == q)
1196 float distance = f.norm();
1200 if (distance < r_cut )
1202 vd.template getPropWrite<0>(p)++;
1203 vd.template getPropWrite<3>(p).add();
1204 vd.template getPropWrite<3>(p).last().xq = xq;
1205 vd.template getPropWrite<3>(p).last().id = vd.template getPropRead<2>(q);
1216 auto NN2 = vd2.template getVerletSym<VerletList>(r_cut);
1218 auto p_it2 = vd2.getDomainIterator();
1220 while (p_it2.isNext())
1222 auto p = p_it2.get();
1226 auto Np = NN2.template getNNIterator<NO_CHECK>(p.getKey());
1232 if (p.getKey() == q)
1243 float distance = f.norm();
1247 if (distance < r_cut )
1249 vd2.template getPropWrite<1>(p)++;
1250 vd2.template getPropWrite<1>(q)++;
1252 vd2.template getPropWrite<4>(p).add();
1253 vd2.template getPropWrite<4>(q).add();
1255 vd2.template getPropWrite<4>(p).last().xq = xq;
1256 vd2.template getPropWrite<4>(q).last().xq = xp;
1257 vd2.template getPropWrite<4>(p).last().id = vd2.template getPropRead<2>(q);
1258 vd2.template getPropWrite<4>(q).last().id = vd2.template getPropRead<2>(p);
1268 vd2.template ghost_put<add_,1>();
1269 vd2.template ghost_put<merge_,4>();
1272 vd2.getDomainIterator();
1275 auto p_it3 = vd.getDomainIterator();
1278 while (p_it3.isNext())
1280 auto p = p_it3.get();
1282 ret &= vd2.template getPropRead<1>(p) == vd.template getPropRead<0>(p);
1284 vd.template getPropWrite<3>(p).sort();
1285 vd2.template getPropWrite<4>(p).sort();
1287 ret &= vd.template getPropRead<3>(p).size() == vd2.template getPropRead<4>(p).size();
1289 for (
size_t i = 0 ; i < vd.template getPropRead<3>(p).size() ; i++)
1290 ret &= vd.template getPropRead<3>(p).get(i).id == vd2.template getPropRead<4>(p).get(i).id;
1298 BOOST_REQUIRE_EQUAL(ret,
true);
1302BOOST_AUTO_TEST_CASE( vector_dist_symmetric_verlet_list_no_bottom )
1304 vector_sym_verlet_list_nb<VERLET_MEMFAST(3,float)>();
1305 vector_sym_verlet_list_nb<VERLET_MEMBAL(3,float)>();
1306 vector_sym_verlet_list_nb<VERLET_MEMMW(3,float)>();
1308 vector_sym_verlet_list_nb<VERLET_MEMFAST_INT(3,float)>();
1309 vector_sym_verlet_list_nb<VERLET_MEMBAL_INT(3,float)>();
1310 vector_sym_verlet_list_nb<VERLET_MEMMW_INT(3,float)>();
1315 std::default_random_engine & eg,
1316 std::uniform_real_distribution<float> & ud,
1324 auto key = it.get();
1336 vd.template getPropWrite<0>(key) = 0;
1337 vd.template getPropWrite<1>(key) = 0;
1338 vd.template getPropWrite<2>(key) = key.
getKey() + start;
1340 vd2.template getPropWrite<0>(key) = 0;
1341 vd2.template getPropWrite<1>(key) = 0;
1342 vd2.template getPropWrite<2>(key) = key.
getKey() + start;
1351 vd.template ghost_get<0,2>();
1352 vd2.template ghost_get<0,2>();
1354 auto NN = vd.template getVerlet<VerletList>(r_cut);
1357 while (p_it.isNext())
1359 auto p = p_it.
get();
1363 auto Np = NN.getNNIterator(p.getKey());
1369 if (p.getKey() == q)
1380 float distance = f.norm();
1384 if (distance < r_cut )
1386 vd.template getPropWrite<0>(p)++;
1387 vd.template getPropWrite<3>(p).
add();
1388 vd.template getPropWrite<3>(p).last().xq = xq;
1389 vd.template getPropWrite<3>(p).last().id = vd.template getPropRead<2>(q);
1400 auto NN2 = vd2.template getVerletCrs<VerletList>(r_cut);
1405 while (p_it2.isNext())
1407 auto p = p_it2.get();
1411 auto Np = NN2.template getNNIterator<NO_CHECK>(p);
1428 float distance = f.norm();
1430 if (distance < r_cut )
1432 vd2.template getPropWrite<1>(p)++;
1433 vd2.template getPropWrite<1>(q)++;
1435 vd2.template getPropWrite<4>(p).
add();
1436 vd2.template getPropWrite<4>(q).
add();
1438 vd2.template getPropWrite<4>(p).last().xq = xq;
1439 vd2.template getPropWrite<4>(q).last().xq = xp;
1440 vd2.template getPropWrite<4>(p).last().id = vd2.template getPropRead<2>(q);
1441 vd2.template getPropWrite<4>(q).last().id = vd2.template getPropRead<2>(p);
1450 vd2.template ghost_put<add_,1>();
1451 vd2.template ghost_put<merge_,4>();
1460 while (p_it3.isNext())
1462 auto p = p_it3.get();
1464 ret &= vd2.template getPropRead<1>(p) == vd.template getPropRead<0>(p);
1469 std::cout <<
"ERROR " << vd2.template getPropWrite<1>(p) <<
" " << vd.template getPropWrite<0>(p) <<
" " << xp.
toString() << std::endl;
1472 vd.template getPropWrite<3>(p).sort();
1473 vd2.template getPropWrite<4>(p).sort();
1475 ret &= vd.template getPropRead<3>(p).size() == vd2.template getPropRead<4>(p).size();
1477 for (
size_t i = 0 ; i < vd.template getPropRead<3>(p).size() ; i++)
1478 ret &= vd.template getPropRead<3>(p).get(i).id == vd2.template getPropRead<4>(p).get(i).id;
1486 BOOST_REQUIRE_EQUAL(ret,
true);
1489template<
typename VerletList>
1490void test_csr_verlet_list()
1502 std::default_random_engine eg;
1503 std::uniform_real_distribution<float> ud(-L,L);
1507 long int big_step = k / 4;
1508 big_step = (big_step == 0)?1:big_step;
1510 print_test_v(
"Testing 3D periodic vector symmetric cell-list k=",k);
1511 BOOST_TEST_CHECKPOINT(
"Testing 3D periodic vector symmetric cell-list k=" << k );
1516 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
1518 float r_cut = 100.0;
1523 ghost2.setLow(0,0.0);
1524 ghost2.setLow(1,0.0);
1525 ghost2.setLow(2,0.0);
1535 return (
id < pag.id);
1546 test_crs_full<VerletList>(vd,vd2,eg,ud,start,r_cut);
1549template<
typename VerletList>
1550void test_csr_verlet_list_override()
1562 std::default_random_engine eg;
1563 std::uniform_real_distribution<float> ud(-L,L);
1567 long int big_step = k / 4;
1568 big_step = (big_step == 0)?1:big_step;
1570 print_test_v(
"Testing 3D periodic vector symmetric cell-list k=",k);
1571 BOOST_TEST_CHECKPOINT(
"Testing 3D periodic vector symmetric cell-list k=" << k );
1576 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
1578 float r_cut = 100.0;
1583 ghost2.setLow(0,0.0);
1584 ghost2.setLow(1,0.0);
1585 ghost2.setLow(2,0.0);
1595 return (
id < pag.id);
1620 test_crs_full<VerletList>(vd,vd2,eg,ud,start,r_cut);
1623BOOST_AUTO_TEST_CASE( vector_dist_symmetric_crs_verlet_list )
1625 test_csr_verlet_list<VERLET_MEMFAST(3,float)>();
1626 test_csr_verlet_list<VERLET_MEMBAL(3,float)>();
1627 test_csr_verlet_list<VERLET_MEMMW(3,float)>();
1630BOOST_AUTO_TEST_CASE( vector_dist_symmetric_crs_verlet_list_dec_override )
1632 test_csr_verlet_list_override<VERLET_MEMFAST(3,float)>();
1633 test_csr_verlet_list_override<VERLET_MEMBAL(3,float)>();
1634 test_csr_verlet_list_override<VERLET_MEMMW(3,float)>();
1637template <
typename VerletList>
1638void test_vd_symmetric_crs_verlet()
1652 std::default_random_engine eg;
1653 std::uniform_real_distribution<float> ud(-L,L);
1657 long int big_step = k / 4;
1658 big_step = (big_step == 0)?1:big_step;
1660 print_test_v(
"Testing 3D periodic vector symmetric cell-list k=",k);
1661 BOOST_TEST_CHECKPOINT(
"Testing 3D periodic vector symmetric cell-list k=" << k );
1666 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
1668 float r_cut = 100.0;
1673 ghost2.setLow(0,0.0);
1674 ghost2.setLow(1,0.0);
1675 ghost2.setLow(2,0.0);
1687 auto key = it.get();
1689 vd.
getPos(key)[0] = ud(eg);
1690 vd.
getPos(key)[1] = ud(eg);
1691 vd.
getPos(key)[2] = ud(eg);
1707 auto NN2 = vd.template getVerletCrs<VerletList>(r_cut);
1713 while (p_it2.isNext())
1715 auto p = p_it2.get();
1716 auto p2 = p_it3.get();
1727 BOOST_REQUIRE_EQUAL(ret,
true);
1730BOOST_AUTO_TEST_CASE( vector_dist_symmetric_crs_verlet_list_partit )
1732 test_vd_symmetric_crs_verlet<VERLET_MEMFAST(3,float)>();
1733 test_vd_symmetric_crs_verlet<VERLET_MEMBAL(3,float)>();
1734 test_vd_symmetric_crs_verlet<VERLET_MEMMW(3,float)>();
1737BOOST_AUTO_TEST_CASE( vector_dist_checking_unloaded_processors )
1749 std::default_random_engine eg;
1750 std::uniform_real_distribution<float> ud(0,L);
1754 long int big_step = k / 4;
1755 big_step = (big_step == 0)?1:big_step;
1757 print_test_v(
"Testing 3D periodic vector symmetric cell-list (unload processors) k=",k);
1758 BOOST_TEST_CHECKPOINT(
"Testing 3D periodic vector symmetric cell-list (unload processors) k=" << k );
1763 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
1765 float r_cut = 100.0;
1770 ghost2.setLow(0,0.0);
1771 ghost2.setLow(1,0.0);
1772 ghost2.setLow(2,0.0);
1784 auto key = it.get();
1786 vd.
getPos(key)[0] = ud(eg);
1787 vd.
getPos(key)[1] = ud(eg);
1788 vd.
getPos(key)[2] = ud(eg);
1807 BOOST_REQUIRE_EQUAL(min,0ul);
1822 BOOST_REQUIRE_EQUAL(min,0ul);
1826BOOST_AUTO_TEST_CASE( vector_dist_cell_list_multi_type )
1838 std::default_random_engine eg;
1839 std::uniform_real_distribution<float> ud(-L,L);
1843 long int big_step = k / 4;
1844 big_step = (big_step == 0)?1:big_step;
1846 print_test_v(
"Testing 3D periodic vector symmetric cell-list k=",k);
1847 BOOST_TEST_CHECKPOINT(
"Testing 3D periodic vector symmetric cell-list k=" << k );
1852 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
1854 float r_cut = 100.0;
1868 auto key = it.get();
1870 vd.
getPos(key)[0] = ud(eg);
1871 vd.
getPos(key)[1] = ud(eg);
1872 vd.
getPos(key)[2] = ud(eg);
1886 auto NN = vd.
getCellList<CELL_MEMFAST(3,
float)>(r_cut);
1887 auto NN2 = vd.
getCellList<CELL_MEMBAL(3,
float)>(r_cut);
1888 auto NN3 = vd.
getCellList<CELL_MEMMW(3,
float)>(r_cut);
1892 while (p_it.isNext())
1894 auto p = p_it.
get();
1898 auto Np = NN.getNNIterator(NN.getCell(xp));
1899 auto Np2 = NN2.getNNIterator(NN2.getCell(xp));
1900 auto Np3 = NN3.getNNIterator(NN3.getCell(xp));
1906 ret &= (Np.isNext() == Np2.isNext()) && (Np3.isNext() == Np.isNext());
1912 auto q2 = Np2.get();
1913 auto q3 = Np3.get();
1915 ret &= (q == q2) && (q == q3);
1925 ret &= (Np.isNext() == Np2.isNext()) && (Np.isNext() == Np3.isNext());
1933 BOOST_REQUIRE_EQUAL(ret,
true);
1944 return (
id < pag.id);
1948template<
typename vector_dist_mp>
1949void test_vector_dist_particle_NN_MP_iteration()
1960 std::default_random_engine eg;
1961 eg.seed(v_cl.
rank()*4533);
1962 std::uniform_real_distribution<float> ud(-L,L);
1966 long int big_step = k / 4;
1967 big_step = (big_step == 0)?1:big_step;
1969 print_test_v(
"Testing 3D periodic vector symmetric cell-list k=",k);
1970 BOOST_TEST_CHECKPOINT(
"Testing 3D periodic vector symmetric cell-list k=" << k );
1975 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
1977 float r_cut = 100.0;
1985 vector_dist_mp vd(k,box,bc,ghost,BIND_DEC_TO_GHOST);
1992 auto key = it.get();
2000 vd.template getPropWrite<0>(key) = 0;
2001 vd.template getPropWrite<1>(key) = 0;
2002 vd.template getPropWrite<2>(key) = key.
getKey() + start;
2010 vd.template ghost_get<0,2>();
2015 while (p_it.isNext())
2017 auto p = p_it.
get();
2021 auto Np = NN.getNNIterator(NN.getCell(xp));
2027 if (p.getKey() == q)
2038 float distance = f.norm();
2042 if (distance < r_cut )
2044 vd.template getPropWrite<0>(p)++;
2045 vd.template getPropWrite<3>(p).
add();
2046 vd.template getPropWrite<3>(p).last().xq = xq;
2047 vd.template getPropWrite<3>(p).last().id = vd.template getPropWrite<2>(q);
2060 phases.add( vector_dist_mp(phases.get(0).getDecomposition(),0));
2061 phases.add( vector_dist_mp(phases.get(0).getDecomposition(),0));
2062 phases.add( vector_dist_mp(phases.get(0).getDecomposition(),0));
2066 while (it2.isNext())
2070 if (p.getKey() % 4 == 0)
2072 phases.get(0).add();
2073 phases.get(0).getLastPos()[0] = vd.
getPos(p)[0];
2074 phases.get(0).getLastPos()[1] = vd.
getPos(p)[1];
2075 phases.get(0).getLastPos()[2] = vd.
getPos(p)[2];
2077 phases.get(0).template getLastProp<1>() = 0;
2079 phases.get(0).template getLastProp<2>() = vd.template getProp<2>(p);
2081 else if (p.getKey() % 4 == 1)
2083 phases.get(1).add();
2084 phases.get(1).getLastPos()[0] = vd.
getPos(p)[0];
2085 phases.get(1).getLastPos()[1] = vd.
getPos(p)[1];
2086 phases.get(1).getLastPos()[2] = vd.
getPos(p)[2];
2088 phases.get(1).template getLastProp<1>() = 0;
2090 phases.get(1).template getLastProp<2>() = vd.template getProp<2>(p);
2092 else if (p.getKey() % 4 == 2)
2094 phases.get(2).add();
2095 phases.get(2).getLastPos()[0] = vd.
getPos(p)[0];
2096 phases.get(2).getLastPos()[1] = vd.
getPos(p)[1];
2097 phases.get(2).getLastPos()[2] = vd.
getPos(p)[2];
2099 phases.get(2).template getLastProp<1>() = 0;
2101 phases.get(2).template getLastProp<2>() = vd.template getProp<2>(p);
2105 phases.get(3).add();
2106 phases.get(3).getLastPos()[0] = vd.
getPos(p)[0];
2107 phases.get(3).getLastPos()[1] = vd.
getPos(p)[1];
2108 phases.get(3).getLastPos()[2] = vd.
getPos(p)[2];
2110 phases.get(3).template getLastProp<1>() = 0;
2112 phases.get(3).template getLastProp<2>() = vd.template getProp<2>(p);
2120 for (
size_t i = 0 ; i < phases.
size() ; i++)
2122 phases.get(i).template ghost_get<0,1,2>();
2127 for (
size_t i = 0 ; i < phases.
size() ; i++)
2129 NN_ptr.add(phases.get(i).getCellListSym(r_cut));
2134 for (
size_t i = 0 ; i < phases.
size() ; i++)
2136 for (
size_t j = 0 ; j < phases.
size() ; j++)
2138 auto p_it2 = phases.get(i).getDomainIterator();
2140 while (p_it2.isNext())
2142 auto p = p_it2.get();
2146 auto Np = NN_ptr.get(j).getNNIteratorSymMP<NO_CHECK>(NN_ptr.get(j).getCell(xp),p.getKey(),phases.get(i).getPosVector(),phases.get(j).getPosVector());
2152 if (p.getKey() == q && i == j)
2163 float distance = f.norm();
2167 if (distance < r_cut )
2169 phases.get(i).template getPropWrite<1>(p)++;
2170 phases.get(j).template getPropWrite<1>(q)++;
2172 phases.get(i).template getPropWrite<4>(p).add();
2173 phases.get(j).template getPropWrite<4>(q).add();
2175 phases.get(i).template getPropWrite<4>(p).last().xq = xq;
2176 phases.get(j).template getPropWrite<4>(q).last().xq = xp;
2177 phases.get(i).template getPropWrite<4>(p).last().id = phases.get(j).template getProp<2>(q);
2178 phases.get(j).template getPropWrite<4>(q).last().id = phases.get(i).template getProp<2>(p);
2189 for (
size_t i = 0 ; i < phases.
size() ; i++)
2191 phases.get(i).template ghost_put<add_,1>();
2192 phases.get(i).template ghost_put<merge_,4>();
2198 while (p_it3.isNext())
2200 auto p = p_it3.get();
2204 if (p.getKey() % 4 == 0)
2206 else if (p.getKey() % 4 == 1)
2208 else if (p.getKey() % 4 == 2)
2213 size_t pah = p.getKey()/4;
2214 ret &= phases.get(ph).template getPropRead<1>(pah) == vd.template getPropRead<0>(p);
2216 vd.template getPropWrite<3>(p).sort();
2217 phases.get(ph).template getPropWrite<4>(pah).sort();
2219 ret &= vd.template getPropRead<3>(p).size() == phases.get(ph).template getPropRead<4>(pah).
size();
2221 for (
size_t i = 0 ; i < vd.template getPropRead<3>(p).size() ; i++)
2222 ret &= vd.template getPropRead<3>(p).get(i).id == phases.get(ph).template getPropRead<4>(pah).get(i).id;
2226 std::cout <<
"Error on particle: " << vd.template getPropRead<2>(p) <<
" " << v_cl.
rank() << std::endl;
2228 std::cout << vd.template getPropRead<3>(p).size() <<
" " << phases.get(ph).template getPropRead<4>(pah).
size() <<
" " << v_cl.
rank() << std::endl;
2230 for (
size_t i = 0 ; i < vd.template getPropRead<3>(p).size() ; i++)
2231 std::cout << vd.template getPropRead<3>(p).get(i).id <<
" " << phases.get(ph).template getPropRead<4>(pah).get(i).id <<
" " << v_cl.
rank() << std::endl;
2233 std::cout << phases.get(ph).template getPropRead<1>(pah) <<
" A " << vd.template getPropRead<0>(p) << std::endl;
2241 BOOST_REQUIRE_EQUAL(ret,
true);
2244BOOST_AUTO_TEST_CASE( vector_dist_particle_NN_MP_iteration )
2248 test_vector_dist_particle_NN_MP_iteration<vector_dist<3,float, part_prop >>();
2251BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
This class implement the point shape in an N-dimensional space.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
std::string toString() const
Return the string with the point coordinate.
void execute()
Execute all the requests.
size_t rank()
Get the process unit id.
size_t getProcessUnitID()
Get the process unit id.
void min(T &num)
Get the minimum number across all processors (or reduction with insinity norm)
size_t getProcessingUnits()
Get the total number of processors.
Implementation of VCluster class.
Implementation of 1-D std::vector like structure.
Grid key for a distributed grid.
__device__ __host__ size_t getKey() const
Get the key.
vect_dist_key_dx get()
Get the actual key.
size_t size_local() const
return the local size of the vector
auto getProp(vect_dist_key_dx vec_key) -> decltype(v_prp.template get< id >(vec_key.getKey()))
Get the property of an element.
auto getPosRead(vect_dist_key_dx vec_key) const -> decltype(v_pos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
size_t init_size_accum(size_t np)
It return the number of particles contained by the previous processors.
size_t size_local_with_ghost() const
return the local size of the vector
openfpm::vector_key_iterator_seq< typename vrl::Mem_type_type::local_index_type > getParticleIteratorCRS(vrl &NN)
Get a special particle iterator able to iterate across particles using symmetric crossing scheme.
auto getPos(vect_dist_key_dx vec_key) -> decltype(v_pos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
ParticleItCRS_Cells< dim, cli, decltype(v_pos)> getParticleIteratorCRS_Cell(cli &NN)
Get a special particle iterator able to iterate across particles using symmetric crossing scheme.
CellL getCellList(St r_cut, bool no_se3=false)
Construct a cell list starting from the stored particles.
vector_dist_iterator getDomainIterator() const
Get an iterator that traverse the particles in the domain.
void ghost_get(size_t opt=WITH_POSITION)
It synchronize the properties and position of the ghost particles.
void map(size_t opt=NONE)
It move all the particles that does not belong to the local processor to the respective processor.
vector_dist_iterator getIterator()
Get an iterator that traverse domain and ghost particles.
auto getPosWrite(vect_dist_key_dx vec_key) -> decltype(v_pos.template get< 0 >(vec_key.getKey()))
Get the position of an element.
void add()
Add local particle.
Decomposition & getDecomposition()
Get the decomposition.
This structure define the operation add to use with copy general.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
This structure define the operation add to use with copy general.