From fe63a59c5b192ec3962586c6173f2b0d4d3e34dc Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Thu, 11 Aug 2016 13:38:56 -0400 Subject: [PATCH] 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