https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ChainControl.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 "ChainControlData.h"
15#include "MooseUtils.h"
16
21class ChainControl : public Control
22{
23public:
25
27
35 virtual void init() {}
36
40 const std::vector<std::string> & getChainControlDataDependencies() const
41 {
43 }
44
45protected:
53 template <typename T>
54 T & declareChainControlData(const std::string & data_name, bool apply_object_prefix = true);
55
62 template <typename T>
63 const T & getChainControlData(const std::string & param);
64
72 template <typename T>
73 const T & getChainControlDataOld(const std::string & param);
74
81 template <typename T>
82 const T & getChainControlDataByName(const std::string & data_name);
83
91 template <typename T>
92 const T & getChainControlDataOldByName(const std::string & data_name);
93
99 void addChainControlDataDependency(const std::string & data_name);
100
107 std::string fullControlDataName(const std::string & data_name,
108 bool apply_object_prefix = true) const;
109
111 std::vector<std::string> _control_data_depends_on;
112
113private:
118};
119
120template <typename T>
121T &
122ChainControl::declareChainControlData(const std::string & data_name, bool apply_object_prefix)
123{
124 const std::string full_data_name = fullControlDataName(data_name, apply_object_prefix);
125 auto & data = getChainControlDataSystem().declareChainControlData<T>(full_data_name, *this);
126 return data.set();
127}
128
129template <typename T>
130const T &
131ChainControl::getChainControlData(const std::string & param)
132{
133 return getChainControlDataByName<T>(getParam<std::string>(param));
134}
135
136template <typename T>
137const T &
138ChainControl::getChainControlDataOld(const std::string & param)
139{
140 return getChainControlDataOldByName<T>(getParam<std::string>(param));
141}
142
143template <typename T>
144const T &
145ChainControl::getChainControlDataByName(const std::string & data_name)
146{
147 auto & system = getChainControlDataSystem();
148
149 if (system.hasChainControlData(data_name) && !system.hasChainControlDataOfType<T>(data_name))
150 mooseError("The chain control data '",
151 data_name,
152 "' has the type '",
153 system.getChainControlDataMap().at(data_name)->type(),
154 "', but this chain control requires its type to be '",
155 MooseUtils::prettyCppType<T>(),
156 "'.");
157
158 auto & data = system.getChainControlData<T>(data_name);
159
161
162 return data.get();
163}
164
165template <typename T>
166const T &
167ChainControl::getChainControlDataOldByName(const std::string & data_name)
168{
169 auto & data = getChainControlDataSystem().getChainControlData<T>(data_name);
170
171 return data.getOld();
172}
System that manages ChainControls.
ChainControlData< T > & getChainControlData(const std::string &data_name)
Gets the chain control data of the given name and type and creates if it does not exist.
ChainControlData< T > & declareChainControlData(const std::string &data_name, ChainControl &chain_control)
Declares chain control data of of the given name and type and creates if it does not exist.
Control that additionally provides the capability to produce/consume data values, to allow control op...
static InputParameters validParams()
const T & getChainControlDataOld(const std::string &param)
Get a reference to control data value from a previous time step that is specified in the input parame...
const T & getChainControlDataByName(const std::string &data_name)
Get a reference to control data that are specified by 'data_name' name.
const T & getChainControlData(const std::string &param)
Get a reference to control data that are specified in the input parameter 'param_name'.
virtual void init()
Initialization that occurs in ChainControlSetupAction, right before the dependencies are added.
std::string fullControlDataName(const std::string &data_name, bool apply_object_prefix=true) const
Gets the full control data name, including object name prefix (if any)
const T & getChainControlDataOldByName(const std::string &data_name)
Get a reference to control data value from previous time step that is specified by 'data_name' name.
ChainControlDataSystem & getChainControlDataSystem()
Retrieve the chain control data system from the MooseApp.
std::vector< std::string > _control_data_depends_on
List of chain control data that this control depends upon.
const std::vector< std::string > & getChainControlDataDependencies() const
Returns the ChainControls that must run before this one.
void addChainControlDataDependency(const std::string &data_name)
Adds a chain control data dependency into the list.
T & declareChainControlData(const std::string &data_name, bool apply_object_prefix=true)
Declares chain control data with the given name and type.
Base class for Control objects.
Definition Control.h:44
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271