31 "The target number of solver outer iterations for adaptive timestepping. " 32 "For a problem using nonlinear systems, the total number of nonlinear iterations is used. " 33 "For a problem using linear systems, the total number of linear iterations is used.");
34 params.
addParam<
int>(
"iteration_window",
35 "Attempt to grow/shrink timestep if the iteration count " 36 "is below/above 'optimal_iterations plus/minus " 37 "iteration_window' (default = optimal_iterations/5).");
38 params.
addParam<
unsigned>(
"linear_iteration_ratio",
39 "The ratio of linear to nonlinear iterations " 40 "to determine target linear iterations and " 41 "window for adaptive timestepping (default = " 43 params.
addParam<std::vector<PostprocessorName>>(
"timestep_limiting_postprocessor",
44 "If specified, a list of postprocessor values " 45 "used as an upper limit for the " 46 "current time step length");
47 params.
addParam<std::vector<FunctionName>>(
48 "timestep_limiting_function",
49 "A list of 'PiecewiseBase' type functions used to control the timestep by " 50 "limiting the change in the function over a timestep");
52 "max_function_change",
53 "The absolute value of the maximum change in timestep_limiting_function over a timestep");
54 params.
addParam<
bool>(
"force_step_every_function_point",
56 "Forces the timestepper to take " 57 "a step that is consistent with " 58 "points defined in the function");
60 "post_function_sync_dt",
61 "post_function_sync_dt>0",
62 "Timestep to apply after time sync with function point. To be used in " 63 "conjunction with 'force_step_every_function_point'.");
65 params.
addParam<std::vector<Real>>(
"time_t", {},
"The values of t");
66 params.
addParam<std::vector<Real>>(
"time_dt", {},
"The values of dt");
69 "Factor to apply to timestep if easy convergence (if " 70 "'optimal_iterations' is specified) or if recovering " 74 "Factor to apply to timestep if difficult convergence " 75 "occurs (if 'optimal_iterations' is specified). " 76 "For failed solves, use cutback_factor_at_failure");
78 params.
addParam<
bool>(
"reject_large_step",
80 "If 'true', time steps that are too large compared to the " 81 "ideal time step will be rejected and repeated");
84 "reject_large_step_threshold > 0 " 85 "& reject_large_step_threshold < 1",
86 "Ratio between the the ideal time step size and the " 87 "current time step size below which a time step will " 88 "be rejected if 'reject_large_step' is 'true'");
98 _dt_old(declareRestartableData<
Real>(
"dt_old", 0.0)),
99 _input_dt(getParam<
Real>(
"dt")),
100 _tfunc_last_step(declareRestartableData<bool>(
"tfunc_last_step", false)),
101 _sync_last_step(declareRestartableData<bool>(
"sync_last_step", false)),
102 _linear_iteration_ratio(isParamValid(
"linear_iteration_ratio")
103 ? getParam<unsigned>(
"linear_iteration_ratio")
105 _adaptive_timestepping(false),
107 parameters.
get<
std::vector<PostprocessorName>>(
"timestep_limiting_postprocessor").size()),
108 _timestep_limiting_functions(),
109 _piecewise_timestep_limiting_functions(),
110 _piecewise_linear_timestep_limiting_functions(),
112 _max_function_change(-1),
113 _force_step_every_function_point(getParam<bool>(
"force_step_every_function_point")),
114 _post_function_sync_dt(isParamValid(
"force_step_every_function_point") &&
115 isParamValid(
"post_function_sync_dt")
116 ? getParam<
Real>(
"post_function_sync_dt")
118 _tfunc_times(getParam<
std::vector<
Real>>(
"time_t").begin(),
119 getParam<
std::vector<
Real>>(
"time_t").end()),
120 _time_ipol(getParam<
std::vector<
Real>>(
"time_t"), getParam<
std::vector<
Real>>(
"time_dt")),
121 _use_time_ipol(_time_ipol.getSampleSize() > 0),
122 _growth_factor(getParam<
Real>(
"growth_factor")),
123 _cutback_factor(getParam<
Real>(
"cutback_factor")),
124 _outer_its(declareRestartableData<unsigned
int>(
"outer_its", 0)),
126 _l_its(declareRestartableData<unsigned
int>(
"l_its", 0)),
127 _cutback_occurred(declareRestartableData<bool>(
"cutback_occurred", false)),
128 _at_function_point(false),
129 _reject_large_step(getParam<bool>(
"reject_large_step")),
130 _large_step_rejection_threshold(getParam<
Real>(
"reject_large_step_threshold"))
132 auto timestep_limiting_postprocessor_names =
133 parameters.
get<std::vector<PostprocessorName>>(
"timestep_limiting_postprocessor");
134 for (
size_t i = 0; i <
_pps_value.size(); ++i)
150 mooseError(
"'optimal_iterations' must be used for 'iteration_window' to be used");
152 mooseError(
"'optimal_iterations' must be used for 'linear_iteration_ratio' to be used");
157 isParamValid(
"max_function_change") ? getParam<Real>(
"max_function_change") : -1;
161 mooseError(
"'timestep_limiting_function' must be used for 'max_function_change' to be used");
163 mooseError(
"'timestep_limiting_function' must be used for 'force_step_every_function_point' " 169 "Not applicable if 'force_step_every_function_point = false'");
177 std::set<Real> times;
179 const auto tid =
isParamValid(
"_tid") ? getParam<THREAD_ID>(
"_tid") : 0;
180 for (
const auto &
name :
getParam<std::vector<FunctionName>>(
"timestep_limiting_function"))
185 const auto * pfunc =
dynamic_cast<const PiecewiseBase *
>(func);
193 const auto ntimes = pfunc->functionSize();
194 for (
unsigned int i = 0; i < ntimes; ++i)
195 times.insert(pfunc->domain(i));
198 mooseError(
"timestep_limiting_function must be a PiecewiseBase function");
200 _times.resize(times.size());
201 std::copy(times.begin(), times.end(),
_times.begin());
205 "Timestep limiting function count inconsistency");
208 "Timestep limiting function count inconsistency");
230 _console <<
"Setting initial dt to value specified by dt function: " << std::setw(9) << dt
237 _console <<
"Setting initial dt to input value: " << std::setw(9) << dt << std::endl;
253 bool allowToGrow =
false;
263 _console <<
"Setting dt to value specified by dt function: " << std::setw(9) << dt
274 _console <<
"Setting dt to 'post_function_sync_dt': " << std::setw(9) << dt << std::endl;
281 _console <<
"Setting dt to unconstrained value used before sync: " << std::setw(9) << dt
296 <<
") and previous dt before sync (" <<
_dt_old <<
") : " << std::setw(9) << dt
327 _console <<
"Limiting dt to sync with dt function time: " << std::setw(9)
328 << *
_tfunc_times.begin() <<
" dt: " << std::setw(9) << dt << std::endl;
331 return at_sync_point;
341 mooseError(
"Solve failed and timestep already at dtmin, cannot continue!");
345 _console <<
"\nSolve failed with dt: " << std::setw(9) <<
_dt 350 _console <<
"\nSolve failed, cutting timestep." << std::endl;
400 unsigned int i_min = 0;
401 for (
size_t i = 1; i <
_pps_value.size(); ++i)
408 if (limitedDT > limiting_pps_value)
410 if (limiting_pps_value < 0)
412 "Negative timestep limiting postprocessor '" +
413 getParam<std::vector<PostprocessorName>>(
"timestep_limiting_postprocessor")[i_min] +
414 "': " + std::to_string(limiting_pps_value));
418 _console <<
"Limiting dt to postprocessor value. dt = " << limitedDT << std::endl;
426 Real orig_dt = limitedDT;
430 for (
unsigned int j = 0; j < nfunc; ++j)
435 const auto current_function_value =
439 for (std::size_t next_time_index = 1; next_time_index < ntimes; ++next_time_index)
441 const auto next_time =
449 const auto next_function_value =
451 const auto change =
std::abs(next_function_value - current_function_value);
461 if (next_time >
_time + limitedDT)
476 change =
std::abs(new_value - old_value);
481 if (restricted_step < limitedDT)
486 for (
unsigned int i = 0; i + 1 <
_times.size(); ++i)
497 if (
_verbose && limitedDT != orig_dt)
500 _console <<
"Limiting dt to match function point. dt = ";
502 _console <<
"Limiting dt to limit change in function. dt = ";
511 const unsigned int growth_outer_its(
522 if (allowToGrow && (
_outer_its < growth_outer_its &&
_l_its < growth_l_its))
528 _console <<
"Growing dt: " + ite_type +
" its = " <<
_outer_its <<
" < " << growth_outer_its
529 <<
" && lin its = " <<
_l_its <<
" < " << growth_l_its <<
" old dt: " << std::setw(9)
530 <<
_dt_old <<
" new dt: " << std::setw(9) << dt <<
'\n';
532 else if (allowToShrink && (
_outer_its > shrink_outer_its ||
_l_its > shrink_l_its))
538 _console <<
"Shrinking dt: " + ite_type +
" its = " <<
_outer_its <<
" > " << shrink_outer_its
539 <<
" || lin its = " <<
_l_its <<
" > " << shrink_l_its <<
" old dt: " << std::setw(9)
540 <<
_dt_old <<
" new dt: " << std::setw(9) << dt <<
'\n';
556 _console <<
"Growing dt to recover from cutback. " 557 <<
" old dt: " << std::setw(9) <<
_dt_old <<
" new dt: " << std::setw(9) << dt
607 _console <<
"Sync point hit in current step, using previous dt for old dt: " << std::setw(9)
std::optional< Real > _dt_from_reject
Timestep used to reject a timestep, used to constrain the next attempt.
TransientBase & _executioner
Reference to transient executioner.
static InputParameters validParams()
Real & _timestep_tolerance
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
unsigned int nLinearIterations() const
Return the number of linear iterations.
Function base which provides a piecewise approximation to a specified (x,y) point data set...
virtual Real & dtOld() const
Real computeInterpolationDT()
virtual std::size_t numNonlinearSystems() const override
const Real & _cutback_factor
cut the timestep by by this factor
bool atSyncPoint()
Is the current step at a sync point (sync times, time interval, target time, etc)?
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
Computes time step size after the initial time 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
Computes time step size for the initial time step.
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.
unsigned int nLinearIterations() const
Return the number of linear iterations.
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
Computes time step size after a failed time step.
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 ...
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)
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.
Real unconstrainedDT()
Get the unconstrained dt.
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
LinearSystem & getLinearSystem(unsigned int sys_num)
Get non-constant reference to a linear system.
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.
unsigned int & _outer_its
Number of outer solver iterations in previous solve.
virtual void preExecute()
virtual void rejectStep()
This gets called when time step is rejected.
IntRange< T > make_range(T beg, T end)
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.
virtual std::size_t numLinearSystems() const override
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.