www.mooseframework.org
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
InputParameterWarehouse Class Reference

Storage container for all InputParamter objects. More...

#include <InputParameterWarehouse.h>

Public Member Functions

 InputParameterWarehouse ()
 Class constructor. More...
 
virtual ~InputParameterWarehouse ()=default
 Destruction. More...
 
const std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > & getInputParameters (THREAD_ID tid=0) const
 Return const reference to the map containing the InputParameter objects. More...
 
void addControllableParameterConnection (const MooseObjectParameterName &master, const MooseObjectParameterName &slave, bool error_on_empty=true)
 Method for linking control parameters of different names. More...
 
void addControllableParameterAlias (const MooseObjectParameterName &alias, const MooseObjectParameterName &slave)
 Method for creating alias to an existing controllable parameters. More...
 
std::string dumpChangedControls (bool reset_changed) const
 
template<typename T >
std::vector< T > getControllableParameterValues (const MooseObjectParameterName &input) const
 Returns a copy of the current values for a controllable parameter. More...
 
const InputParametersgetInputParametersObject (const std::string &name, THREAD_ID tid=0) const
 Return a const reference to the InputParameters for the named object. More...
 
const InputParametersgetInputParametersObject (const std::string &tag, const std::string &name, THREAD_ID tid=0) const
 
const InputParametersgetInputParametersObject (const MooseObjectName &object_name, THREAD_ID tid=0) const
 

Private Member Functions

InputParametersaddInputParameters (const std::string &name, InputParameters parameters, THREAD_ID tid=0)
 Method for adding a new InputParameters object. More...
 
void removeInputParameters (const MooseObject &moose_object, THREAD_ID tid=0)
 Allows for the deletion and cleanup of an object while the simulation is running. More...
 
ControllableParameter getControllableParameter (const MooseObjectParameterName &input) const
 Returns a ControllableParameter object that contains all matches to ControllableItem objects for the provided name. More...
 
std::vector< ControllableItem * > getControllableItems (const MooseObjectParameterName &desired, THREAD_ID tid=0) const
 Returns a ControllableItem iterator, if the name is located. More...
 
 FRIEND_TEST (InputParameterWarehouse, getControllableItems)
 
 FRIEND_TEST (InputParameterWarehouse, getControllableParameter)
 
 FRIEND_TEST (InputParameterWarehouse, getControllableParameterValues)
 
 FRIEND_TEST (InputParameterWarehouse, addControllableParameterConnection)
 
 FRIEND_TEST (InputParameterWarehouse, addControllableParameterAlias)
 
InputParametersgetInputParameters (const std::string &name, THREAD_ID tid=0) const
 Return a reference to the InputParameters for the named object. More...
 
InputParametersgetInputParameters (const std::string &tag, const std::string &name, THREAD_ID tid=0) const
 
InputParametersgetInputParameters (const MooseObjectName &object_name, THREAD_ID tid=0) const
 

Private Attributes

std::vector< std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > > _input_parameters
 Storage for the InputParameters objects TODO: Remove multimap. More...
 
std::vector< std::vector< std::shared_ptr< ControllableItem > > > _controllable_items
 Storage for controllable parameters via ControllableItem objects, a unique_ptr is used to avoid creating multiple copies. More...
 

Friends

class Control
 Only controls are allowed to call getControllableParameter. More...
 
MooseObjectPtr Factory::create (const std::string &, const std::string &, InputParameters, THREAD_ID, bool)
 
void Factory::releaseSharedObjects (const MooseObject &, THREAD_ID)
 

Detailed Description

Storage container for all InputParamter objects.

This object is responsible for InputParameter objects, all MooseObjects should contain a reference to the parameters object stored here.

To avoid abuse, this warehouse is also designed to restrict the ability to change the parameter to Control objects only.

Definition at line 33 of file InputParameterWarehouse.h.

Constructor & Destructor Documentation

◆ InputParameterWarehouse()

InputParameterWarehouse::InputParameterWarehouse ( )

Class constructor.

Definition at line 14 of file InputParameterWarehouse.C.

15  : _input_parameters(libMesh::n_threads()), _controllable_items(libMesh::n_threads())
16 {
17 }
std::vector< std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > > _input_parameters
Storage for the InputParameters objects TODO: Remove multimap.
std::vector< std::vector< std::shared_ptr< ControllableItem > > > _controllable_items
Storage for controllable parameters via ControllableItem objects, a unique_ptr is used to avoid creat...

