www.mooseframework.org
InputParameterWarehouse.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 // MOOSE includes
17 #include "InputParameters.h"
18 
19 InputParameterWarehouse::InputParameterWarehouse() : _input_parameters(libMesh::n_threads()) {}
20 
23  InputParameters parameters,
24  THREAD_ID tid /* =0 */)
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 }
71 
72 const InputParameters &
74 {
75  return getInputParameters(MooseObjectName(name), tid);
76 }
77 
78 const InputParameters &
80  const std::string & name,
81  THREAD_ID tid) const
82 {
83  return getInputParameters(MooseObjectName(tag, name), tid);
84 }
85 
86 const InputParameters &
88  THREAD_ID tid) const
89 {
90  return getInputParameters(object_name, tid);
91 }
92 
94 InputParameterWarehouse::getInputParameters(const std::string & name, THREAD_ID tid) const
95 {
96  return getInputParameters(MooseObjectName(name), tid);
97 }
98 
101  const std::string & name,
102  THREAD_ID tid) const
103 {
104  return getInputParameters(MooseObjectName(tag, name), tid);
105 }
106 
109  THREAD_ID tid) const
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 }
119 
120 const std::multimap<MooseObjectName, std::shared_ptr<InputParameters>> &
122 {
123  return _input_parameters[tid];
124 }
125 
126 void
128  const MooseObjectParameterName & slave)
129 {
130  _input_parameter_links[master].push_back(slave);
131 }
std::map< MooseObjectParameterName, std::vector< MooseObjectParameterName > > _input_parameter_links
InputParameter links.
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
InputParameterWarehouse()
Class constructor.
void addControllableParameterConnection(const MooseObjectParameterName &master, const MooseObjectParameterName &slave)
Method for linking control parameters of different names.
const std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > & getInputParameters(THREAD_ID tid=0) const
Return const reference to the map containing the InputParameter objects.
const InputParameters & getInputParametersObject(const std::string &name, THREAD_ID tid=0) const
Return a const reference to the InputParameters for the named object.
InputParameters & addInputParameters(const std::string &name, InputParameters parameters, THREAD_ID tid=0)
Method for adding a new InputParameters object.
std::vector< std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > > _input_parameters
Storage for the InputParameters objects.
A class for storing an input parameter name.
A class for storing the names of MooseObject by tag and object name.
unsigned int THREAD_ID
Definition: MooseTypes.h:79