www.mooseframework.org
InputParameterWarehouse.h
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 #ifndef INPUTPARAMETERWAREHOUSE_H
16 #define INPUTPARAMETERWAREHOUSE_H
17 
18 // MOOSE includes
19 #include "MooseObjectName.h"
20 #include "MooseTypes.h"
21 #include "ControllableParameter.h"
22 
23 // Forward declarations
24 class InputParameters;
25 
34 {
35 public:
40 
44  virtual ~InputParameterWarehouse() = default;
45 
47 
55  const InputParameters & getInputParametersObject(const std::string & name,
56  THREAD_ID tid = 0) const;
57  const InputParameters & getInputParametersObject(const std::string & tag,
58  const std::string & name,
59  THREAD_ID tid = 0) const;
60  const InputParameters & getInputParametersObject(const MooseObjectName & object_name,
61  THREAD_ID tid = 0) const;
63 
66  const std::multimap<MooseObjectName, std::shared_ptr<InputParameters>> &
67  getInputParameters(THREAD_ID tid = 0) const;
68 
73  template <typename T>
75  bool mark_as_controlled = false);
76 
81  const MooseObjectParameterName & slave);
82 
83 private:
85  std::vector<std::multimap<MooseObjectName, std::shared_ptr<InputParameters>>> _input_parameters;
86 
88  std::map<MooseObjectParameterName, std::vector<MooseObjectParameterName>> _input_parameter_links;
89 
91  std::map<std::shared_ptr<InputParameters>, std::set<MooseObjectParameterName>>
93 
108  addInputParameters(const std::string & name, InputParameters parameters, THREAD_ID tid = 0);
109 
111 
123  InputParameters & getInputParameters(const std::string & name, THREAD_ID tid = 0) const;
125  getInputParameters(const std::string & tag, const std::string & name, THREAD_ID tid = 0) const;
126  InputParameters & getInputParameters(const MooseObjectName & object_name,
127  THREAD_ID tid = 0) const;
129 
134  const std::map<std::shared_ptr<InputParameters>, std::set<MooseObjectParameterName>> &
136  {
137  return _controlled_parameters;
138  }
140 
141  friend class Factory;
142  friend class ActionFactory;
143  friend class Control;
144  friend class ControlOutput;
145 
146  // RELAP-7 Control Logic (This will go away when the MOOSE system is created)
147  friend class Component;
148 };
149 
150 template <typename T>
153  bool mark_as_controlled /*=false*/)
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 }
206 
207 #endif // INPUTPARAMETERWAREHOUSE_H
std::map< MooseObjectParameterName, std::vector< MooseObjectParameterName > > _input_parameter_links
InputParameter links.
Storage container for all InputParamter objects.
const std::string & parameter() const
Return the parameter name.
Generic factory class for build all sorts of objects.
Definition: Factory.h:152
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
virtual ~InputParameterWarehouse()=default
Destruction.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameterWarehouse()
Class constructor.
void addControllableParameterConnection(const MooseObjectParameterName &master, const MooseObjectParameterName &slave)
Method for linking control parameters of different names.
void insert(const MooseObjectParameterName &name, std::shared_ptr< InputParameters > param_object)
Adds a parameter to the container.
Specialized factory for generic Action System objects.
Definition: ActionFactory.h:70
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 std::map< std::shared_ptr< InputParameters >, std::set< MooseObjectParameterName > > & getControlledParameters()
Return the list of controlled parameters (used for output)
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::map< std::shared_ptr< InputParameters >, std::set< MooseObjectParameterName > > _controlled_parameters
A list of parameters that were controlled (only used for output)
Base class for Control objects.
Definition: Control.h:43
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.
Class for output information regarding Controls to the screen.
Definition: ControlOutput.h:30
A class for storing the names of MooseObject by tag and object name.
ControllableParameter< T > getControllableParameter(const MooseObjectParameterName &desired, bool mark_as_controlled=false)
Returns a ControllableParameter object.
unsigned int THREAD_ID
Definition: MooseTypes.h:79