Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Feel::SolverNonLinear< T > Class Template Referenceabstract

#include <solvernonlinear.hpp>

Detailed Description

template<typename T>
class Feel::SolverNonLinear< T >

Non linear solver base interface.

This class provides a uniform interface for nonlinear solvers. This base class is overloaded to provide nonlinear solvers from different packages like PETSC.

Author
Christophe Prud'homme

Public Types

Typedefs
typedef SolverNonLinear< T > self_type
 
typedef boost::shared_ptr
< SolverNonLinear< T > > 
self_ptrtype
 
typedef self_type solvernonlinear_type
 
typedef boost::shared_ptr
< self_type
solvernonlinear_ptrtype
 
typedef T value_type
 
typedef type_traits< T >::real_type real_type
 
typedef boost::shared_ptr
< Preconditioner< T > > 
preconditioner_ptrtype
 
typedef boost::shared_ptr
< Vector< value_type > > 
vector_ptrtype
 
typedef boost::shared_ptr
< MatrixSparse< value_type > > 
sparse_matrix_ptrtype
 
typedef ublas::matrix< value_type > dense_matrix_type
 
typedef ublas::vector< value_type > dense_vector_type
 
typedef Eigen::Map
< Eigen::Matrix< double,
Eigen::Dynamic, Eigen::Dynamic > > 
map_dense_matrix_type
 
typedef Eigen::Map
< Eigen::Matrix< double,
Eigen::Dynamic, 1 > > 
map_dense_vector_type
 
typedef boost::function< void(const
vector_ptrtype &X,
vector_ptrtype &R)> 
residual_function_type
 
typedef boost::function< void(const
vector_ptrtype &X,
sparse_matrix_ptrtype &J)> 
jacobian_function_type
 
typedef boost::function< void(const
vector_ptrtype &X,
vector_ptrtype &R,
sparse_matrix_ptrtype &J)> 
matvec_function_type
 
typedef boost::function< void(dense_vector_type
const &X, dense_vector_type &R)> 
dense_residual_function_type
 
typedef boost::function< void(dense_vector_type
const &X, dense_matrix_type &J)> 
dense_jacobian_function_type
 
typedef boost::function< void(dense_vector_type
const &X, dense_vector_type &R,
dense_matrix_type &J)> 
dense_matvec_function_type
 
typedef boost::function< void(map_dense_vector_type
const &X,
map_dense_vector_type &R)> 
map_dense_residual_function_type
 
typedef boost::function< void(map_dense_vector_type
const &X,
map_dense_matrix_type &J)> 
map_dense_jacobian_function_type
 
typedef boost::function< void(map_dense_vector_type
const &X,
map_dense_vector_type &R,
map_dense_matrix_type &J)> 
map_dense_matvec_function_type
 

Public Member Functions

double atoleranceKSP () const
 
double dtoleranceKSP () const
 
size_type maxitKSP () const
 
double rtoleranceKSP () const
 
void setAtoleranceKSP (double tol)
 
void setDtoleranceKSP (double tol)
 
void setMaxitKSP (size_type n)
 
void setRtoleranceKSP (double tol)
 
void setShowKSPConvergedReason (bool b)
 
void setShowKSPMonitor (bool b)
 
void setShowSNESConvergedReason (bool b)
 
void setShowSNESMonitor (bool b)
 
bool showKSPConvergedReason () const
 
bool showKSPMonitor () const
 
bool showSNESConvergedReason () const
 
bool showSNESMonitor () const
 
Accessors
WorldComm const & comm () const
 
WorldComm const & worldComm () const
 
bool initialized () const
 
virtual void clear ()
 
virtual MatrixStructure precMatrixStructure () const
 
SolverNonLinearType getType () const
 
double getAbsoluteResidualTol () const
 
double getRelativeResidualTol () const
 
double getAbsoluteSolutionTol () const
 
uint getNbItMax () const
 
