https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
Factory Class Reference

Generic factory class for build all sorts of objects. More...

#include <Factory.h>

Public Member Functions

 Factory (MooseApp &app)
 
virtual ~Factory ()
 
void reg (std::shared_ptr< RegistryEntryBase > obj)
 
FileLineInfo getLineInfo (const std::string &name) const
 Gets file and line information where an object was initially registered.
 
void associateNameToClass (const std::string &name, const std::string &class_name)
 Associates an object name with a class name.
 
std::string associatedClassName (const std::string &name) const
 Get the associated class name for an object name.
 
InputParameters getValidParams (const std::string &name) const
 Get valid parameters for the object.
 
template<typename T >
std::unique_ptr< T > clone (const T &object)
 Clones the object object.
 
template<typename T >
std::unique_ptr< T > copyConstruct (const T &object)
 Copy constructs the object object.
 
void releaseSharedObjects (const MooseObject &moose_object, THREAD_ID tid=0)
 Releases any shared resources created as a side effect of creating an object through the Factory::create method(s).
 
void restrictRegisterableObjects (const std::vector< std::string > &names)
 Calling this object with a non-empty vector will cause this factory to ignore registrations from any object not contained within the list.
 
const auto & registeredObjects () const
 Returns a reference to the map from names to RegistryEntryBase pointers.
 
bool isRegistered (const std::string &obj_name) const
 Returns a Boolean indicating whether an object type has been registered.
 
std::vector< std::string > getConstructedObjects () const
 Get a list of all constructed Moose Object types.
 
MooseAppapp ()
 
const InputParameterscurrentlyConstructing () const
 
std::unique_ptr< MooseObjectcreateUnique (const std::string &obj_name, const std::string &name, const InputParameters &parameters, THREAD_ID tid=0, bool print_deprecated=true)
 Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>())
 
std::shared_ptr< MooseObjectcreate (const std::string &obj_name, const std::string &name, const InputParameters &parameters, THREAD_ID tid=0, bool print_deprecated=true)
 
template<typename T >
std::unique_ptr< T > createUnique (const std::string &obj_name, const std::string &name, const InputParameters &parameters, const THREAD_ID tid=0)
 Build an object (must be registered)
 
template<typename T >
std::shared_ptr< T > create (const std::string &obj_name, const std::string &name, const InputParameters &parameters, const THREAD_ID tid=0)
 

Private Member Functions

template<class T , class SmartPtr >
void createCheckObjectType (const SmartPtr &object, const std::string &obj_name) const
 Internal method for checking if the created smart pointer is of the correct expected type.
 
MooseApp_app
 Reference to the application.
 
std::map< std::string, std::shared_ptr< RegistryEntryBase > > _name_to_object
 Storage for pointers to the object registry entry.
 
FileLineInfoMap _name_to_line
 
std::map< std::string, std::string > _name_to_class
 Object name to class name association.
 
std::map< std::string, std::time_t > _deprecated_time
 Storage for deprecated object expiration dates.
 
std::map< std::string, std::string > _deprecated_name
 Storage for the deprecated objects that have replacements.
 
std::set< std::string > _registerable_objects
 The list of objects that may be registered.
 
std::set< std::string > _constructed_types
 Constructed Moose Object types.
 
std::set< std::string > _deprecated_types
 Set of deprecated object types that have been printed.
 
std::set< std::pair< std::string, std::string > > _objects_by_label
 set<label/appname, objectname> used to track if an object previously added is being added again - which is okay/allowed, while still allowing us to detect/reject cases of duplicate object name registration where the label/appname is not identical.
 
std::vector< const InputParameters * > _currently_constructing
 The object's parameters that are currently being constructed (if any).
 
std::map< const MooseObject *, unsigned int_clone_counter
 Counter for keeping track of the number of times an object with a given name has been cloned so that we can continue to create objects with unique names.
 
template<class ptr_type >
ptr_type createTempl (const std::string &obj_name, const std::string &name, const InputParameters &parameters, const THREAD_ID tid, const std::optional< std::string > &deprecated_method_name)
 Internal method for creating a MooseObject, either as a shared_ptr or as a unique_ptr.
 
std::time_t parseTime (std::string)
 Parse time string (mm/dd/yyyy HH:MM)
 
void deprecatedMessage (const std::string obj_name) const
 Show the appropriate message for deprecated objects.
 
void reportUnregisteredError (const std::string &obj_name) const
 Prints error information when an object is not registered.
 
InputParametersinitialize (const std::string &type, const std::string &name, const InputParameters &from_params, const THREAD_ID tid)
 Initializes the data structures and the parameters (in the InputParameterWarehouse) for the object with the given state.
 
