29 #ifndef __SolverNonLinear_H
30 #define __SolverNonLinear_H 1
32 #include <boost/function.hpp>
33 #include <boost/bind.hpp>
37 #include <Eigen/Dense>
39 #include <feel/feelalg/enums.hpp>
41 #include <feel/feelcore/traits.hpp>
48 template<
typename T>
class Vector;
49 template<
typename T>
class MatrixSparse;
72 typedef boost::shared_ptr<SolverNonLinear<T> > self_ptrtype;
74 typedef boost::shared_ptr<self_type> solvernonlinear_ptrtype;
77 typedef typename type_traits<T>::real_type real_type;
79 typedef boost::shared_ptr<Preconditioner<T> > preconditioner_ptrtype;
81 typedef boost::shared_ptr<Vector<value_type> > vector_ptrtype;
82 typedef boost::shared_ptr<MatrixSparse<value_type> > sparse_matrix_ptrtype;
84 typedef ublas::matrix<value_type> dense_matrix_type;
85 typedef ublas::vector<value_type> dense_vector_type;
87 typedef Eigen::Map< Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> > map_dense_matrix_type;
88 typedef Eigen::Map< Eigen::Matrix<double, Eigen::Dynamic, 1> > map_dense_vector_type;
90 typedef boost::function<void (
const vector_ptrtype& X,
91 vector_ptrtype& R )> residual_function_type;
92 typedef boost::function<void (
const vector_ptrtype& X,
93 sparse_matrix_ptrtype& J )> jacobian_function_type;
94 typedef boost::function<void (
const vector_ptrtype& X,
96 sparse_matrix_ptrtype& J )> matvec_function_type;
98 typedef boost::function<void ( dense_vector_type
const& X,
99 dense_vector_type & R )> dense_residual_function_type;
100 typedef boost::function<void ( dense_vector_type
const& X,
101 dense_matrix_type& J )> dense_jacobian_function_type;
102 typedef boost::function<void ( dense_vector_type
const& X,
103 dense_vector_type& R,
104 dense_matrix_type& J )> dense_matvec_function_type;
107 typedef boost::function<void ( map_dense_vector_type
const& X,
108 map_dense_vector_type & R )> map_dense_residual_function_type;
109 typedef boost::function<void ( map_dense_vector_type
const& X,
110 map_dense_matrix_type& J )> map_dense_jacobian_function_type;
111 typedef boost::function<void ( map_dense_vector_type
const& X,
112 map_dense_vector_type& R,
113 map_dense_matrix_type& J )> map_dense_matvec_function_type;
125 SolverNonLinear(WorldComm
const& worldComm = Environment::worldComm() );
142 static solvernonlinear_ptrtype
build( po::variables_map
const& vm, std::string
const&
prefix =
"",
143 WorldComm
const& worldComm = Environment::worldComm() );
149 static solvernonlinear_ptrtype
build(
SolverPackage solver_package, WorldComm
const& worldComm = Environment::worldComm() );
154 virtual void init () = 0;
173 WorldComm
const&
comm()
const {
return M_worldComm; }
174 WorldComm
const& worldComm()
const {
return M_worldComm; }
196 return M_prec_matrix_structure;
204 double getAbsoluteResidualTol()
const
206 return M_absoluteResidualTol;
208 double getRelativeResidualTol()
const
212 double getAbsoluteSolutionTol()
const
217 uint getNbItMax()
const
222 int reuseJacobian()
const
226 int reusePreconditioner()
const
234 std::string
const&
prefix()
const{
return M_prefix; }
246 void setPrefix( std::string
const& p ) { M_prefix = p; }
258 M_prec_matrix_structure = mstruct;
323 std::cerr<<
"Preconditioner must be attached before the solver is initialized!"<<std::endl;
369 void setAbsoluteResidualTol(
double tol )
371 M_absoluteResidualTol = tol;
373 void setAbsoluteSolutionTol(
double tol )
392 void setShowSNESMonitor(
bool b) { M_showSNESMonitor=b; }
398 void setShowKSPMonitor(
bool b) { M_showKSPMonitor=b; }
404 void setShowSNESConvergedReason(
bool b ) { M_showSNESConvergedReason=b; }
410 void setShowKSPConvergedReason(
bool b ) { M_showKSPConvergedReason=b; }
442 virtual std::pair<int, real_type>
solve ( sparse_matrix_ptrtype&,
446 const unsigned int ) = 0;
451 virtual std::pair<unsigned int, real_type>
solve ( dense_matrix_type&,
455 const unsigned int ) = 0;
460 virtual std::pair<unsigned int, real_type>
solve ( map_dense_matrix_type&,
461 map_dense_vector_type&,
462 map_dense_vector_type&,
464 const unsigned int ) = 0;
532 WorldComm M_worldComm;
541 std::string M_prefix;
572 double M_absoluteResidualTol;
594 bool M_showKSPMonitor, M_showSNESMonitor;
595 bool M_showKSPConvergedReason, M_showSNESConvergedReason;
SolverPackage
Definition: feelalg/enums.hpp:217
double dtoleranceKSP() const
Definition: solvernonlinear.hpp:421
SolverNonLinearType nlSolverType() const
Definition: solvernonlinear.hpp:272
void setMatSolverPackageType(const MatSolverPackageType mspackt)
Definition: solvernonlinear.hpp:333
void attachPreconditioner(preconditioner_ptrtype preconditioner)
Definition: solvernonlinear.hpp:319
size_type maxitKSP() const
Definition: solvernonlinear.hpp:431
PreconditionerType
Definition: feelalg/enums.hpp:114
bool M_is_initialized
Definition: solvernonlinear.hpp:537
SolverType M_kspSolver_type
Definition: solvernonlinear.hpp:551
Non linear solver base interface.
Definition: solvernonlinear.hpp:62
size_type M_maxitKSP
Definition: solvernonlinear.hpp:612
virtual std::pair< int, real_type > solve(sparse_matrix_ptrtype &, vector_ptrtype &, vector_ptrtype &, const double, const unsigned int)=0
double M_rtoleranceKSP
Definition: solvernonlinear.hpp:600
virtual ~SolverNonLinear()
Definition: solvernonlinear.cpp:101
bool initialized() const
Definition: solvernonlinear.hpp:180
double M_absoluteSolutionTol
Definition: solvernonlinear.hpp:577
SolverNonLinearType M_snl_type
Definition: solvernonlinear.hpp:546
MatrixStructure
Definition: feelalg/enums.hpp:146
void setPreconditionerType(const PreconditionerType pct)
Definition: solvernonlinear.hpp:307
dense_matvec_function_type dense_matvec
Definition: solvernonlinear.hpp:516
MatSolverPackageType matSolverPackageType() const
Definition: solvernonlinear.hpp:340
double M_relativeResidualTol
Definition: solvernonlinear.hpp:571
map_dense_jacobian_function_type map_dense_jacobian
Definition: solvernonlinear.hpp:508
SolverType
Definition: feelalg/enums.hpp:89
PreconditionerType preconditionerType() const
Definition: solvernonlinear.hpp:296
MatSolverPackageType M_matSolverPackage_type
Definition: solvernonlinear.hpp:566
bool showKSPMonitor() const
Definition: solvernonlinear.hpp:397
double M_atoleranceKSP
Definition: solvernonlinear.hpp:608
void setType(SolverNonLinearType snl_type)
Definition: solvernonlinear.hpp:265
jacobian_function_type jacobian
Definition: solvernonlinear.hpp:476
virtual void setPrecMatrixStructure(MatrixStructure mstruct)
Definition: solvernonlinear.hpp:252
dense_residual_function_type dense_residual
Definition: solvernonlinear.hpp:490
WorldComm const & comm() const
Definition: solvernonlinear.hpp:173
bool showSNESConvergedReason() const
Definition: solvernonlinear.hpp:403
PreconditionerType M_preconditioner_type
Definition: solvernonlinear.hpp:556
SolverType kspSolverType() const
Definition: solvernonlinear.hpp:288
virtual void clear()
Definition: solvernonlinear.hpp:188
virtual MatrixStructure precMatrixStructure() const
Definition: solvernonlinear.hpp:194
uint M_nbItMax
Definition: solvernonlinear.hpp:582
void setPrefix(std::string const &p)
Definition: solvernonlinear.hpp:246
size_t size_type
Indices (starting from 0)
Definition: feelcore/feel.hpp:319
preconditioner_ptrtype M_preconditioner
Definition: solvernonlinear.hpp:561
dense_jacobian_function_type dense_jacobian
Definition: solvernonlinear.hpp:502
double atoleranceKSP() const
Definition: solvernonlinear.hpp:426
double M_dtoleranceKSP
Definition: solvernonlinear.hpp:604
void setRelativeResidualTol(double tol)
Definition: solvernonlinear.hpp:365
map_dense_matvec_function_type map_dense_matvec
Definition: solvernonlinear.hpp:524
residual_function_type residual
Definition: solvernonlinear.hpp:470
SolverNonLinearType
Definition: feelalg/enums.hpp:232
int M_reuse_jac
Definition: solvernonlinear.hpp:587
int M_reuse_prec
Definition: solvernonlinear.hpp:592
void setKspSolverType(const SolverType st)
Definition: solvernonlinear.hpp:280
double rtoleranceKSP() const
Definition: solvernonlinear.hpp:416
matvec_function_type matvec
Definition: solvernonlinear.hpp:484
static solvernonlinear_ptrtype build(po::variables_map const &vm, std::string const &prefix="", WorldComm const &worldComm=Environment::worldComm())
Definition: solvernonlinear.cpp:107
map_dense_residual_function_type map_dense_residual
Definition: solvernonlinear.hpp:496
void setNbItMax(uint n)
Definition: solvernonlinear.hpp:381
SolverNonLinear(WorldComm const &worldComm=Environment::worldComm())
Definition: solvernonlinear.cpp:38
bool showKSPConvergedReason() const
Definition: solvernonlinear.hpp:409
virtual void setReuse(int jac=1, int prec=1)
Definition: solvernonlinear.hpp:356
std::string const & prefix() const
Definition: solvernonlinear.hpp:234
bool showSNESMonitor() const
Definition: solvernonlinear.hpp:391