diff --git a/openmc/data/function.py b/openmc/data/function.py index 751f6cdb57..b0390d19cd 100644 --- a/openmc/data/function.py +++ b/openmc/data/function.py @@ -544,7 +544,7 @@ class Combination(EqualityMixin): self._operations = operations -class Sum(EqualityMixin): +class Sum(Function1D): """Sum of multiple functions. This class allows you to create a callable object which represents the sum diff --git a/openmc/data/thermal.py b/openmc/data/thermal.py index 6cf5a4e9e1..3d5f2df64e 100644 --- a/openmc/data/thermal.py +++ b/openmc/data/thermal.py @@ -701,7 +701,7 @@ class ThermalScattering(EqualityMixin): energy = ace.xss[idx + 1: idx + 1 + n_energy]*EV_PER_MEV P = ace.xss[idx + 1 + n_energy: idx + 1 + 2 * n_energy] coherent_xs = CoherentElastic(energy, P*EV_PER_MEV) - coherent_dist = CoherentElasticAE(xs) + coherent_dist = CoherentElasticAE(coherent_xs) # Coherent elastic shouldn't have angular distributions listed n_mu = ace.nxs[6] + 1 diff --git a/openmc/data/thermal_angle_energy.py b/openmc/data/thermal_angle_energy.py index b7ca349f12..1f37863ea0 100644 --- a/openmc/data/thermal_angle_energy.py +++ b/openmc/data/thermal_angle_energy.py @@ -2,6 +2,7 @@ import numpy as np from .angle_energy import AngleEnergy from .correlated import CorrelatedAngleEnergy +import openmc.data class CoherentElasticAE(AngleEnergy): @@ -33,25 +34,37 @@ class CoherentElasticAE(AngleEnergy): def __init__(self, coherent_xs): self.coherent_xs = coherent_xs - def to_hdf5(self, group, xs_group=None): + def to_hdf5(self, group): """Write coherent elastic distribution to an HDF5 group - .. versionchanged:: 0.13.1 - The *xs_group* argument was added. - Parameters ---------- group : h5py.Group HDF5 group to write to - xs_group : h5py.Group, optional - Group containing 'xs' dataset """ group.attrs['type'] = np.string_('coherent_elastic') - if xs_group is not None: - group['coherent_xs'] = xs_group['xs'] - else: - group['coherent_xs'] = group.parent['xs'] + self.coherent_xs.to_hdf5(group, 'coherent_xs') + + @classmethod + def from_hdf5(cls, group): + """Generate coherent elastic distribution from HDF5 data + + .. versionadded:: 0.13.1 + + Parameters + ---------- + group : h5py.Group + HDF5 group to read from + + Returns + ------- + openmc.data.CoherentElasticAE + Coherent elastic distribution + + """ + coherent_xs = openmc.data.CoherentElastic.from_hdf5(group['coherent_xs']) + return cls(coherent_xs) class IncoherentElasticAE(AngleEnergy): @@ -255,7 +268,7 @@ class MixedElasticAE(AngleEnergy): """ group.attrs['type'] = np.string_('mixed_elastic') coherent_group = group.create_group('coherent') - self.coherent.to_hdf5(coherent_group, group.parent) + self.coherent.to_hdf5(coherent_group) incoherent_group = group.create_group('incoherent') self.incoherent.to_hdf5(incoherent_group)