void finalize (const std::string &type, const MooseObject &object)
 Finalizes the creaction of object of type type.
 

Detailed Description

Generic factory class for build all sorts of objects.

Definition at line 28 of file Factory.h.

Constructor & Destructor Documentation

◆ Factory()

Factory::Factory ( MooseApp app)

Definition at line 18 of file Factory.C.

18: _app(app) {}
MooseApp & _app
Reference to the application.
Definition Factory.h:247
MooseApp & app()
Definition Factory.h:159

◆ ~Factory()

Factory::~Factory ( )
virtual

Definition at line 20 of file Factory.C.

20{}

Member Function Documentation

◆ app()

MooseApp & Factory::app ( )
inline

Definition at line 159 of file Factory.h.

159{ return _app; }

◆ associatedClassName()

std::string Factory::associatedClassName ( const std::string &  name) const

Get the associated class name for an object name.

This will return an empty string if the name was not previously associated with a class name via associateNameToClass()

Definition at line 296 of file Factory.C.

297{
298 auto it = _name_to_class.find(name);
299 if (it == _name_to_class.end())
300 return "";
301 else
302 return it->second;
303}
std::map< std::string, std::string > _name_to_class
Object name to class name association.
Definition Factory.h:255

Referenced by Moose::Builder::buildJsonSyntaxTree().

◆ associateNameToClass()

void Factory::associateNameToClass ( const std::string &  name,
const std::string &  class_name 
)

Associates an object name with a class name.

Primarily used with the registerNamed* macros to store the mapping between the object name and the class that implements the object.

Definition at line 290 of file Factory.C.

291{
292 _name_to_class[name] = class_name;
293}
std::string name(const ElemQuality q)

Referenced by Registry::registerObjectsTo().

◆ clone()

template<typename T >
std::unique_ptr< T > Factory::clone ( const T &  object)

Clones the object object.

Under the hood, this creates a copy of the InputParameters from object and constructs a new object with the copied parameters. The suffix _clone will be added to the object's name, where is incremented each time the object is cloned.

Definition at line 323 of file Factory.h.

324{
325 static_assert(std::is_base_of_v<MooseObject, T>, "Not a MooseObject");
326
327 const auto tid = object.template getParam<THREAD_ID>("_tid");
328 if (tid != 0)
329 mooseError("Factory::clone(): The object ",
330 object.typeAndName(),
331 " is threaded but cloning does not work with threaded objects");
332
333 // Clone the parameters; we can't copy construct InputParameters
334 InputParameters cloned_params = emptyInputParameters();
335 cloned_params += object.parameters();
336 if (const auto hit_node = object.parameters().getHitNode())
337 cloned_params.setHitNode(*hit_node, {});
338
339 // Fill the new parameters in the warehouse
340 const auto type = static_cast<const MooseBase &>(object).type();
341 const auto clone_count = _clone_counter[&object]++;
342 const auto name = object.name() + "_clone" + std::to_string(clone_count);
343 const auto & params = initialize(type, name, cloned_params, 0);
344
345 // Construct the object
346 _currently_constructing.push_back(&params);
347 auto cloned_object = std::make_unique<T>(params);
348 _currently_constructing.pop_back();
349
350 // Do some sanity checking
351 finalize(type, *cloned_object);
352
353 return cloned_object;
354}
InputParameters emptyInputParameters()
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
void finalize(const std::string &type, const MooseObject &object)
Finalizes the creaction of object of type type.
Definition Factory.C:350
std::vector< const InputParameters * > _currently_constructing
The object's parameters that are currently being constructed (if any).
Definition Factory.h:280
std::map< const MooseObject *, unsigned int > _clone_counter
Counter for keeping track of the number of times an object with a given name has been cloned so that ...
Definition Factory.h:284
InputParameters & initialize(const std::string &type, const std::string &name, const InputParameters &from_params, const THREAD_ID tid)
Initializes the data structures and the parameters (in the InputParameterWarehouse) for the object wi...
Definition Factory.C:306
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void setHitNode(const std::string &param, const hit::Node &node, const SetParamHitNodeKey)
Sets the hit node associated with the parameter param to node.
Base class for everything in MOOSE with a name and a type.
Definition MooseBase.h:50

Referenced by LibmeshPartitioner::clone(), BlockWeightedPartitioner::clone(), CopyMeshPartitioner::clone(), GridPartitioner::clone(), HierarchicalGridPartitioner::clone(), RandomPartitioner::clone(), and SingleRankPartitioner::clone().

◆ copyConstruct()

template<typename T >
std::unique_ptr< T > Factory::copyConstruct ( const T &  object)

