https://mooseframework.inl.gov
Loading...
Searching...
No Matches
THMControl.h
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#pragma once
11
12#include "Control.h"
13#include "ControlData.h"
14#include "THMProblem.h"
15
16class THMControl : public Control
17{
18public:
20
21 virtual void init() {}
22
26 const std::vector<std::string> & getControlDataDependencies() const
27 {
29 }
30
31protected:
37 template <typename T>
38 T & declareComponentControlData(const std::string & data_name);
39
45 template <typename T>
46 T & declareControlData(const std::string & data_name);
47
53 template <typename T>
54 const T & getControlData(const std::string & param_name);
55
62 template <typename T>
63 const T & getControlDataOld(const std::string & param_name);
64
70 template <typename T>
71 const T & getControlDataByName(const std::string & data_name);
72
79 template <typename T>
80 const T & getControlDataOldByName(const std::string & data_name);
81
87 template <typename T>
88 const T & getComponentControlDataOld(const std::string & data_name);
89
91
93 std::vector<std::string> _control_data_depends_on;
94
95public:
97};
98
99template <typename T>
100T &
101THMControl::declareComponentControlData(const std::string & data_name)
102{
103 std::string full_name = name() + ":" + data_name;
104 ControlData<T> * data_ptr = _sim->declareControlData<T>(full_name, this);
105 return data_ptr->set();
106}
107
108template <typename T>
109T &
110THMControl::declareControlData(const std::string & data_name)
111{
112 ControlData<T> * data_ptr = _sim->declareControlData<T>(data_name, this);
113 return data_ptr->set();
114}
115
116template <typename T>
117const T &
118THMControl::getControlData(const std::string & param_name)
119{
120 std::string data_name = getParam<std::string>(param_name);
121 return getControlDataByName<T>(data_name);
122}
123
124template <typename T>
125const T &
126THMControl::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
132template <typename T>
133const T &
134THMControl::getControlDataByName(const std::string & data_name)
135{
136 ControlData<T> * data_ptr = _sim->getControlData<T>(data_name);
137 if (data_ptr == nullptr)
138 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 auto it = std::find(_control_data_depends_on.begin(), _control_data_depends_on.end(), data_name);
144 if (it == _control_data_depends_on.end())
145 _control_data_depends_on.push_back(data_name);
146
147 return data_ptr->get();
148}
149
150template <typename T>
151const T &
152THMControl::getControlDataOldByName(const std::string & data_name)
153{
154 ControlData<T> * data_ptr = _sim->getControlData<T>(data_name);
155 if (data_ptr == nullptr)
156 mooseError("Trying to get control data '",
157 data_name,
158 "', but it does not exist in the system. Check your spelling.");
159
160 return data_ptr->getOld();
161}
162
163template <typename T>
164const T &
165THMControl::getComponentControlDataOld(const std::string & data_name)
166{
167 std::string full_name = name() + ":" + data_name;
168 return getControlDataOldByName<T>(full_name);
169}
const double T
Concrete definition of a parameter value for a specified type.
Definition ControlData.h:92
const T & getOld() const
const T & get() const
const InputParameters & parameters() const
const std::string & name() const
void mooseError(Args &&... args) const
ControlData< T > * declareControlData(const std::string &name, THMControl *ctrl)
Declare control data of type T and name 'name', if it does not exist it will be created.
Definition Simulation.h:311
ControlData< T > * getControlData(const std::string &name)
Get control data of type T and name 'name', if it does not exist it will be created.
Definition Simulation.h:290
std::vector< std::string > _control_data_depends_on
A list of control data that are required to run before this control may run.
Definition THMControl.h:93
static InputParameters validParams()
Definition THMControl.C:13
const T & getControlDataByName(const std::string &data_name)
Get a reference to control data that are specified by 'data_name' name.
Definition THMControl.h:134
virtual void init()
Definition THMControl.h:21
const T & getControlData(const std::string &param_name)
Get a reference to control data that are specified in the input parameter 'param_name'.
Definition THMControl.h:118
const std::vector< std::string > & getControlDataDependencies() const
Return the Controls that must run before this Control.
Definition THMControl.h:26
T & declareComponentControlData(const std::string &data_name)
Declare control data with name 'component:data_name'.
Definition THMControl.h:101
const T & getComponentControlDataOld(const std::string &data_name)
Get a reference to a component control data value from previous time step.
Definition THMControl.h:165
THMProblem * _sim
Definition THMControl.h:90
T & declareControlData(const std::string &data_name)
Declare control data with name 'data_name'.
Definition THMControl.h:110
const T & getControlDataOld(const std::string &param_name)
Get a reference to control data value from a previous time step that is specified in the input parame...
Definition THMControl.h:126
const T & getControlDataOldByName(const std::string &data_name)
Get a reference to control data value from previous time step that is specified by 'data_name' name.
Definition THMControl.h:152
Specialization of FEProblem to run with component subsystem.
Definition THMProblem.h:19