13 #define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
14 #define BOOST_MPL_LIMIT_VECTOR_SIZE 40
18 #define BOOST_TEST_DYN_LINK
20 #include "util/util_debug.hpp"
21 #include <boost/test/unit_test.hpp>
23 #include "DCPSE/DCPSE_op/DCPSE_op.hpp"
24 #include "DCPSE/DCPSE_op/DCPSE_Solver.hpp"
25 #include "Operators/Vector/vector_dist_operators.hpp"
26 #include "Vector/vector_dist_subset.hpp"
27 #include "DCPSE/DCPSE_op/EqnsStruct.hpp"
28 #include "Decomposition/Distribution/SpaceDistribution.hpp"
30 BOOST_AUTO_TEST_SUITE(dcpse_op_suite_tests)
32 BOOST_AUTO_TEST_CASE(dcpse_op_solver) {
35 const size_t sz[2] = {31, 31};
37 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
38 double spacing = box.getHigh(0) / (sz[0] - 1);
40 double rCut = 4.0 * spacing;
41 BOOST_TEST_MESSAGE(
"Init vector_dist...");
47 BOOST_TEST_MESSAGE(
"Init domain...");
49 auto it = domain.getGridIterator(sz);
54 double x = key.get(0) * it.getSpacing(0);
55 domain.getLastPos()[0] = x;
56 double y = key.get(1) * it.getSpacing(1);
57 domain.getLastPos()[1] = y;
61 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
64 domain.ghost_get<0>();
66 auto verletList = domain.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
67 Laplacian<decltype(verletList)>
Lap(domain, verletList, 2, rCut, support_options::RADIUS);
69 DCPSE_scheme<
equations2d1,decltype(domain)> Solver(domain);
77 auto v = getV<0>(domain);
78 auto RHS = getV<1>(domain);
79 auto sol = getV<2>(domain);
80 auto anasol = getV<3>(domain);
84 Box<2, double> up({box.getLow(0) - spacing / 2.0, box.getHigh(1) - spacing / 2.0},
85 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) + spacing / 2.0});
87 Box<2, double> up_d({box.getLow(0) - spacing / 2.0, box.getHigh(1) - 8*spacing / 2.0},
88 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - 6*spacing / 2.0});
90 Box<2, double> down({box.getLow(0) - spacing / 2.0, box.getLow(1) - spacing / 2.0},
91 {box.getHigh(0) + spacing / 2.0, box.getLow(1) + spacing / 2.0});
93 Box<2, double> down_u({box.getLow(0) - spacing / 2.0, box.getLow(1) + 3*spacing / 2.0},
94 {box.getHigh(0) + spacing / 2.0, box.getLow(1) + 4*spacing / 2.0});
96 Box<2, double> left({box.getLow(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
97 {box.getLow(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
99 Box<2, double> left_r({box.getLow(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
100 {box.getLow(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
102 Box<2, double> right({box.getHigh(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
103 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
105 Box<2, double> right_l({box.getHigh(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
106 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
122 vtk_box.write(
"vtk_box.vtk");
124 auto it2 = domain.getDomainIterator();
126 while (it2.isNext()) {
129 domain.getProp<2>(p)=1+xp[0]*xp[0]+2*xp[1]*xp[1];
130 if (up.isInside(xp) ==
true) {
132 up_p.last().get<0>() = p.getKey();
133 domain.getProp<1>(p) = 3 + xp.
get(0)*xp.
get(0);
134 }
else if (down.isInside(xp) ==
true) {
136 dw_p.last().get<0>() = p.getKey();
137 domain.getProp<1>(p) = 1 + xp.
get(0)*xp.
get(0);
138 }
else if (left.isInside(xp) ==
true) {
140 l_p.last().get<0>() = p.getKey();
141 domain.getProp<1>(p) = 1 + 2*xp.
get(1)*xp.
get(1);
142 }
else if (right.isInside(xp) ==
true) {
144 r_p.last().get<0>() = p.getKey();
145 domain.getProp<1>(p) = 2 + 2*xp.
get(1)*xp.
get(1);
148 bulk.last().get<0>() = p.getKey();
158 Solver.impose(eq1, bulk, 6);
159 Solver.impose(v, up_p, RHS);
160 Solver.impose(v, dw_p, RHS);
168 it2 = domain.getDomainIterator();
170 while (it2.isNext()) {
172 if (fabs(domain.getProp<0>(p) - domain.getProp<2>(p)) >= worst1) {
173 worst1 = fabs(domain.getProp<0>(p) - domain.getProp<2>(p));
176 domain.getProp<1>(p) = fabs(domain.getProp<0>(p) - domain.getProp<2>(p));
181 domain.write(
"particles");
182 BOOST_REQUIRE(worst1 < 0.03);
187 BOOST_AUTO_TEST_CASE(dcpse_poisson_Robin_anal) {
190 const size_t sz[2] = {81,81};
192 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
193 double spacing = box.getHigh(0) / (sz[0] - 1);
195 double rCut = 3.1 * spacing;
196 BOOST_TEST_MESSAGE(
"Init vector_dist...");
198 vector_dist<2, double, aggregate<double,double,double,double,double,double>> domain(0, box, bc, ghost);
202 BOOST_TEST_MESSAGE(
"Init domain...");
204 auto it = domain.getGridIterator(sz);
205 while (it.isNext()) {
209 double x = key.get(0) * it.getSpacing(0);
210 domain.getLastPos()[0] = x;
211 double y = key.get(1) * it.getSpacing(1);
212 domain.getLastPos()[1] = y;
220 const size_t sz2[2] = {40,40};
221 Box<2,double> bx({0.25 + it.getSpacing(0)/4.0,0.25 + it.getSpacing(0)/4.0},{sz2[0]*it.getSpacing(0)/2.0 + 0.25 + it.getSpacing(0)/4.0, sz2[1]*it.getSpacing(0)/2.0 + 0.25 + it.getSpacing(0)/4.0});
224 auto it = domain.getDomainIterator();
232 if (bx.isInside(xp) ==
true)
242 auto it2 = domain.getGridIterator(sz2);
243 while (it2.isNext()) {
246 auto key = it2.get();
247 double x = key.get(0) * spacing/2.0 + 0.25 + spacing/4.0;
248 domain.getLastPos()[0] = x;
249 double y = key.get(1) * spacing/2.0 + 0.25 + spacing/4.0;
250 domain.getLastPos()[1] = y;
259 const size_t sz2[2] = {40,40};
260 Box<2,double> bx({0.25 + 21.0*spacing/8.0,0.25 + 21.0*spacing/8.0},{sz2[0]*spacing/4.0 + 0.25 + 21.0*spacing/8.0, sz2[1]*spacing/4.0 + 0.25 + 21*spacing/8.0});
263 auto it = domain.getDomainIterator();
271 if (bx.isInside(xp) ==
true)
281 auto it2 = domain.getGridIterator(sz2);
282 while (it2.isNext()) {
285 auto key = it2.get();
286 double x = key.get(0) * spacing/4.0 + 0.25 + 21*spacing/8.0;
287 domain.getLastPos()[0] = x;
288 double y = key.get(1) * spacing/4.0 + 0.25 + 21*spacing/8.0;
289 domain.getLastPos()[1] = y;
297 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
300 domain.ghost_get<0>();
302 auto verletList = domain.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
304 Derivative_x<decltype(verletList)> Dx(domain, verletList, 2, rCut, support_options::RADIUS);
305 Derivative_y<decltype(verletList)> Dy(domain, verletList, 2, rCut, support_options::RADIUS);
306 Laplacian<decltype(verletList)>
Lap(domain, verletList, 2, rCut, support_options::RADIUS);
315 auto v = getV<0>(domain);
316 auto RHS=getV<1>(domain);
317 auto sol = getV<2>(domain);
318 auto anasol = getV<3>(domain);
319 auto err = getV<4>(domain);
320 auto DCPSE_sol=getV<5>(domain);
324 Box<2, double> up({box.getLow(0) - spacing / 2.0, box.getHigh(1) - spacing / 2.0},
325 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) + spacing / 2.0});
327 Box<2, double> down({box.getLow(0) - spacing / 2.0, box.getLow(1) - spacing / 2.0},
328 {box.getHigh(0) + spacing / 2.0, box.getLow(1) + spacing / 2.0});
330 Box<2, double> left({box.getLow(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
331 {box.getLow(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
333 Box<2, double> right({box.getHigh(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
334 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
348 auto it2 = domain.getDomainIterator();
350 while (it2.isNext()) {
353 if (up.isInside(xp) ==
true) {
355 up_p.last().get<0>() = p.getKey();
356 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
357 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
358 }
else if (down.isInside(xp) ==
true) {
360 dw_p.last().get<0>() = p.getKey();
361 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
362 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
364 }
else if (left.isInside(xp) ==
true) {
366 l_p.last().get<0>() = p.getKey();
367 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
368 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
370 }
else if (right.isInside(xp) ==
true) {
372 r_p.last().get<0>() = p.getKey();
373 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
374 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
378 bulk.last().get<0>() = p.getKey();
379 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
380 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
385 domain.ghost_get<1,3>();
387 DCPSE_scheme<
equations2d1,decltype(domain)> Solver( domain);
388 auto Poisson =
Lap(v);
392 Solver.impose(D_y, up_p, 0);
393 Solver.impose(D_x, r_p, 0);
394 Solver.impose(v, dw_p, 0);
395 Solver.impose(v, l_p, 0);
402 Solver.solve_with_solver(solver,sol);
406 domain.ghost_get<2>();
409 domain.ghost_get<5>();
413 v=abs(DCPSE_sol-RHS);
415 for(
int j=0;j<bulk.
size();j++)
416 {
auto p=bulk.get<0>(j);
417 if (fabs(domain.getProp<3>(p) - domain.getProp<2>(p)) >= worst1) {
418 worst1 = fabs(domain.getProp<3>(p) - domain.getProp<2>(p));
420 domain.getProp<4>(p) = fabs(domain.getProp<3>(p) - domain.getProp<2>(p));
427 BOOST_REQUIRE(worst1 < 0.03);
437 BOOST_AUTO_TEST_CASE(dcpse_poisson_Dirichlet_anal) {
440 const size_t sz[2] = {81,81};
442 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
443 double spacing = box.getHigh(0) / (sz[0] - 1);
445 double rCut = 3.1 * spacing;
446 BOOST_TEST_MESSAGE(
"Init vector_dist...");
448 vector_dist<2, double, aggregate<double,double,double,double,double,double>> domain(0, box, bc, ghost);
452 BOOST_TEST_MESSAGE(
"Init domain...");
454 auto it = domain.getGridIterator(sz);
455 while (it.isNext()) {
459 double x = key.get(0) * it.getSpacing(0);
460 domain.getLastPos()[0] = x;
461 double y = key.get(1) * it.getSpacing(1);
462 domain.getLastPos()[1] = y;
466 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
469 domain.ghost_get<0>();
471 auto verletList = domain.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
473 Derivative_x<decltype(verletList)> Dx(domain, verletList, 2, rCut, support_options::RADIUS);
474 Derivative_y<decltype(verletList)> Dy(domain, verletList, 2, rCut, support_options::RADIUS);
475 Laplacian<decltype(verletList)>
Lap(domain, verletList, 2, rCut, support_options::RADIUS);
485 auto v = getV<0>(domain);
486 auto RHS=getV<1>(domain);
487 auto sol = getV<2>(domain);
488 auto anasol = getV<3>(domain);
489 auto err = getV<4>(domain);
490 auto DCPSE_sol=getV<5>(domain);
494 Box<2, double> up({box.getLow(0) - spacing / 2.0, box.getHigh(1) - spacing / 2.0},
495 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) + spacing / 2.0});
497 Box<2, double> down({box.getLow(0) - spacing / 2.0, box.getLow(1) - spacing / 2.0},
498 {box.getHigh(0) + spacing / 2.0, box.getLow(1) + spacing / 2.0});
500 Box<2, double> left({box.getLow(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
501 {box.getLow(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
503 Box<2, double> right({box.getHigh(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
504 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
518 auto it2 = domain.getDomainIterator();
520 while (it2.isNext()) {
523 if (up.isInside(xp) ==
true) {
525 up_p.last().get<0>() = p.getKey();
526 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
527 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
529 bulkF.last().get<0>() = p.getKey();
530 }
else if (down.isInside(xp) ==
true) {
532 dw_p.last().get<0>() = p.getKey();
533 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
534 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
536 bulkF.last().get<0>() = p.getKey();
538 }
else if (left.isInside(xp) ==
true) {
540 l_p.last().get<0>() = p.getKey();
541 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
542 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
544 bulkF.last().get<0>() = p.getKey();
546 }
else if (right.isInside(xp) ==
true) {
548 r_p.last().get<0>() = p.getKey();
549 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
550 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
552 bulkF.last().get<0>() = p.getKey();
556 bulk.last().get<0>() = p.getKey();
557 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
558 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
560 bulkF.last().get<0>() = p.getKey();
564 DCPSE_scheme<
equations2d1,decltype(domain)> Solver( domain);
565 auto Poisson =
Lap(v);
577 for (
int j = 0; j < up_p.
size(); j++) {
578 auto p = up_p.get<0>(j);
579 domain.getProp<5>(p) = 0;
581 for (
int j = 0; j < dw_p.
size(); j++) {
582 auto p = dw_p.get<0>(j);
583 domain.getProp<5>(p) = 0;
585 for (
int j = 0; j < l_p.
size(); j++) {
586 auto p = l_p.get<0>(j);
587 domain.getProp<5>(p) = 0;
589 for (
int j = 0; j < r_p.
size(); j++) {
590 auto p = r_p.get<0>(j);
591 domain.getProp<5>(p) = 0;
596 v=abs(DCPSE_sol-RHS);
598 for(
int j=0;j<bulkF.
size();j++)
599 {
auto p=bulkF.get<0>(j);
600 if (fabs(domain.getProp<3>(p) - domain.getProp<2>(p)) >= worst1) {
601 worst1 = fabs(domain.getProp<3>(p) - domain.getProp<2>(p));
603 domain.getProp<4>(p) = fabs(domain.getProp<3>(p) - domain.getProp<2>(p));
608 BOOST_REQUIRE(worst1 < 0.03);
614 BOOST_AUTO_TEST_CASE(dcpse_poisson_Periodic) {
618 const size_t sz[2] = {31,31};
620 size_t bc[2] = {PERIODIC, NON_PERIODIC};
621 double spacing = box.getHigh(0) / (sz[0] - 1);
623 double rCut = 3.1 * spacing;
624 BOOST_TEST_MESSAGE(
"Init vector_dist...");
626 vector_dist<2, double, aggregate<double,double,double,double,double,VectorS<2, double>>> domain(0, box, bc, ghost);
629 BOOST_TEST_MESSAGE(
"Init domain...");
631 auto it = domain.getGridIterator(sz);
632 while (it.isNext()) {
636 double x = key.get(0) * it.getSpacing(0);
637 domain.getLastPos()[0] = x;
638 double y = key.get(1) * it.getSpacing(1)*0.99999;
639 domain.getLastPos()[1] = y;
643 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
646 domain.ghost_get<0>();
648 auto verletList = domain.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
649 Laplacian<decltype(verletList)>
Lap(domain, verletList, 2, rCut, support_options::RADIUS);
651 DCPSE_scheme<
equations2d1p,decltype(domain)> Solver( domain);
659 auto v = getV<0>(domain);
660 auto RHS=getV<1>(domain);
661 auto sol = getV<2>(domain);
662 auto anasol = getV<3>(domain);
663 auto err = getV<4>(domain);
664 auto u = getV<5>(domain);
668 Box<2, double> up({box.getLow(0) - spacing / 2.0, box.getHigh(1) - spacing / 2.0},
669 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) + spacing / 2.0});
671 Box<2, double> down({box.getLow(0) - spacing / 2.0, box.getLow(1) - spacing / 2.0},
672 {box.getHigh(0) + spacing / 2.0, box.getLow(1) + spacing / 2.0});
674 Box<2, double> left({box.getLow(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
675 {box.getLow(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
677 Box<2, double> right({box.getHigh(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
678 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
692 auto it2 = domain.getDomainIterator();
694 while (it2.isNext()) {
698 if (up.isInside(xp) ==
true) {
700 up_p.last().get<0>() = p.getKey();
701 domain.getProp<1>(p) = 0;
702 }
else if (down.isInside(xp) ==
true) {
704 dw_p.last().get<0>() = p.getKey();
705 domain.getProp<1>(p) = 0;
708 bulk.last().get<0>() = p.getKey();
709 domain.getProp<1>(p) = xp.
get(0)*sin(5*M_PI*xp.
get(1))+exp(-((xp.
get(0)-0.5)*(xp.
get(0)-0.5)+(xp.
get(1)-0.5)*(xp.
get(1)-0.5))/0.02);
715 domain.ghost_get<1>();
716 auto Poisson = -
Lap(v);
718 Solver.impose(v, up_p, 0);
719 Solver.impose(v, dw_p, 0);
722 domain.ghost_get<0>();
726 for(
int j=0;j<bulk.
size();j++)
727 {
auto p=bulk.get<0>(j);
728 if (fabs(domain.getProp<3>(p) - domain.getProp<1>(p)) >= worst1) {
729 worst1 = fabs(domain.getProp<3>(p) - domain.getProp<1>(p));
731 domain.getProp<4>(p) = fabs(domain.getProp<1>(p) - domain.getProp<3>(p));
735 BOOST_REQUIRE(worst1 < 1.0);
741 BOOST_AUTO_TEST_CASE(dcpse_poisson_Robin) {
745 const size_t sz[2] = {31,31};
747 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
748 double spacing = box.getHigh(0) / (sz[0] - 1);
750 double rCut = 3.1 * spacing;
751 BOOST_TEST_MESSAGE(
"Init vector_dist...");
753 vector_dist<2, double, aggregate<double,double,double,double,double,VectorS<2, double>>> domain(0, box, bc, ghost);
757 BOOST_TEST_MESSAGE(
"Init domain...");
759 auto it = domain.getGridIterator(sz);
760 while (it.isNext()) {
764 double x = key.get(0) * it.getSpacing(0);
765 domain.getLastPos()[0] = x;
766 double y = key.get(1) * it.getSpacing(1);
767 domain.getLastPos()[1] = y;
771 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
774 domain.ghost_get<0>();
776 auto verletList = domain.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
778 Derivative_y<decltype(verletList)> Dy(domain, verletList, 2, rCut, support_options::RADIUS);
779 Laplacian<decltype(verletList)>
Lap(domain, verletList, 2, rCut, support_options::RADIUS);
781 DCPSE_scheme<
equations2d1,decltype(domain)> Solver(domain);
789 auto v = getV<0>(domain);
790 auto sol = getV<2>(domain);
791 auto anasol = getV<3>(domain);
792 auto err = getV<4>(domain);
793 auto u = getV<5>(domain);
797 Box<2, double> up({box.getLow(0) - spacing / 2.0, box.getHigh(1) - spacing / 2.0},
798 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) + spacing / 2.0});
800 Box<2, double> down({box.getLow(0) - spacing / 2.0, box.getLow(1) - spacing / 2.0},
801 {box.getHigh(0) + spacing / 2.0, box.getLow(1) + spacing / 2.0});
803 Box<2, double> left({box.getLow(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
804 {box.getLow(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
806 Box<2, double> right({box.getHigh(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
807 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
821 auto it2 = domain.getDomainIterator();
823 while (it2.isNext()) {
827 if (up.isInside(xp) ==
true) {
829 up_p.last().get<0>() = p.getKey();
830 domain.getProp<1>(p) = sin(5.0*xp.
get(0));
831 }
else if (down.isInside(xp) ==
true) {
833 dw_p.last().get<0>() = p.getKey();
834 domain.getProp<1>(p) = sin(5.0*xp.
get(0));
835 }
else if (left.isInside(xp) ==
true) {
837 l_p.last().get<0>() = p.getKey();
838 domain.getProp<1>(p) = sin(5.0*xp.
get(0));
839 }
else if (right.isInside(xp) ==
true) {
841 r_p.last().get<0>() = p.getKey();
842 domain.getProp<1>(p) = sin(5.0*xp.
get(0));
845 bulk.last().get<0>() = p.getKey();
846 domain.getProp<1>(p) = -10.0*exp(-((xp.
get(0)-0.5)*(xp.
get(0)-0.5)+(xp.
get(1)-0.5)*(xp.
get(1)-0.5))/0.02);
855 auto Poisson =
Lap(v);
860 Solver.impose(v, l_p, 0);
861 Solver.impose(v, r_p, 0);
863 Solver.solve_with_solver(pet_sol,sol);
864 domain.ghost_get<2>();
869 for(
int j=0;j<bulk.
size();j++)
870 {
auto p=bulk.get<0>(j);
871 if (fabs(domain.getProp<3>(p) - domain.getProp<1>(p)) >= worst1) {
872 worst1 = fabs(domain.getProp<3>(p) - domain.getProp<1>(p));
874 domain.getProp<4>(p) = fabs(domain.getProp<1>(p) - domain.getProp<3>(p));
878 BOOST_REQUIRE(worst1 < 1.0);
889 BOOST_AUTO_TEST_CASE(dcpse_poisson_Neumann) {
893 const size_t sz[2] = {31,31};
895 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
896 double spacing = box.getHigh(0) / (sz[0] - 1);
897 double rCut = 3.1 * spacing;
899 BOOST_TEST_MESSAGE(
"Init vector_dist...");
905 BOOST_TEST_MESSAGE(
"Init domain...");
907 auto it = domain.getGridIterator(sz);
908 while (it.isNext()) {
913 double x = key.get(0) * it.getSpacing(0);
914 domain.getLastPos()[0] = x;
915 double y = key.get(1) * it.getSpacing(1);
916 domain.getLastPos()[1] = y;
920 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
923 domain.ghost_get<0>();
925 auto verletList = domain.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
927 Derivative_x<decltype(verletList)> Dx(domain, verletList, 2, rCut, support_options::RADIUS);
928 Derivative_y<decltype(verletList)> Dy(domain, verletList, 2, rCut, support_options::RADIUS);
929 Laplacian<decltype(verletList)>
Lap(domain, verletList, 2, rCut, support_options::RADIUS);
941 auto v = getV<0>(domain);
943 auto sol = getV<2>(domain);
944 auto anasol = getV<3>(domain);
945 auto err = getV<4>(domain);
949 Box<2, double> up({box.getLow(0) - spacing / 2.0, box.getHigh(1) - spacing / 2.0},
950 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) + spacing / 2.0});
952 Box<2, double> down({box.getLow(0) - spacing / 2.0, box.getLow(1) - spacing / 2.0},
953 {box.getHigh(0) + spacing / 2.0, box.getLow(1) + spacing / 2.0});
955 Box<2, double> left({box.getLow(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
956 {box.getLow(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
958 Box<2, double> right({box.getHigh(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
959 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
973 auto it2 = domain.getDomainIterator();
975 while (it2.isNext()) {
979 if (up.isInside(xp) ==
true) {
981 up_p.last().get<0>() = p.getKey();
982 domain.getProp<1>(p) = sin(5*xp.
get(0));
983 }
else if (down.isInside(xp) ==
true) {
985 dw_p.last().get<0>() = p.getKey();
986 domain.getProp<1>(p) = sin(5*xp.
get(0));
987 }
else if (left.isInside(xp) ==
true) {
989 l_p.last().get<0>() = p.getKey();
990 domain.getProp<1>(p) = sin(5*xp.
get(0));
991 }
else if (right.isInside(xp) ==
true) {
993 r_p.last().get<0>() = p.getKey();
994 domain.getProp<1>(p) = sin(5*xp.
get(0));
997 bulk.last().get<0>() = p.getKey();
998 domain.getProp<1>(p) = -10*exp(-((xp.
get(0)-0.5)*(xp.
get(0)-0.5)+(xp.
get(1)-0.5)*(xp.
get(1)-0.5))/0.02);
1004 DCPSE_scheme<
equations2d1,decltype(domain)> Solver(domain,options_solver::LAGRANGE_MULTIPLIER);
1005 auto Poisson = -
Lap(v);
1021 Solver.solve_with_solver(solver,sol);
1030 Solver.solve_with_solver(solver,sol);
1033 domain.ghost_get<2>();
1035 double worst1 = 0.0;
1037 for(
int j=0;j<bulk.
size();j++)
1038 {
auto p=bulk.get<0>(j);
1039 if (fabs(domain.getProp<3>(p) - domain.getProp<1>(p)) >= worst1) {
1040 worst1 = fabs(domain.getProp<3>(p) - domain.getProp<1>(p));
1042 domain.getProp<4>(p) = fabs(domain.getProp<1>(p) - domain.getProp<3>(p));
1046 BOOST_REQUIRE(worst1 < 1.0);
1051 BOOST_AUTO_TEST_CASE(dcpse_poisson_Neumann2d) {
1052 const size_t sz[2] = {31,31};
1054 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
1055 double spacing = box.getHigh(0) / (sz[0] - 1);
1056 double rCut = 3.1 * spacing;
1058 BOOST_TEST_MESSAGE(
"Init vector_dist...");
1064 BOOST_TEST_MESSAGE(
"Init domain...");
1066 auto it = domain.getGridIterator(sz);
1067 while (it.isNext()) {
1071 auto key = it.get();
1072 double x = key.get(0) * it.getSpacing(0);
1073 domain.getLastPos()[0] = x;
1074 double y = key.get(1) * it.getSpacing(1);
1075 domain.getLastPos()[1] = y;
1079 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
1082 domain.ghost_get<0>();
1084 auto verletList = domain.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
1086 Derivative_x<decltype(verletList)> Dx(domain, verletList, 2, rCut, support_options::RADIUS);
1087 Derivative_y<decltype(verletList)> Dy(domain, verletList, 2, rCut, support_options::RADIUS);
1088 Laplacian<decltype(verletList)>
Lap(domain, verletList, 2, rCut, support_options::RADIUS);
1100 auto v = getV<0>(domain);
1101 auto RHS=getV<1>(domain);
1102 auto sol = getV<2>(domain);
1103 auto anasol = getV<3>(domain);
1104 auto err = getV<4>(domain);
1108 Box<2, double> up({box.getLow(0) - spacing / 2.0, box.getHigh(1) - spacing / 2.0},
1109 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) + spacing / 2.0});
1111 Box<2, double> down({box.getLow(0) - spacing / 2.0, box.getLow(1) - spacing / 2.0},
1112 {box.getHigh(0) + spacing / 2.0, box.getLow(1) + spacing / 2.0});
1114 Box<2, double> left({box.getLow(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
1115 {box.getLow(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
1117 Box<2, double> right({box.getHigh(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
1118 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
1132 auto it2 = domain.getDomainIterator();
1134 while (it2.isNext()) {
1138 if (up.isInside(xp) ==
true) {
1140 up_p.last().get<0>() = p.getKey();
1141 domain.getProp<1>(p)[0] = sin(5*xp.
get(0));
1142 domain.getProp<1>(p)[1] = sin(5*xp.
get(0));
1143 }
else if (down.isInside(xp) ==
true) {
1145 dw_p.last().get<0>() = p.getKey();
1146 domain.getProp<1>(p)[0] = sin(5*xp.
get(0));
1147 domain.getProp<1>(p)[1] = sin(5*xp.
get(0));
1148 }
else if (left.isInside(xp) ==
true) {
1150 l_p.last().get<0>() = p.getKey();
1151 domain.getProp<1>(p)[0] = sin(5*xp.
get(0));
1152 domain.getProp<1>(p)[1] = sin(5*xp.
get(0));
1153 }
else if (right.isInside(xp) ==
true) {
1155 r_p.last().get<0>() = p.getKey();
1156 domain.getProp<1>(p)[0] = sin(5*xp.
get(0));
1157 domain.getProp<1>(p)[1] = sin(5*xp.
get(0));
1160 bulk.last().get<0>() = p.getKey();
1161 domain.getProp<1>(p)[0] = -10*exp(-((xp.
get(0)-0.5)*(xp.
get(0)-0.5)+(xp.
get(1)-0.5)*(xp.
get(1)-0.5))/0.02);
1162 domain.getProp<1>(p)[1] = -10*exp(-((xp.
get(0)-0.5)*(xp.
get(0)-0.5)+(xp.
get(1)-0.5)*(xp.
get(1)-0.5))/0.02);
1168 DCPSE_scheme<
equations2d2,decltype(domain)> Solver(domain,options_solver::LAGRANGE_MULTIPLIER);
1172 auto Poisson0 = -
Lap(v[0]);
1173 auto D_x0 = Dx(v[0]);
1174 auto D_y0 = Dy(v[0]);
1175 auto Poisson1 = -
Lap(v[1]);
1176 auto D_x1 = Dx(v[1]);
1177 auto D_y1 = Dy(v[1]);
1179 Solver.impose(Poisson0, bulk, RHS[0],
vx);
1180 Solver.impose(Poisson1, bulk, RHS[1],vy);
1181 Solver.impose(D_y0, up_p, RHS[0],
vx);
1182 Solver.impose(-D_y0, dw_p, RHS[0],
vx);
1183 Solver.impose(-D_x0, l_p, RHS[0],
vx);
1184 Solver.impose(D_x0, r_p, RHS[0],
vx);
1186 Solver.impose(D_y1, up_p, RHS[1],vy);
1187 Solver.impose(-D_y1, dw_p, RHS[1],vy);
1188 Solver.impose(-D_x1, l_p, RHS[1],vy);
1189 Solver.impose(D_x1, r_p, RHS[1],vy);
1190 Solver.solve_with_solver(solver,sol[0],sol[1]);
1193 domain.ghost_get<2>();
1194 anasol[0]=-
Lap(sol[0]);
1195 anasol[1]=-
Lap(sol[1]);
1196 double worst1 = 0.0,worst2 = 0.0;
1198 for(
int j=0;j<bulk.
size();j++)
1199 {
auto p=bulk.get<0>(j);
1200 if (fabs(domain.getProp<3>(p)[0]- domain.getProp<1>(p)[0]) >= worst1) {
1201 worst1 = fabs(domain.getProp<3>(p)[0] - domain.getProp<1>(p)[0]);
1203 if (fabs(domain.getProp<3>(p)[1]- domain.getProp<1>(p)[1]) >= worst2) {
1204 worst2 = fabs(domain.getProp<3>(p)[1] - domain.getProp<1>(p)[1]);
1206 domain.getProp<4>(p)[0] = fabs(domain.getProp<1>(p)[0] - domain.getProp<3>(p)[0]);
1207 domain.getProp<4>(p)[1] = fabs(domain.getProp<1>(p)[1] - domain.getProp<3>(p)[1]);
1211 BOOST_REQUIRE(worst1 < 1.0);
1212 BOOST_REQUIRE(worst2 < 1.0);
1214 domain.write(
"Neumann2d");
1218 BOOST_AUTO_TEST_CASE(dcpse_slice_solver) {
1221 const size_t sz[2] = {31,31};
1223 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
1224 double spacing = box.getHigh(0) / (sz[0] - 1);
1225 double rCut = 3.1 * spacing;
1227 BOOST_TEST_MESSAGE(
"Init vector_dist...");
1229 vector_dist<2, double, aggregate<VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>>> domain(0, box, bc, ghost);
1233 BOOST_TEST_MESSAGE(
"Init domain...");
1235 auto it = domain.getGridIterator(sz);
1236 while (it.isNext()) {
1239 auto key = it.get();
1240 double x = key.get(0) * it.getSpacing(0);
1241 domain.getLastPos()[0] = x;
1242 double y = key.get(1) * it.getSpacing(1);
1243 domain.getLastPos()[1] = y;
1247 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
1250 domain.ghost_get<0>();
1252 auto verletList = domain.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
1254 Derivative_x<decltype(verletList)> Dx(domain, verletList, 2, rCut, support_options::RADIUS);
1255 Derivative_y<decltype(verletList)> Dy(domain, verletList, 2, rCut, support_options::RADIUS);
1256 Laplacian<decltype(verletList)>
Lap(domain, verletList, 2, rCut, support_options::RADIUS);
1266 auto v = getV<0>(domain);
1267 auto RHS=getV<1>(domain);
1268 auto sol = getV<2>(domain);
1269 auto anasol = getV<3>(domain);
1270 auto err = getV<4>(domain);
1271 auto DCPSE_sol=getV<5>(domain);
1275 Box<2, double> up({box.getLow(0) - spacing / 2.0, box.getHigh(1) - spacing / 2.0},
1276 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) + spacing / 2.0});
1278 Box<2, double> down({box.getLow(0) - spacing / 2.0, box.getLow(1) - spacing / 2.0},
1279 {box.getHigh(0) + spacing / 2.0, box.getLow(1) + spacing / 2.0});
1281 Box<2, double> left({box.getLow(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
1282 {box.getLow(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
1284 Box<2, double> right({box.getHigh(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
1285 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
1300 auto it2 = domain.getDomainIterator();
1302 while (it2.isNext()) {
1305 if (up.isInside(xp) ==
true) {
1307 up_p.last().get<0>() = p.getKey();
1308 domain.getProp<1>(p)[0] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1309 domain.getProp<3>(p)[0] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1311 domain.getProp<1>(p)[1] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1312 domain.getProp<3>(p)[1] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1315 }
else if (down.isInside(xp) ==
true) {
1317 dw_p.last().get<0>() = p.getKey();
1318 domain.getProp<1>(p)[0] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1319 domain.getProp<3>(p)[0] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1321 domain.getProp<1>(p)[1] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1322 domain.getProp<3>(p)[1] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1324 }
else if (left.isInside(xp) ==
true) {
1326 l_p.last().get<0>() = p.getKey();
1327 domain.getProp<1>(p)[0] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1328 domain.getProp<3>(p)[0] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1330 domain.getProp<1>(p)[1] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1331 domain.getProp<3>(p)[1] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1333 }
else if (right.isInside(xp) ==
true) {
1335 r_p.last().get<0>() = p.getKey();
1336 domain.getProp<1>(p)[0] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1337 domain.getProp<3>(p)[0] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1339 domain.getProp<1>(p)[1] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1340 domain.getProp<3>(p)[1] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1344 bulk.last().get<0>() = p.getKey();
1345 domain.getProp<1>(p)[0] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1346 domain.getProp<3>(p)[0] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1348 domain.getProp<1>(p)[1] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1349 domain.getProp<3>(p)[1] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1359 DCPSE_scheme<
equations2d2,decltype(domain)> Solver(domain);
1360 auto Poisson0 =
Lap(v[0]);
1361 auto Poisson1 =
Lap(v[1]);
1364 Solver.impose(Poisson0, bulk, RHS[0],
vx);
1365 Solver.impose(Poisson1, bulk, RHS[1],vy);
1366 Solver.impose(v[0], up_p, RHS[0],
vx);
1367 Solver.impose(v[1], up_p, RHS[1],vy);
1368 Solver.impose(v[0], r_p, RHS[0],
vx);
1369 Solver.impose(v[1], r_p, RHS[1],vy);
1370 Solver.impose(v[0], dw_p, RHS[0],
vx);
1371 Solver.impose(v[1], dw_p, RHS[1],vy);
1372 Solver.impose(v[0], l_p, RHS[0],
vx);
1373 Solver.impose(v[1], l_p, RHS[1],vy);
1374 Solver.solve(sol[0],sol[1]);
1376 double worst1 = 0.0;
1377 double worst2 = 0.0;
1382 for(
int j=0;j<bulk.
size();j++)
1383 {
auto p=bulk.get<0>(j);
1384 if (fabs(domain.getProp<3>(p)[0] - domain.getProp<2>(p)[0]) >= worst1) {
1385 worst1 = fabs(domain.getProp<3>(p)[0] - domain.getProp<2>(p)[0]);
1387 domain.getProp<4>(p)[0] = fabs(domain.getProp<3>(p)[0] - domain.getProp<2>(p)[0]);
1390 for(
int j=0;j<bulk.
size();j++)
1391 {
auto p=bulk.get<0>(j);
1392 if (fabs(domain.getProp<3>(p)[1] - domain.getProp<2>(p)[1]) >= worst2) {
1393 worst2 = fabs(domain.getProp<3>(p)[1] - domain.getProp<2>(p)[1]);
1395 domain.getProp<4>(p)[1] = fabs(domain.getProp<3>(p)[1] - domain.getProp<2>(p)[1]);
1401 BOOST_REQUIRE(worst1 < 0.03);
1402 BOOST_REQUIRE(worst2 < 0.03);
1407 BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
Laplacian second order on h (spacing)
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
Implementation of 1-D std::vector like structure.
This class is able to do Matrix inversion in parallel with PETSC solvers.
void setPreconditioner(PCType type)
Set the preconditioner of the linear solver.
void setSolver(KSPType type)
Set the Petsc solver.
void setRestart(PetscInt n)
For GMRES based method, the number of Krylov directions to orthogonalize against.
Specify the general characteristic of system to solve.