Skip to content

Commit

Permalink
Adapt new changes in Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
MengnanLi91 committed Jan 15, 2024
1 parent 3454de4 commit 21b74c8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
7 changes: 4 additions & 3 deletions framework/include/parser/Parser.h
Expand Up @@ -165,15 +165,16 @@ class Parser
*/
std::filesystem::path getLastInputFilePath() const { return getLastInputFileName(); }

/// The app types extracted from [Application] block
std::string _app_type;

private:
/// The root node, which owns the whole tree
std::unique_ptr<hit::Node> _root;

/// The input file names
const std::vector<std::string> _input_filenames;

/// The optional input text (to augment reading a single input with the MooseServer)
const std::optional<std::string> _input_text;

/// The app types extracted from [Application] block
std::string _app_type;
};
25 changes: 18 additions & 7 deletions framework/src/base/MooseMain.C
Expand Up @@ -31,16 +31,26 @@ addMainCommandLineParams(InputParameters & params)
"Specify one or multiple input files. Multiple files get merged into a single simulation "
"input.");

input_param.addCommandLineParam<std::string>(
params.addCommandLineParam<std::string>(
"application_type", "Application/type=<app_type>", "Specify the application type.");
}

std::shared_ptr<MooseApp>
createMooseApp(const std::string & default_app_name, int argc, char * argv[])
{
auto command_line = std::make_shared<CommandLine>(argc, argv);

command_line->addCommandLineOptionsFromParams(input_param);
{
auto input_param = emptyInputParameters();
addMainCommandLineParams(input_param);
command_line->addCommandLineOptionsFromParams(input_param);
}

std::vector<std::string> input_filename;
std::vector<std::string> input_filenames;
std::string cl_app_type;

// Get command line arguments
command_line->search("input_file", input_filename);
command_line->search("input_file", input_filenames);
command_line->search("application_type", cl_app_type);

// loop over all the command line arguments and error out when the user uses Application block for
Expand All @@ -59,14 +69,15 @@ addMainCommandLineParams(InputParameters & params)
parser->parse();

// Check whether the application name given in [Application] block is registered or not
auto app_type = front_parser->getAppType();
auto app_type = parser->getAppType();
if (!cl_app_type.empty())
app_type = cl_app_type;
std::cout << "app_type: " << app_type << std::endl;
if (!app_type.empty())
if (!AppFactory::instance().isRegistered(app_type))
mooseError("'", app_type, "' is not a registered application name.\n");
}

// Create an instance of the application and store it in a smart pointer for easy cleanup
return AppFactory::createAppShared(default_app_name, argc, argv, std::move(front_parser));
return AppFactory::createAppShared(default_app_name, argc, argv, std::move(parser));
}
}
14 changes: 6 additions & 8 deletions framework/src/multiapps/MultiApp.C
Expand Up @@ -1107,14 +1107,13 @@ MultiApp::createApp(unsigned int i, Real start_time)
const auto input_index = _input_files.size() == 1 ? 0 : _first_local_app + i;
const auto & input_file = _input_files[input_index];

// create new parser tree for the application
auto front_parser = std::make_unique<Parser>();
std::vector<std::string> multiapp_input{input_file};
// create new parser tree for the application and parse
auto parser = std::make_unique<Parser>(input_file);

if (!multiapp_input.empty())
if (input_file.size())
{
front_parser->parse(multiapp_input);
auto app_type = front_parser->getAppType();
parser->parse();
auto app_type = parser->getAppType();
if (app_type.empty() && _app_type.empty())
mooseWarning("The application type is not specify for ",
full_name,
Expand All @@ -1130,8 +1129,7 @@ MultiApp::createApp(unsigned int i, Real start_time)
"application is provided. \n");
}

app_params.set<std::shared_ptr<Parser>>("_parser") = front_parser;

app_params.set<std::shared_ptr<Parser>>("_parser") = std::move(parser);
_apps[i] = AppFactory::instance().createShared(_app_type, full_name, app_params, _my_comm);
auto & app = _apps[i];

Expand Down
10 changes: 8 additions & 2 deletions framework/src/parser/Parser.C
Expand Up @@ -151,10 +151,16 @@ UnitsConversionEvaler::eval(hit::Field * n,
return ss.str();
}

Parser::Parser() : _sections_read(false), _app_type(std::string()) {}
Parser::Parser(const std::vector<std::string> & input_filenames)
: _root(nullptr), _input_filenames(input_filenames), _input_text(), _app_type(std::string())
{
}

Parser::Parser(const std::string & input_filename, const std::optional<std::string> & input_text)
: _root(nullptr), _input_filenames({input_filename}), _input_text(input_text)
: _root(nullptr),
_input_filenames({input_filename}),
_input_text(input_text),
_app_type(std::string())
{
}

Expand Down
Expand Up @@ -14,5 +14,3 @@
type = Steady
[]

[Application]
[]

0 comments on commit 21b74c8

Please sign in to comment.