From 043c56f3384e738be9eba41ac1d8e5aa4dd17766 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Thu, 11 Aug 2016 11:31:29 -0400 Subject: [PATCH 01/10] Now track OpenCG lattice names. Now strip hyphens on nuclide names --- openmc/nuclide.py | 10 +++++++++- openmc/opencg_compatible.py | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/openmc/nuclide.py b/openmc/nuclide.py index 14609161fe..961ab201f4 100644 --- a/openmc/nuclide.py +++ b/openmc/nuclide.py @@ -1,5 +1,6 @@ from numbers import Integral import sys +import warnings from openmc.checkvalue import check_type @@ -98,7 +99,14 @@ class Nuclide(object): @name.setter def name(self, name): check_type('name', name, basestring) - self._name = name + + if '-' in name: + new_name = name.strip('-', '') + msg = 'OpenMC nuclide names follow the GND standard. Nuclide ' \ + '"{}" is being transformed to "{}".'.format(name, new_name) + warnings.warn(msg, DeprecationWarning) + + self._name = name.replace('-', '') @xs.setter def xs(self, xs): diff --git a/openmc/opencg_compatible.py b/openmc/opencg_compatible.py index 93a257f465..a3b35e0555 100644 --- a/openmc/opencg_compatible.py +++ b/openmc/opencg_compatible.py @@ -911,6 +911,7 @@ def get_openmc_lattice(opencg_lattice): if lattice_id in OPENMC_LATTICES: return OPENMC_LATTICES[lattice_id] + name = opencg_lattice.name dimension = opencg_lattice.dimension width = opencg_lattice.width offset = opencg_lattice.offset @@ -941,7 +942,7 @@ def get_openmc_lattice(opencg_lattice): ((np.array(width, dtype=np.float64) * np.array(dimension, dtype=np.float64))) / -2.0 - openmc_lattice = openmc.RectLattice(lattice_id=lattice_id) + openmc_lattice = openmc.RectLattice(lattice_id=lattice_id, name=name) openmc_lattice.pitch = width openmc_lattice.universes = universe_array openmc_lattice.lower_left = lower_left From 8bc7afe91fe396bb79670221d6a235bf086dfc64 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Thu, 11 Aug 2016 11:48:21 -0400 Subject: [PATCH 02/10] Fixed bug in Nuclide hyphen strip --- openmc/nuclide.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmc/nuclide.py b/openmc/nuclide.py index 961ab201f4..6f7bd79b8f 100644 --- a/openmc/nuclide.py +++ b/openmc/nuclide.py @@ -101,7 +101,7 @@ class Nuclide(object): check_type('name', name, basestring) if '-' in name: - new_name = name.strip('-', '') + new_name = name.replace('-', '') msg = 'OpenMC nuclide names follow the GND standard. Nuclide ' \ '"{}" is being transformed to "{}".'.format(name, new_name) warnings.warn(msg, DeprecationWarning) From 12c8672804b04391cd63d59ff75b3d45d10fb670 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Thu, 11 Aug 2016 12:20:02 -0400 Subject: [PATCH 03/10] Reworded nuclide de-hyphen deprecation warning message --- openmc/nuclide.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openmc/nuclide.py b/openmc/nuclide.py index 6f7bd79b8f..124c86a359 100644 --- a/openmc/nuclide.py +++ b/openmc/nuclide.py @@ -102,8 +102,8 @@ class Nuclide(object): if '-' in name: new_name = name.replace('-', '') - msg = 'OpenMC nuclide names follow the GND standard. Nuclide ' \ - '"{}" is being transformed to "{}".'.format(name, new_name) + msg = 'OpenMC nuclides follow the GND naming convention. Nuclide ' \ + '"{}" is being renamed as "{}".'.format(name, new_name) warnings.warn(msg, DeprecationWarning) self._name = name.replace('-', '') From fe63a59c5b192ec3962586c6173f2b0d4d3e34dc Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Thu, 11 Aug 2016 13:38:56 -0400 Subject: [PATCH 04/10] Moved get_thermal_name(...) from scripts to openmc.data.thermal --- openmc/data/thermal.py | 22 +++++++++++++++++++++- openmc/material.py | 3 ++- scripts/openmc-update-inputs | 21 ++------------------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/openmc/data/thermal.py b/openmc/data/thermal.py index 9de39f518d..275836be77 100644 --- a/openmc/data/thermal.py +++ b/openmc/data/thermal.py @@ -40,6 +40,26 @@ _THERMAL_NAMES = {'al': 'c_Al27', 'al27': 'c_Al27', 'zrzrh': 'c_Zr_in_ZrH', 'zr-h': 'c_Zr_in_ZrH', 'zr/h': 'c_Zr_in_ZrH'} +def get_thermal_name(name): + """Get proper S(a,b) table name, e.g. 'HH2O' -> 'c_H_in_H2O'""" + + if name.lower() in _THERMAL_NAMES: + return _THERMAL_NAMES[name.lower()] + else: + # Make an educated guess?? This actually works well for + # JEFF-3.2 which stupidly uses names like lw00.32t, + # lw01.32t, etc. for different temperatures + matches = get_close_matches( + name.lower(), _THERMAL_NAMES.keys(), cutoff=0.5) + if len(matches) > 0: + return _THERMAL_NAMES[matches[0]] + '.' + xs + else: + # OK, we give up. Just use the ACE name. + return 'c_' + name + + return name + + class CoherentElastic(object): r"""Coherent elastic scattering data from a crystalline material @@ -394,4 +414,4 @@ class ThermalScattering(object): pairs = np.fromiter(map(lambda p: p[0], ace.pairs), int) table.zaids = pairs[np.nonzero(pairs)] - return table + return table \ No newline at end of file diff --git a/openmc/material.py b/openmc/material.py index d7ffd04e94..e1f3da97ab 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -6,6 +6,7 @@ from xml.etree import ElementTree as ET import sys import openmc +import openmc.data import openmc.checkvalue as cv from openmc.clean_xml import sort_xml_elements, clean_xml_indentation @@ -484,7 +485,7 @@ class Material(object): 'non-string cross-section identifier "{1}"'.format(self._id, xs) raise ValueError(msg) - self._sab.append((name, xs)) + self._sab.append((openmc.data.get_thermal_name(name), xs)) def make_isotropic_in_lab(self): for nuclide, percent, percent_type in self._nuclides: diff --git a/scripts/openmc-update-inputs b/scripts/openmc-update-inputs index 5b5bf0978f..613e4a2241 100755 --- a/scripts/openmc-update-inputs +++ b/scripts/openmc-update-inputs @@ -253,23 +253,6 @@ def update_geometry(geometry_root): return was_updated -def get_thermal_name(name): - """Get proper S(a,b) table name, e.g. 'HH2O' -> 'c_H_in_H2O'""" - if name.lower() in _THERMAL_NAMES: - return _THERMAL_NAMES[name.lower()] - else: - # Make an educated guess?? This actually works well for - # JEFF-3.2 which stupidly uses names like lw00.32t, - # lw01.32t, etc. for different temperatures - matches = get_close_matches( - name.lower(), _THERMAL_NAMES.keys(), cutoff=0.5) - if len(matches) > 0: - return _THERMAL_NAMES[matches[0]] + '.' + xs - else: - # OK, we give up. Just use the ACE name. - return 'c_' + name - return name - def update_materials(root): """Update the given XML materials tree. Return True if changes were made.""" was_updated = False @@ -298,13 +281,13 @@ def update_materials(root): for sab in material.findall('sab'): if 'name' in sab.attrib: sabname = sab.attrib['name'] - sab.set('name', get_thermal_name(sabname)) + sab.set('name', openmc.data.get_thermal_name(sabname)) was_updated = True elif sab.find('name') is not None: name_elem = sab.find('name') sabname = name_elem.text - name_elem.text = get_thermal(sabname) + name_elem.text = openmc.data.get_thermal_name(sabname) was_updated = True return was_updated From b791450b751a294cd42904b0638cba6b4fe72b9c Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Thu, 11 Aug 2016 13:46:07 -0400 Subject: [PATCH 05/10] Added conditional to pass qualifying S(a,b) names through converter method --- openmc/data/thermal.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openmc/data/thermal.py b/openmc/data/thermal.py index 275836be77..8b6e35b61a 100644 --- a/openmc/data/thermal.py +++ b/openmc/data/thermal.py @@ -43,7 +43,9 @@ _THERMAL_NAMES = {'al': 'c_Al27', 'al27': 'c_Al27', def get_thermal_name(name): """Get proper S(a,b) table name, e.g. 'HH2O' -> 'c_H_in_H2O'""" - if name.lower() in _THERMAL_NAMES: + if name in _THERMAL_NAMES.values(): + return name + elif name.lower() in _THERMAL_NAMES: return _THERMAL_NAMES[name.lower()] else: # Make an educated guess?? This actually works well for @@ -52,7 +54,7 @@ def get_thermal_name(name): matches = get_close_matches( name.lower(), _THERMAL_NAMES.keys(), cutoff=0.5) if len(matches) > 0: - return _THERMAL_NAMES[matches[0]] + '.' + xs + return _THERMAL_NAMES[matches[0]] else: # OK, we give up. Just use the ACE name. return 'c_' + name From 11a2c31031eeabe29595ab335716739bc2c24cb1 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Thu, 11 Aug 2016 22:12:47 -0400 Subject: [PATCH 06/10] Removed unreachable return in get_thermal_name(...) --- openmc/data/thermal.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/openmc/data/thermal.py b/openmc/data/thermal.py index 8b6e35b61a..cd44f21f95 100644 --- a/openmc/data/thermal.py +++ b/openmc/data/thermal.py @@ -59,8 +59,6 @@ def get_thermal_name(name): # OK, we give up. Just use the ACE name. return 'c_' + name - return name - class CoherentElastic(object): r"""Coherent elastic scattering data from a crystalline material @@ -416,4 +414,4 @@ class ThermalScattering(object): pairs = np.fromiter(map(lambda p: p[0], ace.pairs), int) table.zaids = pairs[np.nonzero(pairs)] - return table \ No newline at end of file + return table From 531a1726078a4b2d7abacf1752a04187a38805ed Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Thu, 11 Aug 2016 22:21:40 -0400 Subject: [PATCH 07/10] Now appending metatable suffix to nuclide names per suggestion by @paulromano --- openmc/nuclide.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/openmc/nuclide.py b/openmc/nuclide.py index 124c86a359..00ae25ac60 100644 --- a/openmc/nuclide.py +++ b/openmc/nuclide.py @@ -102,6 +102,10 @@ class Nuclide(object): if '-' in name: new_name = name.replace('-', '') + new_name = new_name.replace('Nat', '0') + if new_name.endswith('m'): + new_name = new_name[:-1] + '_m1' + msg = 'OpenMC nuclides follow the GND naming convention. Nuclide ' \ '"{}" is being renamed as "{}".'.format(name, new_name) warnings.warn(msg, DeprecationWarning) From cdb882648aff932644870f6bd96c45c3c0c032c7 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Thu, 11 Aug 2016 22:27:53 -0400 Subject: [PATCH 08/10] Now printing a UserWarning in place of a DeprecationWarning for nuclide renaming --- openmc/nuclide.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmc/nuclide.py b/openmc/nuclide.py index 00ae25ac60..2c6998cd5d 100644 --- a/openmc/nuclide.py +++ b/openmc/nuclide.py @@ -108,7 +108,7 @@ class Nuclide(object): msg = 'OpenMC nuclides follow the GND naming convention. Nuclide ' \ '"{}" is being renamed as "{}".'.format(name, new_name) - warnings.warn(msg, DeprecationWarning) + warnings.warn(msg) self._name = name.replace('-', '') From 284058319097c4777d0e3d0c7814b7ed6c4ef665 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Thu, 11 Aug 2016 23:00:59 -0400 Subject: [PATCH 09/10] Fixed nuclide renaming bug --- openmc/nuclide.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/openmc/nuclide.py b/openmc/nuclide.py index 2c6998cd5d..68f95beb94 100644 --- a/openmc/nuclide.py +++ b/openmc/nuclide.py @@ -99,19 +99,18 @@ class Nuclide(object): @name.setter def name(self, name): check_type('name', name, basestring) + self._name = name if '-' in name: - new_name = name.replace('-', '') - new_name = new_name.replace('Nat', '0') - if new_name.endswith('m'): - new_name = new_name[:-1] + '_m1' + self._name = name.replace('-', '') + self._name = self._name.replace('Nat', '0') + if self._name.endswith('m'): + self._name = self._name[:-1] + '_m1' msg = 'OpenMC nuclides follow the GND naming convention. Nuclide ' \ - '"{}" is being renamed as "{}".'.format(name, new_name) + '"{}" is being renamed as "{}".'.format(name, self._name) warnings.warn(msg) - self._name = name.replace('-', '') - @xs.setter def xs(self, xs): check_type('cross-section identifier', xs, basestring) From 6ecf89424e62d65f60f029d83b93645c58762753 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Fri, 12 Aug 2016 10:02:39 -0400 Subject: [PATCH 10/10] Added warning message for S(a,b) table renaming --- openmc/material.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/openmc/material.py b/openmc/material.py index e1f3da97ab..da173c92e7 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -485,7 +485,13 @@ class Material(object): 'non-string cross-section identifier "{1}"'.format(self._id, xs) raise ValueError(msg) - self._sab.append((openmc.data.get_thermal_name(name), xs)) + new_name = openmc.data.get_thermal_name(name) + if new_name != name: + msg = 'OpenMC S(a,b) tables follow the GND naming convention. ' \ + 'Table "{}" is being renamed as "{}".'.format(name, new_name) + warnings.warn(msg) + + self._sab.append((new_name, xs)) def make_isotropic_in_lab(self): for nuclide, percent, percent_type in self._nuclides: