20 #ifndef __mast_petsc_nonlinear_solver_h__ 21 #define __mast_petsc_nonlinear_solver_h__ 37 namespace PETScWrapper {
39 template <
typename FuncType>
68 inline void solve(FuncType &func,
70 const std::string *scope =
nullptr) {
76 VecDuplicate(x, &res);
82 func.residual(x, res);
96 VecNorm(res, NORM_2, &res_l2);
100 <<
" Iter: " << std::setw(5) << iter
101 <<
" : || res ||_2 = " 102 << std::setw(15) << res_l2;
106 func.jacobian(x, *jac);
110 solver.
solve(dx, res);
112 VecNorm(dx, NORM_2, &dx_l2);
116 <<
" : || dx ||_2 = " 117 << std::setw(15) << dx_l2 << std::endl;
127 func.residual(x, res);
130 VecNorm(res, NORM_2, &res_l2);
133 <<
" Iter: " << std::setw(5) << iter
134 <<
" : || res ||_2 = " 135 << std::setw(15) << res_l2;
137 if (res_l2/res0_l2 < rtol) {
141 <<
" Terminating due to residual norm relative convergence" 148 <<
" Terminating due to residual norm convergence" 155 <<
" Terminating due to step norm convergence" 158 if (iter >= max_iter) {
162 <<
" Terminating due to maximum iterations" 180 #endif // __mast_petsc_nonlinear_solver_h__
NonlinearSolver(const MPI_Comm comm)
void solve(FuncType &func, Vec x, const std::string *scope=nullptr)
initialize the solver for function object func that provides the residual and jacobian evaluation...
void solve(Vec x, Vec b)
Solves , where is the system matrix.
virtual ~NonlinearSolver()
void init(Mat A, const std::string *scope=nullptr)
initialize the solver for operator matrix A.