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"
49BOOST_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(fd_op_tests_vec_mat) {
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);
129 grid_dist_id<2, double, aggregate<double, double, double,double[2],double[2][2],double[2][2][2]>> domain(sz, box,ghost,bc);
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 = i * spacing[0];
139 mem_id j = key.get(1);
140 double y = j * spacing[1];
142 domain.template getProp<3>(key_l)[0] = sin(x);
143 domain.template getProp<3>(key_l)[1] = sin(x);
144 domain.template getProp<1>(key_l) = 0;
147 domain.template getProp<2>(key_l) = cos(x);
152 domain.ghost_get<0,3>();
157 auto v = FD::getV<1>(domain);
158 auto P = FD::getV<0>(domain);
160 auto vec = FD::getV<3>(domain);
161 auto Mat = FD::getV<4>(domain);
162 auto Mat3 = FD::getV<5>(domain);
164 Mat[0][1] = Dx(vec[0]);
168 domain.ghost_get<4>();
170 Mat[0][0] = Dx(Mat[1][0]);
171 Mat3[0][0][0] = Dx(vec[0]);
172 Mat3[0][1][0] = Dx(Mat[1][0]);
174 auto it2 = domain.getDomainIterator();
182 if (fabs(domain.getProp<4>(p)[0][1] - domain.getProp<2>(p)) > worst)
184 worst = fabs(domain.getProp<4>(p)[0][1] - domain.getProp<2>(p));
187 if (fabs(domain.getProp<4>(p)[1][0] - domain.getProp<3>(p)[0]) > worst)
189 worst = fabs(domain.getProp<4>(p)[1][0] - domain.getProp<3>(p)[0]);
192 if (fabs(domain.getProp<4>(p)[0][0] - domain.getProp<2>(p)) > worst)
194 worst = fabs(domain.getProp<4>(p)[0][0] - domain.getProp<2>(p));
200 if (fabs(domain.getProp<5>(p)[0][0][0] - domain.getProp<2>(p)) > worst)
202 worst = fabs(domain.getProp<5>(p)[0][0][0] - domain.getProp<2>(p));
205 if (fabs(domain.getProp<5>(p)[0][1][0] - domain.getProp<2>(p)) > worst)
207 worst = fabs(domain.getProp<5>(p)[0][1][0] - domain.getProp<2>(p));
213 BOOST_REQUIRE(worst < 0.003);
216 BOOST_AUTO_TEST_CASE(lalpacian_test) {
217 size_t edgeSemiSize = 80;
218 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
222 spacing[0] = 2 * M_PI / (sz[0] - 1);
223 spacing[1] = 2 * M_PI / (sz[1] - 1);
230 BOOST_TEST_MESSAGE(
"Init domain...");
231 auto it = domain.getDomainIterator();
234 auto key_l = it.get();
235 auto key = it.getGKey(key_l);
236 mem_id i = key.get(0);
237 double x = M_PI / 2 + i * spacing[0];
238 mem_id j = M_PI / 2 + key.get(1);
239 double y = j * spacing[1];
241 domain.template getProp<0>(key_l) = sin(x) + sin(y);
242 domain.template getProp<1>(key_l) = 0;
245 domain.template getProp<2>(key_l) = -sin(x) -sin(y) + cos(x) + cos(y) + 5.0;
250 domain.ghost_get<0>();
256 auto v = FD::getV<1>(domain);
257 auto P = FD::getV<0>(domain);
259 v = L(
P) + Dx(
P) + Dy(
P) + 5;
261 auto it2 = domain.getDomainIterator();
265 while (it2.isNext()) {
268 if (fabs(domain.getProp<1>(p) - domain.getProp<2>(p)) > worst) {
269 worst = fabs(domain.getProp<1>(p) - domain.getProp<2>(p));
279 BOOST_REQUIRE(worst < 0.003);
283 BOOST_AUTO_TEST_CASE(Slice_test) {
284 size_t edgeSemiSize = 80;
285 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
289 spacing[0] = 2 * M_PI / (sz[0] - 1);
290 spacing[1] = 2 * M_PI / (sz[1] - 1);
297 BOOST_TEST_MESSAGE(
"Init domain...");
298 auto it = domain.getDomainIterator();
301 auto key_l = it.get();
302 auto key = it.getGKey(key_l);
303 mem_id i = key.get(0);
304 double x = M_PI / 2 + i * spacing[0];
305 mem_id j = M_PI / 2 + key.get(1);
306 double y = j * spacing[1];
308 domain.template getProp<0>(key_l)[0] = sin(x) + sin(y);
309 domain.template getProp<0>(key_l)[1] = cos(x) + cos(y);
310 domain.template getProp<2>(key_l)[0] = 0;
311 domain.template getProp<2>(key_l)[1] = 0;
312 domain.template getProp<3>(key_l) = 0;
315 domain.template getProp<1>(key_l)[0] = -sin(x) -sin(y) + cos(x) + cos(y) + 5.0;
316 domain.template getProp<1>(key_l)[1] = -cos(x) -cos(y) - sin(x) - sin(y) + 5.0;
321 domain.ghost_get<0>();
328 auto V1 = FD::getV<0>(domain);
329 auto V2 = FD::getV<2>(domain);
330 auto P = FD::getV<3>(domain);
331 constexpr int x=0,y=1;
333 V2[x] = L(V1[y]) + Dx(V1[y]) + Dy(V1[y]) + 5;
334 V2[y] = L(V1[x]) + Dx(V1[x]) + Dy(V1[x]) + 5;
336 auto it2 = domain.getDomainIterator();
340 while (it2.isNext()) {
343 if (fabs(domain.getProp<1>(p)[0] - domain.getProp<2>(p)[1]) > worst) {
344 worst = fabs(domain.getProp<1>(p)[0] - domain.getProp<2>(p)[1]);
354 BOOST_REQUIRE(worst < 0.003);
355 BOOST_REQUIRE(worst != 0);
359 BOOST_AUTO_TEST_CASE(fd_op_tests_staggered) {
361 constexpr int phi_ = 0;
362 constexpr int ux_ = 1;
364 size_t edgeSemiSize = 80;
365 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
369 spacing[0] = 2 * M_PI / (sz[0] - 1);
370 spacing[1] = 2 * M_PI / (sz[1] - 1);
377 comb<2> c({(char)-1,(
char)-1});
381 domain.setStagPosition<phi_>(lc);
383 comb<2> c2({(char)0,(
char)-1});
387 domain.setStagPosition<ux_>(lc);
389 BOOST_TEST_MESSAGE(
"Init domain...");
390 auto it = domain.getDomainIterator();
393 auto key_l = it.get();
394 auto key = it.getGKey(key_l);
395 mem_id i = key.get(0);
396 mem_id j = key.get(1);
398 domain.template getProp<phi_>(key_l) = j % 2;
403 domain.ghost_get<0>();
408 auto ux = FD::getV_stag<ux_>(domain);
409 auto phi = FD::getV_stag<phi_>(domain);
414 auto it2 = domain.getSubDomainIterator(start,stop);
417 auto key_l = it2.
get();
419 double test = phi.value(key_l,c2);
421 BOOST_REQUIRE_EQUAL(test,0.5);
427 BOOST_AUTO_TEST_CASE(fd_op_tests_derivative_staggered) {
432 constexpr int phi_ = 0;
433 constexpr int ux_ = 1;
435 size_t edgeSemiSize = 80;
436 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
440 spacing[0] = 2 * M_PI / (sz[0] - 1);
441 spacing[1] = 2 * M_PI / (sz[1] - 1);
448 comb<2> c({(char)-1,(
char)-1});
452 domain.setStagPosition<phi_>(lc);
454 comb<2> c2({(char)0,(
char)-1});
458 domain.setStagPosition<ux_>(lc);
460 BOOST_TEST_MESSAGE(
"Init domain...");
461 auto it = domain.getDomainIterator();
464 auto key_l = it.get();
465 auto key = it.getGKey(key_l);
466 mem_id i = key.get(0);
467 double x = i * spacing[0];
468 mem_id j = key.get(1);
469 double y = j * spacing[1];
471 domain.template getProp<phi_>(key_l) = x*x + 3.0*y*y;
476 domain.ghost_get<0>();
481 auto ux = FD::getV_stag<ux_>(domain);
482 auto phi = FD::getV_stag<phi_>(domain);
484 ux = Dx(phi) + Dy(phi) + phi + 5;
489 double worst_error = 0.0;
491 auto it2 = domain.getSubDomainIterator(start,stop);
494 auto key = it2.
get();
496 double test = domain.template getProp<ux_>(key);
498 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))) );
499 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))) );
501 dx *= 0.5/spacing[0];
502 dy *= 0.5/spacing[1];
504 double phi_inte = 0.5*(domain.template getProp<phi_>(key.move(y,1)) + domain.template getProp<phi_>(key));
506 if (fabs(test - (dx + dy + phi_inte + 5.0)) > worst_error )
507 {worst_error = fabs(test - (dx + dy + phi_inte + 5.0));}
512 BOOST_REQUIRE(worst_error < 5e-13);
516BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
Test structure used for several test.
This is a distributed grid.
grid_key_dx is the key to access any element in the grid
__device__ __host__ index_type get(index_type i) const
Get the i index.
Implementation of 1-D std::vector like structure.
Implementation of the staggered grid.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
Position of the element of dimension d in the hyper-cube of dimension dim.
Specify the general characteristic of system to solve.