Copy constructs the object object.

Under the hood, the new object's parameters will point to the same address as the parameters in object. This can be dangerous and thus this is only allowed for a subset of objects.

Definition at line 358 of file Factory.h.

359{
360 static_assert(std::is_base_of_v<MooseObject, T>, "Not a MooseObject");
361
362 const auto type = static_cast<const MooseBase &>(object).type();
363 if (object.hasBase())
364 {
365 const auto & base = object.getBase();
366 if (base != "MooseMesh" && base != "RelationshipManager")
367 mooseError("Copy construction of ", type, " objects is not supported.");
368 }
369
370 _currently_constructing.push_back(&object.parameters());
371 auto cloned_object = std::make_unique<T>(object);
372 _currently_constructing.pop_back();
373
374 finalize(type, *cloned_object);
375
376 return cloned_object;
377}
const std::string & getBase() const
Definition MooseBase.h:147

Referenced by RedistributeProperties::clone(), AnnularMesh::safeClone(), ConcentricCircleMesh::safeClone(), FileMesh::safeClone(), GeneratedMesh::safeClone(), ImageMesh::safeClone(), MeshGeneratorMesh::safeClone(), PatternedMesh::safeClone(), RinglebMesh::safeClone(), SpiralAnnularMesh::safeClone(), StitchedMesh::safeClone(), TiledMesh::safeClone(), and MFEMMesh::safeClone().

◆ create() [1/2]

template<typename T >
std::shared_ptr< T > Factory::create ( const std::string &  obj_name,
const std::string &  name,
const InputParameters parameters,
const THREAD_ID  tid = 0 
)

Definition at line 311 of file Factory.h.

315{
316 auto object = create(obj_name, name, parameters, tid, false);
317 createCheckObjectType<T>(object, obj_name);
318 return std::static_pointer_cast<T>(object);
319}
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, const InputParameters &parameters, THREAD_ID tid=0, bool print_deprecated=true)
Definition Factory.C:142

◆ create() [2/2]

std::shared_ptr< MooseObject > Factory::create ( const std::string &  obj_name,
const std::string &  name,
const InputParameters parameters,
THREAD_ID  tid = 0,
bool  print_deprecated = true 
)

◆ createCheckObjectType()

template<class T , class SmartPtr >
void Factory::createCheckObjectType ( const SmartPtr &  object,
const std::string &  obj_name 
) const
private

Internal method for checking if the created smart pointer is of the correct expected type.

Used in create<T> and createUnique<T>.

Definition at line 289 of file Factory.h.

290{
291 if (!dynamic_cast<T *>(object.get()))
292 mooseError("We expected to create an object of type '" + MooseUtils::prettyCppType<T>() +
293 "'.\nInstead we received a parameters object for type '" + obj_name +
294 "'.\nDid you call the wrong \"add\" method in your Action?");
295}
const Elem & get(const ElemType type_in)

◆ createTempl()

template<class ptr_type >
ptr_type Factory::createTempl ( const std::string &  obj_name,
const std::string &  name,
const InputParameters parameters,
const THREAD_ID  tid,
const std::optional< std::string > &  deprecated_method_name 
)
private

Internal method for creating a MooseObject, either as a shared_ptr or as a unique_ptr.

This is needed because we need to explicitly create objects that are requested as a shared_ptr with make_shared, so that the std::enable_shared_from_this interface will work for those objects.

We avoid code duplication by putting the creation logic for shared_ptr and unique_ptr in the same method.

This is explicitly instantiated for std::unique_ptr<MooseObject> and std::shared_ptr<MooseObject> in Factory.C.

Parameters
obj_nameType of the object being constructed
nameName for the object
parametersParameters this object should have
tidThe thread id that this copy will be created for
deprecated_method_nameThe name of the method to throw a deprecated warning for, if any
Returns
The created MooseObject

Definition at line 88 of file Factory.C.

93{
94 static_assert(std::is_same_v<ptr_type, std::unique_ptr<MooseObject>> ||
95 std::is_same_v<ptr_type, std::shared_ptr<MooseObject>>,
96 "Invalid ptr_type");
97
98 if (deprecated_method_name)
99 {
100 const std::string name = "Factory::" + *deprecated_method_name;
101 mooseDeprecated(name + "() is deprecated, please use name" + "<T>() instead");
102 }
103
104 // Build the parameters that are stored in the InputParameterWarehouse for this
105 // object, set a few other things and do a little error checking
106 auto & warehouse_params = initialize(obj_name, name, parameters, tid);
107
108 // Mark that we're constructing this object
109 _currently_constructing.push_back(&warehouse_params);
110
111 // Construct the object
112 auto & registry_entry = *_name_to_object.at(obj_name);
113 ptr_type obj;
114 if constexpr (std::is_same_v<ptr_type, std::unique_ptr<MooseObject>>)
115 obj = registry_entry.build(warehouse_params);
116 else
117 obj = registry_entry.buildShared(warehouse_params);
118
119 // Done constructing the object
120 _currently_constructing.pop_back();
121
122 finalize(obj_name, *obj);
123
124 return obj;
125}
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition MooseError.h:363
std::map< std::string, std::shared_ptr< RegistryEntryBase > > _name_to_object
Storage for pointers to the object registry entry.
Definition Factory.h:250

