29#include "libmesh/implicit_system.h"
30#include "libmesh/nonlinear_implicit_system.h"
31#include "libmesh/transient_system.h"
32#include "libmesh/numeric_vector.h"
46 params.
addParam<Real>(
"steady_state_tolerance",
48 "Whenever the relative residual changes by less "
49 "than this the solution will be considered to be "
53 "Whether to check the auxiliary system for convergence to steady-state. If "
54 "false, then the solution vector from the solver system is used.");
56 "normalize_solution_diff_norm_by_dt",
58 "Whether to divide the solution difference norm by dt. If taking 'small' "
59 "time steps you probably want this to be true. If taking very 'large' timesteps in an "
60 "attempt to *reach* a steady-state, you probably want this parameter to be false.");
62 params.
addParamNamesToGroup(
"steady_state_tolerance check_aux normalize_solution_diff_norm_by_dt",
63 "Steady State Detection");
76 std::vector<Real> sync_times(1);
77 sync_times[0] = -std::numeric_limits<Real>::max();
84 MooseEnum schemes(
"implicit-euler explicit-euler crank-nicolson bdf2 explicit-midpoint dirk "
85 "explicit-tvd-rk-2 newmark-beta",
88 params.
addParam<Real>(
"start_time", 0.0,
"The start time of the simulation");
89 params.
addParam<Real>(
"end_time", 1.0e30,
"The end time of the simulation");
90 params.
addParam<Real>(
"dt", 1.,
"The timestep size between solves");
91 params.
addParam<Real>(
"dtmin", 1.0e-12,
"The minimum timestep size in an adaptive run");
92 params.
addParam<Real>(
"dtmax", 1.0e30,
"The maximum timestep size in an adaptive run");
94 "reset_dt",
false,
"Use when restarting a calculation to force a change in dt.");
95 params.
addParam<
unsigned int>(
"num_steps",
96 std::numeric_limits<unsigned int>::max(),
97 "The number of timesteps in a transient run");
98 params.
addParam<
int>(
"n_startup_steps", 0,
"The number of timesteps during startup");
101 "steady_state_detection",
false,
"Whether or not to check for steady state conditions");
103 "steady_state_convergence",
104 "Name of the Convergence object to use to assess whether the solution has reached a steady "
105 "state. If not provided, a default Convergence will be constructed internally from the "
106 "executioner parameters.");
108 "steady_state_start_time",
110 "Minimum amount of time to run before checking for steady state conditions.");
112 params.
addParam<std::vector<std::string>>(
"time_periods",
"The names of periods");
113 params.
addParam<std::vector<Real>>(
"time_period_starts",
"The start times of time periods");
114 params.
addParam<std::vector<Real>>(
"time_period_ends",
"The end times of time periods");
116 "abort_on_solve_fail",
false,
"abort if solve not converged rather than cut timestep");
120 "Throw error when timestep is less than dtmin instead of just aborting solve.");
122 params.
addParam<Real>(
"timestep_tolerance",
124 "the tolerance setting for final timestep size and sync times");
126 params.
addParam<
bool>(
"use_multiapp_dt",
128 "If true then the dt for the simulation will be "
129 "chosen by the MultiApps. If false (the "
130 "default) then the minimum over the master dt "
131 "and the MultiApps is used");
134 "steady_state_detection steady_state_convergence steady_state_start_time",
135 "Steady State Detection");
138 "abort_on_solve_fail timestep_tolerance use_multiapp_dt",
141 params.
addParamNamesToGroup(
"time_periods time_period_starts time_period_ends",
"Time Periods");
144 params.
set<
bool>(
"_supports_test_restep") =
true;
151 _problem(_fe_problem),
152 _aux(_fe_problem.getAuxiliarySystem()),
153 _time_scheme(getParam<
MooseEnum>(
"scheme").getEnum<
Moose::TimeIntegratorType>()),
154 _time_stepper(nullptr),
155 _t_step(_problem.timeStep()),
156 _time(_problem.time()),
157 _time_old(_problem.timeOld()),
158 _time_older(_problem.timeOlder()),
160 _dt_old(_problem.dtOld()),
161 _unconstrained_dt(declareRecoverableData<Real>(
"unconstrained_dt", -1)),
162 _at_sync_point(declareRecoverableData<bool>(
"at_sync_point", false)),
163 _last_solve_converged(declareRecoverableData<bool>(
"last_solve_converged", true)),
164 _xfem_repeat_step(false),
165 _end_time(getParam<Real>(
"end_time")),
166 _dtmin(getParam<Real>(
"dtmin")),
167 _dtmax(getParam<Real>(
"dtmax")),
168 _num_steps(getParam<unsigned
int>(
"num_steps")),
169 _n_startup_steps(getParam<
int>(
"n_startup_steps")),
170 _steady_state_detection(getParam<bool>(
"steady_state_detection")),
171 _steady_state_start_time(getParam<Real>(
"steady_state_start_time")),
172 _sync_times(_app.getOutputWarehouse().getSyncTimes()),
173 _abort(getParam<bool>(
"abort_on_solve_fail")),
174 _error_on_dtmin(getParam<bool>(
"error_on_dtmin")),
175 _time_interval(declareRecoverableData<bool>(
"time_interval", false)),
176 _start_time(getParam<Real>(
"start_time")),
177 _timestep_tolerance(getParam<Real>(
"timestep_tolerance")),
178 _target_time(declareRecoverableData<Real>(
"target_time", -
std::numeric_limits<Real>::max())),
179 _use_multiapp_dt(getParam<bool>(
"use_multiapp_dt")),
180 _testing_restep(false)
223 std::stringstream msg;
226 <<
" (whichever happens first)";
231 mooseInfo(msg.str(),
" will be forcefully retried due to --test-restep.");
235 "A timestep is not being retried with --test-restep because Problem/solve=false.\n\nTo "
236 "avoid this test being ran, you could set `restep = false` in the test specification.");
267 "Internal error in TransientBase executioner: _t_step is equal to 0 while recovering "
292 mooseError(
"Time stepper computed zero time step size on initial which is not allowed.\n"
293 "1. If you are using an existing time stepper, double check the values in your "
294 "input file or report an error.\n"
295 "2. If you are developing a new time stepper, make sure that initial time step "
296 "size in your code is computed correctly.");
298 for (
auto & ti : tis)
355 TIME_SECTION(
"final", 1,
"Executing Final Objects");
371 " was never retried because the simulation did not get to this timestep.\n\nTo "
372 "support restep testing, specify `num_steps` in the input.\nOtherwise, set "
373 "`restep = false` in this test specification.");
397#ifdef LIBMESH_ENABLE_AMR
406 bool advance_problem_state =
true;
408 for (
auto & ti : tis)
411 if (ti->advancesProblemState())
413 advance_problem_state =
false;
417 if (advance_problem_state)
419 else if (tis.size() > 1)
420 mooseError(
"Either there must be a single time integrator which advances state or none of "
421 "the time integrators should advance state.");
476 else if (input_dt == -1.0)
502 mooseInfo(
"Aborting and retrying solve for timestep ",
_t_step,
" due to --test-restep");
513 _console <<
"Aborting as solve did not converge" << std::endl;
535 if (input_time == -1.0)
548 for (
auto & ti : tis)
575 std::ostringstream diag;
583 diag <<
"Timestep < n_startup_steps, using old dt: " << std::setw(9) << std::setprecision(6)
584 << std::setfill(
'0') << std::showpoint << std::left <<
_dt <<
" tstep: " <<
_t_step
590 _console << diag.str() << std::flush;
604 diag <<
"Limiting dt for time interval output at time: " << std::setw(9) << std::setprecision(6)
606 <<
" dt: " << std::setw(9) << std::setprecision(6) << std::setfill(
'0') << std::showpoint
607 << std::left << dt_cur << std::endl;
617 diag <<
"Limiting dt for target time: " << std::setw(9) << std::setprecision(6)
619 <<
" dt: " << std::setw(9) << std::setprecision(6) << std::setfill(
'0') << std::showpoint
620 << std::left << dt_cur << std::endl;
630 _console << diag.str() << std::flush;
637 std::ostringstream & diag,
643 dt_cur = multi_app_dt;
645 diag <<
"Limiting dt for MultiApps on " << execute_on.
name() <<
": " << std::setw(9)
646 << std::setprecision(6) << std::setfill(
'0') << std::showpoint << std::left << dt_cur
672 _console <<
"Steady-State Solution Achieved at time: " <<
_time << std::endl;
688 _console <<
"Aborting as solve did not converge and input selected to abort" << std::endl;
693 _console <<
"Aborting as timestep already at or below dtmin" << std::endl;
733 mooseError(
"You cannot specify time_scheme in the Executioner and independently add a "
734 "TimeIntegrator to the system at the same time");
740 using namespace Moose;
744 case TI_IMPLICIT_EULER:
745 ti_str =
"ImplicitEuler";
747 case TI_EXPLICIT_EULER:
748 ti_str =
"ExplicitEuler";
750 case TI_CRANK_NICOLSON:
751 ti_str =
"CrankNicolson";
756 case TI_EXPLICIT_MIDPOINT:
757 ti_str =
"ExplicitMidpoint";
759 case TI_LSTABLE_DIRK2:
760 ti_str =
"LStableDirk2";
762 case TI_EXPLICIT_TVD_RK_2:
763 ti_str =
"ExplicitTVDRK2";
765 case TI_NEWMARK_BETA:
766 ti_str =
"NewmarkBeta";
784 return demangle(
typeid(ts).
name());
787 return std::string();
790std::vector<std::string>
795 mooseError(
"Time integrator has not been built yet so we can't retrieve its name");
797 std::vector<std::string> ret;
798 for (
const auto & ti : tis)
800 const auto & sys = ti->getCheckedPointerParam<
SystemBase *>(
"_sys")->system();
801 const auto & uvars = ti->getParam<std::vector<VariableName>>(
"variables");
803 std::vector<VariableName>
vars;
804 for (
const auto & var : uvars)
805 if (sys.has_variable(var))
808 if (!uvars.empty() &&
vars.empty())
814 const std::string var_prefix = MooseUtils::join(
vars,
", ");
815 const bool both = !sys_prefix.empty() && !var_prefix.empty();
816 ret.push_back(
"[" + sys_prefix + (both ?
" (" :
"") + var_prefix + (both ?
")" :
"") +
"]:");
819 ret.push_back(ti->type());
835 const auto status = convergence.checkConvergence(
_t_step);
839 "The steady-state Convergence object (", convergence.name(),
") reported divergence.");
const ExecFlagType EXEC_PRE_MULTIAPP_SETUP
const ExecFlagType EXEC_MULTIAPP_FIXED_POINT_END
const ExecFlagType EXEC_TIMESTEP_END
const ExecFlagType EXEC_TIMESTEP_BEGIN
const ExecFlagType EXEC_INITIAL
const ExecFlagType EXEC_MULTIAPP_FIXED_POINT_BEGIN
const ExecFlagType EXEC_FINAL
void ErrorVector unsigned int
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
virtual void checkIterationType(IterationType) const
Perform checks related to the iteration type.
Executioners are objects that do the actual work of solving your problem.
static InputParameters validParams()
FEProblemBase & _fe_problem
std::unique_ptr< FixedPointSolve > _fixed_point_solve
const bool & _verbose
True if printing out additional information.
const ConvergenceName & getSteadyStateConvergenceName() const
Gets the steady-state detection convergence object name.
bool haveXFEM()
Find out whether the current analysis is using XFEM.
virtual std::size_t numSolverSystems() const override
virtual void addTimeIntegrator(const std::string &type, const std::string &name, InputParameters ¶meters)
void incrementMultiAppTStep(ExecFlagType type)
Advance the MultiApps t_step (incrementStepOrReject) associated with the ExecFlagType.
void setSteadyStateConvergenceName(const ConvergenceName &convergence_name)
Sets the steady-state detection convergence object name if there is one.
void parentOutputPositionChanged()
Calls parentOutputPositionChanged() on all sub apps.
virtual void advanceState()
Advance all of the state holding vectors / datastructures so that we can move to the next timestep.
virtual void postExecute()
Method called at the end of the simulation.
Real computeMultiAppsDT(ExecFlagType type)
Find the smallest timestep over all MultiApps.
virtual Convergence & getConvergence(const std::string &name, const THREAD_ID tid=0) const
Gets a Convergence object.
virtual void transient(bool trans)
void restoreMultiApps(ExecFlagType type, bool force=false)
Restore the MultiApps associated with the ExecFlagType.
bool execMultiApps(ExecFlagType type, bool auto_advance=true)
Execute the MultiApps associated with the ExecFlagType.
void timestepSetup() override
virtual void computeIndicators()
virtual void onTimestepBegin() override
virtual void execute(const ExecFlagType &exec_type)
Convenience function for performing execution of MOOSE systems.
void finishMultiAppStep(ExecFlagType type, bool recurse_through_multiapp_levels=false)
Finish the MultiApp time step (endStep, postStep) associated with the ExecFlagType.
bool hasTimeIntegrator() const
Returns whether or not this Problem has a TimeIntegrator.
virtual void computeMarkers()
void initialSetup() override
virtual void outputStep(ExecFlagType type)
Output the current step.
void setNeedToAddDefaultSteadyStateConvergence()
Sets _need_to_add_default_steady_state_convergence to true.
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
void setStartTime(Real time)
Set the starting time for the simulation.
bool testReStep() const
Whether or not this simulation should fail a timestep and repeat (for testing).
bool hasStartTime() const
bool isRestarting() const
Whether or not this is a "restart" calculation.
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
bool isRecovering() const
Whether or not this is a "recover" calculation.
bool testCheckpointHalfTransient() const
Whether or not this simulation should only run half its transient (useful for testing recovery)
Real getStartTime() const
const InputParameters & parameters() const
Get the parameters of the object.
const std::string & name() const
Get the name of the class.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
const InputParameters & _pars
The object's parameters.
void mooseInfo(Args &&... args) const
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Class for containing MooseEnum item information.
const std::string & name() const
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
MooseApp & _app
The MOOSE application this is associated with.
virtual bool isSolveTerminationRequested() const
Check of termination has been requested.
Base class for a system (of equations)
Base class for time stepping.
virtual bool converged() const
If the time step converged.
virtual void init()
Initialize the time stepper.
virtual void postExecute()
virtual void rejectStep()
This gets called when time step is rejected.
virtual void acceptStep()
This gets called when time step is accepted.
virtual void preExecute()
virtual void step()
Take a time step.
void computeStep()
Called before a new step is started.
virtual bool constrainStep(Real &dt)
Called after computeStep() is called.
Real getCurrentDT()
Get the current_dt.
bool _testing_restep
Whether or not the last timestep we solved is being repeated with –test-restep.
TransientBase(const InputParameters ¶meters)
bool & _last_solve_converged
Whether or not the last solve converged.
std::optional< Real > _test_restep_time
If the time is greater than this then we fail and repeat if –test-restep is enabled.
void setTimeStepper(TimeStepper &ts)
Set the timestepper to use.
virtual void incrementStepOrReject()
This is where the solve step is actually incremented.
FEProblemBase & _problem
Here for backward compatibility.
Real _time_interval_output_interval
virtual Real relativeSolutionDifferenceNorm(bool check_aux) const =0
The relative L2 norm of the difference between solution and old solution vector.
virtual void takeStep(Real input_dt=-1.0)
Do whatever is necessary to advance one step.
static InputParameters defaultSteadyStateConvergenceParams()
Real & _time_old
Previous time.
TimeStepper * getTimeStepper()
Pointer to the TimeStepper.
virtual std::set< TimeIntegrator * > getTimeIntegrators() const =0
Get the time integrators (time integration scheme) used Note that because some systems might be stead...
virtual bool lastSolveConverged() const override
Whether or not the last solve converged.
void setupTimeIntegrator()
Real & _time
Current time.
const bool _error_on_dtmin
This parameter controls how the system will deal with _dt <= _dtmin If true, the time stepper is expe...
virtual void endStep(Real input_time=-1.0)
Moose::TimeIntegratorType _time_scheme
void constrainDTFromMultiApp(Real &dt_cur, std::ostringstream &diag, const ExecFlagType &execute_on) const
Constrain the timestep dt_cur by looking at the timesteps for the MultiApps on execute_on.
virtual Real computeConstrainedDT()
Real & _time_older
The time two steps back, kept so that functors can be evaluated at the older solution.
virtual void execute() override
Pure virtual execute function MUST be overridden by children classes.
virtual bool keepGoing()
Transient loop will continue as long as this keeps returning true.
bool convergedToSteadyState() const
Determines whether the problem has converged to steady state.
virtual void preExecute() override
Override this for actions that should take place before execution.
bool _xfem_repeat_step
Whether step should be repeated due to xfem modifying the mesh.
const bool _steady_state_detection
Steady state detection variables:
void parentOutputPositionChanged() override
Can be used by subclasses to call parentOutputPositionChanged() on the underlying FEProblemBase.
TimeStepper * _time_stepper
static InputParameters validParams()
virtual void init() override
Initialize the executioner.
virtual void setTargetTime(Real target_time)
Can be used to set the next "target time" which is a time to nail perfectly.
std::optional< int > _test_restep_step
The timestep we fail and repeat if –test-restep is enabled.
virtual std::string getTimeStepperName() const override
Get the name of the timestepper.
const Real _steady_state_start_time
Real computeSolutionChangeNorm(bool check_aux, bool normalize_by_dt) const
Compute the relative L2 norm of the change in the solution.
int & _t_step
Current timestep.
bool & _time_interval
if to use time interval output
virtual void estimateTimeError()
virtual void postExecute() override
Override this for actions that should take place after execution.
virtual std::vector< std::string > getTimeIntegratorNames() const override
Get the name of the time integrator (time integration scheme) used.
Real & _dt
Current delta t... or timestep size.
Real _next_interval_output_time
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...