version 0.4.1
adaptivestepsizing.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2025 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 F>
37 void operator()(const NonLinearSolverInformation& solverInfo, SubsidiaryArgs& subsidiaryArgs, const F& f) {}
38
43 [[nodiscard]] int targetIterations() const { return 0; }
44
49 void setTargetIterations([[maybe_unused]] int targetIterations) {}
50};
51
63{
74 template <typename F>
75 void operator()(const NonLinearSolverInformation& solverInfo, SubsidiaryArgs& subsidiaryArgs, const F& f) {
76 if (subsidiaryArgs.currentStep == 0)
77 return;
78 if (targetIterations_ == 0)
79 DUNE_THROW(Dune::InvalidStateException,
80 "TargetIterations should not be equal to 0. Try calling "
81 "setTargetIterations(int) first.");
82 const auto previousIterations = solverInfo.iterations;
83 if (previousIterations > targetIterations_)
84 subsidiaryArgs.stepSize =
85 sqrt(static_cast<double>(targetIterations_) / previousIterations) * subsidiaryArgs.stepSize;
86 }
87
92 [[nodiscard]] int targetIterations() const { return targetIterations_; }
93
99 if (targetIterations == 0)
100 DUNE_THROW(Dune::InvalidStateException, "TargetIterations should not be equal to 0.");
101 targetIterations_ = targetIterations;
102 }
103
104private:
105 int targetIterations_{0};
106};
107} // namespace Ikarus::AdaptiveStepSizing
Implementation of the solver information returned by the nonlinear solvers.
Defines structures and methods related to subsidiary functions for control routines.
Definition: adaptivestepsizing.hh:17
The NoOp strategy for adaptive step sizing.
Definition: adaptivestepsizing.hh:25
void operator()(const NonLinearSolverInformation &solverInfo, SubsidiaryArgs &subsidiaryArgs, const F &f)
Call operator for the NoOp strategy.
Definition: adaptivestepsizing.hh:37
void setTargetIterations(int targetIterations)
Set the target iterations.
Definition: adaptivestepsizing.hh:49
int targetIterations() const
Get the target iterations.
Definition: adaptivestepsizing.hh:43
The IterationBased strategy for adaptive step sizing.
Definition: adaptivestepsizing.hh:63
void setTargetIterations(int targetIterations)
Set the target iterations.
Definition: adaptivestepsizing.hh:98
void operator()(const NonLinearSolverInformation &solverInfo, SubsidiaryArgs &subsidiaryArgs, const F &f)
Call operator of the IterationBased strategy.
Definition: adaptivestepsizing.hh:75
int targetIterations() const
Get the target iterations.
Definition: adaptivestepsizing.hh:92
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:21
int iterations
Definition: solverinfos.hh:31