diff --git a/include/openmc/mgxs_interface.h b/include/openmc/mgxs_interface.h index 0f4a13038..ce0a4a4c7 100644 --- a/include/openmc/mgxs_interface.h +++ b/include/openmc/mgxs_interface.h @@ -15,28 +15,8 @@ namespace openmc { // Global MGXS data container structure //============================================================================== -struct MgxsInterface -{ - int num_energy_groups; - int num_delayed_groups; - - // List of available names in the HDF5 file - std::vector xs_names; - std::vector xs_to_read; - std::vector> xs_temps_to_read; - - // Name of the HDF5 file which contains mgxs - std::string cross_sections_path; - - std::vector nuclides_MG; - std::vector macro_xs; - - std::vector energy_bins; - std::vector energy_bin_avg; - std::vector rev_energy_bins; - - // temperatues of each available nuclide - std::vector> nuc_temps; +struct MgxsInterface { +public: MgxsInterface() = default; @@ -45,25 +25,45 @@ struct MgxsInterface MgxsInterface(const std::string& path_cross_sections, const std::vector xs_to_read, const std::vector> xs_temps); - void set_nuclides_and_temperatures(std::vector arg_xs_to_read, - std::vector> xs_temps); + // Does things to construct after the nuclides and temperatures to + // read have been specified. void init(); + // Set which nuclides and temperatures are to be read + void set_nuclides_and_temperatures(std::vector xs_to_read, + std::vector> xs_temps); + + // Add an Mgxs object to be managed void add_mgxs(hid_t file_id, const std::string& name, const std::vector& temperature); - void create_macro_xs(); - - std::vector> get_mat_kTs(); - // Reads just the header of the cross sections file, to find // min & max energies as well as the available XS void read_header(const std::string& path_cross_sections); + + // Calculate microscopic cross sections from nuclide macro XS + void create_macro_xs(); + + // Get the kT values which are used in the OpenMC model + std::vector> get_mat_kTs(); + + int num_energy_groups_; + int num_delayed_groups_; + std::vector xs_names_; // available names in HDF5 file + std::vector xs_to_read_; // XS which appear in materials + std::vector> xs_temps_to_read_; // temperatures used + std::string cross_sections_path_; // path to MGXS h5 file + std::vector nuclides_; + std::vector macro_xs_; + std::vector energy_bins_; + std::vector energy_bin_avg_; + std::vector rev_energy_bins_; + std::vector> nuc_temps_; // all available temperatures }; namespace data { - extern MgxsInterface mgInterface; + extern MgxsInterface mg; } // Puts available XS in MGXS file to globals so that when @@ -72,7 +72,7 @@ namespace data { void put_mgxs_header_data_to_globals(); // Set which nuclides and temperatures are to be read on -// mgInterface through global data +// mg through global data void set_mg_interface_nuclides_and_temps(); // After macro XS have been read, materials can be marked as fissionable diff --git a/src/cross_sections.cpp b/src/cross_sections.cpp index 0949a9890..6245bca9f 100644 --- a/src/cross_sections.cpp +++ b/src/cross_sections.cpp @@ -155,7 +155,7 @@ void read_cross_sections_xml() if (settings::run_CE) { read_ce_cross_sections_xml(); } else { - data::mgInterface.read_header(settings::path_cross_sections); + data::mg.read_header(settings::path_cross_sections); put_mgxs_header_data_to_globals(); } diff --git a/src/initialize.cpp b/src/initialize.cpp index 513ee62f5..460db2436 100644 --- a/src/initialize.cpp +++ b/src/initialize.cpp @@ -261,7 +261,7 @@ void read_input_xml() } else { // Create material macroscopic data for MGXS set_mg_interface_nuclides_and_temps(); - data::mgInterface.init(); + data::mg.init(); mark_fissionable_mgxs_materials(); } simulation::time_read_xs.stop(); diff --git a/src/material.cpp b/src/material.cpp index e4579e10e..a5bc3dc13 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -368,7 +368,7 @@ void Material::normalize_density() // determine atomic weight ratio int i_nuc = nuclide_[i]; double awr = settings::run_CE ? - data::nuclides[i_nuc]->awr_ : data::mgInterface.nuclides_MG[i_nuc].awr; + data::nuclides[i_nuc]->awr_ : data::mg.nuclides_[i_nuc].awr; // if given weight percent, convert all values so that they are divided // by awr. thus, when a sum is done over the values, it's actually @@ -388,7 +388,7 @@ void Material::normalize_density() for (int i = 0; i < nuclide_.size(); ++i) { int i_nuc = nuclide_[i]; double awr = settings::run_CE ? - data::nuclides[i_nuc]->awr_ : data::mgInterface.nuclides_MG[i_nuc].awr; + data::nuclides[i_nuc]->awr_ : data::mg.nuclides_[i_nuc].awr; sum_percent += atom_density_(i)*awr; } sum_percent = 1.0 / sum_percent; @@ -726,7 +726,7 @@ void Material::init_bremsstrahlung() void Material::init_nuclide_index() { int n = settings::run_CE ? - data::nuclides.size() : data::mgInterface.nuclides_MG.size(); + data::nuclides.size() : data::mg.nuclides_.size(); mat_nuclide_index_.resize(n); std::fill(mat_nuclide_index_.begin(), mat_nuclide_index_.end(), C_NONE); for (int i = 0; i < nuclide_.size(); ++i) { @@ -994,11 +994,11 @@ void Material::to_hdf5(hid_t group) const } else { for (int i = 0; i < nuclide_.size(); ++i) { int i_nuc = nuclide_[i]; - if (data::mgInterface.nuclides_MG[i_nuc].awr != MACROSCOPIC_AWR) { - nuc_names.push_back(data::mgInterface.nuclides_MG[i_nuc].name); + if (data::mg.nuclides_[i_nuc].awr != MACROSCOPIC_AWR) { + nuc_names.push_back(data::mg.nuclides_[i_nuc].name); nuc_densities.push_back(atom_density_(i)); } else { - macro_names.push_back(data::mgInterface.nuclides_MG[i_nuc].name); + macro_names.push_back(data::mg.nuclides_[i_nuc].name); } } } diff --git a/src/mgxs_interface.cpp b/src/mgxs_interface.cpp index d5d379bd0..1b0f2675a 100644 --- a/src/mgxs_interface.cpp +++ b/src/mgxs_interface.cpp @@ -23,7 +23,7 @@ namespace openmc { //============================================================================== namespace data { - MgxsInterface mgInterface; + MgxsInterface mg; } MgxsInterface::MgxsInterface(const std::string& path_cross_sections, @@ -36,13 +36,13 @@ MgxsInterface::MgxsInterface(const std::string& path_cross_sections, } void MgxsInterface::set_nuclides_and_temperatures( - std::vector arg_xs_to_read, + std::vector xs_to_read, std::vector> xs_temps) { // Check to remove all duplicates - xs_to_read = arg_xs_to_read; - xs_temps_to_read = xs_temps; - if (xs_to_read.size() != xs_temps.size()) + xs_to_read_ = xs_to_read; + xs_temps_to_read_ = xs_temps; + if (xs_to_read_.size() != xs_temps.size()) fatal_error("The list of macro XS temperatures to read does not " "correspond in length to the number of XS names. "); } @@ -51,20 +51,20 @@ void MgxsInterface::init() { // Check that at least some data was set to be read - if (xs_to_read.size() == 0) + if (xs_to_read_.size() == 0) warning("No MGXS nuclides were set to be read."); // Check if MGXS Library exists - if (!file_exists(cross_sections_path)) { + if (!file_exists(cross_sections_path_)) { // Could not find MGXS Library file - fatal_error("Cross sections HDF5 file '" + cross_sections_path + + fatal_error("Cross sections HDF5 file '" + cross_sections_path_ + "' does not exist."); } write_message("Loading cross section data...", 5); // Open file for reading - hid_t file_id = file_open(cross_sections_path, 'r'); + hid_t file_id = file_open(cross_sections_path_, 'r'); // Read filetype std::string type; @@ -84,8 +84,8 @@ void MgxsInterface::init() // ========================================================================== // READ ALL MGXS CROSS SECTION TABLES - for (unsigned i_nuc=0; i_nuc atom_densities(mat->atom_density_.begin(), mat->atom_density_.end()); - // Build array of pointers to nuclides_MG's Mgxs objects needed for this + // Build array of pointers to nuclides's Mgxs objects needed for this // material std::vector mgxs_ptr; for (int i_nuclide : mat->nuclide_) { - mgxs_ptr.push_back(&nuclides_MG[i_nuclide]); + mgxs_ptr.push_back(&nuclides_[i_nuclide]); } - macro_xs.emplace_back(mat->name_, kTs[i], mgxs_ptr, atom_densities, - num_energy_groups, num_delayed_groups); + macro_xs_.emplace_back(mat->name_, kTs[i], mgxs_ptr, atom_densities, + num_energy_groups_, num_delayed_groups_); } else { // Preserve the ordering of materials by including a blank entry - macro_xs.emplace_back(); + macro_xs_.emplace_back(); } } } @@ -182,44 +182,44 @@ std::vector> MgxsInterface::get_mat_kTs() void MgxsInterface::read_header(const std::string& path_cross_sections) { // Save name of HDF5 file to be read to struct data - cross_sections_path = path_cross_sections; + cross_sections_path_ = path_cross_sections; // Check if MGXS Library exists - if (!file_exists(cross_sections_path)) { + if (!file_exists(cross_sections_path_)) { // Could not find MGXS Library file - fatal_error("Cross sections HDF5 file '" + cross_sections_path + + fatal_error("Cross sections HDF5 file '" + cross_sections_path_ + "' does not exist."); } write_message("Reading cross sections HDF5 file...", 5); // Open file for reading - hid_t file_id = file_open(cross_sections_path, 'r', true); + hid_t file_id = file_open(cross_sections_path_, 'r', true); ensure_exists(file_id, "energy_groups", true); - read_attribute(file_id, "energy_groups", num_energy_groups); + read_attribute(file_id, "energy_groups", num_energy_groups_); if (attribute_exists(file_id, "delayed_groups")) { - read_attribute(file_id, "delayed_groups", num_delayed_groups); + read_attribute(file_id, "delayed_groups", num_delayed_groups_); } else { - num_delayed_groups = 0; + num_delayed_groups_ = 0; } ensure_exists(file_id, "group structure", true); - read_attribute(file_id, "group structure", rev_energy_bins); + read_attribute(file_id, "group structure", rev_energy_bins_); // Reverse energy bins - std::copy(rev_energy_bins.crbegin(), rev_energy_bins.crend(), - std::back_inserter(energy_bins)); + std::copy(rev_energy_bins_.crbegin(), rev_energy_bins_.crend(), + std::back_inserter(energy_bins_)); // Create average energies - for (int i = 0; i < energy_bins.size() - 1; ++i) { - energy_bin_avg.push_back(0.5* - (energy_bins[i] + energy_bins[i+1])); + 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 - xs_names = group_names(file_id); - if (xs_names.empty()) { + xs_names_ = group_names(file_id); + if (xs_names_.empty()) { fatal_error("At least one MGXS data set must be present in mgxs " "library file!"); } @@ -232,13 +232,13 @@ void put_mgxs_header_data_to_globals() { // Get the minimum and maximum energies int neutron = static_cast(Particle::Type::neutron); - data::energy_min[neutron] = data::mgInterface.energy_bins.back(); - data::energy_max[neutron] = data::mgInterface.energy_bins.front(); + data::energy_min[neutron] = data::mg.energy_bins_.back(); + data::energy_max[neutron] = data::mg.energy_bins_.front(); // Save available XS names to library list, so that when // materials are read, the specified mgxs can be confirmed // as present - for (auto& name : data::mgInterface.xs_names) { + for (auto& name : data::mg.xs_names_) { Library lib {}; lib.type_ = Library::Type::neutron; lib.materials_.push_back(name); @@ -249,9 +249,9 @@ void put_mgxs_header_data_to_globals() void set_mg_interface_nuclides_and_temps() { // Get temperatures from global data - std::vector> these_nuc_temps(data::nuclide_map.size()); + std::vector> nuc_temps(data::nuclide_map.size()); std::vector> dummy; - get_temperatures(these_nuc_temps, dummy); + get_temperatures(nuc_temps, dummy); // Build vector of nuclide names which are to be read std::vector nuclide_names(data::nuclide_map.size()); @@ -267,8 +267,8 @@ void set_mg_interface_nuclides_and_temps() std::string& name = nuclide_names[i_nuc]; if (already_read.find(name) == already_read.end()) { - data::mgInterface.xs_to_read.push_back(name); - data::mgInterface.xs_temps_to_read.push_back(these_nuc_temps[i_nuc]); + data::mg.xs_to_read_.push_back(name); + data::mg.xs_temps_to_read_.push_back(nuc_temps[i_nuc]); already_read.insert(name); } } @@ -280,7 +280,7 @@ void mark_fissionable_mgxs_materials() // Loop over all files for (const auto& mat : model::materials) { for (int i_nuc : mat->nuclide_) { - if (data::mgInterface.nuclides_MG[i_nuc].fissionable) { + if (data::mg.nuclides_[i_nuc].fissionable) { mat->fissionable_ = true; } } @@ -295,7 +295,7 @@ void calculate_xs_c(int i_mat, int gin, double sqrtkT, Direction u, double& total_xs, double& abs_xs, double& nu_fiss_xs) { - data::mgInterface.macro_xs[i_mat].calculate_xs(gin - 1, sqrtkT, u, total_xs, abs_xs, + data::mg.macro_xs_[i_mat].calculate_xs(gin - 1, sqrtkT, u, total_xs, abs_xs, nu_fiss_xs); } @@ -313,7 +313,7 @@ get_nuclide_xs(int index, int xstype, int gin, const int* gout, } else { gout_c_p = gout; } - return data::mgInterface.nuclides_MG[index].get_xs(xstype, gin - 1, gout_c_p, mu, dg); + return data::mg.nuclides_[index].get_xs(xstype, gin - 1, gout_c_p, mu, dg); } //============================================================================== @@ -330,7 +330,7 @@ get_macro_xs(int index, int xstype, int gin, const int* gout, } else { gout_c_p = gout; } - return data::mgInterface.macro_xs[index].get_xs(xstype, gin - 1, gout_c_p, mu, dg); + return data::mg.macro_xs_[index].get_xs(xstype, gin - 1, gout_c_p, mu, dg); } //============================================================================== @@ -345,7 +345,7 @@ get_name_c(int index, int name_len, char* name) std::strcpy(name, str.c_str()); // Now get the data and copy to the C-string - str = data::mgInterface.nuclides_MG[index - 1].name; + str = data::mg.nuclides_[index - 1].name; std::strcpy(name, str.c_str()); // Finally, remove the null terminator @@ -357,7 +357,7 @@ get_name_c(int index, int name_len, char* name) double get_awr_c(int index) { - return data::mgInterface.nuclides_MG[index - 1].awr; + return data::mg.nuclides_[index - 1].awr; } } // namespace openmc diff --git a/src/output.cpp b/src/output.cpp index 8fb628e77..899bce86e 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -710,7 +710,7 @@ write_tallies() << data::nuclides[i_nuclide]->name_ << "\n"; } else { tallies_out << std::string(indent+1, ' ') - << data::mgInterface.nuclides_MG[i_nuclide].name << "\n"; + << data::mg.nuclides_[i_nuclide].name << "\n"; } } diff --git a/src/particle.cpp b/src/particle.cpp index 742f1ead3..030c8dc63 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -123,7 +123,7 @@ Particle::from_source(const Bank* src) } else { g_ = static_cast(src->E); g_last_ = static_cast(src->E); - E_ = data::mgInterface.energy_bin_avg[g_ - 1]; + E_ = data::mg.energy_bin_avg_[g_ - 1]; } E_last_ = E_; } diff --git a/src/particle_restart.cpp b/src/particle_restart.cpp index 87b0093d0..8672ebf84 100644 --- a/src/particle_restart.cpp +++ b/src/particle_restart.cpp @@ -52,7 +52,7 @@ void read_particle_restart(Particle& p, int& previous_run_mode) // Set energy group and average energy in multi-group mode if (!settings::run_CE) { p.g_ = p.E_; - p.E_ = data::mgInterface.energy_bin_avg[p.g_ - 1]; + p.E_ = data::mg.energy_bin_avg_[p.g_ - 1]; } // Set particle last attributes diff --git a/src/physics_mg.cpp b/src/physics_mg.cpp index e2682792f..90e76c67a 100644 --- a/src/physics_mg.cpp +++ b/src/physics_mg.cpp @@ -82,7 +82,7 @@ scatter(Particle* p) int gin = p->g_last_ - 1; int gout = p->g_ - 1; int i_mat = p->material_; - data::mgInterface.macro_xs[i_mat].sample_scatter(gin, gout, p->mu_, p->wgt_); + data::mg.macro_xs_[i_mat].sample_scatter(gin, gout, p->mu_, p->wgt_); // Adjust return value for fortran indexing // TODO: Remove when no longer needed @@ -92,7 +92,7 @@ scatter(Particle* p) p->u() = rotate_angle(p->u(), p->mu_, nullptr); // Update energy value for downstream compatability (in tallying) - p->E_ = data::mgInterface.energy_bin_avg[gout]; + p->E_ = data::mg.energy_bin_avg_[gout]; // Set event component p->event_ = EVENT_SCATTER; @@ -148,7 +148,7 @@ create_fission_sites(Particle* p, std::vector& bank) // the energy in the fission bank int dg; int gout; - data::mgInterface.macro_xs[p->material_].sample_fission_energy(p->g_ - 1, dg, gout); + data::mg.macro_xs_[p->material_].sample_fission_energy(p->g_ - 1, dg, gout); site.E = gout + 1; site.delayed_group = dg + 1; diff --git a/src/source.cpp b/src/source.cpp index f495d5572..6b5cb8aba 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -311,9 +311,9 @@ Particle::Bank sample_external_source() // If running in MG, convert site % E to group if (!settings::run_CE) { - site.E = lower_bound_index(data::mgInterface.rev_energy_bins.begin(), - data::mgInterface.rev_energy_bins.end(), site.E); - site.E = data::mgInterface.num_energy_groups - site.E; + site.E = lower_bound_index(data::mg.rev_energy_bins_.begin(), + data::mg.rev_energy_bins_.end(), site.E); + site.E = data::mg.num_energy_groups_ - site.E; } // Set the random number generator back to the tracking stream. diff --git a/src/state_point.cpp b/src/state_point.cpp index f0dcfe2b0..4c159c167 100644 --- a/src/state_point.cpp +++ b/src/state_point.cpp @@ -208,7 +208,7 @@ openmc_statepoint_write(const char* filename, bool* write_source) if (settings::run_CE) { nuclides.push_back(data::nuclides[i_nuclide]->name_); } else { - nuclides.push_back(data::mgInterface.nuclides_MG[i_nuclide].name); + nuclides.push_back(data::mg.nuclides_[i_nuclide].name); } } } diff --git a/src/summary.cpp b/src/summary.cpp index 0c6222cef..1f5f7a097 100644 --- a/src/summary.cpp +++ b/src/summary.cpp @@ -57,7 +57,7 @@ void write_nuclides(hid_t file) nuc_names.push_back(nuc->name_); awrs.push_back(nuc->awr_); } else { - const auto& nuc {data::mgInterface.nuclides_MG[i]}; + const auto& nuc {data::mg.nuclides_[i]}; if (nuc.awr != MACROSCOPIC_AWR) { nuc_names.push_back(nuc.name); awrs.push_back(nuc.awr); diff --git a/src/tallies/filter_energy.cpp b/src/tallies/filter_energy.cpp index d69b335b6..7737e4fac 100644 --- a/src/tallies/filter_energy.cpp +++ b/src/tallies/filter_energy.cpp @@ -43,10 +43,10 @@ EnergyFilter::set_bins(gsl::span bins) // (after flipping for the different ordering of the library and tallying // systems). if (!settings::run_CE) { - if (n_bins_ == data::mgInterface.num_energy_groups) { + if (n_bins_ == data::mg.num_energy_groups_) { matches_transport_groups_ = true; for (gsl::index i = 0; i < n_bins_ + 1; ++i) { - if (data::mgInterface.rev_energy_bins[i] != bins_[i]) { + if (data::mg.rev_energy_bins_[i] != bins_[i]) { matches_transport_groups_ = false; break; } @@ -61,9 +61,9 @@ const { if (p->g_ != F90_NONE && matches_transport_groups_) { if (estimator == ESTIMATOR_TRACKLENGTH) { - match.bins_.push_back(data::mgInterface.num_energy_groups - p->g_); + match.bins_.push_back(data::mg.num_energy_groups_ - p->g_); } else { - match.bins_.push_back(data::mgInterface.num_energy_groups - p->g_last_); + match.bins_.push_back(data::mg.num_energy_groups_ - p->g_last_); } match.weights_.push_back(1.0); @@ -104,7 +104,7 @@ EnergyoutFilter::get_all_bins(const Particle* p, int estimator, FilterMatch& match) const { if (p->g_ != F90_NONE && matches_transport_groups_) { - match.bins_.push_back(data::mgInterface.num_energy_groups - p->g_); + match.bins_.push_back(data::mg.num_energy_groups_ - p->g_); match.weights_.push_back(1.0); } else { diff --git a/src/tallies/tally_scoring.cpp b/src/tallies/tally_scoring.cpp index bd31960be..582e7dced 100644 --- a/src/tallies/tally_scoring.cpp +++ b/src/tallies/tally_scoring.cpp @@ -361,7 +361,7 @@ score_fission_eout(const Particle* p, int i_tally, int i_score, int score_bin) if (settings::run_CE) { E_out = bank.E; } else { - E_out = data::mgInterface.energy_bin_avg[static_cast(bank.E)]; + E_out = data::mg.energy_bin_avg_[static_cast(bank.E)]; } // Set EnergyoutFilter bin index @@ -1376,13 +1376,13 @@ score_general_mg(const Particle* p, int i_tally, int start_index, // To significantly reduce de-referencing, point matxs to the macroscopic // Mgxs for the material of interest - data::mgInterface.macro_xs[p->material_].set_angle_index(p_u); + data::mg.macro_xs_[p->material_].set_angle_index(p_u); // Do same for nucxs, point it to the microscopic nuclide data of interest if (i_nuclide >= 0) { // And since we haven't calculated this temperature index yet, do so now - data::mgInterface.nuclides_MG[i_nuclide].set_temperature_index(p->sqrtkT_); - data::mgInterface.nuclides_MG[i_nuclide].set_angle_index(p_u); + data::mg.nuclides_[i_nuclide].set_temperature_index(p->sqrtkT_); + data::mg.nuclides_[i_nuclide].set_angle_index(p_u); } for (auto i = 0; i < tally.scores_.size(); ++i) { @@ -1869,7 +1869,7 @@ score_general_mg(const Particle* p, int i_tally, int start_index, // delayed-nu-fission xs to the absorption xs for all delayed // groups score = 0.; - for (auto d = 0; d < data::mgInterface.num_delayed_groups; ++d) { + for (auto d = 0; d < data::mg.num_delayed_groups_; ++d) { if (i_nuclide >= 0) { score += p->wgt_absorb_ * flux * get_nuclide_xs(i_nuclide, MG_GET_XS_DECAY_RATE, @@ -1960,7 +1960,7 @@ score_general_mg(const Particle* p, int i_tally, int start_index, continue; } else { score = 0.; - for (auto d = 0; d < data::mgInterface.num_delayed_groups; ++d) { + for (auto d = 0; d < data::mg.num_delayed_groups_; ++d) { if (i_nuclide >= 0) { score += atom_density * flux * get_nuclide_xs(i_nuclide, MG_GET_XS_DECAY_RATE,