www.mooseframework.org
Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | List of all members
AppFactory Class Reference

Generic AppFactory class for building Application objects. More...

#include <AppFactory.h>

Public Member Functions

virtual ~AppFactory ()
 
template<typename T >
void reg (const std::string &name)
 Register a new object. More...
 
InputParameters getValidParams (const std::string &name)
 Get valid parameters for the object. More...
 
MooseAppPtr createShared (const std::string &app_type, const std::string &name, InputParameters parameters, MPI_Comm COMM_WORLD_IN)
 Build an application object (must be registered) More...
 
bool isRegistered (const std::string &app_name) const
 Returns a Boolean indicating whether an application type has been registered. More...
 
registeredMooseAppIterator registeredObjectsBegin ()
 Returns iterators to the begin/end of the registered objects data structure: a name -> validParams function pointer. More...
 
registeredMooseAppIterator registeredObjectsEnd ()
 

Static Public Member Functions

static AppFactoryinstance ()
 Get the instance of the AppFactory. More...
 
static MooseAppPtr createAppShared (const std::string &app_type, int argc, char **argv, MPI_Comm comm_word=MPI_COMM_WORLD)
 Helper function for creating a MooseApp from command-line arguments. More...
 

Protected Attributes

std::map< std::string, appBuildPtr_name_to_build_pointer
 
std::map< std::string, paramsPtr_name_to_params_pointer
 

Static Protected Attributes

static AppFactory _instance = AppFactory()
 

Private Member Functions

 AppFactory ()
 

Detailed Description

Generic AppFactory class for building Application objects.

Definition at line 58 of file AppFactory.h.

Constructor & Destructor Documentation

◆ ~AppFactory()

AppFactory::~AppFactory ( )
virtual

Definition at line 22 of file AppFactory.C.

22 {}

◆ AppFactory()

AppFactory::AppFactory ( )
inlineprivate

Definition at line 133 of file AppFactory.h.

133 {}

Member Function Documentation

◆ createAppShared()

MooseAppPtr AppFactory::createAppShared ( const std::string &  app_type,
int  argc,
char **  argv,
MPI_Comm  comm_word = MPI_COMM_WORLD 
)
static

Helper function for creating a MooseApp from command-line arguments.

Definition at line 35 of file AppFactory.C.

39 {
40  auto command_line = std::make_shared<CommandLine>(argc, argv);
41  auto app_params = AppFactory::instance().getValidParams(app_type);
42 
43  app_params.set<int>("_argc") = argc;
44  app_params.set<char **>("_argv") = argv;
45  app_params.set<std::shared_ptr<CommandLine>>("_command_line") = command_line;
46 
47  return AppFactory::instance().createShared(app_type, "main", app_params, comm_world_in);
48 }
MooseAppPtr createShared(const std::string &app_type, const std::string &name, InputParameters parameters, MPI_Comm COMM_WORLD_IN)
Build an application object (must be registered)
Definition: AppFactory.C:51
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
static AppFactory & instance()
Get the instance of the AppFactory.
Definition: AppFactory.C:17
InputParameters getValidParams(const std::string &name)
Get valid parameters for the object.
Definition: AppFactory.C:25

◆ createShared()

MooseAppPtr AppFactory::createShared ( const std::string &  app_type,
const std::string &  name,
InputParameters  parameters,
MPI_Comm  COMM_WORLD_IN 
)

Build an application object (must be registered)

Parameters
app_typeType of the application being constructed
nameName for the object
parametersParameters this object should have
Returns
The created object

Definition at line 51 of file AppFactory.C.

Referenced by MultiApp::createApp(), and createAppShared().

