https://mooseframework.inl.gov
InputParameterWarehouse.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include <gtest/gtest.h>
13 #include "MooseObjectName.h"
14 #include "MooseTypes.h"
15 #include "ControllableItem.h"
16 #include "ControllableParameter.h"
17 #include "ControlOutput.h"
18 
19 // Forward declarations
20 class InputParameters;
21 class Factory;
22 class ActionFactory;
23 
34 {
35 public:
40 
44  virtual ~InputParameterWarehouse() = default;
45 
51  {
52  friend class Factory;
53  friend class ActionFactory;
54  FRIEND_TEST(InputParameterWarehouseTest, getControllableItems);
55  FRIEND_TEST(InputParameterWarehouseTest, getControllableParameter);
56  FRIEND_TEST(InputParameterWarehouseTest, getControllableParameterValues);
57  FRIEND_TEST(InputParameterWarehouseTest, emptyControllableParameterValues);
58  FRIEND_TEST(InputParameterWarehouseTest, addControllableParameterConnection);
59  FRIEND_TEST(InputParameterWarehouseTest, addControllableParameterAlias);
62  };
63 
65 
73  const InputParameters & getInputParametersObject(const std::string & name,
74  THREAD_ID tid = 0) const;
75  const InputParameters & getInputParametersObject(const std::string & tag,
76  const std::string & name,
77  THREAD_ID tid = 0) const;
78  const InputParameters & getInputParametersObject(const MooseObjectName & object_name,
79  THREAD_ID tid = 0) const;
81 
84  const std::multimap<MooseObjectName, std::shared_ptr<InputParameters>> &
85  getInputParameters(THREAD_ID tid = 0) const;
86 
91  const MooseObjectParameterName & secondary,
92  bool error_on_empty = true);
93 
101  const MooseObjectParameterName & secondary);
102 
106  void addControllableObjectAlias(const MooseObjectName & alias, const MooseObjectName & secondary);
107 
108  /***
109  * Helper method for printing controllable items.
110  */
111  std::string dumpChangedControls(bool reset_changed) const;
112 
117  template <typename T>
118  std::vector<T> getControllableParameterValues(const MooseObjectParameterName & input) const;
119 
123  std::vector<MooseObjectParameterName>
125 
139  InputParameters & addInputParameters(const std::string & name,
140  const InputParameters & parameters,
141  THREAD_ID tid,
142  const AddRemoveParamsKey);
143 
147  void
148  removeInputParameters(const MooseObject & moose_object, THREAD_ID tid, const AddRemoveParamsKey);
149 
150 private:
153  std::vector<std::multimap<MooseObjectName, std::shared_ptr<InputParameters>>> _input_parameters;
154 
159  std::vector<std::vector<std::shared_ptr<ControllableItem>>> _controllable_items;
160 
168 
173  std::vector<ControllableItem *> getControllableItems(const MooseObjectParameterName & desired,
174  THREAD_ID tid = 0) const;
175 
177 
189  InputParameters & getInputParameters(const std::string & name, THREAD_ID tid = 0) const;
191  getInputParameters(const std::string & tag, const std::string & name, THREAD_ID tid = 0) const;
192  InputParameters & getInputParameters(const MooseObjectName & object_name,
193  THREAD_ID tid = 0) const;
195 
201  friend class Control;
202 
203  // Allow unit test to call methods
204  FRIEND_TEST(InputParameterWarehouseTest, getControllableItems);
205  FRIEND_TEST(InputParameterWarehouseTest, getControllableParameter);
206  FRIEND_TEST(InputParameterWarehouseTest, getControllableParameterValues);
207  FRIEND_TEST(InputParameterWarehouseTest, emptyControllableParameterValues);
208  FRIEND_TEST(InputParameterWarehouseTest, addControllableParameterConnection);
209  FRIEND_TEST(InputParameterWarehouseTest, addControllableParameterAlias);
210 };
211 
212 template <typename T>
213 std::vector<T>
215  const MooseObjectParameterName & input) const
216 {
218  return param.get<T>();
219 }
void addControllableParameterConnection(const MooseObjectParameterName &primary, const MooseObjectParameterName &secondary, bool error_on_empty=true)
Method for linking control parameters of different names.
std::vector< ControllableItem * > getControllableItems(const MooseObjectParameterName &desired, THREAD_ID tid=0) const
Returns a ControllableItem iterator, if the name is located.
Storage container for all InputParamter objects.
Class that is used as a parameter to [add/remove]InputParameters() to restrict access.
Generic factory class for build all sorts of objects.
Definition: Factory.h:28
The ControllableParameter class is simply a set of ControllableItem objects.
virtual ~InputParameterWarehouse()=default
Destruction.
InputParameters & addInputParameters(const std::string &name, const InputParameters &parameters, THREAD_ID tid, const AddRemoveParamsKey)
Method for adding a new InputParameters object.
FRIEND_TEST(InputParameterWarehouseTest, getControllableItems)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void addControllableObjectAlias(const MooseObjectName &alias, const MooseObjectName &secondary)
Method for creating alias for all shared controllable parameters between the two objects.
std::string dumpChangedControls(bool reset_changed) const
InputParameterWarehouse()
Class constructor.
std::vector< MooseObjectParameterName > getControllableParameterNames(const MooseObjectParameterName &input) const
Return a vector of parameters names matching the supplied name.
void removeInputParameters(const MooseObject &moose_object, THREAD_ID tid, const AddRemoveParamsKey)
Allows for the deletion and cleanup of an object while the simulation is running. ...
const std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > & getInputParameters(THREAD_ID tid=0) const
Return const reference to the map containing the InputParameter objects.
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
Specialized factory for generic Action System objects.
Definition: ActionFactory.h:50
ControllableParameter getControllableParameter(const MooseObjectParameterName &input) const
Returns a ControllableParameter object that contains all matches to ControllableItem objects for the ...
void addControllableParameterAlias(const MooseObjectParameterName &alias, const MooseObjectParameterName &secondary)
Method for creating alias to an existing controllable parameters.
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.
Base class for Control objects.
Definition: Control.h:33
const InputParameters & getInputParametersObject(const std::string &name, THREAD_ID tid=0) const
Return a const reference to the InputParameters for the named object.
std::vector< std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > > _input_parameters
Storage for the InputParameters objects TODO: Remove multimap.
FRIEND_TEST(InputParameterWarehouseTest, getControllableItems)
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...
std::vector< T > getControllableParameterValues(const MooseObjectParameterName &input) const
Returns a copy of the current values for a controllable parameter.
unsigned int THREAD_ID
Definition: MooseTypes.h:209