LCOV - code coverage report
Current view: top level - src/base - MooseMain.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: fef103 Lines: 27 27 100.0 %
Date: 2025-09-03 20:01:23 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          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::unique_ptr<MooseApp>
      27       56086 : 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       56086 :   auto command_line_params = emptyInputParameters();
      34             :   {
      35       56086 :     CommandLine cl(argc, argv);
      36       56086 :     cl.parse();
      37       56086 :     MooseApp::addInputParam(command_line_params);
      38       56086 :     MooseApp::addAppParam(command_line_params);
      39       56086 :     cl.populateCommandLineParams(command_line_params);
      40             : 
      41             :     // Do not allow overriding Application/type= for subapps
      42      653262 :     for (const auto & arg : cl.getArguments())
      43      597177 :       if (std::regex_match(arg, std::regex("[A-Za-z0-9]*:Application/.*")))
      44           1 :         mooseError(
      45             :             "For command line argument '",
      46             :             arg,
      47             :             "': overriding the application type for MultiApps via command line is not allowed.");
      48       56086 :   }
      49       56085 :   const auto & input_filenames = command_line_params.get<std::vector<std::string>>("input_file");
      50             : 
      51             :   // Parse command line arguments so that we can get the "--app" entry (if any) and the HIT
      52             :   // command line arguments for the Parser
      53       56085 :   auto command_line = std::make_unique<CommandLine>(argc, argv);
      54       56085 :   command_line->parse();
      55             : 
      56             :   // Setup the parser with the input and the HIT parameters from the command line. The parse
      57             :   // will also look for "Application/type=" in input to specify the application type
      58       56085 :   auto parser = std::make_unique<Parser>(input_filenames);
      59       56085 :   parser->setAppType(default_app_type);
      60       56085 :   parser->setCommandLineParams(command_line->buildHitParams());
      61       56085 :   parser->parse();
      62             : 
      63             :   // Search the command line for either --app or Application/type and let the last one win
      64      583484 :   for (const auto & entry : std::as_const(*command_line).getEntries())
      65      766028 :     if (!entry.subapp_name && entry.value &&
      66      238582 :         (entry.name == "--app" || entry.name == "Application/type"))
      67          19 :       parser->setAppType(*entry.value);
      68             : 
      69       56038 :   const auto & app_type = parser->getAppType();
      70       56038 :   if (!AppFactory::instance().isRegistered(app_type))
      71           1 :     mooseError("'", app_type, "' is not a registered application type.");
      72             : 
      73             :   // Create an instance of the application and store it in a smart pointer for easy cleanup
      74      112070 :   return AppFactory::create(std::move(parser), std::move(command_line));
      75       56037 : }
      76             : }

Generated by: LCOV version 1.14