◆ ~InputParameterWarehouse()

virtual InputParameterWarehouse::~InputParameterWarehouse ( )
virtualdefault

Destruction.

Member Function Documentation

◆ addControllableParameterAlias()

void InputParameterWarehouse::addControllableParameterAlias ( const MooseObjectParameterName alias,
const MooseObjectParameterName slave 
)

Method for creating alias to an existing controllable parameters.

Parameters
aliasThe new name to serve as an alias.
slaveThe name of the slave parameter to be aliased.

Definition at line 183 of file InputParameterWarehouse.C.

185 {
186  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); ++tid)
187  {
188  std::vector<ControllableItem *> slaves = getControllableItems(slave, tid);
189  if (slaves.empty() && tid == 0) // some objects only exist on tid 0
190  mooseError("Unable to locate slave parameter with name ", slave);
191 
192  for (auto slave_ptr : slaves)
193  _controllable_items[tid].emplace_back(
194  libmesh_make_unique<ControllableAlias>(alias, slave_ptr));
195  }
196 }
std::vector< ControllableItem * > getControllableItems(const MooseObjectParameterName &desired, THREAD_ID tid=0) const
Returns a ControllableItem iterator, if the name is located.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
std::vector< std::vector< std::shared_ptr< ControllableItem > > > _controllable_items
Storage for controllable parameters via ControllableItem objects, a unique_ptr is used to avoid creat...
unsigned int THREAD_ID
Definition: MooseTypes.h:97

◆ addControllableParameterConnection()

void InputParameterWarehouse::addControllableParameterConnection ( const MooseObjectParameterName master,
const MooseObjectParameterName slave,
bool  error_on_empty = true 
)

Method for linking control parameters of different names.

Definition at line 157 of file InputParameterWarehouse.C.

Referenced by FEProblemBase::addMaterialHelper().

160 {
161  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); ++tid)
162  {
163  std::vector<ControllableItem *> masters = getControllableItems(master, tid);
164  if (masters.empty() && error_on_empty && tid == 0) // some objects only exist on tid 0
165  mooseError("Unable to locate master parameter with name ", master);
166  else if (masters.empty())
167  return;
168 
169  std::vector<ControllableItem *> slaves = getControllableItems(slave, tid);
170  if (slaves.empty() && error_on_empty && tid == 0) // some objects only exist on tid 0
171  mooseError("Unable to locate slave parameter with name ", slave);
172  else if (slaves.empty())
173  return;
174 
175  for (auto master_ptr : masters)
176  for (auto slave_ptr : slaves)
177  if (master_ptr != slave_ptr)
178  master_ptr->connect(slave_ptr);
179  }
180 }
std::vector< ControllableItem * > getControllableItems(const MooseObjectParameterName &desired, THREAD_ID tid=0) const
Returns a ControllableItem iterator, if the name is located.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
unsigned int THREAD_ID
Definition: MooseTypes.h:97

◆ addInputParameters()

InputParameters & InputParameterWarehouse::addInputParameters ( const std::string &  name,
InputParameters  parameters,
THREAD_ID  tid = 0 
)
private

Method for adding a new InputParameters object.

Parameters
parametersThe InputParameters object to copy and store in the warehouse
Returns
A reference to the warehouse copy of the InputParameters, this is what should be passed into the MooseObjects constructors.

A new object is created from the old object because InputParameters objects are generic until Factory::create() is called and the actual MooseObject is created.

This method is private, because only the factories that are creating objects should be able to call this method.

Definition at line 20 of file InputParameterWarehouse.C.

Referenced by Factory::create().

