Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #include "MooseMain.h" 11 : #include "ParallelUniqueId.h" 12 : #include "Parser.h" 13 : #include "AppFactory.h" 14 : #include "CommandLine.h" 15 : #include "InputParameters.h" 16 : #include "MooseApp.h" 17 : 18 : #ifdef LIBMESH_HAVE_OPENMP 19 : #include <omp.h> 20 : #endif 21 : #include <regex> 22 : 23 : namespace Moose 24 : { 25 : 26 : std::shared_ptr<MooseApp> 27 51391 : createMooseApp(const std::string & default_app_type, int argc, char * argv[]) 28 : { 29 : // Parse the command line early in order to determine the application type, from: 30 : // - the input file, to load and search for Application/type 31 : // - the --app command line argument 32 : // - The Application/type= hit command line argument 33 51391 : CommandLine cl(argc, argv); 34 51391 : cl.parse(); 35 51391 : auto command_line_params = emptyInputParameters(); 36 51391 : MooseApp::addInputParam(command_line_params); 37 51391 : MooseApp::addAppParam(command_line_params); 38 51391 : cl.populateCommandLineParams(command_line_params); 39 : 40 : // Do not allow overriding Application/type= for subapps 41 587765 : for (const auto & arg : cl.getArguments()) 42 536375 : if (std::regex_match(arg, std::regex("[A-Za-z0-9]*:Application/.*"))) 43 1 : mooseError( 44 : "For command line argument '", 45 : arg, 46 : "': overriding the application type for MultiApps via command line is not allowed."); 47 : 48 : // Parse the input file; this will set Parser::getAppType() if Application/type= is found 49 51390 : const auto & input_filenames = command_line_params.get<std::vector<std::string>>("input_file"); 50 51390 : auto parser = std::make_unique<Parser>(input_filenames); 51 51390 : parser->setAppType(default_app_type); 52 51390 : if (input_filenames.size()) 53 50839 : parser->parse(); 54 : 55 : // Search the command line for either --app or Application/type and let the last one win 56 480319 : for (const auto & entry : std::as_const(cl).getEntries()) 57 858236 : if (!entry.subapp_name && entry.value && 58 429272 : (entry.name == "--app" || entry.name == "Application/type")) 59 18 : parser->setAppType(*entry.value); 60 : 61 51355 : const auto & app_type = parser->getAppType(); 62 51355 : if (!AppFactory::instance().isRegistered(app_type)) 63 1 : mooseError("'", app_type, "' is not a registered application type."); 64 : 65 : // Create an instance of the application and store it in a smart pointer for easy cleanup 66 102704 : return AppFactory::createAppShared(argc, argv, std::move(parser)); 67 51355 : } 68 : }