◆ createUnique() [1/2]

template<typename T >
std::unique_ptr< T > Factory::createUnique ( const std::string &  obj_name,
const std::string &  name,
const InputParameters parameters,
const THREAD_ID  tid = 0 
)

Build an object (must be registered)

Parameters
obj_nameType of the object being constructed
nameName for the object
parametersParameters this object should have
tidThe thread id that this copy will be created for
Returns
The created object

Definition at line 299 of file Factory.h.

303{
304 auto object = createUnique(obj_name, name, parameters, tid, false);
305 createCheckObjectType<T>(object, obj_name);
306 return std::unique_ptr<T>(static_cast<T *>(object.release()));
307}
std::unique_ptr< MooseObject > createUnique(const std::string &obj_name, const std::string &name, const InputParameters &parameters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>())
Definition Factory.C:128

◆ createUnique() [2/2]

std::unique_ptr< MooseObject > Factory::createUnique ( const std::string &  obj_name,
const std::string &  name,
const InputParameters parameters,
THREAD_ID  tid = 0,
bool  print_deprecated = true 
)

Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>())

Parameters
obj_nameType of the object being constructed
nameName for the object
parametersParameters this object should have
tidThe thread id that this copy will be created for
print_deprecatedcontrols the deprecated message
Returns
The created object

Definition at line 128 of file Factory.C.

133{
134 std::optional<std::string> deprecated_method_name;
135 if (print_deprecated)
136 deprecated_method_name = "createUnique";
137 return createTempl<std::unique_ptr<MooseObject>>(
138 obj_name, name, parameters, tid, deprecated_method_name);
139}

Referenced by ActionUnitTest::buildMinimalObjects(), MooseObjectUnitTest::buildObjects(), and createUnique().

◆ currentlyConstructing()

const InputParameters * Factory::currentlyConstructing ( ) const
Returns
The InputParameters for the object that is currently being constructed, if any.

Can be used to ensure that all MooseObjects are created using the Factory

Definition at line 278 of file Factory.C.

279{
280 return _currently_constructing.size() ? _currently_constructing.back() : nullptr;
281}

Referenced by MooseObject::MooseObject().

◆ deprecatedMessage()

void Factory::deprecatedMessage ( const std::string  obj_name) const
private

Show the appropriate message for deprecated objects.

Parameters
obj_nameName of the deprecated object

Definition at line 190 of file Factory.C.

