www.mooseframework.org
AppFactory.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #ifndef APPFACTORY_H
16 #define APPFACTORY_H
17 
18 #include <vector>
19 
20 #include "MooseApp.h"
21 
22 // Forward declarations
23 class InputParameters;
24 
28 #define registerApp(name) AppFactory::instance().reg<name>(#name)
29 
36 
40 using paramsPtr = InputParameters (*)();
41 
45 using appBuildPtr = MooseAppPtr (*)(const InputParameters & parameters);
46 
50 using registeredMooseAppIterator = std::map<std::string, paramsPtr>::iterator;
51 
55 template <class T>
56 MooseApp *
57 buildApp(const InputParameters & parameters)
58 {
59  return new T(parameters);
60 }
61 template <class T>
62 MooseApp *
64 {
65  return std::make_shared<T>(parameters);
66 }
67 
72 {
73 public:
78  static AppFactory & instance();
79 
80  virtual ~AppFactory();
81 
85  static MooseApp *
86  createApp(std::string app_type, int argc, char ** argv, MPI_Comm COMM_WORLD_IN = MPI_COMM_WORLD);
87 
88  static std::shared_ptr<MooseApp>
89  createAppShared(const std::string & app_type, int argc, char ** argv);
90 
95  template <typename T>
96  void reg(const std::string & name)
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  }
104 
110  InputParameters getValidParams(const std::string & name);
111 
119  MooseApp * create(const std::string & app_type,
120  const std::string & name,
121  InputParameters parameters,
122  MPI_Comm COMM_WORLD_IN);
123 
125 
132 
136  bool isRegistered(const std::string & app_name) const;
137 
138 protected:
139  std::map<std::string, appBuildPtr> _name_to_build_pointer;
140 
141  std::map<std::string, paramsPtr> _name_to_params_pointer;
142 
144 
145 private:
146  // Private constructor for singleton pattern
148 };
149 
150 #endif /* APPFACTORY_H */
registeredMooseAppIterator registeredObjectsBegin()
Returns iterators to the begin/end of the registered objects data structure: a name -> validParams fu...
Definition: AppFactory.h:129
static AppFactory _instance
Definition: AppFactory.h:143
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
InputParameters(*)( paramsPtr)
alias for validParams function
Definition: AppFactory.h:40
MooseApp * MooseAppPtr
alias to wrap shared pointer type TODO: Convert to shared pointer by default in the future using Moos...
Definition: AppFactory.h:35
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
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
virtual ~AppFactory()
Definition: AppFactory.C:27
bool isRegistered(const std::string &app_name) const
Returns a Boolean indicating whether an application type has been registered.
Definition: AppFactory.C:92
Generic AppFactory class for building Application objects.
Definition: AppFactory.h:71
MooseApp * buildApp(const InputParameters &parameters)
Build an object of type T.
Definition: AppFactory.h:57
void reg(const std::string &name)
Register a new object.
Definition: AppFactory.h:96
static AppFactory & instance()
Get the instance of the AppFactory.
Definition: AppFactory.C:22
MooseApp * buildAppSharedPtr(const InputParameters &parameters)
Definition: AppFactory.h:63
MooseAppPtr(*)(const InputParameters &parameters) appBuildPtr
alias for method to build objects
Definition: AppFactory.h:45
InputParameters getValidParams(const std::string &name)
Get valid parameters for the object.
Definition: AppFactory.C:50
registeredMooseAppIterator registeredObjectsEnd()
Definition: AppFactory.h:130
std::map< std::string, paramsPtr >::iterator registeredMooseAppIterator
alias for registered Object iterator
Definition: AppFactory.h:50
static std::shared_ptr< MooseApp > createAppShared(const std::string &app_type, int argc, char **argv)
Definition: AppFactory.C:44