23 {
24  // Error if the name contains "::"
25  if (name.find("::") != std::string::npos)
26  mooseError("The object name may not contain '::' in the name: ", name);
27 
28  // Create the actual InputParameters object that will be reference by the objects
29  std::shared_ptr<InputParameters> ptr = std::make_shared<InputParameters>(parameters);
30 
31  // The object name defined by the base class name, this method of storing is used for
32  // determining the uniqueness of the name
33  MooseObjectName unique_name(ptr->get<std::string>("_moose_base"), name, "::");
34 
35  // Check that the Parameters do not already exist
36  if (_input_parameters[tid].find(unique_name) != _input_parameters[tid].end())
37  mooseError("A '",
38  unique_name.tag(),
39  "' object already exists with the name '",
40  unique_name.name(),
41  "'.\n");
42 
43  // Store the parameters according to the base name
44  _input_parameters[tid].insert(
45  std::pair<MooseObjectName, std::shared_ptr<InputParameters>>(unique_name, ptr));
46 
47  // Build a list of object names
48  std::vector<MooseObjectName> object_names;
49  object_names.push_back(unique_name);
50 
51  // Store the object according to the control tags
52  if (ptr->isParamValid("control_tags"))
53  {
54  const std::vector<std::string> & tags = ptr->get<std::vector<std::string>>("control_tags");
55  for (const auto & tag : tags)
56  {
57  if (!tag.empty())
58  {
59  _input_parameters[tid].insert(std::pair<MooseObjectName, std::shared_ptr<InputParameters>>(
60  MooseObjectName(tag, name), ptr));
61  object_names.emplace_back(tag, name);
62  }
63  }
64  }
65 
66  // Store controllable parameters using all possible names
67  for (libMesh::Parameters::iterator map_iter = ptr->begin(); map_iter != ptr->end(); ++map_iter)
68  {
69  const std::string & name = map_iter->first;
70  libMesh::Parameters::Value * value = map_iter->second;
71 
72  if (ptr->isControllable(name))
73  for (const auto & object_name : object_names)
74  {
75  MooseObjectParameterName param_name(object_name, name);
76  _controllable_items[tid].emplace_back(
77  std::make_shared<ControllableItem>(param_name, value));
78  }
79  }
80 
81  // Set the name and tid parameters, and unique_name
82  std::stringstream oss;
83  oss << unique_name;
84 
85  ptr->addPrivateParam<std::string>("_unique_name", oss.str());
86  ptr->addPrivateParam<std::string>("_object_name", name);
87  ptr->addPrivateParam<THREAD_ID>("_tid", tid);
88  ptr->allowCopy(false); // no more copies allowed
89 
90  // Return a reference to the InputParameters object
91  return *ptr;
92 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
std::vector< std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > > _input_parameters
Storage for the InputParameters objects TODO: Remove multimap.
A class for storing an input parameter name.
A class for storing the names of MooseObject by tag and object name.
std::vector< std::vector< std::shared_ptr< ControllableItem > > > _controllable_items
Storage for controllable parameters via ControllableItem objects, a unique_ptr is used to avoid creat...
unsigned int THREAD_ID
Definition: MooseTypes.h:97

◆ dumpChangedControls()

std::string InputParameterWarehouse::dumpChangedControls ( bool  reset_changed) const

Definition at line 221 of file InputParameterWarehouse.C.

Referenced by ControlOutput::outputChangedControls().

222 {
223  std::stringstream oss;
224  oss << std::left;
225 
226  for (const auto & item : _controllable_items[0])
227  if (item->isChanged())
228  {
229  oss << item->dump(4);
230  if (reset_changed)
231  item->resetChanged();
232  }
233  return oss.str();
234 }
std::vector< std::vector< std::shared_ptr< ControllableItem > > > _controllable_items
Storage for controllable parameters via ControllableItem objects, a unique_ptr is used to avoid creat...

◆ FRIEND_TEST() [1/5]

InputParameterWarehouse::FRIEND_TEST ( InputParameterWarehouse  ,
getControllableItems   
)
private

◆ FRIEND_TEST() [2/5]

InputParameterWarehouse::FRIEND_TEST ( InputParameterWarehouse  ,
getControllableParameter   
)
private

◆ FRIEND_TEST() [3/5]

InputParameterWarehouse::FRIEND_TEST ( InputParameterWarehouse  ,
getControllableParameterValues   
)
private

◆ FRIEND_TEST() [4/5]

InputParameterWarehouse::FRIEND_TEST ( InputParameterWarehouse  ,
addControllableParameterConnection   
)
private

◆ FRIEND_TEST() [5/5]

InputParameterWarehouse::FRIEND_TEST ( InputParameterWarehouse  ,
addControllableParameterAlias   
)
private

◆ getControllableItems()

std::vector< ControllableItem * > InputParameterWarehouse::getControllableItems ( const MooseObjectParameterName desired,
THREAD_ID  tid = 0 
) const
private

Returns a ControllableItem iterator, if the name is located.

See also
Control

Definition at line 199 of file InputParameterWarehouse.C.

Referenced by addControllableParameterAlias(), and addControllableParameterConnection().

201 {
202  std::vector<ControllableItem *> output;
203  for (auto & ptr : _controllable_items[tid])
204  if (ptr->name() == input)
205  output.push_back(ptr.get());
206  return output;
207 }
std::vector< std::vector< std::shared_ptr< ControllableItem > > > _controllable_items
Storage for controllable parameters via ControllableItem objects, a unique_ptr is used to avoid creat...

◆ getControllableParameter()

ControllableParameter InputParameterWarehouse::getControllableParameter ( const MooseObjectParameterName input) const
private

Returns a ControllableParameter object that contains all matches to ControllableItem objects for the provided name.

This is private because it should only be accessed via a Control object.

Definition at line 210 of file InputParameterWarehouse.C.

Referenced by Control::getControllableParameterByName(), and getControllableParameterValues().

211 {
212  ControllableParameter cparam;
213  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); ++tid)
214  for (auto it = _controllable_items[tid].begin(); it != _controllable_items[tid].end(); ++it)
215  if ((*it)->name() == input)
216  cparam.add(it->get());
217  return cparam;
218 }
The ControllableParameter class is simply a set of ControllableItem objects.
void add(ControllableItem *item)
Adds the supplied item with the other items within this object.
std::vector< std::vector< std::shared_ptr< ControllableItem > > > _controllable_items
Storage for controllable parameters via ControllableItem objects, a unique_ptr is used to avoid creat...
unsigned int THREAD_ID
Definition: MooseTypes.h:97

