4#ifndef lethe_newton_non_linear_solver_strategy_h
5#define lethe_newton_non_linear_solver_strategy_h
14template <
typename VectorType>
40template <
typename VectorType>
47template <
typename VectorType>
74 while ((global_res > this->
params.tolerance) &&
75 this->outer_iteration < this->params.max_iterations)
77 evaluation_point = present_solution;
81 if (!this->
params.reuse_preconditioner || this->outer_iteration == 0)
84 const bool assemble_rhs_this_iteration =
86 if (assemble_rhs_this_iteration)
92 current_res = system_rhs.l2_norm() / rescale_metric;
93 last_res = current_res;
99 <<
" - Residual: " << current_res << std::endl;
103 assemble_rhs_this_iteration,
111 double last_alpha_res = current_res;
113 unsigned int alpha_iter = 0;
114 for (
double alpha = 1.0; alpha > 1e-1; alpha *= 0.5)
118 local_evaluation_point = present_solution;
119 local_evaluation_point.add(alpha, newton_update);
121 evaluation_point = local_evaluation_point;
125 current_res = system_rhs.l2_norm() / rescale_metric;
129 solver->
pcout <<
"\talpha = " << std::defaultfloat << std::setw(6)
130 << alpha << std::setw(6) << std::scientific
131 <<
"\tres = " << std::setw(6) << current_res;
139 if (current_res > last_alpha_res and alpha_iter != 0)
142 local_evaluation_point = present_solution;
143 local_evaluation_point.add(alpha, newton_update);
145 evaluation_point = local_evaluation_point;
150 solver->
pcout <<
"\t\talpha value was kept at alpha = "
151 << std::defaultfloat << alpha
152 <<
" since alpha = " << alpha / 2
153 << std::scientific <<
" increased the residual"
156 current_res = last_alpha_res;
159 if (current_res < this->
params.step_tolerance * last_res ||
160 last_res < this->
params.tolerance)
164 last_alpha_res = current_res;
169 present_solution = evaluation_point;
170 last_res = current_res;
176 if ((global_res > this->
params.tolerance) &&
177 this->outer_iteration >= this->params.max_iterations &&
178 this->params.abort_at_convergence_failure)
180 throw(std::runtime_error(
181 "Stopping simulation because the non-linear solver has failed to converge"));
void solve() override
Solve the non-linear system of equations.
NewtonNonLinearSolverStrategy(PhysicsSolver< VectorType > *physics_solver, const Parameters::NonLinearSolver ¶m)
Constructor.
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