diff --git a/openmc/data/thermal.py b/openmc/data/thermal.py index 99e4b5a53..fefb71518 100644 --- a/openmc/data/thermal.py +++ b/openmc/data/thermal.py @@ -408,30 +408,27 @@ class ThermalScattering(EqualityMixin): # Cross section elastic_xs_type = elastic_group['xs'].attrs['type'].decode() if elastic_xs_type == 'Tabulated1D': - table.elastic_xs[T] = \ - Tabulated1D.from_hdf5(elastic_group['xs']) + table.elastic_xs[T] = Tabulated1D.from_hdf5( + elastic_group['xs']) elif elastic_xs_type == 'bragg': - table.elastic_xs[T] = \ - CoherentElastic.from_hdf5(elastic_group['xs']) + table.elastic_xs[T] = CoherentElastic.from_hdf5( + elastic_group['xs']) # Angular distribution if 'mu_out' in elastic_group: - table.elastic_mu_out[T] = \ - elastic_group['mu_out'].value + table.elastic_mu_out[T] = elastic_group['mu_out'].value # Read thermal inelastic scattering if 'inelastic' in Tgroup: inelastic_group = Tgroup['inelastic'] - table.inelastic_xs[T] = \ - Tabulated1D.from_hdf5(inelastic_group['xs']) + table.inelastic_xs[T] = Tabulated1D.from_hdf5( + inelastic_group['xs']) if table.secondary_mode in ('equal', 'skewed'): - table.inelastic_e_out[T] = \ - inelastic_group['energy_out'] - table.inelastic_mu_out[T] = \ - inelastic_group['mu_out'] + table.inelastic_e_out[T] = inelastic_group['energy_out'].value + table.inelastic_mu_out[T] = inelastic_group['mu_out'].value elif table.secondary_mode == 'continuous': - table.inelastic_dist[T] = \ - AngleEnergy.from_hdf5(inelastic_group) + table.inelastic_dist[T] = AngleEnergy.from_hdf5( + inelastic_group) return table diff --git a/tests/unit_tests/test_data_multipole.py b/tests/unit_tests/test_data_multipole.py index c485abb4f..dc30677e8 100644 --- a/tests/unit_tests/test_data_multipole.py +++ b/tests/unit_tests/test_data_multipole.py @@ -1,10 +1,8 @@ #!/usr/bin/env python -from collections import Callable import os import numpy as np -import pandas as pd import pytest import openmc.data diff --git a/tests/unit_tests/test_data_thermal.py b/tests/unit_tests/test_data_thermal.py new file mode 100644 index 000000000..4af815c88 --- /dev/null +++ b/tests/unit_tests/test_data_thermal.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python + +from collections import Callable +import os + +import numpy as np +import pytest +import openmc.data + + +_ENDF_DATA = os.environ['OPENMC_ENDF_DATA'] + + +@pytest.fixture(scope='module') +def h2o(): + """H in H2O thermal scattering data.""" + directory = os.path.dirname(os.environ['OPENMC_CROSS_SECTIONS']) + filename = os.path.join(directory, 'c_H_in_H2O.h5') + return openmc.data.ThermalScattering.from_hdf5(filename) + + +@pytest.fixture(scope='module') +def graphite(): + """Graphite thermal scattering data.""" + directory = os.path.dirname(os.environ['OPENMC_CROSS_SECTIONS']) + filename = os.path.join(directory, 'c_Graphite.h5') + return openmc.data.ThermalScattering.from_hdf5(filename) + + +@pytest.fixture(scope='module') +def h2o_njoy(): + path_h1 = os.path.join(_ENDF_DATA, 'neutrons', 'n-001_H_001.endf') + path_h2o = os.path.join(_ENDF_DATA, 'thermal_scatt', 'tsl-HinH2O.endf') + return openmc.data.ThermalScattering.from_njoy( + path_h1, path_h2o, temperatures=[293.6, 500.0]) + + +def test_h2o_attributes(h2o): + assert h2o.name == 'c_H_in_H2O' + assert h2o.nuclides == ['H1'] + assert h2o.secondary_mode == 'skewed' + assert h2o.temperatures == ['294K'] + assert h2o.atomic_weight_ratio == pytest.approx(0.999167) + + +def test_h2o_xs(h2o): + assert not h2o.elastic_xs + for temperature, func in h2o.inelastic_xs.items(): + assert temperature.endswith('K') + assert isinstance(func, Callable) + + +def test_graphite_attributes(graphite): + assert graphite.name == 'c_Graphite' + assert graphite.nuclides == ['C0', 'C12', 'C13'] + assert graphite.secondary_mode == 'skewed' + assert graphite.temperatures == ['296K'] + assert graphite.atomic_weight_ratio == pytest.approx(11.898) + + +def test_graphite_xs(graphite): + for temperature, func in graphite.elastic_xs.items(): + assert temperature.endswith('K') + assert isinstance(func, openmc.data.CoherentElastic) + for temperature, func in graphite.inelastic_xs.items(): + assert temperature.endswith('K') + assert isinstance(func, Callable) + elastic = graphite.elastic_xs['296K'] + assert elastic([1e-3, 1.0]) == pytest.approx([13.47464936, 0.62590156]) + + +def test_export_to_hdf5(tmpdir, h2o_njoy, graphite): + filename = str(tmpdir.join('water.h5')) + h2o_njoy.export_to_hdf5(filename) + assert os.path.exists(filename) + + filename = str(tmpdir.join('graphite.h5')) + graphite.export_to_hdf5(filename) + assert os.path.exists(filename) + + +def test_continuous_dist(h2o_njoy): + for temperature, dist in h2o_njoy.inelastic_dist.items(): + assert temperature.endswith('K') + assert isinstance(dist, openmc.data.CorrelatedAngleEnergy) + + +def test_get_thermal_name(): + f = openmc.data.get_thermal_name + # Names which are recognized + assert f('lwtr') == 'c_H_in_H2O' + assert f('hh2o') == 'c_H_in_H2O' + + with pytest.warns(UserWarning, match='is not recognized'): + # Names which can be guessed + assert f('lw00') == 'c_H_in_H2O' + assert f('graphite') == 'c_Graphite' + + # Names that don't remotely match anything + assert f('boogie_monster') == 'c_boogie_monster'