https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Classes | 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>

Classes

class  AddRemoveParamsKey
 Class that is used as a parameter to [add/remove]InputParameters() to restrict access. More...
 

Public Member Functions

 InputParameterWarehouse ()
 Class constructor.
 
virtual ~InputParameterWarehouse ()=default
 Destruction.
 
const std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > & getInputParameters (THREAD_ID tid=0) const
 Return const reference to the map containing the InputParameter objects.
 
void addControllableParameterConnection (const MooseObjectParameterName &primary, const MooseObjectParameterName &secondary, bool error_on_empty=true)
 Method for linking control parameters of different names.
 
void addControllableParameterAlias (const MooseObjectParameterName &alias, const MooseObjectParameterName &secondary)
 Method for creating alias to an existing controllable parameters.
 
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
 
template<typename T >
std::vector< T > getControllableParameterValues (const MooseObjectParameterName &input) const
 Returns a copy of the current values for a controllable parameter.
 
std::vector< MooseObjectParameterNamegetControllableParameterNames (const MooseObjectParameterName &input) const
 Return a vector of parameters names matching the supplied name.
 
InputParametersaddInputParameters (const std::string &name, const InputParameters &parameters, THREAD_ID tid, const AddRemoveParamsKey)
 Method for adding a new InputParameters object.
 
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 InputParametersgetInputParametersObject (const std::string &name, THREAD_ID tid=0) const
 Return a const reference to the InputParameters for the named object.
 
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

ControllableParameter getControllableParameter (const MooseObjectParameterName &input) const
 Returns a ControllableParameter object that contains all matches to ControllableItem objects for the provided name.
 
std::vector< ControllableItem * > getControllableItems (const MooseObjectParameterName &desired, THREAD_ID tid=0) const
 Returns a ControllableItem iterator, if the name is located.
 
 FRIEND_TEST (InputParameterWarehouseTest, getControllableItems)
 
 FRIEND_TEST (InputParameterWarehouseTest, getControllableParameter)
 
 FRIEND_TEST (InputParameterWarehouseTest, getControllableParameterValues)
 
 FRIEND_TEST (InputParameterWarehouseTest, emptyControllableParameterValues)
 
 FRIEND_TEST (InputParameterWarehouseTest, addControllableParameterConnection)
 
 FRIEND_TEST (InputParameterWarehouseTest, addControllableParameterAlias)
 
InputParametersgetInputParameters (const std::string &name, THREAD_ID tid=0) const
 Return a reference to the InputParameters for the named object.
 
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.
 
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.
 

Friends

class Control
 Only controls are allowed to call getControllableParameter.
 

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.

16{
17}
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< std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > > _input_parameters
Storage for the InputParameters objects TODO: Remove multimap.
unsigned int n_threads()

◆ ~InputParameterWarehouse()

virtual InputParameterWarehouse::~InputParameterWarehouse ( )
virtualdefault

Destruction.

Member Function Documentation

◆ addControllableObjectAlias()

void InputParameterWarehouse::addControllableObjectAlias ( const MooseObjectName alias,
const MooseObjectName secondary 
)

Method for creating alias for all shared controllable parameters between the two objects.

Definition at line 207 of file InputParameterWarehouse.C.

209{
210 for (THREAD_ID tid = 0; tid < libMesh::n_threads(); ++tid)
211 {
212 std::vector<ControllableItem *> secondaries =
214 for (auto secondary_ptr : secondaries)
215 {
216 MooseObjectParameterName alias_param(alias, secondary_ptr->name().parameter());
217 MooseObjectParameterName secondary_param(secondary, secondary_ptr->name().parameter());
218 addControllableParameterAlias(alias_param, secondary_param);
219 }
220 }
221}
unsigned int THREAD_ID
Definition MooseTypes.h:237
std::vector< ControllableItem * > getControllableItems(const MooseObjectParameterName &desired, THREAD_ID tid=0) const
Returns a ControllableItem iterator, if the name is located.
void addControllableParameterAlias(const MooseObjectParameterName &alias, const MooseObjectParameterName &secondary)
Method for creating alias to an existing controllable parameters.
A class for storing an input parameter name.

