https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
16class ChainControl;
17
24{
25public:
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>> &
83
85 std::string outputChainControlMap() const;
86
87private:
90
92 std::map<std::string, std::unique_ptr<ChainControlDataBase>> _chain_control_data_map;
93};
94
95template <typename T>
96bool
97ChainControlDataSystem::hasChainControlDataOfType(const std::string & data_name) const
98{
99 if (hasChainControlData(data_name))
100 return dynamic_cast<ChainControlData<T> *>(_chain_control_data_map.at(data_name).get()) !=
101 nullptr;
102 else
103 return false;
104}
105
106template <typename T>
109{
110 if (hasChainControlData(data_name))
111 {
112 if (!hasChainControlDataOfType<T>(data_name))
113 mooseError("The chain control data '",
114 data_name,
115 "' was requested with the type '",
116 MooseUtils::prettyCppType<T>(),
117 "' but has the type '",
118 _chain_control_data_map[data_name]->type(),
119 "'.");
120 }
121 else
122 _chain_control_data_map[data_name] = std::make_unique<ChainControlData<T>>(_app, data_name);
123
124 return static_cast<ChainControlData<T> &>(*_chain_control_data_map[data_name]);
125}
126
127template <typename T>
130 ChainControl & chain_control)
131{
132 auto & data = getChainControlData<T>(data_name);
133 if (!data.getDeclared())
134 {
135 data.setDeclared();
136 data.setChainControl(chain_control);
137 }
138 else
139 mooseError("The chain control data '", data_name, "' has already been declared.");
140
141 return data;
142}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
System that manages ChainControls.
const std::map< std::string, std::unique_ptr< ChainControlDataBase > > & getChainControlDataMap() const
Gets the map of ChainControlData names to the relevant ChainControlDataBase.
void copyValuesBack()
Copies current chain control data values into old values.
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.
std::string outputChainControlMap() const
Output the chain control map to a string.
bool hasChainControlDataOfType(const std::string &data_name) const
Queries if the chain control data of the given name and type exists.
std::map< std::string, std::unique_ptr< ChainControlDataBase > > _chain_control_data_map
Map of chain control data name to its value.
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.
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.
Concrete definition of a parameter value for a specified type.
Control that additionally provides the capability to produce/consume data values, to allow control op...
Base class for MOOSE-based applications.
Definition MooseApp.h:110