https://mooseframework.inl.gov
Loading...
Searching...
No Matches
TimesEnableControl.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 "TimesEnableControl.h"
11#include "Times.h"
12
14
17{
19
20 params.addRequiredParam<UserObjectName>(
21 "times", "The Times object providing the list of times to turn on/off the objects.");
22
23 params.addParam<Real>(
24 "time_window",
25 1e-8,
26 "Window / tolerance on the absolute difference between the time step and the simulation");
27 params.addParam<bool>(
28 "act_on_time_stepping_across_a_time_point",
29 true,
30 "Whether to still perform the control action (enable/disable) if a time step went over a "
31 "'time point' in the Times object without stopping near that exact time");
32
34 "Control for enabling/disabling objects when a certain time is reached.");
35
36 return params;
37}
38
40 : ConditionalEnableControl(parameters),
41 _times(getUserObject<Times>("times")),
42 _time_window(getParam<Real>("time_window")),
43 _act_on_time_stepping_across_time_point(
44 getParam<bool>("act_on_time_stepping_across_a_time_point")),
45 _prev_time_point_current(std::numeric_limits<Real>::max()),
46 _prev_time_point(declareRestartableData<Real>("prev_time", std::numeric_limits<Real>::max())),
47 _t_current(_fe_problem.time())
48{
49}
50
51bool
52TimesEnableControl::conditionMet(const unsigned int & /*i*/)
53{
54 // Retrieve time points around the current time
55 const auto prev_time_point = _times.getPreviousTime(_t);
56 const auto next_time_point = _times.getNextTime(_t, false);
57
58 // Initialize the previous time point for the first time
59 // By doing this here instead of the constructor, we avoid creating a construction dependency
60 // between 'Times' and 'Controls'
61 if (_prev_time_point == std::numeric_limits<Real>::max())
63
64 // Check if we are near a time point
65 // We could have just missed the previous one or be right before the next one
66 if (MooseUtils::absoluteFuzzyEqual(_t, prev_time_point, _time_window))
67 {
68 // Avoid always triggering on the next time step based on the prev_time_point value
70 _prev_time_point = next_time_point;
71 return true;
72 }
73 else if (MooseUtils::absoluteFuzzyEqual(_t, next_time_point, _time_window))
74 {
76 _prev_time_point = _times.getNextTime(next_time_point, false);
77 return true;
78 }
79
80 // Update prev_time_point_current only if we changed time step since the last time conditionMet
81 // was called
82 if (_t != _t_current)
83 {
85 _t_current = _t;
86 }
87
88 // Check if we passed a time point
90 {
91 // We will need to pass the next time point next time to trigger the condition
92 _prev_time_point = next_time_point;
93 // we do not update prev_time_point_current in case conditionMet is called again in the same
94 // time step
95 return true;
96 }
97
98 return false;
99}
registerMooseObject("MooseApp", TimesEnableControl)
Base class for controls that enable/disable object(s) based on some condition.
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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 addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
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.
Control for enabling/disabling objects when near or past times from a Times object.
const Real _time_window
The tolerance on hitting time points with the current simulation time.
const Times & _times
The time object providing the times.
static InputParameters validParams()
const bool _act_on_time_stepping_across_time_point
Whether to consider that going past a time point should trigger the control.
TimesEnableControl(const InputParameters &parameters)
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...
Real _t_current
To keep track of the current time step.
Real _prev_time_point_current
To keep track of the current threshold to hit.
Real _prev_time_point
To keep track of the next threshold to hit.
Times objects are under the hood Reporters, but limited to a vector of Real.
Definition Times.h:19
Real getNextTime(const Real current_time, const bool error_if_no_next) const
Find the next time in the times vector for a given time If current_time is also in the times vector w...
Definition Times.C:87
Real getTimeAtIndex(unsigned int index) const
Getter for a single time at a known index.
Definition Times.C:57
Real getPreviousTime(const Real current_time) const
Find the previous time in the times vector for a given time If current_time is also in the times vect...
Definition Times.C:69