21template <
typename NLO,
typename LS = utils::SolverDefault,
typename UF = utils::UpdateDefault>
34template <
typename LS = utils::SolverDefault,
typename UF = utils::UpdateDefault>
43 template <
typename UF2>
50 template <
typename NLO>
62template <
typename NLO,
typename NRConfig>
63requires traits::isSpecialization<NewtonRaphsonConfig, std::remove_cvref_t<NRConfig>>::value
66 using UF = std::remove_cvref_t<NRConfig>::UpdateFunction;
67 auto solverFactory = []<
class NLO2, class LS2, class UF2>(NLO2&& nlo2, LS2&& ls, UF2&& uf) {
68 return std::make_shared<
70 nlo2, std::forward<LS2>(ls), std::forward<UF2>(uf));
73 if constexpr (std::remove_cvref_t<NLO>::numberOfFunctions == 3) {
75 solverFactory(nonLinearOperator.template subOperator<1, 2>(), std::forward<NRConfig>(config).linearSolver,
76 std::forward<NRConfig>(config).updateFunction);
77 solver->setup(config.parameters);
80 static_assert(std::remove_cvref_t<NLO>::numberOfFunctions > 1,
81 "The number of derivatives in the nonlinear operator have to be more than 1");
82 auto solver = solverFactory(nonLinearOperator, std::forward<NRConfig>(config).linearSolver,
83 std::forward<NRConfig>(config).updateFunction);
86 solver->setup(std::forward<NRConfig>(config).parameters);
100template <
typename NLO,
typename LS,
typename UF>
110 using ValueType =
typename NLO::template ParameterValue<0>;
121 template <
typename LS2 = LS,
typename UF2 = UF>
124 linearSolver_{std::forward<LS2>(linearSolver)},
125 updateFunction_{std::forward<UF2>(updateFunction)} {
126 if constexpr (std::is_same_v<typename NonLinearOperator::ValueType, Eigen::VectorXd>)
127 correction_.setZero(this->nonLinearOperator().value().size());
146 template <
typename SolutionType = NoPredictor>
147 requires std::is_same_v<SolutionType, NoPredictor> ||
148 std::is_convertible_v<SolutionType, std::remove_cvref_t<typename NonLinearOperator::ValueType>>
150 "The solve method returns information of the solution process. You should store this information and check if "
152 solve(
const SolutionType& dxPredictor = NoPredictor{}) {
155 solverInformation.
success =
true;
157 if constexpr (not std::is_same_v<SolutionType, NoPredictor>)
158 updateFunction_(x, dxPredictor);
162 auto rNorm =
norm(rx);
163 decltype(rNorm) dNorm;
166 linearSolver_.analyzePattern(Ax);
167 while (rNorm > settings_.
tol && iter < settings_.
maxIter) {
170 linearSolver_.factorize(Ax);
171 linearSolver_.solve(correction_, -rx);
172 dNorm = correction_.norm();
173 updateFunction_(x, correction_);
175 correction_ = -linearSolver_(rx, Ax);
176 dNorm =
norm(correction_);
177 updateFunction_(x, correction_);
188 solverInformation.
success =
false;
190 solverInformation.
residualNorm =
static_cast<double>(rNorm);
194 return solverInformation;
205 typename NonLinearOperator::ValueType correction_;
221template <
typename NLO,
typename LS = utils::SolverDefault,
typename UF = utils::UpdateDefault>
222auto makeNewtonRaphson(
const NLO& nonLinearOperator, LS&& linearSolver = {}, UF&& updateFunction = {}) {
223 return std::make_shared<NewtonRaphson<NLO, LS, UF>>(nonLinearOperator, std::forward<LS>(linearSolver),
224 std::move(updateFunction));
227template <
typename NLO,
typename LS = utils::SolverDefault,
typename UF = utils::UpdateDefault>
229 UF&& updateFunction = {}) ->
NewtonRaphson<NLO, std::remove_cvref_t<LS>, std::remove_cvref_t<UF>>;
Helper for the autodiff library.
Collection of fallback default functions.
Implementation of the Newton-Raphson method for solving nonlinear equations.
Type-erased linear solver with templated scalar type.
Enums for observer messages.
Implementation of the observer design pattern.
auto norm(const Eigen::MatrixBase< Derived > &v)
Adding free norm function to Eigen types.
Definition: linearalgebrahelper.hh:259
Definition: dirichletbcenforcement.hh:6
LinearSolverTemplate< double > LinearSolver
Definition: linearsolver.hh:235
::value auto createNonlinearSolver(NRConfig &&config, NLO &&nonLinearOperator)
Function to create a NewtonRaphson solver instance.
Definition: newtonraphson.hh:64
NewtonRaphson(const NLO &nonLinearOperator, LS &&linearSolver={}, UF &&updateFunction={}) -> NewtonRaphson< NLO, std::remove_cvref_t< LS >, std::remove_cvref_t< UF > >
auto makeNewtonRaphson(const NLO &nonLinearOperator, LS &&linearSolver={}, UF &&updateFunction={})
Function to create a NewtonRaphson solver instance.
Definition: newtonraphson.hh:222
Implementation of the Newton-Raphson method for solving nonlinear equations.
Definition: newtonraphson.hh:102
Ikarus::NonLinearSolverInformation solve(const SolutionType &dxPredictor=NoPredictor{})
Solve the nonlinear system.
Definition: newtonraphson.hh:152
NRSettings Settings
Compile-time boolean indicating if the linear solver satisfies the non-linear solver concept.
Definition: newtonraphson.hh:105
UF UpdateFunction
Type representing the update function.
Definition: newtonraphson.hh:112
NLO NonLinearOperator
Type of the non-linear operator.
Definition: newtonraphson.hh:113
NewtonRaphson(const NonLinearOperator &nonLinearOperator, LS2 &&linearSolver={}, UF2 &&updateFunction={})
Constructor for NewtonRaphson.
Definition: newtonraphson.hh:122
void setup(const Settings &settings)
Set up the solver with the given settings.
Definition: newtonraphson.hh:134
auto & nonLinearOperator()
Access the nonlinear operator.
Definition: newtonraphson.hh:201
static constexpr bool isLinearSolver
Type representing the parameter vector of the nonlinear operator.
Definition: newtonraphson.hh:106
typename NLO::template ParameterValue< 0 > ValueType
Definition: newtonraphson.hh:110
Definition: newtonraphson.hh:25
int maxIter
Definition: newtonraphson.hh:27
double tol
Definition: newtonraphson.hh:26
Config for the Newton-Raphson solver.
Definition: newtonraphson.hh:36
NRSettings parameters
Definition: newtonraphson.hh:39
UF updateFunction
Definition: newtonraphson.hh:41
LS LinearSolver
Definition: newtonraphson.hh:37
LS linearSolver
Definition: newtonraphson.hh:40
UF UpdateFunction
Definition: newtonraphson.hh:38
auto rebindUpdateFunction(UF2 &&updateFunction) const
Definition: newtonraphson.hh:44
Information about the result of a non-linear solver.
Definition: solverinfos.hh:19
double correctionNorm
Definition: solverinfos.hh:28
int iterations
Definition: solverinfos.hh:29
double residualNorm
Definition: solverinfos.hh:27
bool success
Definition: solverinfos.hh:26
Represents a NonLinearOperator class for handling nonlinear operators.
Definition: nonlinearoperator.hh:156
Generic observable interface for the Observer design pattern. See for a description of the design pa...
Definition: observer.hh:129
void notify(NonLinearSolverMessages message)
Notify observers about a specific message type.
Concept to check if a linear solver implements all the needed functions for given vector and matrix t...
Definition: concepts.hh:212