version 0.4.1
adaptivestepsizing.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2024 The Ikarus Developers mueller@ibb.uni-stuttgart.de
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
12#pragma once
13
16
18
24struct NoOp
25{
36 template <typename NLO>
37 void operator()(const NonLinearSolverInformation& solverInfo, SubsidiaryArgs& subsidiaryArgs,
38 const NLO& nonLinearOperator) {}
39
44 [[nodiscard]] int targetIterations() const { return 0; }
45
50 void setTargetIterations([[maybe_unused]] int targetIterations) {}
51};
52
64{
75 template <typename NLO>
76 void operator()(const NonLinearSolverInformation& solverInfo, SubsidiaryArgs& subsidiaryArgs,
77 const NLO& nonLinearOperator) {
78 if (subsidiaryArgs.currentStep == 0)
79 return;
80 if (targetIterations_ == 0)
81 DUNE_THROW(Dune::InvalidStateException,
82 "TargetIterations should not be equal to 0. Try calling "
83 "setTargetIterations(int) first.");
84 const auto previousIterations = solverInfo.iterations;
85 if (previousIterations > targetIterations_)
86 subsidiaryArgs.stepSize =
87 sqrt(static_cast<double>(targetIterations_) / previousIterations) * subsidiaryArgs.stepSize;
88 }
89
94 [[nodiscard]] int targetIterations() const { return targetIterations_; }
95
101 if (targetIterations == 0)
102 DUNE_THROW(Dune::InvalidStateException, "TargetIterations should not be equal to 0.");
103 targetIterations_ = targetIterations;
104 }
105
106private:
107 int targetIterations_{0};
108};
109} // namespace Ikarus::AdaptiveStepSizing
Defines structures and methods related to subsidiary functions for control routines.
Implementation of the Newton-Raphson method for solving nonlinear equations.
Definition: adaptivestepsizing.hh:17
The NoOp strategy for adaptive step sizing.
Definition: adaptivestepsizing.hh:25
void operator()(const NonLinearSolverInformation &solverInfo, SubsidiaryArgs &subsidiaryArgs, const NLO &nonLinearOperator)
Call operator for the NoOp strategy.
Definition: adaptivestepsizing.hh:37
void setTargetIterations(int targetIterations)
Set the target iterations.
Definition: adaptivestepsizing.hh:50
int targetIterations() const
Get the target iterations.
Definition: adaptivestepsizing.hh:44
The IterationBased strategy for adaptive step sizing.
Definition: adaptivestepsizing.hh:64
void setTargetIterations(int targetIterations)
Set the target iterations.
Definition: adaptivestepsizing.hh:100
void operator()(const NonLinearSolverInformation &solverInfo, SubsidiaryArgs &subsidiaryArgs, const NLO &nonLinearOperator)
Call operator of the IterationBased strategy.
Definition: adaptivestepsizing.hh:76
int targetIterations() const
Get the target iterations.
Definition: adaptivestepsizing.hh:94
Structure containing arguments for subsidiary functions.
Definition: pathfollowingfunctions.hh:39
int currentStep
The current step index in the control routine.
Definition: pathfollowingfunctions.hh:46
double stepSize
The step size in the control routine.
Definition: pathfollowingfunctions.hh:40
Information about the result of a non-linear solver.
Definition: solverinfos.hh:19
int iterations
Definition: solverinfos.hh:29