Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
ChainControlDataSystem.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 "ChainControlData.h"
13 #include "MooseError.h"
14 #include "MooseUtils.h"
15 
16 class ChainControl;
17 
24 {
25 public:
27 
34  bool hasChainControlData(const std::string & data_name) const;
35 
43  template <typename T>
44  bool hasChainControlDataOfType(const std::string & data_name) const;
45 
55  template <typename T>
56  ChainControlData<T> & getChainControlData(const std::string & data_name);
57 
69  template <typename T>
70  ChainControlData<T> & declareChainControlData(const std::string & data_name,
71  ChainControl & chain_control);
72 
76  void copyValuesBack();
77 
81  const std::map<std::string, std::unique_ptr<ChainControlDataBase>> &
82  getChainControlDataMap() const;
83 
84 private:
87 
89  std::map<std::string, std::unique_ptr<ChainControlDataBase>> _chain_control_data_map;
90 };
91 
92 template <typename T>
93 bool
94 ChainControlDataSystem::hasChainControlDataOfType(const std::string & data_name) const
95 {
96  if (hasChainControlData(data_name))
97  return dynamic_cast<ChainControlData<T> *>(_chain_control_data_map.at(data_name).get()) !=
98  nullptr;
99  else
100  return false;
101 }
102 
103 template <typename T>
105 ChainControlDataSystem::getChainControlData(const std::string & data_name)
106 {
107  if (hasChainControlData(data_name))
108  {
109  if (!hasChainControlDataOfType<T>(data_name))
110  mooseError("The chain control data '",
111  data_name,
112  "' was requested with the type '",
113  MooseUtils::prettyCppType<T>(),
114  "' but has the type '",
115  _chain_control_data_map[data_name]->type(),
116  "'.");
117  }
118  else
119  _chain_control_data_map[data_name] = std::make_unique<ChainControlData<T>>(_app, data_name);
120 
121  return static_cast<ChainControlData<T> &>(*_chain_control_data_map[data_name]);
122 }
123 
124 template <typename T>
127  ChainControl & chain_control)
128 {
129  auto & data = getChainControlData<T>(data_name);
130  if (!data.getDeclared())
131  {
132  data.setDeclared();
133  data.setChainControl(chain_control);
134  }
135  else
136  mooseError("The chain control data '", data_name, "' has already been declared.");
137 
138  return data;
139 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
ChainControlDataSystem(MooseApp &app)
Base class for MOOSE-based applications.
Definition: MooseApp.h:85
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...
void copyValuesBack()
Copies current chain control data values into old values.
std::map< std::string, std::unique_ptr< ChainControlDataBase > > _chain_control_data_map
Map of chain control data name to its value.
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...
MooseApp & _app
The MooseApp that owns this system.
bool hasChainControlData(const std::string &data_name) const
Queries if the chain control data of the given name exists.
bool hasChainControlDataOfType(const std::string &data_name) const
Queries if the chain control data of the given name and type exists.
System that manages ChainControls.
Concrete definition of a parameter value for a specified type.
const std::map< std::string, std::unique_ptr< ChainControlDataBase > > & getChainControlDataMap() const
Gets the map of ChainControlData names to the relevant ChainControlDataBase.
Control that additionally provides the capability to produce/consume data values, to allow control op...
Definition: ChainControl.h:21