OGS
NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate > Class Template Referencefinal

Detailed Description

template<typename LinearSolver, typename JacobianMatrixUpdate, typename ResidualUpdate, typename SolutionUpdate>
class NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >

Newton-Raphson solver for system of equations using an Eigen linear solvers library. The current implementation does not update the solution itself, but calls a function for the solution's update with the current increment.

Definition at line 33 of file NewtonRaphson.h.

#include <NewtonRaphson.h>

Classes

struct  FirstArgument
 
struct  FirstArgument< R(C::*)(Arg, Args...) const >
 

Public Member Functions

 NewtonRaphson (LinearSolver &linear_solver, JacobianMatrixUpdate jacobian_update, ResidualUpdate residual_update, SolutionUpdate solution_update, NewtonRaphsonSolverParameters const &solver_parameters)
 
std::optional< int > solve (JacobianMatrix &jacobian) const
 

Private Types

template<typename F >
using FirstArgumentType
 
using JacobianMatrix = FirstArgumentType<JacobianMatrixUpdate>
 
using ResidualVector = FirstArgumentType<ResidualUpdate>
 

Private Attributes

LinearSolver & _linear_solver
 
JacobianMatrixUpdate _jacobian_update
 
ResidualUpdate _residual_update
 
SolutionUpdate _solution_update
 
const int _maximum_iterations
 Maximum number of iterations.
 
const double _residuum_tolerance_squared
 Error tolerance for the residuum.
 
const double _increment_tolerance_squared
 Error tolerance for the increment.
 

Member Typedef Documentation

◆ FirstArgumentType

template<typename LinearSolver , typename JacobianMatrixUpdate , typename ResidualUpdate , typename SolutionUpdate >
template<typename F >
using NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::FirstArgumentType
private
Initial value:
typename FirstArgument<
decltype(&std::remove_reference_t<F>::operator())>::type

Definition at line 55 of file NewtonRaphson.h.

◆ JacobianMatrix

template<typename LinearSolver , typename JacobianMatrixUpdate , typename ResidualUpdate , typename SolutionUpdate >
using NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::JacobianMatrix = FirstArgumentType<JacobianMatrixUpdate>
private

Definition at line 58 of file NewtonRaphson.h.

◆ ResidualVector

template<typename LinearSolver , typename JacobianMatrixUpdate , typename ResidualUpdate , typename SolutionUpdate >
using NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::ResidualVector = FirstArgumentType<ResidualUpdate>
private

Definition at line 59 of file NewtonRaphson.h.

Constructor & Destructor Documentation

◆ NewtonRaphson()

template<typename LinearSolver , typename JacobianMatrixUpdate , typename ResidualUpdate , typename SolutionUpdate >
NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::NewtonRaphson ( LinearSolver & linear_solver,
JacobianMatrixUpdate jacobian_update,
ResidualUpdate residual_update,
SolutionUpdate solution_update,
NewtonRaphsonSolverParameters const & solver_parameters )
inline

Definition at line 62 of file NewtonRaphson.h.

67 : _linear_solver(linear_solver),
68 _jacobian_update(jacobian_update),
69 _residual_update(residual_update),
70 _solution_update(solution_update),
71 _maximum_iterations(solver_parameters.maximum_iterations),
72 _residuum_tolerance_squared(solver_parameters.residuum_tolerance *
73 solver_parameters.residuum_tolerance),
74 _increment_tolerance_squared(solver_parameters.increment_tolerance *
75 solver_parameters.increment_tolerance)
76 {
77 }
ResidualUpdate _residual_update
JacobianMatrixUpdate _jacobian_update
const int _maximum_iterations
Maximum number of iterations.
LinearSolver & _linear_solver
const double _residuum_tolerance_squared
Error tolerance for the residuum.
SolutionUpdate _solution_update
const double _increment_tolerance_squared
Error tolerance for the increment.

Member Function Documentation

◆ solve()

template<typename LinearSolver , typename JacobianMatrixUpdate , typename ResidualUpdate , typename SolutionUpdate >
std::optional< int > NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::solve ( JacobianMatrix & jacobian) const
inline

