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

Detailed Description

template<typename LinearSolver, typename JacobianMatrix, typename JacobianMatrixUpdate, typename ResidualVector, typename ResidualUpdate, typename SolutionUpdate>
class NumLib::NewtonRaphson< LinearSolver, JacobianMatrix, JacobianMatrixUpdate, ResidualVector, 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 34 of file NewtonRaphson.h.

#include <NewtonRaphson.h>

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 Attributes

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

Constructor & Destructor Documentation

◆ NewtonRaphson()

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

Definition at line 37 of file NewtonRaphson.h.

42  : _linear_solver(linear_solver),
43  _jacobian_update(jacobian_update),
44  _residual_update(residual_update),
45  _solution_update(solution_update),
46  _maximum_iterations(solver_parameters.maximum_iterations),
47  _residuum_tolerance_squared(solver_parameters.residuum_tolerance *
48  solver_parameters.residuum_tolerance),
49  _increment_tolerance_squared(solver_parameters.increment_tolerance *
50  solver_parameters.increment_tolerance)
51  {
52  }
SolutionUpdate _solution_update
const double _increment_tolerance_squared
Error tolerance for the increment.
const int _maximum_iterations
Maximum number of iterations.
const double _residuum_tolerance_squared
Error tolerance for the residuum.
LinearSolver & _linear_solver
JacobianMatrixUpdate _jacobian_update
ResidualUpdate _residual_update

Member Function Documentation

◆ solve()

template<typename LinearSolver , typename JacobianMatrix , typename JacobianMatrixUpdate , typename ResidualVector , typename ResidualUpdate , typename SolutionUpdate >
std::optional<int> NumLib::NewtonRaphson< LinearSolver, JacobianMatrix, JacobianMatrixUpdate, ResidualVector, 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 56 of file NewtonRaphson.h.

57  {
58  int iteration = 0;
59  ResidualVector increment;
60  ResidualVector residual;
61  do
62  {
63  // The jacobian and the residual are updated simultaneously to keep
64  // consistency. The jacobian is used after the non-linear solver
65  // onward.
66  _jacobian_update(jacobian);
67  _residual_update(residual);
68 
69  if (residual.squaredNorm() < _residuum_tolerance_squared)
70  {
71  break; // convergence criteria fulfilled.
72  }
73 
74  increment.noalias() =
75  _linear_solver.compute(jacobian).solve(-residual);
76  // DBUG("Local linear solver accuracy |J dx - r| = {:g}",
77  // (jacobian * increment + residual).norm());
78 
79  _solution_update(increment);
80 
81  if (increment.squaredNorm() < _increment_tolerance_squared)
82  {
83  break; // increment to small.
84  }
85 
86  // DBUG("Local Newton: Iteration #{:d} |dx| = {:g}, |r| = {:g}",
87  // iteration, increment.norm(), residual.norm());
88  // fmt::print("Local Newton: Increment {}\n",
89  // fmt::join(increment.data(),
90  // increment.data() + increment.size(), ", "));
91  // fmt::print("Local Newton: Residuum {}\n",
92  // fmt::join(residual.data(),
93  // residual.data() + residual.size(), ", "));
94  } while (iteration++ < _maximum_iterations);
95 
96  if (iteration > _maximum_iterations)
97  {
98  ERR("The local Newton method did not converge within the given "
99  "number of iterations. Iteration: {:d}, increment {:g}, "
100  "residual: "
101  "{:g}",
102  iteration - 1, increment.norm(), residual.norm());
103  return std::nullopt;
104  }
105 
106  return iteration;
107  };
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42

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

Referenced by MaterialLib::Fracture::Coulomb::Coulomb< DisplacementDim >::computeConstitutiveRelation(), ProcessLib::TwoPhaseFlowWithPrho::TwoPhaseFlowWithPrhoMaterialProperties::computeConstitutiveRelation(), ProcessLib::RichardsMechanics::computeMicroPorosity(), MaterialLib::Solids::Creep::CreepBGRa< DisplacementDim >::integrateStress(), MaterialLib::Solids::Ehlers::SolidEhlers< DisplacementDim >::integrateStress(), and MaterialLib::Solids::Lubby2::Lubby2< DisplacementDim >::integrateStress().

Member Data Documentation

◆ _increment_tolerance_squared

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

◆ _jacobian_update

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

◆ _linear_solver

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

◆ _maximum_iterations

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

◆ _residual_update

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

◆ _residuum_tolerance_squared

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

◆ _solution_update

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

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