diff --git a/include/openmc/cross_sections.h b/include/openmc/cross_sections.h index 2b0473becd..06140a6a8c 100644 --- a/include/openmc/cross_sections.h +++ b/include/openmc/cross_sections.h @@ -62,6 +62,11 @@ extern vector libraries; //! libraries void read_cross_sections_xml(); +//! Read cross sections file (either XML or multigroup H5) and populate data +//! libraries +//! \param[in] root node of the cross_sections.xml +void read_cross_sections_xml(pugi::xml_node root); + //! Load nuclide and thermal scattering data from HDF5 files // //! \param[in] nuc_temps Temperatures for each nuclide in [K] diff --git a/include/openmc/geometry_aux.h b/include/openmc/geometry_aux.h index b248d491ac..a4c506c31a 100644 --- a/include/openmc/geometry_aux.h +++ b/include/openmc/geometry_aux.h @@ -10,6 +10,7 @@ #include #include "openmc/vector.h" +#include "openmc/xml_interface.h" namespace openmc { @@ -19,8 +20,13 @@ extern std::unordered_map> extern std::unordered_map universe_level_counts; } // namespace model +//! Read geometry from XML file void read_geometry_xml(); +//! Read geometry from XML node +//! \param[in] root node of geometry XML element +void read_geometry_xml(pugi::xml_node root); + //============================================================================== //! Replace Universe, Lattice, and Material IDs with indices. //============================================================================== diff --git a/include/openmc/material.h b/include/openmc/material.h index b251a3ca85..81f4e1421c 100644 --- a/include/openmc/material.h +++ b/include/openmc/material.h @@ -221,6 +221,10 @@ double density_effect(const vector& f, const vector& e_b_sq, //! Read material data from materials.xml void read_materials_xml(); +//! Read material data XML node +//! \param[in] root node of materials XML element +void read_materials_xml(pugi::xml_node root); + void free_memory_material(); } // namespace openmc diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 650b7e16a1..a415b17473 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -279,6 +279,10 @@ void voxel_finalize(hid_t dspace, hid_t dset, hid_t memspace); //! Read plot specifications from a plots.xml file void read_plots_xml(); +//! Read plot specifications from an XML Node +//! \param[in] XML node containing plot info +void read_plots_xml(pugi::xml_node root); + //! Clear memory void free_memory_plot(); diff --git a/include/openmc/settings.h b/include/openmc/settings.h index 1e061b235b..cd0ab477c4 100644 --- a/include/openmc/settings.h +++ b/include/openmc/settings.h @@ -127,9 +127,12 @@ extern double weight_survive; //!< Survival weight after Russian roulette //============================================================================== //! Read settings from XML file -//! \param[in] root XML node for void read_settings_xml(); +//! Read settings from XML node +//! \param[in] root XML node for +void read_settings_xml(pugi::xml_node root); + void free_memory_settings(); } // namespace openmc diff --git a/include/openmc/tallies/tally.h b/include/openmc/tallies/tally.h index 3cead91dc7..56a51370a8 100644 --- a/include/openmc/tallies/tally.h +++ b/include/openmc/tallies/tally.h @@ -48,10 +48,10 @@ public: void set_nuclides(const vector& nuclides); //! returns vector of indices corresponding to the tally this is called on - const vector& filters() const { return filters_; } + const vector& filters() const { return filters_; } //! \brief Returns the tally filter at index i - int32_t filters(int i) const { return filters_[i]; } + int32_t filters(int i) const { return filters_[i]; } void set_filters(gsl::span filters); @@ -178,6 +178,10 @@ extern double global_tally_leakage; //! Read tally specification from tallies.xml void read_tallies_xml(); +//! Read tally specification from an XML node +//! \param[in] root node of tallies XML element +void read_tallies_xml(pugi::xml_node root); + //! \brief Accumulate the sum of the contributions from each history within the //! batch to a new random variable void accumulate_tallies(); diff --git a/src/cross_sections.cpp b/src/cross_sections.cpp index afb0a1f36c..2094fd551f 100644 --- a/src/cross_sections.cpp +++ b/src/cross_sections.cpp @@ -91,8 +91,7 @@ Library::Library(pugi::xml_node node, const std::string& directory) // Non-member functions //============================================================================== -void read_cross_sections_xml() -{ +void read_cross_sections_xml() { pugi::xml_document doc; std::string filename = settings::path_input + "materials.xml"; // Check if materials.xml exists @@ -104,6 +103,11 @@ void read_cross_sections_xml() auto root = doc.document_element(); + read_cross_sections_xml(root); +} + +void read_cross_sections_xml(pugi::xml_node root) +{ // Find cross_sections.xml file -- the first place to look is the // materials.xml file. If no file is found there, then we check the // OPENMC_CROSS_SECTIONS environment variable diff --git a/src/geometry_aux.cpp b/src/geometry_aux.cpp index 2614719840..83e8494de6 100644 --- a/src/geometry_aux.cpp +++ b/src/geometry_aux.cpp @@ -40,8 +40,7 @@ void update_universe_cell_count(int32_t a, int32_t b) } } -void read_geometry_xml() -{ +void read_geometry_xml() { // Display output message write_message("Reading geometry XML file...", 5); @@ -61,6 +60,11 @@ void read_geometry_xml() // Get root element pugi::xml_node root = doc.document_element(); + read_geometry_xml(root); +} + +void read_geometry_xml(pugi::xml_node root) +{ // Read surfaces, cells, lattice read_surfaces(root); read_cells(root); diff --git a/src/initialize.cpp b/src/initialize.cpp index aa353aa9cb..44f84034a7 100644 --- a/src/initialize.cpp +++ b/src/initialize.cpp @@ -14,6 +14,7 @@ #include "openmc/constants.h" #include "openmc/cross_sections.h" #include "openmc/error.h" +#include "openmc/file_utils.h" #include "openmc/geometry_aux.h" #include "openmc/hdf5_interface.h" #include "openmc/material.h" @@ -291,10 +292,53 @@ int parse_command_line(int argc, char* argv[]) void read_input_xml() { - read_settings_xml(); + + // search for a single model.xml file + // Check if settings.xml exists + std::string model_filename = settings::path_input + "model.xml"; + bool use_model_file = file_exists(model_filename); + pugi::xml_node model_root; + if (use_model_file) { + write_message("Found model.xml file."); + pugi::xml_document doc; + auto result = doc.load_file(model_filename.c_str()); + if (!result) { + fatal_error("Error processing model.xml file."); + } + auto model_root = doc.document_element(); + + 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("A '{}' file is also present. This file will be ignored.", input)); + } + } + } else { + write_message("No model.xml found. Reading separate XML inputs..."); + } + if (use_model_file) { + if (!check_for_node(model_root, "settings")) { + fatal_error("No node present in the model.xml file."); + } + read_settings_xml(model_root.child("settings")); + } else { + read_settings_xml(); + } + read_cross_sections_xml(); - read_materials_xml(); - read_geometry_xml(); + if (use_model_file) { + if (!check_for_node(model_root, "materials")) { + fatal_error("No node present in the model.xml file."); + } + read_materials_xml(model_root.child("materials")); + if (!check_for_node(model_root, "geometry")) { + fatal_error("No node present in the model.xml_file."); + } + read_geometry_xml(model_root.child("geometry")); + } else { + read_materials_xml(); + read_geometry_xml(); + } // Final geometry setup and assign temperatures finalize_geometry(); @@ -302,14 +346,23 @@ void read_input_xml() // Finalize cross sections having assigned temperatures finalize_cross_sections(); - read_tallies_xml(); + if (use_model_file && check_for_node(model_root, "tallies")) { + read_tallies_xml(model_root.child("tallies")); + } else { + read_tallies_xml(); + } // Initialize distribcell_filters prepare_distribcell(); // Read the plots.xml regardless of plot mode in case plots are requested // via the API - read_plots_xml(); + if (use_model_file) { + if (check_for_node(model_root, "plots")) + read_plots_xml(model_root.child("plots")); + } else { + read_plots_xml(); + } if (settings::run_mode == RunMode::PLOTTING) { // Read plots.xml if it exists if (mpi::master && settings::verbosity >= 5) diff --git a/src/material.cpp b/src/material.cpp index 30dfa5ed50..f2e23aede2 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -1264,8 +1264,7 @@ double density_effect(const vector& f, const vector& e_b_sq, return delta - w_sq * (1.0 - beta_sq); } -void read_materials_xml() -{ +void read_materials_xml() { write_message("Reading materials XML file...", 5); pugi::xml_document doc; @@ -1281,6 +1280,12 @@ void read_materials_xml() // Loop over XML material elements and populate the array. pugi::xml_node root = doc.document_element(); + + read_materials_xml(root); +} + +void read_materials_xml(pugi::xml_node root) +{ for (pugi::xml_node material_node : root.children("material")) { model::materials.push_back(make_unique(material_node)); } diff --git a/src/plot.cpp b/src/plot.cpp index b012ed1311..e28543cdff 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -124,8 +124,7 @@ extern "C" int openmc_plot_geometry() return 0; } -void read_plots_xml() -{ +void read_plots_xml() { // Check if plots.xml exists; this is only necessary when the plot runmode is // initiated. Otherwise, we want to read plots.xml because it may be called // later via the API. In that case, its ok for a plots.xml to not exist @@ -141,6 +140,10 @@ void read_plots_xml() doc.load_file(filename.c_str()); pugi::xml_node root = doc.document_element(); +} + +void read_plots_xml(pugi::xml_node root) +{ for (auto node : root.children("plot")) { model::plots.emplace_back(node); model::plot_map[model::plots.back().id_] = model::plots.size() - 1; diff --git a/src/settings.cpp b/src/settings.cpp index eb0d4936c7..710fb28101 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -211,13 +211,11 @@ void get_run_parameters(pugi::xml_node node_base) } } -void read_settings_xml() -{ +void read_settings_xml() { using namespace settings; using namespace pugi; - // Check if settings.xml exists - std::string filename = path_input + "settings.xml"; + std::string filename = settings::path_input + "settings.xml"; if (!file_exists(filename)) { if (run_mode != RunMode::PLOTTING) { fatal_error( @@ -245,6 +243,14 @@ void read_settings_xml() // Get root element xml_node root = doc.document_element(); + read_settings_xml(root); +} + +void read_settings_xml(pugi::xml_node root) +{ + using namespace settings; + using namespace pugi; + // Verbosity if (check_for_node(root, "verbosity")) { verbosity = std::stoi(get_node_value(root, "verbosity")); diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index 51194684ae..1c1f274d79 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -705,8 +705,7 @@ std::string Tally::nuclide_name(int nuclide_idx) const // Non-member functions //============================================================================== -void read_tallies_xml() -{ +void read_tallies_xml() { // Check if tallies.xml exists. If not, just return since it is optional std::string filename = settings::path_input + "tallies.xml"; if (!file_exists(filename)) @@ -719,6 +718,11 @@ void read_tallies_xml() doc.load_file(filename.c_str()); pugi::xml_node root = doc.document_element(); + read_tallies_xml(root); +} + +void read_tallies_xml(pugi::xml_node root) +{ // Check for setting if (check_for_node(root, "assume_separate")) { settings::assume_separate = get_node_value_bool(root, "assume_separate");