www.mooseframework.org
TimeSequenceStepperBase.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
16 #include "FEProblem.h"
17 #include "Transient.h"
18 
19 template <>
22 {
24  return params;
25 }
26 
28  : TimeStepper(parameters),
29  _current_step(declareRestartableData("current_step", (unsigned int)0)),
30  _time_sequence(declareRestartableData<std::vector<Real>>("time_sequence"))
31 {
32 }
33 
34 void
35 TimeSequenceStepperBase::setupSequence(const std::vector<Real> & times)
36 {
37  // In case of half transient, transient's end time needs to be reset to
38  // be able to imprint TimeSequenceStepperBase's end time
39  if (_app.halfTransient())
40  _executioner.endTime() *= 2.0;
41 
42  // only set up _time_sequence if the app is _not_ recovering
43  if (!_app.isRecovering())
44  {
45  // also we need to do something different when restarting
46  if (!_app.isRestarting())
47  {
48  // sync _executioner.startTime and endTime with _time_sequence
49  Real start_time = _executioner.getStartTime();
50  Real end_time = _executioner.endTime();
51 
52  // make sure time sequence is in ascending order
53  for (unsigned int j = 0; j < times.size() - 1; ++j)
54  if (times[j + 1] <= times[j])
55  mooseError("time_sequence must be in ascending order.");
56 
57  _time_sequence.push_back(start_time);
58  for (unsigned int j = 0; j < times.size(); ++j)
59  {
60  if (times[j] > start_time && times[j] < end_time)
61  _time_sequence.push_back(times[j]);
62  }
63  _time_sequence.push_back(end_time);
64  }
65  else
66  {
67  // in case of restart it should be allowed to modify _time_sequence if it follows the
68  // following rule:
69  // all times up to _current_step are identical
70  // 1. start time cannot be modified
71  // 2. the entries in _time_sequence and times must be equal up to entry with index
72  // _current_step
73 
75  mooseError("Timesequencestepper does not allow the start time to be modified.");
76 
77  // sync _executioner.endTime with _time_sequence
78  Real end_time = _executioner.endTime();
79 
80  // make sure time sequence is in ascending order
81  for (unsigned int j = 0; j < times.size() - 1; ++j)
82  if (times[j + 1] <= times[j])
83  mooseError("time_sequence must be in ascending order.");
84 
85  // save the restarted time_sequence
86  std::vector<Real> saved_time_sequence = _time_sequence;
87  _time_sequence.clear();
88 
89  // step 1: fill in the entries up to _current_step
90  for (unsigned int j = 0; j <= _current_step; ++j)
91  {
92  if (!MooseUtils::absoluteFuzzyEqual(times[j], saved_time_sequence[j]))
93  mooseError("The timesequence provided in the restart file must be identical to "
94  "the one in the old file up to entry number ",
95  _current_step + 1,
96  " = ",
97  saved_time_sequence[_current_step]);
98 
99  _time_sequence.push_back(saved_time_sequence[j]);
100  }
101 
102  // step 2: fill in the entries up after _current_step
103  for (unsigned int j = _current_step + 1; j < times.size(); ++j)
104  {
105  if (times[j] < end_time)
106  _time_sequence.push_back(times[j]);
107  }
108  _time_sequence.push_back(end_time);
109  }
110  }
111 
112  if (_app.halfTransient())
113  {
114  unsigned int half = (_time_sequence.size() - 1) / 2;
116  }
117 }
118 
119 void
121 {
123  if (converged())
124  _current_step++;
125 }
126 
127 Real
129 {
130  return computeDT();
131 }
132 
133 Real
135 {
137 }
138 
139 Real
141 {
142  if (computeDT() <= _dt_min)
143  mooseError("Solve failed and timestep already at or below dtmin, cannot continue!");
144 
145  // cut the time step in a half if possible
146  Real dt = 0.5 * computeDT();
147  if (dt < _dt_min)
148  dt = _dt_min;
149  _time_sequence.insert(_time_sequence.begin() + _current_step + 1,
151  return computeDT();
152 }
bool isRecovering() const
Whether or not this is a "recover" calculation.
Definition: MooseApp.C:608
virtual Real computeFailedDT() override
Called to compute _current_dt after a solve has failed.
unsigned int & _current_step
the step that the time stepper is currently at
Base class for time stepping.
Definition: TimeStepper.h:31
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
TimeSequenceStepperBase(const InputParameters &parameters)
Transient & _executioner
Reference to transient executioner.
Definition: TimeStepper.h:126
bool halfTransient()
Whether or not this simulation should only run half its transient (useful for testing recovery) ...
Definition: MooseApp.h:339
void setupSequence(const std::vector< Real > &times)
Real getStartTime()
Return the start time.
Definition: Transient.h:166
std::vector< Real > & _time_sequence
stores the sequence of time points
virtual Real computeDT() override
Called to compute _current_dt for a normal step.
InputParameters validParams< TimeStepper >()
Definition: TimeStepper.C:22
Real & endTime()
Get the end time.
Definition: Transient.h:172
virtual Real computeInitialDT() override
Called to compute _current_dt for the first timestep.
MooseApp & _app
The MooseApp this object is associated with.
Definition: MooseObject.h:108
Real & _dt_min
Definition: TimeStepper.h:133
virtual void step() override
Take a time step.
InputParameters validParams< TimeSequenceStepperBase >()
virtual void step()
Take a time step.
Definition: TimeStepper.C:158
virtual bool converged()
If the time step converged.
Definition: TimeStepper.C:182
bool absoluteFuzzyEqual(const libMesh::Real &var1, const libMesh::Real &var2, const libMesh::Real &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
bool isRestarting() const
Whether or not this is a "restart" calculation.
Definition: MooseApp.C:614