Line data Source code
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 "ConditionalEnableControl.h" 11 : 12 : InputParameters 13 43653 : ConditionalEnableControl::validParams() 14 : { 15 43653 : InputParameters params = Control::validParams(); 16 : 17 130959 : params.addParam<std::vector<std::string>>( 18 87306 : "disable_objects", std::vector<std::string>(), "A list of object tags to disable."); 19 130959 : params.addParam<std::vector<std::string>>( 20 87306 : "enable_objects", std::vector<std::string>(), "A list of object tags to enable."); 21 : 22 130959 : params.addParam<bool>("reverse_on_false", 23 87306 : true, 24 : "When true, the disable/enable lists are set to opposite values when the " 25 : "specified condition is false."); 26 : 27 43653 : return params; 28 0 : } 29 : 30 437 : ConditionalEnableControl::ConditionalEnableControl(const InputParameters & parameters) 31 : : Control(parameters), 32 437 : _enable(getParam<std::vector<std::string>>("enable_objects")), 33 437 : _disable(getParam<std::vector<std::string>>("disable_objects")), 34 874 : _reverse_on_false(getParam<bool>("reverse_on_false")) 35 : { 36 : // Error if enable and disable lists are both empty 37 437 : if (_enable.empty() && _disable.empty()) 38 4 : mooseError( 39 : "Either or both of the 'enable_objects' and 'disable_objects' parameters must be set."); 40 433 : } 41 : 42 : void 43 4902 : ConditionalEnableControl::execute() 44 : { 45 : // ENABLE 46 7636 : for (MooseIndex(_enable) i = 0; i < _enable.size(); ++i) 47 2734 : if (conditionMet(i)) 48 1145 : setControllableValueByName<bool>(_enable[i], std::string("enable"), true); 49 1589 : else if (_reverse_on_false) 50 1589 : setControllableValueByName<bool>(_enable[i], std::string("enable"), false); 51 : 52 : // DISABLE 53 10201 : for (MooseIndex(_disable) i = 0; i < _disable.size(); ++i) 54 5299 : if (conditionMet(i)) 55 2370 : setControllableValueByName<bool>(_disable[i], std::string("enable"), false); 56 2929 : else if (_reverse_on_false) 57 2929 : setControllableValueByName<bool>(_disable[i], std::string("enable"), true); 58 4902 : }