55 {
56  // Error if the application type is not located
57  if (_name_to_build_pointer.find(app_type) == _name_to_build_pointer.end())
58  mooseError("Object '" + app_type + "' was not registered.");
59 
60  // Take the app_type and add it to the parameters so that it can be retrieved in the Application
61  parameters.set<std::string>("_type") = app_type;
62 
63  // Check to make sure that all required parameters are supplied
64  parameters.checkParams("");
65 
66  auto comm = std::make_shared<Parallel::Communicator>(comm_world_in);
67 
68  parameters.set<std::shared_ptr<Parallel::Communicator>>("_comm") = comm;
69  parameters.set<std::string>("_app_name") = name;
70 
71  if (!parameters.isParamValid("_command_line"))
72  mooseError("Valid CommandLine object required");
73 
74  std::shared_ptr<CommandLine> command_line =
75  parameters.get<std::shared_ptr<CommandLine>>("_command_line");
76  command_line->addCommandLineOptionsFromParams(parameters);
77  command_line->populateInputParams(parameters);
78 
79  return (*_name_to_build_pointer[app_type])(parameters);
80 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
std::map< std::string, appBuildPtr > _name_to_build_pointer
Definition: AppFactory.h:125
void checkParams(const std::string &parsing_syntax)
This function checks parameters stored in the object to make sure they are in the correct state as th...
MPI_Comm comm
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.

◆ getValidParams()

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

Get valid parameters for the object.

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

Definition at line 25 of file AppFactory.C.

Referenced by MultiApp::createApp(), and createAppShared().

26 {
27  if (_name_to_params_pointer.find(name) == _name_to_params_pointer.end())
28  mooseError(std::string("A '") + name + "' is not a registered object\n\n");
29 
31  return params;
32 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::map< std::string, paramsPtr > _name_to_params_pointer
Definition: AppFactory.h:127

◆ instance()

AppFactory & AppFactory::instance ( )
static

Get the instance of the AppFactory.

Returns
Pointer to the AppFactory instance

Definition at line 17 of file AppFactory.C.

Referenced by JsonSyntaxTree::addGlobal(), MultiApp::createApp(), createAppShared(), MooseApp::dynamicAppRegistration(), MultiApp::initialSetup(), and validParams< MultiApp >().

18 {
19  return _instance;
20 }
static AppFactory _instance
Definition: AppFactory.h:129

◆ isRegistered()

bool AppFactory::isRegistered ( const std::string &  app_name) const

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

Definition at line 83 of file AppFactory.C.

84 {
85  return _name_to_params_pointer.find(app_name) != _name_to_params_pointer.end();
86 }
std::map< std::string, paramsPtr > _name_to_params_pointer
Definition: AppFactory.h:127

◆ reg()

template<typename T >
void AppFactory::reg ( const std::string &  name)
inline

Register a new object.

Parameters
nameName of the object to register

Definition at line 82 of file AppFactory.h.

83  {
84  if (_name_to_build_pointer.find(name) == _name_to_build_pointer.end())
85  {
86  _name_to_build_pointer[name] = &buildApp<T>;
87  _name_to_params_pointer[name] = &validParams<T>;
88  }
89  }
std::map< std::string, appBuildPtr > _name_to_build_pointer
Definition: AppFactory.h:125
std::map< std::string, paramsPtr > _name_to_params_pointer
Definition: AppFactory.h:127

◆ registeredObjectsBegin()

registeredMooseAppIterator AppFactory::registeredObjectsBegin ( )
inline

Returns iterators to the begin/end of the registered objects data structure: a name -> validParams function pointer.

Definition at line 115 of file AppFactory.h.

Referenced by validParams< MultiApp >().

115 { return _name_to_params_pointer.begin(); }
std::map< std::string, paramsPtr > _name_to_params_pointer
Definition: AppFactory.h:127

◆ registeredObjectsEnd()

registeredMooseAppIterator AppFactory::registeredObjectsEnd ( )
inline

Definition at line 116 of file AppFactory.h.

Referenced by validParams< MultiApp >().

116 { return _name_to_params_pointer.end(); }
std::map< std::string, paramsPtr > _name_to_params_pointer
Definition: AppFactory.h:127

Member Data Documentation

◆ _instance

AppFactory AppFactory::_instance = AppFactory()
staticprotected

Definition at line 129 of file AppFactory.h.

Referenced by instance().

◆ _name_to_build_pointer

std::map<std::string, appBuildPtr> AppFactory::_name_to_build_pointer
protected

Definition at line 125 of file AppFactory.h.

Referenced by createShared(), and reg().

◆ _name_to_params_pointer

std::map<std::string, paramsPtr> AppFactory::_name_to_params_pointer
protected

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