www.mooseframework.org
TimePeriod.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 // MOOSE includes
11 #include "TimePeriod.h"
12 #include "Function.h"
13 #include "Transient.h"
14 #include "MooseUtils.h"
15 
16 registerMooseObject("MooseApp", TimePeriod);
17 
18 template <>
21 {
23 
24  params.addClassDescription("Control the enabled/disabled state of objects with time.");
25 
26  params.addParam<std::vector<Real>>("start_time",
27  "The time at which the objects are to be enabled/disabled.");
28  params.addParam<std::vector<Real>>("end_time",
29  "The time at which the objects are to be enable/disabled.");
30  params.addParam<bool>(
31  "set_sync_times", false, "Set the start and end time as execute sync times.");
32 
33  return params;
34 }
35 
37 {
38  // Error if not a transient problem
39  if (!_fe_problem.isTransient())
40  mooseError("TimePeriod objects only operate on transient problems.");
41 
42  // Set start time
43  if (isParamValid("start_time"))
44  _start_time = getParam<std::vector<Real>>("start_time");
45  else
46  _start_time = {_app.getExecutioner()->getParam<Real>("start_time")};
47 
48  // Set end time
49  if (isParamValid("end_time"))
50  _end_time = getParam<std::vector<Real>>("end_time");
51  else
52  _end_time = std::vector<Real>(_start_time.size(), std::numeric_limits<Real>::max());
53 
54  // Check that start/end time are the same length
55  if (_end_time.size() != _start_time.size())
56  mooseError("The end time and start time vectors must be the same length.");
57 
58  // Resize the start/end times if only a single value given
59  if (_end_time.size() == 1 && (_disable.size() > 1 || _enable.size() > 1))
60  {
61  unsigned int size = std::max(_disable.size(), _enable.size());
62  _end_time = std::vector<Real>(size, _end_time[0]);
63  _start_time = std::vector<Real>(size, _start_time[0]);
64  }
65  else if (_end_time.size() != _disable.size() && _end_time.size() != _enable.size())
66  mooseError("The start/end time input must be a scalar or the same length as the enable/disable "
67  "lists.");
68 
69  // Test that start and end times are in proper order
70  for (unsigned int i = 0; i < _start_time.size(); ++i)
71  if (_start_time[i] >= _end_time[i])
72  mooseError("The start time(s) must be less than the end time(s).");
73 }
74 
75 void
77 {
78  if (getParam<bool>("set_sync_times"))
79  {
80  std::set<Real> & sync_times = _app.getOutputWarehouse().getSyncTimes();
81  sync_times.insert(_start_time.begin(), _start_time.end());
82  sync_times.insert(_end_time.begin(), _end_time.end());
83  }
84 }
85 
86 bool
87 TimePeriod::conditionMet(const unsigned int & i)
88 {
91 }
const std::vector< std::string > & _disable
List of objects to disable if condition is met.
Executioner * getExecutioner() const
Retrieve the Executioner for this App.
Definition: MooseApp.h:255
registerMooseObject("MooseApp", TimePeriod)
virtual bool conditionMet(const unsigned int &i) override
Condition that must be true for an entry of the "enable" list to be enabled and/or an entry of the "d...
Definition: TimePeriod.C:87
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseObject.h:191
std::vector< Real > _start_time
The time to begin enabling the supplied object tags (defaults to the simulation start time) ...
Definition: TimePeriod.h:43
A basic control for disabling objects for a portion of the simulation.
Definition: TimePeriod.h:24
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this object.
Definition: Control.h:75
bool absoluteFuzzyLessThan(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is less than another variable within an absolute tolerance...
Definition: MooseUtils.h:322
TimePeriod(const InputParameters &parameters)
Class constructor.
Definition: TimePeriod.C:36
const std::vector< std::string > & _enable
List of objects to enable if condition is met.
std::vector< Real > _end_time
The time to stop enabling the supplied object tags (defaults to the end of the simulation) ...
Definition: TimePeriod.h:46
MooseApp & _app
The MooseApp this object is associated with.
Definition: MooseObject.h:177
bool absoluteFuzzyGreaterEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is greater than or equal to another variable within an absolute ...
Definition: MooseUtils.h:254
InputParameters validParams< ConditionalEnableControl >()
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...
Base class for controls that enable/disable object(s) based on some condition.
virtual bool isTransient() const override
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseObject.h:89
void initialSetup() override
If enabled, this injects the start/end times into the TimeStepper sync times.
Definition: TimePeriod.C:76
InputParameters validParams< TimePeriod >()
Definition: TimePeriod.C:20
std::set< Real > & getSyncTimes()
Return the sync times for all objects.
OutputWarehouse & getOutputWarehouse()
Get the OutputWarehouse objects.
Definition: MooseApp.C:1055