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. More... | |
void | associateNameToClass (const std::string &name, const std::string &class_name) |
Associates an object name with a class name. More... | |
std::string | associatedClassName (const std::string &name) const |
Get the associated class name for an object name. More... | |
InputParameters | getValidParams (const std::string &name) const |
Get valid parameters for the object. More... | |
template<typename T > | |
std::unique_ptr< T > | clone (const T &object) |
Clones the object object . More... | |
template<typename T > | |
std::unique_ptr< T > | copyConstruct (const T &object) |
Copy constructs the object object . More... | |
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). More... | |
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. More... | |
const auto & | registeredObjects () const |
Returns a reference to the map from names to RegistryEntryBase pointers. More... | |
bool | isRegistered (const std::string &obj_name) const |
Returns a Boolean indicating whether an object type has been registered. More... | |
std::vector< std::string > | getConstructedObjects () const |
Get a list of all constructed Moose Object types. More... | |
MooseApp & | app () |
const InputParameters * | currentlyConstructing () const |
std::unique_ptr< MooseObject > | createUnique (const std::string &obj_name, const std::string &name, const InputParameters ¶meters, THREAD_ID tid=0, bool print_deprecated=true) |
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) More... | |
std::shared_ptr< MooseObject > | create (const std::string &obj_name, const std::string &name, const InputParameters ¶meters, 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 ¶meters, const THREAD_ID tid=0) |
Build an object (must be registered) More... | |
template<typename T > | |
std::shared_ptr< T > | create (const std::string &obj_name, const std::string &name, const InputParameters ¶meters, const THREAD_ID tid=0) |
Private Member Functions | |
std::time_t | parseTime (std::string) |
Parse time string (mm/dd/yyyy HH:MM) More... | |
void | deprecatedMessage (const std::string obj_name) const |
Show the appropriate message for deprecated objects. More... | |
void | reportUnregisteredError (const std::string &obj_name) const |
Prints error information when an object is not registered. More... | |
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 with the given state. More... | |
void | finalize (const std::string &type, const MooseObject &object) |
Finalizes the creaction of object of type type . More... | |
Private Attributes | |
MooseApp & | _app |
Reference to the application. More... | |
std::map< std::string, std::shared_ptr< RegistryEntryBase > > | _name_to_object |
Storage for pointers to the object registry entry. More... | |
FileLineInfoMap | _name_to_line |
std::map< std::string, std::string > | _name_to_class |
Object name to class name association. More... | |
std::map< std::string, std::time_t > | _deprecated_time |
Storage for deprecated object experiation dates. More... | |
std::map< std::string, std::string > | _deprecated_name |
Storage for the deprecated objects that have replacements. More... | |
std::set< std::string > | _registerable_objects |
The list of objects that may be registered. More... | |
std::set< std::string > | _constructed_types |
Constructed Moose Object types. More... | |
std::set< std::string > | _deprecated_types |
Set of deprecated object types that have been printed. More... | |
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. More... | |
std::vector< const InputParameters * > | _currently_constructing |
The object's parameters that are currently being constructed (if any). More... | |
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. More... | |
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 271 of file Factory.C.
Referenced by Moose::Builder::buildJsonSyntaxTree().
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 265 of file Factory.C.
Referenced by Registry::registerObjectsTo().
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 275 of file Factory.h.
Referenced by SingleRankPartitioner::clone(), RandomPartitioner::clone(), BlockWeightedPartitioner::clone(), PetscExternalPartitioner::clone(), LibmeshPartitioner::clone(), HierarchicalGridPartitioner::clone(), and GridPartitioner::clone().
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 310 of file Factory.h.
Referenced by ElementSideNeighborLayers::clone(), ElementPointNeighborLayers::clone(), RedistributeProperties::clone(), ProxyRelationshipManager::clone(), TiledMesh::safeClone(), FileMesh::safeClone(), ImageMesh::safeClone(), SpiralAnnularMesh::safeClone(), GeneratedMesh::safeClone(), RinglebMesh::safeClone(), ConcentricCircleMesh::safeClone(), AnnularMesh::safeClone(), MeshGeneratorMesh::safeClone(), StitchedMesh::safeClone(), and PatternedMesh::safeClone().
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 |
||
) |
Definition at line 110 of file Factory.C.
Referenced by CreateExecutionerAction::act(), PartitionerAction::act(), CreateProblemAction::act(), CreateProblemDefaultAction::act(), AdaptivityAction::act(), SetupMeshAction::act(), SetupPreconditionerAction::act(), SetupPredictorAction::act(), CreateDisplacedProblemAction::act(), MaterialDerivativeTestAction::act(), SetAdaptivityOptionsAction::act(), AddControlAction::act(), AddPeriodicBCAction::act(), FEProblemBase::addAnyRedistributers(), NonlinearSystemBase::addBoundaryCondition(), NonlinearSystemBase::addConstraint(), NonlinearSystemBase::addDamper(), NonlinearSystemBase::addDGKernel(), NonlinearSystemBase::addDiracKernel(), MooseApp::addExecutor(), FEProblemBase::addFunction(), FEProblemBase::addFunctorMaterial(), FEProblemBase::addFVInitialCondition(), FEProblemBase::addIndicator(), FEProblemBase::addInitialCondition(), NonlinearSystemBase::addInterfaceKernel(), MooseEigenSystem::addKernel(), AuxiliarySystem::addKernel(), NonlinearSystemBase::addKernel(), FEProblem::addLineSearch(), FEProblemBase::addMarker(), FEProblemBase::addMaterialHelper(), FEProblemBase::addMeshDivision(), FEProblemBase::addMultiApp(), NonlinearSystemBase::addNodalKernel(), FEProblemBase::addObject(), FEProblemBase::addOutput(), FEProblemBase::addPredictor(), CreateDisplacedProblemAction::addProxyRelationshipManagers(), Action::addRelationshipManager(), AuxiliarySystem::addScalarKernel(), NonlinearSystemBase::addScalarKernel(), NonlinearSystemBase::addSplit(), AuxiliarySystem::addTimeIntegrator(), NonlinearSystemBase::addTimeIntegrator(), FEProblemBase::addTransfer(), FEProblemBase::addUserObject(), SystemBase::addVariable(), AStableDirk4::AStableDirk4(), MooseObjectUnitTest::buildObjects(), MooseApp::createExecutors(), and MeshGeneratorSystem::createMeshGenerator().
std::shared_ptr< T > Factory::create | ( | const std::string & | obj_name, |
const std::string & | name, | ||
const InputParameters & | parameters, | ||
const THREAD_ID | tid = 0 |
||
) |
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>())
obj_name | Type of the object being constructed |
name | Name for the object |
parameters | Parameters this object should have |
tid | The thread id that this copy will be created for |
print_deprecated | controls the deprecated message |
Definition at line 86 of file Factory.C.
Referenced by MooseObjectUnitTest::buildObjects(), OversampleOutput::cloneMesh(), create(), and createUnique().
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)
obj_name | Type of the object being constructed |
name | Name for the object |
parameters | Parameters this object should have |
tid | The thread id that this copy will be created for |
Definition at line 249 of file Factory.h.
const InputParameters * Factory::currentlyConstructing | ( | ) | const |
Can be used to ensure that all MooseObjects are created using the Factory
Definition at line 253 of file Factory.C.
Referenced by MooseObject::MooseObject().
|
private |
Show the appropriate message for deprecated objects.
obj_name | Name of the deprecated object |
Definition at line 160 of file Factory.C.
Referenced by getValidParams(), and initialize().
|
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 325 of file Factory.C.
Referenced by clone(), copyConstruct(), and createUnique().
std::vector< std::string > Factory::getConstructedObjects | ( | ) | const |
Get a list of all constructed Moose Object types.
Definition at line 244 of file Factory.C.
Referenced by MooseApp::runInputFile().
FileLineInfo Factory::getLineInfo | ( | const std::string & | name | ) | const |
Gets file and line information where an object was initially registered.
name | Object name |
Definition at line 259 of file Factory.C.
Referenced by Moose::Builder::buildJsonSyntaxTree(), and MooseServer::gatherDocumentDefinitionLocations().
InputParameters Factory::getValidParams | ( | const std::string & | name | ) | const |
Get valid parameters for the object.
name | Name of the object whose parameter we are requesting |
Definition at line 67 of file Factory.C.
Referenced by AB2PredictorCorrector::AB2PredictorCorrector(), ElementIDOutputAction::act(), AutoCheckpointAction::act(), CreateProblemDefaultAction::act(), AdaptivityAction::act(), SetupMeshAction::act(), ComposeTimeStepperAction::act(), SetupDebugAction::act(), SetupTimeStepperAction::act(), SetupResidualDebugAction::act(), SetAdaptivityOptionsAction::act(), CreateDisplacedProblemAction::act(), MaterialDerivativeTestAction::act(), DisplayGhostingAction::act(), AddPeriodicBCAction::act(), MaterialOutputAction::act(), AddNodalNormalsAction::act(), FEProblemBase::addAuxArrayVariable(), FEProblemBase::addAuxScalarVariable(), FEProblemBase::addAuxVariable(), DiffusionCG::addFEBCs(), DiffusionCG::addFEKernels(), DiffusionFV::addFVBCs(), DiffusionFV::addFVKernels(), FEProblem::addLineSearch(), MeshGenerator::addMeshSubgenerator(), DiffusionFV::addNonlinearVariables(), DiffusionCG::addNonlinearVariables(), CreateDisplacedProblemAction::addProxyRelationshipManagers(), Action::addRelationshipManager(), FVFluxKernel::adjustRMGhostLayers(), AStableDirk4::AStableDirk4(), MooseObjectUnitTest::buildObjects(), OversampleOutput::cloneMesh(), MooseBaseParameterInterface::connectControllableParams(), MooseApp::createExecutors(), DumpObjectsProblem::deduceNecessaryParameters(), ExtraIDIntegralReporter::ExtraIDIntegralReporter(), finalize(), FunctorSmootherTempl< T >::FunctorSmootherTempl(), DiffusionFV::getAdditionalRMParams(), FEProblemBase::getFunction(), MooseServer::getHoverDisplayText(), MooseServer::getObjectParameters(), MaterialOutputAction::getParams(), OverlayMeshGenerator::OverlayMeshGenerator(), ProjectedStatefulMaterialStorageAction::processProperty(), Transient::setupTimeIntegrator(), and SideSetExtruderGenerator::SideSetExtruderGenerator().
|
private |
Initializes the data structures and the parameters (in the InputParameterWarehouse) for the object with the given state.
Definition at line 281 of file Factory.C.
Referenced by clone(), and createUnique().
|
inline |
Returns a Boolean indicating whether an object type has been registered.
Definition at line 152 of file Factory.h.
Referenced by MooseServer::gatherDocumentDefinitionLocations(), MooseServer::getHoverDisplayText(), and MooseServer::getObjectParameters().
|
private |
Parse time string (mm/dd/yyyy HH:MM)
t_str | String with the object expiration date, this must be in the form mm/dd/yyyy HH:MM |
Definition at line 138 of file Factory.C.
Referenced by reg().
void Factory::reg | ( | std::shared_ptr< RegistryEntryBase > | obj | ) |
Definition at line 22 of file Factory.C.
Referenced by Registry::registerObjectsTo().
|
inline |
Returns a reference to the map from names to RegistryEntryBase pointers.
Definition at line 147 of file Factory.h.
Referenced by MooseServer::addValuesToList(), Moose::Builder::buildFullTree(), and Moose::Builder::buildJsonSyntaxTree().
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 126 of file Factory.C.
Referenced by AdaptivityAction::act(), SetAdaptivityOptionsAction::act(), AddPeriodicBCAction::act(), CreateDisplacedProblemAction::addProxyRelationshipManagers(), Action::addRelationshipManager(), and MooseApp::removeRelationshipManager().
|
private |
Prints error information when an object is not registered.
Definition at line 221 of file Factory.C.
Referenced by getValidParams(), and initialize().
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.
names | a vector containing the names of objects that this factory will register |
Definition at line 132 of file Factory.C.
Referenced by DynamicObjectRegistrationAction::DynamicObjectRegistrationAction().
|
private |
Reference to the application.
Definition at line 207 of file Factory.h.
Referenced by app(), create(), getValidParams(), initialize(), releaseSharedObjects(), and reportUnregisteredError().
|
private |
|
private |
Constructed Moose Object types.
Definition at line 227 of file Factory.h.
Referenced by getConstructedObjects(), and initialize().
|
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 240 of file Factory.h.
Referenced by clone(), copyConstruct(), createUnique(), and currentlyConstructing().
|
private |
Storage for the deprecated objects that have replacements.
Definition at line 221 of file Factory.h.
Referenced by deprecatedMessage(), and reg().
|
private |
Storage for deprecated object experiation dates.
Definition at line 218 of file Factory.h.
Referenced by deprecatedMessage(), and reg().
|
mutableprivate |
Set of deprecated object types that have been printed.
Definition at line 230 of file Factory.h.
Referenced by deprecatedMessage().
|
private |
Object name to class name association.
Definition at line 215 of file Factory.h.
Referenced by associatedClassName(), and associateNameToClass().
|
private |
Definition at line 212 of file Factory.h.
Referenced by getLineInfo(), and reg().
|
private |
Storage for pointers to the object registry entry.
Definition at line 210 of file Factory.h.
Referenced by createUnique(), getValidParams(), initialize(), isRegistered(), reg(), and registeredObjects().
|
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 235 of file Factory.h.
Referenced by reg().
|
private |
The list of objects that may be registered.
Definition at line 224 of file Factory.h.
Referenced by reg(), and restrictRegisterableObjects().