mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-21 06:25:30 -04:00
Adding signatures for reading information from an XML node where necessary.
This commit is contained in:
parent
7a9d8c95af
commit
040965245d
13 changed files with 127 additions and 22 deletions
|
|
@ -62,6 +62,11 @@ extern vector<Library> 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]
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "openmc/vector.h"
|
||||
#include "openmc/xml_interface.h"
|
||||
|
||||
namespace openmc {
|
||||
|
||||
|
|
@ -19,8 +20,13 @@ extern std::unordered_map<int32_t, std::unordered_map<int32_t, int32_t>>
|
|||
extern std::unordered_map<int32_t, int32_t> 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.
|
||||
//==============================================================================
|
||||
|
|
|
|||
|
|
@ -221,6 +221,10 @@ double density_effect(const vector<double>& f, const vector<double>& 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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -127,9 +127,12 @@ extern double weight_survive; //!< Survival weight after Russian roulette
|
|||
//==============================================================================
|
||||
|
||||
//! Read settings from XML file
|
||||
//! \param[in] root XML node for <settings>
|
||||
void read_settings_xml();
|
||||
|
||||
//! Read settings from XML node
|
||||
//! \param[in] root XML node for <settings>
|
||||
void read_settings_xml(pugi::xml_node root);
|
||||
|
||||
void free_memory_settings();
|
||||
|
||||
} // namespace openmc
|
||||
|
|
|
|||
|
|
@ -48,10 +48,10 @@ public:
|
|||
void set_nuclides(const vector<std::string>& nuclides);
|
||||
|
||||
//! returns vector of indices corresponding to the tally this is called on
|
||||
const vector<int32_t>& filters() const { return filters_; }
|
||||
const vector<int32_t>& 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<Filter*> 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();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 <settings> 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 <materials> node present in the model.xml file.");
|
||||
}
|
||||
read_materials_xml(model_root.child("materials"));
|
||||
if (!check_for_node(model_root, "geometry")) {
|
||||
fatal_error("No <geometry> 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)
|
||||
|
|
|
|||
|
|
@ -1264,8 +1264,7 @@ double density_effect(const vector<double>& f, const vector<double>& 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>(material_node));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
|
|
|
|||
|
|
@ -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 <assume_separate> setting
|
||||
if (check_for_node(root, "assume_separate")) {
|
||||
settings::assume_separate = get_node_value_bool(root, "assume_separate");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue