OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
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
47const bool poisson_nn_helm::boundary[] = {PERIODIC,PERIODIC,PERIODIC};
48
49BOOST_AUTO_TEST_SUITE( mg_solvers_report_test )
50
51
52BOOST_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
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
100
101 rep.setTergetAMGAccuracy(10e-4);
102
103 rep.try_solve(fd.getA(),fd.getB());
104}
105
106BOOST_AUTO_TEST_SUITE_END()
107
108
109#endif /* OPENFPM_NUMERICS_SRC_SOLVERS_PETSC_SOLVER_REPORT_UNIT_TESTS_HPP_ */
This class represent an N-dimensional box.
Definition Box.hpp:61
Finite Differences.
Definition FDScheme.hpp:127
Definition eq.hpp:83
Laplacian second order on h (spacing)
Definition Laplacian.hpp:23
Sparse Matrix implementation.
size_t getProcessingUnits()
Get the total number of processors.
Implementation of VCluster class.
Definition VCluster.hpp:59
Sparse Matrix implementation stub object when OpenFPM is compiled with no linear algebra support.
Definition Vector.hpp:40
This is a distributed grid.
Class to test AMG solvers.
void try_solve(SparseMatrix< double, int, PETSC_BASE > &A, const Vector< double, PETSC_BASE > &b)
Try to use AMG pre-conditioner and check how they they perform.
void setTergetAMGAccuracy(double t_a)
Set the target accuracy to score the AMG solver.
Boundary conditions.
Definition common.hpp:22
Vector< double, PETSC_BASE > Vector_type
type of vector that store the solution
SparseMatrix< double, int, PETSC_BASE > SparseMatrix_type
type of sparse grid that store the Matrix A
static const bool boundary[]
specify the boundary conditions
static const unsigned int nvar
We have only one scalar unknown.
static const unsigned int dims
Number of dimansions of the problem.
grid_dist_id< 3, float, aggregate< float > > b_grid
Grid that store the solution.