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 9991 : ConditionalEnableControl::validParams() 14 : { 15 9991 : InputParameters params = Control::validParams(); 16 : 17 29973 : params.addParam<std::vector<std::string>>( 18 19982 : "disable_objects", std::vector<std::string>(), "A list of object tags to disable."); 19 29973 : params.addParam<std::vector<std::string>>( 20 19982 : "enable_objects", std::vector<std::string>(), "A list of object tags to enable."); 21 : 22 19982 : params.addParam<bool>("reverse_on_false", 23 19982 : true, 24 : "When true, the disable/enable lists are set to opposite values when the " 25 : "specified condition is false."); 26 : 27 9991 : return params; 28 0 : } 29 : 30 410 : ConditionalEnableControl::ConditionalEnableControl(const InputParameters & parameters) 31 : : Control(parameters), 32 410 : _enable(getParam<std::vector<std::string>>("enable_objects")), 33 820 : _disable(getParam<std::vector<std::string>>("disable_objects")), 34 1230 : _reverse_on_false(getParam<bool>("reverse_on_false")) 35 : { 36 : // Error if enable and disable lists are both empty 37 410 : if (_enable.empty() && _disable.empty()) 38 3 : mooseError( 39 : "Either or both of the 'enable_objects' and 'disable_objects' parameters must be set."); 40 407 : } 41 : 42 : void 43 4515 : ConditionalEnableControl::execute() 44 : { 45 : // ENABLE 46 7041 : for (MooseIndex(_enable) i = 0; i < _enable.size(); ++i) 47 2526 : if (conditionMet(i)) 48 3213 : setControllableValueByName<bool>(_enable[i], std::string("enable"), true); 49 1455 : else if (_reverse_on_false) 50 4365 : setControllableValueByName<bool>(_enable[i], std::string("enable"), false); 51 : 52 : // DISABLE 53 9391 : for (MooseIndex(_disable) i = 0; i < _disable.size(); ++i) 54 4876 : if (conditionMet(i)) 55 6582 : setControllableValueByName<bool>(_disable[i], std::string("enable"), false); 56 2682 : else if (_reverse_on_false) 57 8046 : setControllableValueByName<bool>(_disable[i], std::string("enable"), true); 58 4515 : }