Returns true and the iteration number if succeeded, otherwise false and an undefined value for the number of iterations.

Definition at line 81 of file NewtonRaphson.h.

82 {
83 int iteration = 0;
84 ResidualVector increment;
85 ResidualVector residual;
86 do
87 {
88 // The jacobian and the residual are updated simultaneously to keep
89 // consistency. The jacobian is used after the non-linear solver
90 // onward.
91 _jacobian_update(jacobian);
92 _residual_update(residual);
93
94 if (residual.squaredNorm() < _residuum_tolerance_squared)
95 {
96 break; // convergence criteria fulfilled.
97 }
98
99 increment.noalias() =
100 _linear_solver.compute(jacobian).solve(-residual);
101 // DBUG("Local linear solver accuracy |J dx - r| = {:g}",
102 // (jacobian * increment + residual).norm());
103
104 _solution_update(increment);
105
106 if (increment.squaredNorm() < _increment_tolerance_squared)
107 {
108 break; // increment to small.
109 }
110
111 // DBUG("Local Newton: Iteration #{:d} |dx| = {:g}, |r| = {:g}",
112 // iteration, increment.norm(), residual.norm());
113 // fmt::print("Local Newton: Increment {}\n",
114 // fmt::join(increment.data(),
115 // increment.data() + increment.size(), ", "));
116 // fmt::print("Local Newton: Residuum {}\n",
117 // fmt::join(residual.data(),
118 // residual.data() + residual.size(), ", "));
119 } while (iteration++ < _maximum_iterations);
120
121 if (iteration > _maximum_iterations)
122 {
123 ERR("The local Newton method did not converge within the given "
124 "number of iterations. Iteration: {:d}, increment {:g}, "
125 "residual: "
126 "{:g}",
127 iteration - 1, increment.norm(), residual.norm());
128 return std::nullopt;
129 }
130
131 return iteration;
132 };
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
FirstArgumentType< ResidualUpdate > ResidualVector

References NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::_increment_tolerance_squared, NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::_jacobian_update, NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::_linear_solver, NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::_maximum_iterations, NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::_residual_update, NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::_residuum_tolerance_squared, NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::_solution_update, and ERR().

Referenced by ProcessLib::TwoPhaseFlowWithPrho::TwoPhaseFlowWithPrhoMaterialProperties::computeConstitutiveRelation().

Member Data Documentation

◆ _increment_tolerance_squared

template<typename LinearSolver , typename JacobianMatrixUpdate , typename ResidualUpdate , typename SolutionUpdate >
const double NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::_increment_tolerance_squared
private

Error tolerance for the increment.

Definition at line 143 of file NewtonRaphson.h.

Referenced by NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::solve().

◆ _jacobian_update

template<typename LinearSolver , typename JacobianMatrixUpdate , typename ResidualUpdate , typename SolutionUpdate >
JacobianMatrixUpdate NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::_jacobian_update
private

◆ _linear_solver

template<typename LinearSolver , typename JacobianMatrixUpdate , typename ResidualUpdate , typename SolutionUpdate >
LinearSolver& NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::_linear_solver
private

◆ _maximum_iterations

template<typename LinearSolver , typename JacobianMatrixUpdate , typename ResidualUpdate , typename SolutionUpdate >
const int NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::_maximum_iterations
private

◆ _residual_update

template<typename LinearSolver , typename JacobianMatrixUpdate , typename ResidualUpdate , typename SolutionUpdate >
ResidualUpdate NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::_residual_update
private

◆ _residuum_tolerance_squared

template<typename LinearSolver , typename JacobianMatrixUpdate , typename ResidualUpdate , typename SolutionUpdate >
const double NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::_residuum_tolerance_squared
private

Error tolerance for the residuum.

Definition at line 141 of file NewtonRaphson.h.

Referenced by NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::solve().

◆ _solution_update

template<typename LinearSolver , typename JacobianMatrixUpdate , typename ResidualUpdate , typename SolutionUpdate >
SolutionUpdate NumLib::NewtonRaphson< LinearSolver, JacobianMatrixUpdate, ResidualUpdate, SolutionUpdate >::_solution_update
private

The documentation for this class was generated from the following file: