4#ifndef lethe_inexact_newton_non_linear_solver_strategy_h
5#define lethe_inexact_newton_non_linear_solver_strategy_h
18template <
typename VectorType>
49template <
typename VectorType>
58template <
typename VectorType>
85 if (!this->
params.reuse_matrix)
88 while ((global_res > this->
params.tolerance) &&
89 this->outer_iteration < this->params.max_iterations)
91 evaluation_point = present_solution;
99 const bool assemble_rhs_this_iteration =
101 if (assemble_rhs_this_iteration)
107 current_res = system_rhs.l2_norm() / rescale_metric;
108 last_res = current_res;
114 <<
" - Residual: " << current_res << std::endl;
118 assemble_rhs_this_iteration,
126 double last_alpha_res = current_res;
128 unsigned int alpha_iter = 0;
129 for (
double alpha = 1.0; alpha > 1e-1; alpha *= 0.5)
133 local_evaluation_point = present_solution;
134 local_evaluation_point.add(alpha, newton_update);
136 evaluation_point = local_evaluation_point;
140 current_res = system_rhs.l2_norm() / rescale_metric;
144 solver->
pcout <<
"\talpha = " << std::defaultfloat << std::setw(6)
145 << alpha << std::setw(6) << std::scientific
146 <<
"\tres = " << std::setw(6) << current_res;
154 if (alpha_iter != 0 and current_res > last_alpha_res)
157 local_evaluation_point = present_solution;
158 local_evaluation_point.add(alpha, newton_update);
160 evaluation_point = local_evaluation_point;
165 solver->
pcout <<
"\t\talpha value was kept at alpha = "
166 << std::defaultfloat << alpha
167 <<
" since alpha = " << alpha / 2
168 << std::scientific <<
" increased the residual"
171 current_res = last_alpha_res;
174 if (current_res < this->
params.step_tolerance * last_res ||
175 last_res < this->
params.tolerance)
182 if (current_res > this->
params.matrix_tolerance * last_res ||
190 last_alpha_res = current_res;
195 present_solution = evaluation_point;
196 last_res = current_res;
202 if ((global_res > this->
params.tolerance) &&
203 this->outer_iteration >= this->params.max_iterations &&
204 this->params.abort_at_convergence_failure)
206 throw(std::runtime_error(
207 "Stopping simulation because the non-linear solver has failed to converge"));
bool matrix_requires_assembly
InexactNewtonNonLinearSolverStrategy(PhysicsSolver< VectorType > *physics_solver, const Parameters::NonLinearSolver ¶m)
Constructor.
void solve() override
Solve the non-linear system of equations.
unsigned int outer_iteration
Number of current Newton iteration.
PhysicsSolver< VectorType > * physics_solver
Physics solver for which we need a non-linear solver.
bool skip_linear_solve_if_fresh_rhs_is_already_converged(const bool rhs_was_assembled_this_iteration, const double rescale_metric, double ¤t_res, double &last_res, double &global_res)
Skip the inner linear solve when the current Newton evaluation already produced a freshly assembled R...
PhysicsSolverStrategy(PhysicsSolver< VectorType > *physics_solver, const Parameters::NonLinearSolver ¶ms)
Constructor for the non-linear solver strategies.
Parameters::NonLinearSolver params
Non linear solver parameters.
Contain all the common elements of a physics solver. It creates the non-linear solver as specified by...
virtual VectorType & get_present_solution()=0
virtual double get_residual_rescale_metric() const =0
Return the metric for residual rescaling. By default, should return 1. If the rescale_residual_by_vol...
virtual void solve_linear_system()=0
Solve the linear system of equations.
virtual void setup_preconditioner()=0
Set up the preconditioner.
virtual void assemble_system_matrix()=0
Assemble the matrix.
virtual void assemble_system_rhs()=0
Assemble the right-hand side (rhs).
virtual double get_current_residual()
Default way to evaluate the residual for the nonlinear solver, which is simply the norm of the RHS ve...
virtual VectorType & get_system_rhs()=0
virtual void output_newton_update_norms()=0
Output the L2 and Linfty norms of the correction vector.
virtual VectorType & get_local_evaluation_point()=0
virtual VectorType & get_evaluation_point()=0
Getter methods that give access to the private attributes of the physics being solved....
virtual VectorType & get_newton_update()=0
virtual void apply_constraints()
Applies constraints to a local_evaluation_point.
NonLinearSolver - Parameter that controls the solution of the non-linear problems.
GlobalVectorType VectorType