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 "../DCPSE_Solver.cuh"
21#include "Operators/Vector/vector_dist_operators.hpp"
22#include "Vector/vector_dist_subset.hpp"
23#include "../EqnsStruct.hpp"
29BOOST_AUTO_TEST_SUITE(dcpse_op_subset_suite_tests_cu)
31 BOOST_AUTO_TEST_CASE(dcpse_op_subset_tests) {
32 size_t edgeSemiSize = 40;
33 const size_t sz[2] = {2 * edgeSemiSize, 2 * edgeSemiSize};
35 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
37 spacing[0] = 1.0 / (sz[0] - 1);
38 spacing[1] = 1.0 / (sz[1] - 1);
39 double rCut = 3.9 * spacing[0];
41 double sampling_factor = 4.0;
43 BOOST_TEST_MESSAGE(
"Init vector_dist...");
44 double sigma2 = spacing[0] * spacing[1] / (2 * 4);
46 vector_dist_ws_gpu<2, double, aggregate<double, double, double, VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,
double>> Particles(0, box,
51 BOOST_TEST_MESSAGE(
"Init Particles...");
52 std::mt19937 rng{6666666};
54 std::normal_distribution<> gaussian{0, sigma2};
59 auto it = Particles.getGridIterator(sz);
62 double minNormOne = 999;
67 mem_id k0 = key.get(0);
68 double x = k0 * spacing[0];
69 Particles.getLastPos()[0] = x;
70 mem_id k1 = key.get(1);
71 double y = k1 * spacing[1];
72 Particles.getLastPos()[1] = y;
74 Particles.template getLastProp<0>() = sin(Particles.getLastPos()[0]) + sin(Particles.getLastPos()[1]);
76 if (k0 != 0 && k1 != 0 && k0 != sz[0] -1 && k1 != sz[1] - 1)
81 Particles.getLastSubset(0);
87 Particles.getLastSubset(1);
94 BOOST_TEST_MESSAGE(
"Sync Particles across processors...");
97 Particles.ghost_get<0>();
99 auto git = Particles.getGhostIterator();
105 Particles.template getProp<0>(p) = std::numeric_limits<double>::quiet_NaN();
110 vector_dist_subset_gpu<2, double, aggregate<double, double, double, VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,
double>> Particles_bulk(Particles,0);
111 vector_dist_subset_gpu<2, double, aggregate<double, double, double, VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,
double>> Particles_boundary(Particles,1);
112 auto & boundary = Particles_boundary.getIds();
115 auto P = getV<0>(Particles);
116 auto Out = getV<1>(Particles);
117 auto Pb = getV<2>(Particles);
118 auto Out_V = getV<3>(Particles);
121 auto P_bulk = getV<2>(Particles_bulk);
122 auto Out_bulk = getV<1>(Particles_bulk);
123 auto Out_V_bulk = getV<3>(Particles_bulk);
136 Derivative_x_gpu Dx_bulk(Particles_bulk, 2, rCut,sampling_factor, support_options::RADIUS);
137 Derivative_y_gpu Dy_bulk(Particles_bulk, 2, rCut,sampling_factor, support_options::RADIUS);
139 Out_bulk = Dx_bulk(
P);
140 Out_V_bulk[0] =
P + Dx_bulk(
P);
141 Out_V_bulk[1] = Out_V[0] +Dy_bulk(
P);
146 auto & v_cl = create_vcluster();
149 auto it2 = Particles_bulk.getDomainIterator();
159 is_nan |= std::isnan(Particles_bulk.template getProp<1>(p));
166 BOOST_REQUIRE_EQUAL(is_nan,
true);
172 Particles.ghost_get<0>();
174 for (
int i = 0 ; i < boundary.size() ; i++)
176 Particles.template getProp<0>(boundary.template get<0>(i)) = std::numeric_limits<double>::quiet_NaN();
179 Particles.ghost_get<0>();
181 Out_bulk = Dx_bulk(
P);
182 Out_V_bulk[0] =
P + Dx_bulk(
P);
183 Out_V_bulk[1] = Out_V[0] +Dy_bulk(
P);
185 auto it2 = Particles_bulk.getDomainIterator();
190 BOOST_REQUIRE_EQUAL(Particles_bulk.getProp<2>(p),15.0);
191 BOOST_REQUIRE(fabs(Particles_bulk.getProp<1>(p) - cos(Particles_bulk.getPos(p)[0])) < 0.005 );
192 BOOST_REQUIRE(fabs(Particles_bulk.getProp<3>(p)[0] - Particles_bulk.getProp<0>(p) - cos(Particles_bulk.getPos(p)[0])) < 0.001 );
193 BOOST_REQUIRE(fabs(Particles_bulk.getProp<3>(p)[1] - Particles_bulk.getProp<3>(p)[0] - cos(Particles_bulk.getPos(p)[1])) < 0.001 );
202 BOOST_AUTO_TEST_CASE(dcpse_op_subset_PC_lid) {
207 size_t edgeSemiSize = 20;
208 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
210 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
212 spacing[0] = 1.0 / (sz[0] - 1);
213 spacing[1] = 1.0 / (sz[1] - 1);
214 double rCut = 3.9 * spacing[0];
216 double sampling_factor = 4.0;
218 BOOST_TEST_MESSAGE(
"Init vector_dist...");
219 double sigma2 = spacing[0] * spacing[1] / (2 * 4);
220 auto &v_cl = create_vcluster();
222 typedef aggregate<double, VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,double,
VectorS<2, double>,
VectorS<2, double>,
double> particle_type;
227 BOOST_TEST_MESSAGE(
"Init Particles...");
232 auto it = Particles.getGridIterator(sz);
237 mem_id k0 = key.get(0);
238 double xp0 = k0 * spacing[0];
239 Particles.getLastPos()[0] = xp0;
240 mem_id k1 = key.get(1);
241 double yp0 = k1 * spacing[1];
242 Particles.getLastPos()[1] = yp0;
245 BOOST_TEST_MESSAGE(
"Sync Particles across processors...");
247 Particles.ghost_get<0>();
249 auto it2 = Particles.getDomainIterator();
250 while (it2.isNext()) {
253 if (xp[0] != 0 && xp[1] != 0 && xp[0] != 1.0 && xp[1] != 1.0) {
256 Particles.setSubset(p,0);
257 Particles.getProp<3>(p)[x] = 3.0;
258 Particles.getProp<3>(p)[y] = 3.0;
262 Particles.setSubset(p,1);
263 Particles.getProp<3>(p)[x] = xp[0]*xp[0]+xp[1]*xp[1];
264 Particles.getProp<3>(p)[y] = xp[0]*xp[0]-2*xp[0]*xp[1];
266 Particles.getProp<6>(p)[x] = xp[0]*xp[0]+xp[1]*xp[1];
267 Particles.getProp<6>(p)[y] = xp[0]*xp[0]-2*xp[0]*xp[1];
268 Particles.getProp<7>(p) = xp[0]+xp[1]-1.0;
275 auto & bulk = Particles_bulk.getIds();
276 auto & boundary = Particles_boundary.getIds();
278 auto P = getV<0>(Particles);
279 auto V = getV<1>(Particles);
280 auto RHS = getV<2>(Particles);
281 auto dV = getV<3>(Particles);
282 auto div = getV<4>(Particles);
283 auto V_star = getV<5>(Particles);
286 auto P_bulk = getV<0>(Particles_bulk);
287 auto RHS_bulk =getV<2>(Particles_bulk);
291 Derivative_x_gpu Dx(Particles, 2, rCut,sampling_factor, support_options::RADIUS);
292 Derivative_xx_gpu Dxx(Particles, 2, rCut,sampling_factor, support_options::RADIUS);
293 Derivative_yy_gpu Dyy(Particles, 2, rCut,sampling_factor, support_options::RADIUS);
294 Derivative_y_gpu Dy(Particles, 2, rCut,sampling_factor, support_options::RADIUS);
295 Derivative_x_gpu Bulk_Dx(Particles_bulk, 2, rCut,sampling_factor, support_options::RADIUS);
296 Derivative_y_gpu Bulk_Dy(Particles_bulk, 2, rCut,sampling_factor, support_options::RADIUS);
298 int n = 0, nmax = 5, ctr = 0, errctr=1, Vreset = 0;
309 double sum, sum1, sum_k,V_err_eps=1e-3,V_err_old;
310 auto Stokes1=Dxx(V[x])+Dyy(V[x]);
311 auto Stokes2=Dxx(V[y])+Dyy(V[y]);
320 while (V_err >= V_err_eps && n <= nmax) {
321 Particles.ghost_get<0>(SKIP_LABELLING);
322 RHS_bulk[x] = dV[x] + Bulk_Dx(
P);
323 RHS_bulk[y] = dV[y] + Bulk_Dy(
P);
324 DCPSE_scheme_gpu<equations2d2_gpu,
decltype(Particles)> Solver(Particles);
325 Solver.impose(Stokes1, bulk, RHS[0],
vx);
326 Solver.impose(Stokes2, bulk, RHS[1], vy);
327 Solver.impose(V[x], boundary, RHS[0],
vx);
328 Solver.impose(V[y], boundary, RHS[1], vy);
334 Solver.solve_with_solver(solverPetsc, V[x], V[y]);
335 Particles.ghost_get<1>(SKIP_LABELLING);
336 div = -(Dx(V[x]) + Dy(V[y]));
341 for (
int j = 0; j < bulk.size(); j++) {
342 auto p = bulk.get<0>(j);
343 sum += (Particles.getProp<5>(p)[0] - Particles.getProp<1>(p)[0]) *
344 (Particles.getProp<5>(p)[0] - Particles.getProp<1>(p)[0]) +
345 (Particles.getProp<5>(p)[1] - Particles.getProp<1>(p)[1]) *
346 (Particles.getProp<5>(p)[1] - Particles.getProp<1>(p)[1]);
347 sum1 += Particles.getProp<1>(p)[0] * Particles.getProp<1>(p)[0] +
348 Particles.getProp<1>(p)[1] * Particles.getProp<1>(p)[1];
359 if (V_err > V_err_old || abs(V_err_old - V_err) < 1e-8) {
367 std::cout <<
"CONVERGENCE LOOP BROKEN DUE TO INCREASE/VERY SLOW DECREASE IN ERROR" << std::endl;
375 if (v_cl.rank() == 0) {
376 std::cout <<
"Rel l2 cgs err in V = " << V_err <<
" at " << n << std::endl;
382 for(
int j=0;j<bulk.size();j++)
383 {
auto p=bulk.get<0>(j);
384 if (fabs(Particles.getProp<6>(p)[0] - Particles.getProp<1>(p)[0]) >= worst1) {
385 worst1 = fabs(Particles.getProp<6>(p)[0] - Particles.getProp<1>(p)[0]);
388 for(
int j=0;j<bulk.size();j++)
389 {
auto p=bulk.get<0>(j);
390 if (fabs(Particles.getProp<6>(p)[1] - Particles.getProp<1>(p)[1]) >= worst2) {
391 worst2 = fabs(Particles.getProp<6>(p)[1] - Particles.getProp<1>(p)[1]);
396 std::cout <<
"Maximum Analytic Error in Vx: " << worst1 << std::endl;
397 std::cout <<
"Maximum Analytic Error in Vy: " << worst2 << std::endl;
398 BOOST_REQUIRE(worst1 < 0.03);
399 BOOST_REQUIRE(worst2 < 0.03);
404 BOOST_AUTO_TEST_CASE(dcpse_op_subset_PC_lid2) {
409 size_t edgeSemiSize = 20;
410 const size_t sz[2] = {2 * edgeSemiSize+1, 2 * edgeSemiSize+1};
412 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
414 spacing[0] = 1.0 / (sz[0] - 1);
415 spacing[1] = 1.0 / (sz[1] - 1);
416 double rCut = 3.9 * spacing[0];
418 double sampling_factor = 4.0;
420 BOOST_TEST_MESSAGE(
"Init vector_dist...");
421 auto &v_cl = create_vcluster();
423 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,
426 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);
430 BOOST_TEST_MESSAGE(
"Init Particles...");
435 auto it = Particles.getGridIterator(sz);
437 double minNormOne = 999;
442 mem_id k0 = key.get(0);
443 double xp0 = k0 * spacing[0];
444 Particles.getLastPos()[0] = xp0;
445 mem_id k1 = key.get(1);
446 double yp0 = k1 * spacing[1];
447 Particles.getLastPos()[1] = yp0;
450 BOOST_TEST_MESSAGE(
"Sync Particles across processors...");
452 Particles.ghost_get<0>();
453 auto it2 = Particles.getDomainIterator();
454 while (it2.isNext()) {
457 if (xp[0] != 0 && xp[1] != 0 && xp[0] != 1.0 && xp[1] != 1.0) {
459 bulk.last().get<0>() = p.getKey();
460 Particles.getProp<3>(p)[x] = 3.0;
461 Particles.getProp<3>(p)[y] = 3.0;
464 boundary.last().get<0>() = p.getKey();
465 Particles.getProp<3>(p)[x] = xp[0]*xp[0]+xp[1]*xp[1];
466 Particles.getProp<3>(p)[y] = xp[0]*xp[0]-2*xp[0]*xp[1];
468 Particles.getProp<6>(p)[x] = xp[0]*xp[0]+xp[1]*xp[1];
469 Particles.getProp<6>(p)[y] = xp[0]*xp[0]-2*xp[0]*xp[1];
470 Particles.getProp<7>(p) = xp[0]+xp[1]-1.0;
475 for (
int i = 0; i < bulk.
size(); i++) {
476 Particles_subset.add();
477 Particles_subset.getLastPos()[0] = Particles.getPos(bulk.template get<0>(i))[0];
478 Particles_subset.getLastPos()[1] = Particles.getPos(bulk.template get<0>(i))[1];
480 Particles_subset.map();
481 Particles_subset.ghost_get<0>();
485 auto P = getV<0>(Particles);
486 auto V = getV<1>(Particles);
487 auto RHS = getV<2>(Particles);
488 auto dV = getV<3>(Particles);
489 auto div = getV<4>(Particles);
490 auto V_star = getV<5>(Particles);
492 auto P_bulk = getV<0>(Particles_subset);
493 auto Grad_bulk= getV<2>(Particles_subset);
497 Derivative_x Dx(Particles, 2, rCut,sampling_factor, support_options::RADIUS);
498 Derivative_x Bulk_Dx(Particles_subset, 2, rCut,sampling_factor, support_options::RADIUS);
499 Derivative_xx Dxx(Particles, 2, rCut,sampling_factor, support_options::RADIUS);
500 Derivative_yy Dyy(Particles, 2, rCut,sampling_factor, support_options::RADIUS);
501 Derivative_y Dy(Particles, 2, rCut,sampling_factor, support_options::RADIUS),Bulk_Dy(Particles_subset, 2, rCut,sampling_factor, support_options::RADIUS);;
503 int n = 0, nmax = 5, ctr = 0, errctr=0, Vreset = 0;
514 double sum, sum1, sum_k,V_err_eps=1e-3,V_err_old;
515 auto Stokes1=Dxx(V[x])+Dyy(V[x]);
516 auto Stokes2=Dxx(V[y])+Dyy(V[y]);
523 while (V_err >= V_err_eps && n <= nmax) {
526 Particles_subset.ghost_get<0>(SKIP_LABELLING);
528 Grad_bulk[x] = Bulk_Dx(P_bulk);
529 Grad_bulk[y] = Bulk_Dy(P_bulk);
530 for (
int i = 0; i < bulk.
size(); i++) {
531 Particles.template getProp<2>(bulk.template get<0>(i))[x] += Particles_subset.getProp<2>(i)[x];
532 Particles.template getProp<2>(bulk.template get<0>(i))[y] += Particles_subset.getProp<2>(i)[y];
535 DCPSE_scheme<equations2d2_gpu,
decltype(Particles)> Solver(Particles);
536 Solver.impose(Stokes1, bulk, RHS[0],
vx);
537 Solver.impose(Stokes2, bulk, RHS[1], vy);
538 Solver.impose(V[x], boundary, RHS[0],
vx);
539 Solver.impose(V[y], boundary, RHS[1], vy);
540 Solver.solve_with_solver(solverPetsc, V[x], V[y]);
541 Particles.ghost_get<1>(SKIP_LABELLING);
542 div = -(Dx(V[x]) + Dy(V[y]));
544 for (
int i = 0; i < bulk.
size(); i++) {
545 Particles_subset.getProp<0>(i) = Particles.template getProp<0>(bulk.template get<0>(i));
550 for (
int j = 0; j < bulk.
size(); j++) {
551 auto p = bulk.get<0>(j);
552 sum += (Particles.getProp<5>(p)[0] - Particles.getProp<1>(p)[0]) *
553 (Particles.getProp<5>(p)[0] - Particles.getProp<1>(p)[0]) +
554 (Particles.getProp<5>(p)[1] - Particles.getProp<1>(p)[1]) *
555 (Particles.getProp<5>(p)[1] - Particles.getProp<1>(p)[1]);
556 sum1 += Particles.getProp<1>(p)[0] * Particles.getProp<1>(p)[0] +
557 Particles.getProp<1>(p)[1] * Particles.getProp<1>(p)[1];
568 if (V_err > V_err_old || abs(V_err_old - V_err) < 1e-8) {
576 std::cout <<
"CONVERGENCE LOOP BROKEN DUE TO INCREASE/VERY SLOW DECREASE IN ERROR" << std::endl;
584 if (v_cl.rank() == 0) {
585 std::cout <<
"Rel l2 cgs err in V = " << V_err <<
" at " << n << std::endl;
592 for(
int j=0;j<bulk.
size();j++)
593 {
auto p=bulk.get<0>(j);
594 if (fabs(Particles.getProp<6>(p)[0] - Particles.getProp<1>(p)[0]) >= worst1) {
595 worst1 = fabs(Particles.getProp<6>(p)[0] - Particles.getProp<1>(p)[0]);
598 for(
int j=0;j<bulk.
size();j++)
599 {
auto p=bulk.get<0>(j);
600 if (fabs(Particles.getProp<6>(p)[1] - Particles.getProp<1>(p)[1]) >= worst2) {
601 worst2 = fabs(Particles.getProp<6>(p)[1] - Particles.getProp<1>(p)[1]);
605 std::cout <<
"Maximum Analytic Error in slice x: " << worst1 << std::endl;
606 std::cout <<
"Maximum Analytic Error in slice y: " << worst2 << std::endl;
607 BOOST_REQUIRE(worst1 < 0.03);
608 BOOST_REQUIRE(worst2 < 0.03);
612BOOST_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.