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/DCPSE_op/DCPSE_op.hpp"
22 #include "DCPSE/DCPSE_op/DCPSE_Solver.hpp"
23 #include "Operators/Vector/vector_dist_operators.hpp"
24 #include "Vector/vector_dist_subset.hpp"
25 #include "DCPSE/DCPSE_op/EqnsStruct.hpp"
26 #include "DCPSE/DcpseInterpolation.hpp"
28 BOOST_AUTO_TEST_SUITE(dcpse_op_suite_tests_cu)
29 BOOST_AUTO_TEST_CASE(dcpse_op_tests) {
30 size_t edgeSemiSize = 40;
31 const size_t sz[2] = {2 * edgeSemiSize, 2 * edgeSemiSize};
33 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
35 spacing[0] = 2 * M_PI / (sz[0] - 1);
36 spacing[1] = 2 * M_PI / (sz[1] - 1);
38 double rCut = 3.9 * spacing[0];
39 BOOST_TEST_MESSAGE(
"Init vector_dist...");
40 double sigma2 = spacing[0] * spacing[1] / (2 * 4);
42 vector_dist_gpu<2, double, aggregate<double, double, double, VectorS<2, double>,
VectorS<2, double>>> domain(0, box,
47 BOOST_TEST_MESSAGE(
"Init domain...");
49 auto it = domain.getGridIterator(sz);
52 double minNormOne = 999;
56 mem_id k0 = key.get(0);
57 double x = k0 * spacing[0];
58 domain.getLastPos()[0] = x;
59 mem_id k1 = key.get(1);
60 double y = k1 * spacing[1];
61 domain.getLastPos()[1] = y;
63 domain.template getLastProp<0>() = sin(domain.getLastPos()[0]) + sin(domain.getLastPos()[1]);
64 domain.template getLastProp<2>() = 2*cos(domain.getLastPos()[0]) + cos(domain.getLastPos()[1]);
68 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
71 domain.ghost_get<0>();
73 auto verletList = domain.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
75 Derivative_x_gpu<decltype(verletList)> Dx(domain, verletList, 2, rCut);
76 Derivative_y_gpu<decltype(verletList)> Dy(domain, verletList, 2, rCut);
77 Gradient_gpu<decltype(verletList)> Grad(domain, verletList, 2, rCut);
78 Laplacian_gpu<decltype(verletList)>
Lap(domain, verletList, 2, rCut);
79 auto v = getV<1>(domain);
80 auto P = getV<0>(domain);
83 auto it2 = domain.getDomainIterator();
87 while (it2.isNext()) {
90 if (fabs(domain.getProp<1>(p) - domain.getProp<2>(p)) > worst) {
91 worst = fabs(domain.getProp<1>(p) - domain.getProp<2>(p));
98 BOOST_REQUIRE(worst < 0.03);
101 BOOST_AUTO_TEST_CASE(dcpse_op_test_lap) {
102 size_t edgeSemiSize = 81;
103 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
105 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
107 spacing[0] = 2 * M_PI / (sz[0] - 1);
108 spacing[1] = 2 * M_PI / (sz[1] - 1);
110 double rCut = 3.9 * spacing[0];
111 BOOST_TEST_MESSAGE(
"Init vector_dist...");
112 double sigma2 = spacing[0] * spacing[1] / (2 * 4);
119 BOOST_TEST_MESSAGE(
"Init domain...");
120 std::normal_distribution<> gaussian{0, sigma2};
122 auto it = domain.getGridIterator(sz);
125 double minNormOne = 999;
126 while (it.isNext()) {
129 mem_id k0 = key.get(0);
130 double x = k0 * spacing[0];
131 domain.getLastPos()[0] = x;
132 mem_id k1 = key.get(1);
133 double y = k1 * spacing[1];
134 domain.getLastPos()[1] = y;
136 domain.template getLastProp<0>() = sin(domain.getLastPos()[0]) + sin(domain.getLastPos()[1]);
138 domain.template getLastProp<1>() = - sin(domain.getLastPos()[0]) - sin(domain.getLastPos()[1]);
139 domain.template getLastProp<4>()[0] = -sin(domain.getLastPos()[0]);
140 domain.template getLastProp<4>()[1] = -sin(domain.getLastPos()[1]);
145 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
148 domain.ghost_get<0>();
150 auto verletList = domain.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
152 Laplacian_gpu<decltype(verletList)>
Lap(domain, verletList, 2, rCut);
153 auto v = getV<1>(domain);
154 auto P = getV<0>(domain);
155 auto vv = getV<2>(domain);
156 auto errv = getV<3>(domain);
159 auto it2 = domain.getDomainIterator();
163 while (it2.isNext()) {
166 if (fabs(domain.getProp<1>(p) - domain.getProp<2>(p)) > worst) {
167 worst = fabs(domain.getProp<1>(p) - domain.getProp<2>(p));
173 domain.deleteGhost();
174 BOOST_REQUIRE(worst < 0.3);
177 BOOST_AUTO_TEST_CASE(dcpse_op_div) {
180 size_t edgeSemiSize = 31;
181 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
183 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
185 spacing[0] = box.getHigh(0) / (sz[0] - 1);
186 spacing[1] = box.getHigh(1) / (sz[1] - 1);
187 double rCut = 3.1* spacing[0];
189 BOOST_TEST_MESSAGE(
"Init vector_dist...");
190 double sigma2 = spacing[0] * spacing[1] / (2 * 4);
192 vector_dist_gpu<2, double, aggregate<double, VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,double,
double>> domain(
196 BOOST_TEST_MESSAGE(
"Init domain...");
199 std::mt19937 rng{6666666};
201 std::normal_distribution<> gaussian{0, sigma2};
203 auto it = domain.getGridIterator(sz);
206 double minNormOne = 999;
207 while (it.isNext()) {
210 mem_id k0 = key.get(0);
211 double x = k0 * spacing[0];
212 domain.getLastPos()[0] = x;
213 mem_id k1 = key.get(1);
214 double y = k1 * spacing[1];
215 domain.getLastPos()[1] = y;
217 domain.template getLastProp<1>()[0] = sin(domain.getLastPos()[0]) + sin(domain.getLastPos()[1]);
218 domain.template getLastProp<1>()[1] = cos(domain.getLastPos()[0]) + cos(domain.getLastPos()[1]);
222 domain.template getLastProp<0>()= cos(domain.getLastPos()[0]) - sin(domain.getLastPos()[1]);
234 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
237 domain.ghost_get<0>();
239 auto verletList = domain.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
241 Divergence_gpu<decltype(verletList)> Div(domain, verletList, 2, rCut);
242 Derivative_x_gpu<decltype(verletList)> Dx(domain, verletList, 2, rCut);
243 Derivative_y_gpu<decltype(verletList)> Dy(domain, verletList, 2, rCut);
245 auto v = getV<1>(domain);
246 auto anasol = getV<0>(domain);
247 auto div = getV<5>(domain);
248 auto div2 = getV<6>(domain);
250 domain.ghost_get<1>();
269 domain.deleteGhost();
281 BOOST_AUTO_TEST_CASE(dcpse_op_vec) {
284 size_t edgeSemiSize = 160;
285 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
287 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
289 spacing[0] = box.getHigh(0) / (sz[0] - 1);
290 spacing[1] = box.getHigh(1) / (sz[1] - 1);
292 double rCut = 3.1 * spacing[0];
293 BOOST_TEST_MESSAGE(
"Init vector_dist...");
294 double sigma2 = spacing[0] * spacing[1] / (2 * 4);
296 vector_dist_gpu<2, double, aggregate<double, VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,double,
double>> domain(
300 BOOST_TEST_MESSAGE(
"Init domain...");
301 std::random_device rd{};
303 std::mt19937 rng{6666666};
305 std::normal_distribution<> gaussian{0, sigma2};
307 auto it = domain.getGridIterator(sz);
310 double minNormOne = 999;
311 while (it.isNext()) {
314 mem_id k0 = key.get(0);
315 double x = k0 * spacing[0];
316 domain.getLastPos()[0] = x;
317 mem_id k1 = key.get(1);
318 double y = k1 * spacing[1];
319 domain.getLastPos()[1] = y;
321 domain.template getLastProp<0>() = sin(domain.getLastPos()[0]) + sin(domain.getLastPos()[1]);
322 domain.template getLastProp<1>()[0] = sin(domain.getLastPos()[0]) + sin(domain.getLastPos()[1]);
323 domain.template getLastProp<1>()[1] = cos(domain.getLastPos()[0]) + cos(domain.getLastPos()[1]);
326 domain.template getLastProp<2>()[0] = 0;
327 domain.template getLastProp<2>()[1] = 0;
328 domain.template getLastProp<4>()[0] =
329 cos(domain.getLastPos()[0]) * (sin(domain.getLastPos()[0]) + sin(domain.getLastPos()[1])) +
330 cos(domain.getLastPos()[1]) * (cos(domain.getLastPos()[0]) + cos(domain.getLastPos()[1]));
331 domain.template getLastProp<4>()[1] =
332 -sin(domain.getLastPos()[0]) * (sin(domain.getLastPos()[0]) + sin(domain.getLastPos()[1])) -
333 sin(domain.getLastPos()[1]) * (cos(domain.getLastPos()[0]) + cos(domain.getLastPos()[1]));
335 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]));
341 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
344 domain.ghost_get<0>();
346 auto verletList = domain.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
348 Advection_gpu<decltype(verletList)> Adv(domain, verletList, 2, rCut);
349 auto v = getV<1>(domain);
350 auto P = getV<0>(domain);
351 auto dv = getV<3>(domain);
352 auto dP = getV<6>(domain);
355 domain.ghost_get<1>();
357 auto it2 = domain.getDomainIterator();
361 while (it2.isNext()) {
364 if (fabs(domain.getProp<3>(p)[1] - domain.getProp<4>(p)[1]) > worst1) {
365 worst1 = fabs(domain.getProp<3>(p)[1] - domain.getProp<4>(p)[1]);
374 BOOST_REQUIRE(worst1 < 0.03);
378 auto it3 = domain.getDomainIterator();
382 while (it3.isNext()) {
384 if (fabs(domain.getProp<6>(p) - domain.getProp<5>(p)) > worst2) {
385 worst2 = fabs(domain.getProp<6>(p) - domain.getProp<5>(p));
393 domain.deleteGhost();
395 BOOST_REQUIRE(worst2 < 0.03);
400 BOOST_AUTO_TEST_CASE(dcpse_slice) {
401 const size_t sz[2] = {31,31};
403 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
404 double spacing = box.getHigh(0) / (sz[0] - 1);
406 double rCut = 3.9 * spacing;
410 auto it = Particles.getGridIterator(sz);
411 while (it.isNext()) {
414 double x = key.get(0) * it.getSpacing(0);
415 Particles.getLastPos()[0] = x;
416 double y = key.get(1) * it.getSpacing(1);
417 Particles.getLastPos()[1] = y;
419 Particles.getLastProp<1>()[0] = sin(x+y);
420 Particles.getLastProp<1>()[1] = cos(x+y);
426 Particles.ghost_get<0,1>();
428 auto P = getV<0>(Particles);
429 auto V = getV<1>(Particles);
430 auto S = getV<2>(Particles);
431 auto Sig = getV<3>(Particles);
433 auto verletList = Particles.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
435 Derivative_x_gpu<decltype(verletList)> Dx(Particles, verletList, 2, rCut);
438 S = V[0]*V[0] + V[1]*V[1];
440 Sig[0][1] = V[0]*V[0] + V[1]*V[1];
444 auto it2 = Particles.getDomainIterator();
452 if (fabs(Particles.getProp<0>(p) - Particles.getProp<1>(p)[1]) >= err )
454 err = fabs(Particles.getProp<0>(p) - Particles.getProp<1>(p)[1]);
457 if (fabs(Particles.getProp<2>(p) - 1.0) >= err )
459 err = fabs(Particles.getProp<2>(p) - 1.0);
462 if (fabs(Particles.getProp<3>(p)[0][1] - 1.0) >= err )
464 err = fabs(Particles.getProp<3>(p)[0][1] - 1.0);
467 if (fabs(Particles.getProp<3>(p)[1][0] - Particles.getProp<1>(p)[1]) >= err )
469 err = fabs(Particles.getProp<3>(p)[1][0] - Particles.getProp<1>(p)[1]);
472 if (fabs(Particles.getProp<3>(p)[2][2] - 5.0) >= err )
474 err = fabs(Particles.getProp<3>(p)[2][2] - 5.0);
482 BOOST_REQUIRE(err < 0.03);
485 BOOST_AUTO_TEST_CASE(dcpse_slice_3d) {
486 const size_t sz[3] = {17,17,17};
488 size_t bc[3] = {NON_PERIODIC, NON_PERIODIC,NON_PERIODIC};
489 double spacing = box.getHigh(0) / (sz[0] - 1);
491 double rCut = 3.9 * spacing;
495 auto it = Particles.getGridIterator(sz);
496 while (it.isNext()) {
499 double x = key.get(0) * it.getSpacing(0);
500 Particles.getLastPos()[0] = x;
501 double y = key.get(1) * it.getSpacing(1);
502 Particles.getLastPos()[1] = y;
503 double z = key.get(2) * it.getSpacing(2);
504 Particles.getLastPos()[2] = z;
506 Particles.getLastProp<1>()[0] = sin(x+y);
507 Particles.getLastProp<1>()[1] = cos(x+y);
508 Particles.getLastProp<1>()[2] = 1.0;
514 Particles.ghost_get<0,1>();
517 auto P = getV<0>(Particles);
518 auto V = getV<1>(Particles);
519 auto S = getV<2>(Particles);
520 auto Sig = getV<3>(Particles);
522 auto verletList = Particles.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
524 Derivative_x_gpu<decltype(verletList)> Dx(Particles, verletList, 2, rCut);
527 S = V[0]*V[0] + V[1]*V[1]+V[2]*V[2];
529 Sig[0][1] = V[0]*V[0] + V[1]*V[1]+V[2]*V[2];
533 auto it2 = Particles.getDomainIterator();
546 if (fabs(Particles.getProp<0>(p) - Particles.getProp<1>(p)[1]) >= err1 )
548 err1 = fabs(Particles.getProp<0>(p) - Particles.getProp<1>(p)[1]);
551 if (fabs(Particles.getProp<2>(p) - 2.0) >= err2 )
553 err2 = fabs(Particles.getProp<2>(p) - 2.0);
556 if (fabs(Particles.getProp<3>(p)[0][1] - 2.0) >= err3 )
558 err3 = fabs(Particles.getProp<3>(p)[0][1] - 2.0);
562 if (fabs(Particles.getProp<3>(p)[0][1] - Particles.getProp<2>(p)) >= err4 )
564 err4 = fabs(Particles.getProp<3>(p)[0][1] - Particles.getProp<2>(p));
567 if (fabs(Particles.getProp<3>(p)[2][2] - 5.0) >= err5 )
569 err5 = fabs(Particles.getProp<3>(p)[2][2] - 5.0);
576 BOOST_REQUIRE(err1 < 0.08);
577 BOOST_REQUIRE(err2 < 0.03);
578 BOOST_REQUIRE(err3 < 0.03);
579 BOOST_REQUIRE(err4 < 0.03);
580 BOOST_REQUIRE(err5 < 0.03);
583 BOOST_AUTO_TEST_CASE(dcpse_op_convection) {
584 size_t edgeSemiSize = 20;
585 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
587 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
589 spacing[0] = 2.0/ (sz[0] - 1);
590 spacing[1] = 2.0 / (sz[1] - 1);
591 double rCut = 3.1 * spacing[0];
594 BOOST_TEST_MESSAGE(
"Init vector_dist...");
598 domain.setPropNames({
"Concentration",
"Concentration_temp",
"Temp",
"Velocity"});
601 BOOST_TEST_MESSAGE(
"Init domain...");
603 auto it = domain.getGridIterator(sz);
604 while (it.isNext()) {
607 mem_id k0 = key.get(0);
608 double x = -1.0+k0 * spacing[0];
609 domain.getLastPos()[0] = x;
610 mem_id k1 = key.get(1);
611 double y = -1.0+k1 * spacing[1];
612 domain.getLastPos()[1] = y;
614 if (x>-1 && y>-1 && x<1 && y<1)
616 domain.template getLastProp<3>()[0] = (-y)*exp(-10*((x)*(x)+(y)*(y)));;
617 domain.template getLastProp<3>()[1] = (x)*exp(-10*((x)*(x)+(y)*(y)));;
620 domain.template getLastProp<3>()[0] = 0.0;
621 domain.template getLastProp<3>()[1] = 0.0;
623 if (x==0.0 && y>-0.5 && y<0.5)
625 domain.template getLastProp<0>() = 1.0;
629 domain.template getLastProp<0>() = 0.0;
633 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
636 domain.ghost_get<0>();
638 auto verletList = domain.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
641 Derivative_xx_gpu<decltype(verletList)> Dxx(domain, verletList, 2, rCut);
643 Derivative_yy_gpu<decltype(verletList)> Dyy(domain, verletList, 2, rCut);
644 auto C = getV<0>(domain);
645 auto V = getV<3>(domain);
646 auto Cnew = getV<1>(domain);
647 auto Pos = getV<POS_PROP>(domain);
651 double t=0,tf=1,dt=1e-2;
654 domain.write_frame(
"Convection",ctr);
655 domain.ghost_get<0>();
656 Cnew=C+dt*0.01*(Dxx(C)+Dyy(C));
660 domain.ghost_get<0>();
661 auto it2 = domain.getDomainIterator();
662 while (it2.isNext()) {
665 double x=xp[0],y=xp[1];
666 if (x>-1 && y>-1 && x<1 && y<1)
668 domain.template getProp<3>(p)[0] = (-y)*exp(-10*((x)*(x)+(y)*(y)));
669 domain.template getProp<3>(p)[1] = (x)*exp(-10*((x)*(x)+(y)*(y)));;
672 domain.template getProp<3>(p)[0] = 0.0;
673 domain.template getProp<3>(p)[1] = 0.0;
686 Dxx.deallocate(domain);
687 Dyy.deallocate(domain);
717 BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
Laplacian second order on h (spacing)
Test structure used for several test.
This class implement the point shape in an N-dimensional space.
Class for cpu time benchmarking.
void stop()
Stop the timer.
void start()
Start the timer.