Salome HOME
Suppressed pre_requis directory
[tools/solverlab.git] / CDMATH / linearsolver / inc / LinearSolver.hxx
1 /*
2  * LinearSolver.hxx
3  *
4  *  Created on: 13 April. 2013
5  *      Authors: CDMATH
6  */
7
8 #ifndef LINEARSOLVER_HXX_
9 #define LINEARSOLVER_HXX_
10
11 #include <string>
12 #include <vector>
13
14 #include <petsc.h>
15
16 #include "GenericMatrix.hxx"
17 #include "Vector.hxx"
18
19
20 class LinearSolver
21 {
22 public: //----------------------------------------------------------------
23
24         LinearSolver ( void ) ;
25
26         ~LinearSolver ( void ) ;
27
28         LinearSolver( const GenericMatrix& matrix,
29                         const Vector& secondMember,
30                         int numberMaxOfIter,
31                         double tol,
32                         std::string nameOfMethod,
33                         std::string nameOfPc="" );
34
35         LinearSolver( const GenericMatrix& matrix,
36                         const std::vector<double>& secondMember,
37                         int numberMaxOfIter,
38                         double tol,
39                         std::string nameOfMethod,
40                         std::string nameOfPc="" );
41
42         const LinearSolver& operator= ( const LinearSolver& linearSolver ) ;
43
44         LinearSolver ( const LinearSolver& LS ) ;
45
46         void setMethod(std::string nameOfMethod) ;
47
48         void setPreconditioner(std::string pc) ;
49
50         void setComputeConditionNumber(bool display=true);
51     double getConditionNumber() const;
52     
53         int getNumberOfIter( void ) const ;
54
55         bool getStatus( void ) const ;
56
57         double getResidu( void ) const ;
58
59         double getTolerance( void ) const ;
60
61         int getNumberMaxOfIter( void ) const ;
62
63         void setTolerance(double tol) ;
64
65         void setNumberMaxOfIter(int numberMaxOfIter) ;
66
67         Vector getSndMember( void ) const ;
68
69         std::string getNameOfMethod( void ) const ;
70
71         std::string getNameOfPc( void ) const ;
72
73         Vector solve( void ) ;
74
75         void setMatrix(const GenericMatrix& matrix) ;
76
77         void setSndMember(const Vector& secondMember) ;
78
79         void setMatrixIsSingular(bool sing=true) ;
80
81         bool isMatrixSingular( void ) const;
82
83         bool isSparseMatrix( void ) const ;
84
85         Mat getPetscMatrix() const ;
86         Vec getPetscVector() const ;
87         void viewPetscMatrix() const ;
88         void viewPetscRHS() const;
89         double getPetscMatValue(int i, int j) const;
90         double getPetscRHSValue(int i) const    ;
91
92         void kspDuplicate(const KSP source, const Mat mat, KSP* destination) const;
93
94         void precDuplicate(const PC source, const KSP ksp, PC* destination) const;
95
96
97 private: //----------------------------------------------------------------
98
99         void setLinearSolver(const GenericMatrix& matrix, const Vector& secondMember) ;
100         KSP getPetscKsp() const ;
101         PC getPetscPc() const ;
102
103         Vec vectorToVec( const Vector& myVector ) const ;
104
105         Vector vecToVector(const Vec& vec) const ;
106
107         double _tol;
108         int _numberMaxOfIter;
109         double _residu;
110         bool _convergence;
111         int _numberOfIter;
112         bool _isSingular;
113         bool _isSparseMatrix;
114         bool _computeConditionNumber;
115         double _conditionNumber;
116         std::string _nameOfPc;
117         std::string _nameOfMethod;
118         Vector _secondMember;
119         Mat _mat;
120         Vec _smb;
121         PC _prec;
122         KSP _ksp;
123
124 };
125
126 #endif /* LINEARSOLVER_HXX_ */