www.mooseframework.org
FunctionDT.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 
15 #include "FunctionDT.h"
16 #include "FEProblem.h"
17 #include "Transient.h"
18 #include <limits>
19 
20 template <>
23 {
25  params.addRequiredParam<std::vector<Real>>("time_t", "The values of t");
26  params.addRequiredParam<std::vector<Real>>("time_dt", "The values of dt");
27  params.addParam<Real>("growth_factor",
28  std::numeric_limits<Real>::max(),
29  "Maximum ratio of new to previous timestep sizes following a step that "
30  "required the time step to be cut due to a failed solve.");
31  params.addParam<Real>("min_dt", 0, "The minimal dt to take.");
32  params.addParam<bool>("interpolate",
33  true,
34  "Whether or not to interpolate DT between times. "
35  "This is true by default for historical reasons.");
36  params.addClassDescription(
37  "Timestepper whose steps vary over time according to a user-defined fuction");
38 
39  return params;
40 }
41 
43  : TimeStepper(parameters),
44  _time_t(getParam<std::vector<Real>>("time_t")),
45  _time_dt(getParam<std::vector<Real>>("time_dt")),
46  _growth_factor(getParam<Real>("growth_factor")),
47  _cutback_occurred(false),
48  _min_dt(getParam<Real>("min_dt")),
49  _interpolate(getParam<bool>("interpolate"))
50 {
51  try
52  {
53  _time_ipol = libmesh_make_unique<LinearInterpolation>(_time_t, _time_dt);
54  }
55  catch (std::domain_error & e)
56  {
57  mooseError("In FunctionDT ", _name, ": ", e.what());
58  }
59 
61 }
62 
63 void
65 {
66 }
67 
68 void
70 {
71  while ((_time_knots.size() > 0) &&
72  (*_time_knots.begin() <= _time || std::abs(*_time_knots.begin() - _time) < 1e-10))
73  _time_knots.erase(_time_knots.begin());
74 }
75 
76 void
78 {
81 }
82 
83 Real
85 {
86  return computeDT();
87 }
88 
89 Real
91 {
92  Real local_dt = 0;
93 
94  if (_interpolate)
95  local_dt = _time_ipol->sample(_time);
96  else // Find where we are
97  {
98  unsigned int i = 0;
100  {
101  i = _time_t.size();
102  }
103  else
104  {
105  for (; i < _time_t.size() - 1; i++)
107  break;
108  }
109 
110  // Use the last dt after the end
111  if (i == _time_t.size())
112  local_dt = _time_dt.back();
113  else
114  local_dt = _time_dt[i];
115  }
116 
117  // sync to time knot
118  if ((_time_knots.size() > 0) && (_time + local_dt >= (*_time_knots.begin())))
119  local_dt = (*_time_knots.begin()) - _time;
120  // honor minimal dt
121  if (local_dt < _min_dt)
122  local_dt = _min_dt;
123 
124  if (_cutback_occurred && (local_dt > _dt * _growth_factor))
125  local_dt = _dt * _growth_factor;
126  _cutback_occurred = false;
127 
128  return local_dt;
129 }
130 
131 void
133 {
134  removeOldKnots();
135 }
136 
137 void
139 {
140  _cutback_occurred = true;
142 }
std::unique_ptr< LinearInterpolation > _time_ipol
Piecewise linear definition of time stepping.
Definition: FunctionDT.h:48
std::vector< Real > _time_knots
Definition: FunctionDT.h:58
virtual void preExecute() override
Definition: FunctionDT.C:77
Base class for time stepping.
Definition: TimeStepper.h:31
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const std::vector< Real > & _time_t
Definition: FunctionDT.h:44
bool _interpolate
Whether or not to interpolate DT between times.
Definition: FunctionDT.h:56
virtual void postStep() override
Definition: FunctionDT.C:132
bool relativeFuzzyLessThan(const libMesh::Real &var1, const libMesh::Real &var2, const libMesh::Real &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is less than another variable within a relative tolerance...
InputParameters validParams< FunctionDT >()
Definition: FunctionDT.C:22
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void removeOldKnots()
Definition: FunctionDT.C:69
virtual void init() override
Initialize the time stepper.
Definition: FunctionDT.C:64
virtual Real computeDT() override
Called to compute _current_dt for a normal step.
Definition: FunctionDT.C:90
InputParameters validParams< TimeStepper >()
Definition: TimeStepper.C:22
const std::string & _name
The name of this object, reference to value stored in InputParameters.
Definition: MooseObject.h:114
bool _cutback_occurred
True if cut back of the time step occurred.
Definition: FunctionDT.h:52
virtual void preExecute()
Definition: TimeStepper.C:65
virtual void rejectStep()
This gets called when time step is rejected.
Definition: TimeStepper.C:175
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
bool relativeFuzzyGreaterEqual(const libMesh::Real &var1, const libMesh::Real &var2, const libMesh::Real &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is greater than or equal to another variable within a relative t...
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...
virtual Real computeInitialDT() override
Called to compute _current_dt for the first timestep.
Definition: FunctionDT.C:84
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
virtual void rejectStep() override
This gets called when time step is rejected.
Definition: FunctionDT.C:138
Real _min_dt
Definition: FunctionDT.h:53
Real _growth_factor
Definition: FunctionDT.h:50
Real & _dt
Definition: TimeStepper.h:132
FunctionDT(const InputParameters &parameters)
Definition: FunctionDT.C:42
const std::vector< Real > & _time_dt
Definition: FunctionDT.h:45
Real & _time
Values from executioner.
Definition: TimeStepper.h:129