38 return it->second->buildParameters();
40 mooseError(std::string(
"A '") + name +
"' is not a registered object\n\n");
49 mooseError(
"AppFactory::getAppParams(): Parameters for application with ID ",
id,
" not found");
60 "AppFactory::clearAppParams(): Parameters for application with ID ",
id,
" not found");
63std::unique_ptr<MooseApp>
65 const std::vector<std::string> & cli_args )
67 auto parser = std::make_unique<Parser>(std::vector<std::string>());
69 parser->setAppType(app_type);
71 auto command_line = std::make_unique<CommandLine>(std::vector<std::string>{
"unused"});
72 command_line->addArguments(cli_args);
73 command_line->parse();
78std::unique_ptr<MooseApp>
81 mooseAssert(parser,
"Not set");
82 mooseAssert(parser->getAppType().size(),
"App type not set");
83 mooseAssert(parser->queryRoot(),
"Has not parsed");
84 mooseAssert(command_line,
"Not set");
85 mooseAssert(command_line->hasParsed(),
"Has not parsed");
87 const std::string app_type = parser->getAppType();
90 app_params.
set<std::shared_ptr<Parser>>(
"_parser") = std::move(parser);
91 app_params.set<std::shared_ptr<CommandLine>>(
"_command_line") = std::move(command_line);
96std::shared_ptr<MooseApp>
100 MPI_Comm comm_world_in)
102 mooseDeprecated(
"Please update your main.C to adapt new main function in MOOSE framework, "
103 "see'test/src/main.C in MOOSE as an example of moose::main()'. ");
111 pre_command_line.
parse();
114 const auto & input_filenames = command_line_params.get<std::vector<std::string>>(
"input_file");
115 std::string app_type = command_line_params.get<std::string>(
"app_to_run");
117 auto command_line = std::make_unique<CommandLine>(argc, argv);
118 command_line->parse();
120 auto parser = std::make_unique<Parser>(input_filenames);
121 parser->setCommandLineParams(command_line->buildHitParams());
124 if (app_type.empty())
125 app_type = default_app_type;
127 mooseDeprecated(
"Please use [Application] block to specify application type, '--app <AppName>' "
128 "is deprecated and will be removed in a future release.");
130 parser->setAppType(app_type);
133 app_params.
set<std::shared_ptr<Parser>>(
"_parser") = std::move(parser);
134 app_params.set<std::shared_ptr<CommandLine>>(
"_command_line") = std::move(command_line);
139std::unique_ptr<MooseApp>
141 const std::string & name,
143 MPI_Comm comm_world_in)
148 mooseError(
"AppFactory::Create(): Application '" + app_type +
"' was not registered");
149 auto & build_info = it->second;
151 auto comm = std::make_shared<Parallel::Communicator>(comm_world_in);
157 parameters.
set<std::shared_ptr<Parallel::Communicator>>(
"_comm") = comm;
158 parameters.
set<std::string>(
"_app_name") = name;
160 auto parser = parameters.
get<std::shared_ptr<Parser>>(
"_parser");
161 mooseAssert(parser,
"Parser not valid");
162 mooseAssert(parser->queryRoot(),
"Parser has not parsed");
164 auto command_line = parameters.
get<std::shared_ptr<CommandLine>>(
"_command_line");
165 mooseAssert(command_line,
"Command line not valid");
166 mooseAssert(command_line->hasParsed(),
"Command line has not parsed");
167 command_line->populateCommandLineParams(parameters);
176 build_info->_app_creation_count++;
178 return build_info->build(params);
181std::shared_ptr<MooseApp>
183 const std::string & name,
185 MPI_Comm comm_world_in)
196 mooseError(
"AppFactory::createdAppCount(): '", app_type,
"' is not a registered app");
198 return it->second->_app_creation_count;
204 const std::size_t next_id =
207 const auto it_inserted_pair =
209 mooseAssert(it_inserted_pair.second,
"Already exists");
210 auto & stored_params = *it_inserted_pair.first->second;
211 stored_params.finalize(
"");
212 return stored_params;
219 mooseError(
"AppFactory::getAppParamsID(): Invalid application parameters (missing "
220 "'_app_params_id')");
221 return params.
get<std::size_t>(
"_app_params_id");
230 "MOOSE application " + app_name +
" is available.");
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Class that is used as a parameter to clearAppParams() that allows only MooseApp to call clearAppParam...
Generic AppFactory class for building Application objects.
static std::shared_ptr< MooseApp > createAppShared(const std::string &default_app_type, int argc, char **argv, MPI_Comm comm_word=MPI_COMM_WORLD)
Deprecated helper function for creating a MooseApp for Apps haven't adapted to the new Parser and Bui...
std::size_t getAppParamsID(const InputParameters ¶ms) const
Get the ID for the InputParameters associated with an application, used in storing them in _input_par...
const InputParameters & getAppParams(const InputParameters ¶ms) const
InputParameters getValidParams(const std::string &name)
Get valid parameters for the object.
const InputParameters & storeAppParams(InputParameters ¶ms)
Stores the given parameters within _input_parameters for app construction.
void registerAppCapability(const std::string &app_name)
Register an application name as a capability.
std::shared_ptr< MooseApp > createShared(const std::string &app_type, const std::string &name, InputParameters parameters, MPI_Comm COMM_WORLD_IN)
AppFactoryBuildInfoMap _name_to_build_info
std::size_t createdAppCount(const std::string &app_type) const
static std::unique_ptr< MooseApp > create(const std::string &app_type, const std::vector< std::string > &cli_args={})
Create an app with no input and command line arguments.
AppFactory()
Private constructor for singleton pattern.
static const std::string main_app_name
The name for the "main" moose application.
std::map< std::size_t, std::unique_ptr< InputParameters > > _input_parameters
Storage of input parameters used in applications (ID (from getAppParamsID()) -> params)
static AppFactory & instance()
Get the instance of the AppFactory.
void clearAppParams(const InputParameters ¶ms, const ClearAppParamsKey)
Clears the stored parameters for the given application parameteres.
This class wraps provides and tracks access to command line parameters.
void populateCommandLineParams(InputParameters ¶ms)
Populates the command line input parameters from params.
void parse()
Performs the parsing, which is the combining of arguments into [name, value] pairs.
static void addAppParam(InputParameters ¶ms)
static void addInputParam(InputParameters ¶ms)
static const std::string unique_name_param
The name of the parameter that contains the unique object name.
static const std::string name_param
The name of the parameter that contains the object name.
static const std::string type_param
The name of the parameter that contains the object type.
static Capabilities & getCapabilities(const GetCapabilitiesPassKey)
Get the singleton Capabilities.
Capability & add(const std::string_view name, const Moose::Capability::Value &value, const std::string_view doc)
Add a capability.
std::string toLower(std::string name)
Convert supplied string to lower case.