https://mooseframework.inl.gov
Public Member Functions | Private Attributes | List of all members
ChainControlDataSystem Class Reference

System that manages ChainControls. More...

#include <ChainControlDataSystem.h>

Public Member Functions

 ChainControlDataSystem (MooseApp &app)
 
bool hasChainControlData (const std::string &data_name) const
 Queries if the chain control data of the given name exists. More...
 
template<typename T >
bool hasChainControlDataOfType (const std::string &data_name) const
 Queries if the chain control data of the given name and type exists. More...
 
template<typename T >
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. More...
 
template<typename T >
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. More...
 
void copyValuesBack ()
 Copies current chain control data values into old values. More...
 
const std::map< std::string, std::unique_ptr< ChainControlDataBase > > & getChainControlDataMap () const
 Gets the map of ChainControlData names to the relevant ChainControlDataBase. More...
 
std::string outputChainControlMap () const
 Output the chain control map to a string. More...
 

Private Attributes

MooseApp_app
 The MooseApp that owns this system. More...
 
std::map< std::string, std::unique_ptr< ChainControlDataBase > > _chain_control_data_map
 Map of chain control data name to its value. More...
 

Detailed Description

System that manages ChainControls.

To be owned by the MooseApp.

Definition at line 23 of file ChainControlDataSystem.h.

Constructor & Destructor Documentation

◆ ChainControlDataSystem()

ChainControlDataSystem::ChainControlDataSystem ( MooseApp app)

Definition at line 12 of file ChainControlDataSystem.C.

12 : _app(app) {}
MooseApp & _app
The MooseApp that owns this system.

Member Function Documentation

◆ copyValuesBack()

void ChainControlDataSystem::copyValuesBack ( )

Copies current chain control data values into old values.

Definition at line 21 of file ChainControlDataSystem.C.

Referenced by ChainControlSetupAction::act(), and FEProblemBase::advanceState().

22 {
23  for (const auto & item : _chain_control_data_map)
24  item.second->copyValuesBack();
25 }
std::map< std::string, std::unique_ptr< ChainControlDataBase > > _chain_control_data_map
Map of chain control data name to its value.

◆ declareChainControlData()

template<typename T >
ChainControlData< T > & ChainControlDataSystem::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.

If the data has already been declared, an error is thrown; otherwise the data is now set to be declared, and the declaring ChainControl is captured.

Template Parameters
TType of the data
Parameters
[in]data_nameChain control data name
[in]chain_controlChain control that is declaring the data
Returns
Reference to the declared chain control data

Definition at line 129 of file ChainControlDataSystem.h.

Referenced by ChainControl::declareChainControlData().

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:323

◆ getChainControlData()

template<typename T >
ChainControlData< T > & ChainControlDataSystem::getChainControlData ( const std::string &  data_name)

Gets the chain control data of the given name and type and creates if it does not exist.

If the data exists but of another type, then an error is thrown.

Template Parameters
TType of the data
Parameters
[in]data_nameChain control data name
Returns
Reference to the requested chain control data

Definition at line 108 of file ChainControlDataSystem.h.

Referenced by ChainControl::getChainControlDataOldByName(), and ChainControlParsedFunctionWrapper::initializeFunctionInputs().

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 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
std::map< std::string, std::unique_ptr< ChainControlDataBase > > _chain_control_data_map
Map of chain control data name to its value.
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.

◆ getChainControlDataMap()

const std::map< std::string, std::unique_ptr< ChainControlDataBase > > & ChainControlDataSystem::getChainControlDataMap ( ) const

Gets the map of ChainControlData names to the relevant ChainControlDataBase.

Definition at line 28 of file ChainControlDataSystem.C.

Referenced by ChainControlSetupAction::act().

29 {
31 }
std::map< std::string, std::unique_ptr< ChainControlDataBase > > _chain_control_data_map
Map of chain control data name to its value.

◆ hasChainControlData()

bool ChainControlDataSystem::hasChainControlData ( const std::string &  data_name) const

Queries if the chain control data of the given name exists.

Parameters
[in]data_nameChain control data name
Returns
True if the chain control data of the given name exists

Definition at line 15 of file ChainControlDataSystem.C.

Referenced by getChainControlData(), and hasChainControlDataOfType().

16 {
17  return _chain_control_data_map.find(data_name) != _chain_control_data_map.end();
18 }
std::map< std::string, std::unique_ptr< ChainControlDataBase > > _chain_control_data_map
Map of chain control data name to its value.

◆ hasChainControlDataOfType()

template<typename T >
bool ChainControlDataSystem::hasChainControlDataOfType ( const std::string &  data_name) const

Queries if the chain control data of the given name and type exists.

Template Parameters
TType of the data
Parameters
[in]data_nameChain control data name
Returns
True if the chain control data of the given name and type exists

Definition at line 97 of file ChainControlDataSystem.h.

Referenced by ChainControlParsedFunctionWrapper::initializeFunctionInputs().

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 }
std::map< std::string, std::unique_ptr< ChainControlDataBase > > _chain_control_data_map
Map of chain control data name to its value.
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.

◆ outputChainControlMap()

std::string ChainControlDataSystem::outputChainControlMap ( ) const

Output the chain control map to a string.

Definition at line 34 of file ChainControlDataSystem.C.

Referenced by ChainControlSetupAction::act(), SubProblem::initialSetup(), and SubProblem::timestepSetup().

35 {
36  std::string map_str = "Chain control data:\n";
37  for (const auto & item : _chain_control_data_map)
38  {
39  map_str += item.first + " (" + item.second->type() + ") declared? " +
40  (item.second->getDeclared() ? "true" : "false");
41  if (const auto ctl_real = dynamic_cast<ChainControlData<Real> *>(item.second.get()))
42  map_str += ". Current value: " + std::to_string(ctl_real->get());
43  else if (const auto ctl_bool = dynamic_cast<ChainControlData<bool> *>(item.second.get()))
44  map_str += ". Current value: " + std::to_string(ctl_bool->get());
45  else
46  mooseWarning("Chain control data output has not been enabled for this this data type: ",
47  item.second->type());
48  map_str += "\n";
49  }
50 
51  return map_str;
52 }
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:357
std::map< std::string, std::unique_ptr< ChainControlDataBase > > _chain_control_data_map
Map of chain control data name to its value.

Member Data Documentation

◆ _app

MooseApp& ChainControlDataSystem::_app
private

The MooseApp that owns this system.

Definition at line 89 of file ChainControlDataSystem.h.

Referenced by getChainControlData().

◆ _chain_control_data_map

std::map<std::string, std::unique_ptr<ChainControlDataBase> > ChainControlDataSystem::_chain_control_data_map
private

Map of chain control data name to its value.

Definition at line 92 of file ChainControlDataSystem.h.

Referenced by copyValuesBack(), getChainControlData(), getChainControlDataMap(), hasChainControlData(), hasChainControlDataOfType(), and outputChainControlMap().


The documentation for this class was generated from the following files: