OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
petsc_solver_report_unit_tests.hpp
1 /*
2  * petsc_solver_report_unit_tests.hpp
3  *
4  * Created on: Jun 23, 2017
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_NUMERICS_SRC_SOLVERS_PETSC_SOLVER_REPORT_UNIT_TESTS_HPP_
9 #define OPENFPM_NUMERICS_SRC_SOLVERS_PETSC_SOLVER_REPORT_UNIT_TESTS_HPP_
10 
11 
12 #include "Grid/grid_dist_id.hpp"
13 #include "Matrix/SparseMatrix.hpp"
14 #include "Vector/Vector.hpp"
15 #include "FiniteDifference/Laplacian.hpp"
16 #include "FiniteDifference/FDScheme.hpp"
17 #include "Solvers/petsc_solver.hpp"
18 #include "petsc_solver_AMG_report.hpp"
19 
21 {
23  static const unsigned int dims = 3;
24 
26  static const unsigned int nvar = 1;
27 
29  static const bool boundary[];
30 
32  typedef float stype;
33 
36 
39 
42 
44  static const int grid_type = NORMAL_GRID;
45 };
46 
47 const bool poisson_nn_helm::boundary[] = {PERIODIC,PERIODIC,PERIODIC};
48 
49 BOOST_AUTO_TEST_SUITE( mg_solvers_report_test )
50 
51 
52 BOOST_AUTO_TEST_CASE( laplacian_3D_int_zero_mg_report )
53 {
54  constexpr unsigned int phi = 0;
55  typedef Field<phi,poisson_nn_helm> phi_f;
56 
57  Vcluster & v_cl = create_vcluster();
58  if (v_cl.getProcessingUnits() != 3)
59  return;
60 
61  Ghost<3,long int> g(2);
62  Ghost<3,long int> stencil_max(2);
63  Box<3,float> domain({0.0,0.0,0.0},{1.0,1.0,1.0});
64 
65  periodicity<3> p({PERIODIC,PERIODIC,PERIODIC});
66 
68  grid_dist_id<3,float,aggregate<float>> psi({64,64,64},domain,g,p);
69  grid_dist_id<3,float,aggregate<float>> psi2(psi.getDecomposition(),{64,64,64},g);
70 
71  // Fill B
72 
73  size_t center_x = psi.size(0) / 2;
74  size_t center_y = psi.size(1) / 2;
75  size_t center_z = psi.size(2) / 2;
76  auto it = psi.getDomainIterator();
77 
78  while (it.isNext())
79  {
80  auto key = it.get();
81  auto gkey = it.getGKey(key);
82 
83  float sx = (float)(gkey.get(0))-center_x;
84  float sy = (float)(gkey.get(1))-center_y;
85  float sz = (float)(gkey.get(2))-center_z;
86 
87  float gs = 100.0*exp(-((sx*sx)+(sy*sy)+(sz*sz))/100.0);
88 
89  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;
90  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;
91 
92  ++it;
93  }
94 
95  FDScheme<poisson_nn_helm> fd(stencil_max, domain, psi);
96 
97  fd.template impose_dit<0>(poisson(),psi,psi.getDomainIterator());
98 
99  petsc_AMG_report rep;
100 
101  rep.setTergetAMGAccuracy(10e-4);
102 
103  rep.try_solve(fd.getA(),fd.getB());
104 }
105 
106 BOOST_AUTO_TEST_SUITE_END()
107 
108 
109 #endif /* OPENFPM_NUMERICS_SRC_SOLVERS_PETSC_SOLVER_REPORT_UNIT_TESTS_HPP_ */
Class to test AMG solvers.
Sparse Matrix implementation stub object when OpenFPM is compiled with no linear algebra support...
Definition: Vector.hpp:39
Definition: eq.hpp:81
static const unsigned int dims
Number of dimansions of the problem.
SparseMatrix< double, int, PETSC_BASE > SparseMatrix_type
type of sparse grid that store the Matrix A
size_t size() const
Return the total number of points in the grid.
float stype
type of the space
Definition: Ghost.hpp:39
Vector< double, PETSC_BASE > Vector_type
type of vector that store the solution
Implementation of VCluster class.
Definition: VCluster.hpp:36
Sparse Matrix implementation.
This is a distributed grid.
static const unsigned int nvar
We have only one scalar unknown.
Laplacian second order on h (spacing)
Definition: Laplacian.hpp:22
This class is a trick to indicate the compiler a specific specialization pattern. ...
Definition: memory_c.hpp:201
grid_dist_id< 3, float, aggregate< float > > b_grid
Grid that store the solution.
static const bool boundary[]
specify the boundary conditions
Finite Differences.
Definition: FDScheme.hpp:124
size_t getProcessingUnits()
Get the total number of processors.
void setTergetAMGAccuracy(double t_a)
Set the target accuracy to score the AMG solver.