https://mooseframework.inl.gov
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"
14 #include "ChainControlDataSystem.h"
15 #include "MooseUtils.h"
16 
21 class ChainControl : public Control
22 {
23 public:
25 
27 
35  virtual void init() {}
36 
40  const std::vector<std::string> & getChainControlDataDependencies() const
41  {
43  }
44 
45 protected:
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 
113 private:
118 };
119 
120 template <typename T>
121 T &
122 ChainControl::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 
129 template <typename T>
130 const T &
131 ChainControl::getChainControlData(const std::string & param)
132 {
133  return getChainControlDataByName<T>(getParam<std::string>(param));
134 }
135 
136 template <typename T>
137 const T &
138 ChainControl::getChainControlDataOld(const std::string & param)
139 {
140  return getChainControlDataOldByName<T>(getParam<std::string>(param));
141 }
142 
143 template <typename T>
144 const T &
145 ChainControl::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 
165 template <typename T>
166 const T &
167 ChainControl::getChainControlDataOldByName(const std::string & data_name)
168 {
169  auto & data = getChainControlDataSystem().getChainControlData<T>(data_name);
170 
171  return data.getOld();
172 }
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)
Definition: ChainControl.C:32
const T & getChainControlData(const std::string &param)
Get a reference to control data that are specified in the input parameter &#39;param_name&#39;.
Definition: ChainControl.h:131
ChainControlDataSystem & getChainControlDataSystem()
Retrieve the chain control data system from the MooseApp.
Definition: ChainControl.C:38
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...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
ChainControl(const InputParameters &parameters)
Definition: ChainControl.C:21
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...
const T & getChainControlDataOldByName(const std::string &data_name)
Get a reference to control data value from previous time step that is specified by &#39;data_name&#39; name...
Definition: ChainControl.h:167
static InputParameters validParams()
Definition: ChainControl.C:14
std::vector< std::string > _control_data_depends_on
List of chain control data that this control depends upon.
Definition: ChainControl.h:111
virtual void init()
Initialization that occurs in ChainControlSetupAction, right before the dependencies are added...
Definition: ChainControl.h:35
const T & getChainControlDataByName(const std::string &data_name)
Get a reference to control data that are specified by &#39;data_name&#39; name.
Definition: ChainControl.h:145
Base class for Control objects.
Definition: Control.h:33
const std::vector< std::string > & getChainControlDataDependencies() const
Returns the ChainControls that must run before this one.
Definition: ChainControl.h:40
System that manages ChainControls.
void addChainControlDataDependency(const std::string &data_name)
Adds a chain control data dependency into the list.
Definition: ChainControl.C:24
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & parameters() const
Get the parameters of the object.
T & declareChainControlData(const std::string &data_name, bool apply_object_prefix=true)
Declares chain control data with the given name and type.
Definition: ChainControl.h:122
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...
Definition: ChainControl.h:138
Control that additionally provides the capability to produce/consume data values, to allow control op...
Definition: ChainControl.h:21