8 #ifndef OPENFPM_NUMERICS_SRC_INTERPOLATION_INTERPOLATION_UNIT_TESTS_HPP_
9 #define OPENFPM_NUMERICS_SRC_INTERPOLATION_INTERPOLATION_UNIT_TESTS_HPP_
11 #include "interpolation/mp4_kernel.hpp"
12 #include "interpolation/z_spline.hpp"
13 #include "interpolation.hpp"
15 BOOST_AUTO_TEST_SUITE( interpolation_test )
17 template<typename
grid,
unsigned int mom_p>
void momenta_grid(grid & gd,typename grid::stype (& mom_tot)[grid::dims])
19 auto it = gd.getDomainGhostIterator();
21 for (
size_t i = 0 ; i < grid::dims ; i++)
27 auto key_g = gd.getGKey(
key);
29 for (
size_t i = 0 ; i < grid::dims ; i++)
31 typename grid::stype coord = gd.spacing(i)*key_g.get(i);
33 mom_tot[i] += boost::math::pow<mom_p>(coord)*gd.template getProp<0>(
key);
40 template<
typename gr
id,
unsigned int mom_p>
void momenta_grid_domain(grid & gd,
typename grid::stype (& mom_tot)[grid::dims])
42 auto it = gd.getDomainIterator();
44 for (
size_t i = 0 ; i < grid::dims ; i++)
50 auto key_g = gd.getGKey(
key);
52 for (
size_t i = 0 ; i < grid::dims ; i++)
54 typename grid::stype coord = gd.spacing(i)*key_g.get(i);
56 mom_tot[i] += boost::math::pow<mom_p>(coord)*gd.template getProp<0>(
key);
63 template<
typename vector,
unsigned int mom_p>
void momenta_vector(vector & vd,
typename vector::stype (& mom_tot)[vector::dims])
65 auto it = vd.getDomainIterator();
67 for (
size_t i = 0 ; i < vector::dims ; i++)
74 for (
size_t i = 0 ; i < vector::dims ; i++)
76 typename vector::stype coord = vd.getPos(
key)[i];
78 mom_tot[i] += boost::math::pow<mom_p>(coord)*vd.template getProp<0>(
key);
85 template<
unsigned int dim,
typename T,
typename gr
id,
typename vector>
86 void interp_test(grid & gd, vector & vd,
bool single_particle)
90 auto it2 = gd.getDomainGhostIterator();
96 gd.template get<0>(
key) = 0.0;
103 if (single_particle ==
false)
104 {inte.template p2m<0,0>(vd,gd);}
107 auto it = vd.getDomainIterator();
113 inte.template p2m<0,0>(vd,gd,p);
122 momenta_grid<grid,0>(gd,mg);
123 momenta_vector<vector,0>(vd,mv);
125 for (
size_t i = 0 ; i < dim ; i++)
126 {BOOST_REQUIRE_CLOSE(mg[i],mv[i],0.001);}
128 momenta_grid<grid,1>(gd,mg);
129 momenta_vector<vector,1>(vd,mv);
131 for (
size_t i = 0 ; i < dim ; i++)
132 {BOOST_REQUIRE_CLOSE(mg[i],mv[i],0.001);}
134 momenta_grid<grid,2>(gd,mg);
135 momenta_vector<vector,2>(vd,mv);
137 for (
size_t i = 0 ; i < dim ; i++)
138 {BOOST_REQUIRE_CLOSE(mg[i],mv[i],0.001);}
141 BOOST_AUTO_TEST_CASE( interpolation_full_single_test_2D )
144 size_t sz[2] = {64,64};
149 size_t bc_v[2] = {PERIODIC,PERIODIC};
162 vd.getPos(p)[0] = (double)rand()/RAND_MAX;
163 vd.getPos(p)[1] = (double)rand()/RAND_MAX;
165 vd.getProp<0>(p) = 5.0;
172 interp_test<2,float>(gd,vd,
true);
176 BOOST_AUTO_TEST_CASE( interpolation_full_test_2D )
179 size_t sz[2] = {64,64};
184 size_t bc_v[2] = {PERIODIC,PERIODIC};
198 vd.getPos(p)[0] = (double)rand()/RAND_MAX;
199 vd.getPos(p)[1] = (double)rand()/RAND_MAX;
201 vd.getProp<0>(p) = 5.0;
209 interp_test<2,float>(gd,vd,
false);
214 auto & v_cl = create_vcluster();
224 auto it4 = vd.getGridIterator(sz);
228 auto key = it4.get();
232 vd.getLastPos()[0] =
key.get(0) * it4.getSpacing(0) + domain.getLow(0) + 0.1*it4.getSpacing(0);
233 vd.getLastPos()[1] =
key.get(1) * it4.getSpacing(1) + domain.getLow(1) + 0.1*it4.getSpacing(1);
235 vd.getLastProp<0>() = 0.0;
242 auto it5 = gd.getDomainGhostIterator();
246 auto key = it5.get();
248 gd.get<0>(
key) = 0.0;
255 grid_key_dx<2> stop({(
long int)gd.size(0) - 4,(
long int)gd.size(1) - 4});
257 auto it6 = gd.getSubDomainIterator(start,stop);
262 gd.get<0>(
key) = 5.0;
270 inte.m2p<0,0>(gd,vd);
272 momenta_grid_domain<decltype(gd),0>(gd,mg);
273 momenta_vector<decltype(vd),0>(vd,mv);
281 BOOST_REQUIRE_CLOSE(mg[0],mv[0],0.001);
282 BOOST_REQUIRE_CLOSE(mg[1],mv[1],0.001);
284 momenta_grid_domain<decltype(gd),1>(gd,mg);
285 momenta_vector<decltype(vd),1>(vd,mv);
293 BOOST_REQUIRE_CLOSE(mg[0],mv[0],0.001);
294 BOOST_REQUIRE_CLOSE(mg[1],mv[1],0.001);
296 momenta_grid_domain<decltype(gd),2>(gd,mg);
297 momenta_vector<decltype(vd),2>(vd,mv);
305 BOOST_REQUIRE_CLOSE(mg[0],mv[0],0.001);
306 BOOST_REQUIRE_CLOSE(mg[1],mv[1],0.001);
311 BOOST_AUTO_TEST_CASE( interpolation_full_single_test_3D )
314 size_t sz[3] = {64,64,64};
319 size_t bc_v[3] = {PERIODIC,PERIODIC,PERIODIC};
332 vd.getPos(p)[0] = (double)rand()/RAND_MAX;
333 vd.getPos(p)[1] = (double)rand()/RAND_MAX;
334 vd.getPos(p)[2] = (double)rand()/RAND_MAX;
336 vd.getProp<0>(p) = 5.0;
344 interp_test<3,double>(gd,vd,
true);
347 BOOST_AUTO_TEST_CASE( interpolation_full_test_3D )
350 size_t sz[3] = {64,64,64};
355 size_t bc_v[3] = {PERIODIC,PERIODIC,PERIODIC};
369 vd.getPos(p)[0] = (double)rand()/RAND_MAX;
370 vd.getPos(p)[1] = (double)rand()/RAND_MAX;
371 vd.getPos(p)[2] = (double)rand()/RAND_MAX;
373 vd.getProp<0>(p) = 5.0;
383 interp_test<3,double>(gd,vd,
false);
385 auto & v_cl = create_vcluster();
396 auto it4 = vd.getGridIterator(sz);
400 auto key = it4.get();
404 vd.getLastPos()[0] =
key.get(0) * it4.getSpacing(0) + domain.getLow(0) + 0.1*it4.getSpacing(0);
405 vd.getLastPos()[1] =
key.get(1) * it4.getSpacing(1) + domain.getLow(1) + 0.1*it4.getSpacing(1);
406 vd.getLastPos()[2] =
key.get(2) * it4.getSpacing(2) + domain.getLow(2) + 0.1*it4.getSpacing(2);
408 vd.getLastProp<0>() = 0.0;
415 auto it5 = gd.getDomainGhostIterator();
419 auto key = it5.get();
421 gd.get<0>(
key) = 0.0;
428 grid_key_dx<3> stop({(
long int)gd.size(0) - 4,(
long int)gd.size(1) - 4,(
long int)gd.size(2) - 4});
430 auto it6 = gd.getSubDomainIterator(start,stop);
435 gd.get<0>(
key) = 5.0;
443 inte.m2p<0,0>(gd,vd);
445 momenta_grid_domain<decltype(gd),0>(gd,mg);
446 momenta_vector<decltype(vd),0>(vd,mv);
456 BOOST_REQUIRE_CLOSE(mg[0],mv[0],0.001);
457 BOOST_REQUIRE_CLOSE(mg[1],mv[1],0.001);
458 BOOST_REQUIRE_CLOSE(mg[2],mv[2],0.001);
460 momenta_grid_domain<decltype(gd),1>(gd,mg);
461 momenta_vector<decltype(vd),1>(vd,mv);
471 BOOST_REQUIRE_CLOSE(mg[0],mv[0],0.001);
472 BOOST_REQUIRE_CLOSE(mg[1],mv[1],0.001);
473 BOOST_REQUIRE_CLOSE(mg[2],mv[2],0.001);
475 momenta_grid_domain<decltype(gd),2>(gd,mg);
476 momenta_vector<decltype(vd),2>(vd,mv);
486 BOOST_REQUIRE_CLOSE(mg[0],mv[0],0.001);
487 BOOST_REQUIRE_CLOSE(mg[1],mv[1],0.001);
488 BOOST_REQUIRE_CLOSE(mg[2],mv[2],0.001);
493 BOOST_AUTO_TEST_CASE( int_kernel_test )
501 tot += mp4.value(-1.3f,0);
502 tot += mp4.value(-0.3f,1);
503 tot += mp4.value(0.7f,2);
504 tot += mp4.value(1.7f,3);
506 BOOST_REQUIRE_CLOSE(tot,1.0f,0.001);
512 tot += -1.3f*mp4.value(-1.3f,0);
513 tot += -0.3f*mp4.value(-0.3f,1);
514 tot += 0.7f*mp4.value(0.7f,2);
515 tot += 1.7f*mp4.value(1.7f,3);
517 BOOST_REQUIRE_SMALL(tot,0.001f);
523 tot += (1.3f)*(1.3f)*mp4.value(-1.3f,0);
524 tot += (0.3f)*(0.3f)*mp4.value(-0.3f,1);
525 tot += (0.7f)*(0.7f)*mp4.value(0.7f,2);
526 tot += (1.7f)*(1.7f)*mp4.value(1.7f,3);
528 BOOST_REQUIRE_SMALL(tot,0.001f);
537 tot += zk1.value(-0.3f,0);
538 tot += zk1.value(0.7f,1);
540 BOOST_REQUIRE_CLOSE(tot,1.0f,0.001);
552 tot += zk3.value(-2.3f,0);
553 tot += zk3.value(-1.3f,1);
554 tot += zk3.value(-0.3f,2);
555 tot += zk3.value(0.7f,3);
556 tot += zk3.value(1.7f,4);
557 tot += zk3.value(2.7f,5);
559 BOOST_REQUIRE_CLOSE(tot,1.0f,0.001);
565 tot += -2.3*zk3.value(-2.3f,0);
566 tot += -1.3*zk3.value(-1.3f,1);
567 tot += -0.3*zk3.value(-0.3f,2);
568 tot += 0.7*zk3.value(0.7f,3);
569 tot += 1.7*zk3.value(1.7f,4);
570 tot += 2.7*zk3.value(2.7f,5);
572 BOOST_REQUIRE_SMALL(tot,0.001f);
578 tot += 2.3*2.3*zk3.value(-2.3f,0);
579 tot += 1.3*1.3*zk3.value(-1.3f,1);
580 tot += 0.3*0.3*zk3.value(-0.3f,2);
581 tot += 0.7*0.7*zk3.value(0.7f,3);
582 tot += 1.7*1.7*zk3.value(1.7f,4);
583 tot += 2.7*2.7*zk3.value(2.7f,5);
585 BOOST_REQUIRE_SMALL(tot,0.001f);
591 tot += -2.3*-2.3*-2.3*zk3.value(-2.3f,0);
592 tot += -1.3*-1.3*-1.3*zk3.value(-1.3f,1);
593 tot += -0.3*-0.3*-0.3*zk3.value(-0.3f,2);
594 tot += 0.7*0.7*0.7*zk3.value(0.7f,3);
595 tot += 1.7*1.7*1.7*zk3.value(1.7f,4);
596 tot += 2.7*2.7*2.7*zk3.value(2.7f,5);
598 BOOST_REQUIRE_SMALL(tot,0.001f);
609 tot += zk4.value(-3.3f,0);
610 tot += zk4.value(-2.3f,1);
611 tot += zk4.value(-1.3f,2);
612 tot += zk4.value(-0.3f,3);
613 tot += zk4.value(0.7f,4);
614 tot += zk4.value(1.7f,5);
615 tot += zk4.value(2.7f,6);
616 tot += zk4.value(3.7f,7);
618 BOOST_REQUIRE_CLOSE(tot,1.0f,0.001);
624 tot += -3.3*zk4.value(-3.3f,0);
625 tot += -2.3*zk4.value(-2.3f,1);
626 tot += -1.3*zk4.value(-1.3f,2);
627 tot += -0.3*zk4.value(-0.3f,3);
628 tot += 0.7*zk4.value(0.7f,4);
629 tot += 1.7*zk4.value(1.7f,5);
630 tot += 2.7*zk4.value(2.7f,6);
631 tot += 3.7*zk4.value(3.7f,7);
633 BOOST_REQUIRE_SMALL(tot,0.001f);
639 tot += 3.3*3.3*zk4.value(-3.3f,0);
640 tot += 2.3*2.3*zk4.value(-2.3f,1);
641 tot += 1.3*1.3*zk4.value(-1.3f,2);
642 tot += 0.3*0.3*zk4.value(-0.3f,3);
643 tot += 0.7*0.7*zk4.value(0.7f,4);
644 tot += 1.7*1.7*zk4.value(1.7f,5);
645 tot += 2.7*2.7*zk4.value(2.7f,6);
646 tot += 3.7*3.7*zk4.value(3.7f,7);
648 BOOST_REQUIRE_SMALL(tot,0.001f);
654 tot += -3.3*-3.3*-3.3*zk4.value(-3.3f,0);
655 tot += -2.3*-2.3*-2.3*zk4.value(-2.3f,1);
656 tot += -1.3*-1.3*-1.3*zk4.value(-1.3f,2);
657 tot += -0.3*-0.3*-0.3*zk4.value(-0.3f,3);
658 tot += 0.7*0.7*0.7*zk4.value(0.7f,4);
659 tot += 1.7*1.7*1.7*zk4.value(1.7f,5);
660 tot += 2.7*2.7*2.7*zk4.value(2.7f,6);
661 tot += 3.7*3.7*3.7*zk4.value(3.7f,7);
663 BOOST_REQUIRE_SMALL(tot,0.001f);
669 tot += -3.3*-3.3*-3.3*-3.3*zk4.value(-3.3f,0);
670 tot += -2.3*-2.3*-2.3*-2.3*zk4.value(-2.3f,1);
671 tot += -1.3*-1.3*-1.3*-1.3*zk4.value(-1.3f,2);
672 tot += -0.3*-0.3*-0.3*-0.3*zk4.value(-0.3f,3);
673 tot += 0.7*0.7*0.7*0.7*zk4.value(0.7f,4);
674 tot += 1.7*1.7*1.7*1.7*zk4.value(1.7f,5);
675 tot += 2.7*2.7*2.7*2.7*zk4.value(2.7f,6);
676 tot += 3.7*3.7*3.7*3.7*zk4.value(3.7f,7);
678 BOOST_REQUIRE_SMALL(tot,0.001f);
681 BOOST_AUTO_TEST_SUITE_END()
auto get(const grid_dist_key_dx< dim > &v1) const -> typename std::add_lvalue_reference< decltype(loc_grid.get(v1.getSub()).template get< p >(v1.getKey()))>::type
Get the reference of the selected element.
grid_dist_iterator< dim, device_grid, FREE > getDomainIterator() const
It return an iterator that span the full grid domain (each processor span its local domain) ...
grid_key_dx is the key to access any element in the grid
mem_id get(size_t i) const
Get the i index.
void map()
It move all the grid parts that do not belong to the local processor to the respective processor...
This is a distributed grid.
This class represent an N-dimensional box.
This class is a trick to indicate the compiler a specific specialization pattern. ...
Main class for interpolation Particle to mest p2m and Mesh to particle m2p.