8 #ifndef OPENFPM_NUMERICS_SRC_SOLVERS_PETSC_SOLVER_UNIT_TESTS_CPP_
9 #define OPENFPM_NUMERICS_SRC_SOLVERS_PETSC_SOLVER_UNIT_TESTS_CPP_
14 #define BOOST_TEST_DYN_LINK
15 #include <boost/test/unit_test.hpp>
17 #include "petsc_solver_report_unit_tests.hpp"
19 #include "Grid/grid_dist_id.hpp"
20 #include "Matrix/SparseMatrix.hpp"
21 #include "Vector/Vector.hpp"
22 #include "FiniteDifference/Laplacian.hpp"
23 #include "FiniteDifference/FDScheme.hpp"
24 #include "Solvers/petsc_solver.hpp"
27 BOOST_AUTO_TEST_SUITE( mg_solvers_test )
30 BOOST_AUTO_TEST_CASE( laplacian_3D_int_zero_mg )
32 constexpr
unsigned int phi = 0;
51 size_t center_x = psi.size(0) / 2;
52 size_t center_y = psi.size(1) / 2;
53 size_t center_z = psi.size(2) / 2;
54 auto it = psi.getDomainIterator();
59 auto gkey = it.getGKey(key);
61 float sx = (float)(gkey.get(0))-center_x;
62 float sy = (float)(gkey.get(1))-center_y;
63 float sz = (float)(gkey.get(2))-center_z;
65 float gs = 100.0*exp(-((sx*sx)+(sy*sy)+(sz*sz))/100.0);
67 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;
68 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;
75 fd.template impose_dit<0>(poisson(),psi,psi.getDomainIterator());
94 auto x_ = solver.
solve(fd.getA(),fd.getB());
97 fd.template copy<phi>(x_,psi);
101 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");
105 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");
125 check = compare(
"AMG_psi2_" + std::to_string(v_cl.
getProcessUnitID()) +
".vtk",
"test/AMG_psi2_" + std::to_string(v_cl.
getProcessUnitID()) +
"_test_GCC6.vtk");
127 check = compare(
"AMG_psi2_" + std::to_string(v_cl.
getProcessUnitID()) +
".vtk",
"test/AMG_psi2_" + std::to_string(v_cl.
getProcessUnitID()) +
"_test_GCC4.vtk");
131 BOOST_REQUIRE_EQUAL(check,
true);
134 BOOST_AUTO_TEST_SUITE_END()
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.
This class is able to do Matrix inversion in parallel with PETSC solvers.
Vector< T, PETSC_BASE > solve(SparseMatrix< T, int, PETSC_BASE > &A, const Vector< T, PETSC_BASE > &b, bool initial_guess=false)
Here we invert the matrix and solve the system.
void setPreconditionerAMG_cycleType(const std::string &cycle_type, int sweep_up=-1, int sweep_dw=-1, int sweep_crs=-1)
It set the type of cycle and optionally the number of sweep.
void setPreconditionerAMG_nl(int nl)
Set the number of levels for the algebraic-multigrid preconditioner.
void setPreconditionerAMG_coarsenNodalType(int norm)
Set the block coarsening norm type.
void setPreconditioner(PCType type)
Set the preconditioner of the linear solver.
void setPreconditionerAMG_coarsen(const std::string &type)
Set the coarsening method for the algebraic-multi-grid preconditioner.
void setSolver(KSPType type)
Set the Petsc solver.
void setPreconditionerAMG_relax(const std::string &type, int k=REL_ALL)
Set the relaxation method for the algebraic-multi-grid preconditioner.
void setMaxIter(PetscInt n)
Set the maximum number of iteration for Krylov solvers.
void setAbsTol(PetscReal abstol_)
Set the absolute tolerance as stop criteria.
void setPreconditionerAMG_maxit(int nit)
Set the maximum number of V or W cycle for algebraic-multi-grid.
Class for cpu time benchmarking.
void stop()
Stop the timer.
void start()
Start the timer.