Improve guessing in openmc.data.get_thermal_name

This commit is contained in:
Paul Romano 2017-12-19 14:08:26 +07:00
parent 39f3ea9327
commit 9f7e5e85e7
3 changed files with 55 additions and 43 deletions

View file

@ -23,40 +23,40 @@ from openmc.stats import Discrete, Tabular
_THERMAL_NAMES = {
'c_Al27': ('al', 'al27'),
'c_Be': ('be', 'be-metal'),
'c_BeO': ('beo',),
'c_Be_in_BeO': ('bebeo', 'be-o', 'be/o'),
'c_C6H6': ('benz', 'c6h6'),
'c_C_in_SiC': ('csic',),
'c_Ca_in_CaH2': ('cah',),
'c_D_in_D2O': ('dd2o', 'hwtr', 'hw'),
'c_Fe56': ('fe', 'fe56'),
'c_Graphite': ('graph', 'grph', 'gr'),
'c_H_in_CaH2': ('hcah2',),
'c_H_in_CH2': ('hch2', 'poly', 'pol'),
'c_H_in_CH4_liquid': ('lch4', 'lmeth'),
'c_H_in_CH4_solid': ('sch4', 'smeth'),
'c_H_in_H2O': ('hh2o', 'lwtr', 'lw'),
'c_H_in_H2O_solid': ('hice',),
'c_H_in_C5O2H8': ('lucite', 'c5o2h8'),
'c_H_in_YH2': ('hyh2',),
'c_H_in_ZrH': ('hzrh', 'h-zr', 'h/zr', 'hzr'),
'c_Mg24': ('mg', 'mg24'),
'c_O_in_BeO': ('obeo', 'o-be', 'o/be'),
'c_O_in_D2O': ('od2o',),
'c_O_in_H2O_ice': ('oice',),
'c_O_in_UO2': ('ouo2', 'o2-u', 'o2/u'),
'c_ortho_D': ('orthod', 'dortho'),
'c_ortho_H': ('orthoh', 'hortho'),
'c_Si_in_SiC': ('sisic',),
'c_SiO2_alpha': ('sio2', 'sio2a'),
'c_SiO2_beta': ('sio2b'),
'c_para_D': ('parad', 'dpara'),
'c_para_H': ('parah', 'hpara'),
'c_U_in_UO2': ('uuo2', 'u-o2', 'u/o2'),
'c_Y_in_YH2': ('yyh2',),
'c_Zr_in_ZrH': ('zrzrh', 'zr-h', 'zr/h')
'c_Al27': ['al', 'al27'],
'c_Be': ['be', 'be-metal'],
'c_BeO': ['beo'],
'c_Be_in_BeO': ['bebeo', 'be-o', 'be/o'],
'c_C6H6': ['benz', 'c6h6'],
'c_C_in_SiC': ['csic',],
'c_Ca_in_CaH2': ['cah'],
'c_D_in_D2O': ['dd2o', 'hwtr', 'hw'],
'c_Fe56': ['fe', 'fe56'],
'c_Graphite': ['graph', 'grph', 'gr'],
'c_H_in_CaH2': ['hcah2'],
'c_H_in_CH2': ['hch2', 'poly', 'pol'],
'c_H_in_CH4_liquid': ['lch4', 'lmeth'],
'c_H_in_CH4_solid': ['sch4', 'smeth'],
'c_H_in_H2O': ['hh2o', 'lwtr', 'lw'],
'c_H_in_H2O_solid': ['hice',],
'c_H_in_C5O2H8': ['lucite', 'c5o2h8'],
'c_H_in_YH2': ['hyh2'],
'c_H_in_ZrH': ['hzrh', 'h-zr', 'h/zr', 'hzr'],
'c_Mg24': ['mg', 'mg24'],
'c_O_in_BeO': ['obeo', 'o-be', 'o/be'],
'c_O_in_D2O': ['od2o'],
'c_O_in_H2O_ice': ['oice'],
'c_O_in_UO2': ['ouo2', 'o2-u', 'o2/u'],
'c_ortho_D': ['orthod', 'dortho'],
'c_ortho_H': ['orthoh', 'hortho'],
'c_Si_in_SiC': ['sisic'],
'c_SiO2_alpha': ['sio2', 'sio2a'],
'c_SiO2_beta': ['sio2b'],
'c_para_D': ['parad', 'dpara'],
'c_para_H': ['parah', 'hpara'],
'c_U_in_UO2': ['uuo2', 'u-o2', 'u/o2'],
'c_Y_in_YH2': ['yyh2'],
'c_Zr_in_ZrH': ['zrzrh', 'zr-h', 'zr/h']
}
@ -84,13 +84,25 @@ def get_thermal_name(name):
# 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
for proper_name, names in _THERMAL_NAMES.items():
matches = get_close_matches(
name.lower(), names, cutoff=0.5)
if len(matches) > 0:
warn('Thermal scattering material "{}" is not recognized. '
'Assigning a name of {}.'.format(name, proper_name))
return proper_name
# First, construct a list of all the values/keys in the names
# dictionary
all_names = sum(_THERMAL_NAMES.values(), [])
all_names += _THERMAL_NAMES.keys()
matches = get_close_matches(name, all_names, cutoff=0.5)
if len(matches) > 0:
# Figure out the key for the corresponding match
match = matches[0]
if match not in _THERMAL_NAMES:
for key, value_list in _THERMAL_NAMES.items():
if match in value_list:
match = key
break
warn('Thermal scattering material "{}" is not recognized. '
'Assigning a name of {}.'.format(name, match))
return match
else:
# OK, we give up. Just use the ACE name.
warn('Thermal scattering material "{0}" is not recognized. '

View file

@ -348,8 +348,7 @@ def test_ace_convert(tmpdir):
filename = os.path.join(_ENDF_DATA, 'neutrons', 'n-001_H_001.endf')
ace_ascii = str(tmpdir.join('ace_ascii'))
ace_binary = str(tmpdir.join('ace_binary'))
retcode = openmc.data.njoy.make_ace(filename, ace=ace_ascii)
assert retcode == 0
openmc.data.njoy.make_ace(filename, ace=ace_ascii)
# Convert to binary
openmc.data.ace.ascii_to_binary(ace_ascii, ace_binary)

View file

@ -95,6 +95,7 @@ def test_get_thermal_name():
# Names which can be guessed
assert f('lw00') == 'c_H_in_H2O'
assert f('graphite') == 'c_Graphite'
assert f('D_in_D2O') == 'c_D_in_D2O'
# Names that don't remotely match anything
assert f('boogie_monster') == 'c_boogie_monster'