Loading [MathJax]/extensions/tex2jax.js
www.mooseframework.org
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
TimeStepper.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "TimeStepper.h"
11 #include "FEProblem.h"
12 #include "Transient.h"
13 #include "MooseApp.h"
14 
16 
19 {
21  params.addParam<bool>(
22  "reset_dt", false, "Use when restarting a calculation to force a change in dt.");
23  params.addRangeCheckedParam<Real>(
24  "cutback_factor_at_failure",
25  0.5,
26  "cutback_factor_at_failure>0 & cutback_factor_at_failure<1",
27  "Factor to apply to timestep if it a time step fails to convergence.");
28 
29  params.registerBase("TimeStepper");
30 
31  return params;
32 }
33 
35  : MooseObject(parameters),
36  Restartable(this, "TimeSteppers"),
37  ScalarCoupleable(this),
38  _fe_problem(parameters.have_parameter<FEProblemBase *>("_fe_problem_base")
39  ? *getParam<FEProblemBase *>("_fe_problem_base")
40  : *getParam<FEProblem *>("_fe_problem")),
41  _executioner(*getCheckedPointerParam<Transient *>("_executioner")),
42  _time(_fe_problem.time()),
43  _time_old(_fe_problem.timeOld()),
44  _t_step(_fe_problem.timeStep()),
45  _dt(_fe_problem.dt()),
46  _dt_min(_executioner.dtMin()),
47  _dt_max(_executioner.dtMax()),
48  _end_time(_executioner.endTime()),
49  _sync_times(_app.getOutputWarehouse().getSyncTimes()),
50  _timestep_tolerance(_executioner.timestepTol()),
51  _verbose(_executioner.verbose()),
52  _converged(true),
53  _cutback_factor_at_failure(getParam<Real>("cutback_factor_at_failure")),
54  _reset_dt(getParam<bool>("reset_dt")),
55  _has_reset_dt(false),
56  _current_dt(declareRestartableData("current_dt", 1.0))
57 {
58 }
59 
61 
62 void
64 {
65 }
66 
67 void
69 {
70  // Delete all sync times that are at or before the begin time
71  while (!_sync_times.empty() && _time + _timestep_tolerance >= *_sync_times.begin())
72  _sync_times.erase(_sync_times.begin());
73 }
74 
75 void
77 {
78  if (_t_step < 2 || (_reset_dt && !_has_reset_dt))
79  {
80  _has_reset_dt = true;
81 
82  if (converged())
84  else
86  }
87  else
88  {
89  if (converged())
91  else
93  }
94 }
95 
96 bool
98 {
99  bool at_sync_point = false;
100 
101  std::ostringstream diag;
102 
103  // Don't let the time step size exceed maximum time step size
104  if (dt > _dt_max)
105  {
106  dt = _dt_max;
107  diag << "Limiting dt to dtmax: " << std::setw(9) << std::setprecision(6) << std::setfill('0')
108  << std::showpoint << std::left << _dt_max << std::endl;
109  }
110 
111  // Don't allow time step size to be smaller than minimum time step size
112  if (dt < _dt_min)
113  {
114  dt = _dt_min;
115  diag << "Increasing dt to dtmin: " << std::setw(9) << std::setprecision(6) << std::setfill('0')
116  << std::showpoint << std::left << _dt_min << std::endl;
117  }
118 
119  // Don't let time go beyond simulation end time (unless we're doing a half transient)
120  if (_time + dt > _end_time && !_app.halfTransient())
121  {
122  dt = _end_time - _time;
123  diag << "Limiting dt for end_time: " << std::setw(9) << std::setprecision(6)
124  << std::setfill('0') << std::showpoint << std::left << _end_time << " dt: " << std::setw(9)
125  << std::setprecision(6) << std::setfill('0') << std::showpoint << std::left << dt
126  << std::endl;
127  }
128 
129  // Adjust to a sync time if supplied
130  if (!_sync_times.empty() && _time + dt + _timestep_tolerance >= (*_sync_times.begin()))
131  {
132  dt = *_sync_times.begin() - _time;
133  diag << "Limiting dt for sync_time: " << std::setw(9) << std::setprecision(6)
134  << std::setfill('0') << std::showpoint << std::left << *_sync_times.begin()
135  << " dt: " << std::setw(9) << std::setprecision(6) << std::setfill('0') << std::showpoint
136  << std::left << dt << std::endl;
137 
138  if (dt <= 0.0)
139  {
140  _console << diag.str();
141  mooseError("Adjusting to sync_time resulted in a non-positive time step. dt: ",
142  dt,
143  " sync_time: ",
144  *_sync_times.begin(),
145  " time: ",
146  _time);
147  }
148 
149  at_sync_point = true;
150  }
151 
152  if (_verbose)
153  {
154  _console << diag.str();
155  }
156 
157  return at_sync_point;
158 }
159 
160 void
162 {
164 }
165 
166 void
168 {
169  // If there are sync times at or before the current time, delete them
170  while (!_sync_times.empty() && _time + _timestep_tolerance >= *_sync_times.begin())
171  {
172  _sync_times.erase(_sync_times.begin());
173  }
174 }
175 
176 void
178 {
180 }
181 
182 bool
184 {
185  return _converged;
186 }
187 
188 Real
190 {
191  if (_dt <= _dt_min)
192  mooseError("Solve failed and timestep already at or below dtmin, cannot continue!");
193 
194  // cut the time step
197  else // (_cutback_factor_at_failure * _current_dt < _dt_min)
198  return _dt_min;
199 }
200 
201 void
203 {
204  _current_dt = dt;
205 }
Transient
Transient executioners usually loop through a number of timesteps...
Definition: Transient.h:30
MooseObject::validParams
static InputParameters validParams()
Definition: MooseObject.C:35
TimeStepper::_dt_max
Real & _dt_max
Definition: TimeStepper.h:131
FEProblemBase::restoreSolutions
virtual void restoreSolutions()
Definition: FEProblemBase.C:4771
FEProblem.h
TimeStepper::_dt
Real & _dt
Definition: TimeStepper.h:129
FEProblem
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Definition: FEProblem.h:24
MooseObject::mooseError
void mooseError(Args &&... args) const
Definition: MooseObject.h:141
TimeStepper::_time
Real & _time
Values from executioner.
Definition: TimeStepper.h:126
TimeStepper::_executioner
Transient & _executioner
Reference to transient executioner.
Definition: TimeStepper.h:123
MooseApp::halfTransient
bool halfTransient() const
Whether or not this simulation should only run half its transient (useful for testing recovery)
Definition: MooseApp.h:413
TimeStepper::_timestep_tolerance
Real & _timestep_tolerance
Definition: TimeStepper.h:135
TimeStepper::_sync_times
std::set< Real > & _sync_times
Definition: TimeStepper.h:133
TimeStepper::~TimeStepper
virtual ~TimeStepper()
Definition: TimeStepper.C:60
TimeStepper::computeStep
void computeStep()
Called before a new step is started.
Definition: TimeStepper.C:76
TimeStepper::constrainStep
virtual bool constrainStep(Real &dt)
Called after computeStep() is called.
Definition: TimeStepper.C:97
InputParameters::addParam
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object.
Definition: InputParameters.h:1198
TimeStepper::converged
virtual bool converged() const
If the time step converged.
Definition: TimeStepper.C:183
TimeStepper::_fe_problem
FEProblemBase & _fe_problem
Definition: TimeStepper.h:121
TimeStepper::_current_dt
Real & _current_dt
Size of the current time step as computed by the Stepper. Note that the actual dt that was taken migh...
Definition: TimeStepper.h:154
TimeStepper::TimeStepper
TimeStepper(const InputParameters &parameters)
Definition: TimeStepper.C:34
TimeStepper::_verbose
const bool & _verbose
should detailed diagnostic output be printed
Definition: TimeStepper.h:138
InputParameters::registerBase
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System.
Definition: InputParameters.C:330
ConsoleStreamInterface::_console
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
Definition: ConsoleStreamInterface.h:31
MooseObject
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:50
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
TimeStepper.h
TimeStepper::_cutback_factor_at_failure
const Real _cutback_factor_at_failure
Cutback factor if a time step fails to converge.
Definition: TimeStepper.h:144
TimeStepper::_has_reset_dt
bool _has_reset_dt
True if dt has been reset.
Definition: TimeStepper.h:150
ScalarCoupleable
Interface for objects that needs scalar coupling capabilities.
Definition: ScalarCoupleable.h:34
MooseApp.h
TimeStepper
Base class for time stepping.
Definition: TimeStepper.h:26
TimeStepper::computeDT
virtual Real computeDT()=0
Called to compute _current_dt for a normal step.
TimeStepper::_end_time
Real & _end_time
Definition: TimeStepper.h:132
Restartable
A class for creating restricted objects.
Definition: Restartable.h:29
TimeStepper::acceptStep
virtual void acceptStep()
This gets called when time step is accepted.
Definition: TimeStepper.C:167
PicardSolve::solve
virtual bool solve() override
Picard solve the FEProblem.
Definition: PicardSolve.C:115
TimeStepper::step
virtual void step()
Take a time step.
Definition: TimeStepper.C:161
InputParameters::addRangeCheckedParam
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
Definition: InputParameters.h:1245
TimeStepper::_converged
bool _converged
Whether or not the previous solve converged.
Definition: TimeStepper.h:141
Transient.h
TimeStepper::_dt_min
Real & _dt_min
Definition: TimeStepper.h:130
TimeStepper::forceTimeStep
virtual void forceTimeStep(Real dt)
Definition: TimeStepper.C:202
TimeStepper::_t_step
int & _t_step
Definition: TimeStepper.h:128
TimeStepper::rejectStep
virtual void rejectStep()
This gets called when time step is rejected.
Definition: TimeStepper.C:177
TimeStepper::validParams
static InputParameters validParams()
Definition: TimeStepper.C:18
FEProblemBase
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Definition: FEProblemBase.h:139
TimeStepper::_reset_dt
bool _reset_dt
If true then the next dt will be computed by computeInitialDT()
Definition: TimeStepper.h:147
TimeStepper::preExecute
virtual void preExecute()
Definition: TimeStepper.C:68
Executioner::picardSolve
PicardSolve & picardSolve()
Return underlining PicardSolve object.
Definition: Executioner.h:113
MooseObject::_app
MooseApp & _app
The MooseApp this object is associated with.
Definition: MooseObject.h:172
TimeStepper::init
virtual void init()
Initialize the time stepper.
Definition: TimeStepper.C:63
defineLegacyParams
defineLegacyParams(TimeStepper)
TimeStepper::computeInitialDT
virtual Real computeInitialDT()=0
Called to compute _current_dt for the first timestep.
TimeStepper::computeFailedDT
virtual Real computeFailedDT()
Called to compute _current_dt after a solve has failed.
Definition: TimeStepper.C:189