◆ addControllableParameterAlias()

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

Method for creating alias to an existing controllable parameters.

Parameters
aliasThe new name to serve as an alias.
secondaryThe name of the secondary parameter to be aliased.

Definition at line 224 of file InputParameterWarehouse.C.

226{
227 for (THREAD_ID tid = 0; tid < libMesh::n_threads(); ++tid)
228 {
229 std::vector<ControllableItem *> secondaries = getControllableItems(secondary, tid);
230 if (secondaries.empty() && tid == 0) // some objects only exist on tid 0
231 mooseError("Unable to locate secondary parameter with name ", secondary);
232
233 for (auto secondary_ptr : secondaries)
234 _controllable_items[tid].emplace_back(
235 std::make_unique<ControllableAlias>(alias, secondary_ptr));
236 }
237}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Allows for aliases to be defined via InputParameterWarehouse::addControllableParameterAlias.

Referenced by addControllableObjectAlias().

◆ addControllableParameterConnection()

void InputParameterWarehouse::addControllableParameterConnection ( const MooseObjectParameterName primary,
const MooseObjectParameterName secondary,
bool  error_on_empty = true 
)

Method for linking control parameters of different names.

Definition at line 174 of file InputParameterWarehouse.C.

178{
179 for (THREAD_ID tid = 0; tid < libMesh::n_threads(); ++tid)
180 {
181 std::vector<ControllableItem *> primaries = getControllableItems(primary, tid);
182 if (primaries.empty() && error_on_empty && tid == 0) // some objects only exist on tid 0
183 mooseError("Unable to locate primary parameter with name ", primary);
184 else if (primaries.empty())
185 {
186 if (tid == 0)
187 return;
188 else
189 // try to connect non-threaded primary control to secondary controls of all threads
190 primaries = getControllableItems(primary, 0);
191 }
192
193 std::vector<ControllableItem *> secondaries = getControllableItems(secondary, tid);
194 if (secondaries.empty() && error_on_empty && tid == 0) // some objects only exist on tid 0
195 mooseError("Unable to locate secondary parameter with name ", secondary);
196 else if (secondaries.empty())
197 return;
198
199 for (auto primary_ptr : primaries)
200 for (auto secondary_ptr : secondaries)
201 if (primary_ptr != secondary_ptr)
202 primary_ptr->connect(secondary_ptr);
203 }
204}
for(PetscInt i=0;i< nvars;++i)
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD

Referenced by FEProblemBase::addMaterialHelper().

◆ addInputParameters()

InputParameters & InputParameterWarehouse::addInputParameters ( const std::string &  name,
const InputParameters parameters,
THREAD_ID  tid,
const AddRemoveParamsKey   
)

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 protected by the AddRemoveParamsKey, because only the factories that are creating objects should be able to call this method.

Definition at line 20 of file InputParameterWarehouse.C.