◆ getControllableParameterValues()

template<typename T >
std::vector< T > InputParameterWarehouse::getControllableParameterValues ( const MooseObjectParameterName input) const

Returns a copy of the current values for a controllable parameter.

This method is designed to provide access to objects for monitoring the state of a controllable parameter.

Definition at line 188 of file InputParameterWarehouse.h.

190 {
192  return param.get<T>();
193 }
The ControllableParameter class is simply a set of ControllableItem objects.
ControllableParameter getControllableParameter(const MooseObjectParameterName &input) const
Returns a ControllableParameter object that contains all matches to ControllableItem objects for the ...
std::vector< T > get(bool type_check=true, bool warn_when_values_difffer=false) const
Return a copy of the values of the given type.

◆ getInputParameters() [1/4]

const std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > & InputParameterWarehouse::getInputParameters ( THREAD_ID  tid = 0) const

Return const reference to the map containing the InputParameter objects.

Definition at line 151 of file InputParameterWarehouse.C.

Referenced by getInputParameters(), getInputParametersObject(), ControlOutput::outputActiveObjects(), and ControlOutput::outputControls().

152 {
153  return _input_parameters[tid];
154 }
std::vector< std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > > _input_parameters
Storage for the InputParameters objects TODO: Remove multimap.

◆ getInputParameters() [2/4]

InputParameters & InputParameterWarehouse::getInputParameters ( const std::string &  name,
THREAD_ID  tid = 0 
) const
private

Return a reference to the InputParameters for the named object.

Parameters
tagThe tag of the object (e.g., 'Kernel')
nameThe name of the parameters object, including the tag (name only input) or MooseObjectName object
tidThe thread id
Returns
A reference to the warehouse copy of the InputParameters

If you are using this method to access a writable reference to input parameters, this will break the ability to control the parameters with the MOOSE control logic system. Only change parameters if you know what you are doing. Hence, this is private for a reason.

Definition at line 124 of file InputParameterWarehouse.C.

125 {
126  return getInputParameters(MooseObjectName(name), tid);
127 }
const std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > & getInputParameters(THREAD_ID tid=0) const
Return const reference to the map containing the InputParameter objects.
A class for storing the names of MooseObject by tag and object name.

◆ getInputParameters() [3/4]

InputParameters & InputParameterWarehouse::getInputParameters ( const std::string &  tag,
const std::string &  name,
THREAD_ID  tid = 0 
) const
private

Definition at line 130 of file InputParameterWarehouse.C.

133 {
134  return getInputParameters(MooseObjectName(tag, name), tid);
135 }
const std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > & getInputParameters(THREAD_ID tid=0) const
Return const reference to the map containing the InputParameter objects.
A class for storing the names of MooseObject by tag and object name.

◆ getInputParameters() [4/4]

InputParameters & InputParameterWarehouse::getInputParameters ( const MooseObjectName object_name,
THREAD_ID  tid = 0 
) const
private

Definition at line 138 of file InputParameterWarehouse.C.

