36 return it->second->buildParameters();
38 mooseError(std::string(
"A '") +
name +
"' is not a registered object\n\n");
47 mooseError(
"AppFactory::getAppParams(): Parameters for application with ID ",
id,
" not found");
58 "AppFactory::clearAppParams(): Parameters for application with ID ",
id,
" not found");
61 std::unique_ptr<MooseApp>
63 const std::vector<std::string> & cli_args )
65 auto parser = std::make_unique<Parser>(std::vector<std::string>());
67 parser->setAppType(app_type);
69 auto command_line = std::make_unique<CommandLine>(std::vector<std::string>{
"unused"});
70 command_line->addArguments(cli_args);
71 command_line->parse();
76 std::unique_ptr<MooseApp>
79 mooseAssert(parser,
"Not set");
80 mooseAssert(parser->getAppType().size(),
"App type not set");
81 mooseAssert(parser->queryRoot(),
"Has not parsed");
82 mooseAssert(command_line,
"Not set");
83 mooseAssert(command_line->hasParsed(),
"Has not parsed");
85 const std::string app_type = parser->getAppType();
88 app_params.
set<std::shared_ptr<Parser>>(
"_parser") = std::move(parser);
89 app_params.set<std::shared_ptr<CommandLine>>(
"_command_line") = std::move(command_line);
94 std::shared_ptr<MooseApp>
98 MPI_Comm comm_world_in)
100 mooseDeprecated(
"Please update your main.C to adapt new main function in MOOSE framework, " 101 "see'test/src/main.C in MOOSE as an example of moose::main()'. ");
109 pre_command_line.
parse();
112 const auto & input_filenames = command_line_params.get<std::vector<std::string>>(
"input_file");
113 std::string app_type = command_line_params.get<std::string>(
"app_to_run");
115 auto command_line = std::make_unique<CommandLine>(argc, argv);
116 command_line->parse();
118 auto parser = std::make_unique<Parser>(input_filenames);
119 parser->setCommandLineParams(command_line->buildHitParams());
122 if (app_type.empty())
123 app_type = default_app_type;
125 mooseDeprecated(
"Please use [Application] block to specify application type, '--app <AppName>' " 126 "is deprecated and will be removed in a future release.");
128 parser->setAppType(app_type);
131 app_params.
set<std::shared_ptr<Parser>>(
"_parser") = std::move(parser);
132 app_params.set<std::shared_ptr<CommandLine>>(
"_command_line") = std::move(command_line);
137 std::unique_ptr<MooseApp>
139 const std::string & name,
141 MPI_Comm comm_world_in)
146 mooseError(
"AppFactory::Create(): Application '" + app_type +
"' was not registered");
147 auto & build_info = it->second;
149 auto comm = std::make_shared<Parallel::Communicator>(comm_world_in);
155 parameters.
set<std::shared_ptr<Parallel::Communicator>>(
"_comm") = comm;
156 parameters.
set<std::string>(
"_app_name") =
name;
158 auto parser = parameters.
get<std::shared_ptr<Parser>>(
"_parser");
159 mooseAssert(parser,
"Parser not valid");
160 mooseAssert(parser->queryRoot() && parser->queryCommandLineRoot(),
"Parser has not parsed");
162 auto command_line = parameters.
get<std::shared_ptr<CommandLine>>(
"_command_line");
163 mooseAssert(command_line,
"Command line not valid");
164 mooseAssert(command_line->hasParsed(),
"Command line has not parsed");
165 command_line->populateCommandLineParams(parameters);
174 build_info->_app_creation_count++;
176 return build_info->build(params);
179 std::shared_ptr<MooseApp>
181 const std::string & name,
183 MPI_Comm comm_world_in)
194 mooseError(
"AppFactory::createdAppCount(): '", app_type,
"' is not a registered app");
196 return it->second->_app_creation_count;
202 const std::size_t next_id =
205 const auto it_inserted_pair =
207 mooseAssert(it_inserted_pair.second,
"Already exists");
208 auto & stored_params = *it_inserted_pair.first->second;
209 stored_params.finalize(
"");
210 return stored_params;
217 mooseError(
"AppFactory::getAppParamsID(): Invalid application parameters (missing " 218 "'_app_params_id')");
219 return params.
get<std::size_t>(
"_app_params_id");
std::string name(const ElemQuality q)
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.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
std::shared_ptr< MooseApp > createShared(const std::string &app_type, const std::string &name, InputParameters parameters, MPI_Comm COMM_WORLD_IN)
static const std::string main_app_name
The name for the "main" moose application.
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...
const InputParameters & storeAppParams(InputParameters ¶ms)
Stores the given parameters within _input_parameters for app construction.
static void addInputParam(InputParameters ¶ms)
const InputParameters & getAppParams(const InputParameters ¶ms) const
static const std::string unique_name_param
The name of the parameter that contains the unique object name.
This class wraps provides and tracks access to command line parameters.
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.
void populateCommandLineParams(InputParameters ¶ms)
Populates the command line input parameters from params.
Generic AppFactory class for building Application objects.
void clearAppParams(const InputParameters ¶ms, const ClearAppParamsKey)
Clears the stored parameters for the given application parameteres.
AppFactoryBuildInfoMap _name_to_build_info
std::size_t createdAppCount(const std::string &app_type) const
std::map< std::size_t, std::unique_ptr< InputParameters > > _input_parameters
Storage of input parameters used in applications (ID (from getAppParamsID()) -> params) ...
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
AppFactory()
Private constructor for singleton pattern.
static AppFactory & instance()
Get the instance of the AppFactory.
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...
static void addAppParam(InputParameters ¶ms)
Class that is used as a parameter to clearAppParams() that allows only MooseApp to call clearAppParam...
void parse()
Performs the parsing, which is the combining of arguments into [name, value] pairs.
InputParameters getValidParams(const std::string &name)
Get valid parameters for the object.