https://mooseframework.inl.gov
TimePeriodBase.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 "TimePeriodBase.h"
11 #include "Function.h"
12 #include "Transient.h"
13 #include "MooseUtils.h"
14 #include "FEProblemBase.h"
15 
18 {
20  params.addClassDescription(
21  "Base class for controlling the enabled/disabled state of objects with time.");
22  return params;
23 }
24 
26  : ConditionalEnableControl(parameters)
27 {
28  // Error if not a transient problem
29  if (!_fe_problem.isTransient())
30  mooseError("TimePeriodBase objects only operate on transient problems.");
31 }
32 
33 void
35 {
36  // Check that start/end time are the same length
37  if (_end_time.size() != _start_time.size())
38  mooseError("The end time and start time vectors must be the same length.");
39 
40  // Resize the start/end times if only a single value given
41  if (_end_time.size() == 1 && (_disable.size() > 1 || _enable.size() > 1))
42  {
43  unsigned int size = std::max(_disable.size(), _enable.size());
44  _end_time = std::vector<Real>(size, _end_time[0]);
45  _start_time = std::vector<Real>(size, _start_time[0]);
46  }
47  else if (_end_time.size() != _disable.size() && _end_time.size() != _enable.size())
48  mooseError("The start/end time input must be a scalar or the same length as the enable/disable "
49  "lists.");
50 
51  // Test that start and end times are in proper order
52  for (unsigned int i = 0; i < _start_time.size(); ++i)
53  if (_start_time[i] >= _end_time[i])
54  mooseError("The start time(s) must be less than the end time(s).");
55 }
const std::vector< std::string > & _disable
List of objects to disable if condition is met.
TimePeriodBase(const InputParameters &parameters)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
Class constructor.
auto max(const L &left, const R &right)
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this object.
Definition: Control.h:74
static InputParameters validParams()
std::vector< Real > _start_time
The time to begin enabling the supplied object tags (defaults to the simulation start time) ...
const std::vector< std::string > & _enable
List of objects to enable if condition is met.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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...
Base class for controls that enable/disable object(s) based on some condition.
virtual bool isTransient() const override
void setupTimes()
Helper base method to set start and end times for controls.
std::vector< Real > _end_time
The time to stop enabling the supplied object tags (defaults to the end of the simulation) ...