From 487f02dd1dddfa09e51a3a2b78b70947aafec1be Mon Sep 17 00:00:00 2001 From: guyshtot Date: Tue, 21 Mar 2023 13:18:24 +0200 Subject: [PATCH 1/8] Add option to specify nuclides in the Library class --- openmc/mgxs/library.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/openmc/mgxs/library.py b/openmc/mgxs/library.py index efe8dbe84..063134f7a 100644 --- a/openmc/mgxs/library.py +++ b/openmc/mgxs/library.py @@ -72,6 +72,11 @@ class Library: Number of equi-width polar angle bins for angle discretization num_azimuthal : Integral Number of equi-width azimuthal angle bins for angle discretization + nuclides : Iterable of str or 'sum' + The optional user-specified nuclides for which to compute cross + sections (e.g., 'U238', 'O16'). If by_nuclide is True but nuclides + are not specified by the user, all nuclides in the domain + are included. estimator : str or None The tally estimator used to compute multi-group cross sections. If None, the default for each MGXS type is used. @@ -107,6 +112,7 @@ class Library: self._energy_groups = None self._num_polar = 1 self._num_azimuthal = 1 + self._nuclides = None self._num_delayed_groups = 0 self._correction = 'P0' self._scatter_format = 'legendre' @@ -145,6 +151,7 @@ class Library: clone._energy_groups = copy.deepcopy(self.energy_groups, memo) clone._num_polar = self.num_polar clone._num_azimuthal = self.num_azimuthal + clone._nuclides = self._nuclides clone._num_delayed_groups = self.num_delayed_groups clone._tally_trigger = copy.deepcopy(self.tally_trigger, memo) clone._all_mgxs = copy.deepcopy(self.all_mgxs) @@ -206,6 +213,14 @@ class Library: return self._domains @property + def nuclides(self): + if self.by_nuclide and self._nuclides: + return self._nuclides + elif self.by_nuclide: + raise ValueError("Nuclides weren't defined") + else: + return 'sum' + @property def energy_groups(self): return self._energy_groups @@ -275,6 +290,11 @@ class Library: cv.check_type('name', name, str) self._name = name + @nuclides.setter + def nuclides(self, nuclides): + cv.check_type('nuclides', nuclides, str) + self._nuclides = nuclides + @mgxs_types.setter def mgxs_types(self, mgxs_types): all_mgxs_types = openmc.mgxs.MGXS_TYPES + openmc.mgxs.MDGXS_TYPES + \ @@ -524,6 +544,18 @@ class Library: mgxs.legendre_order = self.legendre_order mgxs.histogram_bins = self.histogram_bins + if self.by_nuclide: + try: + domain_nuclides = domain.get_nuclides() + except AttributeError: + domain_nuclides = None + if self._nuclides: + if domain_nuclides: + mgxs.nuclides = [nuclide for nuclide in self.nuclides if nuclide in domain_nuclides] + [ + "total"] + else: + mgxs.nuclides = self._nuclides + self.all_mgxs[domain.id][mgxs_type] = mgxs def add_to_tallies_file(self, tallies_file, merge=True): From 354fd34c2c5dd1fa6d47dcff623089d87128e5ca Mon Sep 17 00:00:00 2001 From: guyshtot Date: Tue, 21 Mar 2023 14:59:01 +0200 Subject: [PATCH 2/8] Renamed previous use of _nuclides to _atomic_weight_ratios in the library class --- openmc/mgxs/library.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/openmc/mgxs/library.py b/openmc/mgxs/library.py index 063134f7a..0eb00c8f1 100644 --- a/openmc/mgxs/library.py +++ b/openmc/mgxs/library.py @@ -214,12 +214,8 @@ class Library: @property def nuclides(self): - if self.by_nuclide and self._nuclides: - return self._nuclides - elif self.by_nuclide: - raise ValueError("Nuclides weren't defined") - else: - return 'sum' + return self._nuclides + @property def energy_groups(self): return self._energy_groups @@ -292,7 +288,7 @@ class Library: @nuclides.setter def nuclides(self, nuclides): - cv.check_type('nuclides', nuclides, str) + cv.check_iterable_type('nuclides', nuclides, str) self._nuclides = nuclides @mgxs_types.setter @@ -549,12 +545,12 @@ class Library: domain_nuclides = domain.get_nuclides() except AttributeError: domain_nuclides = None - if self._nuclides: + if self.nuclides: if domain_nuclides: mgxs.nuclides = [nuclide for nuclide in self.nuclides if nuclide in domain_nuclides] + [ "total"] else: - mgxs.nuclides = self._nuclides + mgxs.nuclides = self.nuclides self.all_mgxs[domain.id][mgxs_type] = mgxs @@ -622,7 +618,7 @@ class Library: self._sp_filename = statepoint._f.filename self._geometry = statepoint.summary.geometry - self._nuclides = statepoint.summary.nuclides + self._atomic_weight_ratios = statepoint.summary.nuclides if statepoint.run_mode == 'eigenvalue': self._keff = statepoint.keff.n @@ -1037,7 +1033,7 @@ class Library: xsdata.num_azimuthal = self.num_azimuthal if nuclide != 'total': - xsdata.atomic_weight_ratio = self._nuclides[nuclide] + xsdata.atomic_weight_ratio = self._atomic_weight_ratios[nuclide] if subdomain is None: subdomain = 'all' From 675ec5f9abc72d9e0c885139cc7a06539e33a459 Mon Sep 17 00:00:00 2001 From: guyshtot Date: Thu, 23 Mar 2023 13:07:21 +0200 Subject: [PATCH 3/8] Added test for the use of a Library with specified nuclides --- .../__init__.py | 0 .../inputs_true.dat | 1769 +++++++++++++++++ .../results_true.dat | 1 + .../mgxs_library_specific_nuclides/test.py | 71 + 4 files changed, 1841 insertions(+) create mode 100644 tests/regression_tests/mgxs_library_specific_nuclides/__init__.py create mode 100644 tests/regression_tests/mgxs_library_specific_nuclides/inputs_true.dat create mode 100644 tests/regression_tests/mgxs_library_specific_nuclides/results_true.dat create mode 100644 tests/regression_tests/mgxs_library_specific_nuclides/test.py diff --git a/tests/regression_tests/mgxs_library_specific_nuclides/__init__.py b/tests/regression_tests/mgxs_library_specific_nuclides/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/regression_tests/mgxs_library_specific_nuclides/inputs_true.dat b/tests/regression_tests/mgxs_library_specific_nuclides/inputs_true.dat new file mode 100644 index 000000000..205eb059c --- /dev/null +++ b/tests/regression_tests/mgxs_library_specific_nuclides/inputs_true.dat @@ -0,0 +1,1769 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + eigenvalue + 100 + 10 + 5 + + + -0.63 -0.63 -1 0.63 0.63 1 + + + + + + + 1 + + + 0.0 0.625 20000000.0 + + + 0.0 0.625 20000000.0 + + + 1 + + + 3 + + + 0.0 20000000.0 + + + 2 + + + 3 + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + total + tracklength + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + total + tracklength + + + 1 2 + total + flux + analog + + + 1 5 6 + U235 total + scatter + analog + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + total + tracklength + + + 1 2 + total + flux + analog + + + 1 5 6 + U235 total + nu-scatter + analog + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + absorption + tracklength + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + absorption + tracklength + + + 1 2 + U235 total + (n,2n) + tracklength + + + 1 2 + U235 total + (n,3n) + tracklength + + + 1 2 + U235 total + (n,4n) + tracklength + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + absorption + tracklength + + + 1 2 + U235 total + fission + tracklength + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + fission + tracklength + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + nu-fission + tracklength + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + kappa-fission + tracklength + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + scatter + tracklength + + + 1 2 + total + flux + analog + + + 1 2 + U235 total + nu-scatter + analog + + + 1 2 + total + flux + analog + + + 1 2 5 30 + U235 total + scatter + analog + + + 1 2 + total + flux + analog + + + 1 2 5 30 + U235 total + nu-scatter + analog + + + 1 2 5 + U235 total + nu-scatter + analog + + + 1 2 5 + U235 total + scatter + analog + + + 1 2 + total + flux + analog + + + 1 2 5 + U235 total + nu-fission + analog + + + 1 2 5 + U235 total + scatter + analog + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + scatter + tracklength + + + 1 2 5 30 + U235 total + scatter + analog + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + scatter + tracklength + + + 1 2 5 30 + U235 total + scatter + analog + + + 1 2 5 + U235 total + nu-scatter + analog + + + 1 54 + U235 total + nu-fission + analog + + + 1 5 + U235 total + nu-fission + analog + + + 1 54 + U235 total + prompt-nu-fission + analog + + + 1 5 + U235 total + prompt-nu-fission + analog + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + inverse-velocity + tracklength + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + prompt-nu-fission + tracklength + + + 1 2 + total + flux + analog + + + 1 2 5 + U235 total + prompt-nu-fission + analog + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + total + tracklength + + + 1 2 + total + flux + analog + + + 1 5 6 + U235 total + scatter + analog + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + total + tracklength + + + 1 2 + total + flux + analog + + + 1 5 6 + U235 total + nu-scatter + analog + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + (n,elastic) + tracklength + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + (n,level) + tracklength + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + (n,2n) + tracklength + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + (n,na) + tracklength + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + (n,nc) + tracklength + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + (n,gamma) + tracklength + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + (n,a) + tracklength + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + (n,Xa) + tracklength + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + heating + tracklength + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + damage-energy + tracklength + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + (n,n1) + tracklength + + + 1 2 + total + flux + tracklength + + + 1 2 + U235 total + (n,a0) + tracklength + + + 1 2 + total + flux + analog + + + 1 2 5 + U235 total + (n,nc) + analog + + + 1 2 + total + flux + analog + + + 1 2 5 + U235 total + (n,n1) + analog + + + 1 2 + total + flux + analog + + + 1 2 5 + U235 total + (n,2n) + analog + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + total + tracklength + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + total + tracklength + + + 106 2 + total + flux + analog + + + 106 5 6 + Zr90 total + scatter + analog + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + total + tracklength + + + 106 2 + total + flux + analog + + + 106 5 6 + Zr90 total + nu-scatter + analog + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + absorption + tracklength + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + absorption + tracklength + + + 106 2 + Zr90 total + (n,2n) + tracklength + + + 106 2 + Zr90 total + (n,3n) + tracklength + + + 106 2 + Zr90 total + (n,4n) + tracklength + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + absorption + tracklength + + + 106 2 + Zr90 total + fission + tracklength + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + fission + tracklength + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + nu-fission + tracklength + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + kappa-fission + tracklength + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + scatter + tracklength + + + 106 2 + total + flux + analog + + + 106 2 + Zr90 total + nu-scatter + analog + + + 106 2 + total + flux + analog + + + 106 2 5 30 + Zr90 total + scatter + analog + + + 106 2 + total + flux + analog + + + 106 2 5 30 + Zr90 total + nu-scatter + analog + + + 106 2 5 + Zr90 total + nu-scatter + analog + + + 106 2 5 + Zr90 total + scatter + analog + + + 106 2 + total + flux + analog + + + 106 2 5 + Zr90 total + nu-fission + analog + + + 106 2 5 + Zr90 total + scatter + analog + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + scatter + tracklength + + + 106 2 5 30 + Zr90 total + scatter + analog + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + scatter + tracklength + + + 106 2 5 30 + Zr90 total + scatter + analog + + + 106 2 5 + Zr90 total + nu-scatter + analog + + + 106 54 + Zr90 total + nu-fission + analog + + + 106 5 + Zr90 total + nu-fission + analog + + + 106 54 + Zr90 total + prompt-nu-fission + analog + + + 106 5 + Zr90 total + prompt-nu-fission + analog + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + inverse-velocity + tracklength + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + prompt-nu-fission + tracklength + + + 106 2 + total + flux + analog + + + 106 2 5 + Zr90 total + prompt-nu-fission + analog + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + total + tracklength + + + 106 2 + total + flux + analog + + + 106 5 6 + Zr90 total + scatter + analog + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + total + tracklength + + + 106 2 + total + flux + analog + + + 106 5 6 + Zr90 total + nu-scatter + analog + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + (n,elastic) + tracklength + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + (n,level) + tracklength + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + (n,2n) + tracklength + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + (n,na) + tracklength + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + (n,nc) + tracklength + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + (n,gamma) + tracklength + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + (n,a) + tracklength + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + (n,Xa) + tracklength + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + heating + tracklength + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + damage-energy + tracklength + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + (n,n1) + tracklength + + + 106 2 + total + flux + tracklength + + + 106 2 + Zr90 total + (n,a0) + tracklength + + + 106 2 + total + flux + analog + + + 106 2 5 + Zr90 total + (n,nc) + analog + + + 106 2 + total + flux + analog + + + 106 2 5 + Zr90 total + (n,n1) + analog + + + 106 2 + total + flux + analog + + + 106 2 5 + Zr90 total + (n,2n) + analog + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + total + tracklength + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + total + tracklength + + + 211 2 + total + flux + analog + + + 211 5 6 + H1 total + scatter + analog + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + total + tracklength + + + 211 2 + total + flux + analog + + + 211 5 6 + H1 total + nu-scatter + analog + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + absorption + tracklength + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + absorption + tracklength + + + 211 2 + H1 total + (n,2n) + tracklength + + + 211 2 + H1 total + (n,3n) + tracklength + + + 211 2 + H1 total + (n,4n) + tracklength + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + absorption + tracklength + + + 211 2 + H1 total + fission + tracklength + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + fission + tracklength + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + nu-fission + tracklength + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + kappa-fission + tracklength + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + scatter + tracklength + + + 211 2 + total + flux + analog + + + 211 2 + H1 total + nu-scatter + analog + + + 211 2 + total + flux + analog + + + 211 2 5 30 + H1 total + scatter + analog + + + 211 2 + total + flux + analog + + + 211 2 5 30 + H1 total + nu-scatter + analog + + + 211 2 5 + H1 total + nu-scatter + analog + + + 211 2 5 + H1 total + scatter + analog + + + 211 2 + total + flux + analog + + + 211 2 5 + H1 total + nu-fission + analog + + + 211 2 5 + H1 total + scatter + analog + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + scatter + tracklength + + + 211 2 5 30 + H1 total + scatter + analog + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + scatter + tracklength + + + 211 2 5 30 + H1 total + scatter + analog + + + 211 2 5 + H1 total + nu-scatter + analog + + + 211 54 + H1 total + nu-fission + analog + + + 211 5 + H1 total + nu-fission + analog + + + 211 54 + H1 total + prompt-nu-fission + analog + + + 211 5 + H1 total + prompt-nu-fission + analog + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + inverse-velocity + tracklength + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + prompt-nu-fission + tracklength + + + 211 2 + total + flux + analog + + + 211 2 5 + H1 total + prompt-nu-fission + analog + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + total + tracklength + + + 211 2 + total + flux + analog + + + 211 5 6 + H1 total + scatter + analog + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + total + tracklength + + + 211 2 + total + flux + analog + + + 211 5 6 + H1 total + nu-scatter + analog + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + (n,elastic) + tracklength + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + (n,level) + tracklength + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + (n,2n) + tracklength + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + (n,na) + tracklength + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + (n,nc) + tracklength + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + (n,gamma) + tracklength + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + (n,a) + tracklength + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + (n,Xa) + tracklength + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + heating + tracklength + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + damage-energy + tracklength + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + (n,n1) + tracklength + + + 211 2 + total + flux + tracklength + + + 211 2 + H1 total + (n,a0) + tracklength + + + 211 2 + total + flux + analog + + + 211 2 5 + H1 total + (n,nc) + analog + + + 211 2 + total + flux + analog + + + 211 2 5 + H1 total + (n,n1) + analog + + + 211 2 + total + flux + analog + + + 211 2 5 + H1 total + (n,2n) + analog + + diff --git a/tests/regression_tests/mgxs_library_specific_nuclides/results_true.dat b/tests/regression_tests/mgxs_library_specific_nuclides/results_true.dat new file mode 100644 index 000000000..05ee40902 --- /dev/null +++ b/tests/regression_tests/mgxs_library_specific_nuclides/results_true.dat @@ -0,0 +1 @@ +3e86542d1166b8a0bcc61742b88c9e931d63733477f3274b32b4da64d8f05413fa6330d5615f44f24735c2c2f77d3071f3dce38faba284c321ceab81c1064480 \ No newline at end of file diff --git a/tests/regression_tests/mgxs_library_specific_nuclides/test.py b/tests/regression_tests/mgxs_library_specific_nuclides/test.py new file mode 100644 index 000000000..41ae0a689 --- /dev/null +++ b/tests/regression_tests/mgxs_library_specific_nuclides/test.py @@ -0,0 +1,71 @@ +import hashlib + +import openmc +import openmc.mgxs +from openmc.examples import pwr_pin_cell + +from tests.testing_harness import PyAPITestHarness + + +class MGXSTestHarness(PyAPITestHarness): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + # Initialize a two-group structure + energy_groups = openmc.mgxs.EnergyGroups(group_edges=[0, 0.625, 20.e6]) + + # Initialize MGXS Library for a few cross section types + self.mgxs_lib = openmc.mgxs.Library(self._model.geometry) + self.mgxs_lib.by_nuclide = True + + # Test relevant MGXS types + relevant_MGXS_TYPES = [item for item in openmc.mgxs.MGXS_TYPES + if item != 'current'] + # Add in a subset of openmc.mgxs.ARBITRARY_VECTOR_TYPES and + # openmc.mgxs.ARBITRARY_MATRIX_TYPES so we can see the code works, + # but not use too much resources + relevant_MGXS_TYPES += [ + "(n,elastic)", "(n,level)", "(n,2n)", "(n,na)", "(n,nc)", + "(n,gamma)", "(n,a)", "(n,Xa)", "heating", "damage-energy", + "(n,n1)", "(n,a0)", "(n,nc) matrix", "(n,n1) matrix", + "(n,2n) matrix"] + self.mgxs_lib.mgxs_types = tuple(relevant_MGXS_TYPES) + self.mgxs_lib.energy_groups = energy_groups + self.mgxs_lib.legendre_order = 3 + self.mgxs_lib.domain_type = 'material' + self.mgxs_lib.nuclides=['U235','Zr90','H1'] + self.mgxs_lib.build_library() + + # Add tallies + self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=False) + + def _get_results(self, hash_output=True): + """Digest info in the statepoint and return as a string.""" + + # Read the statepoint file. + sp = openmc.StatePoint(self._sp_name) + + # Load the MGXS library from the statepoint + self.mgxs_lib.load_from_statepoint(sp) + + # Build a string from Pandas Dataframe for each MGXS + outstr = '' + for domain in self.mgxs_lib.domains: + for mgxs_type in self.mgxs_lib.mgxs_types: + mgxs = self.mgxs_lib.get_mgxs(domain, mgxs_type) + df = mgxs.get_pandas_dataframe() + outstr += df.to_string() + '\n' + + # Hash the results if necessary + if hash_output: + sha512 = hashlib.sha512() + sha512.update(outstr.encode('utf-8')) + outstr = sha512.hexdigest() + + return outstr + + +def test_mgxs_library_specific_nuclides(): + model = pwr_pin_cell() + harness = MGXSTestHarness('statepoint.10.h5', model) + harness.main() From a704ec73f26a7e89de06c2e2303ee170f0adf5cf Mon Sep 17 00:00:00 2001 From: guyshtot Date: Thu, 23 Mar 2023 13:12:36 +0200 Subject: [PATCH 4/8] Applied CR suggestion --- openmc/mgxs/library.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openmc/mgxs/library.py b/openmc/mgxs/library.py index 0eb00c8f1..1c3a5dbb4 100644 --- a/openmc/mgxs/library.py +++ b/openmc/mgxs/library.py @@ -547,8 +547,10 @@ class Library: domain_nuclides = None if self.nuclides: if domain_nuclides: - mgxs.nuclides = [nuclide for nuclide in self.nuclides if nuclide in domain_nuclides] + [ - "total"] + mgxs.nuclides = [ + nuclide for nuclide in self.nuclides + if nuclide in domain_nuclides + ] + ["total"] else: mgxs.nuclides = self.nuclides From 00657ccf871ba6a4ea4d1d0cdd1ed087ba838120 Mon Sep 17 00:00:00 2001 From: guyshtot Date: Sat, 25 Mar 2023 13:50:06 +0300 Subject: [PATCH 5/8] Update openmc/mgxs/library.py apply CR suggestion Co-authored-by: Paul Romano --- openmc/mgxs/library.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openmc/mgxs/library.py b/openmc/mgxs/library.py index 1c3a5dbb4..8ab052b0d 100644 --- a/openmc/mgxs/library.py +++ b/openmc/mgxs/library.py @@ -548,9 +548,9 @@ class Library: if self.nuclides: if domain_nuclides: mgxs.nuclides = [ - nuclide for nuclide in self.nuclides - if nuclide in domain_nuclides - ] + ["total"] + nuclide for nuclide in self.nuclides + if nuclide in domain_nuclides + ] + ["total"] else: mgxs.nuclides = self.nuclides From ff9d2283c428a0fe435c5fc2867426f818d18d21 Mon Sep 17 00:00:00 2001 From: guyshtot Date: Sat, 25 Mar 2023 13:52:23 +0300 Subject: [PATCH 6/8] Update tests/regression_tests/mgxs_library_specific_nuclides/test.py Remove double spaces at MGXS types in a test Co-authored-by: Paul Romano --- .../regression_tests/mgxs_library_specific_nuclides/test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/regression_tests/mgxs_library_specific_nuclides/test.py b/tests/regression_tests/mgxs_library_specific_nuclides/test.py index 41ae0a689..e749ca137 100644 --- a/tests/regression_tests/mgxs_library_specific_nuclides/test.py +++ b/tests/regression_tests/mgxs_library_specific_nuclides/test.py @@ -25,9 +25,9 @@ class MGXSTestHarness(PyAPITestHarness): # openmc.mgxs.ARBITRARY_MATRIX_TYPES so we can see the code works, # but not use too much resources relevant_MGXS_TYPES += [ - "(n,elastic)", "(n,level)", "(n,2n)", "(n,na)", "(n,nc)", - "(n,gamma)", "(n,a)", "(n,Xa)", "heating", "damage-energy", - "(n,n1)", "(n,a0)", "(n,nc) matrix", "(n,n1) matrix", + "(n,elastic)", "(n,level)", "(n,2n)", "(n,na)", "(n,nc)", + "(n,gamma)", "(n,a)", "(n,Xa)", "heating", "damage-energy", + "(n,n1)", "(n,a0)", "(n,nc) matrix", "(n,n1) matrix", "(n,2n) matrix"] self.mgxs_lib.mgxs_types = tuple(relevant_MGXS_TYPES) self.mgxs_lib.energy_groups = energy_groups From 4e7cae8b9858db63fc8e2806c997dc90311e3958 Mon Sep 17 00:00:00 2001 From: guyshtot Date: Sat, 25 Mar 2023 13:52:37 +0300 Subject: [PATCH 7/8] Update tests/regression_tests/mgxs_library_specific_nuclides/test.py Co-authored-by: Paul Romano --- tests/regression_tests/mgxs_library_specific_nuclides/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/regression_tests/mgxs_library_specific_nuclides/test.py b/tests/regression_tests/mgxs_library_specific_nuclides/test.py index e749ca137..9af2ce17c 100644 --- a/tests/regression_tests/mgxs_library_specific_nuclides/test.py +++ b/tests/regression_tests/mgxs_library_specific_nuclides/test.py @@ -33,7 +33,7 @@ class MGXSTestHarness(PyAPITestHarness): self.mgxs_lib.energy_groups = energy_groups self.mgxs_lib.legendre_order = 3 self.mgxs_lib.domain_type = 'material' - self.mgxs_lib.nuclides=['U235','Zr90','H1'] + self.mgxs_lib.nuclides = ['U235', 'Zr90', 'H1'] self.mgxs_lib.build_library() # Add tallies From 3d1811a64a9f168d003ce6791a5b7da6c0bfd906 Mon Sep 17 00:00:00 2001 From: guyshtot Date: Sat, 25 Mar 2023 13:57:08 +0300 Subject: [PATCH 8/8] Changed merge=False to merge=True in mgxs_library_specific_nucides test to speed up the test. --- .../inputs_true.dat | 1691 +---------------- .../mgxs_library_specific_nuclides/test.py | 2 +- 2 files changed, 71 insertions(+), 1622 deletions(-) diff --git a/tests/regression_tests/mgxs_library_specific_nuclides/inputs_true.dat b/tests/regression_tests/mgxs_library_specific_nuclides/inputs_true.dat index 205eb059c..061aa1b95 100644 --- a/tests/regression_tests/mgxs_library_specific_nuclides/inputs_true.dat +++ b/tests/regression_tests/mgxs_library_specific_nuclides/inputs_true.dat @@ -50,12 +50,15 @@ - - 1 + + 1 2 3 0.0 0.625 20000000.0 + + 1 + 0.0 0.625 20000000.0 @@ -71,1699 +74,145 @@ 2 - + 3 - - 1 2 + + 383 2 total flux tracklength - + 1 2 U235 total - total + total absorption (n,2n) (n,3n) (n,4n) fission nu-fission kappa-fission scatter inverse-velocity prompt-nu-fission (n,elastic) (n,level) (n,na) (n,nc) (n,gamma) (n,a) (n,Xa) heating damage-energy (n,n1) (n,a0) tracklength - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - total - tracklength - - - 1 2 + + 383 2 total flux analog - + 1 5 6 U235 total - scatter + scatter nu-scatter analog - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - total - tracklength - - - 1 2 - total - flux - analog - - - 1 5 6 - U235 total - nu-scatter - analog - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - absorption - tracklength - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - absorption - tracklength - - - 1 2 - U235 total - (n,2n) - tracklength - - - 1 2 - U235 total - (n,3n) - tracklength - - - 1 2 - U235 total - (n,4n) - tracklength - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - absorption - tracklength - - - 1 2 - U235 total - fission - tracklength - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - fission - tracklength - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - nu-fission - tracklength - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - kappa-fission - tracklength - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - scatter - tracklength - - - 1 2 - total - flux - analog - - - 1 2 - U235 total - nu-scatter - analog - - - 1 2 - total - flux - analog - - - 1 2 5 30 - U235 total - scatter - analog - - - 1 2 - total - flux - analog - - - 1 2 5 30 - U235 total - nu-scatter - analog - - - 1 2 5 - U235 total - nu-scatter - analog - - - 1 2 5 - U235 total - scatter - analog - - - 1 2 - total - flux - analog - - - 1 2 5 - U235 total - nu-fission - analog - - - 1 2 5 - U235 total - scatter - analog - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - scatter - tracklength - - - 1 2 5 30 - U235 total - scatter - analog - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - scatter - tracklength - - - 1 2 5 30 - U235 total - scatter - analog - - - 1 2 5 - U235 total - nu-scatter - analog - - - 1 54 - U235 total - nu-fission - analog - - - 1 5 - U235 total - nu-fission - analog - - - 1 54 - U235 total - prompt-nu-fission - analog - - - 1 5 - U235 total - prompt-nu-fission - analog - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - inverse-velocity - tracklength - - - 1 2 - total - flux - tracklength - 1 2 U235 total - prompt-nu-fission - tracklength - - - 1 2 - total - flux - analog - - - 1 2 5 - U235 total - prompt-nu-fission - analog - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - total - tracklength - - - 1 2 - total - flux - analog - - - 1 5 6 - U235 total - scatter - analog - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - total - tracklength - - - 1 2 - total - flux - analog - - - 1 5 6 - U235 total nu-scatter analog - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - (n,elastic) - tracklength - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - (n,level) - tracklength - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - (n,2n) - tracklength - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - (n,na) - tracklength - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - (n,nc) - tracklength - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - (n,gamma) - tracklength - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - (n,a) - tracklength - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - (n,Xa) - tracklength - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - heating - tracklength - - - 1 2 - total - flux - tracklength - - 1 2 + 1 2 5 30 U235 total - damage-energy - tracklength + scatter nu-scatter + analog - - 1 2 - total - flux - tracklength - - - 1 2 + + 1 2 5 U235 total - (n,n1) - tracklength - - - 1 2 - total - flux - tracklength - - - 1 2 - U235 total - (n,a0) - tracklength - - - 1 2 - total - flux + nu-scatter scatter nu-fission prompt-nu-fission (n,nc) (n,n1) (n,2n) analog - 1 2 5 + 1 54 U235 total - (n,nc) + nu-fission prompt-nu-fission analog - 1 2 - total - flux - analog - - - 1 2 5 + 1 5 U235 total - (n,n1) + nu-fission prompt-nu-fission analog - - 1 2 - total - flux - analog - - - 1 2 5 - U235 total - (n,2n) - analog - - - 106 2 - total - flux - tracklength - - + 106 2 Zr90 total - total + total absorption (n,2n) (n,3n) (n,4n) fission nu-fission kappa-fission scatter inverse-velocity prompt-nu-fission (n,elastic) (n,level) (n,na) (n,nc) (n,gamma) (n,a) (n,Xa) heating damage-energy (n,n1) (n,a0) tracklength - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - total - tracklength - - - 106 2 - total - flux - analog - - + 106 5 6 Zr90 total - scatter - analog - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - total - tracklength - - - 106 2 - total - flux - analog - - - 106 5 6 - Zr90 total - nu-scatter - analog - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - absorption - tracklength - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - absorption - tracklength - - - 106 2 - Zr90 total - (n,2n) - tracklength - - - 106 2 - Zr90 total - (n,3n) - tracklength - - - 106 2 - Zr90 total - (n,4n) - tracklength - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - absorption - tracklength - - - 106 2 - Zr90 total - fission - tracklength - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - fission - tracklength - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - nu-fission - tracklength - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - kappa-fission - tracklength - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - scatter - tracklength - - - 106 2 - total - flux - analog - - - 106 2 - Zr90 total - nu-scatter - analog - - - 106 2 - total - flux - analog - - - 106 2 5 30 - Zr90 total - scatter - analog - - - 106 2 - total - flux - analog - - - 106 2 5 30 - Zr90 total - nu-scatter - analog - - - 106 2 5 - Zr90 total - nu-scatter - analog - - - 106 2 5 - Zr90 total - scatter - analog - - - 106 2 - total - flux - analog - - - 106 2 5 - Zr90 total - nu-fission - analog - - - 106 2 5 - Zr90 total - scatter - analog - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - scatter - tracklength - - - 106 2 5 30 - Zr90 total - scatter - analog - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - scatter - tracklength - - - 106 2 5 30 - Zr90 total - scatter - analog - - - 106 2 5 - Zr90 total - nu-scatter - analog - - - 106 54 - Zr90 total - nu-fission - analog - - - 106 5 - Zr90 total - nu-fission - analog - - - 106 54 - Zr90 total - prompt-nu-fission - analog - - - 106 5 - Zr90 total - prompt-nu-fission - analog - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - inverse-velocity - tracklength - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - prompt-nu-fission - tracklength - - - 106 2 - total - flux - analog - - - 106 2 5 - Zr90 total - prompt-nu-fission - analog - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - total - tracklength - - - 106 2 - total - flux - analog - - - 106 5 6 - Zr90 total - scatter - analog - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - total - tracklength - - - 106 2 - total - flux - analog - - - 106 5 6 - Zr90 total - nu-scatter - analog - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - (n,elastic) - tracklength - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - (n,level) - tracklength - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - (n,2n) - tracklength - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - (n,na) - tracklength - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - (n,nc) - tracklength - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - (n,gamma) - tracklength - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - (n,a) - tracklength - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - (n,Xa) - tracklength - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - heating - tracklength - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - damage-energy - tracklength - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - (n,n1) - tracklength - - - 106 2 - total - flux - tracklength - - - 106 2 - Zr90 total - (n,a0) - tracklength - - - 106 2 - total - flux - analog - - - 106 2 5 - Zr90 total - (n,nc) - analog - - - 106 2 - total - flux - analog - - - 106 2 5 - Zr90 total - (n,n1) - analog - - - 106 2 - total - flux - analog - - - 106 2 5 - Zr90 total - (n,2n) - analog - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - total - tracklength - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - total - tracklength - - - 211 2 - total - flux - analog - - - 211 5 6 - H1 total - scatter - analog - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - total - tracklength - - - 211 2 - total - flux - analog - - - 211 5 6 - H1 total - nu-scatter - analog - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - absorption - tracklength - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - absorption - tracklength - - - 211 2 - H1 total - (n,2n) - tracklength - - - 211 2 - H1 total - (n,3n) - tracklength - - - 211 2 - H1 total - (n,4n) - tracklength - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - absorption - tracklength - - - 211 2 - H1 total - fission - tracklength - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - fission - tracklength - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - nu-fission - tracklength - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - kappa-fission - tracklength - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - scatter - tracklength - - - 211 2 - total - flux - analog - - - 211 2 - H1 total - nu-scatter - analog - - - 211 2 - total - flux - analog - - - 211 2 5 30 - H1 total - scatter - analog - - - 211 2 - total - flux - analog - - - 211 2 5 30 - H1 total - nu-scatter - analog - - - 211 2 5 - H1 total - nu-scatter - analog - - - 211 2 5 - H1 total - scatter - analog - - - 211 2 - total - flux - analog - - - 211 2 5 - H1 total - nu-fission - analog - - - 211 2 5 - H1 total - scatter - analog - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - scatter - tracklength - - - 211 2 5 30 - H1 total - scatter - analog - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - scatter - tracklength - - - 211 2 5 30 - H1 total - scatter - analog - - - 211 2 5 - H1 total - nu-scatter + scatter nu-scatter analog - 211 54 - H1 total - nu-fission + 106 2 + Zr90 total + nu-scatter analog - - 211 5 - H1 total - nu-fission + + 106 2 5 30 + Zr90 total + scatter nu-scatter analog - - 211 54 - H1 total - prompt-nu-fission + + 106 2 5 + Zr90 total + nu-scatter scatter nu-fission prompt-nu-fission (n,nc) (n,n1) (n,2n) analog - - 211 5 - H1 total - prompt-nu-fission + + 106 54 + Zr90 total + nu-fission prompt-nu-fission analog - - 211 2 - total - flux + + 106 5 + Zr90 total + nu-fission prompt-nu-fission + analog + + + 251 2 + H1 total + total absorption (n,2n) (n,3n) (n,4n) fission nu-fission kappa-fission scatter inverse-velocity prompt-nu-fission (n,elastic) (n,level) (n,na) (n,nc) (n,gamma) (n,a) (n,Xa) heating damage-energy (n,n1) (n,a0) tracklength - - 211 2 + + 251 5 6 H1 total - inverse-velocity - tracklength - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - prompt-nu-fission - tracklength - - - 211 2 - total - flux + scatter nu-scatter analog - - 211 2 5 - H1 total - prompt-nu-fission - analog - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - total - tracklength - - - 211 2 - total - flux - analog - - - 211 5 6 - H1 total - scatter - analog - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - total - tracklength - - - 211 2 - total - flux - analog - - - 211 5 6 + + 251 2 H1 total nu-scatter analog - - 211 2 - total - flux - tracklength - - - 211 2 + + 251 2 5 30 H1 total - (n,elastic) - tracklength - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - (n,level) - tracklength - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - (n,2n) - tracklength - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - (n,na) - tracklength - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - (n,nc) - tracklength - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - (n,gamma) - tracklength - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - (n,a) - tracklength - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - (n,Xa) - tracklength - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - heating - tracklength - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - damage-energy - tracklength - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - (n,n1) - tracklength - - - 211 2 - total - flux - tracklength - - - 211 2 - H1 total - (n,a0) - tracklength - - - 211 2 - total - flux + scatter nu-scatter analog - - 211 2 5 + + 251 2 5 H1 total - (n,nc) + nu-scatter scatter nu-fission prompt-nu-fission (n,nc) (n,n1) (n,2n) analog - - 211 2 - total - flux - analog - - - 211 2 5 + + 251 54 H1 total - (n,n1) + nu-fission prompt-nu-fission analog - - 211 2 - total - flux - analog - - - 211 2 5 + + 251 5 H1 total - (n,2n) + nu-fission prompt-nu-fission analog diff --git a/tests/regression_tests/mgxs_library_specific_nuclides/test.py b/tests/regression_tests/mgxs_library_specific_nuclides/test.py index 9af2ce17c..61910e539 100644 --- a/tests/regression_tests/mgxs_library_specific_nuclides/test.py +++ b/tests/regression_tests/mgxs_library_specific_nuclides/test.py @@ -37,7 +37,7 @@ class MGXSTestHarness(PyAPITestHarness): self.mgxs_lib.build_library() # Add tallies - self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=False) + self.mgxs_lib.add_to_tallies_file(self._model.tallies, merge=True) def _get_results(self, hash_output=True): """Digest info in the statepoint and return as a string."""