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.

71 _maximum_iterations(solver_parameters.maximum_iterations),
73 solver_parameters.residuum_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.

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

82 {
83 int iteration = 0;
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.
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
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
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:48
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 143 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 136 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 135 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 139 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 137 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 141 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 138 of file NewtonRaphson.h.

Referenced by NewtonRaphson(), and solve().


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