int reuseJacobian () const
 
int reusePreconditioner () const
 
std::string const & prefix () const
 
Mutators
void setPrefix (std::string const &p)
 
virtual void setPrecMatrixStructure (MatrixStructure mstruct)
 
void setType (SolverNonLinearType snl_type)
 
SolverNonLinearType nlSolverType () const
 
void setKspSolverType (const SolverType st)
 
SolverType kspSolverType () const
 
PreconditionerType preconditionerType () const
 
void setPreconditionerType (const PreconditionerType pct)
 
void attachPreconditioner (preconditioner_ptrtype preconditioner)
 
void setMatSolverPackageType (const MatSolverPackageType mspackt)
 
MatSolverPackageType matSolverPackageType () const
 
virtual void setReuse (int jac=1, int prec=1)
 
void setRelativeResidualTol (double tol)
 
void setAbsoluteResidualTol (double tol)
 
void setAbsoluteSolutionTol (double tol)
 
void setNbItMax (uint n)
 

Protected Attributes

double M_absoluteResidualTol
 
double M_absoluteSolutionTol
 
double M_atoleranceKSP
 
double M_dtoleranceKSP
 
bool M_is_initialized
 
SolverType M_kspSolver_type
 
MatSolverPackageType M_matSolverPackage_type
 
size_type M_maxitKSP
 
uint M_nbItMax
 
MatrixStructure M_prec_matrix_structure
 
preconditioner_ptrtype M_preconditioner
 
PreconditionerType M_preconditioner_type
 
std::string M_prefix
 
double M_relativeResidualTol
 
int M_reuse_jac
 
int M_reuse_prec
 
double M_rtoleranceKSP
 
bool M_showKSPConvergedReason
 
bool M_showKSPMonitor
 
bool M_showSNESConvergedReason
 
bool M_showSNESMonitor
 
SolverNonLinearType M_snl_type
 
WorldComm M_worldComm
 

Constructors, destructor

 SolverNonLinear (WorldComm const &worldComm=Environment::worldComm())
 
 SolverNonLinear (SolverNonLinear const &)
 
virtual ~SolverNonLinear ()
 
virtual void init ()=0
 
static solvernonlinear_ptrtype build (po::variables_map const &vm, std::string const &prefix="", WorldComm const &worldComm=Environment::worldComm())
 
static solvernonlinear_ptrtype build (SolverPackage solver_package, WorldComm const &worldComm=Environment::worldComm())
 

Methods

residual_function_type residual
 
jacobian_function_type jacobian
 
matvec_function_type matvec
 
dense_residual_function_type dense_residual
 
map_dense_residual_function_type map_dense_residual
 
dense_jacobian_function_type dense_jacobian
 
map_dense_jacobian_function_type map_dense_jacobian
 
dense_matvec_function_type dense_matvec
 
map_dense_matvec_function_type map_dense_matvec
 
virtual std::pair< int, real_type > solve (sparse_matrix_ptrtype &, vector_ptrtype &, vector_ptrtype &, const double, const unsigned int)=0
 
virtual std::pair< unsigned
int, real_type > 
solve (dense_matrix_type &, dense_vector_type &, dense_vector_type &, const double, const unsigned int)=0
 
virtual std::pair< unsigned
int, real_type > 
solve (map_dense_matrix_type &, map_dense_vector_type &, map_dense_vector_type &, const double, const unsigned int)=0
 

Constructor & Destructor Documentation

template<typename T >
Feel::SolverNonLinear< T >::SolverNonLinear ( WorldComm const &  worldComm = Environment::worldComm())
inline

Constructor. Initializes Solver data structures

template<typename T >
Feel::SolverNonLinear< T >::SolverNonLinear ( SolverNonLinear< T > const &  snl)
inline

copy constructor

template<typename T >
Feel::SolverNonLinear< T >::~SolverNonLinear ( )
inlinevirtual

