diff --git a/include/openmc/cross_sections.h b/include/openmc/cross_sections.h index 72e89692c4..d8a3799c58 100644 --- a/include/openmc/cross_sections.h +++ b/include/openmc/cross_sections.h @@ -30,24 +30,36 @@ public: } // Data members - Type type_; - std::vector materials_; - std::string path_; + Type type_; //!< Type of data library + std::vector materials_; //!< Materials contained in library + std::string path_; //!< File path to library }; +using LibraryKey = std::pair; + //============================================================================== // Global variable declarations //============================================================================== +namespace data { + +//!< Data libraries extern std::vector libraries; -using LibraryKey = std::pair; -extern std::map library_dict; + +//! Maps (type, name) to index in libraries +extern std::map library_map; + +} // namespace data //============================================================================== // Non-member functions //============================================================================== +//! Read cross sections file (either XML or multigroup H5) and populate data +//! libraries extern "C" void read_cross_sections_xml(); + +//! Read cross_sections.xml and populate data libraries void read_ce_cross_sections_xml(); } // namespace openmc diff --git a/src/cross_sections.cpp b/src/cross_sections.cpp index ebe9dc0e7e..aca46a5b9a 100644 --- a/src/cross_sections.cpp +++ b/src/cross_sections.cpp @@ -19,10 +19,12 @@ namespace openmc { // Global variable declarations //============================================================================== -std::vector libraries; -std::map library_dict; +namespace data { -extern "C" void read_mg_cross_sections_header(); +std::vector libraries; +std::map library_map; + +} //============================================================================== // Library methods @@ -76,6 +78,8 @@ Library::Library(pugi::xml_node node, const std::string& directory) // Non-member functions //============================================================================== +extern "C" void read_mg_cross_sections_header(); + void read_cross_sections_xml() { // Check if materials.xml exists @@ -146,12 +150,12 @@ void read_cross_sections_xml() // Establish mapping between (type, material) and index in libraries int i = 0; - for (const auto& lib : libraries) { + for (const auto& lib : data::libraries) { for (const auto& name : lib.materials_) { std::string lower_name = name; to_lower(lower_name); LibraryKey key {lib.type_, lower_name}; - library_dict.insert({key, i}); + data::library_map.insert({key, i}); } ++i; } @@ -161,7 +165,7 @@ void read_cross_sections_xml() std::string lower_name = name; to_lower(lower_name); LibraryKey key {Library::Type::neutron, lower_name}; - if (library_dict.find(key) == library_dict.end()) { + if (data::library_map.find(key) == data::library_map.end()) { fatal_error("Could not find resonant scatterer " + name + " in cross_sections.xml file!"); } @@ -200,11 +204,11 @@ void read_ce_cross_sections_xml() } for (const auto& node_library : root.children("library")) { - libraries.emplace_back(node_library, directory); + data::libraries.emplace_back(node_library, directory); } // Make sure file was not empty - if (libraries.empty()) { + if (data::libraries.empty()) { fatal_error("No cross section libraries present in cross_sections.xml file."); } } @@ -214,25 +218,25 @@ void read_ce_cross_sections_xml() //============================================================================== extern "C" void library_clear() { - libraries.clear(); - library_dict.clear(); + data::libraries.clear(); + data::library_map.clear(); } extern "C" const char* library_path(int type, const char* name) { auto lib_type = static_cast(type); LibraryKey key {lib_type, name}; - if (library_dict.find(key) == library_dict.end()) { + if (data::library_map.find(key) == data::library_map.end()) { return nullptr; } else { - auto idx = library_dict[key]; - return libraries[idx].path_.c_str(); + auto idx = data::library_map[key]; + return data::libraries[idx].path_.c_str(); } } extern "C" bool library_present(int type, const char* name) { auto lib_type = static_cast(type); LibraryKey key {lib_type, name}; - return library_dict.find(key) != library_dict.end(); + return data::library_map.find(key) != data::library_map.end(); } } // namespace openmc diff --git a/src/mgxs_interface.cpp b/src/mgxs_interface.cpp index 9b320c4e1c..80aa66621c 100644 --- a/src/mgxs_interface.cpp +++ b/src/mgxs_interface.cpp @@ -122,7 +122,7 @@ void read_mg_cross_sections_header_c(hid_t file_id) Library lib {}; lib.type_ = Library::Type::neutron; lib.materials_.push_back(name); - libraries.push_back(lib); + data::libraries.push_back(lib); } }