191{
192 const auto time_it = _deprecated_time.find(obj_name);
193
194 // If the object is not deprecated return
195 if (time_it == _deprecated_time.end())
196 return;
197
198 // If the message has already been printed, return
199 if (_deprecated_types.count(obj_name))
200 return;
201 _deprecated_types.emplace(obj_name);
202
203 // Get the current time
204 std::time_t now;
205 time(&now);
206
207 // Get the stop time
208 std::time_t t_end = time_it->second;
209
210 // Message storage
211 std::ostringstream msg;
212
213 const auto name_it = _deprecated_name.find(obj_name);
214
215 // Expired object
216 if (now > t_end)
217 {
218 msg << "***** Invalid Object: " << obj_name << " *****\n";
219 msg << "Expired on " << ctime(&t_end);
220
221 // Append replacement object, if it exists
222 if (name_it != _deprecated_name.end())
223 msg << "Update your application using the '" << name_it->second << "' object";
224
225 // Produce the error message
227 }
228
229 // Expiring object
230 else
231 {
232 // Build the basic message
233 msg << "Deprecated Object: " << obj_name << "\n";
234 msg << "This object will be removed on " << ctime(&t_end);
235
236 // Append replacement object, if it exists
237 if (name_it != _deprecated_name.end())
238 msg << "Replace " << obj_name << " with " << name_it->second;
239
240 // Produce the error message
241 mooseDeprecatedNoTrace(msg.str());
242 }
243}
void mooseDeprecatedNoTrace(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition MooseError.h:373
void mooseDeprecationExpiredNoTrace(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition MooseError.h:392
std::map< std::string, std::string > _deprecated_name
Storage for the deprecated objects that have replacements.
Definition Factory.h:261
std::set< std::string > _deprecated_types
Set of deprecated object types that have been printed.
Definition Factory.h:270
std::map< std::string, std::time_t > _deprecated_time
Storage for deprecated object expiration dates.
Definition Factory.h:258

Referenced by getValidParams(), and initialize().

◆ finalize()

void Factory::finalize ( const std::string &  type,
const MooseObject object 
)
private

Finalizes the creaction of object of type type.

This will do some sanity checking on whether or not the parameters in the created object match the valid paramters of the associated type.

Definition at line 350 of file Factory.C.

351{
352 // Make sure no unexpected parameters were added by the object's constructor or by the action
353 // initiating this create call. All parameters modified by the constructor must have already
354 // been specified in the object's validParams function.
355 InputParameters orig_params = getValidParams(type);
356 const auto & object_params = object.parameters();
357 if (orig_params.n_parameters() != object_params.n_parameters())
358 {
359 std::set<std::string> orig, populated;
360 for (const auto & it : orig_params)
361 orig.emplace(it.first);
362 for (const auto & it : object_params)
363 populated.emplace(it.first);
364
365 std::set<std::string> diff;
366 std::set_difference(populated.begin(),
367 populated.end(),
368 orig.begin(),
369 orig.end(),
370 std::inserter(diff, diff.begin()));
371
372 if (!diff.empty())
373 {
374 std::stringstream ss;
375 for (const auto & name : diff)
376 ss << ", " << name;
377 object.mooseError("Attempted to set unregistered parameter(s):\n ", ss.str().substr(2));
378 }
379 }
380}
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
std::size_t n_parameters() const

Referenced by clone(), copyConstruct(), and createTempl().

◆ getConstructedObjects()

std::vector< std::string > Factory::getConstructedObjects ( ) const

Get a list of all constructed Moose Object types.

Definition at line 269 of file Factory.C.

270{
271 std::vector<std::string> list;
272 for (const auto & name : _constructed_types)
273 list.push_back(name);
274 return list;
275}
std::set< std::string > _constructed_types
Constructed Moose Object types.
Definition Factory.h:267

◆ getLineInfo()

FileLineInfo Factory::getLineInfo ( const std::string &  name) const

Gets file and line information where an object was initially registered.

Parameters
nameObject name
Returns
The FileLineInfo associated with name

Definition at line 284 of file Factory.C.

285{
286 return _name_to_line.getInfo(name);
287}
FileLineInfoMap _name_to_line
Definition Factory.h:252
FileLineInfo getInfo(const std::string &key0) const
Get file/line info for a key.

Referenced by Moose::Builder::buildJsonSyntaxTree(), and MooseServer::gatherDocumentDefinitionLocations().

◆ getValidParams()

InputParameters Factory::getValidParams ( const std::string &  name) const

Get valid parameters for the object.

Parameters
nameName of the object whose parameter we are requesting
Returns
Parameters of the object

Definition at line 68 of file Factory.C.

69{
70 const auto it = _name_to_object.find(obj_name);
71
72 // Check if the object is registered
73 if (it == _name_to_object.end())
75
76 // Print out deprecated message, if it exists
77 deprecatedMessage(obj_name);
78
79 // Return the parameters
80 auto params = it->second->buildParameters();
81 params.addPrivateParam(MooseBase::app_param, &_app);
82
83 return params;
84}
void reportUnregisteredError(const std::string &obj_name) const
Prints error information when an object is not registered.
Definition Factory.C:246
void deprecatedMessage(const std::string obj_name) const
Show the appropriate message for deprecated objects.
Definition Factory.C:190
static const std::string app_param
The name of the parameter that contains the MooseApp.
Definition MooseBase.h:59

Referenced by ElementIDOutputAction::act(), AddPeriodicBCAction::act(), AutoCheckpointAction::act(), CombineComponentsMeshes::act(), CommonOutputAction::act(), ComposeTimeStepperAction::act(), CreateDisplacedProblemAction::act(), CreateProblemDefaultAction::act(), DisplayGhostingAction::act(), MaterialDerivativeTestAction::act(), MaterialOutputAction::act(), SetAdaptivityOptionsAction::act(), SetupMeshAction::act(), SetupResidualDebugAction::act(), SetupTimeStepperAction::act(), DiffusionCG::addBoundaryConditionsFromComponents(), DiffusionCG::addFEBCs(), DiffusionCG::addFEKernels(), DiffusionFV::addFVBCs(), DiffusionFV::addFVKernels(), DiffusionPhysicsBase::addInitialConditions(), DiffusionPhysicsBase::addInitialConditionsFromComponents(), FEProblem::addLineSearch(), ComponentMaterialPropertyInterface::addMaterials(), BatchMeshGeneratorAction::addMeshGenerators(), ComponentJunction::addMeshGenerators(), ComponentMeshTransformHelper::addMeshGenerators(), CylinderComponent::addMeshGenerators(), MeshGenerator::addMeshSubgenerator(), MFEMProblem::addMFEMFESpaceFromMOOSEVariable(), DiffusionPhysicsBase::addPostprocessors(), CreateDisplacedProblemAction::addProxyRelationshipManagers(), AddActionComponentAction::addRelationshipManagers(), DiffusionCG::addSolverVariables(), DiffusionFV::addSolverVariables(), BatchMeshGeneratorAction::BatchMeshGeneratorAction(), ActionUnitTest::buildMinimalObjects(), MooseObjectUnitTest::buildObjects(), ExtraIDIntegralReporter::ExtraIDIntegralReporter(), finalize(), FunctorSmootherTempl< T >::FunctorSmootherTempl(), DiffusionFV::getAdditionalRMParams(), MooseServer::getHoverDisplayText(), FEProblemBase::getKokkosFunction(), MooseServer::getObjectParameters(), MaterialOutputAction::getParams(), OverlayMeshGenerator::OverlayMeshGenerator(), ProjectedStatefulMaterialStorageAction::processProperty(), TransientBase::setupTimeIntegrator(), and SideSetExtruderGenerator::SideSetExtruderGenerator().

◆ initialize()

InputParameters & Factory::initialize ( const std::string &  type,
const std::string &  name,
const InputParameters from_params,
const THREAD_ID  tid 
)
private

Initializes the data structures and the parameters (in the InputParameterWarehouse) for the object with the given state.

Definition at line 306 of file Factory.C.

310{
311 // Pointer to the object constructor
312 const auto it = _name_to_object.find(type);
313
314 // Check if the object is registered
315 if (it == _name_to_object.end())
317
318 // Print out deprecated message, if it exists
319 deprecatedMessage(type);
320
321 // Create the actual parameters object that the object will reference
322 InputParameters & params =
323 _app.getInputParameterWarehouse().addInputParameters(name, from_params, tid, {});
324
325 // Add the hit node from the action if it isn't set already (it might be set
326 // already because someone had a better option than just the action)
327 // If it isn't set, it typically means that this object was created by a
328 // non-MooseObjectAction Action
329 if (!params.getHitNode() || params.getHitNode()->isRoot())
330 if (const auto hit_node = _app.getCurrentActionHitNode())
331 params.setHitNode(*hit_node, {});
332
333 // Set the type parameter
334 params.set<std::string>(MooseBase::type_param) = type;
335
336 // Check to make sure that all required parameters are supplied
337 params.finalize(name);
338
339 // register type name as constructed
340 _constructed_types.insert(type);
341
342 // add FEProblem pointers to object's params object
344 _app.actionWarehouse().problemBase()->setInputParametersFEProblem(params);
345
346 return params;
347}
std::shared_ptr< FEProblemBase > & problemBase()
InputParameters & addInputParameters(const std::string &name, const InputParameters &parameters, THREAD_ID tid, const AddRemoveParamsKey)
Method for adding a new InputParameters object.
void finalize(const std::string &parsing_syntax)
Finalizes the parameters, which must be done before constructing any objects with these parameters (t...
const hit::Node * getHitNode(const std::string &param) const
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
ActionWarehouse & actionWarehouse()
Return a writable reference to the ActionWarehouse associated with this app.
Definition MooseApp.h:217
const hit::Node * getCurrentActionHitNode() const
Definition MooseApp.C:3062
InputParameterWarehouse & getInputParameterWarehouse()
Get the InputParameterWarehouse for MooseObjects.
Definition MooseApp.C:2867
static const std::string type_param
The name of the parameter that contains the object type.
Definition MooseBase.h:53

Referenced by clone(), and createTempl().

◆ isRegistered()

bool Factory::isRegistered ( const std::string &  obj_name) const
inline

Returns a Boolean indicating whether an object type has been registered.

Definition at line 152 of file Factory.h.

152{ return _name_to_object.count(obj_name); }

Referenced by MooseServer::gatherDocumentDefinitionLocations(), MooseServer::getHoverDisplayText(), and MooseServer::getObjectParameters().

◆ parseTime()

std::time_t Factory::parseTime ( std::string  t_str)
private

Parse time string (mm/dd/yyyy HH:MM)

Parameters
t_strString with the object expiration date, this must be in the form mm/dd/yyyy HH:MM
Returns
A time_t object with the expiration date

Definition at line 168 of file Factory.C.

169{
170 // The string must be a certain length to be valid
171 if (t_str.size() != 16)
172 mooseError("The deprecated time not formatted correctly; it must be given as mm/dd/yyyy HH:MM");
173
174 // Store the time, the time must be specified as: mm/dd/yyyy HH:MM
175 std::time_t t_end;
176 struct tm * t_end_info;
177 time(&t_end);
178 t_end_info = localtime(&t_end);
179 t_end_info->tm_mon = std::atoi(t_str.substr(0, 2).c_str()) - 1;
180 t_end_info->tm_mday = std::atoi(t_str.substr(3, 2).c_str());
181 t_end_info->tm_year = std::atoi(t_str.substr(6, 4).c_str()) - 1900;
182 t_end_info->tm_hour = std::atoi(t_str.substr(11, 2).c_str()) + 1;
183 t_end_info->tm_min = std::atoi(t_str.substr(14, 2).c_str());
184 t_end_info->tm_sec = 0;
185 t_end = mktime(t_end_info);
186 return t_end;
187}

Referenced by reg().

◆ reg()

void Factory::reg ( std::shared_ptr< RegistryEntryBase obj)

Definition at line 23 of file Factory.C.

24{
25 const std::string obj_name = obj->name();
26 const std::string & label = obj->_label;
27 const std::string & deprecated_time = obj->_deprecated_time;
28 const std::string & replacement_name = obj->_replaced_by;
29 const std::string & file = obj->_file;
30 const int line = obj->_line;
31
32 // do nothing if we have already added this exact object before
33 auto key = std::make_pair(label, obj_name);
34 if (_objects_by_label.find(key) != _objects_by_label.end())
35 return;
36
37 /*
38 * If _registerable_objects has been set the user has requested that we only register some
39 * subset
40 * of the objects for a dynamically loaded application. The objects listed in *this*
41 * application's
42 * registerObjects() method will have already been registered before that member was set.
43 *
44 * If _registerable_objects is empty, the factory is unrestricted
45 */
46 if (_registerable_objects.empty() ||
47 _registerable_objects.find(obj_name) != _registerable_objects.end())
48 {
49 if (_name_to_object.find(obj_name) != _name_to_object.end())
50 mooseError("Object '" + obj_name + "' registered from multiple files: ",
51 file,
52 " and ",
53 _name_to_line.getInfo(obj_name).file());
54 _name_to_object[obj_name] = obj;
55 _objects_by_label.insert(key);
56 }
57 _name_to_line.addInfo(obj_name, file, line);
58
59 if (!replacement_name.empty())
60 _deprecated_name[obj_name] = replacement_name;
61 if (!deprecated_time.empty())
62 _deprecated_time[obj_name] = parseTime(deprecated_time);
63
64 // TODO: Possibly store and print information about objects that are skipped here?
65}
std::set< std::pair< std::string, std::string > > _objects_by_label
set<label/appname, objectname> used to track if an object previously added is being added again - whi...
Definition Factory.h:275
std::set< std::string > _registerable_objects
The list of objects that may be registered.
Definition Factory.h:264
std::time_t parseTime(std::string)
Parse time string (mm/dd/yyyy HH:MM)
Definition Factory.C:168
void addInfo(const std::string &key0, const std::string &file, int line)
Associate a key with file/line info.
std::string file() const

Referenced by Registry::registerObjectsTo().

◆ registeredObjects()

const auto & Factory::registeredObjects ( ) const
inline

Returns a reference to the map from names to RegistryEntryBase pointers.

Definition at line 147 of file Factory.h.

147{ return _name_to_object; }

Referenced by MooseServer::addValuesToList(), Moose::Builder::buildFullTree(), and Moose::Builder::buildJsonSyntaxTree().

◆ releaseSharedObjects()

void Factory::releaseSharedObjects ( const MooseObject moose_object,
THREAD_ID  tid = 0 
)

Releases any shared resources created as a side effect of creating an object through the Factory::create method(s).

Currently, this object just moves the InputParameters object from the InputParameterWarehouse. Normally this method does not need to be explicitly called during a normal simulation.

Definition at line 156 of file Factory.C.

157{
159}
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.

Referenced by AddPeriodicBCAction::act(), SetAdaptivityOptionsAction::act(), CreateDisplacedProblemAction::addProxyRelationshipManagers(), and AddActionComponentAction::addRelationshipManagers().

◆ reportUnregisteredError()

void Factory::reportUnregisteredError ( const std::string &  obj_name) const
private

Prints error information when an object is not registered.

Definition at line 246 of file Factory.C.

247{
248 std::ostringstream oss;
249 std::set<std::string> paths = _app.getLoadedLibraryPaths();
250
251 oss << "A '" + obj_name + "' is not a registered object.\n";
252
253 if (!paths.empty())
254 {
255 oss << "\nWe loaded objects from the following libraries and still couldn't find your "
256 "object:\n\t";
257 std::copy(paths.begin(), paths.end(), infix_ostream_iterator<std::string>(oss, "\n\t"));
258 oss << '\n';
259 }
260
261 oss << "\nIf you are trying to find this object in a dynamically loaded library, make sure that\n"
262 "the library can be found either in your \"Problem/library_path\" parameter or in the\n"
263 "MOOSE_LIBRARY_PATH environment variable.";
264
265 mooseError(oss.str());
266}
std::set< std::string > getLoadedLibraryPaths() const
Return the paths of loaded libraries.
Definition MooseApp.C:2830
GCC9 currently hits a "no type named 'value_type'" error during build if this is removed and iterator...

Referenced by getValidParams(), and initialize().

◆ restrictRegisterableObjects()

void Factory::restrictRegisterableObjects ( const std::vector< std::string > &  names)

Calling this object with a non-empty vector will cause this factory to ignore registrations from any object not contained within the list.

Parameters
namesa vector containing the names of objects that this factory will register

Definition at line 162 of file Factory.C.

163{
164 _registerable_objects.insert(names.begin(), names.end());
165}

Referenced by DynamicObjectRegistrationAction::DynamicObjectRegistrationAction().

Member Data Documentation

◆ _app

MooseApp& Factory::_app
private

Reference to the application.

Definition at line 247 of file Factory.h.

Referenced by app(), getValidParams(), initialize(), releaseSharedObjects(), and reportUnregisteredError().

◆ _clone_counter

std::map<const MooseObject *, unsigned int> Factory::_clone_counter
private

Counter for keeping track of the number of times an object with a given name has been cloned so that we can continue to create objects with unique names.

Definition at line 284 of file Factory.h.

Referenced by clone().

◆ _constructed_types

std::set<std::string> Factory::_constructed_types
private

Constructed Moose Object types.

Definition at line 267 of file Factory.h.

Referenced by getConstructedObjects(), and initialize().

◆ _currently_constructing

std::vector<const InputParameters *> Factory::_currently_constructing
private

The object's parameters that are currently being constructed (if any).

This is a vector because we create within create, thus the last entry is the one that is being constructed at the moment

Definition at line 280 of file Factory.h.

Referenced by clone(), copyConstruct(), createTempl(), and currentlyConstructing().

◆ _deprecated_name

std::map<std::string, std::string> Factory::_deprecated_name
private

Storage for the deprecated objects that have replacements.

Definition at line 261 of file Factory.h.

Referenced by deprecatedMessage(), and reg().

◆ _deprecated_time

std::map<std::string, std::time_t> Factory::_deprecated_time
private

Storage for deprecated object expiration dates.

Definition at line 258 of file Factory.h.

Referenced by deprecatedMessage(), and reg().

◆ _deprecated_types

std::set<std::string> Factory::_deprecated_types
mutableprivate

Set of deprecated object types that have been printed.

Definition at line 270 of file Factory.h.

Referenced by deprecatedMessage().

◆ _name_to_class

std::map<std::string, std::string> Factory::_name_to_class
private

Object name to class name association.

Definition at line 255 of file Factory.h.

Referenced by associatedClassName(), and associateNameToClass().

◆ _name_to_line

FileLineInfoMap Factory::_name_to_line
private

Definition at line 252 of file Factory.h.

Referenced by getLineInfo(), and reg().

◆ _name_to_object

std::map<std::string, std::shared_ptr<RegistryEntryBase> > Factory::_name_to_object
private

Storage for pointers to the object registry entry.

Definition at line 250 of file Factory.h.

Referenced by createTempl(), getValidParams(), initialize(), isRegistered(), reg(), and registeredObjects().

◆ _objects_by_label

std::set<std::pair<std::string, std::string> > Factory::_objects_by_label
private

set<label/appname, objectname> used to track if an object previously added is being added again - which is okay/allowed, while still allowing us to detect/reject cases of duplicate object name registration where the label/appname is not identical.

Definition at line 275 of file Factory.h.

Referenced by reg().

◆ _registerable_objects

std::set<std::string> Factory::_registerable_objects
private

The list of objects that may be registered.

Definition at line 264 of file Factory.h.

Referenced by reg(), and restrictRegisterableObjects().


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