24{
25 // Error if the name contains "::"
26 if (name.find("::") != std::string::npos)
27 mooseError("The object name may not contain '::' in the name: ", name);
28
29 // Create the actual InputParameters object that will be reference by the objects
30 std::shared_ptr<InputParameters> ptr = std::make_shared<InputParameters>(parameters);
31
32 const auto & base = ptr->getBase();
33
34 // The object name defined by the base class name, this method of storing is used for
35 // determining the uniqueness of the name
36 MooseObjectName unique_name(base, name, "::");
37
38 // Check that the Parameters do not already exist. We allow duplicate unique_names for
39 // MooseVariableBase objects because we require duplication of the variable for reference and
40 // displaced problems. We must also have std::pair(reference_var, reference_params) AND
41 // std::pair(displaced_var, displaced_params) elements because the two vars will have different
42 // values for _sys. It's a good thing we are using a multi-map as our underlying storage.
43 // We also allow duplicate unique_names for Action objects because it is allowed to have
44 // multiple [Materials] input blocks each of which can add an action but all of these actions
45 // will have the same unique name.
46 if (_input_parameters[tid].find(unique_name) != _input_parameters[tid].end() &&
47 base != "MooseVariableBase" && base != "Action")
48 mooseError("A '",
49 unique_name.tag(),
50 "' object already exists with the name '",
51 unique_name.name(),
52 "'.\n");
53
54 // Store the parameters according to the base name
55 _input_parameters[tid].insert(
56 std::pair<MooseObjectName, std::shared_ptr<InputParameters>>(unique_name, ptr));
57
58 // Build a list of object names
59 std::vector<MooseObjectName> object_names;
60 object_names.push_back(unique_name);
61
62 // Store the object according to the control tags
63 if (ptr->isParamValid("control_tags"))
64 {
65 const std::vector<std::string> & tags = ptr->get<std::vector<std::string>>("control_tags");
66 for (const auto & tag : tags)
67 {
68 if (!tag.empty())
69 {
70 auto short_name = MooseUtils::shortName(name);
71 _input_parameters[tid].insert(std::pair<MooseObjectName, std::shared_ptr<InputParameters>>(
72 MooseObjectName(tag, short_name), ptr));
73 object_names.emplace_back(tag, short_name);
74 }
75 }
76 }
77
78 // Store controllable parameters using all possible names
79 for (libMesh::Parameters::iterator map_iter = ptr->begin(); map_iter != ptr->end(); ++map_iter)
80 {
81 const std::string & pname = map_iter->first;
82 libMesh::Parameters::Value * value = MooseUtils::get(map_iter->second);
83
84 if (ptr->isControllable(pname))
85 for (const auto & object_name : object_names)
86 {
87 MooseObjectParameterName param_name(object_name, pname);
88 _controllable_items[tid].emplace_back(std::make_shared<ControllableItem>(
89 param_name, value, ptr->getControllableExecuteOnTypes(pname)));
90 }
91 }
92
93 // Set the name and tid parameters, and unique_name
94 std::stringstream oss;
95 oss << unique_name;
96
97 ptr->addPrivateParam<std::string>(MooseBase::unique_name_param, oss.str());
98 ptr->addPrivateParam<std::string>(MooseBase::name_param, name);
99 ptr->addPrivateParam<THREAD_ID>("_tid", tid);
100
101 // no more copies allowed
102 ptr->allowCopy(false);
103
104 // Return a reference to the InputParameters object
105 return *ptr;
106}
static const std::string unique_name_param
The name of the parameter that contains the unique object name.
Definition MooseBase.h:57
static const std::string name_param
The name of the parameter that contains the object name.
Definition MooseBase.h:55
A class for storing the names of MooseObject by tag and object name.
std::string shortName(const std::string &name)
Definition MooseUtils.C:623
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
Definition KokkosUtils.h:40
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
std::string name(const ElemQuality q)

Referenced by ActionFactory::create(), and Factory::initialize().

◆ dumpChangedControls()

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

Definition at line 262 of file InputParameterWarehouse.C.

263{
264 std::stringstream oss;
265 oss << std::left;
266
267 for (const auto & item : _controllable_items[0])
268 if (item->isChanged())
269 {
270 oss << item->dump(4);
271 if (reset_changed)
272 item->resetChanged();
273 }
274 return oss.str();
275}

Referenced by ControlOutput::outputChangedControls().

◆ FRIEND_TEST() [1/6]

InputParameterWarehouse::FRIEND_TEST ( InputParameterWarehouseTest  ,
addControllableParameterAlias   
)
private

◆ FRIEND_TEST() [2/6]

InputParameterWarehouse::FRIEND_TEST ( InputParameterWarehouseTest  ,
addControllableParameterConnection   
)
private

◆ FRIEND_TEST() [3/6]

InputParameterWarehouse::FRIEND_TEST ( InputParameterWarehouseTest  ,
emptyControllableParameterValues   
)
private

◆ FRIEND_TEST() [4/6]

InputParameterWarehouse::FRIEND_TEST ( InputParameterWarehouseTest  ,
getControllableItems   
)
private

◆ FRIEND_TEST() [5/6]

InputParameterWarehouse::FRIEND_TEST ( InputParameterWarehouseTest  ,
getControllableParameter   
)
private

