www.mooseframework.org
TimePeriod.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 // MOOSE includes
16 #include "TimePeriod.h"
17 #include "Function.h"
18 #include "Transient.h"
19 #include "MooseUtils.h"
20 
21 template <>
24 {
26  params.addClassDescription("Control the enabled/disabled state of objects with time.");
27  params.addParam<std::vector<std::string>>(
28  "disable_objects", std::vector<std::string>(), "A list of object tags to disable.");
29  params.addParam<std::vector<std::string>>(
30  "enable_objects", std::vector<std::string>(), "A list of object tags to enable.");
31  params.addParam<std::vector<Real>>("start_time",
32  "The time at which the objects are to be enabled/disabled.");
33  params.addParam<std::vector<Real>>("end_time",
34  "The time at which the objects are to be enable/disabled.");
35  params.addParam<bool>(
36  "set_sync_times", false, "Set the start and end time as execute sync times.");
37  params.addParam<bool>("set_outside_of_range",
38  true,
39  "When true the disable/enable lists are set "
40  "to opposite values when outside of the "
41  "given time range.");
42  return params;
43 }
44 
46  : Control(parameters),
47  _enable(getParam<std::vector<std::string>>("enable_objects")),
48  _disable(getParam<std::vector<std::string>>("disable_objects")),
49  _set_outside_of_range(getParam<bool>("set_outside_of_range"))
50 {
51  // Error if not a transient problem
52  if (!_fe_problem.isTransient())
53  mooseError("TimePeriod objects only operate on transient problems.");
54 
55  // Error if enable and disable lists are both empty
56  if (_enable.empty() && _disable.empty())
57  mooseError(
58  "Either or both of the 'enable_objects' and 'disable_objects' parameters must be set.");
59 
60  // Set start time
61  if (isParamValid("start_time"))
62  _start_time = getParam<std::vector<Real>>("start_time");
63  else
64  _start_time = {_app.executioner()->getParam<Real>("start_time")};
65 
66  // Set end time
67  if (isParamValid("end_time"))
68  _end_time = getParam<std::vector<Real>>("end_time");
69  else
70  _end_time = std::vector<Real>(_start_time.size(), std::numeric_limits<Real>::max());
71 
72  // Check that start/end time are the same length
73  if (_end_time.size() != _start_time.size())
74  mooseError("The end time and start time vectors must be the same length.");
75 
76  // Resize the start/end times if only a single value given
77  if (_end_time.size() == 1 && (_disable.size() > 1 || _enable.size() > 1))
78  {
79  unsigned int size = std::max(_disable.size(), _enable.size());
80  _end_time = std::vector<Real>(size, _end_time[0]);
81  _start_time = std::vector<Real>(size, _start_time[0]);
82  }
83  else if (_end_time.size() != _disable.size() && _end_time.size() != _enable.size())
84  mooseError("The start/end time input must be a scalar or the same length as the enable/disable "
85  "lists.");
86 
87  // Test that start and end times are in proper order
88  for (unsigned int i = 0; i < _start_time.size(); ++i)
89  if (_start_time[i] >= _end_time[i])
90  mooseError("The start time(s) must be less than the end time(s).");
91 }
92 
93 void
95 {
96  // ENABLE
97  for (auto i = beginIndex(_enable); i < _enable.size(); ++i)
98  {
99  // If the current time falls between the start and end time, ENABLE the object (_t >=
100  // _start_time and _t < _end_time)
103  setControllableValueByName<bool>(_enable[i], std::string("enable"), true);
104 
105  else if (_set_outside_of_range)
106  setControllableValueByName<bool>(_enable[i], std::string("enable"), false);
107  }
108 
109  // DISABLE
110  for (auto i = beginIndex(_disable); i < _disable.size(); ++i)
111  {
112  // If the current time falls between the start and end time, DISABLE the object (_t >=
113  // _start_time and _t < _end_time)
116  setControllableValueByName<bool>(_disable[i], std::string("enable"), false);
117 
118  else if (_set_outside_of_range)
119  setControllableValueByName<bool>(_disable[i], std::string("enable"), true);
120  }
121 }
122 
123 void
125 {
126  if (getParam<bool>("set_sync_times"))
127  {
128  std::set<Real> & sync_times = _app.getOutputWarehouse().getSyncTimes();
129  sync_times.insert(_start_time.begin(), _start_time.end());
130  sync_times.insert(_end_time.begin(), _end_time.end());
131  }
132 }
bool absoluteFuzzyGreaterEqual(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 an absolute ...
std::shared_ptr< Executioner > & executioner()
Retrieve the Executioner shared pointer for this App.
Definition: MooseApp.h:238
virtual void execute() override
Execute the control.
Definition: TimePeriod.C:94
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const std::vector< std::string > & _disable
List of objects to disable.
Definition: TimePeriod.h:53
bool absoluteFuzzyLessThan(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 an absolute tolerance...
std::vector< Real > _start_time
The time to begin enabling the supplied object tags (defaults to the simulation start time) ...
Definition: TimePeriod.h:56
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this object.
Definition: Control.h:80
virtual bool isTransient() const override
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseObject.h:67
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseObject.h:122
TimePeriod(const InputParameters &parameters)
Class constructor.
Definition: TimePeriod.C:45
const std::vector< std::string > & _enable
List of objects to enable.
Definition: TimePeriod.h:50
Base class for Control objects.
Definition: Control.h:43
std::vector< Real > _end_time
The time to stop enabling the supplied object tags (defaults to the end of the simulation) ...
Definition: TimePeriod.h:59
InputParameters validParams< Control >()
Definition: Control.C:20
MooseApp & _app
The MooseApp this object is associated with.
Definition: MooseObject.h:108
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...
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...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
void initialSetup() override
If enabled, this injects the start/end times into the TimeStepper sync times.
Definition: TimePeriod.C:124
bool _set_outside_of_range
Flag for setting value outside of time range.
Definition: TimePeriod.h:62
InputParameters validParams< TimePeriod >()
Definition: TimePeriod.C:23
std::set< Real > & getSyncTimes()
Return the sync times for all objects.
OutputWarehouse & getOutputWarehouse()
Get the OutputWarehouse objects.
Definition: MooseApp.C:840