LCOV - code coverage report
Current view: top level - src/base - MooseMain.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #33380 (547b29) with base 8581c3 Lines: 28 28 100.0 %
Date: 2026-07-20 19:36:28 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 "Moose.h"
      17             : #include "MooseApp.h"
      18             : 
      19             : #ifdef LIBMESH_HAVE_OPENMP
      20             : #include <omp.h>
      21             : #endif
      22             : #include <regex>
      23             : 
      24             : namespace Moose
      25             : {
      26             : 
      27             : std::unique_ptr<MooseApp>
      28       55447 : createMooseApp(const std::string & default_app_type, int argc, char * argv[])
      29             : {
      30             :   // Parse the command line early in order to determine the application type, from:
      31             :   // - the input file, to load and search for Application/type
      32             :   // - the --app command line argument
      33             :   // - The Application/type= hit command line argument
      34       55447 :   auto command_line_params = emptyInputParameters();
      35             :   {
      36       55447 :     CommandLine cl(argc, argv);
      37       55447 :     cl.parse();
      38       55447 :     MooseApp::addInputParam(command_line_params);
      39       55447 :     MooseApp::addAppParam(command_line_params);
      40       55447 :     cl.populateCommandLineParams(command_line_params);
      41             : 
      42             :     // Do not allow overriding Application/type= for subapps
      43      652044 :     for (const auto & arg : cl.getArguments())
      44      596599 :       if (std::regex_match(arg, std::regex("[A-Za-z0-9]*:Application/.*")))
      45           2 :         mooseError(
      46             :             "For command line argument '",
      47             :             arg,
      48             :             "': overriding the application type for MultiApps via command line is not allowed.");
      49       55447 :   }
      50       55445 :   const auto & input_filenames = command_line_params.get<std::vector<std::string>>("input_file");
      51             : 
      52             :   // Parse command line arguments so that we can get the "--app" entry (if any) and the HIT
      53             :   // command line arguments for the Parser
      54       55445 :   auto command_line = std::make_unique<CommandLine>(argc, argv);
      55       55445 :   command_line->parse();
      56      110890 :   Moose::_suppress_info = command_line->hasArgument("--suppress-info");
      57             : 
      58             :   // Setup the parser with the input and the HIT parameters from the command line. The parse
      59             :   // will also look for "Application/type=" in input to specify the application type
      60       55445 :   auto parser = std::make_unique<Parser>(input_filenames);
      61       55445 :   parser->setAppType(default_app_type);
      62       55445 :   parser->setCommandLineParams(command_line->buildHitParams());
      63       55445 :   parser->parse();
      64             : 
      65             :   // Search the command line for either --app or Application/type and let the last one win
      66      588236 :   for (const auto & entry : std::as_const(*command_line).getEntries())
      67      772631 :     if (!entry.subapp_name && entry.value &&
      68      239806 :         (entry.name == "--app" || entry.name == "Application/type"))
      69          24 :       parser->setAppType(*entry.value);
      70             : 
      71       55411 :   const auto & app_type = parser->getAppType();
      72       55411 :   if (!AppFactory::instance().isRegistered(app_type))
      73           2 :     mooseError("'", app_type, "' is not a registered application type.");
      74             : 
      75             :   // Create an instance of the application and store it in a smart pointer for easy cleanup
      76      110815 :   return AppFactory::create(std::move(parser), std::move(command_line));
      77       55414 : }
      78             : }

Generated by: LCOV version 1.14