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" 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);
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",
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.");
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()),
154 _time_stepper(nullptr),
155 _t_step(_problem.timeStep()),
156 _time(_problem.time()),
157 _time_old(_problem.timeOld()),
159 _dt_old(_problem.dtOld()),
160 _unconstrained_dt(declareRecoverableData<
Real>(
"unconstrained_dt", -1)),
161 _at_sync_point(declareRecoverableData<bool>(
"at_sync_point", false)),
162 _last_solve_converged(declareRecoverableData<bool>(
"last_solve_converged", true)),
163 _xfem_repeat_step(false),
164 _end_time(getParam<
Real>(
"end_time")),
165 _dtmin(getParam<
Real>(
"dtmin")),
166 _dtmax(getParam<
Real>(
"dtmax")),
167 _num_steps(getParam<unsigned
int>(
"num_steps")),
168 _n_startup_steps(getParam<
int>(
"n_startup_steps")),
169 _steady_state_detection(getParam<bool>(
"steady_state_detection")),
170 _steady_state_start_time(getParam<
Real>(
"steady_state_start_time")),
171 _sync_times(_app.getOutputWarehouse().getSyncTimes()),
172 _abort(getParam<bool>(
"abort_on_solve_fail")),
173 _error_on_dtmin(getParam<bool>(
"error_on_dtmin")),
174 _time_interval(declareRecoverableData<bool>(
"time_interval", false)),
175 _start_time(getParam<
Real>(
"start_time")),
176 _timestep_tolerance(getParam<
Real>(
"timestep_tolerance")),
177 _target_time(declareRecoverableData<
Real>(
"target_time", -
std::numeric_limits<
Real>::
max())),
178 _use_multiapp_dt(getParam<bool>(
"use_multiapp_dt")),
179 _testing_restep(false)
222 std::stringstream msg;
225 <<
" (whichever happens first)";
230 mooseInfo(msg.str(),
" will be forcefully retried due to --test-restep.");
234 "A timestep is not being retried with --test-restep because Problem/solve=false.\n\nTo " 235 "avoid this test being ran, you could set `restep = false` in the test specification.");
266 "Internal error in TransientBase executioner: _t_step is equal to 0 while recovering " 291 mooseError(
"Time stepper computed zero time step size on initial which is not allowed.\n" 292 "1. If you are using an existing time stepper, double check the values in your " 293 "input file or report an error.\n" 294 "2. If you are developing a new time stepper, make sure that initial time step " 295 "size in your code is computed correctly.");
297 for (
auto & ti : tis)
354 TIME_SECTION(
"final", 1,
"Executing Final Objects");
370 " was never retried because the simulation did not get to this timestep.\n\nTo " 371 "support restep testing, specify `num_steps` in the input.\nOtherwise, set " 372 "`restep = false` in this test specification.");
396 #ifdef LIBMESH_ENABLE_AMR 404 bool advance_problem_state =
true;
406 for (
auto & ti : tis)
409 if (ti->advancesProblemState())
411 advance_problem_state =
false;
415 if (advance_problem_state)
417 else if (tis.size() > 1)
418 mooseError(
"Either there must be a single time integrator which advances state or none of " 419 "the time integrators should advance state.");
474 else if (input_dt == -1.0)
500 mooseInfo(
"Aborting and retrying solve for timestep ",
_t_step,
" due to --test-restep");
511 _console <<
"Aborting as solve did not converge" << std::endl;
533 if (input_time == -1.0)
546 for (
auto & ti : tis)
573 std::ostringstream diag;
581 diag <<
"Timestep < n_startup_steps, using old dt: " << std::setw(9) << std::setprecision(6)
582 << std::setfill(
'0') << std::showpoint << std::left <<
_dt <<
" tstep: " <<
_t_step 602 diag <<
"Limiting dt for time interval output at time: " << std::setw(9) << std::setprecision(6)
604 <<
" dt: " << std::setw(9) << std::setprecision(6) << std::setfill(
'0') << std::showpoint
605 << std::left << dt_cur << std::endl;
615 diag <<
"Limiting dt for target time: " << std::setw(9) << std::setprecision(6)
617 <<
" dt: " << std::setw(9) << std::setprecision(6) << std::setfill(
'0') << std::showpoint
618 << std::left << dt_cur << std::endl;
635 std::ostringstream & diag,
641 dt_cur = multi_app_dt;
643 diag <<
"Limiting dt for MultiApps on " << execute_on.
name() <<
": " << std::setw(9)
644 << std::setprecision(6) << std::setfill(
'0') << std::showpoint << std::left << dt_cur
670 _console <<
"Steady-State Solution Achieved at time: " <<
_time << std::endl;
686 _console <<
"Aborting as solve did not converge and input selected to abort" << std::endl;
691 _console <<
"Aborting as timestep already at or below dtmin" << std::endl;
731 mooseError(
"You cannot specify time_scheme in the Executioner and independently add a " 732 "TimeIntegrator to the system at the same time");
738 using namespace Moose;
743 ti_str =
"ImplicitEuler";
746 ti_str =
"ExplicitEuler";
749 ti_str =
"CrankNicolson";
755 ti_str =
"ExplicitMidpoint";
758 ti_str =
"LStableDirk2";
761 ti_str =
"ExplicitTVDRK2";
764 ti_str =
"NewmarkBeta";
785 return std::string();
788 std::vector<std::string>
793 mooseError(
"Time integrator has not been built yet so we can't retrieve its name");
795 std::vector<std::string> ret;
796 for (
const auto & ti : tis)
798 const auto & sys = ti->getCheckedPointerParam<
SystemBase *>(
"_sys")->system();
799 const auto & uvars = ti->getParam<std::vector<VariableName>>(
"variables");
801 std::vector<VariableName>
vars;
802 for (
const auto & var : uvars)
803 if (sys.has_variable(var))
806 if (!uvars.empty() &&
vars.empty())
813 const bool both = !sys_prefix.empty() && !var_prefix.empty();
814 ret.push_back(
"[" + sys_prefix + (both ?
" (" :
"") + var_prefix + (both ?
")" :
"") +
"]:");
817 ret.push_back(ti->type());
837 "The steady-state Convergence object (", convergence.name(),
") reported divergence.");
void setTimeStepper(TimeStepper &ts)
Set the timestepper to use.
virtual void preExecute() override
Override this for actions that should take place before execution.
void timestepSetup() override
std::string join(Iterator begin, Iterator end, const std::string &delimiter)
Python-like join function for strings over an iterator range.
virtual void postExecute() override
Override this for actions that should take place after execution.
void setNeedToAddDefaultSteadyStateConvergence()
Sets _need_to_add_default_steady_state_convergence to true.
const Real _steady_state_start_time
const std::string & name() const
virtual void estimateTimeError()
Real _time_interval_output_interval
virtual std::string getTimeStepperName() const override
Get the name of the timestepper.
virtual void postExecute()
Method called at the end of the simulation.
static InputParameters validParams()
virtual void endStep(Real input_time=-1.0)
void mooseInfo(Args &&... args) const
Real computeSolutionChangeNorm(bool check_aux, bool normalize_by_dt) const
Compute the relative L2 norm of the change in the solution.
void computeStep()
Called before a new step is started.
virtual void setTargetTime(Real target_time)
Can be used to set the next "target time" which is a time to nail perfectly.
std::optional< Real > _test_restep_time
If the time is greater than this then we fail and repeat if –test-restep is enabled.
void parentOutputPositionChanged()
Calls parentOutputPositionChanged() on all sub apps.
bool & _last_solve_converged
Whether or not the last solve converged.
virtual MooseConvergenceStatus checkConvergence(unsigned int iter)=0
Returns convergence status.
virtual void computeMarkers()
void setupTimeIntegrator()
std::optional< int > _test_restep_step
The timestep we fail and repeat if –test-restep is enabled.
const bool _error_on_dtmin
This parameter controls how the system will deal with _dt <= _dtmin If true, the time stepper is expe...
const bool & _verbose
True if printing out additional information.
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Base class for time stepping.
void setSteadyStateConvergenceName(const ConvergenceName &convergence_name)
Sets the steady-state detection convergence object name if there is one.
const ExecFlagType EXEC_MULTIAPP_FIXED_POINT_END
void finishMultiAppStep(ExecFlagType type, bool recurse_through_multiapp_levels=false)
Finish the MultiApp time step (endStep, postStep) associated with the ExecFlagType.
Real & _time
Current time.
virtual void postExecute()
virtual bool constrainStep(Real &dt)
Called after computeStep() is called.
bool haveXFEM()
Find out whether the current analysis is using XFEM.
const ExecFlagType EXEC_TIMESTEP_END
virtual void execute() override
Pure virtual execute function MUST be overridden by children classes.
Real getStartTime() const
virtual bool converged() const
If the time step converged.
virtual std::set< TimeIntegrator * > getTimeIntegrators() const =0
Get the time integrators (time integration scheme) used Note that because some systems might be stead...
Base class for a system (of equations)
bool isRestarting() const
Whether or not this is a "restart" calculation.
bool convergedToSteadyState() const
Determines whether the problem has converged to steady state.
virtual const std::string & name() const
Get the name of the class.
Real computeMultiAppsDT(ExecFlagType type)
Find the smallest timestep over all MultiApps.
TimeStepper * _time_stepper
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
auto max(const L &left, const R &right)
virtual bool isSolveTerminationRequested() const
Check of termination has been requested.
virtual Real computeConstrainedDT()
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
FEProblemBase & _problem
Here for backward compatibility.
virtual void advanceState()
Advance all of the state holding vectors / datastructures so that we can move to the next timestep...
virtual void execute(const ExecFlagType &exec_type)
Convenience function for performing execution of MOOSE systems.
virtual std::vector< std::string > getTimeIntegratorNames() const override
Get the name of the time integrator (time integration scheme) used.
TransientBase(const InputParameters ¶meters)
const ConvergenceName & getSteadyStateConvergenceName() const
Gets the steady-state detection convergence object name.
virtual bool keepGoing()
Transient loop will continue as long as this keeps returning true.
virtual void acceptStep()
This gets called when time step is accepted.
TimeStepper * getTimeStepper()
Pointer to the TimeStepper.
static InputParameters validParams()
virtual Convergence & getConvergence(const std::string &name, const THREAD_ID tid=0) const
Gets a Convergence object.
const ExecFlagType EXEC_TIMESTEP_BEGIN
const bool _steady_state_detection
Steady state detection variables:
const ExecFlagType EXEC_PRE_MULTIAPP_SETUP
bool & _time_interval
if to use time interval output
bool hasTimeIntegrator() const
Returns whether or not this Problem has a TimeIntegrator.
virtual void takeStep(Real input_dt=-1.0)
Do whatever is necessary to advance one step.
virtual void computeIndicators()
Real & _time_old
Previous time.
void initialSetup() override
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Real & _dt
Current delta t... or timestep size.
Executioners are objects that do the actual work of solving your problem.
virtual void addTimeIntegrator(const std::string &type, const std::string &name, InputParameters ¶meters)
bool testReStep() const
Whether or not this simulation should fail a timestep and repeat (for testing).
bool testCheckpointHalfTransient() const
Whether or not this simulation should only run half its transient (useful for testing recovery) ...
virtual void checkIterationType(IterationType) const
Perform checks related to the iteration type.
bool _xfem_repeat_step
Whether step should be repeated due to xfem modifying the mesh.
MooseApp & _app
The MOOSE application this is associated with.
std::string demangle(const char *name)
bool _testing_restep
Whether or not the last timestep we solved is being repeated with –test-restep.
virtual Real relativeSolutionDifferenceNorm(bool check_aux) const =0
The relative L2 norm of the difference between solution and old solution vector.
virtual void init() override
Initialize the executioner.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Class for containing MooseEnum item information.
Moose::TimeIntegratorType _time_scheme
const ExecFlagType EXEC_MULTIAPP_FIXED_POINT_BEGIN
void restoreMultiApps(ExecFlagType type, bool force=false)
Restore the MultiApps associated with the ExecFlagType.
bool hasStartTime() const
virtual void onTimestepBegin() override
static InputParameters defaultSteadyStateConvergenceParams()
virtual void preExecute()
virtual void rejectStep()
This gets called when time step is rejected.
void incrementMultiAppTStep(ExecFlagType type)
Advance the MultiApps t_step (incrementStepOrReject) associated with the ExecFlagType.
virtual void transient(bool trans)
virtual void incrementStepOrReject()
This is where the solve step is actually incremented.
TimeIntegratorType
Time integrators.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & _pars
Parameters of this object, references the InputParameters stored in the InputParametersWarehouse.
virtual void step()
Take a time step.
const InputParameters & parameters() const
Get the parameters of the object.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
virtual bool lastSolveConverged() const override
Whether or not the last solve converged.
bool execMultiApps(ExecFlagType type, bool auto_advance=true)
Execute the MultiApps associated with the ExecFlagType.
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.
bool isRecovering() const
Whether or not this is a "recover" calculation.
virtual void init()
Initialize the time stepper.
virtual std::size_t numSolverSystems() const override
const ExecFlagType EXEC_FINAL
Real getCurrentDT()
Get the current_dt.
void ErrorVector unsigned int
std::unique_ptr< FixedPointSolve > _fixed_point_solve
virtual void outputStep(ExecFlagType type)
Output the current step.
int & _t_step
Current timestep.
Real _next_interval_output_time
void setStartTime(Real time)
Set the starting time for the simulation.
void parentOutputPositionChanged() override
Can be used by subclasses to call parentOutputPositionChanged() on the underlying FEProblemBase...
FEProblemBase & _fe_problem
const ExecFlagType EXEC_INITIAL