11 #define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS 12 #define BOOST_MPL_LIMIT_VECTOR_SIZE 30 16 #define BOOST_TEST_DYN_LINK 18 #include "util/util_debug.hpp" 19 #include <boost/test/unit_test.hpp> 21 #include "../DCPSE_op.hpp" 22 #include "../DCPSE_Solver.hpp" 23 #include "Operators/Vector/vector_dist_operators.hpp" 24 #include "Vector/vector_dist_subset.hpp" 25 #include "../EqnsStruct.hpp" 27 BOOST_AUTO_TEST_SUITE(dcpse_op_suite_tests)
28 BOOST_AUTO_TEST_CASE(dcpse_op_tests) {
29 size_t edgeSemiSize = 40;
30 const size_t sz[2] = {2 * edgeSemiSize, 2 * edgeSemiSize};
32 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
34 spacing[0] = 2 * M_PI / (sz[0] - 1);
35 spacing[1] = 2 * M_PI / (sz[1] - 1);
37 double rCut = 3.9 * spacing[0];
38 BOOST_TEST_MESSAGE(
"Init vector_dist...");
39 double sigma2 = spacing[0] * spacing[1] / (2 * 4);
41 vector_dist<2, double, aggregate<double, double, double, VectorS<2, double>,
VectorS<2, double>>> domain(0, box,
46 BOOST_TEST_MESSAGE(
"Init domain...");
48 auto it = domain.getGridIterator(sz);
51 double minNormOne = 999;
55 mem_id k0 = key.get(0);
56 double x = k0 * spacing[0];
57 domain.getLastPos()[0] = x;
58 mem_id k1 = key.get(1);
59 double y = k1 * spacing[1];
60 domain.getLastPos()[1] = y;
62 domain.template getLastProp<0>() = sin(domain.getLastPos()[0]) + sin(domain.getLastPos()[1]);
63 domain.template getLastProp<2>() = cos(domain.getLastPos()[0]) + cos(domain.getLastPos()[1]);
67 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
70 domain.ghost_get<0>();
72 Derivative_x Dx(domain, 2, rCut);
73 Derivative_y Dy(domain, 2, rCut);
74 Gradient Grad(domain, 2, rCut);
75 Laplacian
Lap(domain, 2, rCut);
76 auto v = getV<1>(domain);
77 auto P = getV<0>(domain);
80 auto it2 = domain.getDomainIterator();
84 while (it2.isNext()) {
87 if (fabs(domain.getProp<1>(p) - domain.getProp<2>(p)) > worst) {
88 worst = fabs(domain.getProp<1>(p) - domain.getProp<2>(p));
95 BOOST_REQUIRE(worst < 0.03);
100 BOOST_AUTO_TEST_CASE(dcpse_op_test_lap) {
101 size_t edgeSemiSize = 81;
102 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
104 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
106 spacing[0] = 2 * M_PI / (sz[0] - 1);
107 spacing[1] = 2 * M_PI / (sz[1] - 1);
109 double rCut = 3.9 * spacing[0];
110 BOOST_TEST_MESSAGE(
"Init vector_dist...");
111 double sigma2 = spacing[0] * spacing[1] / (2 * 4);
118 BOOST_TEST_MESSAGE(
"Init domain...");
119 std::normal_distribution<> gaussian{0, sigma2};
121 auto it = domain.getGridIterator(sz);
124 double minNormOne = 999;
125 while (it.isNext()) {
128 mem_id k0 = key.get(0);
129 double x = k0 * spacing[0];
130 domain.getLastPos()[0] = x;
131 mem_id k1 = key.get(1);
132 double y = k1 * spacing[1];
133 domain.getLastPos()[1] = y;
135 domain.template getLastProp<0>() = sin(domain.getLastPos()[0]) + sin(domain.getLastPos()[1]);
137 domain.template getLastProp<1>() = - sin(domain.getLastPos()[0]) - sin(domain.getLastPos()[1]);
138 domain.template getLastProp<4>()[0] = -sin(domain.getLastPos()[0]);
139 domain.template getLastProp<4>()[1] = -sin(domain.getLastPos()[1]);
144 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
147 domain.ghost_get<0>();
149 Laplacian
Lap(domain, 2, rCut);
150 auto v = getV<1>(domain);
151 auto P = getV<0>(domain);
152 auto vv = getV<2>(domain);
153 auto errv = getV<3>(domain);
156 auto it2 = domain.getDomainIterator();
160 while (it2.isNext()) {
163 if (fabs(domain.getProp<1>(p) - domain.getProp<2>(p)) > worst) {
164 worst = fabs(domain.getProp<1>(p) - domain.getProp<2>(p));
170 domain.deleteGhost();
171 BOOST_REQUIRE(worst < 0.3);
174 BOOST_AUTO_TEST_CASE(dcpse_op_div) {
177 size_t edgeSemiSize = 31;
178 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
180 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
182 spacing[0] = box.getHigh(0) / (sz[0] - 1);
183 spacing[1] = box.getHigh(1) / (sz[1] - 1);
184 double rCut = 3.1* spacing[0];
186 BOOST_TEST_MESSAGE(
"Init vector_dist...");
187 double sigma2 = spacing[0] * spacing[1] / (2 * 4);
189 vector_dist<2, double, aggregate<double, VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,double,
double>> domain(
193 BOOST_TEST_MESSAGE(
"Init domain...");
196 std::mt19937 rng{6666666};
198 std::normal_distribution<> gaussian{0, sigma2};
200 auto it = domain.getGridIterator(sz);
203 double minNormOne = 999;
204 while (it.isNext()) {
207 mem_id k0 = key.get(0);
208 double x = k0 * spacing[0];
209 domain.getLastPos()[0] = x;
210 mem_id k1 = key.get(1);
211 double y = k1 * spacing[1];
212 domain.getLastPos()[1] = y;
214 domain.template getLastProp<1>()[0] = sin(domain.getLastPos()[0]) + sin(domain.getLastPos()[1]);
215 domain.template getLastProp<1>()[1] = cos(domain.getLastPos()[0]) + cos(domain.getLastPos()[1]);
219 domain.template getLastProp<0>()= cos(domain.getLastPos()[0]) - sin(domain.getLastPos()[1]);
231 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
234 domain.ghost_get<0>();
236 Divergence Div(domain, 2, rCut);
237 Derivative_x Dx(domain, 2, rCut);
238 Derivative_y Dy(domain, 2, rCut);
240 auto v = getV<1>(domain);
241 auto anasol = getV<0>(domain);
242 auto div = getV<5>(domain);
243 auto div2 = getV<6>(domain);
245 domain.ghost_get<1>();
247 div2=Dx(v[0])+Dy(v[1]);
248 auto it2 = domain.getDomainIterator();
253 while (it2.isNext()) {
255 if (fabs(domain.getProp<0>(p) - domain.getProp<5>(p)) > worst1) {
256 worst1 = fabs(domain.getProp<0>(p) - domain.getProp<5>(p));
258 if (fabs(domain.getProp<0>(p) - domain.getProp<6>(p)) > worst2) {
259 worst2 = fabs(domain.getProp<0>(p) - domain.getProp<6>(p));
264 domain.deleteGhost();
271 BOOST_REQUIRE(worst1 < 0.05);
272 BOOST_REQUIRE(worst2 < 0.05);
276 BOOST_AUTO_TEST_CASE(dcpse_op_vec) {
279 size_t edgeSemiSize = 160;
280 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
282 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
284 spacing[0] = box.getHigh(0) / (sz[0] - 1);
285 spacing[1] = box.getHigh(1) / (sz[1] - 1);
287 double rCut = 3.1 * spacing[0];
288 BOOST_TEST_MESSAGE(
"Init vector_dist...");
289 double sigma2 = spacing[0] * spacing[1] / (2 * 4);
291 vector_dist<2, double, aggregate<double, VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,double,
double>> domain(
295 BOOST_TEST_MESSAGE(
"Init domain...");
298 std::mt19937 rng{6666666};
300 std::normal_distribution<> gaussian{0, sigma2};
302 auto it = domain.getGridIterator(sz);
305 double minNormOne = 999;
306 while (it.isNext()) {
309 mem_id k0 = key.get(0);
310 double x = k0 * spacing[0];
311 domain.getLastPos()[0] = x;
312 mem_id k1 = key.get(1);
313 double y = k1 * spacing[1];
314 domain.getLastPos()[1] = y;
316 domain.template getLastProp<0>() = sin(domain.getLastPos()[0]) + sin(domain.getLastPos()[1]);
317 domain.template getLastProp<1>()[0] = sin(domain.getLastPos()[0]) + sin(domain.getLastPos()[1]);
318 domain.template getLastProp<1>()[1] = cos(domain.getLastPos()[0]) + cos(domain.getLastPos()[1]);
321 domain.template getLastProp<2>()[0] = 0;
322 domain.template getLastProp<2>()[1] = 0;
323 domain.template getLastProp<4>()[0] =
324 cos(domain.getLastPos()[0]) * (sin(domain.getLastPos()[0]) + sin(domain.getLastPos()[1])) +
325 cos(domain.getLastPos()[1]) * (cos(domain.getLastPos()[0]) + cos(domain.getLastPos()[1]));
326 domain.template getLastProp<4>()[1] =
327 -sin(domain.getLastPos()[0]) * (sin(domain.getLastPos()[0]) + sin(domain.getLastPos()[1])) -
328 sin(domain.getLastPos()[1]) * (cos(domain.getLastPos()[0]) + cos(domain.getLastPos()[1]));
330 domain.template getLastProp<5>() = cos(domain.getLastPos()[0])*(sin(domain.getLastPos()[0]) + sin(domain.getLastPos()[1]))+cos(domain.getLastPos()[1]) * (cos(domain.getLastPos()[0]) + cos(domain.getLastPos()[1]));
336 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
339 domain.ghost_get<0>();
341 Advection Adv(domain, 2, rCut);
342 auto v = getV<1>(domain);
343 auto P = getV<0>(domain);
344 auto dv = getV<3>(domain);
345 auto dP = getV<6>(domain);
348 domain.ghost_get<1>();
350 auto it2 = domain.getDomainIterator();
354 while (it2.isNext()) {
357 if (fabs(domain.getProp<3>(p)[1] - domain.getProp<4>(p)[1]) > worst1) {
358 worst1 = fabs(domain.getProp<3>(p)[1] - domain.getProp<4>(p)[1]);
367 BOOST_REQUIRE(worst1 < 0.03);
371 auto it3 = domain.getDomainIterator();
375 while (it3.isNext()) {
377 if (fabs(domain.getProp<6>(p) - domain.getProp<5>(p)) > worst2) {
378 worst2 = fabs(domain.getProp<6>(p) - domain.getProp<5>(p));
386 domain.deleteGhost();
388 BOOST_REQUIRE(worst2 < 0.03);
393 BOOST_AUTO_TEST_CASE(dcpse_slice) {
394 const size_t sz[2] = {31,31};
396 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
397 double spacing = box.getHigh(0) / (sz[0] - 1);
399 double rCut = 3.9 * spacing;
403 auto it = Particles.getGridIterator(sz);
404 while (it.isNext()) {
407 double x = key.get(0) * it.getSpacing(0);
408 Particles.getLastPos()[0] = x;
409 double y = key.get(1) * it.getSpacing(1);
410 Particles.getLastPos()[1] = y;
412 Particles.getLastProp<1>()[0] = sin(x+y);
413 Particles.getLastProp<1>()[1] = cos(x+y);
419 Particles.ghost_get<0,1>();
422 auto P = getV<0>(Particles);
423 auto V = getV<1>(Particles);
424 auto S = getV<2>(Particles);
425 auto Sig = getV<3>(Particles);
428 Derivative_x Dx(Particles, 2, rCut,2);
431 S = V[0]*V[0] + V[1]*V[1];
433 Sig[0][1] = V[0]*V[0] + V[1]*V[1];
437 auto it2 = Particles.getDomainIterator();
445 if (fabs(Particles.getProp<0>(p) - Particles.getProp<1>(p)[1]) >= err )
447 err = fabs(Particles.getProp<0>(p) - Particles.getProp<1>(p)[1]);
450 if (fabs(Particles.getProp<2>(p) - 1.0) >= err )
452 err = fabs(Particles.getProp<2>(p) - 1.0);
455 if (fabs(Particles.getProp<3>(p)[0][1] - 1.0) >= err )
457 err = fabs(Particles.getProp<3>(p)[0][1] - 1.0);
460 if (fabs(Particles.getProp<3>(p)[1][0] - Particles.getProp<1>(p)[1]) >= err )
462 err = fabs(Particles.getProp<3>(p)[1][0] - Particles.getProp<1>(p)[1]);
465 if (fabs(Particles.getProp<3>(p)[2][2] - 5.0) >= err )
467 err = fabs(Particles.getProp<3>(p)[2][2] - 5.0);
475 BOOST_REQUIRE(err < 0.03);
479 BOOST_AUTO_TEST_CASE(dcpse_slice_3d) {
480 const size_t sz[3] = {17,17,17};
482 size_t bc[3] = {NON_PERIODIC, NON_PERIODIC,NON_PERIODIC};
483 double spacing = box.getHigh(0) / (sz[0] - 1);
485 double rCut = 3.9 * spacing;
489 auto it = Particles.getGridIterator(sz);
490 while (it.isNext()) {
493 double x = key.get(0) * it.getSpacing(0);
494 Particles.getLastPos()[0] = x;
495 double y = key.get(1) * it.getSpacing(1);
496 Particles.getLastPos()[1] = y;
497 double z = key.get(2) * it.getSpacing(2);
498 Particles.getLastPos()[2] = z;
500 Particles.getLastProp<1>()[0] = sin(x+y);
501 Particles.getLastProp<1>()[1] = cos(x+y);
502 Particles.getLastProp<1>()[2] = 1.0;
508 Particles.ghost_get<0,1>();
511 auto P = getV<0>(Particles);
512 auto V = getV<1>(Particles);
513 auto S = getV<2>(Particles);
514 auto Sig = getV<3>(Particles);
517 Derivative_x Dx(Particles, 2, rCut,2);
520 S = V[0]*V[0] + V[1]*V[1]+V[2]*V[2];
522 Sig[0][1] = V[0]*V[0] + V[1]*V[1]+V[2]*V[2];
526 auto it2 = Particles.getDomainIterator();
539 if (fabs(Particles.getProp<0>(p) - Particles.getProp<1>(p)[1]) >= err1 )
541 err1 = fabs(Particles.getProp<0>(p) - Particles.getProp<1>(p)[1]);
544 if (fabs(Particles.getProp<2>(p) - 2.0) >= err2 )
546 err2 = fabs(Particles.getProp<2>(p) - 2.0);
549 if (fabs(Particles.getProp<3>(p)[0][1] - 2.0) >= err3 )
551 err3 = fabs(Particles.getProp<3>(p)[0][1] - 2.0);
555 if (fabs(Particles.getProp<3>(p)[0][1] - Particles.getProp<2>(p)) >= err4 )
557 err4 = fabs(Particles.getProp<3>(p)[0][1] - Particles.getProp<2>(p));
560 if (fabs(Particles.getProp<3>(p)[2][2] - 5.0) >= err5 )
562 err5 = fabs(Particles.getProp<3>(p)[2][2] - 5.0);
569 BOOST_REQUIRE(err1 < 0.08);
570 BOOST_REQUIRE(err2 < 0.03);
571 BOOST_REQUIRE(err3 < 0.03);
572 BOOST_REQUIRE(err4 < 0.03);
573 BOOST_REQUIRE(err5 < 0.03);
576 BOOST_AUTO_TEST_CASE(dcpse_op_convection) {
577 size_t edgeSemiSize = 20;
578 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
580 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
582 spacing[0] = 2.0/ (sz[0] - 1);
583 spacing[1] = 2.0 / (sz[1] - 1);
584 double rCut = 3.1 * spacing[0];
587 BOOST_TEST_MESSAGE(
"Init vector_dist...");
591 domain.setPropNames({
"Concentration",
"Concentration_temp",
"Temp",
"Velocity"});
594 BOOST_TEST_MESSAGE(
"Init domain...");
596 auto it = domain.getGridIterator(sz);
597 while (it.isNext()) {
600 mem_id k0 = key.get(0);
601 double x = -1.0+k0 * spacing[0];
602 domain.getLastPos()[0] = x;
603 mem_id k1 = key.get(1);
604 double y = -1.0+k1 * spacing[1];
605 domain.getLastPos()[1] = y;
607 if (x>-1 && y>-1 && x<1 && y<1)
609 domain.template getLastProp<3>()[0] = (-y)*exp(-10*((x)*(x)+(y)*(y)));;
610 domain.template getLastProp<3>()[1] = (x)*exp(-10*((x)*(x)+(y)*(y)));;
613 domain.template getLastProp<3>()[0] = 0.0;
614 domain.template getLastProp<3>()[1] = 0.0;
616 if (x==0.0 && y>-0.5 && y<0.5)
618 domain.template getLastProp<0>() = 1.0;
622 domain.template getLastProp<0>() = 0.0;
626 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
629 domain.ghost_get<0>();
632 Derivative_xx Dxx(domain, 2, rCut);
634 Derivative_yy Dyy(domain, 2, rCut);
635 auto C = getV<0>(domain);
636 auto V = getV<3>(domain);
637 auto Cnew = getV<1>(domain);
638 auto Pos = getV<PROP_POS>(domain);
642 double t=0,tf=1,dt=1e-2;
645 domain.write_frame(
"Convection",ctr);
646 domain.ghost_get<0>();
647 Cnew=C+dt*0.01*(Dxx(C)+Dyy(C));
651 domain.ghost_get<0>();
652 auto it2 = domain.getDomainIterator();
653 while (it2.isNext()) {
656 double x=xp[0],y=xp[1];
657 if (x>-1 && y>-1 && x<1 && y<1)
659 domain.template getProp<3>(p)[0] = (-y)*exp(-10*((x)*(x)+(y)*(y)));
660 domain.template getProp<3>(p)[1] = (x)*exp(-10*((x)*(x)+(y)*(y)));;
663 domain.template getProp<3>(p)[0] = 0.0;
664 domain.template getProp<3>(p)[1] = 0.0;
677 Dxx.deallocate(domain);
678 Dyy.deallocate(domain);
708 BOOST_AUTO_TEST_SUITE_END()
This class implement the point shape in an N-dimensional space.
void start()
Start the timer.
Laplacian second order on h (spacing)
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.
Class for cpu time benchmarking.
void stop()
Stop the timer.