LCOV - code coverage report
Current view: top level - src/controls - ConditionalEnableControl.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 28 29 96.6 %
Date: 2025-07-17 01:28:37 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          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       43595 : ConditionalEnableControl::validParams()
      14             : {
      15       43595 :   InputParameters params = Control::validParams();
      16             : 
      17      130785 :   params.addParam<std::vector<std::string>>(
      18       87190 :       "disable_objects", std::vector<std::string>(), "A list of object tags to disable.");
      19      130785 :   params.addParam<std::vector<std::string>>(
      20       87190 :       "enable_objects", std::vector<std::string>(), "A list of object tags to enable.");
      21             : 
      22      130785 :   params.addParam<bool>("reverse_on_false",
      23       87190 :                         true,
      24             :                         "When true, the disable/enable lists are set to opposite values when the "
      25             :                         "specified condition is false.");
      26             : 
      27       43595 :   return params;
      28           0 : }
      29             : 
      30         408 : ConditionalEnableControl::ConditionalEnableControl(const InputParameters & parameters)
      31             :   : Control(parameters),
      32         408 :     _enable(getParam<std::vector<std::string>>("enable_objects")),
      33         408 :     _disable(getParam<std::vector<std::string>>("disable_objects")),
      34         816 :     _reverse_on_false(getParam<bool>("reverse_on_false"))
      35             : {
      36             :   // Error if enable and disable lists are both empty
      37         408 :   if (_enable.empty() && _disable.empty())
      38           4 :     mooseError(
      39             :         "Either or both of the 'enable_objects' and 'disable_objects' parameters must be set.");
      40         404 : }
      41             : 
      42             : void
      43        4522 : ConditionalEnableControl::execute()
      44             : {
      45             :   // ENABLE
      46        7068 :   for (MooseIndex(_enable) i = 0; i < _enable.size(); ++i)
      47        2546 :     if (conditionMet(i))
      48        1052 :       setControllableValueByName<bool>(_enable[i], std::string("enable"), true);
      49        1494 :     else if (_reverse_on_false)
      50        1494 :       setControllableValueByName<bool>(_enable[i], std::string("enable"), false);
      51             : 
      52             :   // DISABLE
      53        9403 :   for (MooseIndex(_disable) i = 0; i < _disable.size(); ++i)
      54        4881 :     if (conditionMet(i))
      55        2168 :       setControllableValueByName<bool>(_disable[i], std::string("enable"), false);
      56        2713 :     else if (_reverse_on_false)
      57        2713 :       setControllableValueByName<bool>(_disable[i], std::string("enable"), true);
      58        4522 : }

Generated by: LCOV version 1.14