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_op.hpp"
24#include "../DCPSE_Solver.hpp"
25#include "Operators/Vector/vector_dist_operators.hpp"
26#include "Vector/vector_dist_subset.hpp"
27#include "../EqnsStruct.hpp"
28#include "Decomposition/Distribution/SpaceDistribution.hpp"
30BOOST_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 = 2.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 Laplacian
Lap(domain, 2, rCut, 2,support_options::N_PARTICLES);
68 DCPSE_scheme<
equations2d1,
decltype(domain)> Solver(domain);
76 auto v = getV<0>(domain);
77 auto RHS = getV<1>(domain);
78 auto sol = getV<2>(domain);
79 auto anasol = getV<3>(domain);
83 Box<2, double> up({box.getLow(0) - spacing / 2.0, box.getHigh(1) - spacing / 2.0},
84 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) + spacing / 2.0});
86 Box<2, double> up_d({box.getLow(0) - spacing / 2.0, box.getHigh(1) - 8*spacing / 2.0},
87 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - 6*spacing / 2.0});
89 Box<2, double> down({box.getLow(0) - spacing / 2.0, box.getLow(1) - spacing / 2.0},
90 {box.getHigh(0) + spacing / 2.0, box.getLow(1) + spacing / 2.0});
92 Box<2, double> down_u({box.getLow(0) - spacing / 2.0, box.getLow(1) + 3*spacing / 2.0},
93 {box.getHigh(0) + spacing / 2.0, box.getLow(1) + 4*spacing / 2.0});
95 Box<2, double> left({box.getLow(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
96 {box.getLow(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
98 Box<2, double> left_r({box.getLow(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
99 {box.getLow(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
101 Box<2, double> right({box.getHigh(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
102 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
104 Box<2, double> right_l({box.getHigh(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
105 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
121 vtk_box.write(
"vtk_box.vtk");
123 auto it2 = domain.getDomainIterator();
125 while (it2.isNext()) {
128 domain.getProp<2>(p)=1+xp[0]*xp[0]+2*xp[1]*xp[1];
129 if (up.isInside(xp) ==
true) {
131 up_p.last().get<0>() = p.getKey();
132 domain.getProp<1>(p) = 3 + xp.
get(0)*xp.
get(0);
133 }
else if (down.isInside(xp) ==
true) {
135 dw_p.last().get<0>() = p.getKey();
136 domain.getProp<1>(p) = 1 + xp.
get(0)*xp.
get(0);
137 }
else if (left.isInside(xp) ==
true) {
139 l_p.last().get<0>() = p.getKey();
140 domain.getProp<1>(p) = 1 + 2*xp.
get(1)*xp.
get(1);
141 }
else if (right.isInside(xp) ==
true) {
143 r_p.last().get<0>() = p.getKey();
144 domain.getProp<1>(p) = 2 + 2*xp.
get(1)*xp.
get(1);
147 bulk.last().get<0>() = p.getKey();
157 Solver.impose(eq1, bulk, 6);
158 Solver.impose(v, up_p, RHS);
159 Solver.impose(v, dw_p, RHS);
167 it2 = domain.getDomainIterator();
169 while (it2.isNext()) {
171 if (fabs(domain.getProp<0>(p) - domain.getProp<2>(p)) >= worst1) {
172 worst1 = fabs(domain.getProp<0>(p) - domain.getProp<2>(p));
175 domain.getProp<1>(p) = fabs(domain.getProp<0>(p) - domain.getProp<2>(p));
180 domain.write(
"particles");
181 BOOST_REQUIRE(worst1 < 0.03);
186 BOOST_AUTO_TEST_CASE(dcpse_poisson_Robin_anal) {
189 const size_t sz[2] = {81,81};
191 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
192 double spacing = box.getHigh(0) / (sz[0] - 1);
194 double rCut = 3.1 * spacing;
195 BOOST_TEST_MESSAGE(
"Init vector_dist...");
197 vector_dist<2, double, aggregate<double,double,double,double,double,double>> domain(0, box, bc, ghost);
201 BOOST_TEST_MESSAGE(
"Init domain...");
203 auto it = domain.getGridIterator(sz);
204 while (it.isNext()) {
208 double x = key.get(0) * it.getSpacing(0);
209 domain.getLastPos()[0] = x;
210 double y = key.get(1) * it.getSpacing(1);
211 domain.getLastPos()[1] = y;
219 const size_t sz2[2] = {40,40};
220 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});
223 auto it = domain.getDomainIterator();
231 if (bx.isInside(xp) ==
true)
241 auto it2 = domain.getGridIterator(sz2);
242 while (it2.isNext()) {
245 auto key = it2.get();
246 double x = key.get(0) * spacing/2.0 + 0.25 + spacing/4.0;
247 domain.getLastPos()[0] = x;
248 double y = key.get(1) * spacing/2.0 + 0.25 + spacing/4.0;
249 domain.getLastPos()[1] = y;
258 const size_t sz2[2] = {40,40};
259 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});
262 auto it = domain.getDomainIterator();
270 if (bx.isInside(xp) ==
true)
280 auto it2 = domain.getGridIterator(sz2);
281 while (it2.isNext()) {
284 auto key = it2.get();
285 double x = key.get(0) * spacing/4.0 + 0.25 + 21*spacing/8.0;
286 domain.getLastPos()[0] = x;
287 double y = key.get(1) * spacing/4.0 + 0.25 + 21*spacing/8.0;
288 domain.getLastPos()[1] = y;
296 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
299 domain.ghost_get<0>();
301 Derivative_x Dx(domain, 2, rCut/3.0 ,1.9,support_options::N_PARTICLES);
302 Derivative_y Dy(domain, 2, rCut/3.0,1.9,support_options::N_PARTICLES);
303 Laplacian
Lap(domain, 2, rCut/3.0 ,1.9,support_options::N_PARTICLES);
312 auto v = getV<0>(domain);
313 auto RHS=getV<1>(domain);
314 auto sol = getV<2>(domain);
315 auto anasol = getV<3>(domain);
316 auto err = getV<4>(domain);
317 auto DCPSE_sol=getV<5>(domain);
321 Box<2, double> up({box.getLow(0) - spacing / 2.0, box.getHigh(1) - spacing / 2.0},
322 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) + spacing / 2.0});
324 Box<2, double> down({box.getLow(0) - spacing / 2.0, box.getLow(1) - spacing / 2.0},
325 {box.getHigh(0) + spacing / 2.0, box.getLow(1) + spacing / 2.0});
327 Box<2, double> left({box.getLow(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
328 {box.getLow(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
330 Box<2, double> right({box.getHigh(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
331 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
345 auto it2 = domain.getDomainIterator();
347 while (it2.isNext()) {
350 if (up.isInside(xp) ==
true) {
352 up_p.last().get<0>() = p.getKey();
353 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
354 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
355 }
else if (down.isInside(xp) ==
true) {
357 dw_p.last().get<0>() = p.getKey();
358 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
359 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
361 }
else if (left.isInside(xp) ==
true) {
363 l_p.last().get<0>() = p.getKey();
364 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
365 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
367 }
else if (right.isInside(xp) ==
true) {
369 r_p.last().get<0>() = p.getKey();
370 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
371 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
375 bulk.last().get<0>() = p.getKey();
376 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
377 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
382 domain.ghost_get<1,3>();
384 DCPSE_scheme<
equations2d1,
decltype(domain)> Solver( domain);
385 auto Poisson =
Lap(v);
389 Solver.impose(D_y, up_p, 0);
390 Solver.impose(D_x, r_p, 0);
391 Solver.impose(v, dw_p, 0);
392 Solver.impose(v, l_p, 0);
396 solver.setPreconditioner(PCBJACOBI);
397 solver.setRestart(500);
399 Solver.solve_with_solver(solver,sol);
403 domain.ghost_get<2>();
406 domain.ghost_get<5>();
410 v=abs(DCPSE_sol-RHS);
412 for(
int j=0;j<bulk.
size();j++)
413 {
auto p=bulk.get<0>(j);
414 if (fabs(domain.getProp<3>(p) - domain.getProp<2>(p)) >= worst1) {
415 worst1 = fabs(domain.getProp<3>(p) - domain.getProp<2>(p));
417 domain.getProp<4>(p) = fabs(domain.getProp<3>(p) - domain.getProp<2>(p));
424 BOOST_REQUIRE(worst1 < 0.03);
434 BOOST_AUTO_TEST_CASE(dcpse_poisson_Dirichlet_anal) {
437 const size_t sz[2] = {81,81};
439 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
440 double spacing = box.getHigh(0) / (sz[0] - 1);
442 double rCut = 3.1 * spacing;
443 BOOST_TEST_MESSAGE(
"Init vector_dist...");
445 vector_dist<2, double, aggregate<double,double,double,double,double,double>> domain(0, box, bc, ghost);
449 BOOST_TEST_MESSAGE(
"Init domain...");
451 auto it = domain.getGridIterator(sz);
452 while (it.isNext()) {
456 double x = key.get(0) * it.getSpacing(0);
457 domain.getLastPos()[0] = x;
458 double y = key.get(1) * it.getSpacing(1);
459 domain.getLastPos()[1] = y;
463 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
466 domain.ghost_get<0>();
468 Derivative_x Dx(domain, 2, rCut,1.9,support_options::RADIUS);
469 Derivative_y Dy(domain, 2, rCut,1.9,support_options::RADIUS);
470 Laplacian
Lap(domain, 2, rCut, 1.9,support_options::RADIUS);
480 auto v = getV<0>(domain);
481 auto RHS=getV<1>(domain);
482 auto sol = getV<2>(domain);
483 auto anasol = getV<3>(domain);
484 auto err = getV<4>(domain);
485 auto DCPSE_sol=getV<5>(domain);
489 Box<2, double> up({box.getLow(0) - spacing / 2.0, box.getHigh(1) - spacing / 2.0},
490 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) + spacing / 2.0});
492 Box<2, double> down({box.getLow(0) - spacing / 2.0, box.getLow(1) - spacing / 2.0},
493 {box.getHigh(0) + spacing / 2.0, box.getLow(1) + spacing / 2.0});
495 Box<2, double> left({box.getLow(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
496 {box.getLow(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
498 Box<2, double> right({box.getHigh(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
499 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
513 auto it2 = domain.getDomainIterator();
515 while (it2.isNext()) {
518 if (up.isInside(xp) ==
true) {
520 up_p.last().get<0>() = p.getKey();
521 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
522 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
524 bulkF.last().get<0>() = p.getKey();
525 }
else if (down.isInside(xp) ==
true) {
527 dw_p.last().get<0>() = p.getKey();
528 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
529 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
531 bulkF.last().get<0>() = p.getKey();
533 }
else if (left.isInside(xp) ==
true) {
535 l_p.last().get<0>() = p.getKey();
536 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
537 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
539 bulkF.last().get<0>() = p.getKey();
541 }
else if (right.isInside(xp) ==
true) {
543 r_p.last().get<0>() = p.getKey();
544 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
545 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
547 bulkF.last().get<0>() = p.getKey();
551 bulk.last().get<0>() = p.getKey();
552 domain.getProp<1>(p) = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
553 domain.getProp<3>(p) = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
555 bulkF.last().get<0>() = p.getKey();
559 DCPSE_scheme<
equations2d1,
decltype(domain)> Solver( domain);
560 auto Poisson =
Lap(v);
572 for (
int j = 0; j < up_p.
size(); j++) {
573 auto p = up_p.get<0>(j);
574 domain.getProp<5>(p) = 0;
576 for (
int j = 0; j < dw_p.
size(); j++) {
577 auto p = dw_p.get<0>(j);
578 domain.getProp<5>(p) = 0;
580 for (
int j = 0; j < l_p.
size(); j++) {
581 auto p = l_p.get<0>(j);
582 domain.getProp<5>(p) = 0;
584 for (
int j = 0; j < r_p.
size(); j++) {
585 auto p = r_p.get<0>(j);
586 domain.getProp<5>(p) = 0;
591 v=abs(DCPSE_sol-RHS);
593 for(
int j=0;j<bulkF.
size();j++)
594 {
auto p=bulkF.get<0>(j);
595 if (fabs(domain.getProp<3>(p) - domain.getProp<2>(p)) >= worst1) {
596 worst1 = fabs(domain.getProp<3>(p) - domain.getProp<2>(p));
598 domain.getProp<4>(p) = fabs(domain.getProp<3>(p) - domain.getProp<2>(p));
603 BOOST_REQUIRE(worst1 < 0.03);
609 BOOST_AUTO_TEST_CASE(dcpse_poisson_Periodic) {
613 const size_t sz[2] = {31,31};
615 size_t bc[2] = {PERIODIC, NON_PERIODIC};
616 double spacing = box.getHigh(0) / (sz[0] - 1);
618 double rCut = 3.1 * spacing;
619 BOOST_TEST_MESSAGE(
"Init vector_dist...");
621 vector_dist<2, double, aggregate<double,double,double,double,double,VectorS<2, double>>> domain(0, box, bc, ghost);
624 BOOST_TEST_MESSAGE(
"Init domain...");
626 auto it = domain.getGridIterator(sz);
627 while (it.isNext()) {
631 double x = key.get(0) * it.getSpacing(0);
632 domain.getLastPos()[0] = x;
633 double y = key.get(1) * it.getSpacing(1)*0.99999;
634 domain.getLastPos()[1] = y;
638 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
641 domain.ghost_get<0>();
644 Laplacian
Lap(domain, 2, rCut, 1.9, support_options::RADIUS);
646 DCPSE_scheme<
equations2d1p,
decltype(domain)> Solver( domain);
654 auto v = getV<0>(domain);
655 auto RHS=getV<1>(domain);
656 auto sol = getV<2>(domain);
657 auto anasol = getV<3>(domain);
658 auto err = getV<4>(domain);
659 auto u = getV<5>(domain);
663 Box<2, double> up({box.getLow(0) - spacing / 2.0, box.getHigh(1) - spacing / 2.0},
664 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) + spacing / 2.0});
666 Box<2, double> down({box.getLow(0) - spacing / 2.0, box.getLow(1) - spacing / 2.0},
667 {box.getHigh(0) + spacing / 2.0, box.getLow(1) + spacing / 2.0});
669 Box<2, double> left({box.getLow(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
670 {box.getLow(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
672 Box<2, double> right({box.getHigh(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
673 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
687 auto it2 = domain.getDomainIterator();
689 while (it2.isNext()) {
693 if (up.isInside(xp) ==
true) {
695 up_p.last().get<0>() = p.getKey();
696 domain.getProp<1>(p) = 0;
697 }
else if (down.isInside(xp) ==
true) {
699 dw_p.last().get<0>() = p.getKey();
700 domain.getProp<1>(p) = 0;
703 bulk.last().get<0>() = p.getKey();
704 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);
710 domain.ghost_get<1>();
711 auto Poisson = -
Lap(v);
713 Solver.impose(v, up_p, 0);
714 Solver.impose(v, dw_p, 0);
717 domain.ghost_get<0>();
721 for(
int j=0;j<bulk.
size();j++)
722 {
auto p=bulk.get<0>(j);
723 if (fabs(domain.getProp<3>(p) - domain.getProp<1>(p)) >= worst1) {
724 worst1 = fabs(domain.getProp<3>(p) - domain.getProp<1>(p));
726 domain.getProp<4>(p) = fabs(domain.getProp<1>(p) - domain.getProp<3>(p));
730 BOOST_REQUIRE(worst1 < 1.0);
736 BOOST_AUTO_TEST_CASE(dcpse_poisson_Robin) {
740 const size_t sz[2] = {31,31};
742 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
743 double spacing = box.getHigh(0) / (sz[0] - 1);
745 double rCut = 2.0 * spacing;
746 BOOST_TEST_MESSAGE(
"Init vector_dist...");
748 vector_dist<2, double, aggregate<double,double,double,double,double,VectorS<2, double>>> domain(0, box, bc, ghost);
752 BOOST_TEST_MESSAGE(
"Init domain...");
754 auto it = domain.getGridIterator(sz);
755 while (it.isNext()) {
759 double x = key.get(0) * it.getSpacing(0);
760 domain.getLastPos()[0] = x;
761 double y = key.get(1) * it.getSpacing(1);
762 domain.getLastPos()[1] = y;
766 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
769 domain.ghost_get<0>();
771 Derivative_y Dy(domain, 2, rCut,2,support_options::N_PARTICLES);
772 Laplacian
Lap(domain, 2, rCut, 3,support_options::N_PARTICLES);
774 DCPSE_scheme<
equations2d1,
decltype(domain)> Solver(domain);
782 auto v = getV<0>(domain);
783 auto sol = getV<2>(domain);
784 auto anasol = getV<3>(domain);
785 auto err = getV<4>(domain);
786 auto u = getV<5>(domain);
790 Box<2, double> up({box.getLow(0) - spacing / 2.0, box.getHigh(1) - spacing / 2.0},
791 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) + spacing / 2.0});
793 Box<2, double> down({box.getLow(0) - spacing / 2.0, box.getLow(1) - spacing / 2.0},
794 {box.getHigh(0) + spacing / 2.0, box.getLow(1) + spacing / 2.0});
796 Box<2, double> left({box.getLow(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
797 {box.getLow(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
799 Box<2, double> right({box.getHigh(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
800 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
814 auto it2 = domain.getDomainIterator();
816 while (it2.isNext()) {
820 if (up.isInside(xp) ==
true) {
822 up_p.last().get<0>() = p.getKey();
823 domain.getProp<1>(p) = sin(5.0*xp.
get(0));
824 }
else if (down.isInside(xp) ==
true) {
826 dw_p.last().get<0>() = p.getKey();
827 domain.getProp<1>(p) = sin(5.0*xp.
get(0));
828 }
else if (left.isInside(xp) ==
true) {
830 l_p.last().get<0>() = p.getKey();
831 domain.getProp<1>(p) = sin(5.0*xp.
get(0));
832 }
else if (right.isInside(xp) ==
true) {
834 r_p.last().get<0>() = p.getKey();
835 domain.getProp<1>(p) = sin(5.0*xp.
get(0));
838 bulk.last().get<0>() = p.getKey();
839 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);
846 pet_sol.setPreconditioner(PCNONE);
848 auto Poisson =
Lap(v);
853 Solver.impose(v, l_p, 0);
854 Solver.impose(v, r_p, 0);
856 Solver.solve_with_solver(pet_sol,sol);
857 domain.ghost_get<2>();
862 for(
int j=0;j<bulk.
size();j++)
863 {
auto p=bulk.get<0>(j);
864 if (fabs(domain.getProp<3>(p) - domain.getProp<1>(p)) >= worst1) {
865 worst1 = fabs(domain.getProp<3>(p) - domain.getProp<1>(p));
867 domain.getProp<4>(p) = fabs(domain.getProp<1>(p) - domain.getProp<3>(p));
871 BOOST_REQUIRE(worst1 < 1.0);
882 BOOST_AUTO_TEST_CASE(dcpse_poisson_Neumann) {
886 const size_t sz[2] = {31,31};
888 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
889 double spacing = box.getHigh(0) / (sz[0] - 1);
890 double rCut = 3.1 * spacing;
892 BOOST_TEST_MESSAGE(
"Init vector_dist...");
898 BOOST_TEST_MESSAGE(
"Init domain...");
900 auto it = domain.getGridIterator(sz);
901 while (it.isNext()) {
906 double x = key.get(0) * it.getSpacing(0);
907 domain.getLastPos()[0] = x;
908 double y = key.get(1) * it.getSpacing(1);
909 domain.getLastPos()[1] = y;
913 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
916 domain.ghost_get<0>();
918 Derivative_x Dx(domain, 2, rCut,1.9,support_options::N_PARTICLES);
919 Derivative_y Dy(domain, 2, rCut,1.9,support_options::N_PARTICLES);
920 Laplacian
Lap(domain, 2, rCut, 1.9,support_options::N_PARTICLES);
922 solver.setRestart(500);
923 solver.setSolver(KSPGMRES);
924 solver.setPreconditioner(PCSVD);
932 auto v = getV<0>(domain);
934 auto sol = getV<2>(domain);
935 auto anasol = getV<3>(domain);
936 auto err = getV<4>(domain);
940 Box<2, double> up({box.getLow(0) - spacing / 2.0, box.getHigh(1) - spacing / 2.0},
941 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) + spacing / 2.0});
943 Box<2, double> down({box.getLow(0) - spacing / 2.0, box.getLow(1) - spacing / 2.0},
944 {box.getHigh(0) + spacing / 2.0, box.getLow(1) + spacing / 2.0});
946 Box<2, double> left({box.getLow(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
947 {box.getLow(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
949 Box<2, double> right({box.getHigh(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
950 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
964 auto it2 = domain.getDomainIterator();
966 while (it2.isNext()) {
970 if (up.isInside(xp) ==
true) {
972 up_p.last().get<0>() = p.getKey();
973 domain.getProp<1>(p) = sin(5*xp.
get(0));
974 }
else if (down.isInside(xp) ==
true) {
976 dw_p.last().get<0>() = p.getKey();
977 domain.getProp<1>(p) = sin(5*xp.
get(0));
978 }
else if (left.isInside(xp) ==
true) {
980 l_p.last().get<0>() = p.getKey();
981 domain.getProp<1>(p) = sin(5*xp.
get(0));
982 }
else if (right.isInside(xp) ==
true) {
984 r_p.last().get<0>() = p.getKey();
985 domain.getProp<1>(p) = sin(5*xp.
get(0));
988 bulk.last().get<0>() = p.getKey();
989 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);
995 DCPSE_scheme<
equations2d1,
decltype(domain)> Solver(domain,options_solver::LAGRANGE_MULTIPLIER);
996 auto Poisson = -
Lap(v);
1012 Solver.solve_with_solver(solver,sol);
1021 Solver.solve_with_solver(solver,sol);
1024 domain.ghost_get<2>();
1026 double worst1 = 0.0;
1028 for(
int j=0;j<bulk.
size();j++)
1029 {
auto p=bulk.get<0>(j);
1030 if (fabs(domain.getProp<3>(p) - domain.getProp<1>(p)) >= worst1) {
1031 worst1 = fabs(domain.getProp<3>(p) - domain.getProp<1>(p));
1033 domain.getProp<4>(p) = fabs(domain.getProp<1>(p) - domain.getProp<3>(p));
1037 BOOST_REQUIRE(worst1 < 1.0);
1042 BOOST_AUTO_TEST_CASE(dcpse_poisson_Neumann2d) {
1043 const size_t sz[2] = {31,31};
1045 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
1046 double spacing = box.getHigh(0) / (sz[0] - 1);
1047 double rCut = 3.1 * spacing;
1049 BOOST_TEST_MESSAGE(
"Init vector_dist...");
1055 BOOST_TEST_MESSAGE(
"Init domain...");
1057 auto it = domain.getGridIterator(sz);
1058 while (it.isNext()) {
1062 auto key = it.get();
1063 double x = key.get(0) * it.getSpacing(0);
1064 domain.getLastPos()[0] = x;
1065 double y = key.get(1) * it.getSpacing(1);
1066 domain.getLastPos()[1] = y;
1070 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
1073 domain.ghost_get<0>();
1075 Derivative_x Dx(domain, 2, rCut,1.9,support_options::N_PARTICLES);
1076 Derivative_y Dy(domain, 2, rCut,1.9,support_options::N_PARTICLES);
1077 Laplacian
Lap(domain, 2, rCut, 1.9,support_options::N_PARTICLES);
1079 solver.setRestart(500);
1080 solver.setSolver(KSPGMRES);
1081 solver.setPreconditioner(PCSVD);
1089 auto v = getV<0>(domain);
1090 auto RHS=getV<1>(domain);
1091 auto sol = getV<2>(domain);
1092 auto anasol = getV<3>(domain);
1093 auto err = getV<4>(domain);
1097 Box<2, double> up({box.getLow(0) - spacing / 2.0, box.getHigh(1) - spacing / 2.0},
1098 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) + spacing / 2.0});
1100 Box<2, double> down({box.getLow(0) - spacing / 2.0, box.getLow(1) - spacing / 2.0},
1101 {box.getHigh(0) + spacing / 2.0, box.getLow(1) + spacing / 2.0});
1103 Box<2, double> left({box.getLow(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
1104 {box.getLow(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
1106 Box<2, double> right({box.getHigh(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
1107 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
1121 auto it2 = domain.getDomainIterator();
1123 while (it2.isNext()) {
1127 if (up.isInside(xp) ==
true) {
1129 up_p.last().get<0>() = p.getKey();
1130 domain.getProp<1>(p)[0] = sin(5*xp.
get(0));
1131 domain.getProp<1>(p)[1] = sin(5*xp.
get(0));
1132 }
else if (down.isInside(xp) ==
true) {
1134 dw_p.last().get<0>() = p.getKey();
1135 domain.getProp<1>(p)[0] = sin(5*xp.
get(0));
1136 domain.getProp<1>(p)[1] = sin(5*xp.
get(0));
1137 }
else if (left.isInside(xp) ==
true) {
1139 l_p.last().get<0>() = p.getKey();
1140 domain.getProp<1>(p)[0] = sin(5*xp.
get(0));
1141 domain.getProp<1>(p)[1] = sin(5*xp.
get(0));
1142 }
else if (right.isInside(xp) ==
true) {
1144 r_p.last().get<0>() = p.getKey();
1145 domain.getProp<1>(p)[0] = sin(5*xp.
get(0));
1146 domain.getProp<1>(p)[1] = sin(5*xp.
get(0));
1149 bulk.last().get<0>() = p.getKey();
1150 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);
1151 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);
1157 DCPSE_scheme<
equations2d2,
decltype(domain)> Solver(domain,options_solver::LAGRANGE_MULTIPLIER);
1161 auto Poisson0 = -
Lap(v[0]);
1162 auto D_x0 = Dx(v[0]);
1163 auto D_y0 = Dy(v[0]);
1164 auto Poisson1 = -
Lap(v[1]);
1165 auto D_x1 = Dx(v[1]);
1166 auto D_y1 = Dy(v[1]);
1168 Solver.impose(Poisson0, bulk, RHS[0],
vx);
1169 Solver.impose(Poisson1, bulk, RHS[1],vy);
1170 Solver.impose(D_y0, up_p, RHS[0],
vx);
1171 Solver.impose(-D_y0, dw_p, RHS[0],
vx);
1172 Solver.impose(-D_x0, l_p, RHS[0],
vx);
1173 Solver.impose(D_x0, r_p, RHS[0],
vx);
1175 Solver.impose(D_y1, up_p, RHS[1],vy);
1176 Solver.impose(-D_y1, dw_p, RHS[1],vy);
1177 Solver.impose(-D_x1, l_p, RHS[1],vy);
1178 Solver.impose(D_x1, r_p, RHS[1],vy);
1179 Solver.solve_with_solver(solver,sol[0],sol[1]);
1182 domain.ghost_get<2>();
1183 anasol[0]=-
Lap(sol[0]);
1184 anasol[1]=-
Lap(sol[1]);
1185 double worst1 = 0.0,worst2 = 0.0;
1187 for(
int j=0;j<bulk.
size();j++)
1188 {
auto p=bulk.get<0>(j);
1189 if (fabs(domain.getProp<3>(p)[0]- domain.getProp<1>(p)[0]) >= worst1) {
1190 worst1 = fabs(domain.getProp<3>(p)[0] - domain.getProp<1>(p)[0]);
1192 if (fabs(domain.getProp<3>(p)[1]- domain.getProp<1>(p)[1]) >= worst2) {
1193 worst2 = fabs(domain.getProp<3>(p)[1] - domain.getProp<1>(p)[1]);
1195 domain.getProp<4>(p)[0] = fabs(domain.getProp<1>(p)[0] - domain.getProp<3>(p)[0]);
1196 domain.getProp<4>(p)[1] = fabs(domain.getProp<1>(p)[1] - domain.getProp<3>(p)[1]);
1200 BOOST_REQUIRE(worst1 < 1.0);
1201 BOOST_REQUIRE(worst2 < 1.0);
1203 domain.write(
"Neumann2d");
1207 BOOST_AUTO_TEST_CASE(dcpse_slice_solver) {
1210 const size_t sz[2] = {31,31};
1212 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
1213 double spacing = box.getHigh(0) / (sz[0] - 1);
1214 double rCut = 3.1 * spacing;
1216 BOOST_TEST_MESSAGE(
"Init vector_dist...");
1218 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);
1222 BOOST_TEST_MESSAGE(
"Init domain...");
1224 auto it = domain.getGridIterator(sz);
1225 while (it.isNext()) {
1228 auto key = it.get();
1229 double x = key.get(0) * it.getSpacing(0);
1230 domain.getLastPos()[0] = x;
1231 double y = key.get(1) * it.getSpacing(1);
1232 domain.getLastPos()[1] = y;
1236 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
1239 domain.ghost_get<0>();
1241 Derivative_x Dx(domain, 2, rCut,1.9,support_options::RADIUS);
1242 Derivative_y Dy(domain, 2, rCut,1.9,support_options::RADIUS);
1243 Laplacian
Lap(domain, 2, rCut,1.9,support_options::RADIUS);
1253 auto v = getV<0>(domain);
1254 auto RHS=getV<1>(domain);
1255 auto sol = getV<2>(domain);
1256 auto anasol = getV<3>(domain);
1257 auto err = getV<4>(domain);
1258 auto DCPSE_sol=getV<5>(domain);
1262 Box<2, double> up({box.getLow(0) - spacing / 2.0, box.getHigh(1) - spacing / 2.0},
1263 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) + spacing / 2.0});
1265 Box<2, double> down({box.getLow(0) - spacing / 2.0, box.getLow(1) - spacing / 2.0},
1266 {box.getHigh(0) + spacing / 2.0, box.getLow(1) + spacing / 2.0});
1268 Box<2, double> left({box.getLow(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
1269 {box.getLow(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
1271 Box<2, double> right({box.getHigh(0) - spacing / 2.0, box.getLow(1) + spacing / 2.0},
1272 {box.getHigh(0) + spacing / 2.0, box.getHigh(1) - spacing / 2.0});
1287 auto it2 = domain.getDomainIterator();
1289 while (it2.isNext()) {
1292 if (up.isInside(xp) ==
true) {
1294 up_p.last().get<0>() = p.getKey();
1295 domain.getProp<1>(p)[0] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1296 domain.getProp<3>(p)[0] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1298 domain.getProp<1>(p)[1] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1299 domain.getProp<3>(p)[1] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1302 }
else if (down.isInside(xp) ==
true) {
1304 dw_p.last().get<0>() = p.getKey();
1305 domain.getProp<1>(p)[0] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1306 domain.getProp<3>(p)[0] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1308 domain.getProp<1>(p)[1] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1309 domain.getProp<3>(p)[1] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1311 }
else if (left.isInside(xp) ==
true) {
1313 l_p.last().get<0>() = p.getKey();
1314 domain.getProp<1>(p)[0] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1315 domain.getProp<3>(p)[0] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1317 domain.getProp<1>(p)[1] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1318 domain.getProp<3>(p)[1] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1320 }
else if (right.isInside(xp) ==
true) {
1322 r_p.last().get<0>() = p.getKey();
1323 domain.getProp<1>(p)[0] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1324 domain.getProp<3>(p)[0] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1326 domain.getProp<1>(p)[1] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1327 domain.getProp<3>(p)[1] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1331 bulk.last().get<0>() = p.getKey();
1332 domain.getProp<1>(p)[0] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1333 domain.getProp<3>(p)[0] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1335 domain.getProp<1>(p)[1] = -2*M_PI*M_PI*sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1336 domain.getProp<3>(p)[1] = sin(M_PI*xp.
get(0))*sin(M_PI*xp.
get(1));
1346 DCPSE_scheme<
equations2d2,
decltype(domain)> Solver(domain);
1347 auto Poisson0 =
Lap(v[0]);
1348 auto Poisson1 =
Lap(v[1]);
1351 Solver.impose(Poisson0, bulk, RHS[0],
vx);
1352 Solver.impose(Poisson1, bulk, RHS[1],vy);
1353 Solver.impose(v[0], up_p, RHS[0],
vx);
1354 Solver.impose(v[1], up_p, RHS[1],vy);
1355 Solver.impose(v[0], r_p, RHS[0],
vx);
1356 Solver.impose(v[1], r_p, RHS[1],vy);
1357 Solver.impose(v[0], dw_p, RHS[0],
vx);
1358 Solver.impose(v[1], dw_p, RHS[1],vy);
1359 Solver.impose(v[0], l_p, RHS[0],
vx);
1360 Solver.impose(v[1], l_p, RHS[1],vy);
1361 Solver.solve(sol[0],sol[1]);
1363 double worst1 = 0.0;
1364 double worst2 = 0.0;
1369 for(
int j=0;j<bulk.
size();j++)
1370 {
auto p=bulk.get<0>(j);
1371 if (fabs(domain.getProp<3>(p)[0] - domain.getProp<2>(p)[0]) >= worst1) {
1372 worst1 = fabs(domain.getProp<3>(p)[0] - domain.getProp<2>(p)[0]);
1374 domain.getProp<4>(p)[0] = fabs(domain.getProp<3>(p)[0] - domain.getProp<2>(p)[0]);
1377 for(
int j=0;j<bulk.
size();j++)
1378 {
auto p=bulk.get<0>(j);
1379 if (fabs(domain.getProp<3>(p)[1] - domain.getProp<2>(p)[1]) >= worst2) {
1380 worst2 = fabs(domain.getProp<3>(p)[1] - domain.getProp<2>(p)[1]);
1382 domain.getProp<4>(p)[1] = fabs(domain.getProp<3>(p)[1] - domain.getProp<2>(p)[1]);
1388 BOOST_REQUIRE(worst1 < 0.03);
1389 BOOST_REQUIRE(worst2 < 0.03);
1394BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
Laplacian second order on h (spacing)
This class implement the point shape in an N-dimensional space.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
Implementation of 1-D std::vector like structure.
In case T does not match the PETSC precision compilation create a stub structure.
Specify the general characteristic of system to solve.