Skip to content

Commit

Permalink
Multiple input file support (idaholab#17989)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Jun 9, 2021
1 parent b0ea463 commit 7b84a5c
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 131 deletions.
11 changes: 7 additions & 4 deletions framework/include/base/MooseApp.h
Expand Up @@ -187,7 +187,10 @@ class MooseApp : public ConsoleStreamInterface, public libMesh::ParallelObject
/**
* Returns the input file name that was set with setInputFileName
*/
std::string getInputFileName() const { return _input_filename; }
std::string getInputFileName() const
{
return _input_filenames.empty() ? "" : _input_filenames[0];
}

/**
* Override the selection of the output file base name.
Expand Down Expand Up @@ -271,7 +274,7 @@ class MooseApp : public ConsoleStreamInterface, public libMesh::ParallelObject
Real getGlobalTimeOffset() const { return _global_time_offset; }

/**
* Return the filename that was parsed
* Return the primary (first) filename that was parsed
* Note: When stripLeadingPath is false, this function returns the same name as
* getInputFileName() method when the input file is not a link.
*/
Expand Down Expand Up @@ -885,8 +888,8 @@ class MooseApp : public ConsoleStreamInterface, public libMesh::ParallelObject
/// The RankMap is a useful object for determining how
const RankMap _rank_map;

/// Input file name used
std::string _input_filename;
/// Input file names used
std::vector<std::string> _input_filenames;

/// The output file basename
std::string _output_file_base;
Expand Down
10 changes: 5 additions & 5 deletions framework/include/parser/Parser.h
Expand Up @@ -63,15 +63,15 @@ class Parser : public ConsoleStreamInterface, public hit::Walker
virtual ~Parser();

/**
* Return the filename that was parsed
* Return the primary (first) filename that was parsed
*/
std::string getFileName(bool stripLeadingPath = true) const;
std::string getPrimaryFileName(bool stripLeadingPath = true) const;

/**
* Parse an input file consisting of hit syntax and setup objects
* in the MOOSE derived application
*/
void parse(const std::string & input_filename);
void parse(const std::vector<std::string> & input_filenames);

/**
* This function attempts to extract values from the input file based on the contents of
Expand Down Expand Up @@ -216,8 +216,8 @@ class Parser : public ConsoleStreamInterface, public hit::Walker
/// Object for holding the syntax parse tree
std::unique_ptr<SyntaxTree> _syntax_formatter;

/// The input file name that is used for parameter extraction
std::string _input_filename;
/// The input file names that are used for parameter extraction
std::vector<std::string> _input_filenames;

/// The set of all variables extracted from the input file
std::set<std::string> _extracted_vars;
Expand Down
2 changes: 1 addition & 1 deletion framework/src/actions/MeshOnlyAction.C
Expand Up @@ -54,7 +54,7 @@ MeshOnlyAction::act()

if (should_generate)
{
mesh_file = _app.parser().getFileName();
mesh_file = _app.parser().getPrimaryFileName();
size_t pos = mesh_file.find_last_of('.');

// Default to writing out an ExodusII mesh base on the input filename.
Expand Down
21 changes: 13 additions & 8 deletions framework/src/base/MooseApp.C
Expand Up @@ -83,7 +83,11 @@ MooseApp::validParams()

params.addCommandLineParam<bool>(
"display_version", "-v --version", false, "Print application version");
params.addCommandLineParam<std::string>("input_file", "-i <input_file>", "Specify an input file");
params.addCommandLineParam<std::vector<std::string>>(
"input_file",
"-i <input_files>",
"Specify one or multiple input files. Multiple files get merged into a single simulation "
"input.");
params.addCommandLineParam<std::string>(
"mesh_only",
"--mesh-only [mesh_file_name]",
Expand Down Expand Up @@ -868,11 +872,11 @@ MooseApp::setupOptions()
Moose::out << "MooseApp Type: " << type() << std::endl;
_ready_to_exit = true;
}
else if (_input_filename != "" ||
else if (!_input_filenames.empty() ||
isParamValid("input_file")) // They already specified an input filename
{
if (_input_filename == "")
_input_filename = getParam<std::string>("input_file");
if (_input_filenames.empty())
_input_filenames = getParam<std::vector<std::string>>("input_file");

if (isParamValid("recover"))
{
Expand All @@ -897,7 +901,7 @@ MooseApp::setupOptions()
_restart_recover_suffix = getParam<std::string>("recoversuffix");
}

_parser.parse(_input_filename);
_parser.parse(_input_filenames);

if (isParamValid("mesh_only"))
{
Expand Down Expand Up @@ -929,7 +933,7 @@ MooseApp::setupOptions()
}
else if (isUltimateMaster())
{
// if this app is a master, we use the input file name as the default file base
// if this app is a master, we use the first input file name as the default file base
std::string base = getInputFileName();
size_t pos = base.find_last_of('.');
_output_file_base = base.substr(0, pos);
Expand All @@ -956,7 +960,8 @@ MooseApp::setupOptions()
void
MooseApp::setInputFileName(const std::string & input_filename)
{
_input_filename = input_filename;
// for now we only permit single input to be set for multiapps
_input_filenames = {input_filename};
}

std::string
Expand Down Expand Up @@ -1317,7 +1322,7 @@ MooseApp::setStartTime(Real time)
std::string
MooseApp::getFileName(bool stripLeadingPath) const
{
return _parser.getFileName(stripLeadingPath);
return _parser.getPrimaryFileName(stripLeadingPath);
}

OutputWarehouse &
Expand Down

0 comments on commit 7b84a5c

Please sign in to comment.