Destructor.

Member Function Documentation

template<typename T >
double Feel::SolverNonLinear< T >::atoleranceKSP ( ) const
inline

KSP absolute tolerance

References Feel::SolverNonLinear< T >::M_atoleranceKSP.

template<typename T >
void Feel::SolverNonLinear< T >::attachPreconditioner ( preconditioner_ptrtype  preconditioner)
inline
template<typename T >
boost::shared_ptr< SolverNonLinear< T > > Feel::SolverNonLinear< T >::build ( po::variables_map const &  vm,
std::string const &  prefix = "",
WorldComm const &  worldComm = Environment::worldComm() 
)
static

Builds a NonlinearSolver using the nonlinear solver package specified by the variables_map vm and prefix

template<typename T >
boost::shared_ptr< SolverNonLinear< T > > Feel::SolverNonLinear< T >::build ( SolverPackage  solver_package,
WorldComm const &  worldComm = Environment::worldComm() 
)
static

Builds a NonlinearSolver using the nonlinear solver package specified by solver_package

template<typename T >
virtual void Feel::SolverNonLinear< T >::clear ( )
inlinevirtual

Release all memory and clear data structures.

template<typename T >
WorldComm const& Feel::SolverNonLinear< T >::comm ( ) const
inline
Returns
the communicator
template<typename T >
double Feel::SolverNonLinear< T >::dtoleranceKSP ( ) const
inline

KSP divergence tolerance

References Feel::SolverNonLinear< T >::M_dtoleranceKSP.

template<typename T >
virtual void Feel::SolverNonLinear< T >::init ( )
pure virtual

Initialize data structures if not done so already.

template<typename T >
bool Feel::SolverNonLinear< T >::initialized ( ) const
inline
Returns
true if the data structures are initialized, false otherwise.

References Feel::SolverNonLinear< T >::M_is_initialized.

template<typename T >
SolverType Feel::SolverNonLinear< T >::kspSolverType ( ) const
inline

Returns the type of solver to use.

References Feel::SolverNonLinear< T >::M_kspSolver_type.

template<typename T >
MatSolverPackageType Feel::SolverNonLinear< T >::matSolverPackageType ( ) const
inline

Returns the type of preconditioner to use.

References Feel::SolverNonLinear< T >::M_matSolverPackage_type.

template<typename T >
size_type Feel::SolverNonLinear< T >::maxitKSP ( ) const
inline

KSP maximum number of iterations

References Feel::SolverNonLinear< T >::M_maxitKSP.

template<typename T >
SolverNonLinearType Feel::SolverNonLinear< T >::nlSolverType ( ) const
inline

Returns the type of solver to use.

References Feel::SolverNonLinear< T >::M_snl_type.

template<typename T >
virtual MatrixStructure Feel::SolverNonLinear< T >::precMatrixStructure ( ) const
inlinevirtual
Returns
the preconditioner matrix structure it may not be relevant to all non linear solvers
template<typename T >
PreconditionerType Feel::SolverNonLinear< T >::preconditionerType ( ) const
inline

Returns the type of preconditioner to use.

References Feel::SolverNonLinear< T >::M_preconditioner, and Feel::SolverNonLinear< T >::M_preconditioner_type.

template<typename T >
std::string const& Feel::SolverNonLinear< T >::prefix ( ) const
inline
Returns
the prefix
template<typename T >
double Feel::SolverNonLinear< T >::rtoleranceKSP ( ) const
inline

KSP relative tolerance

References Feel::SolverNonLinear< T >::M_rtoleranceKSP.

template<typename T >
void Feel::SolverNonLinear< T >::setKspSolverType ( const SolverType  st)
inline

Sets the type of solver to use.

References Feel::SolverNonLinear< T >::M_kspSolver_type.

template<typename T >
void Feel::SolverNonLinear< T >::setMatSolverPackageType ( const MatSolverPackageType  mspackt)
inline

