www.mooseframework.org
Public Member Functions | 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...
 
std::vector< std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > > _input_parameters
 Storage for the InputParameters objects. More...
 
std::map< MooseObjectParameterName, std::vector< MooseObjectParameterName > > _input_parameter_links
 InputParameter links. More...
 
std::map< std::shared_ptr< InputParameters >, std::set< MooseObjectParameterName > > _controlled_parameters
 A list of parameters that were controlled (only used for output) More...
 
class Factory
 
class ActionFactory
 
class Control
 
class ControlOutput
 
class Component
 
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
 
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...
 
template<typename T >
ControllableParameter< T > getControllableParameter (const MooseObjectParameterName &desired, bool mark_as_controlled=false)
 Returns a ControllableParameter object. More...
 
void addControllableParameterConnection (const MooseObjectParameterName &master, const MooseObjectParameterName &slave)
 Method for linking control parameters of different names. More...
 
InputParametersaddInputParameters (const std::string &name, InputParameters parameters, THREAD_ID tid=0)
 Method for adding a new InputParameters object. More...
 
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
 
const std::map< std::shared_ptr< InputParameters >, std::set< MooseObjectParameterName > > & getControlledParameters ()
 Return the list of controlled parameters (used for output) More...
 
void clearControlledParameters ()
 

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.

Definition at line 33 of file InputParameterWarehouse.h.

Constructor & Destructor Documentation

InputParameterWarehouse::InputParameterWarehouse ( )

Class constructor.

Definition at line 19 of file InputParameterWarehouse.C.

19 : _input_parameters(libMesh::n_threads()) {}
std::vector< std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > > _input_parameters
Storage for the InputParameters objects.
virtual InputParameterWarehouse::~InputParameterWarehouse ( )
virtualdefault

Destruction.

Member Function Documentation

void InputParameterWarehouse::addControllableParameterConnection ( const MooseObjectParameterName master,
const MooseObjectParameterName slave 
)

Method for linking control parameters of different names.

Definition at line 127 of file InputParameterWarehouse.C.

Referenced by FEProblemBase::addMaterial().

129 {
130  _input_parameter_links[master].push_back(slave);
131 }
std::map< MooseObjectParameterName, std::vector< MooseObjectParameterName > > _input_parameter_links
InputParameter links.
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 22 of file InputParameterWarehouse.C.

Referenced by Factory::create().

25 {
26  // Error if the name contains "::"
27  if (name.find("::") != std::string::npos)
28  mooseError("The object name may not contain '::' in the name: ", name);
29 
30  // Create the actual InputParameters object that will be reference by the objects
31  std::shared_ptr<InputParameters> ptr = std::make_shared<InputParameters>(parameters);
32 
33  // Set the name parameter to the object being created
34  ptr->set<std::string>("_object_name") = name;
35 
36  // The object name defined by the base class name, this method of storing is used for
37  // determining the uniqueness of the name
38  MooseObjectName unique_name(ptr->get<std::string>("_moose_base"), name, "::");
39 
40  // Check that the Parameters do not already exist
41  if (_input_parameters[tid].find(unique_name) != _input_parameters[tid].end())
42  mooseError("A '",
43  unique_name.tag(),
44  "' object already exists with the name '",
45  unique_name.name(),
46  "'.\n");
47 
48  // Store the parameters according to the base name
49  _input_parameters[tid].insert(
50  std::pair<MooseObjectName, std::shared_ptr<InputParameters>>(unique_name, ptr));
51 
52  // Store the object according to the control tags
53  if (ptr->isParamValid("control_tags"))
54  {
55  const std::vector<std::string> & tags = ptr->get<std::vector<std::string>>("control_tags");
56  for (const auto & tag : tags)
57  {
58  if (!tag.empty())
59  _input_parameters[tid].insert(std::pair<MooseObjectName, std::shared_ptr<InputParameters>>(
60  MooseObjectName(tag, name), ptr));
61  }
62  }
63 
64  // Set the name and tid parameters
65  ptr->addPrivateParam<THREAD_ID>("_tid", tid);
66  ptr->allowCopy(false); // no more copies allowed
67 
68  // Return a reference to the InputParameters object
69  return *ptr;
70 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::vector< std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > > _input_parameters
Storage for the InputParameters objects.
A class for storing the names of MooseObject by tag and object name.
unsigned int THREAD_ID
Definition: MooseTypes.h:79
void InputParameterWarehouse::clearControlledParameters ( )
inlineprivate

Definition at line 139 of file InputParameterWarehouse.h.

Referenced by ControlOutput::outputChangedControls().

139 { _controlled_parameters.clear(); }
std::map< std::shared_ptr< InputParameters >, std::set< MooseObjectParameterName > > _controlled_parameters
A list of parameters that were controlled (only used for output)
template<typename T >
ControllableParameter< T > InputParameterWarehouse::getControllableParameter ( const MooseObjectParameterName desired,
bool  mark_as_controlled = false 
)

Returns a ControllableParameter object.

See also
Control

Definition at line 152 of file InputParameterWarehouse.h.

Referenced by Control::getControllableParameterHelper().

154 {
155 
156  // The ControllableParameter object to return
158 
159  // Vector of desired parameters
160  std::vector<MooseObjectParameterName> params(1, input);
161  const auto link_it = _input_parameter_links.find(input);
162 
163  // Add connected parameters
164  if (link_it != _input_parameter_links.end())
165  params.insert(params.end(), link_it->second.begin(), link_it->second.end());
166 
167  // Loop over all threads
168  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); ++tid)
169  {
170  // Loop over all InputParameter objects
171  for (const auto & param_pair : _input_parameters[tid])
172  {
173  // Loop of all desired params
174  for (const auto & param : params)
175  {
176  // If the desired object name does not match the current object name, move on
177  MooseObjectParameterName desired = param;
178 
179  if (desired != param_pair.first)
180  continue;
181 
182  // If the parameter is valid and controllable update the output vector with a pointer to the
183  // parameter
184  if (param_pair.second->libMesh::Parameters::have_parameter<T>(desired.parameter()))
185  {
186  // Do not allow non-controllable types to be controlled
187  if (!param_pair.second->isControllable(desired.parameter()))
188  mooseError("The desired parameter is not controllable: ", desired);
189 
190  // Store pointer to the writable parameter
191  output.insert(desired, param_pair.second);
192 
193  if (mark_as_controlled && tid == 0)
194  _controlled_parameters[param_pair.second].insert(desired);
195  }
196  }
197  }
198  }
199 
200  // Error if nothing was found
201  if (output.size() == 0)
202  mooseError("The controlled parameter was not found: ", input);
203 
204  return output;
205 }
std::map< MooseObjectParameterName, std::vector< MooseObjectParameterName > > _input_parameter_links
InputParameter links.
const std::string & parameter() const
Return the parameter name.
A class for accessing controllable InputParameters.
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
void insert(const MooseObjectParameterName &name, std::shared_ptr< InputParameters > param_object)
Adds a parameter to the container.
std::map< std::shared_ptr< InputParameters >, std::set< MooseObjectParameterName > > _controlled_parameters
A list of parameters that were controlled (only used for output)
std::vector< std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > > _input_parameters
Storage for the InputParameters objects.
std::size_t size() const
The number of parameters contained in the class.
A class for storing an input parameter name.
unsigned int THREAD_ID
Definition: MooseTypes.h:79
const std::map<std::shared_ptr<InputParameters>, std::set<MooseObjectParameterName> >& InputParameterWarehouse::getControlledParameters ( )
inlineprivate