◆ FRIEND_TEST() [6/6]

InputParameterWarehouse::FRIEND_TEST ( InputParameterWarehouseTest  ,
getControllableParameterValues   
)
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 240 of file InputParameterWarehouse.C.

242{
243 std::vector<ControllableItem *> output;
244 for (auto & ptr : _controllable_items[tid])
245 if (ptr->name() == input)
246 output.push_back(ptr.get());
247 return output;
248}
const Elem & get(const ElemType type_in)

Referenced by addControllableObjectAlias(), addControllableParameterAlias(), and addControllableParameterConnection().

◆ 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 251 of file InputParameterWarehouse.C.

252{
254 for (THREAD_ID tid = 0; tid < libMesh::n_threads(); ++tid)
255 for (auto it = _controllable_items[tid].begin(); it != _controllable_items[tid].end(); ++it)
256 if ((*it)->name() == input)
257 cparam.add(it->get());
258 return cparam;
259}
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.

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

◆ getControllableParameterNames()

std::vector< MooseObjectParameterName > InputParameterWarehouse::getControllableParameterNames ( const MooseObjectParameterName input) const

Return a vector of parameters names matching the supplied name.

Definition at line 278 of file InputParameterWarehouse.C.

279{
280 std::vector<MooseObjectParameterName> names;
281 for (THREAD_ID tid = 0; tid < libMesh::n_threads(); ++tid)
282 for (auto it = _controllable_items[tid].begin(); it != _controllable_items[tid].end(); ++it)
283 if ((*it)->name() == input)
284 names.push_back((*it)->name());
285 return names;
286}

Referenced by FEProblemBase::addMaterialHelper().

◆ 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 214 of file InputParameterWarehouse.h.

216{
218 return param.get<T>();
219}
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.
ControllableParameter getControllableParameter(const MooseObjectParameterName &input) const
Returns a ControllableParameter object that contains all matches to ControllableItem objects for the ...

◆ getInputParameters() [1/4]

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

Definition at line 155 of file InputParameterWarehouse.C.

157{
158 // Locate the InputParameters object and error if it was not located
159 const auto iter = _input_parameters[tid].find(object_name);
160 if (iter == _input_parameters[tid].end())
161 mooseError("Unknown InputParameters object ", object_name);
162
163 // Return a reference to the parameter
164 return *(iter->second.get());
165}

◆ 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 141 of file InputParameterWarehouse.C.

142{
143 return getInputParameters(MooseObjectName(name), tid);
144}
const std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > & getInputParameters(THREAD_ID tid=0) const
Return const reference to the map containing the InputParameter objects.

◆ getInputParameters() [3/4]

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

Definition at line 147 of file InputParameterWarehouse.C.

150{
151 return getInputParameters(MooseObjectName(tag, name), tid);
152}

◆ getInputParameters() [4/4]

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

◆ getInputParametersObject() [1/3]

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

Definition at line 134 of file InputParameterWarehouse.C.

136{
137 return getInputParameters(object_name, tid);
138}

◆ getInputParametersObject() [2/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 120 of file InputParameterWarehouse.C.

121{
122 return getInputParameters(MooseObjectName(name), tid);
123}

◆ getInputParametersObject() [3/3]

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

Definition at line 126 of file InputParameterWarehouse.C.

129{
130 return getInputParameters(MooseObjectName(tag, name), tid);
131}

◆ removeInputParameters()

void InputParameterWarehouse::removeInputParameters ( const MooseObject moose_object,
THREAD_ID  tid,
const AddRemoveParamsKey   
)

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

Definition at line 109 of file InputParameterWarehouse.C.

112{
113 auto moose_object_name_string =
114 moose_object.parameters().get<std::string>(MooseBase::unique_name_param);
115 MooseObjectName moose_object_name(moose_object_name_string);
116 _input_parameters[tid].erase(moose_object_name);
117}
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131

Referenced by Factory::releaseSharedObjects().

Friends And Related Symbol 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 201 of file InputParameterWarehouse.h.

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 159 of file InputParameterWarehouse.h.

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

◆ _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 153 of file InputParameterWarehouse.h.

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


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