8#ifndef OPENFPM_NUMERICS_SRC_SOLVERS_PETSC_SOLVER_UNIT_TESTS_CPP_
9#define OPENFPM_NUMERICS_SRC_SOLVERS_PETSC_SOLVER_UNIT_TESTS_CPP_
13#define BOOST_TEST_DYN_LINK
14#include <boost/test/unit_test.hpp>
16#include "petsc_solver_report_unit_tests.hpp"
18#include "Grid/grid_dist_id.hpp"
19#include "Matrix/SparseMatrix.hpp"
20#include "Vector/Vector.hpp"
21#include "FiniteDifference/Laplacian.hpp"
22#include "FiniteDifference/FDScheme.hpp"
23#include "Solvers/petsc_solver.hpp"
26BOOST_AUTO_TEST_SUITE( mg_solvers_test )
29BOOST_AUTO_TEST_CASE( laplacian_3D_int_zero_mg )
31 constexpr unsigned int phi = 0;
50 size_t center_x = psi.size(0) / 2;
51 size_t center_y = psi.size(1) / 2;
52 size_t center_z = psi.size(2) / 2;
53 auto it = psi.getDomainIterator();
58 auto gkey = it.getGKey(key);
60 float sx = (float)(gkey.get(0))-center_x;
61 float sy = (float)(gkey.get(1))-center_y;
62 float sz = (float)(gkey.get(2))-center_z;
64 float gs = 100.0*exp(-((sx*sx)+(sy*sy)+(sz*sz))/100.0);
66 psi.get<0>(key) = sin(2*M_PI*sx/psi.size(0))*sin(2*M_PI*sy/psi.size(1))*sin(2*M_PI*sz/psi.size(2))*gs;
67 psi2.get<0>(key) = sin(2*M_PI*sx/psi.size(0))*sin(2*M_PI*sy/psi.size(1))*sin(2*M_PI*sz/psi.size(2))*gs;
74 fd.template impose_dit<0>(poisson(),psi,psi.getDomainIterator());
77 solver.setSolver(KSPBCGS);
78 solver.setAbsTol(0.01);
79 solver.setMaxIter(500);
83 solver.setPreconditioner(PCHYPRE_BOOMERAMG);
84 solver.setPreconditionerAMG_nl(6);
85 solver.setPreconditionerAMG_maxit(3);
86 solver.setPreconditionerAMG_relax(
"SOR/Jacobi");
87 solver.setPreconditionerAMG_cycleType(
"V",6,6);
88 solver.setPreconditionerAMG_coarsen(
"HMIS");
89 solver.setPreconditionerAMG_coarsenNodalType(0);
93 auto x_ = solver.
solve(fd.getA(),fd.getB());
96 fd.template copy<phi>(x_,psi);
100 bool check = compare(
"AMG_psi_" + std::to_string(v_cl.
getProcessUnitID()) +
".vtk",
"test/AMG_psi_" + std::to_string(v_cl.
getProcessUnitID()) +
"_test_osx.vtk");
103 bool check = compare(
"AMG_psi_" + std::to_string(v_cl.
getProcessUnitID()) +
".vtk",
"test/AMG_psi_" + std::to_string(v_cl.
getProcessUnitID()) +
"_test_GCC6.vtk");
106 bool check = compare(
"AMG_psi_" + std::to_string(v_cl.
getProcessUnitID()) +
".vtk",
"test/AMG_psi_" + std::to_string(v_cl.
getProcessUnitID()) +
"_test_GCC4.vtk");
110 BOOST_REQUIRE_EQUAL(check,
true);
116 auto x2_ = solver.
solve(fd.getB());
119 fd.template copy<phi>(x_,psi2);
120 psi2.write(
"AMG_psi2");
123 check = compare(
"AMG_psi2_" + std::to_string(v_cl.
getProcessUnitID()) +
".vtk",
"test/AMG_psi2_" + std::to_string(v_cl.
getProcessUnitID()) +
"_test_osx.vtk");
126 check = compare(
"AMG_psi2_" + std::to_string(v_cl.
getProcessUnitID()) +
".vtk",
"test/AMG_psi2_" + std::to_string(v_cl.
getProcessUnitID()) +
"_test_GCC6.vtk");
129 check = compare(
"AMG_psi2_" + std::to_string(v_cl.
getProcessUnitID()) +
".vtk",
"test/AMG_psi2_" + std::to_string(v_cl.
getProcessUnitID()) +
"_test_GCC4.vtk");
132 BOOST_REQUIRE_EQUAL(check,
true);
135BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
Laplacian second order on h (spacing)
size_t getProcessUnitID()
Get the process unit id.
size_t getProcessingUnits()
Get the total number of processors.
Implementation of VCluster class.
This is a distributed grid.
In case T does not match the PETSC precision compilation create a stub structure.
static Vector< T > solve(const SparseMatrix< T, impl > &A, const Vector< T > &b)
Solve the linear system.
Class for cpu time benchmarking.
void stop()
Stop the timer.
void start()
Start the timer.