From 3e45571a5b162febe3ccb0f981b0cbf7576cdaeb Mon Sep 17 00:00:00 2001 From: GuySten Date: Wed, 4 Feb 2026 00:24:10 +0200 Subject: [PATCH 01/18] multigroup inverse-speed data for void regions --- include/openmc/mgxs_interface.h | 2 ++ include/openmc/simulation.h | 1 + src/cell.cpp | 6 ++++++ src/mgxs_interface.cpp | 4 ++++ src/particle.cpp | 6 ++++++ src/simulation.cpp | 1 + 6 files changed, 20 insertions(+) diff --git a/include/openmc/mgxs_interface.h b/include/openmc/mgxs_interface.h index da074f825ee..5afda1e3ad5 100644 --- a/include/openmc/mgxs_interface.h +++ b/include/openmc/mgxs_interface.h @@ -49,6 +49,8 @@ class MgxsInterface { // Get the group index corresponding to a continuous energy int get_group_index(double E); + int size() const { return macro_xs_.size(); } + int num_energy_groups_; int num_delayed_groups_; vector xs_names_; // available names in HDF5 file diff --git a/include/openmc/simulation.h b/include/openmc/simulation.h index 9a6cf1b2131..842adbb07b8 100644 --- a/include/openmc/simulation.h +++ b/include/openmc/simulation.h @@ -34,6 +34,7 @@ extern "C" double extern "C" double k_abs_tra; //!< sum over batches of k_absorption * k_tracklength extern double log_spacing; //!< lethargy spacing for energy grid searches +extern int32_t mg_void_index; //!< index of void xs in mg data extern "C" int n_lost_particles; //!< cumulative number of lost particles extern "C" bool need_depletion_rx; //!< need to calculate depletion rx? extern "C" int restart_batch; //!< batch at which a restart job resumed diff --git a/src/cell.cpp b/src/cell.cpp index ebe28c3d2ce..1b86ef5beeb 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -22,6 +22,7 @@ #include "openmc/material.h" #include "openmc/nuclide.h" #include "openmc/settings.h" +#include "openmc/simulation.h" #include "openmc/xml_interface.h" namespace openmc { @@ -397,6 +398,11 @@ CSGCell::CSGCell(pugi::xml_node cell_node) for (std::string mat : mats) { if (mat.compare("void") == 0) { material_.push_back(MATERIAL_VOID); + if (!settings::run_CE && simulation::mg_void_index < 0) + fatal_error("Could not find void data in the " + "multi-group nuclear data library. " + "Multi-group data for void regions" + " is needed for inverse-velocity data."); } else { material_.push_back(std::stoi(mat)); } diff --git a/src/mgxs_interface.cpp b/src/mgxs_interface.cpp index 34f87d17984..fe6645b4ab1 100644 --- a/src/mgxs_interface.cpp +++ b/src/mgxs_interface.cpp @@ -17,6 +17,7 @@ #include "openmc/nuclide.h" #include "openmc/search.h" #include "openmc/settings.h" +#include "openmc/simulation.h" namespace openmc { @@ -108,6 +109,9 @@ void MgxsInterface::add_mgxs( fmt::format("Data for {} does not exist in provided MGXS Library", name)); } + if (name == "void") + simulation::mg_void_index = size(); + nuclides_.emplace_back( xs_grp, temperature, num_energy_groups_, num_delayed_groups_); close_group(xs_grp); diff --git a/src/particle.cpp b/src/particle.cpp index a1176abc79a..f426b54ae6c 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -66,6 +66,9 @@ double Particle::speed() const return C_LIGHT * std::sqrt(this->E() * (this->E() + 2 * mass)) / (this->E() + mass); } else { + auto mat = this->material(); + if (mat == MATERIAL_VOID) + mat = simulation::mg_void_index; auto& macro_xs = data::mg.macro_xs_[this->material()]; int macro_t = this->mg_xs_cache().t; int macro_a = macro_xs.get_angle_index(this->u()); @@ -232,6 +235,9 @@ void Particle::event_calculate_xs() macro_xs().absorption = 0.0; macro_xs().fission = 0.0; macro_xs().nu_fission = 0.0; + if (!settings::run_CE && simulation::mg_void_index > -1) { + data::mg.macro_xs_[simulation::mg_void_index].calculate_xs(*this); + } } } diff --git a/src/simulation.cpp b/src/simulation.cpp index 18e40a8bc73..f76589cdcdd 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -307,6 +307,7 @@ double keff_std; double k_col_abs {0.0}; double k_col_tra {0.0}; double k_abs_tra {0.0}; +int32_t mg_void_index {-1}; double log_spacing; int n_lost_particles {0}; bool need_depletion_rx {false}; From 1d19ba00064299ce4e26dab58b8b9a278036f941 Mon Sep 17 00:00:00 2001 From: GuySten Date: Wed, 4 Feb 2026 01:06:40 +0200 Subject: [PATCH 02/18] wip --- openmc/mgxs_library.py | 78 +++++++++++++++++++++++++++++++++++++++--- src/cell.cpp | 7 ++-- src/particle.cpp | 11 ++++-- 3 files changed, 84 insertions(+), 12 deletions(-) diff --git a/openmc/mgxs_library.py b/openmc/mgxs_library.py index c1a15998e19..13098ddd3f0 100644 --- a/openmc/mgxs_library.py +++ b/openmc/mgxs_library.py @@ -177,7 +177,9 @@ class XSdata: def __init__(self, name, energy_groups, temperatures=[ROOM_TEMPERATURE_KELVIN], representation=REPRESENTATION_ISOTROPIC, num_delayed_groups=0): - # Initialize class attributes + self._is_void = False + + #Initialize class attributes self.name = name self.energy_groups = energy_groups self.num_delayed_groups = num_delayed_groups @@ -260,6 +262,9 @@ def name(self): def name(self, name): check_type('name for XSdata', name, str) + if name == 'void': + self._is_void = True + self._name = name @property @@ -481,6 +486,8 @@ def add_temperature(self, temperature): Temperature (in units of Kelvin) of the provided dataset. """ + if self._is_void: + raise TypeError('Cannot add temperatures to a void xs') check_type('temperature', temperature, Real) @@ -532,6 +539,8 @@ def set_total(self, total, temperature=ROOM_TEMPERATURE_KELVIN): openmc.mgxs_library.set_total_mgxs() """ + if self._is_void: + raise TypeError('Cannot set total xs in a void') # Get the accepted shapes for this xs shapes = [self.xs_shapes["[G]"]] @@ -561,6 +570,8 @@ def set_absorption(self, absorption, temperature=ROOM_TEMPERATURE_KELVIN): openmc.mgxs_library.set_absorption_mgxs() """ + if self._is_void: + raise TypeError('Cannot set absorption xs in a void') # Get the accepted shapes for this xs shapes = [self.xs_shapes["[G]"]] @@ -590,6 +601,8 @@ def set_fission(self, fission, temperature=ROOM_TEMPERATURE_KELVIN): openmc.mgxs_library.set_fission_mgxs() """ + if self._is_void: + raise TypeError('Cannot set fission xs in a void') # Get the accepted shapes for this xs shapes = [self.xs_shapes["[G]"]] @@ -621,6 +634,8 @@ def set_kappa_fission(self, kappa_fission, temperature=ROOM_TEMPERATURE_KELVIN): openmc.mgxs_library.set_kappa_fission_mgxs() """ + if self._is_void: + raise TypeError('Cannot set kappa-fission xs in a void') # Get the accepted shapes for this xs shapes = [self.xs_shapes["[G]"]] @@ -652,6 +667,8 @@ def set_chi(self, chi, temperature=ROOM_TEMPERATURE_KELVIN): openmc.mgxs_library.set_chi_mgxs() """ + if self._is_void: + raise TypeError('Cannot set chi in a void') # Get the accepted shapes for this xs shapes = [self.xs_shapes["[G']"]] @@ -681,6 +698,8 @@ def set_chi_prompt(self, chi_prompt, temperature=ROOM_TEMPERATURE_KELVIN): openmc.mgxs_library.set_chi_prompt_mgxs() """ + if self._is_void: + raise TypeError('Cannot set chi-prompt in a void') # Get the accepted shapes for this xs shapes = [self.xs_shapes["[G']"]] @@ -710,6 +729,8 @@ def set_chi_delayed(self, chi_delayed, temperature=ROOM_TEMPERATURE_KELVIN): openmc.mgxs_library.set_chi_delayed_mgxs() """ + if self._is_void: + raise TypeError('Cannot set chi-delayed in a void') # Get the accepted shapes for this xs shapes = [self.xs_shapes["[G']"], self.xs_shapes["[DG][G']"]] @@ -741,6 +762,8 @@ def set_beta(self, beta, temperature=ROOM_TEMPERATURE_KELVIN): openmc.mgxs_library.set_beta_mgxs() """ + if self._is_void: + raise TypeError('Cannot set beta in a void') # Get the accepted shapes for this xs shapes = [self.xs_shapes["[DG]"], self.xs_shapes["[DG][G]"]] @@ -770,6 +793,8 @@ def set_decay_rate(self, decay_rate, temperature=ROOM_TEMPERATURE_KELVIN): openmc.mgxs_library.set_decay_rate_mgxs() """ + if self._is_void: + raise TypeError('Cannot set decay rate in a void') # Get the accepted shapes for this xs shapes = [self.xs_shapes["[DG]"]] @@ -799,6 +824,8 @@ def set_scatter_matrix(self, scatter, temperature=ROOM_TEMPERATURE_KELVIN): openmc.mgxs_library.set_scatter_matrix_mgxs() """ + if self._is_void: + raise TypeError('Cannot set scatter matrix in a void') # Get the accepted shapes for this xs shapes = [self.xs_shapes["[G][G'][Order]"]] @@ -830,6 +857,8 @@ def set_multiplicity_matrix(self, multiplicity, temperature=ROOM_TEMPERATURE_KEL openmc.mgxs_library.set_multiplicity_matrix_mgxs() """ + if self._is_void: + raise TypeError('Cannot set multiplicity matrix in a void') # Get the accepted shapes for this xs shapes = [self.xs_shapes["[G][G']"]] @@ -861,6 +890,8 @@ def set_nu_fission(self, nu_fission, temperature=ROOM_TEMPERATURE_KELVIN): openmc.mgxs_library.set_nu_fission_mgxs() """ + if self._is_void: + raise TypeError('Cannot set nu-fission in a void') # Get the accepted shapes for this xs shapes = [self.xs_shapes["[G]"], self.xs_shapes["[G][G']"]] @@ -893,6 +924,8 @@ def set_prompt_nu_fission(self, prompt_nu_fission, temperature=ROOM_TEMPERATURE_ openmc.mgxs_library.set_prompt_nu_fission_mgxs() """ + if self._is_void: + raise TypeError('Cannot set prompt nu-fission in a void') # Get the accepted shapes for this xs shapes = [self.xs_shapes["[G]"], self.xs_shapes["[G][G']"]] @@ -925,6 +958,8 @@ def set_delayed_nu_fission(self, delayed_nu_fission, temperature=ROOM_TEMPERATUR openmc.mgxs_library.set_delayed_nu_fission_mgxs() """ + if self._is_void: + raise TypeError('Cannot set delayed nu-fission in a void') # Get the accepted shapes for this xs shapes = [self.xs_shapes["[DG][G]"], self.xs_shapes["[DG][G][G']"]] @@ -996,6 +1031,8 @@ def set_total_mgxs(self, total, temperature=ROOM_TEMPERATURE_KELVIN, nuclide='to openmc.mgxs.Library.get_xsdata() """ + if self._is_void: + raise TypeError('Cannot set total xs in a void') check_type('total', total, (openmc.mgxs.TotalXS, openmc.mgxs.TransportXS)) @@ -1036,6 +1073,8 @@ def set_absorption_mgxs(self, absorption, temperature=ROOM_TEMPERATURE_KELVIN, openmc.mgxs.Library.get_xsdata() """ + if self._is_void: + raise TypeError('Cannot set absorption xs in a void') check_type('absorption', absorption, openmc.mgxs.AbsorptionXS) check_value('energy_groups', absorption.energy_groups, @@ -1078,6 +1117,8 @@ def set_fission_mgxs(self, fission, temperature=ROOM_TEMPERATURE_KELVIN, nuclide openmc.mgxs.Library.get_xsdata() """ + if self._is_void: + raise TypeError('Cannot set fission in a void') check_type('fission', fission, openmc.mgxs.FissionXS) check_value('energy_groups', fission.energy_groups, @@ -1120,6 +1161,8 @@ def set_nu_fission_mgxs(self, nu_fission, temperature=ROOM_TEMPERATURE_KELVIN, openmc.mgxs.Library.get_xsdata() """ + if self._is_void: + raise TypeError('Cannot set nu-fission in a void') check_type('nu_fission', nu_fission, (openmc.mgxs.FissionXS, openmc.mgxs.NuFissionMatrixXS)) @@ -1171,6 +1214,8 @@ def set_prompt_nu_fission_mgxs(self, prompt_nu_fission, temperature=ROOM_TEMPERA openmc.mgxs.Library.get_xsdata() """ + if self._is_void: + raise TypeError('Cannot set prompt nu-fission in a void') check_type('prompt_nu_fission', prompt_nu_fission, (openmc.mgxs.FissionXS, openmc.mgxs.NuFissionMatrixXS)) @@ -1218,6 +1263,8 @@ def set_delayed_nu_fission_mgxs(self, delayed_nu_fission, temperature=ROOM_TEMPE openmc.mgxs.Library.get_xsdata() """ + if self._is_void: + raise TypeError('Cannot set delayed nu-fission in a void') check_type('delayed_nu_fission', delayed_nu_fission, (openmc.mgxs.DelayedNuFissionXS, @@ -1267,6 +1314,8 @@ def set_kappa_fission_mgxs(self, k_fission, temperature=ROOM_TEMPERATURE_KELVIN, openmc.mgxs.Library.get_xsdata() """ + if self._is_void: + raise TypeError('Cannot set kappa-fission in a void') check_type('kappa_fission', k_fission, openmc.mgxs.KappaFissionXS) check_value('energy_groups', k_fission.energy_groups, @@ -1308,6 +1357,8 @@ def set_chi_mgxs(self, chi, temperature=ROOM_TEMPERATURE_KELVIN, nuclide='total' openmc.mgxs.Library.get_xsdata() """ + if self._is_void: + raise TypeError('Cannot set chi in a void') check_type('chi', chi, openmc.mgxs.Chi) check_value('energy_groups', chi.energy_groups, [self.energy_groups]) @@ -1346,6 +1397,8 @@ def set_chi_prompt_mgxs(self, chi_prompt, temperature=ROOM_TEMPERATURE_KELVIN, openmc.mgxs.Library.get_xsdata() """ + if self._is_void: + raise TypeError('Cannot set prompt chi in a void') check_type('chi_prompt', chi_prompt, openmc.mgxs.Chi) check_value('prompt', chi_prompt.prompt, [True]) @@ -1388,6 +1441,8 @@ def set_chi_delayed_mgxs(self, chi_delayed, temperature=ROOM_TEMPERATURE_KELVIN, openmc.mgxs.Library.get_xsdata() """ + if self._is_void: + raise TypeError('Cannot set delayed chi in a void') check_type('chi_delayed', chi_delayed, openmc.mgxs.ChiDelayed) check_value('energy_groups', chi_delayed.energy_groups, @@ -1431,6 +1486,8 @@ def set_beta_mgxs(self, beta, temperature=ROOM_TEMPERATURE_KELVIN, openmc.mgxs.Library.get_xsdata() """ + if self._is_void: + raise TypeError('Cannot set beta in a void') check_type('beta', beta, openmc.mgxs.Beta) check_value('num_delayed_groups', beta.num_delayed_groups, @@ -1471,6 +1528,8 @@ def set_decay_rate_mgxs(self, decay_rate, temperature=ROOM_TEMPERATURE_KELVIN, openmc.mgxs.Library.get_xsdata() """ + if self._is_void: + raise TypeError('Cannot set decay rate in a void') check_type('decay_rate', decay_rate, openmc.mgxs.DecayRate) check_value('num_delayed_groups', decay_rate.num_delayed_groups, @@ -1516,6 +1575,8 @@ def set_scatter_matrix_mgxs(self, scatter, temperature=ROOM_TEMPERATURE_KELVIN, openmc.mgxs.Library.get_xsdata() """ + if self._is_void: + raise TypeError('Cannot set scatter matrix in a void') check_type('scatter', scatter, openmc.mgxs.ScatterMatrixXS) check_value('energy_groups', scatter.energy_groups, @@ -1604,6 +1665,8 @@ def set_multiplicity_matrix_mgxs(self, nuscatter, scatter=None, openmc.mgxs.Library.get_xsdata() """ + if self._is_void: + raise TypeError('Cannot set multiplicity matrix in a void') check_type('nuscatter', nuscatter, (openmc.mgxs.ScatterMatrixXS, openmc.mgxs.MultiplicityMatrixXS)) @@ -1992,6 +2055,15 @@ def to_hdf5(self, file): xs_grp = grp.create_group(str(int(np.round(temperature))) + "K") + # Add the kinetics data + if self._inverse_velocity[i] is not None: + xs_grp.create_dataset("inverse-velocity", + data=self._inverse_velocity[i]) + elif self._is_void: + raise TypeError('Void mgxs must have inverse-velocity data.') + + if self._is_void: continue + if self._total[i] is None: raise ValueError('total data must be provided when writing ' 'the HDF5 library') @@ -2141,10 +2213,6 @@ def to_hdf5(self, file): scatt_grp.create_dataset("g_min", data=g_out_bounds[:, :, :, 0]) scatt_grp.create_dataset("g_max", data=g_out_bounds[:, :, :, 1]) - # Add the kinetics data - if self._inverse_velocity[i] is not None: - xs_grp.create_dataset("inverse-velocity", - data=self._inverse_velocity[i]) @classmethod def from_hdf5(cls, group, name, energy_groups, num_delayed_groups): diff --git a/src/cell.cpp b/src/cell.cpp index 1b86ef5beeb..235be310b97 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -399,10 +399,9 @@ CSGCell::CSGCell(pugi::xml_node cell_node) if (mat.compare("void") == 0) { material_.push_back(MATERIAL_VOID); if (!settings::run_CE && simulation::mg_void_index < 0) - fatal_error("Could not find void data in the " - "multi-group nuclear data library. " - "Multi-group data for void regions" - " is needed for inverse-velocity data."); + warning("Void data is not available in the " + "multi-group nuclear data library. " + "Time related calculation results might be wrong!"); } else { material_.push_back(std::stoi(mat)); } diff --git a/src/particle.cpp b/src/particle.cpp index f426b54ae6c..686faea0b9c 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -67,9 +67,14 @@ double Particle::speed() const (this->E() + mass); } else { auto mat = this->material(); - if (mat == MATERIAL_VOID) - mat = simulation::mg_void_index; - auto& macro_xs = data::mg.macro_xs_[this->material()]; + if (mat == MATERIAL_VOID) { + if (simulation::mg_void_index > -1) { + mat = simulation::mg_void_index; + } else { + return 0.0; + } + } + auto& macro_xs = data::mg.macro_xs_[mat]; int macro_t = this->mg_xs_cache().t; int macro_a = macro_xs.get_angle_index(this->u()); return 1.0 / macro_xs.get_xs(MgxsType::INVERSE_VELOCITY, this->g(), nullptr, From 6c51c14f30d7e69f3749c10fb6db3092a126dc76 Mon Sep 17 00:00:00 2001 From: GuySten Date: Wed, 4 Feb 2026 01:18:17 +0200 Subject: [PATCH 03/18] add another warning --- src/xsdata.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/xsdata.cpp b/src/xsdata.cpp index 1929f51e6fa..23b9960f5bc 100644 --- a/src/xsdata.cpp +++ b/src/xsdata.cpp @@ -96,6 +96,11 @@ void XsData::from_hdf5(hid_t xsdata_grp, bool fissionable, read_nd_vector(xsdata_grp, "absorption", absorption, true); read_nd_vector(xsdata_grp, "inverse-velocity", inverse_velocity); + if (!object_exists(xsdata_grp, "inverse-velocity")) { + warning("Inverse-velocity is not available in XsData " + "Time related calculation results might be wrong!"); + } + // Get scattering data scatter_from_hdf5( xsdata_grp, n_ang, scatter_format, final_scatter_format, order_data); From 51dfb7653801afff3bc77e01434d2e174c6a2ea8 Mon Sep 17 00:00:00 2001 From: GuySten Date: Wed, 4 Feb 2026 02:10:27 +0200 Subject: [PATCH 04/18] wip --- include/openmc/mgxs_interface.h | 3 +-- include/openmc/simulation.h | 1 - openmc/mgxs_library.py | 4 +++- src/cell.cpp | 5 ++--- src/mgxs_interface.cpp | 28 ++++++++++++++++++++++++---- src/particle.cpp | 7 ++----- src/simulation.cpp | 1 - 7 files changed, 32 insertions(+), 17 deletions(-) diff --git a/include/openmc/mgxs_interface.h b/include/openmc/mgxs_interface.h index 5afda1e3ad5..71072056778 100644 --- a/include/openmc/mgxs_interface.h +++ b/include/openmc/mgxs_interface.h @@ -49,8 +49,6 @@ class MgxsInterface { // Get the group index corresponding to a continuous energy int get_group_index(double E); - int size() const { return macro_xs_.size(); } - int num_energy_groups_; int num_delayed_groups_; vector xs_names_; // available names in HDF5 file @@ -63,6 +61,7 @@ class MgxsInterface { vector energy_bin_avg_; vector rev_energy_bins_; vector> nuc_temps_; // all available temperatures + vecotr void_velocities_; // velocity of particles in void regions }; namespace data { diff --git a/include/openmc/simulation.h b/include/openmc/simulation.h index 842adbb07b8..9a6cf1b2131 100644 --- a/include/openmc/simulation.h +++ b/include/openmc/simulation.h @@ -34,7 +34,6 @@ extern "C" double extern "C" double k_abs_tra; //!< sum over batches of k_absorption * k_tracklength extern double log_spacing; //!< lethargy spacing for energy grid searches -extern int32_t mg_void_index; //!< index of void xs in mg data extern "C" int n_lost_particles; //!< cumulative number of lost particles extern "C" bool need_depletion_rx; //!< need to calculate depletion rx? extern "C" int restart_batch; //!< batch at which a restart job resumed diff --git a/openmc/mgxs_library.py b/openmc/mgxs_library.py index 13098ddd3f0..a02e05ec3f7 100644 --- a/openmc/mgxs_library.py +++ b/openmc/mgxs_library.py @@ -11,7 +11,7 @@ import openmc.mgxs from openmc.mgxs import SCATTER_TABULAR, SCATTER_LEGENDRE, SCATTER_HISTOGRAM from .checkvalue import check_type, check_value, check_greater_than, \ - check_iterable_type, check_less_than, check_filetype_version, PathLike + check_iterable_type, check_length, check_less_than, check_filetype_version, PathLike ROOM_TEMPERATURE_KELVIN = 294.0 @@ -327,6 +327,8 @@ def temperatures(self): @temperatures.setter def temperatures(self, temperatures): + if self._is_void: + check_length('temperatures', temperatures, 1, 1) check_iterable_type('temperatures', temperatures, Real) self._temperatures = np.array(temperatures) diff --git a/src/cell.cpp b/src/cell.cpp index 235be310b97..0664ccd9f2a 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -22,7 +22,6 @@ #include "openmc/material.h" #include "openmc/nuclide.h" #include "openmc/settings.h" -#include "openmc/simulation.h" #include "openmc/xml_interface.h" namespace openmc { @@ -398,8 +397,8 @@ CSGCell::CSGCell(pugi::xml_node cell_node) for (std::string mat : mats) { if (mat.compare("void") == 0) { material_.push_back(MATERIAL_VOID); - if (!settings::run_CE && simulation::mg_void_index < 0) - warning("Void data is not available in the " + if (!settings::run_CE && mg::void_velocities_.empty()) + warning("Void inverse-velocity data is not available in the " "multi-group nuclear data library. " "Time related calculation results might be wrong!"); } else { diff --git a/src/mgxs_interface.cpp b/src/mgxs_interface.cpp index fe6645b4ab1..d71beafe679 100644 --- a/src/mgxs_interface.cpp +++ b/src/mgxs_interface.cpp @@ -17,7 +17,6 @@ #include "openmc/nuclide.h" #include "openmc/search.h" #include "openmc/settings.h" -#include "openmc/simulation.h" namespace openmc { @@ -83,6 +82,30 @@ void MgxsInterface::init() "supported by OpenMC."); } + // Read void velocities + if (object_exists(file_id, "void")) { + auto void_grp = open_group(file_id, "void"); + // Determine the available temperatures + hid_t kT_group = open_group(void_grp, "kTs"); + size_t num_temps = get_num_datasets(kT_group); + char** dset_names = new char*[num_temps]; + for (int i = 0; i < num_temps; i++) { + dset_names[i] = new char[151]; + } + get_datasets(kT_group, dset_names); + if (num_temps > 1) + fatal_error("Multigroup void data must have only one dummy temperature"); + xsdata_grp = open_group(kT_group, dset_names[0]); + auto inverse_velocity = xt::zeros({ + num_energy_groups_, + }); + read_nd_vector(xsdata_grp, "inverse-velocity", inverse_velocity); + auto velocity = 1.0 / inverse_velocity; + for (double v : velocity) { + void_velocities_.push_back(v); + } + } + // ========================================================================== // READ ALL MGXS CROSS SECTION TABLES for (unsigned i_nuc = 0; i_nuc < xs_to_read_.size(); ++i_nuc) @@ -109,9 +132,6 @@ void MgxsInterface::add_mgxs( fmt::format("Data for {} does not exist in provided MGXS Library", name)); } - if (name == "void") - simulation::mg_void_index = size(); - nuclides_.emplace_back( xs_grp, temperature, num_energy_groups_, num_delayed_groups_); close_group(xs_grp); diff --git a/src/particle.cpp b/src/particle.cpp index 686faea0b9c..f1146d5d0d7 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -68,8 +68,8 @@ double Particle::speed() const } else { auto mat = this->material(); if (mat == MATERIAL_VOID) { - if (simulation::mg_void_index > -1) { - mat = simulation::mg_void_index; + if (!mg::void_velocities_.empty()) { + return mg::void_velocities_[this->g()]; } else { return 0.0; } @@ -240,9 +240,6 @@ void Particle::event_calculate_xs() macro_xs().absorption = 0.0; macro_xs().fission = 0.0; macro_xs().nu_fission = 0.0; - if (!settings::run_CE && simulation::mg_void_index > -1) { - data::mg.macro_xs_[simulation::mg_void_index].calculate_xs(*this); - } } } diff --git a/src/simulation.cpp b/src/simulation.cpp index f76589cdcdd..18e40a8bc73 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -307,7 +307,6 @@ double keff_std; double k_col_abs {0.0}; double k_col_tra {0.0}; double k_abs_tra {0.0}; -int32_t mg_void_index {-1}; double log_spacing; int n_lost_particles {0}; bool need_depletion_rx {false}; From 3d22ce7e4adb3234bef771c983ba8ef6baa24814 Mon Sep 17 00:00:00 2001 From: GuySten Date: Wed, 4 Feb 2026 02:12:04 +0200 Subject: [PATCH 05/18] fix typo and import --- include/openmc/mgxs_interface.h | 2 +- src/cell.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/openmc/mgxs_interface.h b/include/openmc/mgxs_interface.h index 71072056778..893ad1c1889 100644 --- a/include/openmc/mgxs_interface.h +++ b/include/openmc/mgxs_interface.h @@ -61,7 +61,7 @@ class MgxsInterface { vector energy_bin_avg_; vector rev_energy_bins_; vector> nuc_temps_; // all available temperatures - vecotr void_velocities_; // velocity of particles in void regions + vector void_velocities_; // velocity of particles in void regions }; namespace data { diff --git a/src/cell.cpp b/src/cell.cpp index 0664ccd9f2a..59aed8b82df 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -20,6 +20,7 @@ #include "openmc/hdf5_interface.h" #include "openmc/lattice.h" #include "openmc/material.h" +#include "openmc/mgxs_interface.h" #include "openmc/nuclide.h" #include "openmc/settings.h" #include "openmc/xml_interface.h" From a1b09c271bcfd4629e1bfe05a048513f4b239387 Mon Sep 17 00:00:00 2001 From: GuySten Date: Wed, 4 Feb 2026 02:14:18 +0200 Subject: [PATCH 06/18] fix typo --- src/cell.cpp | 2 +- src/mgxs_interface.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cell.cpp b/src/cell.cpp index 59aed8b82df..63629e3ee49 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -398,7 +398,7 @@ CSGCell::CSGCell(pugi::xml_node cell_node) for (std::string mat : mats) { if (mat.compare("void") == 0) { material_.push_back(MATERIAL_VOID); - if (!settings::run_CE && mg::void_velocities_.empty()) + if (!settings::run_CE && data::mg.void_velocities_.empty()) warning("Void inverse-velocity data is not available in the " "multi-group nuclear data library. " "Time related calculation results might be wrong!"); diff --git a/src/mgxs_interface.cpp b/src/mgxs_interface.cpp index d71beafe679..0a647929a88 100644 --- a/src/mgxs_interface.cpp +++ b/src/mgxs_interface.cpp @@ -95,7 +95,7 @@ void MgxsInterface::init() get_datasets(kT_group, dset_names); if (num_temps > 1) fatal_error("Multigroup void data must have only one dummy temperature"); - xsdata_grp = open_group(kT_group, dset_names[0]); + auto xsdata_grp = open_group(kT_group, dset_names[0]); auto inverse_velocity = xt::zeros({ num_energy_groups_, }); From 7ac31b32f41068b661e27b43f6bdda23ff722372 Mon Sep 17 00:00:00 2001 From: GuySten Date: Wed, 4 Feb 2026 02:25:29 +0200 Subject: [PATCH 07/18] fix typo --- src/mgxs_interface.cpp | 5 ++--- src/particle.cpp | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/mgxs_interface.cpp b/src/mgxs_interface.cpp index 0a647929a88..81a82312298 100644 --- a/src/mgxs_interface.cpp +++ b/src/mgxs_interface.cpp @@ -96,9 +96,8 @@ void MgxsInterface::init() if (num_temps > 1) fatal_error("Multigroup void data must have only one dummy temperature"); auto xsdata_grp = open_group(kT_group, dset_names[0]); - auto inverse_velocity = xt::zeros({ - num_energy_groups_, - }); + vector shape {1, num_energy_groups_}; + xt::xtensor inverse_velocity = xt::zeros(shape); read_nd_vector(xsdata_grp, "inverse-velocity", inverse_velocity); auto velocity = 1.0 / inverse_velocity; for (double v : velocity) { diff --git a/src/particle.cpp b/src/particle.cpp index f1146d5d0d7..531673af193 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -68,8 +68,8 @@ double Particle::speed() const } else { auto mat = this->material(); if (mat == MATERIAL_VOID) { - if (!mg::void_velocities_.empty()) { - return mg::void_velocities_[this->g()]; + if (!data::mg.void_velocities_.empty()) { + return data::mg.void_velocities_[this->g()]; } else { return 0.0; } From 6e358d18b352c8d59a434039d0234807b9c0e8ce Mon Sep 17 00:00:00 2001 From: GuySten Date: Wed, 4 Feb 2026 02:27:30 +0200 Subject: [PATCH 08/18] fix typo --- src/mgxs_interface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mgxs_interface.cpp b/src/mgxs_interface.cpp index 81a82312298..1dfb2980e88 100644 --- a/src/mgxs_interface.cpp +++ b/src/mgxs_interface.cpp @@ -95,7 +95,7 @@ void MgxsInterface::init() get_datasets(kT_group, dset_names); if (num_temps > 1) fatal_error("Multigroup void data must have only one dummy temperature"); - auto xsdata_grp = open_group(kT_group, dset_names[0]); + auto xsdata_grp = open_group(void_grp, dset_names[0]); vector shape {1, num_energy_groups_}; xt::xtensor inverse_velocity = xt::zeros(shape); read_nd_vector(xsdata_grp, "inverse-velocity", inverse_velocity); From ba43542149ac04b7932b98c218785839af92a0b5 Mon Sep 17 00:00:00 2001 From: GuySten Date: Wed, 4 Feb 2026 02:36:51 +0200 Subject: [PATCH 09/18] move around code --- src/mgxs_interface.cpp | 46 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/mgxs_interface.cpp b/src/mgxs_interface.cpp index 1dfb2980e88..77858c43af7 100644 --- a/src/mgxs_interface.cpp +++ b/src/mgxs_interface.cpp @@ -82,29 +82,6 @@ void MgxsInterface::init() "supported by OpenMC."); } - // Read void velocities - if (object_exists(file_id, "void")) { - auto void_grp = open_group(file_id, "void"); - // Determine the available temperatures - hid_t kT_group = open_group(void_grp, "kTs"); - size_t num_temps = get_num_datasets(kT_group); - char** dset_names = new char*[num_temps]; - for (int i = 0; i < num_temps; i++) { - dset_names[i] = new char[151]; - } - get_datasets(kT_group, dset_names); - if (num_temps > 1) - fatal_error("Multigroup void data must have only one dummy temperature"); - auto xsdata_grp = open_group(void_grp, dset_names[0]); - vector shape {1, num_energy_groups_}; - xt::xtensor inverse_velocity = xt::zeros(shape); - read_nd_vector(xsdata_grp, "inverse-velocity", inverse_velocity); - auto velocity = 1.0 / inverse_velocity; - for (double v : velocity) { - void_velocities_.push_back(v); - } - } - // ========================================================================== // READ ALL MGXS CROSS SECTION TABLES for (unsigned i_nuc = 0; i_nuc < xs_to_read_.size(); ++i_nuc) @@ -260,6 +237,29 @@ void MgxsInterface::read_header(const std::string& path_cross_sections) "library file!"); } + // Read void velocities + if (object_exists(file_id, "void")) { + auto void_grp = open_group(file_id, "void"); + // Determine the available temperatures + hid_t kT_group = open_group(void_grp, "kTs"); + size_t num_temps = get_num_datasets(kT_group); + char** dset_names = new char*[num_temps]; + for (int i = 0; i < num_temps; i++) { + dset_names[i] = new char[151]; + } + get_datasets(kT_group, dset_names); + if (num_temps > 1) + fatal_error("Multigroup void data must have only one dummy temperature"); + auto xsdata_grp = open_group(void_grp, dset_names[0]); + vector shape {1, num_energy_groups_}; + xt::xtensor inverse_velocity = xt::zeros(shape); + read_nd_vector(xsdata_grp, "inverse-velocity", inverse_velocity); + auto velocity = 1.0 / inverse_velocity; + for (double v : velocity) { + void_velocities_.push_back(v); + } + } + // Close MGXS HDF5 file file_close(file_id); } From 59c0b50a15c57da83352dd6ddb3cbf6ff7416984 Mon Sep 17 00:00:00 2001 From: GuySten Date: Wed, 4 Feb 2026 04:31:04 +0200 Subject: [PATCH 10/18] rename void to approx void in random ray example --- openmc/examples.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openmc/examples.py b/openmc/examples.py index 350a4d24d5e..b53d22c6a05 100644 --- a/openmc/examples.py +++ b/openmc/examples.py @@ -1061,7 +1061,7 @@ def fill_cube(N, n_1, n_2, fill_1, fill_2, fill_3): void_sigma_a = 4.0e-6 void_sigma_s = 3.0e-4 - void_mat_data = openmc.XSdata('void', groups) + void_mat_data = openmc.XSdata('approx void', groups) void_mat_data.order = 0 void_mat_data.set_total([void_sigma_a + void_sigma_s]) void_mat_data.set_absorption([void_sigma_a]) @@ -1097,7 +1097,7 @@ def fill_cube(N, n_1, n_2, fill_1, fill_2, fill_3): # Instantiate some Macroscopic Data source_data = openmc.Macroscopic('source') - void_data = openmc.Macroscopic('void') + void_data = openmc.Macroscopic('approx void') absorber_data = openmc.Macroscopic('absorber') # Instantiate some Materials and register the appropriate Macroscopic objects @@ -1105,7 +1105,7 @@ def fill_cube(N, n_1, n_2, fill_1, fill_2, fill_3): source_mat.set_density('macro', 1.0) source_mat.add_macroscopic(source_data) - void_mat = openmc.Material(name='void') + void_mat = openmc.Material(name='approx void') void_mat.set_density('macro', 1.0) void_mat.add_macroscopic(void_data) From 6568952a6c6382f2b3252069c1063a05fef0b4ca Mon Sep 17 00:00:00 2001 From: GuySten Date: Wed, 4 Feb 2026 07:32:21 +0200 Subject: [PATCH 11/18] update inputs --- .../random_ray_adjoint_fixed_source/inputs_true.dat | 4 ++-- .../random_ray_cell_density/fs/inputs_true.dat | 4 ++-- .../random_ray_fixed_source_domain/cell/inputs_true.dat | 4 ++-- .../random_ray_fixed_source_domain/material/inputs_true.dat | 4 ++-- .../random_ray_fixed_source_domain/universe/inputs_true.dat | 4 ++-- .../random_ray_fixed_source_linear/linear/inputs_true.dat | 4 ++-- .../random_ray_fixed_source_linear/linear_xy/inputs_true.dat | 4 ++-- .../random_ray_fixed_source_mesh/flat/inputs_true.dat | 4 ++-- .../random_ray_fixed_source_mesh/linear/inputs_true.dat | 4 ++-- .../False/inputs_true.dat | 4 ++-- .../True/inputs_true.dat | 4 ++-- tests/regression_tests/random_ray_low_density/inputs_true.dat | 4 ++-- tests/regression_tests/random_ray_low_density/test.py | 2 +- .../random_ray_point_source_locator/inputs_true.dat | 4 ++-- tests/regression_tests/random_ray_void/flat/inputs_true.dat | 4 ++-- tests/regression_tests/random_ray_void/linear/inputs_true.dat | 4 ++-- .../random_ray_volume_estimator/hybrid/inputs_true.dat | 4 ++-- .../random_ray_volume_estimator/naive/inputs_true.dat | 4 ++-- .../simulation_averaged/inputs_true.dat | 4 ++-- .../random_ray_volume_estimator_linear/hybrid/inputs_true.dat | 4 ++-- .../random_ray_volume_estimator_linear/naive/inputs_true.dat | 4 ++-- .../simulation_averaged/inputs_true.dat | 4 ++-- tests/regression_tests/weightwindows_fw_cadis/inputs_true.dat | 4 ++-- .../weightwindows_fw_cadis_mesh/flat/inputs_true.dat | 4 ++-- .../weightwindows_fw_cadis_mesh/linear/inputs_true.dat | 4 ++-- 25 files changed, 49 insertions(+), 49 deletions(-) diff --git a/tests/regression_tests/random_ray_adjoint_fixed_source/inputs_true.dat b/tests/regression_tests/random_ray_adjoint_fixed_source/inputs_true.dat index 0adfc548848..74937ce13e8 100644 --- a/tests/regression_tests/random_ray_adjoint_fixed_source/inputs_true.dat +++ b/tests/regression_tests/random_ray_adjoint_fixed_source/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_cell_density/fs/inputs_true.dat b/tests/regression_tests/random_ray_cell_density/fs/inputs_true.dat index e90f25973e2..f8ebc855b3a 100644 --- a/tests/regression_tests/random_ray_cell_density/fs/inputs_true.dat +++ b/tests/regression_tests/random_ray_cell_density/fs/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_fixed_source_domain/cell/inputs_true.dat b/tests/regression_tests/random_ray_fixed_source_domain/cell/inputs_true.dat index 9f1987f3acc..f58da8d57be 100644 --- a/tests/regression_tests/random_ray_fixed_source_domain/cell/inputs_true.dat +++ b/tests/regression_tests/random_ray_fixed_source_domain/cell/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_fixed_source_domain/material/inputs_true.dat b/tests/regression_tests/random_ray_fixed_source_domain/material/inputs_true.dat index b4f57dbfa8a..5c455d3608a 100644 --- a/tests/regression_tests/random_ray_fixed_source_domain/material/inputs_true.dat +++ b/tests/regression_tests/random_ray_fixed_source_domain/material/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_fixed_source_domain/universe/inputs_true.dat b/tests/regression_tests/random_ray_fixed_source_domain/universe/inputs_true.dat index ab91f74e50d..9a9b2aebb5b 100644 --- a/tests/regression_tests/random_ray_fixed_source_domain/universe/inputs_true.dat +++ b/tests/regression_tests/random_ray_fixed_source_domain/universe/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_fixed_source_linear/linear/inputs_true.dat b/tests/regression_tests/random_ray_fixed_source_linear/linear/inputs_true.dat index 220fa7db643..e22d48466a5 100644 --- a/tests/regression_tests/random_ray_fixed_source_linear/linear/inputs_true.dat +++ b/tests/regression_tests/random_ray_fixed_source_linear/linear/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_fixed_source_linear/linear_xy/inputs_true.dat b/tests/regression_tests/random_ray_fixed_source_linear/linear_xy/inputs_true.dat index f8c4430852f..dbf29b9ae54 100644 --- a/tests/regression_tests/random_ray_fixed_source_linear/linear_xy/inputs_true.dat +++ b/tests/regression_tests/random_ray_fixed_source_linear/linear_xy/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_fixed_source_mesh/flat/inputs_true.dat b/tests/regression_tests/random_ray_fixed_source_mesh/flat/inputs_true.dat index c84e544fcc4..219ccddb0d3 100644 --- a/tests/regression_tests/random_ray_fixed_source_mesh/flat/inputs_true.dat +++ b/tests/regression_tests/random_ray_fixed_source_mesh/flat/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_fixed_source_mesh/linear/inputs_true.dat b/tests/regression_tests/random_ray_fixed_source_mesh/linear/inputs_true.dat index 05c4846e6b4..f9593f4139e 100644 --- a/tests/regression_tests/random_ray_fixed_source_mesh/linear/inputs_true.dat +++ b/tests/regression_tests/random_ray_fixed_source_mesh/linear/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_fixed_source_normalization/False/inputs_true.dat b/tests/regression_tests/random_ray_fixed_source_normalization/False/inputs_true.dat index 0c870e10067..037c66b0488 100644 --- a/tests/regression_tests/random_ray_fixed_source_normalization/False/inputs_true.dat +++ b/tests/regression_tests/random_ray_fixed_source_normalization/False/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_fixed_source_normalization/True/inputs_true.dat b/tests/regression_tests/random_ray_fixed_source_normalization/True/inputs_true.dat index ab91f74e50d..9a9b2aebb5b 100644 --- a/tests/regression_tests/random_ray_fixed_source_normalization/True/inputs_true.dat +++ b/tests/regression_tests/random_ray_fixed_source_normalization/True/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_low_density/inputs_true.dat b/tests/regression_tests/random_ray_low_density/inputs_true.dat index ab91f74e50d..9a9b2aebb5b 100644 --- a/tests/regression_tests/random_ray_low_density/inputs_true.dat +++ b/tests/regression_tests/random_ray_low_density/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_low_density/test.py b/tests/regression_tests/random_ray_low_density/test.py index 1b4ffb78183..fa594e2cee0 100644 --- a/tests/regression_tests/random_ray_low_density/test.py +++ b/tests/regression_tests/random_ray_low_density/test.py @@ -25,7 +25,7 @@ def test_random_ray_low_density(): void_sigma_a = 4.0e-6 void_sigma_s = 3.0e-4 - void_mat_data = openmc.XSdata('void', groups) + void_mat_data = openmc.XSdata('approx void', groups) void_mat_data.order = 0 void_mat_data.set_total([void_sigma_a + void_sigma_s]) void_mat_data.set_absorption([void_sigma_a]) diff --git a/tests/regression_tests/random_ray_point_source_locator/inputs_true.dat b/tests/regression_tests/random_ray_point_source_locator/inputs_true.dat index 088f803bfa8..3ef0b0ff985 100644 --- a/tests/regression_tests/random_ray_point_source_locator/inputs_true.dat +++ b/tests/regression_tests/random_ray_point_source_locator/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_void/flat/inputs_true.dat b/tests/regression_tests/random_ray_void/flat/inputs_true.dat index aa28e7b68bf..22a5f22678b 100644 --- a/tests/regression_tests/random_ray_void/flat/inputs_true.dat +++ b/tests/regression_tests/random_ray_void/flat/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_void/linear/inputs_true.dat b/tests/regression_tests/random_ray_void/linear/inputs_true.dat index e4b2f22fa27..7a33bee6049 100644 --- a/tests/regression_tests/random_ray_void/linear/inputs_true.dat +++ b/tests/regression_tests/random_ray_void/linear/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_volume_estimator/hybrid/inputs_true.dat b/tests/regression_tests/random_ray_volume_estimator/hybrid/inputs_true.dat index 8e8a8ed9b81..255a2730ec5 100644 --- a/tests/regression_tests/random_ray_volume_estimator/hybrid/inputs_true.dat +++ b/tests/regression_tests/random_ray_volume_estimator/hybrid/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_volume_estimator/naive/inputs_true.dat b/tests/regression_tests/random_ray_volume_estimator/naive/inputs_true.dat index 1e25b97da66..0806732be55 100644 --- a/tests/regression_tests/random_ray_volume_estimator/naive/inputs_true.dat +++ b/tests/regression_tests/random_ray_volume_estimator/naive/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_volume_estimator/simulation_averaged/inputs_true.dat b/tests/regression_tests/random_ray_volume_estimator/simulation_averaged/inputs_true.dat index 78c16269763..f2c60ed8ab4 100644 --- a/tests/regression_tests/random_ray_volume_estimator/simulation_averaged/inputs_true.dat +++ b/tests/regression_tests/random_ray_volume_estimator/simulation_averaged/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_volume_estimator_linear/hybrid/inputs_true.dat b/tests/regression_tests/random_ray_volume_estimator_linear/hybrid/inputs_true.dat index 47a8a718249..9a9a3c6c695 100644 --- a/tests/regression_tests/random_ray_volume_estimator_linear/hybrid/inputs_true.dat +++ b/tests/regression_tests/random_ray_volume_estimator_linear/hybrid/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_volume_estimator_linear/naive/inputs_true.dat b/tests/regression_tests/random_ray_volume_estimator_linear/naive/inputs_true.dat index 80a9ada4d5b..dd250bfc483 100644 --- a/tests/regression_tests/random_ray_volume_estimator_linear/naive/inputs_true.dat +++ b/tests/regression_tests/random_ray_volume_estimator_linear/naive/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/random_ray_volume_estimator_linear/simulation_averaged/inputs_true.dat b/tests/regression_tests/random_ray_volume_estimator_linear/simulation_averaged/inputs_true.dat index 4f032a62a82..0b383945c75 100644 --- a/tests/regression_tests/random_ray_volume_estimator_linear/simulation_averaged/inputs_true.dat +++ b/tests/regression_tests/random_ray_volume_estimator_linear/simulation_averaged/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/weightwindows_fw_cadis/inputs_true.dat b/tests/regression_tests/weightwindows_fw_cadis/inputs_true.dat index 5fa6505ddf4..b0864454101 100644 --- a/tests/regression_tests/weightwindows_fw_cadis/inputs_true.dat +++ b/tests/regression_tests/weightwindows_fw_cadis/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/weightwindows_fw_cadis_mesh/flat/inputs_true.dat b/tests/regression_tests/weightwindows_fw_cadis_mesh/flat/inputs_true.dat index ceb89e6e34c..e093825cf22 100644 --- a/tests/regression_tests/weightwindows_fw_cadis_mesh/flat/inputs_true.dat +++ b/tests/regression_tests/weightwindows_fw_cadis_mesh/flat/inputs_true.dat @@ -6,9 +6,9 @@ - + - + diff --git a/tests/regression_tests/weightwindows_fw_cadis_mesh/linear/inputs_true.dat b/tests/regression_tests/weightwindows_fw_cadis_mesh/linear/inputs_true.dat index c7691e950c4..9a058a2362f 100644 --- a/tests/regression_tests/weightwindows_fw_cadis_mesh/linear/inputs_true.dat +++ b/tests/regression_tests/weightwindows_fw_cadis_mesh/linear/inputs_true.dat @@ -6,9 +6,9 @@ - + - + From fb469c6f1c72128a77721911428faeada4e368c5 Mon Sep 17 00:00:00 2001 From: GuySten Date: Wed, 4 Feb 2026 12:13:26 +0200 Subject: [PATCH 12/18] more fixes --- openmc/mgxs_library.py | 1 + src/mgxs_interface.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/openmc/mgxs_library.py b/openmc/mgxs_library.py index a02e05ec3f7..01a8a2b6b5c 100644 --- a/openmc/mgxs_library.py +++ b/openmc/mgxs_library.py @@ -214,6 +214,7 @@ def __deepcopy__(self, memo): # If this is the first time we have tried to copy this object, copy it if existing is None: clone = type(self).__new__(type(self)) + clone._is_void = self._is_void clone._name = self.name clone._energy_groups = copy.deepcopy(self.energy_groups, memo) clone._num_delayed_groups = self.num_delayed_groups diff --git a/src/mgxs_interface.cpp b/src/mgxs_interface.cpp index 77858c43af7..70928d6b743 100644 --- a/src/mgxs_interface.cpp +++ b/src/mgxs_interface.cpp @@ -251,7 +251,7 @@ void MgxsInterface::read_header(const std::string& path_cross_sections) if (num_temps > 1) fatal_error("Multigroup void data must have only one dummy temperature"); auto xsdata_grp = open_group(void_grp, dset_names[0]); - vector shape {1, num_energy_groups_}; + vector shape {1, static_cast(num_energy_groups_)}; xt::xtensor inverse_velocity = xt::zeros(shape); read_nd_vector(xsdata_grp, "inverse-velocity", inverse_velocity); auto velocity = 1.0 / inverse_velocity; From 5672eacdb61bf7d5601f0a6194e4eeb42b71b8d7 Mon Sep 17 00:00:00 2001 From: GuySten Date: Sat, 7 Feb 2026 18:00:37 +0200 Subject: [PATCH 13/18] use default velocity approx when imberse velocity data is missing --- src/mgxs_interface.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/mgxs_interface.cpp b/src/mgxs_interface.cpp index 70928d6b743..51a021ce555 100644 --- a/src/mgxs_interface.cpp +++ b/src/mgxs_interface.cpp @@ -258,6 +258,17 @@ void MgxsInterface::read_header(const std::string& path_cross_sections) for (double v : velocity) { void_velocities_.push_back(v); } + } else { + for (int i = 0; i < energy_bins_.size() - 1; ++i) { + double e_min = energy_bins_[i]; + double e_max = energy_bins_[i + 1]; + double v = C_LIGHT * std::log(e_max / e_min) / + (std::acosh(1 + e_max / MASS_NEUTRON_EV) - + std::sqrt(1 + 2 * MASS_NEUTRON_EV / e_max) - + std::acosh(1 + e_min / MASS_NEUTRON_EV) + + std::sqrt(1 + 2 * MASS_NEUTRON_EV / e_min)); + void_velocities_.push_back(v); + } } // Close MGXS HDF5 file From 9ef5648ad318f254587fbd6d1a269ccf8ac30efa Mon Sep 17 00:00:00 2001 From: GuySten Date: Sat, 7 Feb 2026 18:36:51 +0200 Subject: [PATCH 14/18] wip --- src/mgxs.cpp | 9 +++++---- src/mgxs_interface.cpp | 2 +- src/xsdata.cpp | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/mgxs.cpp b/src/mgxs.cpp index a2c479f2156..a7e38508e6e 100644 --- a/src/mgxs.cpp +++ b/src/mgxs.cpp @@ -271,9 +271,9 @@ void Mgxs::metadata_from_hdf5(hid_t xs_id, const vector& temperature, //============================================================================== -Mgxs::Mgxs( - hid_t xs_id, const vector& temperature, int num_group, int num_delay) - : num_groups(num_group), num_delayed_groups(num_delay) +Mgxs::Mgxs(hid_t xs_id, const vector& temperature, + const vector& energy_bins, int num_delay) + : num_groups(energy_bins.size()), num_delayed_groups(num_delay) { // Call generic data gathering routine (will populate the metadata) int order_data; @@ -296,7 +296,8 @@ Mgxs::Mgxs( hid_t xsdata_grp = open_group(xs_id, temp_str.c_str()); xs[t].from_hdf5(xsdata_grp, fissionable, scatter_format, - final_scatter_format, order_data, is_isotropic, n_pol, n_azi); + final_scatter_format, order_data, is_isotropic, n_pol, n_azi, + energy_bins); close_group(xsdata_grp); } // end temperature loop diff --git a/src/mgxs_interface.cpp b/src/mgxs_interface.cpp index 51a021ce555..23a326f6bd8 100644 --- a/src/mgxs_interface.cpp +++ b/src/mgxs_interface.cpp @@ -109,7 +109,7 @@ void MgxsInterface::add_mgxs( } nuclides_.emplace_back( - xs_grp, temperature, num_energy_groups_, num_delayed_groups_); + xs_grp, temperature, energy_groups_, num_delayed_groups_); close_group(xs_grp); } diff --git a/src/xsdata.cpp b/src/xsdata.cpp index 23b9960f5bc..250f5064bb0 100644 --- a/src/xsdata.cpp +++ b/src/xsdata.cpp @@ -81,7 +81,7 @@ XsData::XsData(bool fissionable, AngleDistributionType scatter_format, void XsData::from_hdf5(hid_t xsdata_grp, bool fissionable, AngleDistributionType scatter_format, AngleDistributionType final_scatter_format, int order_data, bool is_isotropic, - int n_pol, int n_azi) + int n_pol, int n_azi, const vector& energy_bins) { // Reconstruct the dimension information so it doesn't need to be passed size_t n_ang = n_pol * n_azi; From 05abd9c9f6a48f142c1a038e45569beb245b997f Mon Sep 17 00:00:00 2001 From: GuySten Date: Sat, 7 Feb 2026 18:57:18 +0200 Subject: [PATCH 15/18] wip --- include/openmc/mgxs.h | 6 +++--- src/mgxs_interface.cpp | 2 +- src/xsdata.cpp | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/include/openmc/mgxs.h b/include/openmc/mgxs.h index 9b1602f299a..0a031fd24c9 100644 --- a/include/openmc/mgxs.h +++ b/include/openmc/mgxs.h @@ -95,10 +95,10 @@ class Mgxs { //! //! @param xs_id HDF5 group id for the cross section data. //! @param temperature Temperatures to read. - //! @param num_group number of energy groups + //! @param energy_bins energy bins //! @param num_delay number of delayed groups - Mgxs(hid_t xs_id, const vector& temperature, int num_group, - int num_delay); + Mgxs(hid_t xs_id, const vector& temperature, + const vector& energy_bins, int num_delay); //! \brief Constructor that initializes and populates all data to build a //! macroscopic cross section from microscopic cross sections. diff --git a/src/mgxs_interface.cpp b/src/mgxs_interface.cpp index 23a326f6bd8..1da998dc172 100644 --- a/src/mgxs_interface.cpp +++ b/src/mgxs_interface.cpp @@ -109,7 +109,7 @@ void MgxsInterface::add_mgxs( } nuclides_.emplace_back( - xs_grp, temperature, energy_groups_, num_delayed_groups_); + xs_grp, temperature, energy_bins_, num_delayed_groups_); close_group(xs_grp); } diff --git a/src/xsdata.cpp b/src/xsdata.cpp index 250f5064bb0..538bb94f068 100644 --- a/src/xsdata.cpp +++ b/src/xsdata.cpp @@ -97,8 +97,18 @@ void XsData::from_hdf5(hid_t xsdata_grp, bool fissionable, read_nd_vector(xsdata_grp, "inverse-velocity", inverse_velocity); if (!object_exists(xsdata_grp, "inverse-velocity")) { - warning("Inverse-velocity is not available in XsData " - "Time related calculation results might be wrong!"); + vector inv_vel; + for (int i = 0; i < energy_bins_.size() - 1; ++i) { + double e_min = energy_bins_[i]; + double e_max = energy_bins_[i + 1]; + double inv_v = (std::acosh(1 + e_max / MASS_NEUTRON_EV) - + std::sqrt(1 + 2 * MASS_NEUTRON_EV / e_max) - + std::acosh(1 + e_min / MASS_NEUTRON_EV) + + std::sqrt(1 + 2 * MASS_NEUTRON_EV / e_min)) / + std::log(e_max / e_min) / C_LIGHT; + inv_vel.push_back(inv_v); + } + inverse_velocity = xt::adapt(inv_vel); } // Get scattering data From 957d098965765234d1d68d03faf5f221eb9fce63 Mon Sep 17 00:00:00 2001 From: GuySten Date: Sat, 7 Feb 2026 19:15:12 +0200 Subject: [PATCH 16/18] wip --- include/openmc/xsdata.h | 3 ++- src/xsdata.cpp | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/openmc/xsdata.h b/include/openmc/xsdata.h index feafde68dd3..ba760bffa75 100644 --- a/include/openmc/xsdata.h +++ b/include/openmc/xsdata.h @@ -120,10 +120,11 @@ class XsData { //! the incoming particle. //! @param n_pol Number of polar angles. //! @param n_azi Number of azimuthal angles. + //! @param energy_bins energy bins of XsData void from_hdf5(hid_t xsdata_grp, bool fissionable, AngleDistributionType scatter_format, AngleDistributionType final_scatter_format, int order_data, - bool is_isotropic, int n_pol, int n_azi); + bool is_isotropic, int n_pol, int n_azi, const vector& energy_bins); //! \brief Combines the microscopic data to a macroscopic object. //! diff --git a/src/xsdata.cpp b/src/xsdata.cpp index 538bb94f068..4bfe858c386 100644 --- a/src/xsdata.cpp +++ b/src/xsdata.cpp @@ -98,9 +98,9 @@ void XsData::from_hdf5(hid_t xsdata_grp, bool fissionable, if (!object_exists(xsdata_grp, "inverse-velocity")) { vector inv_vel; - for (int i = 0; i < energy_bins_.size() - 1; ++i) { - double e_min = energy_bins_[i]; - double e_max = energy_bins_[i + 1]; + for (int i = 0; i < energy_bins.size() - 1; ++i) { + double e_min = energy_bins[i]; + double e_max = energy_bins[i + 1]; double inv_v = (std::acosh(1 + e_max / MASS_NEUTRON_EV) - std::sqrt(1 + 2 * MASS_NEUTRON_EV / e_max) - std::acosh(1 + e_min / MASS_NEUTRON_EV) + From 59b4c008ec2cf66d940f22cc134e668dadb9058a Mon Sep 17 00:00:00 2001 From: GuySten Date: Sat, 7 Feb 2026 19:17:47 +0200 Subject: [PATCH 17/18] revert warning --- src/cell.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/cell.cpp b/src/cell.cpp index 63629e3ee49..ebe28c3d2ce 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -20,7 +20,6 @@ #include "openmc/hdf5_interface.h" #include "openmc/lattice.h" #include "openmc/material.h" -#include "openmc/mgxs_interface.h" #include "openmc/nuclide.h" #include "openmc/settings.h" #include "openmc/xml_interface.h" @@ -398,10 +397,6 @@ CSGCell::CSGCell(pugi::xml_node cell_node) for (std::string mat : mats) { if (mat.compare("void") == 0) { material_.push_back(MATERIAL_VOID); - if (!settings::run_CE && data::mg.void_velocities_.empty()) - warning("Void inverse-velocity data is not available in the " - "multi-group nuclear data library. " - "Time related calculation results might be wrong!"); } else { material_.push_back(std::stoi(mat)); } From a78f7d618b5ea041125e9588cd7904b241304328 Mon Sep 17 00:00:00 2001 From: GuySten Date: Mon, 9 Feb 2026 00:36:12 +0200 Subject: [PATCH 18/18] simplify code --- src/particle.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/particle.cpp b/src/particle.cpp index 05f8d173971..372e9e02a72 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -67,18 +67,13 @@ double Particle::speed() const (this->E() + mass); } else { auto mat = this->material(); - if (mat == MATERIAL_VOID) { - if (!data::mg.void_velocities_.empty()) { - return data::mg.void_velocities_[this->g()]; - } else { - return 0.0; - } - } + if (mat == MATERIAL_VOID) + return data::mg.void_velocities_[this->g()]; auto& macro_xs = data::mg.macro_xs_[mat]; int macro_t = this->mg_xs_cache().t; int macro_a = macro_xs.get_angle_index(this->u()); - return 1.0 / macro_xs.get_xs(MgxsType::INVERSE_VELOCITY, this->g(), nullptr, - nullptr, nullptr, macro_t, macro_a); + return 1.0 / macro_xs.get_xs( + MgxsType::INVERSE_VELOCITY, this->g(), macro_t, macro_a); } }