Return the list of controlled parameters (used for output)

See also
ControlOutput

Definition at line 135 of file InputParameterWarehouse.h.

Referenced by ControlOutput::outputChangedControls().

136  {
137  return _controlled_parameters;
138  }
std::map< std::shared_ptr< InputParameters >, std::set< MooseObjectParameterName > > _controlled_parameters
A list of parameters that were controlled (only used for output)
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 121 of file InputParameterWarehouse.C.

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

122 {
123  return _input_parameters[tid];
124 }
std::vector< std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > > _input_parameters
Storage for the InputParameters objects.
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 94 of file InputParameterWarehouse.C.

95 {
96  return getInputParameters(MooseObjectName(name), tid);
97 }
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.
InputParameters & InputParameterWarehouse::getInputParameters ( const std::string &  tag,
const std::string &  name,
THREAD_ID  tid = 0 
) const
private

Definition at line 100 of file InputParameterWarehouse.C.

103 {
104  return getInputParameters(MooseObjectName(tag, name), tid);
105 }
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.
InputParameters & InputParameterWarehouse::getInputParameters ( const MooseObjectName object_name,
THREAD_ID  tid = 0 
) const
private

Definition at line 108 of file InputParameterWarehouse.C.

110 {
111  // Locate the InputParameters object and error if it was not located
112  const auto iter = _input_parameters[tid].find(object_name);
113  if (iter == _input_parameters[tid].end())
114  mooseError("Unknown InputParameters object ", object_name);
115 
116  // Return a reference to the parameter
117  return *(iter->second.get());
118 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::vector< std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > > _input_parameters
Storage for the InputParameters objects.
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 73 of file InputParameterWarehouse.C.

74 {
75  return getInputParameters(MooseObjectName(name), tid);
76 }
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.
const InputParameters & InputParameterWarehouse::getInputParametersObject ( const std::string &  tag,
const std::string &  name,
THREAD_ID  tid = 0 
) const

Definition at line 79 of file InputParameterWarehouse.C.

82 {
83  return getInputParameters(MooseObjectName(tag, name), tid);
84 }
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.
const InputParameters & InputParameterWarehouse::getInputParametersObject ( const MooseObjectName object_name,
THREAD_ID  tid = 0 
) const

Definition at line 87 of file InputParameterWarehouse.C.

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

Friends And Related Function Documentation

friend class ActionFactory
friend

Definition at line 142 of file InputParameterWarehouse.h.

friend class Component
friend

Definition at line 147 of file InputParameterWarehouse.h.

friend class Control
friend

Definition at line 143 of file InputParameterWarehouse.h.

friend class ControlOutput
friend

Definition at line 144 of file InputParameterWarehouse.h.

friend class Factory
friend

Definition at line 141 of file InputParameterWarehouse.h.

Member Data Documentation

std::map<std::shared_ptr<InputParameters>, std::set<MooseObjectParameterName> > InputParameterWarehouse::_controlled_parameters
private

A list of parameters that were controlled (only used for output)

Definition at line 92 of file InputParameterWarehouse.h.

Referenced by clearControlledParameters(), getControllableParameter(), and getControlledParameters().

std::map<MooseObjectParameterName, std::vector<MooseObjectParameterName> > InputParameterWarehouse::_input_parameter_links
private

InputParameter links.

Definition at line 88 of file InputParameterWarehouse.h.

Referenced by addControllableParameterConnection(), and getControllableParameter().

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

Storage for the InputParameters objects.

Definition at line 85 of file InputParameterWarehouse.h.

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


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