Sets the type of preconditioner to use.

References Feel::SolverNonLinear< T >::M_matSolverPackage_type.

template<typename T >
void Feel::SolverNonLinear< T >::setNbItMax ( uint  n)
inline

Define the number max of iteration

References Feel::SolverNonLinear< T >::M_nbItMax.

template<typename T >
virtual void Feel::SolverNonLinear< T >::setPrecMatrixStructure ( MatrixStructure  mstruct)
inlinevirtual
Returns
the preconditioner matrix structure it may not be relevant to all non linear solvers

References Feel::SolverNonLinear< T >::M_preconditioner.

template<typename T >
void Feel::SolverNonLinear< T >::setPreconditionerType ( const PreconditionerType  pct)
inline
template<typename T >
void Feel::SolverNonLinear< T >::setPrefix ( std::string const &  p)
inline

set the prefix of the solver (typically for command line options)

template<typename T >
void Feel::SolverNonLinear< T >::setRelativeResidualTol ( double  tol)
inline

Define values of tolerance for the non linear solver

References Feel::SolverNonLinear< T >::M_relativeResidualTol.

template<typename T >
virtual void Feel::SolverNonLinear< T >::setReuse ( int  jac = 1,
int  prec = 1 
)
inlinevirtual

set reuse jacobian and/or preconditioner

  • jac=-1: means never rebuilt (preconditioner is not rebuit either)
  • jac=-2: build at each new nonlinear iterations (preconditioner is not rebuit either)
  • jac= 1: build at each new nonlinear iterations (rebuild jacobian every single nonlinear iteration)
  • jac= <n> (n>1): build every n iterations when jac >= n, prec=-1 (rebuilt once at each new nonlinear iteration) when jac >= n, prec=-1 (rebuilt once at each new nonlinear iteration)

References Feel::SolverNonLinear< T >::M_reuse_jac, and Feel::SolverNonLinear< T >::M_reuse_prec.

template<typename T >
void Feel::SolverNonLinear< T >::setType ( SolverNonLinearType  snl_type)
inline

Select type of non linear solver : LINEAR_SEARCH, TRUST_REGION, ...

References Feel::SolverNonLinear< T >::M_snl_type.

template<typename T >
bool Feel::SolverNonLinear< T >::showKSPConvergedReason ( ) const
inline

show KSP converged reason

template<typename T >
bool Feel::SolverNonLinear< T >::showKSPMonitor ( ) const
inline

show KSP monitor

template<typename T >
bool Feel::SolverNonLinear< T >::showSNESConvergedReason ( ) const
inline

show SNES converged reason

template<typename T >
bool Feel::SolverNonLinear< T >::showSNESMonitor ( ) const
inline

show SNES monitor

template<typename T >
virtual std::pair<int, real_type> Feel::SolverNonLinear< T >::solve ( sparse_matrix_ptrtype &  ,
vector_ptrtype &  ,
vector_ptrtype &  ,
const double  ,
const unsigned  int 
)
pure virtual

Solves a sparse nonlinear system.

template<typename T >
virtual std::pair<unsigned int, real_type> Feel::SolverNonLinear< T >::solve ( dense_matrix_type &  ,
dense_vector_type &  ,
dense_vector_type &  ,
const double  ,
const unsigned  int 
)
pure virtual

Solves a dense nonlinear system.

template<typename T >
virtual std::pair<unsigned int, real_type> Feel::SolverNonLinear< T >::solve ( map_dense_matrix_type &  ,
map_dense_vector_type &  ,
map_dense_vector_type &  ,
const double  ,
const unsigned  int 
)
pure virtual

Solves a dense nonlinear system ( using eigen).

Member Data Documentation

template<typename T >
dense_jacobian_function_type Feel::SolverNonLinear< T >::dense_jacobian

Function that computes the Jacobian J(X) of the nonlinear system at the input iterate X.

