48 #ifndef __petsc_linear_solver_h__
49 #define __petsc_linear_solver_h__
52 #include <feel/feelcore/feel.hpp>
55 #include <feel/feelalg/solverlinear.hpp>
65 #ifdef FEELPP_HAS_PETSC_H
68 #ifndef USE_COMPLEX_NUMBERS
70 # include <petscversion.h>
71 # if (PETSC_VERSION_MAJOR == 2) && (PETSC_VERSION_MINOR <= 1)
72 # include <petscsles.h>
74 # include <petscksp.h>
78 # include <petscversion.h>
79 # if (PETSC_VERSION_MAJOR == 2) && (PETSC_VERSION_MINOR <= 1)
80 # include <petscsles.h>
82 # include <petscksp.h>
94 #if PETSC_VERSION_LESS_THAN(3,0,1) && PETSC_VERSION_RELEASE
99 PetscErrorCode __feel_petsc_preconditioner_setup (
void * ctx );
105 PetscErrorCode __feel_petsc_preconditioner_apply(
void *ctx, Vec x, Vec y );
107 PetscErrorCode __feel_petsc_preconditioner_setup ( PC );
108 PetscErrorCode __feel_petsc_preconditioner_apply( PC, Vec x, Vec y );
127 template <
typename T>
128 class SolverLinearPetsc :
public SolverLinear<T>
130 typedef SolverLinear<T> super;
134 typedef typename super::value_type value_type;
135 typedef typename super::real_type real_type;
140 SolverLinearPetsc ( WorldComm
const& worldComm=Environment::worldComm() );
145 SolverLinearPetsc ( po::variables_map
const& vm, WorldComm
const& worldComm=Environment::worldComm() );
150 ~SolverLinearPetsc ();
165 void setConstantNullSpace(
bool cns )
167 M_constant_null_space = cns;
183 boost::tuple<bool,unsigned int, real_type>
184 solve ( MatrixSparse<T>
const &mat,
187 const double tolerance,
188 const unsigned int maxit,
191 return this->solve( mat, mat, x, b, tolerance, maxit, transpose );
194 boost::tuple<bool,unsigned int, real_type>
195 solve ( MatrixShell<T>
const &mat,
198 const double tolerance,
199 const unsigned int maxit,
228 boost::tuple<bool,unsigned int, real_type>
229 solve ( MatrixSparse<T>
const& mat,
230 MatrixSparse<T>
const& prec,
233 const double tolerance,
234 const unsigned int maxit,
252 void getResidualHistory( std::vector<double>& hist );
260 real_type getInitialResidual();
268 void setPetscSolverType ();
274 void setPetscPreconditionerType ();
276 void setPetscConstantNullSpace ();
279 #if (PETSC_VERSION_MAJOR == 2) && (PETSC_VERSION_MINOR <= 1)
298 bool M_constant_null_space;
303 template <
typename T>
305 SolverLinearPetsc<T>::SolverLinearPetsc ( WorldComm
const& worldComm )
308 M_constant_null_space( false )
310 if ( this->worldComm().globalSize() == 1 )
317 template <
typename T>
319 SolverLinearPetsc<T>::SolverLinearPetsc ( po::variables_map
const& vm, WorldComm
const& worldComm )
321 super( vm, worldComm ),
322 M_constant_null_space( false )
328 template <
typename T>
330 SolverLinearPetsc<T>::~SolverLinearPetsc ()
337 #endif // #ifdef FEELPP_HAS_PETSC_H
338 #endif // #ifdef __petsc_linear_solver_h__