https://mooseframework.inl.gov
TimeIntervalTimes.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 "TimeIntervalTimes.h"
11 #include "MooseUtils.h"
12 #include "Transient.h"
13 
15 
18 {
20  params.addClassDescription("Times between a start time and end time with a fixed time interval.");
22  "time_interval", "time_interval > 0", "Time interval between times");
23  params.addParam<Real>("start_time",
24  "Start time. If not provided, the simulation start time is used.");
25  params.addParam<Real>("end_time", "End time. If not provided, the simulation end time is used.");
26  params.addParam<bool>(
27  "always_include_end_time",
28  true,
29  "If true, includes the end time even if the last time interval would be partial");
30 
31  // Times are known for all processes already
32  params.set<bool>("auto_broadcast") = false;
33 
34  return params;
35 }
36 
38 {
39  // Get start time
40  Real start_time;
41  if (isParamValid("start_time"))
42  start_time = getParam<Real>("start_time");
43  else
44  {
45  if (auto transient = dynamic_cast<TransientBase *>(_app.getExecutioner()))
46  start_time = transient->getStartTime();
47  else
48  mooseError("If the parameter 'start_time' is not provided, the executioner type must be "
49  "'Transient'.");
50  }
51 
52  // Get end time
53  Real end_time;
54  if (isParamValid("end_time"))
55  end_time = getParam<Real>("end_time");
56  else
57  {
58  if (auto transient = dynamic_cast<TransientBase *>(_app.getExecutioner()))
59  end_time = transient->endTime();
60  else
61  mooseError(
62  "If the parameter 'end_time' is not provided, the executioner type must be 'Transient'.");
63  }
64 
65  if (MooseUtils::absoluteFuzzyLessEqual(end_time, start_time))
66  mooseError("The end time must be greater than the start time.");
67 
68  const auto time_interval = getParam<Real>("time_interval");
69  const bool always_include_end_time = getParam<bool>("always_include_end_time");
70 
71  _times.push_back(start_time);
72  while (true)
73  {
74  const auto proposed_new_time = _times.back() + time_interval;
75  if (MooseUtils::absoluteFuzzyGreaterThan(proposed_new_time, end_time))
76  {
77  if (always_include_end_time && !MooseUtils::absoluteFuzzyEqual(_times.back(), end_time))
78  _times.push_back(end_time);
79  break;
80  }
81  else
82  _times.push_back(proposed_new_time);
83  }
84 }
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
These methods add an range checked parameters.
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
Definition: MooseUtils.h:380
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
Times objects are under the hood Reporters, but limited to a vector of Real.
Definition: Times.h:18
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
static InputParameters validParams()
Definition: Times.C:14
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:84
Executioner * getExecutioner() const
Retrieve the Executioner for this App.
Definition: MooseApp.C:2118
TimeIntervalTimes(const InputParameters &parameters)
Times between a start time and end time with a fixed time interval.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
registerMooseObject("MooseApp", TimeIntervalTimes)
bool absoluteFuzzyLessEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is less than or equal to another variable within an absolute tol...
Definition: MooseUtils.h:452
static InputParameters validParams()
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...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
std::vector< Real > & _times
The vector holding the times.
Definition: Times.h:72
bool absoluteFuzzyGreaterThan(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is greater than another variable within an absolute tolerance...
Definition: MooseUtils.h:428