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 35 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 57 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 60 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 61 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 64 of file NewtonRaphson.h.

69 : _linear_solver(linear_solver),
70 _jacobian_update(jacobian_update),
71 _residual_update(residual_update),
72 _solution_update(solution_update),
73 _maximum_iterations(solver_parameters.maximum_iterations),
74 _residuum_tolerance_squared(solver_parameters.residuum_tolerance *
75 solver_parameters.residuum_tolerance),
76 _increment_tolerance_squared(solver_parameters.increment_tolerance *
77 solver_parameters.increment_tolerance)
78 {
79 }
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 83 of file NewtonRaphson.h.

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