OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
interpolation_unit_tests.cpp
1 /*
2  * interpolation_unit_tests.hpp
3  *
4  * Created on: May 5, 2017
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_NUMERICS_SRC_INTERPOLATION_INTERPOLATION_UNIT_TESTS_HPP_
9 #define OPENFPM_NUMERICS_SRC_INTERPOLATION_INTERPOLATION_UNIT_TESTS_HPP_
10 
11 #define BOOST_TEST_DYN_LINK
12 #include <boost/test/unit_test.hpp>
13 
14 #include "interpolation/mp4_kernel.hpp"
15 #include "interpolation/lambda_kernel.hpp"
16 #include "interpolation/z_spline.hpp"
17 #include "interpolation.hpp"
18 #include <boost/math/special_functions/pow.hpp>
19 #include <Vector/vector_dist.hpp>
20 #include <Grid/grid_dist_id.hpp>
21 
22 BOOST_AUTO_TEST_SUITE( interpolation_test )
23 
24 template<typename grid, unsigned int mom_p> void momenta_grid(grid & gd,typename grid::stype (& mom_tot)[grid::dims])
25 {
26  auto it = gd.getDomainGhostIterator();
27 
28  for (size_t i = 0 ; i < grid::dims ; i++)
29  mom_tot[i] = 0.0;
30 
31  while (it.isNext())
32  {
33  auto key = it.get();
34  auto key_g = gd.getGKey(key);
35 
36  for (size_t i = 0 ; i < grid::dims ; i++)
37  {
38  typename grid::stype coord = gd.spacing(i)*key_g.get(i);
39 
40  mom_tot[i] += boost::math::pow<mom_p>(coord)*gd.template getProp<0>(key);
41  }
42 
43  ++it;
44  }
45 }
46 
47 template<typename grid, unsigned int mom_p> void momenta_grid_domain(grid & gd,typename grid::stype (& mom_tot)[grid::dims])
48 {
49  auto it = gd.getDomainIterator();
50 
51  for (size_t i = 0 ; i < grid::dims ; i++)
52  mom_tot[i] = 0.0;
53 
54  while (it.isNext())
55  {
56  auto key = it.get();
57  auto key_g = gd.getGKey(key);
58 
59  for (size_t i = 0 ; i < grid::dims ; i++)
60  {
61  typename grid::stype coord = gd.spacing(i)*key_g.get(i);
62 
63  mom_tot[i] += boost::math::pow<mom_p>(coord)*gd.template getProp<0>(key);
64  }
65 
66  ++it;
67  }
68 }
69 
70 template<typename vector, unsigned int mom_p> void momenta_vector(vector & vd,typename vector::stype (& mom_tot)[vector::dims])
71 {
72  auto it = vd.getDomainIterator();
73 
74  for (size_t i = 0 ; i < vector::dims ; i++)
75  mom_tot[i] = 0.0;
76 
77  while (it.isNext())
78  {
79  auto key = it.get();
80 
81  for (size_t i = 0 ; i < vector::dims ; i++)
82  {
83  typename vector::stype coord = vd.getPos(key)[i];
84 
85  mom_tot[i] += boost::math::pow<mom_p>(coord)*vd.template getProp<0>(key);
86  }
87 
88  ++it;
89  }
90 }
91 
92 template<unsigned int dim, typename T,typename Kernel, typename grid, typename vector>
93 void interp_test(grid & gd, vector & vd, bool single_particle,unsigned int numberOfMomenta)
94 {
95  // Reset the grid
96 
97  auto it2 = gd.getDomainGhostIterator();
98 
99  while (it2.isNext())
100  {
101  auto key = it2.get();
102 
103  gd.template get<0>(key) = 0.0;
104 
105  ++it2;
106  }
107 
109 
110  if (single_particle == false)
111  {inte.template p2m<0,0>(vd,gd);}
112  else
113  {
114  auto it = vd.getDomainIterator();
115 
116  while (it.isNext())
117  {
118  auto p = it.get();
119 
120  inte.template p2m<0,0>(vd,gd,p);
121 
122  ++it;
123  }
124  }
125 
126  T mg[dim];
127  T mv[dim];
128  vd.write("Particles");
129  gd.write("Grid");
130 
131  if(numberOfMomenta>=0){
132  momenta_grid<grid,0>(gd,mg);
133  momenta_vector<vector,0>(vd,mv);
134  for (size_t i = 0 ; i < dim ; i++)
135  {BOOST_REQUIRE_CLOSE(mg[i],mv[i],0.001);}
136  }
137 
138  if(numberOfMomenta>=1){
139  momenta_grid<grid,1>(gd,mg);
140  momenta_vector<vector,1>(vd,mv);
141  for (size_t i = 0 ; i < dim ; i++)
142  {BOOST_REQUIRE_CLOSE(mg[i],mv[i],0.001);}
143  }
144 
145  if(numberOfMomenta>=2){
146  momenta_grid<grid,2>(gd,mg);
147  momenta_vector<vector,2>(vd,mv);
148  for (size_t i = 0 ; i < dim ; i++)
149  {BOOST_REQUIRE_CLOSE(mg[i],mv[i],0.001);}
150  }
151 
152  if(numberOfMomenta>=3){
153  momenta_grid<grid,3>(gd,mg);
154  momenta_vector<vector,3>(vd,mv);
155  for (size_t i = 0 ; i < dim ; i++)
156  {BOOST_REQUIRE_CLOSE(mg[i],mv[i],0.001);}
157  }
158 
159  if(numberOfMomenta>=4){
160  momenta_grid<grid,4>(gd,mg);
161  momenta_vector<vector,4>(vd,mv);
162  for (size_t i = 0 ; i < dim ; i++)
163  {BOOST_REQUIRE_CLOSE(mg[i],mv[i],0.001);}
164  }
165 }
166 
167 
168 
169 BOOST_AUTO_TEST_CASE( interpolation_full_single_test_2D )
170 {
171  Box<2,float> domain({0.0,0.0},{1.0,1.0});
172  size_t sz[2] = {64,64};
173 
174  Ghost<2,long int> gg(2);
175  Ghost<2,float> gv(0.01);
176 
177  size_t bc_v[2] = {PERIODIC,PERIODIC};
178 
179  vector_dist<2,float,aggregate<float>> vd(65536,domain,bc_v,gv);
180  grid_dist_id<2,float,aggregate<float>> gd(vd.getDecomposition(),sz,gg);
181 
182  // set one particle on vd
183 
184  auto it = vd.getDomainIterator();
185 
186  while (it.isNext())
187  {
188  auto p = it.get();
189 
190  vd.getPos(p)[0] = (double)rand()/RAND_MAX;
191  vd.getPos(p)[1] = (double)rand()/RAND_MAX;
192 
193  vd.getProp<0>(p) = 5.0;
194 
195  ++it;
196  }
197 
198  vd.map();
199 
200  interp_test<2,float,mp4_kernel<float>>(gd,vd,true,2);
201 }
202  BOOST_AUTO_TEST_CASE( interpolation_full_single_test_2D_double )
203  {
204  Box<2,double> domain({0.0,0.0},{1.0,1.0});
205  size_t sz[2] = {64,64};
206 
207  Ghost<2,long int> gg(3);
208  Ghost<2,double> gv(0.01);
209 
210  size_t bc_v[2] = {PERIODIC,PERIODIC};
211 
212  vector_dist<2,double,aggregate<double>> vd(65536,domain,bc_v,gv);
213  grid_dist_id<2,double,aggregate<double>> gd(vd.getDecomposition(),sz,gg);
214 
215  // set one particle on vd
216 
217  auto it = vd.getDomainIterator();
218 
219  while (it.isNext())
220  {
221  auto p = it.get();
222 
223  vd.getPos(p)[0] = (double)rand()/RAND_MAX;
224  vd.getPos(p)[1] = (double)rand()/RAND_MAX;
225 
226  vd.getProp<0>(p) = 5.0;
227 
228  ++it;
229  }
230 
231  vd.map();
232 
233  interp_test<2,double,lambda4_4kernel<double>>(gd,vd,true,2);
234  }
235 
236 
237 BOOST_AUTO_TEST_CASE( interpolation_full_test_2D )
238 {
239  Box<2,float> domain({0.0,0.0},{1.0,1.0});
240  size_t sz[2] = {64,64};
241 
242  Ghost<2,long int> gg(3);
243  Ghost<2,float> gv(0.01);
244 
245  size_t bc_v[2] = {PERIODIC,PERIODIC};
246 
247  {
248  vector_dist<2,float,aggregate<float>> vd(4096,domain,bc_v,gv);
249  grid_dist_id<2,float,aggregate<float>> gd(vd.getDecomposition(),sz,gg);
250 
251  // set one particle on vd
252 
253  auto it = vd.getDomainIterator();
254 
255  while (it.isNext())
256  {
257  auto p = it.get();
258 
259  vd.getPos(p)[0] = (double)rand()/RAND_MAX;
260  vd.getPos(p)[1] = (double)rand()/RAND_MAX;
261 
262  vd.getProp<0>(p) = 5.0;
263 
264  ++it;
265  }
266 
267  vd.map();
268 
269  // Reset the grid
270  interp_test<2,float,mp4_kernel<float>>(gd,vd,false,2);
271 
272  float mg[2];
273  float mv[2];
274 
275  auto & v_cl = create_vcluster();
276 
277  interpolate<decltype(vd),decltype(gd),mp4_kernel<float>> inte(vd,gd);
278 
279  // We have to do a ghost get before interpolating m2p
280  // Before doing mesh to particle particle must be arranged
281  // into a grid like
282 
283  vd.clear();
284 
285  auto it4 = vd.getGridIterator(sz);
286 
287  while(it4.isNext())
288  {
289  auto key = it4.get();
290 
291  vd.add();
292 
293  vd.getLastPos()[0] = key.get(0) * it4.getSpacing(0) + domain.getLow(0) + 0.1*it4.getSpacing(0);
294  vd.getLastPos()[1] = key.get(1) * it4.getSpacing(1) + domain.getLow(1) + 0.1*it4.getSpacing(1);
295 
296  vd.getLastProp<0>() = 0.0;
297 
298  ++it4;
299  }
300 
301  // Reset also the grid
302 
303  auto it5 = gd.getDomainGhostIterator();
304 
305  while(it5.isNext())
306  {
307  auto key = it5.get();
308 
309  gd.get<0>(key) = 0.0;
310 
311  ++it5;
312  }
313  gd.ghost_get<0>();
314 
315  grid_key_dx<2> start({3,3});
316  grid_key_dx<2> stop({(long int)gd.size(0) - 4,(long int)gd.size(1) - 4});
317 
318  auto it6 = gd.getSubDomainIterator(start,stop);
319  while(it6.isNext())
320  {
321  auto key = it6.get();
322 
323  gd.get<0>(key) = 5.0/*(double)rand()/RAND_MAX;*/;
324 
325  ++it6;
326  }
327  gd.ghost_get<0>();
328 
329  vd.map();
330  gd.ghost_get<0>();
331  inte.m2p<0,0>(gd,vd);
332 
333  momenta_grid_domain<decltype(gd),0>(gd,mg);
334  momenta_vector<decltype(vd),0>(vd,mv);
335 
336  v_cl.sum(mg[0]);
337  v_cl.sum(mg[1]);
338  v_cl.sum(mv[0]);
339  v_cl.sum(mv[1]);
340  v_cl.execute();
341 
342  BOOST_REQUIRE_CLOSE(mg[0],mv[0],0.001);
343  BOOST_REQUIRE_CLOSE(mg[1],mv[1],0.001);
344 
345  momenta_grid_domain<decltype(gd),1>(gd,mg);
346  momenta_vector<decltype(vd),1>(vd,mv);
347 
348  v_cl.sum(mg[0]);
349  v_cl.sum(mg[1]);
350  v_cl.sum(mv[0]);
351  v_cl.sum(mv[1]);
352  v_cl.execute();
353 
354  BOOST_REQUIRE_CLOSE(mg[0],mv[0],0.001);
355  BOOST_REQUIRE_CLOSE(mg[1],mv[1],0.001);
356 
357  momenta_grid_domain<decltype(gd),2>(gd,mg);
358  momenta_vector<decltype(vd),2>(vd,mv);
359 
360  v_cl.sum(mg[0]);
361  v_cl.sum(mg[1]);
362  v_cl.sum(mv[0]);
363  v_cl.sum(mv[1]);
364  v_cl.execute();
365 
366  BOOST_REQUIRE_CLOSE(mg[0],mv[0],0.001);
367  BOOST_REQUIRE_CLOSE(mg[1],mv[1],0.001);
368 
369  }
370 }
371 
372 BOOST_AUTO_TEST_CASE( interpolation_full_single_test_3D )
373 {
374  Box<3,double> domain({0.0,0.0,0.0},{1.0,1.0,1.0});
375  size_t sz[3] = {64,64,64};
376 
377  Ghost<3,long int> gg(2);
378  Ghost<3,double> gv(0.01);
379 
380  size_t bc_v[3] = {PERIODIC,PERIODIC,PERIODIC};
381 
382  vector_dist<3,double,aggregate<double>> vd(65536,domain,bc_v,gv);
383  grid_dist_id<3,double,aggregate<double>> gd(vd.getDecomposition(),sz,gg);
384 
385  // set one particle on vd
386 
387  auto it = vd.getDomainIterator();
388 
389  while (it.isNext())
390  {
391  auto p = it.get();
392 
393  // coverty[dont_call]
394  vd.getPos(p)[0] = (double)rand()/RAND_MAX;
395  // coverty[dont_call]
396  vd.getPos(p)[1] = (double)rand()/RAND_MAX;
397  // coverty[dont_call]
398  vd.getPos(p)[2] = (double)rand()/RAND_MAX;
399 
400  vd.getProp<0>(p) = 5.0;
401 
402  ++it;
403  }
404 
405  vd.map();
406 
407  // Reset the grid
408  interp_test<3,double,mp4_kernel<float>>(gd,vd,true,2);
409 }
410 
411 BOOST_AUTO_TEST_CASE( interpolation_getSubCheck )
412 {
413  Box<3,double> domain({0.0,0.0,0.0},{1.0,1.0,1.0});
414  size_t sz[3] = {64,64,64};
415 
416  Ghost<3,long int> gg(2);
417  Ghost<3,double> gv(0.01);
418 
419  size_t bc_v[3] = {NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
420 
423 
424  vector vd(0,domain,bc_v,gv);
425  grid_dist_id<3,double,aggregate<double>> gd(vd.getDecomposition(),sz,gg);
426 
427  // interpolate
429 
430  // decomposition
431  auto & dec = vd.getDecomposition();
432 
433  int nl = dec.getNLocalSub();
434 
435  for (int i = 0 ; i < nl ; i++)
436  {
437  int nll = dec.getLocalNIGhost(i);
438  for (int j = 0 ; j < nll ; j++)
439  {
440  auto ibx = dec.getLocalIGhostBox(i,j);
441  int x = dec.getLocalIGhostSub(i,j);
442  auto bx = dec.getSubDomain(x);
443 
444  Point<3,double> p;
445  for (int s = 0; s < 3 ; s++)
446  {
447  Point<3,double> p;
448  for (int s1 = 0; s1 < 3 ; s1++)
449  {
450  p.get(s1) = (ibx.getHigh(s1) - ibx.getLow(s1)) / 2.0 + ibx.getLow(s1);
451  }
452 
453  if (ibx.getLow(s) == bx.getHigh(s))
454  {
455  p.get(s) = ibx.getLow(s);
456  int sub = inte.getSub(p);
457  BOOST_REQUIRE_EQUAL(sub,i);
458  }
459  else if (ibx.getHigh(s) == bx.getLow(s))
460  {
461  p.get(s) = ibx.getHigh(s);
462  int sub = inte.getSub(p);
463  BOOST_REQUIRE_EQUAL(sub,x);
464  }
465  }
466  }
467  }
468 }
469 
470 BOOST_AUTO_TEST_CASE( interpolation_full_test_3D )
471 {
472  Box<3,double> domain({0.0,0.0,0.0},{1.0,1.0,1.0});
473  size_t sz[3] = {64,64,64};
474 
475  Ghost<3,long int> gg(2);
476  Ghost<3,double> gv(0.01);
477 
478  size_t bc_v[3] = {PERIODIC,PERIODIC,PERIODIC};
479 
480  {
481  vector_dist<3,double,aggregate<double>> vd(65536,domain,bc_v,gv);
482  grid_dist_id<3,double,aggregate<double>> gd(vd.getDecomposition(),sz,gg);
483 
484  // set one particle on vd
485 
486  auto it = vd.getDomainIterator();
487 
488  while (it.isNext())
489  {
490  auto p = it.get();
491 
492  vd.getPos(p)[0] = (double)rand()/RAND_MAX;
493  vd.getPos(p)[1] = (double)rand()/RAND_MAX;
494  vd.getPos(p)[2] = (double)rand()/RAND_MAX;
495 
496  vd.getProp<0>(p) = 5.0;
497 
498  ++it;
499  }
500 
501  vd.map();
502 
503  // Reset the grid
504 
505  // Reset the grid
506  interp_test<3,double,mp4_kernel<float>>(gd,vd,false,2);
507 
508  auto & v_cl = create_vcluster();
509  double mg[3];
510  double mv[3];
511  interpolate<decltype(vd),decltype(gd),mp4_kernel<double>> inte(vd,gd);
512 
513  // We have to do a ghost get before interpolating m2p
514  // Before doing mesh to particle particle must be arranged
515  // into a grid like
516 
517  vd.clear();
518 
519  auto it4 = vd.getGridIterator(sz);
520 
521  while(it4.isNext())
522  {
523  auto key = it4.get();
524 
525  vd.add();
526 
527  vd.getLastPos()[0] = key.get(0) * it4.getSpacing(0) + domain.getLow(0) + 0.1*it4.getSpacing(0);
528  vd.getLastPos()[1] = key.get(1) * it4.getSpacing(1) + domain.getLow(1) + 0.1*it4.getSpacing(1);
529  vd.getLastPos()[2] = key.get(2) * it4.getSpacing(2) + domain.getLow(2) + 0.1*it4.getSpacing(2);
530 
531  vd.getLastProp<0>() = 0.0;
532 
533  ++it4;
534  }
535 
536  // Reset also the grid
537 
538  auto it5 = gd.getDomainGhostIterator();
539 
540  while(it5.isNext())
541  {
542  auto key = it5.get();
543 
544  gd.get<0>(key) = 0.0;
545 
546  ++it5;
547  }
548  gd.ghost_get<0>();
549 
550  grid_key_dx<3> start({3,3,3});
551  grid_key_dx<3> stop({(long int)gd.size(0) - 4,(long int)gd.size(1) - 4,(long int)gd.size(2) - 4});
552 
553  auto it6 = gd.getSubDomainIterator(start,stop);
554  while(it6.isNext())
555  {
556  auto key = it6.get();
557 
558  gd.get<0>(key) = 5.0;
559 
560  ++it6;
561  }
562  gd.ghost_get<0>();
563 
564  vd.map();
565  gd.ghost_get<0>();
566  inte.m2p<0,0>(gd,vd);
567 
568  momenta_grid_domain<decltype(gd),0>(gd,mg);
569  momenta_vector<decltype(vd),0>(vd,mv);
570 
571  v_cl.sum(mg[0]);
572  v_cl.sum(mg[1]);
573  v_cl.sum(mg[2]);
574  v_cl.sum(mv[0]);
575  v_cl.sum(mv[1]);
576  v_cl.sum(mv[2]);
577  v_cl.execute();
578 
579  BOOST_REQUIRE_CLOSE(mg[0],mv[0],0.001);
580  BOOST_REQUIRE_CLOSE(mg[1],mv[1],0.001);
581  BOOST_REQUIRE_CLOSE(mg[2],mv[2],0.001);
582 
583  momenta_grid_domain<decltype(gd),1>(gd,mg);
584  momenta_vector<decltype(vd),1>(vd,mv);
585 
586  v_cl.sum(mg[0]);
587  v_cl.sum(mg[1]);
588  v_cl.sum(mg[2]);
589  v_cl.sum(mv[0]);
590  v_cl.sum(mv[1]);
591  v_cl.sum(mv[2]);
592  v_cl.execute();
593 
594  BOOST_REQUIRE_CLOSE(mg[0],mv[0],0.001);
595  BOOST_REQUIRE_CLOSE(mg[1],mv[1],0.001);
596  BOOST_REQUIRE_CLOSE(mg[2],mv[2],0.001);
597 
598  momenta_grid_domain<decltype(gd),2>(gd,mg);
599  momenta_vector<decltype(vd),2>(vd,mv);
600 
601  v_cl.sum(mg[0]);
602  v_cl.sum(mg[1]);
603  v_cl.sum(mg[2]);
604  v_cl.sum(mv[0]);
605  v_cl.sum(mv[1]);
606  v_cl.sum(mv[2]);
607  v_cl.execute();
608 
609  BOOST_REQUIRE_CLOSE(mg[0],mv[0],0.001);
610  BOOST_REQUIRE_CLOSE(mg[1],mv[1],0.001);
611  BOOST_REQUIRE_CLOSE(mg[2],mv[2],0.001);
612 
613  }
614 }
615 
616 BOOST_AUTO_TEST_CASE( int_kernel_test )
617 {
618  mp4_kernel<float> mp4;
619 
620  float tot = 0.0;
621 
622  // Check momenta 0
623 
624  tot += mp4.value(-1.3f,0);
625  tot += mp4.value(-0.3f,1);
626  tot += mp4.value(0.7f,2);
627  tot += mp4.value(1.7f,3);
628 
629  BOOST_REQUIRE_CLOSE(tot,1.0f,0.001);
630 
631  // Check momenta 1
632 
633  tot = 0.0;
634 
635  tot += -1.3f*mp4.value(-1.3f,0);
636  tot += -0.3f*mp4.value(-0.3f,1);
637  tot += 0.7f*mp4.value(0.7f,2);
638  tot += 1.7f*mp4.value(1.7f,3);
639 
640  BOOST_REQUIRE_SMALL(tot,0.001f);
641 
642  // Check momenta 2
643 
644  tot = 0.0;
645 
646  tot += (1.3f)*(1.3f)*mp4.value(-1.3f,0);
647  tot += (0.3f)*(0.3f)*mp4.value(-0.3f,1);
648  tot += (0.7f)*(0.7f)*mp4.value(0.7f,2);
649  tot += (1.7f)*(1.7f)*mp4.value(1.7f,3);
650 
651  BOOST_REQUIRE_SMALL(tot,0.001f);
652 
653 
655 
656  tot = 0.0;
657 
658  z_kernel<float,1> zk1;
659 
660  tot += zk1.value(-0.3f,0);
661  tot += zk1.value(0.7f,1);
662 
663  BOOST_REQUIRE_CLOSE(tot,1.0f,0.001);
664 
666 
668 
669  z_kernel<float,3> zk3;
670 
671  tot = 0.0;
672 
673  // Check momenta 0
674 
675  tot += zk3.value(-2.3f,0);
676  tot += zk3.value(-1.3f,1);
677  tot += zk3.value(-0.3f,2);
678  tot += zk3.value(0.7f,3);
679  tot += zk3.value(1.7f,4);
680  tot += zk3.value(2.7f,5);
681 
682  BOOST_REQUIRE_CLOSE(tot,1.0f,0.001);
683 
684  // Check momenta 1
685 
686  tot = 0.0;
687 
688  tot += -2.3*zk3.value(-2.3f,0);
689  tot += -1.3*zk3.value(-1.3f,1);
690  tot += -0.3*zk3.value(-0.3f,2);
691  tot += 0.7*zk3.value(0.7f,3);
692  tot += 1.7*zk3.value(1.7f,4);
693  tot += 2.7*zk3.value(2.7f,5);
694 
695  BOOST_REQUIRE_SMALL(tot,0.001f);
696 
697  // Check momenta 2
698 
699  tot = 0.0;
700 
701  tot += 2.3*2.3*zk3.value(-2.3f,0);
702  tot += 1.3*1.3*zk3.value(-1.3f,1);
703  tot += 0.3*0.3*zk3.value(-0.3f,2);
704  tot += 0.7*0.7*zk3.value(0.7f,3);
705  tot += 1.7*1.7*zk3.value(1.7f,4);
706  tot += 2.7*2.7*zk3.value(2.7f,5);
707 
708  BOOST_REQUIRE_SMALL(tot,0.001f);
709 
710  // Check momenta 3
711 
712  tot = 0.0;
713 
714  tot += -2.3*-2.3*-2.3*zk3.value(-2.3f,0);
715  tot += -1.3*-1.3*-1.3*zk3.value(-1.3f,1);
716  tot += -0.3*-0.3*-0.3*zk3.value(-0.3f,2);
717  tot += 0.7*0.7*0.7*zk3.value(0.7f,3);
718  tot += 1.7*1.7*1.7*zk3.value(1.7f,4);
719  tot += 2.7*2.7*2.7*zk3.value(2.7f,5);
720 
721  BOOST_REQUIRE_SMALL(tot,0.001f);
722 
723 
724  // z4
725 
726  z_kernel<float,4> zk4;
727 
728  // Check momenta 0
729 
730  tot = 0.0;
731 
732  tot += zk4.value(-3.3f,0);
733  tot += zk4.value(-2.3f,1);
734  tot += zk4.value(-1.3f,2);
735  tot += zk4.value(-0.3f,3);
736  tot += zk4.value(0.7f,4);
737  tot += zk4.value(1.7f,5);
738  tot += zk4.value(2.7f,6);
739  tot += zk4.value(3.7f,7);
740 
741  BOOST_REQUIRE_CLOSE(tot,1.0f,0.001);
742 
743  // Check momenta 1
744 
745  tot = 0.0;
746 
747  tot += -3.3*zk4.value(-3.3f,0);
748  tot += -2.3*zk4.value(-2.3f,1);
749  tot += -1.3*zk4.value(-1.3f,2);
750  tot += -0.3*zk4.value(-0.3f,3);
751  tot += 0.7*zk4.value(0.7f,4);
752  tot += 1.7*zk4.value(1.7f,5);
753  tot += 2.7*zk4.value(2.7f,6);
754  tot += 3.7*zk4.value(3.7f,7);
755 
756  BOOST_REQUIRE_SMALL(tot,0.001f);
757 
758  // Check momenta 2
759 
760  tot = 0.0;
761 
762  tot += 3.3*3.3*zk4.value(-3.3f,0);
763  tot += 2.3*2.3*zk4.value(-2.3f,1);
764  tot += 1.3*1.3*zk4.value(-1.3f,2);
765  tot += 0.3*0.3*zk4.value(-0.3f,3);
766  tot += 0.7*0.7*zk4.value(0.7f,4);
767  tot += 1.7*1.7*zk4.value(1.7f,5);
768  tot += 2.7*2.7*zk4.value(2.7f,6);
769  tot += 3.7*3.7*zk4.value(3.7f,7);
770 
771  BOOST_REQUIRE_SMALL(tot,0.001f);
772 
773  // Check momenta 3
774 
775  tot = 0.0;
776 
777  tot += -3.3*-3.3*-3.3*zk4.value(-3.3f,0);
778  tot += -2.3*-2.3*-2.3*zk4.value(-2.3f,1);
779  tot += -1.3*-1.3*-1.3*zk4.value(-1.3f,2);
780  tot += -0.3*-0.3*-0.3*zk4.value(-0.3f,3);
781  tot += 0.7*0.7*0.7*zk4.value(0.7f,4);
782  tot += 1.7*1.7*1.7*zk4.value(1.7f,5);
783  tot += 2.7*2.7*2.7*zk4.value(2.7f,6);
784  tot += 3.7*3.7*3.7*zk4.value(3.7f,7);
785 
786  BOOST_REQUIRE_SMALL(tot,0.001f);
787 
788  // Check momenta 4
789 
790  tot = 0.0;
791 
792  tot += -3.3*-3.3*-3.3*-3.3*zk4.value(-3.3f,0);
793  tot += -2.3*-2.3*-2.3*-2.3*zk4.value(-2.3f,1);
794  tot += -1.3*-1.3*-1.3*-1.3*zk4.value(-1.3f,2);
795  tot += -0.3*-0.3*-0.3*-0.3*zk4.value(-0.3f,3);
796  tot += 0.7*0.7*0.7*0.7*zk4.value(0.7f,4);
797  tot += 1.7*1.7*1.7*1.7*zk4.value(1.7f,5);
798  tot += 2.7*2.7*2.7*2.7*zk4.value(2.7f,6);
799  tot += 3.7*3.7*3.7*3.7*zk4.value(3.7f,7);
800 
801  BOOST_REQUIRE_SMALL(tot,0.001f);
802 }
803 
804 BOOST_AUTO_TEST_SUITE_END()
805 
806 
807 #endif /* OPENFPM_NUMERICS_SRC_INTERPOLATION_INTERPOLATION_UNIT_TESTS_HPP_ */
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
auto get(const grid_dist_key_dx< dim, bg_key > &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.
__device__ __host__ index_type get(index_type i) const
Get the i index.
Definition: grid_key.hpp:503
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:27
Definition: Ghost.hpp:39
This is a distributed grid.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
Definition: Point.hpp:172
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
grid_dist_iterator< dim, device_grid, decltype(device_grid::type_of_subiterator()), FREE > getDomainIterator() const
It return an iterator that span the full grid domain (each processor span its local domain)
This class represent an N-dimensional box.
Definition: Box.hpp:60
Distributed vector.
Main class for interpolation Particle to mest p2m and Mesh to particle m2p.
void map(size_t opt=0)
It move all the grid parts that do not belong to the local processor to the respective processor.