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 : #pragma once 11 : 12 : #include "Control.h" 13 : #include "ControlData.h" 14 : #include "THMProblem.h" 15 : 16 : class THMControl : public Control 17 : { 18 : public: 19 : THMControl(const InputParameters & parameters); 20 : 21 10886 : virtual void init() {} 22 : 23 : /** 24 : * Return the Controls that must run before this Control 25 : */ 26 : const std::vector<std::string> & getControlDataDependencies() const 27 : { 28 : return _control_data_depends_on; 29 : } 30 : 31 : protected: 32 : /** 33 : * Declare control data with name 'component:data_name' 34 : * 35 : * @param data_name A unique name for the control data 36 : */ 37 : template <typename T> 38 : T & declareComponentControlData(const std::string & data_name); 39 : 40 : /** 41 : * Declare control data with name 'data_name' 42 : * 43 : * @param data_name A unique name for the control data 44 : */ 45 : template <typename T> 46 : T & declareControlData(const std::string & data_name); 47 : 48 : /** 49 : * Get a reference to control data that are specified in the input parameter 'param_name' 50 : * 51 : * @param param_name The parameter name that contains the name of the control data 52 : */ 53 : template <typename T> 54 : const T & getControlData(const std::string & param_name); 55 : 56 : /** 57 : * Get a reference to control data value from a previous time step that is specified in the input 58 : * parameter 'param_name' 59 : * 60 : * @param param_name The parameter name that contains the name of the control data 61 : */ 62 : template <typename T> 63 : const T & getControlDataOld(const std::string & param_name); 64 : 65 : /** 66 : * Get a reference to control data that are specified by 'data_name' name 67 : * 68 : * @param data_name The name of the control data 69 : */ 70 : template <typename T> 71 : const T & getControlDataByName(const std::string & data_name); 72 : 73 : /** 74 : * Get a reference to control data value from previous time step that is specified by 'data_name' 75 : * name 76 : * 77 : * @param data_name The name of the control data 78 : */ 79 : template <typename T> 80 : const T & getControlDataOldByName(const std::string & data_name); 81 : 82 : /** 83 : * Get a reference to a component control data value from previous time step 84 : * 85 : * @param data_name The name of the control data 86 : */ 87 : template <typename T> 88 : const T & getComponentControlDataOld(const std::string & data_name); 89 : 90 : THMProblem * _sim; 91 : 92 : /// A list of control data that are required to run before this control may run 93 : std::vector<std::string> _control_data_depends_on; 94 : 95 : public: 96 : static InputParameters validParams(); 97 : }; 98 : 99 : template <typename T> 100 : T & 101 469 : THMControl::declareComponentControlData(const std::string & data_name) 102 : { 103 469 : std::string full_name = name() + ":" + data_name; 104 469 : ControlData<T> * data_ptr = _sim->declareControlData<T>(full_name, this); 105 469 : return data_ptr->set(); 106 : } 107 : 108 : template <typename T> 109 : T & 110 : THMControl::declareControlData(const std::string & data_name) 111 : { 112 9997 : ControlData<T> * data_ptr = _sim->declareControlData<T>(data_name, this); 113 : return data_ptr->set(); 114 : } 115 : 116 : template <typename T> 117 : const T & 118 275 : THMControl::getControlData(const std::string & param_name) 119 : { 120 275 : std::string data_name = getParam<std::string>(param_name); 121 550 : return getControlDataByName<T>(data_name); 122 : } 123 : 124 : template <typename T> 125 : const T & 126 : THMControl::getControlDataOld(const std::string & param_name) 127 : { 128 : std::string data_name = getParam<std::string>(param_name); 129 : return getControlDataOldByName<T>(data_name); 130 : } 131 : 132 : template <typename T> 133 : const T & 134 413 : THMControl::getControlDataByName(const std::string & data_name) 135 : { 136 413 : ControlData<T> * data_ptr = _sim->getControlData<T>(data_name); 137 413 : if (data_ptr == nullptr) 138 0 : mooseError("Trying to get control data '", 139 : data_name, 140 : "', but it does not exist in the system. Check your spelling."); 141 : 142 : // set up dependencies for this control object 143 413 : auto it = std::find(_control_data_depends_on.begin(), _control_data_depends_on.end(), data_name); 144 413 : if (it == _control_data_depends_on.end()) 145 413 : _control_data_depends_on.push_back(data_name); 146 : 147 413 : return data_ptr->get(); 148 : } 149 : 150 : template <typename T> 151 : const T & 152 97 : THMControl::getControlDataOldByName(const std::string & data_name) 153 : { 154 97 : ControlData<T> * data_ptr = _sim->getControlData<T>(data_name); 155 97 : if (data_ptr == nullptr) 156 0 : mooseError("Trying to get control data '", 157 : data_name, 158 : "', but it does not exist in the system. Check your spelling."); 159 : 160 97 : return data_ptr->getOld(); 161 : } 162 : 163 : template <typename T> 164 : const T & 165 97 : THMControl::getComponentControlDataOld(const std::string & data_name) 166 : { 167 97 : std::string full_name = name() + ":" + data_name; 168 194 : return getControlDataOldByName<T>(full_name); 169 : }