version 0.4
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
24 struct NoOp {
34 template <typename NonLinearOperator>
35 void operator()(const NonLinearSolverInformation& solverInfo, SubsidiaryArgs& subsidiaryArgs,
36 const NonLinearOperator& nonLinearOperator) {}
37
42 [[nodiscard]] int targetIterations() const { return 0; }
43
48 void setTargetIterations([[maybe_unused]] int targetIterations) {}
49 };
50
71 template <typename NonLinearOperator>
72 void operator()(const NonLinearSolverInformation& solverInfo, SubsidiaryArgs& subsidiaryArgs,
73 const NonLinearOperator&) {
74 if (subsidiaryArgs.currentStep == 0) return;
75 if (targetIterations_ == 0)
76 DUNE_THROW(Dune::InvalidStateException,
77 "For IterationBased, targetIterations should not be equal to 0. Try calling "
78 "setTargetIterations(int) first.");
79 const auto previousIterations = solverInfo.iterations;
80 if (previousIterations > targetIterations_)
81 subsidiaryArgs.stepSize
82 = sqrt(static_cast<double>(targetIterations_) / previousIterations) * subsidiaryArgs.stepSize;
83 }
84
89 [[nodiscard]] int targetIterations() const { return targetIterations_; }
90
95 void setTargetIterations(int targetIterations) { targetIterations_ = targetIterations; }
96
97 private:
98 int targetIterations_{0};
99 };
100} // namespace Ikarus::AdaptiveStepSizing
Implementation of the Newton-Raphson method for solving nonlinear equations.
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:24
void setTargetIterations(int targetIterations)
Set the target iterations.
Definition: adaptivestepsizing.hh:48
void operator()(const NonLinearSolverInformation &solverInfo, SubsidiaryArgs &subsidiaryArgs, const NonLinearOperator &nonLinearOperator)
Call operator for the NoOp strategy.
Definition: adaptivestepsizing.hh:35
int targetIterations() const
Get the target iterations.
Definition: adaptivestepsizing.hh:42
The IterationBased strategy for adaptive step sizing.
Definition: adaptivestepsizing.hh:61
void setTargetIterations(int targetIterations)
Set the target iterations.
Definition: adaptivestepsizing.hh:95
int targetIterations() const
Get the target iterations.
Definition: adaptivestepsizing.hh:89
void operator()(const NonLinearSolverInformation &solverInfo, SubsidiaryArgs &subsidiaryArgs, const NonLinearOperator &)
Call operator of the IterationBased strategy.
Definition: adaptivestepsizing.hh:72
Structure containing arguments for subsidiary functions.
Definition: pathfollowingfunctions.hh:38
int currentStep
The current step index in the control routine.
Definition: pathfollowingfunctions.hh:45
double stepSize
The step size in the control routine.
Definition: pathfollowingfunctions.hh:39
Information about the result of a non-linear solver.
Definition: solverinfos.hh:18
int iterations
Definition: solverinfos.hh:28
Represents a NonLinearOperator class for handling nonlinear operators.
Definition: nonlinearoperator.hh:154