From c48d5f07c42c561795ef0e84e4899095e3fd59ec Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 22 May 2019 07:33:42 -0500 Subject: [PATCH] Change how incoherent elastic data is written to HDF5 --- openmc/data/angle_energy.py | 4 ++-- openmc/data/function.py | 4 ++-- openmc/data/thermal.py | 35 ++++++++++++++++++++--------- openmc/data/thermal_angle_energy.py | 6 ++--- src/endf.cpp | 7 ++++-- 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/openmc/data/angle_energy.py b/openmc/data/angle_energy.py index 5fb176f681..8cf9bcf5e8 100644 --- a/openmc/data/angle_energy.py +++ b/openmc/data/angle_energy.py @@ -43,8 +43,8 @@ class AngleEnergy(EqualityMixin, metaclass=ABCMeta): return openmc.data.IncoherentElasticAEDiscrete.from_hdf5(group) elif dist_type == 'incoherent_inelastic_discrete': return openmc.data.IncoherentInelasticAEDiscrete.from_hdf5(group) - elif dist_type == 'incoherent_inelastic_continuous': - return openmc.data.IncoherentInelasticAEContinuous.from_hdf5(group) + elif dist_type == 'incoherent_inelastic': + return openmc.data.IncoherentInelasticAE.from_hdf5(group) @staticmethod def from_ace(ace, location_dist, location_start, rx=None): diff --git a/openmc/data/function.py b/openmc/data/function.py index 99ee20900a..9175e5e3bf 100644 --- a/openmc/data/function.py +++ b/openmc/data/function.py @@ -591,8 +591,8 @@ class Regions1D(EqualityMixin): Functions which are to be combined in a piecewise fashion breakpoints : Iterable of float The values of the dependent variable that define the domain of - each function. The `i`th and `(i+1)`th values are the limits of the - domain of the `i`th function. Values must be monotonically increasing. + each function. The `i`\ th and `(i+1)`\ th values are the limits of the + domain of the `i`\ th function. Values must be monotonically increasing. Attributes ---------- diff --git a/openmc/data/thermal.py b/openmc/data/thermal.py index cacc3478c5..5ec9b83659 100644 --- a/openmc/data/thermal.py +++ b/openmc/data/thermal.py @@ -24,7 +24,7 @@ from .njoy import make_ace_thermal from .thermal_angle_energy import (CoherentElasticAE, IncoherentElasticAE, IncoherentElasticAEDiscrete, IncoherentInelasticAEDiscrete, - IncoherentInelasticAEContinuous) + IncoherentInelasticAE) _THERMAL_NAMES = { @@ -247,26 +247,26 @@ class IncoherentElastic(Function1D): Parameters ---------- - xs : float + bound_xs : float Characteristic bound cross section in [b] debye_waller : float Debye-Waller integral in [eV\ :math:`^{-1}`] Attributes ---------- - xs : float + bound_xs : float Characteristic bound cross section in [b] debye_waller : float Debye-Waller integral in [eV\ :math:`^{-1}`] """ - def __init__(self, xs, debye_waller): - self.xs = xs + def __init__(self, bound_xs, debye_waller): + self.bound_xs = bound_xs self.debye_waller = debye_waller def __call__(self, E): W = self.debye_waller - return self.xs / 2.0 * (1 - np.exp(-4*E*W)) / (2*E*W) + return self.bound_xs / 2.0 * (1 - np.exp(-4*E*W)) / (2*E*W) def to_hdf5(self, group, name): """Write incoherent elastic scattering to an HDF5 group @@ -279,14 +279,27 @@ class IncoherentElastic(Function1D): Name of the dataset to create """ - dataset = group.create_dataset(name) + data = np.array([self.bound_xs, self.debye_waller]) + dataset = group.create_dataset(name, data=data) dataset.attrs['type'] = np.string_(type(self).__name__) - dataset.attrs['debye_waller'] = self.debye_waller - dataset.attrs['bound_xs'] = self.xs @classmethod def from_hdf5(cls, dataset): - return cls(dataset.attrs['xs'], dataset.attrs['debye_waller']) + """Read incoherent elastic scattering from an HDF5 dataset + + Parameters + ---------- + dataset : h5py.Dataset + HDF5 dataset to read from + + Returns + ------- + openmc.data.IncoherentElastic + Incoherent elastic scattering cross section + + """ + bound_xs, debye_waller = dataset[()] + return cls(bound_xs, debye_waller) class ThermalScatteringReaction(EqualityMixin): @@ -676,7 +689,7 @@ class ThermalScattering(EqualityMixin): breakpoints = [n_energy] interpolation = [2] energy = inelastic_xs.x - distribution = IncoherentInelasticAEContinuous( + distribution = IncoherentInelasticAE( breakpoints, interpolation, energy, energy_out, mu_out) table = cls(name, ace.atomic_weight_ratio, energy_max, kTs) diff --git a/openmc/data/thermal_angle_energy.py b/openmc/data/thermal_angle_energy.py index d6053ed2a4..3537b91fa4 100644 --- a/openmc/data/thermal_angle_energy.py +++ b/openmc/data/thermal_angle_energy.py @@ -106,7 +106,7 @@ class IncoherentInelasticAEDiscrete(AngleEnergy): mu_out : numpy.ndarray Discrete angles for each incoming/outgoing energy skewed : bool - Whether distance angles are equi-probable or have a skewed distribution + Whether discrete angles are equi-probable or have a skewed distribution Attributes ---------- @@ -115,7 +115,7 @@ class IncoherentInelasticAEDiscrete(AngleEnergy): mu_out : numpy.ndarray Discrete angles for each incoming/outgoing energy skewed : bool - Whether distance angles are equi-probable or have a skewed distribution + Whether discrete angles are equi-probable or have a skewed distribution """ def __init__(self, energy_out, mu_out, skewed=False): @@ -137,5 +137,5 @@ class IncoherentInelasticAEDiscrete(AngleEnergy): return cls(energy_out, mu_out, skewed) -class IncoherentInelasticAEContinuous(CorrelatedAngleEnergy): +class IncoherentInelasticAE(CorrelatedAngleEnergy): _name = 'incoherent_inelastic' diff --git a/src/endf.cpp b/src/endf.cpp index 23512c4dbf..f01a643113 100644 --- a/src/endf.cpp +++ b/src/endf.cpp @@ -1,6 +1,7 @@ #include "openmc/endf.h" #include // for copy +#include #include // for log, exp #include // for back_inserter #include // for runtime_error @@ -244,8 +245,10 @@ double CoherentElasticXS::operator()(double E) const IncoherentElasticXS::IncoherentElasticXS(hid_t dset) { - read_attribute(dset, "bound_xs", bound_xs_); - read_attribute(dset, "debye_waller", debye_waller_); + std::array tmp; + read_dataset(dset, nullptr, tmp); + bound_xs_ = tmp[0]; + debye_waller_ = tmp[1]; } double IncoherentElasticXS::operator()(double E) const