9#define BOOST_TEST_DYN_LINK
10#include <boost/test/unit_test.hpp>
11#include "Grid/grid_dist_id.hpp"
12#include "Point_test.hpp"
19BOOST_AUTO_TEST_SUITE( sgrid_dist_id_test )
23BOOST_AUTO_TEST_CASE (sgrid_dist_id_soa )
43 auto it = sg.getGridIterator();
48 auto key = it.get_dist();
50 size_t sx = gkey.get(0) - 512;
51 size_t sy = gkey.get(1) - 512;
52 size_t sz = gkey.get(2) - 512;
54 if (sx*sx + sy*sy + sz*sz < 128*128)
56 sg.template insert<0>(key) = 1.0;
63 auto it2 = sg.getGridIterator();
67 auto gkey = it2.get();
68 auto key = it2.get_dist();
70 size_t sx = gkey.get(0) - 512;
71 size_t sy = gkey.get(1) - 512;
72 size_t sz = gkey.get(2) - 512;
74 if (sx*sx + sy*sy + sz*sz < 128*128)
76 match &= (sg.template get<0>(key) == 1.0);
82 auto & gr = sg.getGridInfo();
84 auto it3 = sg.getDomainIterator();
89 auto gkey = it3.getGKey(key);
91 sg.template insert<0>(key) = gkey.get(0)*gkey.get(0) + gkey.get(1)*gkey.get(1) + gkey.get(2)*gkey.get(2);
100 auto it4 = sg.getDomainIterator();
104 auto key = it4.get();
105 auto gkey = it4.getGKey(key);
107 size_t sx = gkey.get(0) - 512;
108 size_t sy = gkey.get(1) - 512;
109 size_t sz = gkey.get(2) - 512;
113 lap = sg.template get<0>(key.move(x,1)) + sg.template get<0>(key.move(x,-1)) +
114 sg.template get<0>(key.move(y,1)) + sg.template get<0>(key.move(y,-1)) +
115 sg.template get<0>(key.move(z,1)) + sg.template get<0>(key.move(z,-1)) -
116 6.0*sg.template get<0>(key);
118 good &= (lap == 6.0);
123 BOOST_REQUIRE_EQUAL(match,
true);
126BOOST_AUTO_TEST_CASE( sgrid_dist_id_basic_test_2D)
145 auto it = sg.getGridIterator();
149 auto gkey = it.get();
150 auto key = it.get_dist();
153 long int sx = gkey.get(0) - 512;
154 long int sy = gkey.get(1) - 512;
156 if (sx*sx + sy*sy < 128*128)
158 sg.template insert<0>(key) = 1.0;
165 auto it2 = sg.getGridIterator();
169 auto gkey = it2.get();
170 auto key = it2.get_dist();
172 long int sx = gkey.get(0) - 512;
173 long int sy = gkey.get(1) - 512;
175 if (sx*sx + sy*sy < 128*128)
177 match &= (sg.template get<0>(key) == 1.0);
183 BOOST_REQUIRE_EQUAL(match,
true);
185 auto & gr = sg.getGridInfo();
187 auto it3 = sg.getDomainIterator();
191 auto key = it3.get();
192 auto gkey = it3.getGKey(key);
194 sg.template insert<0>(key) = gkey.get(0)*gkey.get(0) + gkey.get(1)*gkey.get(1);
204 auto it4 = sg.getDomainIterator();
208 auto key = it4.get();
209 auto gkey = it4.getGKey(key);
215 long int sx = gkey.get(0) - 512;
216 long int sy = gkey.get(1) - 512;
218 if (sx*sx + sy*sy < 126*126)
220 lap = sg.template get<0>(key.move(x,1)) + sg.template get<0>(key.move(x,-1)) +
221 sg.template get<0>(key.move(y,1)) + sg.template get<0>(key.move(y,-1)) -
222 4.0*sg.template get<0>(key);
224 good &= (lap == 4.0);
230 BOOST_REQUIRE_EQUAL(good,
true);
233BOOST_AUTO_TEST_CASE( sgrid_dist_id_basic_test)
253 auto it = sg.getGridIterator();
257 auto gkey = it.get();
258 auto key = it.get_dist();
260 size_t sx = gkey.get(0) - 512;
261 size_t sy = gkey.get(1) - 512;
262 size_t sz = gkey.get(2) - 512;
264 if (sx*sx + sy*sy + sz*sz < 128*128)
266 sg.template insert<0>(key) = 1.0;
273 auto it2 = sg.getGridIterator();
277 auto gkey = it2.get();
278 auto key = it2.get_dist();
280 size_t sx = gkey.get(0) - 512;
281 size_t sy = gkey.get(1) - 512;
282 size_t sz = gkey.get(2) - 512;
284 if (sx*sx + sy*sy + sz*sz < 128*128)
286 match &= (sg.template get<0>(key) == 1.0);
292 auto & gr = sg.getGridInfo();
294 auto it3 = sg.getDomainIterator();
298 auto key = it3.get();
299 auto gkey = it3.getGKey(key);
301 sg.template insert<0>(key) = gkey.get(0)*gkey.get(0) + gkey.get(1)*gkey.get(1) + gkey.get(2)*gkey.get(2);
310 auto it4 = sg.getDomainIterator();
314 auto key = it4.get();
315 auto gkey = it4.getGKey(key);
317 size_t sx = gkey.get(0) - 512;
318 size_t sy = gkey.get(1) - 512;
319 size_t sz = gkey.get(2) - 512;
321 if (sx*sx + sy*sy + sz*sz < 125*125)
325 lap = sg.template get<0>(key.move(x,1)) + sg.template get<0>(key.move(x,-1)) +
326 sg.template get<0>(key.move(y,1)) + sg.template get<0>(key.move(y,-1)) +
327 sg.template get<0>(key.move(z,1)) + sg.template get<0>(key.move(z,-1)) -
328 6.0*sg.template get<0>(key);
330 good &= (lap == 6.0);
336 BOOST_REQUIRE_EQUAL(match,
true);
340BOOST_AUTO_TEST_CASE( sparse_grid_fast_stencil_vectorized_simplified_conv2)
345 constexpr int U_next = 2;
346 constexpr int V_next = 3;
355 size_t sz[3] = {32,32,32};
373 size_t timeSteps = 5000;
381 auto it =
grid.getGridIterator();
386 auto key = it.get_dist();
389 grid.template insert<U>(key) = 1.0;
390 grid.template insert<V>(key) = 0.0;
393 grid.template insert<U_next>(key) = 0.0;
394 grid.template insert<V_next>(key) = 0.0;
399 long int x_start =
grid.size(0)*1.55f/domain.getHigh(0);
400 long int y_start =
grid.size(1)*1.55f/domain.getHigh(1);
401 long int z_start =
grid.size(1)*1.55f/domain.getHigh(2);
403 long int x_stop =
grid.size(0)*1.85f/domain.getHigh(0);
404 long int y_stop =
grid.size(1)*1.85f/domain.getHigh(1);
405 long int z_stop =
grid.size(1)*1.85f/domain.getHigh(2);
409 auto it_init =
grid.getGridIterator(start,stop);
411 while (it_init.isNext())
413 auto key = it_init.get_dist();
415 grid.template insert<U>(key) = 0.5 + (((double)std::rand())/RAND_MAX -0.5)/10.0;
416 grid.template insert<V>(key) = 0.25 + (((double)std::rand())/RAND_MAX -0.5)/20.0;
422 double spacing[3] = {
grid.spacing(0),
grid.spacing(1),
grid.spacing(2)};
425 grid.template ghost_get<U,V>();
429 double uFactor = deltaT * du/(spacing[x]*spacing[x]);
430 double vFactor = deltaT * dv/(spacing[x]*spacing[x]);
432 int stencil[6][3] = {{1,0,0},{-1,0,0},{0,-1,0},{0,1,0},{0,0,-1},{0,0,1}};
438 auto func = [uFactor,vFactor,deltaT,
F,K](Vc::double_v & u_out,Vc::double_v & v_out,
439 Vc::double_v (& u)[7],Vc::double_v (& v)[7],
440 unsigned char * mask){
442 u_out = u[0] + uFactor *(u[1] + u[2] +
444 u[5] + u[6] - 6.0*u[0]) - deltaT * u[0]*v[0]*v[0]
445 - deltaT *
F * (u[0] - 1.0);
447 v_out = v[0] + vFactor *(v[1] + v[2] +
449 v[5] + v[6] - 6.0*v[0]) + deltaT * u[0]*v[0]*v[0]
450 - deltaT * (
F+K) * v[0];
453 grid.conv2<U,V,U_next,V_next,1>(stencil,{0,0,0},{(
long int)sz[0]-1,(
long int)sz[1]-1,(
long int)sz[2]-1},func);
454 grid.conv2<U,V,U_next,V_next,1>(stencil,{0,0,0},{(
long int)sz[0]-1,(
long int)sz[1]-1,(
long int)sz[2]-1},func);
459 auto it =
grid.getDomainIterator();
470 auto mx = Cp.
move(0,-1);
471 auto px = Cp.move(0,+1);
472 auto my = Cp.move(1,-1);
473 auto py = Cp.move(1,1);
474 auto mz = Cp.move(2,-1);
475 auto pz = Cp.move(2,1);
478 if ( fabs(
grid.get<U>(Cp) + uFactor * (
485 6.0*
grid.get<U>(Cp)) +
486 - deltaT *
grid.get<U>(Cp) *
grid.get<V>(Cp) *
grid.get<V>(Cp) +
487 - deltaT *
F * (
grid.get<U>(Cp) - 1.0) -
grid.get<U_next>(Cp)) > 0.000000001 )
494 if ( fabs(
grid.get<V>(Cp) + vFactor * (
502 deltaT *
grid.get<U>(Cp) *
grid.get<V>(Cp) *
grid.get<V>(Cp) +
503 - deltaT * (
F+K) *
grid.get<V>(Cp) -
grid.get<V_next>(Cp)) > 0.000000001 )
513 BOOST_REQUIRE_EQUAL(match,
true);
517BOOST_AUTO_TEST_CASE( sparse_grid_fast_stencil_vectorized_simplified_conv2_crossing)
522 constexpr int U_next = 2;
523 constexpr int V_next = 3;
532 size_t sz[3] = {32,32,32};
550 size_t timeSteps = 5000;
558 auto it =
grid.getGridIterator();
563 auto key = it.get_dist();
566 grid.template insert<U>(key) = 1.0;
567 grid.template insert<V>(key) = 0.0;
570 grid.template insert<U_next>(key) = 0.0;
571 grid.template insert<V_next>(key) = 0.0;
576 long int x_start =
grid.size(0)*1.55f/domain.getHigh(0);
577 long int y_start =
grid.size(1)*1.55f/domain.getHigh(1);
578 long int z_start =
grid.size(1)*1.55f/domain.getHigh(2);
580 long int x_stop =
grid.size(0)*1.85f/domain.getHigh(0);
581 long int y_stop =
grid.size(1)*1.85f/domain.getHigh(1);
582 long int z_stop =
grid.size(1)*1.85f/domain.getHigh(2);
586 auto it_init =
grid.getGridIterator(start,stop);
588 while (it_init.isNext())
590 auto key = it_init.get_dist();
592 grid.template insert<U>(key) = 0.5 + (((double)std::rand())/RAND_MAX -0.5)/10.0;
593 grid.template insert<V>(key) = 0.25 + (((double)std::rand())/RAND_MAX -0.5)/20.0;
599 double spacing[3] = {
grid.spacing(0),
grid.spacing(1),
grid.spacing(2)};
602 grid.template ghost_get<U,V>();
606 double uFactor = deltaT * du/(spacing[x]*spacing[x]);
607 double vFactor = deltaT * dv/(spacing[x]*spacing[x]);
613 auto func = [uFactor,vFactor,deltaT,
F,K](Vc::double_v & u_out,Vc::double_v & v_out,
614 Vc::double_v & u,Vc::double_v & v,
616 unsigned char * mask){
618 u_out = u + uFactor *(us.xm + us.xp +
620 us.zm + us.zp - 6.0*u) - deltaT * u*v*v
621 - deltaT *
F * (u - 1.0);
623 v_out = v + vFactor *(vs.xm + vs.xp +
625 vs.zm + vs.zp - 6.0*v) + deltaT * u*v*v
626 - deltaT * (
F+K) * v;
629 grid.conv_cross2<U,V,U_next,V_next,1>({0,0,0},{(
long int)sz[0]-1,(
long int)sz[1]-1,(
long int)sz[2]-1},func);
630 grid.conv_cross2<U,V,U_next,V_next,1>({0,0,0},{(
long int)sz[0]-1,(
long int)sz[1]-1,(
long int)sz[2]-1},func);
635 auto it =
grid.getDomainIterator();
646 auto mx = Cp.
move(0,-1);
647 auto px = Cp.move(0,+1);
648 auto my = Cp.move(1,-1);
649 auto py = Cp.move(1,1);
650 auto mz = Cp.move(2,-1);
651 auto pz = Cp.move(2,1);
654 if ( fabs(
grid.get<U>(Cp) + uFactor * (
661 6.0*
grid.get<U>(Cp)) +
662 - deltaT *
grid.get<U>(Cp) *
grid.get<V>(Cp) *
grid.get<V>(Cp) +
663 - deltaT *
F * (
grid.get<U>(Cp) - 1.0) -
grid.get<U_next>(Cp)) > 0.000000001 )
670 if ( fabs(
grid.get<V>(Cp) + vFactor * (
678 deltaT *
grid.get<U>(Cp) *
grid.get<V>(Cp) *
grid.get<V>(Cp) +
679 - deltaT * (
F+K) *
grid.get<V>(Cp) -
grid.get<V_next>(Cp)) > 0.000000001 )
689 BOOST_REQUIRE_EQUAL(match,
true);
692BOOST_AUTO_TEST_CASE( sparse_grid_fast_stencil_vectorized_simplified_conv2_crossing_float)
697 constexpr int U_next = 2;
698 constexpr int V_next = 3;
707 size_t sz[3] = {32,32,32};
725 size_t timeSteps = 5000;
733 auto it =
grid.getGridIterator();
738 auto key = it.get_dist();
741 grid.template insert<U>(key) = 1.0;
742 grid.template insert<V>(key) = 0.0;
745 grid.template insert<U_next>(key) = 0.0;
746 grid.template insert<V_next>(key) = 0.0;
751 long int x_start =
grid.size(0)*1.55f/domain.getHigh(0);
752 long int y_start =
grid.size(1)*1.55f/domain.getHigh(1);
753 long int z_start =
grid.size(1)*1.55f/domain.getHigh(2);
755 long int x_stop =
grid.size(0)*1.85f/domain.getHigh(0);
756 long int y_stop =
grid.size(1)*1.85f/domain.getHigh(1);
757 long int z_stop =
grid.size(1)*1.85f/domain.getHigh(2);
761 auto it_init =
grid.getGridIterator(start,stop);
763 while (it_init.isNext())
765 auto key = it_init.get_dist();
767 grid.template insert<U>(key) = 0.5 + (((float)std::rand())/RAND_MAX -0.5)/10.0;
768 grid.template insert<V>(key) = 0.25 + (((float)std::rand())/RAND_MAX -0.5)/20.0;
774 float spacing[3] = {
grid.spacing(0),
grid.spacing(1),
grid.spacing(2)};
777 grid.template ghost_get<U,V>();
781 float uFactor = deltaT * du/(spacing[x]*spacing[x]);
782 float vFactor = deltaT * dv/(spacing[x]*spacing[x]);
788 auto func = [uFactor,vFactor,deltaT,
F,K](Vc::float_v & u_out,Vc::float_v & v_out,
789 Vc::float_v & u,Vc::float_v & v,
791 unsigned char * mask){
793 u_out = u + uFactor *(us.xm + us.xp +
795 us.zm + us.zp - 6.0f*u) - deltaT * u*v*v
796 - deltaT *
F * (u - 1.0f);
798 v_out = v + vFactor *(vs.xm + vs.xp +
800 vs.zm + vs.zp - 6.0f*v) + deltaT * u*v*v
801 - deltaT * (
F+K) * v;
804 grid.conv_cross2<U,V,U_next,V_next,1>({0,0,0},{(
long int)sz[0]-1,(
long int)sz[1]-1,(
long int)sz[2]-1},func);
805 grid.conv_cross2<U,V,U_next,V_next,1>({0,0,0},{(
long int)sz[0]-1,(
long int)sz[1]-1,(
long int)sz[2]-1},func);
810 auto it =
grid.getDomainIterator();
821 auto mx = Cp.
move(0,-1);
822 auto px = Cp.move(0,+1);
823 auto my = Cp.move(1,-1);
824 auto py = Cp.move(1,1);
825 auto mz = Cp.move(2,-1);
826 auto pz = Cp.move(2,1);
829 if ( fabs(
grid.get<U>(Cp) + uFactor * (
836 6.0*
grid.get<U>(Cp)) +
837 - deltaT *
grid.get<U>(Cp) *
grid.get<V>(Cp) *
grid.get<V>(Cp) +
838 - deltaT *
F * (
grid.get<U>(Cp) - 1.0) -
grid.get<U_next>(Cp)) > 0.00001 )
845 if ( fabs(
grid.get<V>(Cp) + vFactor * (
853 deltaT *
grid.get<U>(Cp) *
grid.get<V>(Cp) *
grid.get<V>(Cp) +
854 - deltaT * (
F+K) *
grid.get<V>(Cp) -
grid.get<V_next>(Cp)) > 0.00001 )
864 BOOST_REQUIRE_EQUAL(match,
true);
868BOOST_AUTO_TEST_CASE (sgrid_dist_id_soa_write )
872 auto & v_cl = create_vcluster<>();
874 if (v_cl.size() > 16)
894 auto it = sg1.getGridIterator();
898 auto gkey = it.get();
899 auto key = it.get_dist();
901 size_t sx = gkey.get(0) - 128;
902 size_t sy = gkey.get(1) - 128;
903 size_t sz = gkey.get(2) - 128;
905 if (sx*sx + sy*sy + sz*sz < 32*32)
907 sg1.template insert<0>(key) = 1.0;
908 sg1.template insert<1>(key)[0] = gkey.get(0);
909 sg1.template insert<1>(key)[1] = gkey.get(1);
910 sg1.template insert<1>(key)[2] = gkey.get(2);
912 sg2.template insert<0>(key) = 1.0;
913 sg2.template insert<1>(key)[0] = gkey.get(0);
914 sg2.template insert<1>(key)[1] = gkey.get(1);
915 sg2.template insert<1>(key)[2] = gkey.get(2);
921 sg1.write(
"sg1_test");
922 sg2.write(
"sg2_test");
924 bool test = compare(
"sg1_test_" + std::to_string(v_cl.rank()) +
".vtk",
"sg2_test_" + std::to_string(v_cl.rank()) +
".vtk");
925 BOOST_REQUIRE_EQUAL(
true,test);
927 sg1.save(
"hdf5_w1_test");
928 sg2.save(
"hdf5_w2_test");
938BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
This is a distributed grid.
Grid key for a distributed grid.
grid_dist_key_dx< dim, base_key > move(size_t i, int s) const
Create a new key moving the old one.
grid_key_dx is the key to access any element in the grid
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
[v_transform metafunction]