www.mooseframework.org
ConditionalEnableControl.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
12 template <>
15 {
17 
18  params.addParam<std::vector<std::string>>(
19  "disable_objects", std::vector<std::string>(), "A list of object tags to disable.");
20  params.addParam<std::vector<std::string>>(
21  "enable_objects", std::vector<std::string>(), "A list of object tags to enable.");
22 
23  params.addParam<bool>("reverse_on_false",
24  true,
25  "When true, the disable/enable lists are set to opposite values when the "
26  "specified condition is false.");
27 
28  return params;
29 }
30 
32  : Control(parameters),
33  _enable(getParam<std::vector<std::string>>("enable_objects")),
34  _disable(getParam<std::vector<std::string>>("disable_objects")),
35  _reverse_on_false(getParam<bool>("reverse_on_false"))
36 {
37  // Error if enable and disable lists are both empty
38  if (_enable.empty() && _disable.empty())
39  mooseError(
40  "Either or both of the 'enable_objects' and 'disable_objects' parameters must be set.");
41 }
42 
43 void
45 {
46  // ENABLE
47  for (MooseIndex(_enable) i = 0; i < _enable.size(); ++i)
48  if (conditionMet(i))
49  setControllableValueByName<bool>(_enable[i], std::string("enable"), true);
50  else if (_reverse_on_false)
51  setControllableValueByName<bool>(_enable[i], std::string("enable"), false);
52 
53  // DISABLE
54  for (MooseIndex(_disable) i = 0; i < _disable.size(); ++i)
55  if (conditionMet(i))
56  setControllableValueByName<bool>(_disable[i], std::string("enable"), false);
57  else if (_reverse_on_false)
58  setControllableValueByName<bool>(_disable[i], std::string("enable"), true);
59 }
const std::vector< std::string > & _disable
List of objects to disable if condition is met.
ConditionalEnableControl(const InputParameters &parameters)
virtual void execute() override
Execute the control.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const bool & _reverse_on_false
When true, the disable/enable lists are set to opposite values when the specified condition is false...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
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...
const std::vector< std::string > & _enable
List of objects to enable if condition is met.
Base class for Control objects.
Definition: Control.h:37
InputParameters validParams< Control >()
Definition: Control.C:16
InputParameters validParams< ConditionalEnableControl >()
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...