Go to the documentation of this file.
26 params.
addParam<
int>(
"optimal_iterations",
27 "The target number of nonlinear iterations for adaptive timestepping");
28 params.
addParam<
int>(
"iteration_window",
29 "Attempt to grow/shrink timestep if the iteration count "
30 "is below/above 'optimal_iterations plus/minus "
31 "iteration_window' (default = optimal_iterations/5).");
32 params.
addParam<
unsigned>(
"linear_iteration_ratio",
33 "The ratio of linear to nonlinear iterations "
34 "to determine target linear iterations and "
35 "window for adaptive timestepping (default = "
37 params.
addParam<PostprocessorName>(
"timestep_limiting_postprocessor",
38 "If specified, the postprocessor value "
39 "is used as an upper limit for the "
40 "current time step length");
41 params.
addParam<FunctionName>(
"timestep_limiting_function",
42 "A 'PiecewiseBase' type function used to control the timestep by "
43 "limiting the change in the function over a timestep");
45 "max_function_change",
46 "The absolute value of the maximum change in timestep_limiting_function over a timestep");
47 params.
addParam<
bool>(
"force_step_every_function_point",
49 "Forces the timestepper to take "
50 "a step that is consistent with "
51 "points defined in the function");
52 params.
addRequiredParam<Real>(
"dt",
"The default timestep size between solves");
53 params.
addParam<std::vector<Real>>(
"time_t",
"The values of t");
54 params.
addParam<std::vector<Real>>(
"time_dt",
"The values of dt");
55 params.
addParam<Real>(
"growth_factor",
57 "Factor to apply to timestep if easy convergence (if "
58 "'optimal_iterations' is specified) or if recovering "
60 params.
addParam<Real>(
"cutback_factor",
62 "Factor to apply to timestep if difficult "
63 "convergence (if 'optimal_iterations' is specified) "
64 "or if solution failed");
66 params.
addParam<
bool>(
"reject_large_step",
68 "If 'true', time steps that are too large compared to the "
69 "ideal time step will be rejected and repeated");
72 "reject_large_step_threshold > 0 "
73 "& reject_large_step_threshold < 1",
74 "Ratio between the the ideal time step size and the "
75 "current time step size below which a time step will "
76 "be rejected if 'reject_large_step' is 'true'");
86 _dt_old(declareRestartableData<Real>(
"dt_old", 0.0)),
87 _input_dt(getParam<Real>(
"dt")),
88 _tfunc_last_step(declareRestartableData<bool>(
"tfunc_last_step", false)),
89 _sync_last_step(declareRestartableData<bool>(
"sync_last_step", false)),
90 _linear_iteration_ratio(isParamValid(
"linear_iteration_ratio")
91 ? getParam<unsigned>(
"linear_iteration_ratio")
93 _adaptive_timestepping(false),
94 _pps_value(isParamValid(
"timestep_limiting_postprocessor")
95 ? &getPostprocessorValue(
"timestep_limiting_postprocessor")
97 _timestep_limiting_function(nullptr),
98 _piecewise_timestep_limiting_function(nullptr),
99 _piecewise_linear_timestep_limiting_function(nullptr),
101 _max_function_change(-1),
102 _force_step_every_function_point(getParam<bool>(
"force_step_every_function_point")),
103 _tfunc_times(getParam<
std::vector<Real>>(
"time_t").begin(),
104 getParam<
std::vector<Real>>(
"time_t").end()),
105 _time_ipol(getParam<
std::vector<Real>>(
"time_t"), getParam<
std::vector<Real>>(
"time_dt")),
106 _use_time_ipol(_time_ipol.getSampleSize() > 0),
107 _growth_factor(getParam<Real>(
"growth_factor")),
108 _cutback_factor(getParam<Real>(
"cutback_factor")),
109 _nl_its(declareRestartableData<unsigned int>(
"nl_its", 0)),
110 _l_its(declareRestartableData<unsigned int>(
"l_its", 0)),
111 _cutback_occurred(declareRestartableData<bool>(
"cutback_occurred", false)),
112 _at_function_point(false),
113 _reject_large_step(getParam<bool>(
"reject_large_step")),
114 _large_step_rejection_threshold(getParam<Real>(
"reject_large_step_threshold"))
129 mooseError(
"'optimal_iterations' must be used for 'iteration_window' to be used");
131 mooseError(
"'optimal_iterations' must be used for 'linear_iteration_ratio' to be used");
136 isParamValid(
"max_function_change") ? getParam<Real>(
"max_function_change") : -1;
140 mooseError(
"'timestep_limiting_function' must be used for 'max_function_change' to be used");
142 mooseError(
"'timestep_limiting_function' must be used for 'force_step_every_function_point' "
154 isParamValid(
"_tid") ? getParam<THREAD_ID>(
"_tid") : 0);
165 for (
unsigned int i = 0; i < time_size; ++i)
169 mooseError(
"timestep_limiting_function must be a PiecewiseBase function");
200 bool allowToGrow =
false;
212 _console <<
"Setting dt to value specified by dt function: " << std::setw(9) << dt <<
'\n';
222 _console <<
"Setting dt to value used before sync: " << std::setw(9) << dt <<
'\n';
257 _console <<
"Limiting dt to sync with dt function time: " << std::setw(9)
258 << *
_tfunc_times.begin() <<
" dt: " << std::setw(9) << dt <<
'\n';
262 return at_sync_point;
272 mooseError(
"Solve failed and timestep already at dtmin, cannot continue!");
276 _console <<
"\nSolve failed with dt: " << std::setw(9) <<
_dt
280 _console <<
"\nSolve failed, cutting timestep.\n";
327 _console <<
"Limiting dt to postprocessor value. dt = " << limitedDT <<
'\n';
335 Real orig_dt = limitedDT;
340 const auto current_function_value =
343 for (std::size_t next_time_index = 1; next_time_index <
_times.size(); ++next_time_index)
345 const auto next_time =
_times[next_time_index];
352 const auto next_function_value =
354 const auto change =
std::abs(next_function_value - current_function_value);
359 if (restrictedStep < limitedDT)
361 limitedDT = std::max(
_dt_min, restrictedStep);
367 if (next_time >
_time + limitedDT)
376 Real change =
std::abs(newValue - oldValue);
384 change =
std::abs(newValue - oldValue);
392 for (
unsigned int i = 0; i + 1 <
_times.size(); ++i)
406 if (
_verbose && limitedDT != orig_dt)
409 _console <<
"Limiting dt to match function point. dt = ";
411 _console <<
"Limiting dt to limit change in function. dt = ";
420 const unsigned int growth_nl_its(
430 if (allowToGrow && (
_nl_its < growth_nl_its &&
_l_its < growth_l_its))
437 _console <<
"Growing dt: nl its = " <<
_nl_its <<
" < " << growth_nl_its
438 <<
" && lin its = " <<
_l_its <<
" < " << growth_l_its <<
" old dt: " << std::setw(9)
439 <<
_dt_old <<
" new dt: " << std::setw(9) << dt <<
'\n';
442 else if (allowToShrink && (
_nl_its > shrink_nl_its ||
_l_its > shrink_l_its))
449 _console <<
"Shrinking dt: nl its = " <<
_nl_its <<
" > " << shrink_nl_its
450 <<
" || lin its = " <<
_l_its <<
" > " << shrink_l_its <<
" old dt: " << std::setw(9)
451 <<
_dt_old <<
" new dt: " << std::setw(9) << dt <<
'\n';
467 _console <<
"Growing dt to recover from cutback. "
468 <<
" old dt: " << std::setw(9) <<
_dt_old <<
" new dt: " << std::setw(9) << dt
506 _console <<
"Sync point hit in current step, using previous dt for old dt: " << std::setw(9)
virtual Real functionSize() const
void limitDTToPostprocessorValue(Real &limitedDT) const
void limitDTByFunction(Real &limitedDT)
virtual Real computeInitialDT() override
Called to compute _current_dt for the first timestep.
void mooseError(Args &&... args) const
virtual Real value(Real t, const Point &p) const
Override this to evaluate the scalar function at point (t,x,y,z), by default this returns zero,...
Real & _time
Values from executioner.
virtual Real & dtOld() const
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Transient & _executioner
Reference to transient executioner.
void computeAdaptiveDT(Real &dt, bool allowToGrow=true, bool allowToShrink=true)
T sample(const T &x) const
This function will take an independent variable input and will return the dependent variable based on...
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
Real & _timestep_tolerance
virtual void init() override
Initialize the time stepper.
virtual bool constrainStep(Real &dt)
Called after computeStep() is called.
virtual bool converged() const
If the time step converged.
FEProblemBase & _fe_problem
Real unconstrainedDT()
Get the unconstrained dt.
Real computeInterpolationDT()
bool _force_step_every_function_point
insert sync points at the time nodes of the _piecewise_timestep_limiting_function
const Real & _growth_factor
grow the timestep by this factor
const bool & _verbose
should detailed diagnostic output be printed
virtual Real computeFailedDT() override
Called to compute _current_dt after a solve has failed.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
const Function * _timestep_limiting_function
unsigned int & _nl_its
Number of nonlinear iterations in previous solve.
virtual bool converged() const override
If the time step converged.
static InputParameters validParams()
virtual Real value(Real t, const Point &pt) const override
Override this to evaluate the scalar function at point (t,x,y,z), by default this returns zero,...
std::vector< Real > _times
time point defined in the piecewise function
virtual void rejectStep() override
This gets called when time step is rejected.
defineLegacyParams(IterationAdaptiveDT)
Interface class for classes which interact with Postprocessors.
Base class for time stepping.
virtual Real range(const int i) const
double _large_step_rejection_threshold
Threshold used to detect whether we need to reject a step.
bool _adaptive_timestepping
adaptive timestepping is active if the optimal_iterations input parameter is specified
int _iteration_window
...plus/minus this value.
IterationAdaptiveDT(const InputParameters ¶meters)
virtual void acceptStep()
This gets called when time step is accepted.
virtual Real computeDT() override
Called to compute _current_dt for a normal step.
bool atSyncPoint()
Is the current step at a sync point (sync times, time interval, target time, etc)?
const PiecewiseLinear * _piecewise_linear_timestep_limiting_function
virtual void acceptStep() override
This gets called when time step is accepted.
bool _reject_large_step
Indicates whether we need to reject a time step much larger than its ideal size.
LinearInterpolation _time_ipol
PiecewiseBase linear definition of time stepping.
const PiecewiseBase * _piecewise_timestep_limiting_function
virtual Function & getFunction(const std::string &name, THREAD_ID tid=0)
std::set< Real > _tfunc_times
virtual bool constrainStep(Real &dt) override
Called after computeStep() is called.
const Real _input_dt
The dt from the input file.
const Real & _cutback_factor
cut the timestep by by this factor
virtual Real domain(const int i) const
virtual void preExecute() override
NonlinearSystemBase & getNonlinearSystemBase()
virtual void rejectStep()
This gets called when time step is rejected.
registerMooseObject("MooseApp", IterationAdaptiveDT)
const PostprocessorValue * _pps_value
if specified, the postprocessor value is an upper limit for the time step length
unsigned int nLinearIterations() const
Return the number of linear iterations.
static InputParameters validParams()
Adjust the timestep based on the number of iterations.
unsigned int & _l_its
Number of linear iterations in previous solve.
int _optimal_iterations
Adapt the timestep to maintain this non-linear iteration count...
const bool _use_time_ipol
true if we want to use piecewise-defined time stepping
virtual void preExecute()
const int _linear_iteration_ratio
use _optimal_iterations and _iteration_window multiplied with this factor for linear iterations
Real _max_function_change
unsigned int nNonlinearIterations() const
Return the number of non-linear iterations.