From ef2f690e3d4c7bb1f700f189bdaad88689fa5b16 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 6 Dec 2022 12:59:08 -0600 Subject: [PATCH] Updating handling of single XML input to leverage existing settings::path_input --- src/initialize.cpp | 42 +++++++++++++++++++----------------------- src/settings.cpp | 3 ++- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/initialize.cpp b/src/initialize.cpp index 212b2f7bd..c0333e01c 100644 --- a/src/initialize.cpp +++ b/src/initialize.cpp @@ -181,9 +181,6 @@ int parse_command_line(int argc, char* argv[]) } else if (arg == "-e" || arg == "--event") { settings::event_based = true; - } else if (arg == "-i" || arg == "--input") { - i += 1; - args_xml_filename = std::string(argv[i]); } else if (arg == "-r" || arg == "--restart") { i += 1; // Check what type of file this is @@ -295,27 +292,24 @@ int parse_command_line(int argc, char* argv[]) } bool read_model_xml() { - // get verbosity from settings node + std::string model_filename = settings::path_input; - std::string xml_filename = "model.xml"; - if (!args_xml_filename.empty()) xml_filename = args_xml_filename; - std::string model_filename = settings::path_input + xml_filename; - - // check that the model file exists. If it does not and a custom filename was - // supplied by the user report an error - if (!file_exists(model_filename)) { - if (!args_xml_filename.empty()) { - fatal_error(fmt::format("The input file '{}' specified on the command line does not exist", args_xml_filename)); - } - return false; + // if the path input isn't an existing file, assume its a directory + // and append the default model.xml filename + if (!file_exists(settings::path_input)) { + model_filename += "/model.xml"; + if (!file_exists(model_filename)) + return false; } - // attempt to open the document + // try to process the path input as an XML file pugi::xml_document doc; - auto result = doc.load_file(model_filename.c_str()); - if (!result) { - fatal_error("Error processing model.xml file."); + // if the input is a file, try to read it + if (!doc.load_file(model_filename.c_str())) { + fatal_error(fmt::format( + "Error reading from single XML input file '{}'", model_filename)); } + pugi::xml_node root = doc.document_element(); // Read settings @@ -348,15 +342,17 @@ bool read_model_xml() { auto other_inputs = {"materials.xml", "geometry.xml", "settings.xml", "tallies.xml", "plots.xml"}; for (const auto& input : other_inputs) { if (file_exists(settings::path_input + input)) { - warning((fmt::format("Other XML file input(s) are present. These file will be ignored in favor of the {} file.", xml_filename))); + warning((fmt::format("Other XML file input(s) are present. These file " + "will be ignored in favor of the {} file.", + model_filename))); break; } } // Read materials and cross sections if (!check_for_node(root, "materials")) { - fatal_error( - fmt::format("No node present in the {} file.", xml_filename)); + fatal_error(fmt::format( + "No node present in the {} file.", model_filename)); } read_cross_sections_xml(root.child("materials")); @@ -365,7 +361,7 @@ bool read_model_xml() { // Read geometry if (!check_for_node(root, "geometry")) { fatal_error(fmt::format( - "No node present in the model.xml_file.", xml_filename)); + "No node present in the model.xml_file.", model_filename)); } read_geometry_xml(root.child("geometry")); diff --git a/src/settings.cpp b/src/settings.cpp index 3048862e3..74d45543d 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -222,7 +222,8 @@ void read_settings_xml() { fmt::format("Settings XML file '{}' does not exist! In order " "to run OpenMC, you first need a set of input files; at a " "minimum, this " - "includes settings.xml, geometry.xml, and materials.xml. " + "includes settings.xml, geometry.xml, and materials.xml " + "or a single XML file containing all of these files. " "Please consult " "the user's guide at https://docs.openmc.org for further " "information.",