41template <
typename NLO,
typename LS = utils::SolverDefault,
typename UF = utils::UpdateDefault>
50 using ValueType =
typename NLO::template ParameterValue<0>;
65 linearSolver_{std::move(linearSolver)},
66 updateFunction_{updateFunction} {}
91 template <
typename SolutionType = NoPredictor,
typename Subs
idiaryType>
92 requires std::is_same_v<SolutionType, NoPredictor> ||
93 std::is_convertible_v<SolutionType, std::remove_cvref_t<typename NLO::ValueType>>
95 "The solve method returns information of the solution process. You should store this information and check if "
96 "it was successful")]] NonLinearSolverInformation
98 const SolutionType& dxPredictor = NoPredictor{}) {
103 solverInformation.
success =
true;
105 if constexpr (not std::is_same_v<SolutionType, NoPredictor>)
106 updateFunction_(x, dxPredictor);
113 auto lambdaDummy = lambda;
119 lambda = lambdaDummy;
122 Eigen::MatrixX2<double> residual2d, sol2d;
127 Eigen::VectorXd deltaD;
128 deltaD.resizeLike(rx);
131 subsidiaryArgs.
dfdDD.resizeLike(Fext0);
133 subsidiaryFunction(subsidiaryArgs);
134 auto rNorm = sqrt(rx.dot(rx));
135 decltype(rNorm) dNorm;
141 while (rNorm > settings_.
tol && iter < settings_.
maxIter) {
145 residual2d.resize(rx.rows(), 2);
146 residual2d << -rx, Fext0;
147 sol2d.resize(rx.rows(), 2);
151 linearSolver_.
solve(sol2d, residual2d);
153 sol2d = linearSolver(residual2d, Ax);
156 subsidiaryFunction(subsidiaryArgs);
158 const double deltalambda = (-subsidiaryArgs.
f - subsidiaryArgs.
dfdDD.dot(sol2d.col(0))) /
160 deltaD = sol2d.col(0) + deltalambda * sol2d.col(1);
162 updateFunction_(x, deltaD);
163 updateFunction_(subsidiaryArgs.
DD, deltaD);
165 lambda += deltalambda;
166 subsidiaryArgs.
Dlambda += deltalambda;
168 dNorm = sqrt(deltaD.dot(deltaD) + deltalambda * deltalambda);
170 rNorm = sqrt(rx.dot(rx) + subsidiaryArgs.
f * subsidiaryArgs.
f);
181 solverInformation.
success =
false;
188 return solverInformation;
198 NLO nonLinearOperator_;
214template <
typename NLO,
typename LS = utils::SolverDefault,
typename UF = utils::UpdateDefault>
216 UF&& updateFunction = {}) {
217 return std::make_shared<NewtonRaphsonWithSubsidiaryFunction<NLO, LS, UF>>(
218 nonLinearOperator, std::forward<LS>(linearSolver), std::move(updateFunction));
Implementation of the Newton-Raphson method for solving nonlinear equations.
Defines structures and methods related to subsidiary functions for control routines.
Enums for observer messages.
Implementation of the observer design pattern.
Definition: simpleassemblers.hh:22
auto makeNewtonRaphsonWithSubsidiaryFunction(const NLO &nonLinearOperator, LS &&linearSolver={}, UF &&updateFunction={})
Function to create a NewtonRaphson with subsidiary function solver instance.
Definition: newtonraphsonwithscalarsubsidiaryfunction.hh:215
Structure containing arguments for subsidiary functions.
Definition: pathfollowingfunctions.hh:39
double Dlambda
The increment in the load factor.
Definition: pathfollowingfunctions.hh:42
double dfdDlambda
The derivative of the subsidiary function with respect to Dlambda.
Definition: pathfollowingfunctions.hh:45
double f
The value of the subsidiary function.
Definition: pathfollowingfunctions.hh:43
Eigen::VectorX< double > dfdDD
The derivative of the subsidiary function with respect to DD.
Definition: pathfollowingfunctions.hh:44
Eigen::VectorX< double > DD
The vector representing the solution increment.
Definition: pathfollowingfunctions.hh:41
void analyzePattern(const MatrixType &A)
Analyze the pattern of the matrix.
Definition: linearsolver.hh:202
void factorize(const MatrixType &A)
Factorize the matrix.
Definition: linearsolver.hh:213
void solve(Eigen::VectorX< ScalarType > &x, const Eigen::VectorX< ScalarType > &b)
Solve the linear system for a vector.
Definition: linearsolver.hh:222
Settings for the Newton-Raphson solver with subsidiary function.
Definition: newtonraphsonwithscalarsubsidiaryfunction.hh:26
double tol
Definition: newtonraphsonwithscalarsubsidiaryfunction.hh:27
int maxIter
Definition: newtonraphsonwithscalarsubsidiaryfunction.hh:28
Newton-Raphson solver with subsidiary function.
Definition: newtonraphsonwithscalarsubsidiaryfunction.hh:43
UF UpdateFunctionType
Definition: newtonraphsonwithscalarsubsidiaryfunction.hh:52
typename NLO::template ParameterValue< 0 > ValueType
Type representing the update function.
Definition: newtonraphsonwithscalarsubsidiaryfunction.hh:51
static constexpr bool isLinearSolver
< Compile-time boolean indicating if the linear solver satisfies the non-linear solver concept
Definition: newtonraphsonwithscalarsubsidiaryfunction.hh:46
void setup(const NewtonRaphsonWithSubsidiaryFunctionSettings &settings)
Setup the Newton-Raphson solver with subsidiary function.
Definition: newtonraphsonwithscalarsubsidiaryfunction.hh:73
NewtonRaphsonWithSubsidiaryFunction(const NLO &nonLinearOperator, LS &&linearSolver={}, UpdateFunctionType updateFunction={})
Constructor for NewtonRaphsonWithSubsidiaryFunction.
Definition: newtonraphsonwithscalarsubsidiaryfunction.hh:62
auto & nonLinearOperator()
Access the nonlinear operator.
Definition: newtonraphsonwithscalarsubsidiaryfunction.hh:195
NonLinearSolverInformation solve(SubsidiaryType &&subsidiaryFunction, SubsidiaryArgs &subsidiaryArgs, const SolutionType &dxPredictor=NoPredictor{})
Solve the nonlinear system using the Newton-Raphson method with subsidiary function.
Definition: newtonraphsonwithscalarsubsidiaryfunction.hh:97
NLO NonLinearOperator
Type of the non-linear operator.
Definition: newtonraphsonwithscalarsubsidiaryfunction.hh:53
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
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:210