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 26 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 48 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 51 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 52 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 55 of file NewtonRaphson.h.

64 _maximum_iterations(solver_parameters.maximum_iterations),
66 solver_parameters.residuum_tolerance),
68 solver_parameters.increment_tolerance)
69 {
70 }
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.

References _increment_tolerance_squared, _jacobian_update, _linear_solver, _maximum_iterations, _residual_update, _residuum_tolerance_squared, and _solution_update.

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 74 of file NewtonRaphson.h.

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

References _increment_tolerance_squared, _jacobian_update, _linear_solver, _maximum_iterations, _residual_update, _residuum_tolerance_squared, _solution_update, and ERR().

Referenced by ProcessLib::WellboreCompensateNeumannBoundaryConditionLocalAssembler< ShapeFunction, GlobalDim >::assemble(), and ProcessLib::WellboreSimulator::WellboreSimulatorFEM< ShapeFunction, GlobalDim >::assemble().

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 136 of file NewtonRaphson.h.

Referenced by NewtonRaphson(), and solve().

◆ _jacobian_update

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

Definition at line 129 of file NewtonRaphson.h.

Referenced by NewtonRaphson(), and solve().

◆ _linear_solver

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

Definition at line 128 of file NewtonRaphson.h.

Referenced by NewtonRaphson(), and solve().

◆ _maximum_iterations

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

Maximum number of iterations.

Definition at line 132 of file NewtonRaphson.h.

Referenced by NewtonRaphson(), and solve().

◆ _residual_update

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

Definition at line 130 of file NewtonRaphson.h.

Referenced by NewtonRaphson(), and solve().

◆ _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 134 of file NewtonRaphson.h.

Referenced by NewtonRaphson(), and solve().

◆ _solution_update

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

Definition at line 131 of file NewtonRaphson.h.

Referenced by NewtonRaphson(), and solve().


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