27 params.
addParam<
int>(
"optimal_iterations",
28 "The target number of nonlinear iterations for adaptive timestepping");
29 params.
addParam<
int>(
"iteration_window",
30 "Attempt to grow/shrink timestep if the iteration count " 31 "is below/above 'optimal_iterations plus/minus " 32 "iteration_window' (default = optimal_iterations/5).");
33 params.
addParam<
unsigned>(
"linear_iteration_ratio",
34 "The ratio of linear to nonlinear iterations " 35 "to determine target linear iterations and " 36 "window for adaptive timestepping (default = " 38 params.
addParam<std::vector<PostprocessorName>>(
"timestep_limiting_postprocessor",
39 "If specified, a list of postprocessor values " 40 "used as an upper limit for the " 41 "current time step length");
42 params.
addParam<std::vector<FunctionName>>(
43 "timestep_limiting_function",
44 "A list of 'PiecewiseBase' type functions used to control the timestep by " 45 "limiting the change in the function over a timestep");
47 "max_function_change",
48 "The absolute value of the maximum change in timestep_limiting_function over a timestep");
49 params.
addParam<
bool>(
"force_step_every_function_point",
51 "Forces the timestepper to take " 52 "a step that is consistent with " 53 "points defined in the function");
55 "post_function_sync_dt",
56 "post_function_sync_dt>0",
57 "Timestep to apply after time sync with function point. To be used in " 58 "conjunction with 'force_step_every_function_point'.");
60 params.
addParam<std::vector<Real>>(
"time_t", {},
"The values of t");
61 params.
addParam<std::vector<Real>>(
"time_dt", {},
"The values of dt");
64 "Factor to apply to timestep if easy convergence (if " 65 "'optimal_iterations' is specified) or if recovering " 69 "Factor to apply to timestep if difficult convergence " 70 "occurs (if 'optimal_iterations' is specified). " 71 "For failed solves, use cutback_factor_at_failure");
73 params.
addParam<
bool>(
"reject_large_step",
75 "If 'true', time steps that are too large compared to the " 76 "ideal time step will be rejected and repeated");
79 "reject_large_step_threshold > 0 " 80 "& reject_large_step_threshold < 1",
81 "Ratio between the the ideal time step size and the " 82 "current time step size below which a time step will " 83 "be rejected if 'reject_large_step' is 'true'");
93 _dt_old(declareRestartableData<
Real>(
"dt_old", 0.0)),
94 _input_dt(getParam<
Real>(
"dt")),
95 _tfunc_last_step(declareRestartableData<bool>(
"tfunc_last_step", false)),
96 _sync_last_step(declareRestartableData<bool>(
"sync_last_step", false)),
97 _linear_iteration_ratio(isParamValid(
"linear_iteration_ratio")
98 ? getParam<unsigned>(
"linear_iteration_ratio")
100 _adaptive_timestepping(false),
102 parameters.
get<
std::vector<PostprocessorName>>(
"timestep_limiting_postprocessor").size()),
103 _timestep_limiting_functions(),
104 _piecewise_timestep_limiting_functions(),
105 _piecewise_linear_timestep_limiting_functions(),
107 _max_function_change(-1),
108 _force_step_every_function_point(getParam<bool>(
"force_step_every_function_point")),
109 _post_function_sync_dt(isParamValid(
"force_step_every_function_point") &&
110 isParamValid(
"post_function_sync_dt")
111 ? getParam<
Real>(
"post_function_sync_dt")
113 _tfunc_times(getParam<
std::vector<
Real>>(
"time_t").begin(),
114 getParam<
std::vector<
Real>>(
"time_t").end()),
115 _time_ipol(getParam<
std::vector<
Real>>(
"time_t"), getParam<
std::vector<
Real>>(
"time_dt")),
116 _use_time_ipol(_time_ipol.getSampleSize() > 0),
117 _growth_factor(getParam<
Real>(
"growth_factor")),
118 _cutback_factor(getParam<
Real>(
"cutback_factor")),
119 _nl_its(declareRestartableData<unsigned
int>(
"nl_its", 0)),
120 _l_its(declareRestartableData<unsigned
int>(
"l_its", 0)),
121 _cutback_occurred(declareRestartableData<bool>(
"cutback_occurred", false)),
122 _at_function_point(false),
123 _reject_large_step(getParam<bool>(
"reject_large_step")),
124 _large_step_rejection_threshold(getParam<
Real>(
"reject_large_step_threshold"))
126 auto timestep_limiting_postprocessor_names =
127 parameters.
get<std::vector<PostprocessorName>>(
"timestep_limiting_postprocessor");
128 for (
size_t i = 0; i <
_pps_value.size(); ++i)
144 mooseError(
"'optimal_iterations' must be used for 'iteration_window' to be used");
146 mooseError(
"'optimal_iterations' must be used for 'linear_iteration_ratio' to be used");
151 isParamValid(
"max_function_change") ? getParam<Real>(
"max_function_change") : -1;
155 mooseError(
"'timestep_limiting_function' must be used for 'max_function_change' to be used");
157 mooseError(
"'timestep_limiting_function' must be used for 'force_step_every_function_point' " 163 "Not applicable if 'force_step_every_function_point = false'");
171 std::set<Real> times;
173 const auto tid =
isParamValid(
"_tid") ? getParam<THREAD_ID>(
"_tid") : 0;
174 for (
const auto &
name :
getParam<std::vector<FunctionName>>(
"timestep_limiting_function"))
179 const auto * pfunc =
dynamic_cast<const PiecewiseBase *
>(func);
187 const auto ntimes = pfunc->functionSize();
188 for (
unsigned int i = 0; i < ntimes; ++i)
189 times.insert(pfunc->domain(i));
192 mooseError(
"timestep_limiting_function must be a PiecewiseBase function");
194 _times.resize(times.size());
195 std::copy(times.begin(), times.end(),
_times.begin());
199 "Timestep limiting function count inconsistency");
202 "Timestep limiting function count inconsistency");
224 _console <<
"Setting initial dt to value specified by dt function: " << std::setw(9) << dt
231 _console <<
"Setting initial dt to input value: " << std::setw(9) << dt << std::endl;
247 bool allowToGrow =
false;
257 _console <<
"Setting dt to value specified by dt function: " << std::setw(9) << dt
268 _console <<
"Setting dt to 'post_function_sync_dt': " << std::setw(9) << dt << std::endl;
275 _console <<
"Setting dt to unconstrained value used before sync: " << std::setw(9) << dt
290 <<
") and previous dt before sync (" <<
_dt_old <<
") : " << std::setw(9) << dt
314 _console <<
"Limiting dt to sync with dt function time: " << std::setw(9)
315 << *
_tfunc_times.begin() <<
" dt: " << std::setw(9) << dt << std::endl;
318 return at_sync_point;
328 mooseError(
"Solve failed and timestep already at dtmin, cannot continue!");
332 _console <<
"\nSolve failed with dt: " << std::setw(9) <<
_dt 337 _console <<
"\nSolve failed, cutting timestep." << std::endl;
380 unsigned int i_min = 0;
381 for (
size_t i = 1; i <
_pps_value.size(); ++i)
388 if (limitedDT > limiting_pps_value)
390 if (limiting_pps_value < 0)
392 "Negative timestep limiting postprocessor '" +
393 getParam<std::vector<PostprocessorName>>(
"timestep_limiting_postprocessor")[i_min] +
394 "': " + std::to_string(limiting_pps_value));
398 _console <<
"Limiting dt to postprocessor value. dt = " << limitedDT << std::endl;
406 Real orig_dt = limitedDT;
410 for (
unsigned int j = 0; j < nfunc; ++j)
415 const auto current_function_value =
419 for (std::size_t next_time_index = 1; next_time_index < ntimes; ++next_time_index)
421 const auto next_time =
429 const auto next_function_value =
431 const auto change =
std::abs(next_function_value - current_function_value);
441 if (next_time >
_time + limitedDT)
456 change =
std::abs(new_value - old_value);
461 if (restricted_step < limitedDT)
466 for (
unsigned int i = 0; i + 1 <
_times.size(); ++i)
477 if (
_verbose && limitedDT != orig_dt)
480 _console <<
"Limiting dt to match function point. dt = ";
482 _console <<
"Limiting dt to limit change in function. dt = ";
491 const unsigned int growth_nl_its(
501 if (allowToGrow && (
_nl_its < growth_nl_its &&
_l_its < growth_l_its))
507 _console <<
"Growing dt: nl its = " <<
_nl_its <<
" < " << growth_nl_its
508 <<
" && lin its = " <<
_l_its <<
" < " << growth_l_its <<
" old dt: " << std::setw(9)
509 <<
_dt_old <<
" new dt: " << std::setw(9) << dt <<
'\n';
511 else if (allowToShrink && (
_nl_its > shrink_nl_its ||
_l_its > shrink_l_its))
517 _console <<
"Shrinking dt: nl its = " <<
_nl_its <<
" > " << shrink_nl_its
518 <<
" || lin its = " <<
_l_its <<
" > " << shrink_l_its <<
" old dt: " << std::setw(9)
519 <<
_dt_old <<
" new dt: " << std::setw(9) << dt <<
'\n';
535 _console <<
"Growing dt to recover from cutback. " 536 <<
" old dt: " << std::setw(9) <<
_dt_old <<
" new dt: " << std::setw(9) << dt
573 _console <<
"Sync point hit in current step, using previous dt for old dt: " << std::setw(9)
static InputParameters validParams()
Real & _timestep_tolerance
unsigned int nLinearIterations() const
Return the number of linear iterations.
bool atSyncPoint()
Is the current step at a sync point (sync times, time interval, target time, etc)?
Function base which provides a piecewise approximation to a specified (x,y) point data set...
virtual Real & dtOld() const
Real computeInterpolationDT()
const Real & _cutback_factor
cut the timestep by by this factor
unsigned int & _nl_its
Number of nonlinear iterations in previous solve.
std::vector< const Function * > _timestep_limiting_functions
std::vector< const PostprocessorValue * > _pps_value
if specified, the postprocessor values used to determine an upper limit for the time step length ...
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
virtual Real computeDT() override
Called to compute _current_dt for a normal step.
Adjust the timestep based on the number of iterations.
Base class for time stepping.
T sample(const T &x) const
This function will take an independent variable input and will return the dependent variable based on...
const Real _input_dt
The dt from the input file.
Function which provides a piecewise continuous linear interpolation of a provided (x...
virtual Real computeInitialDT() override
Called to compute _current_dt for the first timestep.
Transient & _executioner
Reference to transient executioner.
IterationAdaptiveDT(const InputParameters ¶meters)
virtual bool constrainStep(Real &dt)
Called after computeStep() is called.
bool _reject_large_step
Indicates whether we need to reject a time step much larger than its ideal size.
void limitDTByFunction(Real &limitedDT)
virtual bool constrainStep(Real &dt) override
Called after computeStep() is called.
virtual bool converged() const
If the time step converged.
std::vector< const PiecewiseLinear * > _piecewise_linear_timestep_limiting_functions
const Real _cutback_factor_at_failure
Cutback factor if a time step fails to converge.
const Real & _growth_factor
grow the timestep by this factor
virtual const std::string & name() const
Get the name of the class.
int _optimal_iterations
Adapt the timestep to maintain this non-linear iteration count...
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
auto max(const L &left, const R &right)
virtual Real computeFailedDT() override
Called to compute _current_dt after a solve has failed.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
const bool _force_step_every_function_point
insert sync points at the time nodes of the _piecewise_timestep_limiting_function ...
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
const bool & _verbose
whether a detailed diagnostic output should be printed
FEProblemBase & _fe_problem
virtual Function & getFunction(const std::string &name, const THREAD_ID tid=0)
Real unconstrainedDT()
Get the unconstrained dt.
const bool _use_time_ipol
true if we want to use piecewise-defined time stepping
std::vector< const PiecewiseBase * > _piecewise_timestep_limiting_functions
unsigned int & _l_its
Number of linear iterations in previous solve.
static InputParameters validParams()
virtual void preExecute() override
Real _max_function_change
virtual void acceptStep()
This gets called when time step is accepted.
LinearInterpolation _time_ipol
PiecewiseBase linear definition of time stepping.
const Real _post_function_sync_dt
Set timestep size if previous timestep is synced with function.
virtual void rejectStep() override
This gets called when time step is rejected.
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
std::set< Real > _tfunc_times
bool _adaptive_timestepping
adaptive timestepping is active if the optimal_iterations input parameter is specified ...
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
void limitDTToPostprocessorValue(Real &limitedDT) const
virtual bool converged() const override
If the time step converged.
virtual const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName &name) const
Retrieve the value of the Postprocessor.
virtual void init() override
Initialize the time stepper.
void computeAdaptiveDT(Real &dt, bool allowToGrow=true, bool allowToShrink=true)
unsigned int nNonlinearIterations() const
Return the number of non-linear iterations.
const int _linear_iteration_ratio
use _optimal_iterations and _iteration_window multiplied with this factor for linear iterations ...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< Real > _times
time point defined in the piecewise function
registerMooseObject("MooseApp", IterationAdaptiveDT)
int _iteration_window
...plus/minus this value.
virtual void preExecute()
virtual void rejectStep()
This gets called when time step is rejected.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & parameters() const
Get the parameters of the object.
double _large_step_rejection_threshold
Threshold used to detect whether we need to reject a step.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
auto min(const L &left, const R &right)
void ErrorVector unsigned int
Real & _time
Values from executioner.
Interface class for classes which interact with Postprocessors.
virtual void acceptStep() override
This gets called when time step is accepted.