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;