12#ifndef DUMUX_NEWTON_SOLVER_LINESEARCH_CUBIC_BACKTRACKING_HH
13#define DUMUX_NEWTON_SOLVER_LINESEARCH_CUBIC_BACKTRACKING_HH
49 class Comm = Dune::Communication<Dune::MPIHelper::MPICommunicator> >
51:
public NewtonSolver<Assembler, LinearSolver, Reassembler, Comm>
54 using Scalar =
typename Assembler::Scalar;
69 const std::string& paramGroupName =
"Newton",
86 const Scalar g0 = 0.5*residualNorm0*residualNorm0;
88 const Scalar slope = -residualNorm0*residualNorm0;
91 Scalar lambdaPrev = 0.0;
93 bool hasPrevTrial =
false;
94 auto uCurrentIter = uLastIter;
97 Backend::axpy(-lambda, deltaU, uCurrentIter);
102 if (g <= g0 + armijoC1_*lambda*slope || lambda <= minRelaxationFactor_)
108 Scalar lambdaNext = 0.5*lambda;
111 const Scalar lambdaModel = hasPrevTrial ? cubicMinimizer_(g0, slope, lambda, g, lambdaPrev, gPrev)
112 : quadraticMinimizer_(g0, slope, lambda, g);
113 if (isfinite(lambdaModel))
114 lambdaNext = lambdaModel;
121 lambda = std::max<Scalar>(std::clamp<Scalar>(lambdaNext, 0.1*lambda, 0.5*lambda), minRelaxationFactor_);
122 uCurrentIter = uLastIter;
127 static Scalar quadraticMinimizer_(Scalar g0, Scalar slope, Scalar lambda, Scalar g)
128 {
return -slope*lambda*lambda/(2.0*(g - g0 - slope*lambda)); }
131 static Scalar cubicMinimizer_(Scalar g0, Scalar slope, Scalar lambda, Scalar g, Scalar lambdaPrev, Scalar gPrev)
134 const Scalar t = (g - g0 - slope*lambda)/(lambda*lambda);
135 const Scalar tPrev = (gPrev - g0 - slope*lambdaPrev)/(lambdaPrev*lambdaPrev);
136 const Scalar a = (t - tPrev)/(lambda - lambdaPrev);
137 const Scalar b = (lambda*tPrev - lambdaPrev*t)/(lambda - lambdaPrev);
139 return -slope/(2.0*b);
141 const Scalar discriminant = b*b - 3.0*a*slope;
142 if (discriminant < 0.0)
145 return (-b + sqrt(discriminant))/(3.0*a);
147 return -slope/(b + sqrt(discriminant));
150 Scalar minRelaxationFactor_;
Base class for linear solvers.
Definition solver.hh:27
typename Assembler::ResidualType ResidualVector
Definition nonlinear/newtonsolver.hh:189
const std::string & paramGroup() const
Returns the parameter group.
Definition nonlinear/newtonsolver.hh:826
Scalar reduction_
Definition nonlinear/newtonsolver.hh:895
int verbosity() const
Return the verbosity level.
Definition nonlinear/newtonsolver.hh:808
NewtonSolver(std::shared_ptr< Assembler > assembler, std::shared_ptr< LinearSolver > linearSolver, const Communication &comm=Dune::MPIHelper::getCommunication(), const std::string ¶mGroup="", const std::string ¶mGroupName="Newton", int verbosity=2)
Definition nonlinear/newtonsolver.hh:209
virtual void solutionChanged_(Variables &vars, const SolutionVector &uCurrentIter)
Update solution-dependent quantities like grid variables after the solution has changed.
Definition nonlinear/newtonsolver.hh:860
Scalar initialResidual_
Definition nonlinear/newtonsolver.hh:898
Scalar lastReduction_
Definition nonlinear/newtonsolver.hh:897
void setUseLineSearch(bool val=true)
Specify whether line search is enabled or not.
Definition nonlinear/newtonsolver.hh:814
std::ostringstream endIterMsgStream_
message stream to be displayed at the end of iterations
Definition nonlinear/newtonsolver.hh:905
typename Backend::DofVector SolutionVector
Definition nonlinear/newtonsolver.hh:188
const Communication & comm() const
the communicator for parallel runs
Definition nonlinear/newtonsolver.hh:239
VariablesBackend< typename ParentType::Variables > Backend
Definition nonlinear/newtonsolver.hh:187
void computeResidualReduction_(const Variables &vars)
Definition nonlinear/newtonsolver.hh:868
Scalar residualNorm_
Definition nonlinear/newtonsolver.hh:896
NewtonSolverLinesearchCubicbacktracking(std::shared_ptr< Assembler > assembler, std::shared_ptr< LinearSolver > linearSolver, const Communication &comm=Dune::MPIHelper::getCommunication(), const std::string ¶mGroup="", const std::string ¶mGroupName="Newton", int verbosity=2)
Definition newtonsolver_linesearch_cubicbacktracking.hh:65
typename ParentType::SolutionVector SolutionVector
Definition newtonsolver_linesearch_cubicbacktracking.hh:58
Comm Communication
Definition newtonsolver_linesearch_cubicbacktracking.hh:63
void lineSearchUpdate_(Variables &vars, const SolutionVector &uLastIter, const ResidualVector &deltaU) override
Use a line search update based on simple backtracking.
Definition newtonsolver_linesearch_cubicbacktracking.hh:79
typename ParentType::Backend Backend
Definition newtonsolver_linesearch_cubicbacktracking.hh:57
typename ParentType::ResidualVector ResidualVector
Definition newtonsolver_linesearch_cubicbacktracking.hh:59
const LinearSolver & linearSolver() const
Definition common/pdesolver.hh:133
const Assembler & assembler() const
Definition common/pdesolver.hh:121
Detail::PDESolver::AssemblerVariables< Assembler > Variables
Definition common/pdesolver.hh:71
detects which entries in the Jacobian have to be recomputed
Definition partialreassembler.hh:418
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition parameters.hh:165
Reference implementation of a Newton solver.
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.