39 template <
typename NonLinearOperatorImpl,
typename LinearSolver = utils::SolverDefault,
40 typename UpdateFunctionTypeImpl = utils::UpdateDefault>
46 typename NonLinearOperatorImpl::ValueType>;
49 using ValueType =
typename NonLinearOperatorImpl::template ParameterValue<0>;
61 UpdateFunctionTypeImpl p_updateFunction = {})
62 : nonLinearOperator_{p_nonLinearOperator},
63 linearSolver{std::move(p_linearSolver)},
64 updateFunction{p_updateFunction} {
65 if constexpr (std::is_same_v<typename NonLinearOperatorImpl::ValueType, Eigen::VectorXd>)
76 struct NoPredictor {};
83 template <
typename SolutionType = NoPredictor>
84 requires std::is_same_v<SolutionType, NoPredictor> || std::is_convertible_v<
85 SolutionType, std::remove_cvref_t<typename NonLinearOperatorImpl::ValueType>>
87 "The solve method returns information of the solution process. You should store this information and check if "
89 solve(
const SolutionType& dx_predictor = NoPredictor{}) {
92 solverInformation.
success =
true;
94 if constexpr (not std::is_same_v<SolutionType, NoPredictor>) updateFunction(x, dx_predictor);
98 auto rNorm =
norm(rx);
99 decltype(rNorm) dNorm;
102 while (rNorm > settings.
tol && iter < settings.
maxIter) {
106 linearSolver.
solve(correction, -rx);
107 dNorm = correction.norm();
108 updateFunction(x, correction);
110 correction = -linearSolver(rx, Ax);
111 dNorm =
norm(correction);
112 updateFunction(x, correction);
124 solverInformation.
residualNorm =
static_cast<double>(rNorm);
127 return solverInformation;
137 NonLinearOperatorImpl nonLinearOperator_;
138 typename NonLinearOperatorImpl::ValueType correction;
154 template <
typename NonLinearOperatorImpl,
typename LinearSolver = utils::SolverDefault,
155 typename UpdateFunctionType = utils::UpdateDefault>
157 UpdateFunctionType&& p_updateFunction = {}) {
158 return std::make_shared<NewtonRaphson<NonLinearOperatorImpl, LinearSolver, UpdateFunctionType>>(
159 p_nonLinearOperator, std::forward<LinearSolver>(p_linearSolver), std::move(p_updateFunction));
Collection of fallback default functions.
Helper for the autodiff library.
Enums for observer messages.
Implementation of the observer design pattern.
Implementation of the Newton-Raphson method for solving nonlinear equations.
Type-erased linear solver with templated scalar type.
auto norm(const Eigen::MatrixBase< Derived > &v)
Adding free norm function to Eigen types.
Definition: linearalgebrahelper.hh:258
Definition: simpleassemblers.hh:21
auto makeNewtonRaphson(const NonLinearOperatorImpl &p_nonLinearOperator, LinearSolver &&p_linearSolver={}, UpdateFunctionType &&p_updateFunction={})
Function to create a NewtonRaphson solver instance.
Definition: newtonraphson.hh:156
LinearSolverTemplate< double > LinearSolver
Definition: linearsolver.hh:234
void analyzePattern(const MatrixType &A)
Analyze the pattern of the matrix.
Definition: linearsolver.hh:195
void solve(Eigen::VectorX< ScalarType > &x, const Eigen::VectorX< ScalarType > &b)
Solve the linear system for a vector.
Definition: linearsolver.hh:211
void factorize(const MatrixType &A)
Factorize the matrix.
Definition: linearsolver.hh:204
Settings for the Newton-Raphson solver.
Definition: newtonraphson.hh:25
double tol
Definition: newtonraphson.hh:26
int maxIter
Definition: newtonraphson.hh:27
Implementation of the Newton-Raphson method for solving nonlinear equations.
Definition: newtonraphson.hh:41
typename NonLinearOperatorImpl::template ParameterValue< 0 > ValueType
Definition: newtonraphson.hh:49
void setup(const NewtonRaphsonSettings &p_settings)
Set up the solver with the given settings.
Definition: newtonraphson.hh:73
auto & nonLinearOperator()
Access the nonlinear operator.
Definition: newtonraphson.hh:134
NonLinearOperatorImpl NonLinearOperator
Type of the non-linear operator.
Definition: newtonraphson.hh:52
Ikarus::NonLinearSolverInformation solve(const SolutionType &dx_predictor=NoPredictor{})
Solve the nonlinear system.
Definition: newtonraphson.hh:89
static constexpr bool isLinearSolver
< Compile-time boolean indicating if the linear solver satisfies the non-linear solver concept
Definition: newtonraphson.hh:45
UpdateFunctionTypeImpl UpdateFunctionType
Type representing the update function.
Definition: newtonraphson.hh:51
NewtonRaphson(const NonLinearOperatorImpl &p_nonLinearOperator, LinearSolver &&p_linearSolver={}, UpdateFunctionTypeImpl p_updateFunction={})
Constructor for NewtonRaphson.
Definition: newtonraphson.hh:60
Information about the result of a non-linear solver.
Definition: solverinfos.hh:18
double correctionNorm
Definition: solverinfos.hh:27
int iterations
Definition: solverinfos.hh:28
double residualNorm
Definition: solverinfos.hh:26
bool success
Definition: solverinfos.hh:25
Generic observable interface for the Observer design pattern. See for a description of the design pa...
Definition: observer.hh:125
void notify(NonLinearSolverMessages message)
Notify observers about a specific message type.
Definition: observer.hh:254
Concept to check if a linear solver implements all the needed functions for given vector and matrix t...
Definition: concepts.hh:218