8 #define BOOST_TEST_DYN_LINK 10 #include "util/util_debug.hpp" 11 #include <boost/test/unit_test.hpp> 13 #include "Grid/grid_dist_id.hpp" 15 #include "Grid/staggered_dist_grid.hpp" 49 BOOST_AUTO_TEST_SUITE(fd_op_suite_tests)
51 BOOST_AUTO_TEST_CASE(fd_op_tests) {
52 size_t edgeSemiSize = 80;
53 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
57 spacing[0] = 2 * M_PI / (sz[0] - 1);
58 spacing[1] = 2 * M_PI / (sz[1] - 1);
65 BOOST_TEST_MESSAGE(
"Init domain...");
66 auto it = domain.getDomainIterator();
69 auto key_l = it.get();
70 auto key = it.getGKey(key_l);
71 mem_id i = key.get(0);
72 double x = i * spacing[0];
73 mem_id j = key.get(1);
74 double y = j * spacing[1];
76 domain.template getProp<0>(key_l) = sin(x) + sin(y);
77 domain.template getProp<1>(key_l) = 0;
80 domain.template getProp<2>(key_l) = cos(x) + cos(y) + sin(x) + sin(y) + 5.0;
85 domain.ghost_get<0>();
90 auto v = FD::getV<1>(domain);
91 auto P = FD::getV<0>(domain);
93 v = Dx(
P) + Dy(
P) +
P + 5;
95 auto it2 = domain.getDomainIterator();
99 while (it2.isNext()) {
102 if (fabs(domain.getProp<1>(p) - domain.getProp<2>(p)) > worst) {
103 worst = fabs(domain.getProp<1>(p) - domain.getProp<2>(p));
113 BOOST_REQUIRE(worst < 0.003);
117 BOOST_AUTO_TEST_CASE(lalpacian_test) {
118 size_t edgeSemiSize = 80;
119 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
123 spacing[0] = 2 * M_PI / (sz[0] - 1);
124 spacing[1] = 2 * M_PI / (sz[1] - 1);
131 BOOST_TEST_MESSAGE(
"Init domain...");
132 auto it = domain.getDomainIterator();
135 auto key_l = it.get();
136 auto key = it.getGKey(key_l);
137 mem_id i = key.get(0);
138 double x = M_PI / 2 + i * spacing[0];
139 mem_id j = M_PI / 2 + key.get(1);
140 double y = j * spacing[1];
142 domain.template getProp<0>(key_l) = sin(x) + sin(y);
143 domain.template getProp<1>(key_l) = 0;
146 domain.template getProp<2>(key_l) = -sin(x) -sin(y) + cos(x) + cos(y) + 5.0;
151 domain.ghost_get<0>();
157 auto v = FD::getV<1>(domain);
158 auto P = FD::getV<0>(domain);
160 v = L(
P) + Dx(
P) + Dy(
P) + 5;
162 auto it2 = domain.getDomainIterator();
166 while (it2.isNext()) {
169 if (fabs(domain.getProp<1>(p) - domain.getProp<2>(p)) > worst) {
170 worst = fabs(domain.getProp<1>(p) - domain.getProp<2>(p));
180 BOOST_REQUIRE(worst < 0.003);
184 BOOST_AUTO_TEST_CASE(Slice_test) {
185 size_t edgeSemiSize = 80;
186 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
190 spacing[0] = 2 * M_PI / (sz[0] - 1);
191 spacing[1] = 2 * M_PI / (sz[1] - 1);
198 BOOST_TEST_MESSAGE(
"Init domain...");
199 auto it = domain.getDomainIterator();
202 auto key_l = it.get();
203 auto key = it.getGKey(key_l);
204 mem_id i = key.get(0);
205 double x = M_PI / 2 + i * spacing[0];
206 mem_id j = M_PI / 2 + key.get(1);
207 double y = j * spacing[1];
209 domain.template getProp<0>(key_l)[0] = sin(x) + sin(y);
210 domain.template getProp<0>(key_l)[1] = cos(x) + cos(y);
211 domain.template getProp<2>(key_l)[0] = 0;
212 domain.template getProp<2>(key_l)[1] = 0;
213 domain.template getProp<3>(key_l) = 0;
216 domain.template getProp<1>(key_l)[0] = -sin(x) -sin(y) + cos(x) + cos(y) + 5.0;
217 domain.template getProp<1>(key_l)[1] = -cos(x) -cos(y) - sin(x) - sin(y) + 5.0;
222 domain.ghost_get<0>();
229 auto V1 = FD::getV<0>(domain);
230 auto V2 = FD::getV<2>(domain);
231 auto P = FD::getV<3>(domain);
232 constexpr
int x=0,y=1;
234 V2[x] = L(V1[y]) + Dx(V1[y]) + Dy(V1[y]) + 5;
235 V2[y] = L(V1[x]) + Dx(V1[x]) + Dy(V1[x]) + 5;
237 auto it2 = domain.getDomainIterator();
241 while (it2.isNext()) {
244 if (fabs(domain.getProp<1>(p)[0] - domain.getProp<2>(p)[1]) > worst) {
245 worst = fabs(domain.getProp<1>(p)[0] - domain.getProp<2>(p)[1]);
255 BOOST_REQUIRE(worst < 0.003);
256 BOOST_REQUIRE(worst != 0);
260 BOOST_AUTO_TEST_CASE(fd_op_tests_staggered) {
262 constexpr
int phi_ = 0;
263 constexpr
int ux_ = 1;
265 size_t edgeSemiSize = 80;
266 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
270 spacing[0] = 2 * M_PI / (sz[0] - 1);
271 spacing[1] = 2 * M_PI / (sz[1] - 1);
278 comb<2> c({(char)-1,(
char)-1});
282 domain.setStagPosition<phi_>(lc);
284 comb<2> c2({(char)0,(
char)-1});
288 domain.setStagPosition<ux_>(lc);
290 BOOST_TEST_MESSAGE(
"Init domain...");
291 auto it = domain.getDomainIterator();
294 auto key_l = it.get();
295 auto key = it.getGKey(key_l);
296 mem_id i = key.get(0);
297 mem_id j = key.get(1);
299 domain.template getProp<phi_>(key_l) = j % 2;
304 domain.ghost_get<0>();
309 auto ux = FD::getV_stag<ux_>(domain);
310 auto phi = FD::getV_stag<phi_>(domain);
315 auto it2 = domain.getSubDomainIterator(start,stop);
318 auto key_l = it2.
get();
320 double test = phi.value(key_l,c2);
322 BOOST_REQUIRE_EQUAL(test,0.5);
328 BOOST_AUTO_TEST_CASE(fd_op_tests_derivative_staggered) {
333 constexpr
int phi_ = 0;
334 constexpr
int ux_ = 1;
336 size_t edgeSemiSize = 80;
337 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
341 spacing[0] = 2 * M_PI / (sz[0] - 1);
342 spacing[1] = 2 * M_PI / (sz[1] - 1);
349 comb<2> c({(char)-1,(
char)-1});
353 domain.setStagPosition<phi_>(lc);
355 comb<2> c2({(char)0,(
char)-1});
359 domain.setStagPosition<ux_>(lc);
361 BOOST_TEST_MESSAGE(
"Init domain...");
362 auto it = domain.getDomainIterator();
365 auto key_l = it.get();
366 auto key = it.getGKey(key_l);
367 mem_id i = key.get(0);
368 double x = i * spacing[0];
369 mem_id j = key.get(1);
370 double y = j * spacing[1];
372 domain.template getProp<phi_>(key_l) = x*x + 3.0*y*y;
377 domain.ghost_get<0>();
382 auto ux = FD::getV_stag<ux_>(domain);
383 auto phi = FD::getV_stag<phi_>(domain);
385 ux = Dx(phi) + Dy(phi) + phi + 5;
390 double worst_error = 0.0;
392 auto it2 = domain.getSubDomainIterator(start,stop);
395 auto key = it2.
get();
397 double test = domain.template getProp<ux_>(key);
399 double dx = 0.5* (domain.template getProp<phi_>(key.move(x,1).move(y,1)) + domain.template getProp<phi_>(key.move(x,1)) - (domain.template getProp<phi_>(key.move(x,-1).move(y,1)) + domain.template getProp<phi_>(key.move(x,-1))) );
400 double dy = 0.5* (domain.template getProp<phi_>(key.move(y,1).move(y,1)) + domain.template getProp<phi_>(key.move(y,1)) - (domain.template getProp<phi_>(key.move(y,-1).move(y,1)) + domain.template getProp<phi_>(key.move(y,-1))) );
402 dx *= 0.5/spacing[0];
403 dy *= 0.5/spacing[1];
405 double phi_inte = 0.5*(domain.template getProp<phi_>(key.move(y,1)) + domain.template getProp<phi_>(key));
407 if (fabs(test - (dx + dy + phi_inte + 5.0)) > worst_error )
408 {worst_error = fabs(test - (dx + dy + phi_inte + 5.0));}
413 BOOST_REQUIRE(worst_error < 5e-13);
417 BOOST_AUTO_TEST_SUITE_END()
Specify the general characteristic of system to solve.
grid_key_dx is the key to access any element in the grid
Position of the element of dimension d in the hyper-cube of dimension dim.
__device__ __host__ index_type get(index_type i) const
Get the i index.
This is a distributed grid.
Implementation of the staggered grid.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
This class represent an N-dimensional box.
auto get() -> decltype(boost::fusion::at_c< i >(data))
getter method for a general property i
Test structure used for several test.
Implementation of 1-D std::vector like structure.