From de666e3291a4804fa207ee1c884ddcbb1911998d Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 6 Nov 2018 09:52:18 -0600 Subject: [PATCH] Make sure MG materials get put in libraries --- include/openmc/cross_sections.h | 1 + src/hdf5_interface.cpp | 2 +- src/input_xml.F90 | 12 ------------ src/mgxs_interface.cpp | 15 +++++++++++++++ 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/include/openmc/cross_sections.h b/include/openmc/cross_sections.h index 2b7a94f805..72e89692c4 100644 --- a/include/openmc/cross_sections.h +++ b/include/openmc/cross_sections.h @@ -21,6 +21,7 @@ public: }; // Constructors + Library() { }; Library(pugi::xml_node node, const std::string& directory); // Comparison operator (for using in map) diff --git a/src/hdf5_interface.cpp b/src/hdf5_interface.cpp index 4b0aedd0ae..865b6eb202 100644 --- a/src/hdf5_interface.cpp +++ b/src/hdf5_interface.cpp @@ -362,7 +362,7 @@ member_names(hid_t group_id, H5O_type_t type) char buffer[size]; H5Lget_name_by_idx(group_id, ".", H5_INDEX_NAME, H5_ITER_INC, i, buffer, size, H5P_DEFAULT); - names.emplace_back(&buffer[0], size); + names.emplace_back(&buffer[0]); } return names; } diff --git a/src/input_xml.F90 b/src/input_xml.F90 index 06beee34e1..8dc7452037 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -1907,10 +1907,8 @@ contains subroutine read_mg_cross_sections_header() bind(C) integer :: i ! loop index - integer :: n_libraries logical :: file_exists ! does mgxs.h5 exist? integer(HID_T) :: file_id - character(len=MAX_WORD_LEN), allocatable :: names(:) character(kind=C_CHAR), pointer :: string(:) interface @@ -1984,16 +1982,6 @@ contains call set_particle_energy_bounds(NEUTRON, energy_min(NEUTRON), & energy_max(NEUTRON)) - ! Get the datasets present in the library - call get_groups(file_id, names) - n_libraries = size(names) - - ! Allocate libraries array - if (n_libraries == 0) then - call fatal_error("At least one MGXS data set must be present in & - &mgxs library file!") - end if - ! Close MGXS HDF5 file call file_close(file_id) diff --git a/src/mgxs_interface.cpp b/src/mgxs_interface.cpp index 0729e466c7..9b320c4e1c 100644 --- a/src/mgxs_interface.cpp +++ b/src/mgxs_interface.cpp @@ -2,6 +2,7 @@ #include +#include "openmc/cross_sections.h" #include "openmc/error.h" #include "openmc/math_functions.h" @@ -109,6 +110,20 @@ void read_mg_cross_sections_header_c(hid_t file_id) for (int i = 0; i < energy_bins.size() - 1; ++i) { energy_bin_avg.push_back(0.5*(energy_bins[i] + energy_bins[i+1])); } + + // Add entries into libraries for MG data + auto names = group_names(file_id); + if (names.empty()) { + fatal_error("At least one MGXS data set must be present in mgxs " + "library file!"); + } + + for (auto& name : names) { + Library lib {}; + lib.type_ = Library::Type::neutron; + lib.materials_.push_back(name); + libraries.push_back(lib); + } } //==============================================================================