LCOV - code coverage report
Current view: top level - src/controllogic - UnitTripControl.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #32971 (54bef8) with base c6cf66 Lines: 43 44 97.7 %
Date: 2026-05-29 20:41:18 Functions: 6 6 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 "UnitTripControl.h"
      11             : #include "THMParsedFunctionWrapper.h"
      12             : 
      13             : registerMooseObject("ThermalHydraulicsApp", UnitTripControl);
      14             : 
      15             : InputParameters
      16          96 : UnitTripControl::validParams()
      17             : {
      18          96 :   InputParameters params = THMControl::validParams();
      19          96 :   params += MooseParsedFunctionBase::validParams();
      20          96 :   params.addClassDescription(
      21             :       "Trips a boolean based on the evaluation of a parsed condition expression");
      22         192 :   params.addRequiredCustomTypeParam<std::string>(
      23             :       "condition",
      24             :       "FunctionExpression",
      25             :       "The condition that this trip unit uses to determine its state.");
      26         192 :   params.addParam<bool>("latch",
      27         192 :                         false,
      28             :                         "Determines if the output of this control stays true after the trip went "
      29             :                         "from false to true.");
      30          96 :   return params;
      31           0 : }
      32             : 
      33          48 : UnitTripControl::UnitTripControl(const InputParameters & parameters)
      34             :   : THMControl(parameters),
      35             :     MooseParsedFunctionBase(parameters),
      36          48 :     _condition(verifyFunction(getParam<std::string>("condition"))),
      37          48 :     _state(declareComponentControlData<bool>("state")),
      38          96 :     _latch(getParam<bool>("latch")),
      39          96 :     _tripped(false)
      40             : {
      41          48 : }
      42             : 
      43             : void
      44          96 : UnitTripControl::buildConditionFunction()
      45             : {
      46          96 :   if (!_condition_ptr)
      47             :   {
      48          48 :     THREAD_ID tid = 0;
      49          96 :     if (isParamValid("_tid"))
      50          96 :       tid = getParam<THREAD_ID>("_tid");
      51             : 
      52          48 :     _condition_ptr = std::make_unique<THMParsedFunctionWrapper>(
      53          48 :         *_sim, _pfb_feproblem, _condition, _vars, _vals, tid);
      54             :   }
      55          96 : }
      56             : 
      57             : void
      58          48 : UnitTripControl::initialSetup()
      59             : {
      60          48 :   buildConditionFunction();
      61          48 : }
      62             : 
      63             : void
      64          48 : UnitTripControl::init()
      65             : {
      66          48 :   buildConditionFunction();
      67             : 
      68             :   // establish dependency so that the control data graph is properly evaluated
      69          82 :   for (auto & ctrl_name : _condition_ptr->getRealControlData())
      70          82 :     getControlDataByName<Real>(ctrl_name->name());
      71          48 :   for (auto & ctrl_name : _condition_ptr->getBoolControlData())
      72          48 :     getControlDataByName<bool>(ctrl_name->name());
      73          48 : }
      74             : 
      75             : void
      76         398 : UnitTripControl::execute()
      77             : {
      78         398 :   if (_latch && _tripped)
      79             :   {
      80          42 :     _state = true;
      81          42 :     return;
      82             :   }
      83             : 
      84         356 :   Real result = _condition_ptr->evaluate(_t, Point(0., 0., 0.));
      85         356 :   if (result == 0.)
      86         216 :     _state = false;
      87         140 :   else if (result == 1.)
      88             :   {
      89         138 :     _state = true;
      90         138 :     _tripped = true;
      91             :   }
      92             :   else
      93           2 :     mooseError(name(),
      94             :                ": The user-provided condition expression did not return a boolean value (0 or 1).");
      95             : }

Generated by: LCOV version 1.14