https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ConditionalEnableControl.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
11
14{
16
17 params.addParam<std::vector<std::string>>(
18 "disable_objects", std::vector<std::string>(), "A list of object tags to disable.");
19 params.addParam<std::vector<std::string>>(
20 "enable_objects", std::vector<std::string>(), "A list of object tags to enable.");
21
22 params.addParam<bool>("reverse_on_false",
23 true,
24 "When true, the disable/enable lists are set to opposite values when the "
25 "specified condition is false.");
26
27 return params;
28}
29
31 : Control(parameters),
32 _enable(getParam<std::vector<std::string>>("enable_objects")),
33 _disable(getParam<std::vector<std::string>>("disable_objects")),
34 _reverse_on_false(getParam<bool>("reverse_on_false"))
35{
36 // Error if enable and disable lists are both empty
37 if (_enable.empty() && _disable.empty())
39 "Either or both of the 'enable_objects' and 'disable_objects' parameters must be set.");
40}
41
42void
44{
45 // ENABLE
46 for (MooseIndex(_enable) i = 0; i < _enable.size(); ++i)
47 if (conditionMet(i))
48 setControllableValueByName<bool>(_enable[i], std::string("enable"), true);
49 else if (_reverse_on_false)
50 setControllableValueByName<bool>(_enable[i], std::string("enable"), false);
51
52 // DISABLE
53 for (MooseIndex(_disable) i = 0; i < _disable.size(); ++i)
54 if (conditionMet(i))
55 setControllableValueByName<bool>(_disable[i], std::string("enable"), false);
56 else if (_reverse_on_false)
57 setControllableValueByName<bool>(_disable[i], std::string("enable"), true);
58}
const std::vector< std::string > & _enable
List of objects to enable if condition is met.
virtual bool conditionMet(const unsigned int &i)=0
Condition that must be true for an entry of the "enable" list to be enabled and/or an entry of the "d...
virtual void execute() override
Execute the control.
ConditionalEnableControl(const InputParameters &parameters)
const std::vector< std::string > & _disable
List of objects to disable if condition is met.
static InputParameters validParams()
const bool & _reverse_on_false
When true, the disable/enable lists are set to opposite values when the specified condition is false.
Base class for Control objects.
Definition Control.h:44
static InputParameters validParams()
Class constructor.
Definition Control.C:16
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 mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271