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 184 : UnitTripControl::validParams() 17 : { 18 184 : InputParameters params = THMControl::validParams(); 19 184 : params += MooseParsedFunctionBase::validParams(); 20 184 : params.addClassDescription( 21 : "Trips a boolean based on the evaluation of a parsed condition expression"); 22 368 : params.addRequiredCustomTypeParam<std::string>( 23 : "condition", 24 : "FunctionExpression", 25 : "The condition that this trip unit uses to determine its state."); 26 368 : params.addParam<bool>("latch", 27 368 : false, 28 : "Determines if the output of this control stays true after the trip went " 29 : "from false to true."); 30 184 : return params; 31 0 : } 32 : 33 92 : UnitTripControl::UnitTripControl(const InputParameters & parameters) 34 : : THMControl(parameters), 35 : MooseParsedFunctionBase(parameters), 36 92 : _condition(verifyFunction(getParam<std::string>("condition"))), 37 92 : _state(declareComponentControlData<bool>("state")), 38 184 : _latch(getParam<bool>("latch")), 39 184 : _tripped(false) 40 : { 41 92 : } 42 : 43 : void 44 184 : UnitTripControl::buildConditionFunction() 45 : { 46 184 : if (!_condition_ptr) 47 : { 48 92 : THREAD_ID tid = 0; 49 184 : if (isParamValid("_tid")) 50 184 : tid = getParam<THREAD_ID>("_tid"); 51 : 52 92 : _condition_ptr = std::make_unique<THMParsedFunctionWrapper>( 53 92 : *_sim, _pfb_feproblem, _condition, _vars, _vals, tid); 54 : } 55 184 : } 56 : 57 : void 58 92 : UnitTripControl::initialSetup() 59 : { 60 92 : buildConditionFunction(); 61 92 : } 62 : 63 : void 64 92 : UnitTripControl::init() 65 : { 66 92 : buildConditionFunction(); 67 : 68 : // establish dependency so that the control data graph is properly evaluated 69 158 : for (auto & ctrl_name : _condition_ptr->getRealControlData()) 70 66 : getControlDataByName<Real>(ctrl_name->name()); 71 92 : for (auto & ctrl_name : _condition_ptr->getBoolControlData()) 72 0 : getControlDataByName<bool>(ctrl_name->name()); 73 92 : } 74 : 75 : void 76 670 : UnitTripControl::execute() 77 : { 78 670 : if (_latch && _tripped) 79 : { 80 78 : _state = true; 81 78 : return; 82 : } 83 : 84 592 : Real result = _condition_ptr->evaluate(_t, Point(0., 0., 0.)); 85 592 : if (result == 0.) 86 348 : _state = false; 87 244 : else if (result == 1.) 88 : { 89 242 : _state = true; 90 242 : _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 : }