template<typename T >
dense_matvec_function_type Feel::SolverNonLinear< T >::dense_matvec

Function that computes either the residual $ R(X) $ or the Jacobian $ J(X) $ of the nonlinear system at the input iterate $ X $. Note that either R or J could be XSNULL.

template<typename T >
dense_residual_function_type Feel::SolverNonLinear< T >::dense_residual

Function that computes the residual R(X) of the nonlinear system at the input iterate X.

template<typename T >
jacobian_function_type Feel::SolverNonLinear< T >::jacobian

Function that computes the Jacobian J(X) of the nonlinear system at the input iterate X.

template<typename T >
double Feel::SolverNonLinear< T >::M_absoluteSolutionTol
protected

Absolute tolerances between successive iteration

template<typename T >
double Feel::SolverNonLinear< T >::M_atoleranceKSP
protected

KSP absolute tolerance

template<typename T >
double Feel::SolverNonLinear< T >::M_dtoleranceKSP
protected

KSP divergence tolerance

template<typename T >
bool Feel::SolverNonLinear< T >::M_is_initialized
protected

Flag indicating if the data structures have been initialized.

template<typename T >
SolverType Feel::SolverNonLinear< T >::M_kspSolver_type
protected

Enum stating which type of iterative linear solver to use.

template<typename T >
MatSolverPackageType Feel::SolverNonLinear< T >::M_matSolverPackage_type
protected

Enum the software that is used to perform the factorization

template<typename T >
size_type Feel::SolverNonLinear< T >::M_maxitKSP
protected

KSP maximum number of iterations

template<typename T >
uint Feel::SolverNonLinear< T >::M_nbItMax
protected

The maximum numbers of allowable nonlinear iterations

template<typename T >
preconditioner_ptrtype Feel::SolverNonLinear< T >::M_preconditioner
protected

Holds the Preconditioner object to be used for the linear solves.

template<typename T >
PreconditionerType Feel::SolverNonLinear< T >::M_preconditioner_type
protected

Enum statitng with type of preconditioner to use.

template<typename T >
double Feel::SolverNonLinear< T >::M_relativeResidualTol
protected

Two differents tolerances on the residual for the resolution of non linear system

template<typename T >
int Feel::SolverNonLinear< T >::M_reuse_jac
protected

reuse jac level

template<typename T >
int Feel::SolverNonLinear< T >::M_reuse_prec
protected

reuse preconditioner level

template<typename T >
double Feel::SolverNonLinear< T >::M_rtoleranceKSP
protected

KSP relative tolerance

template<typename T >
SolverNonLinearType Feel::SolverNonLinear< T >::M_snl_type
protected

Define the type of non linear solver

template<typename T >
map_dense_jacobian_function_type Feel::SolverNonLinear< T >::map_dense_jacobian

Function that computes the Jacobian J(X) of the nonlinear system at the input iterate X using eigen.

template<typename T >
map_dense_matvec_function_type Feel::SolverNonLinear< T >::map_dense_matvec

Function that computes either the residual $ R(X) $ or the Jacobian $ J(X) $ of the nonlinear system at the input iterate $ X $. Note that either R or J could be XSNULL.

template<typename T >
map_dense_residual_function_type Feel::SolverNonLinear< T >::map_dense_residual

Function that computes the residual R(X) of the nonlinear system at the input iterate X using eigen.

template<typename T >
matvec_function_type Feel::SolverNonLinear< T >::matvec

Function that computes either the residual $ R(X) $ or the Jacobian $ J(X) $ of the nonlinear system at the input iterate $ X $. Note that either R or J could be XSNULL.

template<typename T >
residual_function_type Feel::SolverNonLinear< T >::residual

Function that computes the residual R(X) of the nonlinear system at the input iterate X.


The documentation for this class was generated from the following files:

Generated on Sun Dec 22 2013 13:11:21 for Feel++ by doxygen 1.8.5