https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
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 mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
registerMooseObject("MooseApp", TimeIntervalTimes)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
These methods add an range checked parameters.
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.
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
Executioner * getExecutioner() const
Retrieve the Executioner for this App.
Definition MooseApp.C:2015
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
Times between a start time and end time with a fixed time interval.
TimeIntervalTimes(const InputParameters &parameters)
static InputParameters validParams()
Times objects are under the hood Reporters, but limited to a vector of Real.
Definition Times.h:19
static InputParameters validParams()
Definition Times.C:14
std::vector< Real > & _times
The vector holding the times.
Definition Times.h:74
Base class for transient executioners that use a FixedPointSolve solve object for multiapp-main app i...