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...
 
MooseAppcreate (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 MooseAppcreateApp (std::string app_type, int argc, char **argv, MPI_Comm COMM_WORLD_IN=MPI_COMM_WORLD)
 Helper function for creating a MooseApp from command-line arguments. More...
 
static std::shared_ptr< MooseAppcreateAppShared (const std::string &app_type, int argc, char **argv)
 

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 71 of file AppFactory.h.

Constructor & Destructor Documentation

AppFactory::~AppFactory ( )
virtual

Definition at line 27 of file AppFactory.C.

27 {}
AppFactory::AppFactory ( )
inlineprivate

Definition at line 147 of file AppFactory.h.

147 {}

Member Function Documentation

MooseApp * AppFactory::create ( 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 60 of file AppFactory.C.

Referenced by createApp(), and reg().

64 {
65  // Error if the application type is not located
66  if (_name_to_build_pointer.find(app_type) == _name_to_build_pointer.end())
67  mooseError("Object '" + app_type + "' was not registered.");
68 
69  // Take the app_type and add it to the parameters so that it can be retrieved in the Application
70  parameters.set<std::string>("_type") = app_type;
71 
72  // Check to make sure that all required parameters are supplied
73  parameters.checkParams("");
74 
75  auto comm = std::make_shared<Parallel::Communicator>(COMM_WORLD_IN);
76 
77  parameters.set<std::shared_ptr<Parallel::Communicator>>("_comm") = comm;
78  parameters.set<std::string>("_app_name") = name;
79 
80  if (!parameters.isParamValid("_command_line"))
81  mooseError("Valid CommandLine object required");
82 
83  std::shared_ptr<CommandLine> command_line =
84  parameters.get<std::shared_ptr<CommandLine>>("_command_line");
85  command_line->addCommandLineOptionsFromParams(parameters);
86  command_line->populateInputParams(parameters);
87 
88  return (*_name_to_build_pointer[app_type])(parameters);
89 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
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:139
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.
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
MooseApp * AppFactory::createApp ( std::string  app_type,
int  argc,
char **  argv,
MPI_Comm  COMM_WORLD_IN = MPI_COMM_WORLD 
)
static

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

Definition at line 30 of file AppFactory.C.

Referenced by createAppShared().

31 {
32  auto command_line = std::make_shared<CommandLine>(argc, argv);
33  InputParameters app_params = AppFactory::instance().getValidParams(app_type);
34 
35  app_params.set<int>("_argc") = argc;
36  app_params.set<char **>("_argv") = argv;
37  app_params.set<std::shared_ptr<CommandLine>>("_command_line") = command_line;
38 
39  MooseApp * app = AppFactory::instance().create(app_type, "main", app_params, COMM_WORLD_IN);
40  return app;
41 }
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
Base class for MOOSE-based applications.
Definition: MooseApp.h:58
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
MooseApp * create(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:60
static AppFactory & instance()
Get the instance of the AppFactory.
Definition: AppFactory.C:22
InputParameters getValidParams(const std::string &name)
Get valid parameters for the object.
Definition: AppFactory.C:50
std::shared_ptr< MooseApp > AppFactory::createAppShared ( const std::string &  app_type,
int  argc,
char **  argv 
)
static

Definition at line 44 of file AppFactory.C.

45 {
46  return std::shared_ptr<MooseApp>(createApp(app_type, argc, argv));
47 }
static MooseApp * createApp(std::string app_type, int argc, char **argv, MPI_Comm COMM_WORLD_IN=MPI_COMM_WORLD)
Helper function for creating a MooseApp from command-line arguments.
Definition: AppFactory.C:30
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 50 of file AppFactory.C.

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

51 {
52  if (_name_to_params_pointer.find(name) == _name_to_params_pointer.end())
53  mooseError(std::string("A '") + name + "' is not a registered object\n\n");
54 
56  return params;
57 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
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:141
AppFactory & AppFactory::instance ( )
static

Get the instance of the AppFactory.

Returns
Pointer to the AppFactory instance

Definition at line 22 of file AppFactory.C.

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

23 {
24  return _instance;
25 }
static AppFactory _instance
Definition: AppFactory.h:143
bool AppFactory::isRegistered ( const std::string &  app_name) const

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

Definition at line 92 of file AppFactory.C.

Referenced by registeredObjectsEnd().

93 {
94  return _name_to_params_pointer.find(app_name) != _name_to_params_pointer.end();
95 }
std::map< std::string, paramsPtr > _name_to_params_pointer
Definition: AppFactory.h:141
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 96 of file AppFactory.h.

97  {
98  if (_name_to_build_pointer.find(name) == _name_to_build_pointer.end())
99  {
100  _name_to_build_pointer[name] = &buildApp<T>;
101  _name_to_params_pointer[name] = &validParams<T>;
102  }
103  }
std::map< std::string, appBuildPtr > _name_to_build_pointer
Definition: AppFactory.h:139
std::map< std::string, paramsPtr > _name_to_params_pointer
Definition: AppFactory.h:141
registeredMooseAppIterator AppFactory::registeredObjectsBegin ( )
inline

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

Definition at line 129 of file AppFactory.h.

Referenced by validParams< MultiApp >().

129 { return _name_to_params_pointer.begin(); }
std::map< std::string, paramsPtr > _name_to_params_pointer
Definition: AppFactory.h:141
registeredMooseAppIterator AppFactory::registeredObjectsEnd ( )
inline

Definition at line 130 of file AppFactory.h.

Referenced by validParams< MultiApp >().

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

Member Data Documentation

AppFactory AppFactory::_instance = AppFactory()
staticprotected

Definition at line 143 of file AppFactory.h.

Referenced by instance().

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

Definition at line 139 of file AppFactory.h.

Referenced by create(), and reg().

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

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