13#define BOOST_TEST_DYN_LINK
15#include "util/util_debug.hpp"
16#include <boost/test/unit_test.hpp>
18#include "../DCPSE_op.hpp"
19#include "../DCPSE_Solver.hpp"
20#include "Operators/Vector/vector_dist_operators.hpp"
21#include "Vector/vector_dist_subset.hpp"
22#include "../EqnsStruct.hpp"
29BOOST_AUTO_TEST_SUITE(dcpse_op_subset_suite_tests)
31 BOOST_AUTO_TEST_CASE(dcpse_op_subset_tests) {
34 size_t edgeSemiSize = 40;
35 const size_t sz[2] = {2 * edgeSemiSize, 2 * edgeSemiSize};
37 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
39 spacing[0] = 1.0 / (sz[0] - 1);
40 spacing[1] = 1.0 / (sz[1] - 1);
41 double rCut = 3.9 * spacing[0];
43 double sampling_factor = 4.0;
45 BOOST_TEST_MESSAGE(
"Init vector_dist...");
46 double sigma2 = spacing[0] * spacing[1] / (2 * 4);
48 vector_dist_ws<2, double, aggregate<double, double, double, VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,
double>> Particles(0, box,
51 Particles.setPropNames({
"0",
"1",
"2",
"3",
"4",
"5",
"6"});
53 BOOST_TEST_MESSAGE(
"Init Particles...");
54 std::mt19937 rng{6666666};
56 std::normal_distribution<> gaussian{0, sigma2};
61 auto it = Particles.getGridIterator(sz);
64 double minNormOne = 999;
69 mem_id k0 = key.get(0);
70 double x = k0 * spacing[0];
71 Particles.getLastPos()[0] = x;
72 mem_id k1 = key.get(1);
73 double y = k1 * spacing[1];
74 Particles.getLastPos()[1] = y;
76 Particles.template getLastProp<0>() = sin(Particles.getLastPos()[0]) + sin(Particles.getLastPos()[1]);
78 if (k0 != 0 && k1 != 0 && k0 != sz[0] -1 && k1 != sz[1] - 1)
83 Particles.getLastSubset(0);
89 Particles.getLastSubset(1);
96 BOOST_TEST_MESSAGE(
"Sync Particles across processors...");
99 Particles.ghost_get<0>();
101 auto git = Particles.getGhostIterator();
107 Particles.template getProp<0>(p) = std::numeric_limits<double>::quiet_NaN();
112 vector_dist_subset<2, double, aggregate<double, double, double, VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,
double>> Particles_bulk(Particles,0);
113 vector_dist_subset<2, double, aggregate<double, double, double, VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,
double>> Particles_boundary(Particles,1);
114 auto & boundary = Particles_boundary.getIds();
117 auto P = getV<0>(Particles);
118 auto Out = getV<1>(Particles);
119 auto Pb = getV<2>(Particles);
120 auto Out_V = getV<3>(Particles);
123 auto P_bulk = getV<2>(Particles_bulk);
124 auto Out_bulk = getV<1>(Particles_bulk);
125 auto Out_V_bulk = getV<3>(Particles_bulk);
138 Derivative_x Dx_bulk(Particles_bulk, 2, rCut,sampling_factor, support_options::RADIUS);
139 Derivative_y Dy_bulk(Particles_bulk, 2, rCut,sampling_factor, support_options::RADIUS);
141 Out_bulk = Dx_bulk(
P);
142 Out_V_bulk[0] =
P + Dx_bulk(
P);
143 Out_V_bulk[1] = Out_V[0] +Dy_bulk(
P);
148 auto & v_cl = create_vcluster();
151 auto it2 = Particles_bulk.getDomainIterator();
161 is_nan |= std::isnan(Particles_bulk.template getProp<1>(p));
168 BOOST_REQUIRE_EQUAL(is_nan,
true);
174 Particles.ghost_get<0>();
175 Particles.write(
"TEST");
177 for (
int i = 0 ; i < boundary.size() ; i++)
179 Particles.template getProp<0>(boundary.template get<0>(i)) = std::numeric_limits<double>::quiet_NaN();
182 Particles.ghost_get<0>();
184 Out_bulk = Dx_bulk(
P);
185 Out_V_bulk[0] =
P + Dx_bulk(
P);
186 Out_V_bulk[1] = Out_V[0] +Dy_bulk(
P);
188 auto it2 = Particles_bulk.getDomainIterator();
193 BOOST_REQUIRE_EQUAL(Particles_bulk.getProp<2>(p),15.0);
194 BOOST_REQUIRE(fabs(Particles_bulk.getProp<1>(p) - cos(Particles_bulk.getPos(p)[0])) < 0.005 );
195 BOOST_REQUIRE(fabs(Particles_bulk.getProp<3>(p)[0] - Particles_bulk.getProp<0>(p) - cos(Particles_bulk.getPos(p)[0])) < 0.001 );
196 BOOST_REQUIRE(fabs(Particles_bulk.getProp<3>(p)[1] - Particles_bulk.getProp<3>(p)[0] - cos(Particles_bulk.getPos(p)[1])) < 0.001 );
204 BOOST_AUTO_TEST_CASE(dcpse_op_subset_PC_lid) {
209 size_t edgeSemiSize = 20;
210 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
212 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
214 spacing[0] = 1.0 / (sz[0] - 1);
215 spacing[1] = 1.0 / (sz[1] - 1);
216 double rCut = 3.9 * spacing[0];
218 double sampling_factor = 4.0;
220 BOOST_TEST_MESSAGE(
"Init vector_dist...");
221 double sigma2 = spacing[0] * spacing[1] / (2 * 4);
222 auto &v_cl = create_vcluster();
224 typedef aggregate<double, VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,double,
VectorS<2, double>,
VectorS<2, double>,
double> particle_type;
229 BOOST_TEST_MESSAGE(
"Init Particles...");
234 auto it = Particles.getGridIterator(sz);
239 mem_id k0 = key.get(0);
240 double xp0 = k0 * spacing[0];
241 Particles.getLastPos()[0] = xp0;
242 mem_id k1 = key.get(1);
243 double yp0 = k1 * spacing[1];
244 Particles.getLastPos()[1] = yp0;
247 BOOST_TEST_MESSAGE(
"Sync Particles across processors...");
249 Particles.ghost_get<0>();
251 auto it2 = Particles.getDomainIterator();
252 while (it2.isNext()) {
255 if (xp[0] != 0 && xp[1] != 0 && xp[0] != 1.0 && xp[1] != 1.0) {
258 Particles.setSubset(p,0);
259 Particles.getProp<3>(p)[x] = 3.0;
260 Particles.getProp<3>(p)[y] = 3.0;
264 Particles.setSubset(p,1);
265 Particles.getProp<3>(p)[x] = xp[0]*xp[0]+xp[1]*xp[1];
266 Particles.getProp<3>(p)[y] = xp[0]*xp[0]-2*xp[0]*xp[1];
268 Particles.getProp<6>(p)[x] = xp[0]*xp[0]+xp[1]*xp[1];
269 Particles.getProp<6>(p)[y] = xp[0]*xp[0]-2*xp[0]*xp[1];
270 Particles.getProp<7>(p) = xp[0]+xp[1]-1.0;
277 auto & bulk = Particles_bulk.getIds();
278 auto & boundary = Particles_boundary.getIds();
280 auto P = getV<0>(Particles);
281 auto V = getV<1>(Particles);
282 auto RHS = getV<2>(Particles);
283 auto dV = getV<3>(Particles);
284 auto div = getV<4>(Particles);
285 auto V_star = getV<5>(Particles);
288 auto P_bulk = getV<0>(Particles_bulk);
289 auto RHS_bulk =getV<2>(Particles_bulk);
293 Derivative_x Dx(Particles, 2, rCut,sampling_factor, support_options::RADIUS);
294 Derivative_xx Dxx(Particles, 2, rCut,sampling_factor, support_options::RADIUS);
295 Derivative_yy Dyy(Particles, 2, rCut,sampling_factor, support_options::RADIUS);
296 Derivative_y Dy(Particles, 2, rCut,sampling_factor, support_options::RADIUS);
297 Derivative_x Bulk_Dx(Particles_bulk, 2, rCut,sampling_factor, support_options::RADIUS);
298 Derivative_y Bulk_Dy(Particles_bulk, 2, rCut,sampling_factor, support_options::RADIUS);
300 int n = 0, nmax = 5, ctr = 0, errctr=1, Vreset = 0;
311 double sum, sum1, sum_k,V_err_eps=1e-3,V_err_old;
312 auto Stokes1=Dxx(V[x])+Dyy(V[x]);
313 auto Stokes2=Dxx(V[y])+Dyy(V[y]);
322 while (V_err >= V_err_eps && n <= nmax) {
323 Particles.ghost_get<0>(SKIP_LABELLING);
324 RHS_bulk[x] = dV[x] + Bulk_Dx(
P);
325 RHS_bulk[y] = dV[y] + Bulk_Dy(
P);
326 DCPSE_scheme<
equations2d2,
decltype(Particles)> Solver(Particles);
327 Solver.impose(Stokes1, bulk, RHS[0],
vx);
328 Solver.impose(Stokes2, bulk, RHS[1], vy);
329 Solver.impose(V[x], boundary, RHS[0],
vx);
330 Solver.impose(V[y], boundary, RHS[1], vy);
336 Solver.solve_with_solver(solverPetsc, V[x], V[y]);
337 Particles.ghost_get<1>(SKIP_LABELLING);
338 div = -(Dx(V[x]) + Dy(V[y]));
343 for (
int j = 0; j < bulk.size(); j++) {
344 auto p = bulk.get<0>(j);
345 sum += (Particles.getProp<5>(p)[0] - Particles.getProp<1>(p)[0]) *
346 (Particles.getProp<5>(p)[0] - Particles.getProp<1>(p)[0]) +
347 (Particles.getProp<5>(p)[1] - Particles.getProp<1>(p)[1]) *
348 (Particles.getProp<5>(p)[1] - Particles.getProp<1>(p)[1]);
349 sum1 += Particles.getProp<1>(p)[0] * Particles.getProp<1>(p)[0] +
350 Particles.getProp<1>(p)[1] * Particles.getProp<1>(p)[1];
361 if (V_err > V_err_old || abs(V_err_old - V_err) < 1e-8) {
369 std::cout <<
"CONVERGENCE LOOP BROKEN DUE TO INCREASE/VERY SLOW DECREASE IN ERROR" << std::endl;
377 if (v_cl.rank() == 0) {
378 std::cout <<
"Rel l2 cgs err in V = " << V_err <<
" at " << n << std::endl;
384 for(
int j=0;j<bulk.size();j++)
385 {
auto p=bulk.get<0>(j);
386 if (fabs(Particles.getProp<6>(p)[0] - Particles.getProp<1>(p)[0]) >= worst1) {
387 worst1 = fabs(Particles.getProp<6>(p)[0] - Particles.getProp<1>(p)[0]);
390 for(
int j=0;j<bulk.size();j++)
391 {
auto p=bulk.get<0>(j);
392 if (fabs(Particles.getProp<6>(p)[1] - Particles.getProp<1>(p)[1]) >= worst2) {
393 worst2 = fabs(Particles.getProp<6>(p)[1] - Particles.getProp<1>(p)[1]);
398 std::cout <<
"Maximum Analytic Error in Vx: " << worst1 << std::endl;
399 std::cout <<
"Maximum Analytic Error in Vy: " << worst2 << std::endl;
400 BOOST_REQUIRE(worst1 < 0.03);
401 BOOST_REQUIRE(worst2 < 0.03);
406 BOOST_AUTO_TEST_CASE(dcpse_op_subset_PC_lid2) {
411 size_t edgeSemiSize = 20;
412 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
414 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
416 spacing[0] = 1.0 / (sz[0] - 1);
417 spacing[1] = 1.0 / (sz[1] - 1);
418 double rCut = 3.9 * spacing[0];
420 double sampling_factor = 4.0;
422 BOOST_TEST_MESSAGE(
"Init vector_dist...");
423 auto &v_cl = create_vcluster();
425 vector_dist<2, double, aggregate<double, VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,double,
VectorS<2, double>,
VectorS<2, double>,
double>> Particles(0, box,
428 vector_dist<2, double, aggregate<double, VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,double,
VectorS<2, double>,
VectorS<2, double>,
double>> Particles_subset(Particles.getDecomposition(), 0);
432 BOOST_TEST_MESSAGE(
"Init Particles...");
437 auto it = Particles.getGridIterator(sz);
439 double minNormOne = 999;
444 mem_id k0 = key.get(0);
445 double xp0 = k0 * spacing[0];
446 Particles.getLastPos()[0] = xp0;
447 mem_id k1 = key.get(1);
448 double yp0 = k1 * spacing[1];
449 Particles.getLastPos()[1] = yp0;
452 BOOST_TEST_MESSAGE(
"Sync Particles across processors...");
454 Particles.ghost_get<0>();
455 auto it2 = Particles.getDomainIterator();
456 while (it2.isNext()) {
459 if (xp[0] != 0 && xp[1] != 0 && xp[0] != 1.0 && xp[1] != 1.0) {
461 bulk.last().get<0>() = p.getKey();
462 Particles.getProp<3>(p)[x] = 3.0;
463 Particles.getProp<3>(p)[y] = 3.0;
466 boundary.last().get<0>() = p.getKey();
467 Particles.getProp<3>(p)[x] = xp[0]*xp[0]+xp[1]*xp[1];
468 Particles.getProp<3>(p)[y] = xp[0]*xp[0]-2*xp[0]*xp[1];
470 Particles.getProp<6>(p)[x] = xp[0]*xp[0]+xp[1]*xp[1];
471 Particles.getProp<6>(p)[y] = xp[0]*xp[0]-2*xp[0]*xp[1];
472 Particles.getProp<7>(p) = xp[0]+xp[1]-1.0;
477 for (
int i = 0; i < bulk.
size(); i++) {
478 Particles_subset.add();
479 Particles_subset.getLastPos()[0] = Particles.getPos(bulk.template get<0>(i))[0];
480 Particles_subset.getLastPos()[1] = Particles.getPos(bulk.template get<0>(i))[1];
482 Particles_subset.map();
483 Particles_subset.ghost_get<0>();
487 auto P = getV<0>(Particles);
488 auto V = getV<1>(Particles);
489 auto RHS = getV<2>(Particles);
490 auto dV = getV<3>(Particles);
491 auto div = getV<4>(Particles);
492 auto V_star = getV<5>(Particles);
494 auto P_bulk = getV<0>(Particles_subset);
495 auto Grad_bulk= getV<2>(Particles_subset);
499 Derivative_x Dx(Particles, 2, rCut,sampling_factor, support_options::RADIUS);
500 Derivative_x Bulk_Dx(Particles_subset, 2, rCut,sampling_factor, support_options::RADIUS);
501 Derivative_xx Dxx(Particles, 2, rCut,sampling_factor, support_options::RADIUS);
502 Derivative_yy Dyy(Particles, 2, rCut,sampling_factor, support_options::RADIUS);
503 Derivative_y Dy(Particles, 2, rCut,sampling_factor, support_options::RADIUS),Bulk_Dy(Particles_subset, 2, rCut,sampling_factor, support_options::RADIUS);;
505 int n = 0, nmax = 5, ctr = 0, errctr=0, Vreset = 0;
516 double sum, sum1, sum_k,V_err_eps=1e-3,V_err_old;
517 auto Stokes1=Dxx(V[x])+Dyy(V[x]);
518 auto Stokes2=Dxx(V[y])+Dyy(V[y]);
525 while (V_err >= V_err_eps && n <= nmax) {
528 Particles_subset.ghost_get<0>(SKIP_LABELLING);
530 Grad_bulk[x] = Bulk_Dx(P_bulk);
531 Grad_bulk[y] = Bulk_Dy(P_bulk);
532 for (
int i = 0; i < bulk.
size(); i++) {
533 Particles.template getProp<2>(bulk.template get<0>(i))[x] += Particles_subset.getProp<2>(i)[x];
534 Particles.template getProp<2>(bulk.template get<0>(i))[y] += Particles_subset.getProp<2>(i)[y];
537 DCPSE_scheme<
equations2d2,
decltype(Particles)> Solver(Particles);
538 Solver.impose(Stokes1, bulk, RHS[0],
vx);
539 Solver.impose(Stokes2, bulk, RHS[1], vy);
540 Solver.impose(V[x], boundary, RHS[0],
vx);
541 Solver.impose(V[y], boundary, RHS[1], vy);
542 Solver.solve_with_solver(solverPetsc, V[x], V[y]);
543 Particles.ghost_get<1>(SKIP_LABELLING);
544 div = -(Dx(V[x]) + Dy(V[y]));
546 for (
int i = 0; i < bulk.
size(); i++) {
547 Particles_subset.getProp<0>(i) = Particles.template getProp<0>(bulk.template get<0>(i));
552 for (
int j = 0; j < bulk.
size(); j++) {
553 auto p = bulk.get<0>(j);
554 sum += (Particles.getProp<5>(p)[0] - Particles.getProp<1>(p)[0]) *
555 (Particles.getProp<5>(p)[0] - Particles.getProp<1>(p)[0]) +
556 (Particles.getProp<5>(p)[1] - Particles.getProp<1>(p)[1]) *
557 (Particles.getProp<5>(p)[1] - Particles.getProp<1>(p)[1]);
558 sum1 += Particles.getProp<1>(p)[0] * Particles.getProp<1>(p)[0] +
559 Particles.getProp<1>(p)[1] * Particles.getProp<1>(p)[1];
570 if (V_err > V_err_old || abs(V_err_old - V_err) < 1e-8) {
578 std::cout <<
"CONVERGENCE LOOP BROKEN DUE TO INCREASE/VERY SLOW DECREASE IN ERROR" << std::endl;
586 if (v_cl.rank() == 0) {
587 std::cout <<
"Rel l2 cgs err in V = " << V_err <<
" at " << n << std::endl;
594 for(
int j=0;j<bulk.
size();j++)
595 {
auto p=bulk.get<0>(j);
596 if (fabs(Particles.getProp<6>(p)[0] - Particles.getProp<1>(p)[0]) >= worst1) {
597 worst1 = fabs(Particles.getProp<6>(p)[0] - Particles.getProp<1>(p)[0]);
600 for(
int j=0;j<bulk.
size();j++)
601 {
auto p=bulk.get<0>(j);
602 if (fabs(Particles.getProp<6>(p)[1] - Particles.getProp<1>(p)[1]) >= worst2) {
603 worst2 = fabs(Particles.getProp<6>(p)[1] - Particles.getProp<1>(p)[1]);
607 std::cout <<
"Maximum Analytic Error in slice x: " << worst1 << std::endl;
608 std::cout <<
"Maximum Analytic Error in slice y: " << worst2 << std::endl;
609 BOOST_REQUIRE(worst1 < 0.03);
610 BOOST_REQUIRE(worst2 < 0.03);
615BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
Test structure used for several test.
This class implement the point shape in an N-dimensional space.
Implementation of 1-D std::vector like structure.
In case T does not match the PETSC precision compilation create a stub structure.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
It model an expression expr1 + ... exprn.