140 {
141  // Locate the InputParameters object and error if it was not located
142  const auto iter = _input_parameters[tid].find(object_name);
143  if (iter == _input_parameters[tid].end())
144  mooseError("Unknown InputParameters object ", object_name);
145 
146  // Return a reference to the parameter
147  return *(iter->second.get());
148 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
std::vector< std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > > _input_parameters
Storage for the InputParameters objects TODO: Remove multimap.

◆ getInputParametersObject() [1/3]

const InputParameters & InputParameterWarehouse::getInputParametersObject ( const std::string &  name,
THREAD_ID  tid = 0 
) const

Return a const reference to the InputParameters for the named object.

Parameters
tagThe tag of the object (e.g., 'Kernel')
nameThe name of the parameters object, including the tag (name only input) or MooseObjectName object
tidThe thread id
Returns
A const reference to the warehouse copy of the InputParameters

Definition at line 103 of file InputParameterWarehouse.C.

104 {
105  return getInputParameters(MooseObjectName(name), tid);
106 }
const std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > & getInputParameters(THREAD_ID tid=0) const
Return const reference to the map containing the InputParameter objects.
A class for storing the names of MooseObject by tag and object name.

◆ getInputParametersObject() [2/3]

const InputParameters & InputParameterWarehouse::getInputParametersObject ( const std::string &  tag,
const std::string &  name,
THREAD_ID  tid = 0 
) const

Definition at line 109 of file InputParameterWarehouse.C.

112 {
113  return getInputParameters(MooseObjectName(tag, name), tid);
114 }
const std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > & getInputParameters(THREAD_ID tid=0) const
Return const reference to the map containing the InputParameter objects.
A class for storing the names of MooseObject by tag and object name.

◆ getInputParametersObject() [3/3]

const InputParameters & InputParameterWarehouse::getInputParametersObject ( const MooseObjectName object_name,
THREAD_ID  tid = 0 
) const

Definition at line 117 of file InputParameterWarehouse.C.

119 {
120  return getInputParameters(object_name, tid);
121 }
const std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > & getInputParameters(THREAD_ID tid=0) const
Return const reference to the map containing the InputParameter objects.

◆ removeInputParameters()

void InputParameterWarehouse::removeInputParameters ( const MooseObject moose_object,
THREAD_ID  tid = 0 
)
private

Allows for the deletion and cleanup of an object while the simulation is running.

Definition at line 95 of file InputParameterWarehouse.C.

Referenced by Factory::releaseSharedObjects().

96 {
97  auto moose_object_name_string = moose_object.parameters().get<std::string>("_unique_name");
98  MooseObjectName moose_object_name(moose_object_name_string);
99  _input_parameters[tid].erase(moose_object_name);
100 }
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:57
std::vector< std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > > _input_parameters
Storage for the InputParameters objects TODO: Remove multimap.
A class for storing the names of MooseObject by tag and object name.

Friends And Related Function Documentation

◆ Control

friend class Control
friend

Only controls are allowed to call getControllableParameter.

The Control::getControllableParameter is the only method that calls getControllableParameter. However, this method cannot be made a friend explicitly because the method would need to be public. If the method is public then it is possible to call the method by getting access to the Control object.

Definition at line 176 of file InputParameterWarehouse.h.

◆ Factory::create

MooseObjectPtr Factory::create ( const std::string &  ,
const std::string &  ,
InputParameters  ,
THREAD_ID  ,
bool   
)
friend

The factory is allowed to call addInputParameters and removeInputParameters.

◆ Factory::releaseSharedObjects

void Factory::releaseSharedObjects ( const MooseObject ,
THREAD_ID   
)
friend

Member Data Documentation

◆ _controllable_items

std::vector<std::vector<std::shared_ptr<ControllableItem> > > InputParameterWarehouse::_controllable_items
private

Storage for controllable parameters via ControllableItem objects, a unique_ptr is used to avoid creating multiple copies.

All access to the objects are done via pointers. The ControllableItem objects are not designed and will not be used directly in user code. All user level access goes through the ControllableParameter object.

Definition at line 106 of file InputParameterWarehouse.h.

Referenced by addControllableParameterAlias(), addInputParameters(), dumpChangedControls(), getControllableItems(), and getControllableParameter().

◆ _input_parameters

std::vector<std::multimap<MooseObjectName, std::shared_ptr<InputParameters> > > InputParameterWarehouse::_input_parameters
private

Storage for the InputParameters objects TODO: Remove multimap.

Definition at line 100 of file InputParameterWarehouse.h.

Referenced by addInputParameters(), getInputParameters(), and removeInputParameters().


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