1 | /* |
2 | * grid_test_utils.hpp |
3 | * |
4 | * Created on: Jun 16, 2019 |
5 | * Author: i-bird |
6 | */ |
7 | |
8 | #ifndef GRID_TEST_UTILS_HPP_ |
9 | #define GRID_TEST_UTILS_HPP_ |
10 | |
11 | |
12 | template<typename grid_type> |
13 | void copy_test(grid_type & g_src, grid_type & g_dst, |
14 | Box<grid_type::dims,size_t> & box_src, Box<grid_type::dims,size_t> & box_dst) |
15 | { |
16 | g_dst.setMemory(); |
17 | g_src.setMemory(); |
18 | |
19 | auto itd = g_dst.getIterator(); |
20 | |
21 | while (itd.isNext()) |
22 | { |
23 | auto k = itd.get(); |
24 | |
25 | g_dst.template get<0>(k) = 0; |
26 | |
27 | g_dst.template get<1>(k)[0] = 0; |
28 | g_dst.template get<1>(k)[1] = 0; |
29 | g_dst.template get<1>(k)[2] = 0; |
30 | |
31 | g_dst.template get<2>(k)[0][0] = 0; |
32 | g_dst.template get<2>(k)[0][1] = 0; |
33 | g_dst.template get<2>(k)[0][2] = 0; |
34 | g_dst.template get<2>(k)[1][0] = 0; |
35 | g_dst.template get<2>(k)[1][1] = 0; |
36 | g_dst.template get<2>(k)[1][2] = 0; |
37 | g_dst.template get<2>(k)[2][0] = 0; |
38 | g_dst.template get<2>(k)[2][1] = 0; |
39 | g_dst.template get<2>(k)[2][2] = 0; |
40 | |
41 | ++itd; |
42 | } |
43 | |
44 | auto & gs = g_src.getGrid(); |
45 | |
46 | auto its = g_src.getIterator(); |
47 | |
48 | while (its.isNext()) |
49 | { |
50 | auto k = its.get(); |
51 | |
52 | g_src.template get<0>(k) = gs.LinId(k); |
53 | |
54 | g_src.template get<1>(k)[0] = gs.LinId(k) + 100; |
55 | g_src.template get<1>(k)[1] = gs.LinId(k) + 200; |
56 | g_src.template get<1>(k)[2] = gs.LinId(k) + 300; |
57 | |
58 | g_src.template get<2>(k)[0][0] = gs.LinId(k) + 1000; |
59 | g_src.template get<2>(k)[0][1] = gs.LinId(k) + 2000; |
60 | g_src.template get<2>(k)[0][2] = gs.LinId(k) + 3000; |
61 | g_src.template get<2>(k)[1][0] = gs.LinId(k) + 4000; |
62 | g_src.template get<2>(k)[1][1] = gs.LinId(k) + 5000; |
63 | g_src.template get<2>(k)[1][2] = gs.LinId(k) + 6000; |
64 | g_src.template get<2>(k)[2][0] = gs.LinId(k) + 7000; |
65 | g_src.template get<2>(k)[2][1] = gs.LinId(k) + 8000; |
66 | g_src.template get<2>(k)[2][2] = gs.LinId(k) + 9000; |
67 | |
68 | ++its; |
69 | } |
70 | |
71 | // copy |
72 | g_dst.copy_to(g_src,box_src,box_dst); |
73 | |
74 | |
75 | // Check |
76 | |
77 | itd = g_dst.getIterator(); |
78 | |
79 | while (itd.isNext()) |
80 | { |
81 | auto k = itd.get(); |
82 | Point<grid_type::dims,size_t> p; |
83 | |
84 | for (size_t i = 0 ; i < grid_type::dims ; i++) |
85 | {p.get(i) = k.get(i);} |
86 | |
87 | if (box_dst.isInside(p) == true) |
88 | { |
89 | grid_key_dx<grid_type::dims> ks = k + box_src.getKP1() - box_dst.getKP1(); |
90 | |
91 | BOOST_REQUIRE_EQUAL(g_dst.template get<0>(k),gs.LinId(ks)); |
92 | |
93 | BOOST_REQUIRE_EQUAL(g_dst.template get<1>(k)[0],gs.LinId(ks) + 100); |
94 | BOOST_REQUIRE_EQUAL(g_dst.template get<1>(k)[1],gs.LinId(ks) + 200); |
95 | BOOST_REQUIRE_EQUAL(g_dst.template get<1>(k)[2],gs.LinId(ks) + 300); |
96 | |
97 | BOOST_REQUIRE_EQUAL(g_dst.template get<2>(k)[0][0],gs.LinId(ks) + 1000); |
98 | BOOST_REQUIRE_EQUAL(g_dst.template get<2>(k)[0][1],gs.LinId(ks) + 2000); |
99 | BOOST_REQUIRE_EQUAL(g_dst.template get<2>(k)[0][2],gs.LinId(ks) + 3000); |
100 | BOOST_REQUIRE_EQUAL(g_dst.template get<2>(k)[1][0],gs.LinId(ks) + 4000); |
101 | BOOST_REQUIRE_EQUAL(g_dst.template get<2>(k)[1][1],gs.LinId(ks) + 5000); |
102 | BOOST_REQUIRE_EQUAL(g_dst.template get<2>(k)[1][2],gs.LinId(ks) + 6000); |
103 | BOOST_REQUIRE_EQUAL(g_dst.template get<2>(k)[2][0],gs.LinId(ks) + 7000); |
104 | BOOST_REQUIRE_EQUAL(g_dst.template get<2>(k)[2][1],gs.LinId(ks) + 8000); |
105 | BOOST_REQUIRE_EQUAL(g_dst.template get<2>(k)[2][2],gs.LinId(ks) + 9000); |
106 | } |
107 | else |
108 | { |
109 | BOOST_REQUIRE_EQUAL(g_dst.template get<0>(k),0); |
110 | |
111 | BOOST_REQUIRE_EQUAL(g_dst.template get<1>(k)[0],0); |
112 | BOOST_REQUIRE_EQUAL(g_dst.template get<1>(k)[1],0); |
113 | BOOST_REQUIRE_EQUAL(g_dst.template get<1>(k)[2],0); |
114 | |
115 | BOOST_REQUIRE_EQUAL(g_dst.template get<2>(k)[0][0],0); |
116 | BOOST_REQUIRE_EQUAL(g_dst.template get<2>(k)[0][1],0); |
117 | BOOST_REQUIRE_EQUAL(g_dst.template get<2>(k)[0][2],0); |
118 | BOOST_REQUIRE_EQUAL(g_dst.template get<2>(k)[1][0],0); |
119 | BOOST_REQUIRE_EQUAL(g_dst.template get<2>(k)[1][1],0); |
120 | BOOST_REQUIRE_EQUAL(g_dst.template get<2>(k)[1][2],0); |
121 | BOOST_REQUIRE_EQUAL(g_dst.template get<2>(k)[2][0],0); |
122 | BOOST_REQUIRE_EQUAL(g_dst.template get<2>(k)[2][1],0); |
123 | BOOST_REQUIRE_EQUAL(g_dst.template get<2>(k)[2][2],0); |
124 | } |
125 | |
126 | ++itd; |
127 | } |
128 | } |
129 | |
130 | |
131 | #endif /* GRID_TEST_UTILS_HPP_ */ |
132 | |