NewtonRaphsonSolver< number, VectorType > Class Template Reference
|
Developer Documentation
|
#include <newton_raphson_solver.hpp>
Public Member Functions | |
| NewtonRaphsonSolver (const NonlinearSolverData< number > &nlsolve_data) | |
| void | solve (VectorType &solution) |
| const VectorType & | get_residual () const |
| const VectorType & | get_solution_update () const |
Public Attributes | |
| std::function< void(const VectorType &evaluation_point, VectorType &residual)> | residual = {} |
| std::function< int(const VectorType &rhs, VectorType &dst)> | solve_with_jacobian = {} |
| std::function< void(VectorType &v)> | reinit_vector = {} |
| std::function< void(VectorType &v)> | distribute_constraints = {} |
| std::function< number()> | norm_of_solution_vector = {} |
Private Member Functions | |
| void | solve_increment (const VectorType ¤t_solution) |
| number | suggest_new_time_increment () |
| void | set_tolerances_to_alternative_values () |
| bool | is_converged (const VectorType &solution) |
| void | print_header () const |
| std::string | print_checkmark (bool is_converged) const |
Private Attributes | |
| const NonlinearSolverData< number > | nlsolve_data |
| dealii::ConditionalOStream | pcout |
| const int | max_number_of_iterations |
| number | residual_tolerance |
| number | field_correction_tolerance |
| VectorType | rhs |
| VectorType | solution_update |
| int | linear_iter_acc = 0 |
| number | initial_residual_norm = 0.0 |
| std::ostringstream | str_ |
Detailed Description
class MeltPoolDG::NewtonRaphsonSolver< number, VectorType >
Newton-Raphson solver for a nonlinear system of equations \(F(x) = 0\).
The solver does not know the nonlinear problem itself. Instead, the problem is defined by the public std::function members residual, solve_with_jacobian, reinit_vector, distribute_constraints and norm_of_solution_vector, which have to be set before calling solve().
Algorithm
Starting from the initial guess \(x_0\) passed to solve(), each Newton iteration \(k\)
- computes the right-hand side \(r_k = -F(x_k)\) with residual(),
- solves the linearized system \(J(x_k)\,\Delta x_k = r_k\) with solve_with_jacobian(), where \(J = \partial F / \partial x\) is the Jacobian,
- checks for convergence, and, if not converged,
- updates the solution \(x_{k+1} = x_k + \Delta x_k\) and applies the constraints with distribute_constraints().
Convergence criterion
The solver is converged if both the residual and the solution update are small, i.e.
\[ \|r_k\| < \mathrm{tol}_r \quad \mathrm{and} \quad \|\Delta x_k\| < \mathrm{tol}_{\Delta x}, \]
with the l2 norms of the vectors and the tolerances NonlinearSolverData::residual_tolerance and NonlinearSolverData::field_correction_tolerance.
If NonlinearSolverData::use_relative_tolerances is set, the tolerances are interpreted relative to reference norms:
\[ \frac{\|r_k\|}{\|r_0\|} < \mathrm{tol}_r \quad \mathrm{and} \quad \frac{\|\Delta x_k\|}{\|x_k\|} < \mathrm{tol}_{\Delta x}, \]
where \(r_0\) is the right-hand side of the first Newton iteration of the current call to solve() and \(x_k\) the current iterate. If a reference norm is zero, the respective tolerance is applied as an absolute value.
If the solver does not converge within NonlinearSolverData::max_nonlinear_iterations iterations, it continues for up to NonlinearSolverData::max_nonlinear_iterations_alt iterations with the alternative tolerances NonlinearSolverData::residual_tolerance_alt and NonlinearSolverData::field_correction_tolerance_alt. If it does not converge with those either, ExcNewtonDidNotConverge is thrown. Each call to solve() starts with the standard tolerances.
- Note
- If a linear solver with an absolute tolerance is used in solve_with_jacobian(), this tolerance limits how far the residual can be reduced: once \(\|r_k\|\) falls below it, the linear solver returns a zero update. In combination with relative tolerances, make sure that the absolute tolerance of the linear solver is well below \(\mathrm{tol}_r \|r_0\|\).
Output
For NonlinearSolverData::verbosity_level >= 2, the number of linear iterations and the norms compared against the tolerances are printed in each Newton iteration. For NonlinearSolverData::verbosity_level >= 1, the norm of the converged solution is printed.
- Template Parameters
-
number The floating point type. VectorType The type of the solution vector.
Constructor & Destructor Documentation
◆ NewtonRaphsonSolver()
|
explicit |
Constructor.
- Parameters
-
nlsolve_data Parameters of the nonlinear solver.
Member Function Documentation
◆ get_residual()
|
inline |
Return the right-hand side of the last Newton iteration, i.e. the negative nonlinear residual \(-F(x)\) at the solution returned by solve().
◆ get_solution_update()
|
inline |
Return the solution update of the last Newton iteration. If solve() converged, this update has not been added to the solution.
◆ is_converged()
|
private |
Check the convergence criterion for the right-hand side and the solution update of the current Newton iteration. For NonlinearSolverData::verbosity_level >= 2, the norms are printed.
- Parameters
-
solution The current iterate. It is the reference for the relative field correction tolerance.
- Returns
- Whether both the residual and the field correction criterion are fulfilled.
◆ print_checkmark()
|
private |
Return a check mark if is_converged is true and a cross otherwise.
◆ print_header()
|
private |
Print the header of the table of Newton iterations for NonlinearSolverData::verbosity_level >= 2.
◆ set_tolerances_to_alternative_values()
|
private |
Replace the standard tolerances by NonlinearSolverData::residual_tolerance_alt and NonlinearSolverData::field_correction_tolerance_alt. It is called by solve() if the solver did not converge within NonlinearSolverData::max_nonlinear_iterations iterations.
◆ solve()
| void MeltPoolDG::NewtonRaphsonSolver< number, VectorType >::solve | ( | VectorType & | solution | ) |
Solve the nonlinear system. All std::function members have to be set before calling this function. The number of Newton iterations and linear iterations are reported to the IterationMonitor.
- Parameters
-
solution On input, the initial guess. On output, the converged solution.
- Note
- On convergence, the solution update of the last Newton iteration is not added to
solution. Thus, get_residual() corresponds to the returned solution.
- Exceptions
-
ExcNewtonDidNotConverge if the solver does not converge within the maximum number of iterations.
◆ solve_increment()
|
private |
Compute the right-hand side at current_solution and solve for the solution update. The results are stored in rhs and solution_update.
- Parameters
-
current_solution The current iterate.
◆ suggest_new_time_increment()
|
private |
Not implemented yet.
Member Data Documentation
◆ distribute_constraints
| std::function<void(VectorType &v)> MeltPoolDG::NewtonRaphsonSolver< number, VectorType >::distribute_constraints = {} |
Apply the constraints to v. It is called after each update of the solution.
◆ field_correction_tolerance
|
private |
Currently used field correction tolerance. It is set to the standard tolerance at the beginning of solve() and replaced by the alternative one in set_tolerances_to_alternative_values().
◆ initial_residual_norm
|
private |
Norm of the right-hand side of the first Newton iteration of the current call to solve(). It is the reference for the relative residual tolerance.
◆ linear_iter_acc
|
private |
Accumulated number of linear iterations of the current call to solve().
◆ max_number_of_iterations
|
private |
Total number of Newton iterations, i.e. NonlinearSolverData::max_nonlinear_iterations + NonlinearSolverData::max_nonlinear_iterations_alt.
◆ nlsolve_data
|
private |
Parameters of the nonlinear solver.
◆ norm_of_solution_vector
| std::function<number()> MeltPoolDG::NewtonRaphsonSolver< number, VectorType >::norm_of_solution_vector = {} |
Compute the norm of the solution vector. It is only used for the console output for NonlinearSolverData::verbosity_level >= 1.
◆ pcout
|
private |
Output stream that prints on the first MPI process only.
◆ reinit_vector
| std::function<void(VectorType &v)> MeltPoolDG::NewtonRaphsonSolver< number, VectorType >::reinit_vector = {} |
Initialize v with the parallel layout of the solution vector. It is used to set up the internal vectors for the right-hand side and the solution update.
◆ residual
| std::function<void(const VectorType &evaluation_point, VectorType &residual)> MeltPoolDG::NewtonRaphsonSolver< number, VectorType >::residual = {} |
Compute the right-hand side of the linearized system at evaluation_point, i.e. the negative nonlinear residual \(-F(x)\). The vector residual is set to zero before the call.
- Parameters
-
evaluation_point The current iterate, i.e. the vector passed to solve() in its current state. residual The vector to store the right-hand side in.
◆ residual_tolerance
|
private |
Currently used residual tolerance. It is set to the standard tolerance at the beginning of solve() and replaced by the alternative one in set_tolerances_to_alternative_values().
◆ rhs
|
private |
Right-hand side of the current Newton iteration.
◆ solution_update
|
private |
Solution update of the current Newton iteration.
◆ solve_with_jacobian
| std::function<int(const VectorType &rhs, VectorType &dst)> MeltPoolDG::NewtonRaphsonSolver< number, VectorType >::solve_with_jacobian = {} |
Solve the linearized system \(J\,\Delta x = r\) with the Jacobian \(J\) evaluated at the evaluation point of the preceding call to residual(). The vector dst is set to zero before the call.
- Parameters
-
rhs The right-hand side \(r\) computed by residual(). dst The vector to store the solution update \(\Delta x\) in.
- Returns
- The number of linear iterations.
◆ str_
|
private |
Buffer for the console output of the current Newton iteration.
The documentation for this class was generated from the following files:
- include/meltpooldg/linear_algebra/newton_raphson_solver.hpp
- source/linear_algebra/newton_raphson_solver.cpp
Generated by