https://mooseframework.inl.gov
UnitTripControl.C
Go to the documentation of this file.
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"
12 
13 registerMooseObject("ThermalHydraulicsApp", UnitTripControl);
14 
17 {
20  params.addClassDescription(
21  "Trips a boolean based on the evaluation of a parsed condition expression");
22  params.addRequiredCustomTypeParam<std::string>(
23  "condition",
24  "FunctionExpression",
25  "The condition that this trip unit uses to determine its state.");
26  params.addParam<bool>("latch",
27  false,
28  "Determines if the output of this control stays true after the trip went "
29  "from false to true.");
30  return params;
31 }
32 
34  : THMControl(parameters),
35  MooseParsedFunctionBase(parameters),
36  _condition(verifyFunction(getParam<std::string>("condition"))),
37  _state(declareComponentControlData<bool>("state")),
38  _latch(getParam<bool>("latch")),
39  _tripped(false)
40 {
41 }
42 
43 void
45 {
46  if (!_condition_ptr)
47  {
48  THREAD_ID tid = 0;
49  if (isParamValid("_tid"))
50  tid = getParam<THREAD_ID>("_tid");
51 
52  _condition_ptr = std::make_unique<THMParsedFunctionWrapper>(
54  }
55 }
56 
57 void
59 {
61 }
62 
63 void
65 {
67 
68  // establish dependency so that the control data graph is properly evaluated
69  for (auto & ctrl_name : _condition_ptr->getRealControlData())
70  getControlDataByName<Real>(ctrl_name->name());
71  for (auto & ctrl_name : _condition_ptr->getBoolControlData())
72  getControlDataByName<bool>(ctrl_name->name());
73 }
74 
75 void
77 {
78  if (_latch && _tripped)
79  {
80  _state = true;
81  return;
82  }
83 
84  Real result = _condition_ptr->evaluate(_t, Point(0., 0., 0.));
85  if (result == 0.)
86  _state = false;
87  else if (result == 1.)
88  {
89  _state = true;
90  _tripped = true;
91  }
92  else
93  mooseError(name(),
94  ": The user-provided condition expression did not return a boolean value (0 or 1).");
95 }
registerMooseObject("ThermalHydraulicsApp", UnitTripControl)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
virtual void initialSetup() override
FEProblemBase & _pfb_feproblem
const std::vector< std::string > _vals
virtual void init() override
const bool & _latch
Determines if the state of the trip should stay true for the rest of the simulation after the trip ha...
virtual const std::string & name() const
bool isParamValid(const std::string &name) const
std::string _condition
The user-defined condition.
bool _tripped
true if the trip happened, otherwise false
static InputParameters validParams()
Definition: THMControl.C:13
static InputParameters validParams()
Real & _t
std::unique_ptr< THMParsedFunctionWrapper > _condition_ptr
Pointer to the Parsed function wrapper object.
THMProblem * _sim
Definition: THMControl.h:90
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
This control block uses a user-defined condition to determine if a trip happened. ...
static InputParameters validParams()
void mooseError(Args &&... args) const
void buildConditionFunction()
Build the function that is used to evaluate the condition of this trip control.
void addRequiredCustomTypeParam(const std::string &name, const std::string &custom_type, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
const std::vector< std::string > _vars
bool & _state
The state of this control object.
virtual void execute() override
unsigned int THREAD_ID
UnitTripControl(const InputParameters &parameters)