Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure skewed dataset is cast to bool properly #3001

Merged
merged 1 commit into from
Jun 12, 2024

Conversation

paulromano
Copy link
Contributor

Description

I ran into a bug loading a thermal scattering file from HDF5 recently. Namely, the skewed dataset for discrete incoherent inelastic angle-energy distribution is not read and converted to a bool properly. Right now, we're applying bool(...) on the dataset object itself, which is always true because it's not an empty object. We should be applying bool(...) on the value of the dataset. Below is a demonstration of the bug from a Python prompt (pay attention to the last two lines with bool). Note that when passing iwt=1 when generating the data, skewed should be false:

In [3]: lch4 = openmc.data.ThermalScattering.from_njoy(
   ...:     '/opt/data/endf/endf-b-viii.0/neutrons/n-001_H_001.endf',
   ...:     '/opt/data/endf/endf-b-viii.0/thermal_scatt/tsl-l-CH4.endf',
   ...:     iwt=1, stdout=True)

 njoy 2016.68  30Sep22                                       05/14/24 12:42:03
 *****************************************************************************

 reconr...                                                                0.0s

 broadr...                                                                0.0s

 thermr...                                                                0.1s

 wrote thermal data for temp = 1.0000E+02                                 2.5s

 thermr...                                                                2.5s

 ***warning***maximum value of beta limits the allowed energy transfer
 the sct approx. will be used for transfers larger than  1.389 ev.

 wrote thermal data for temp = 1.0000E+02                                13.8s

 acer...                                                                 13.8s
                                                                         14.3s
 *****************************************************************************

In [4]: lch4.export_to_hdf5('lch4_iwt1.h5')

In [5]: f = h5py.File('lch4_iwt1.h5', 'r')

In [6]: skewed_dataset = f['c_H_in_CH4_liquid/100K/inelastic/distribution/skewed']

In [7]: bool(skewed_dataset)
Out[7]: True

In [8]: bool(skewed_dataset[()])
Out[8]: False

Unfortunately we don't have any thermal scattering data in our test cross section set that triggers this problem and I'm hesitant to add another test that runs NJOY because of the time required, so for now I haven't added a test.

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 15) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

@paulromano paulromano added this to the v0.15.0 milestone Jun 11, 2024
Copy link
Contributor

@eepeterson eepeterson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch @paulromano!

@eepeterson eepeterson merged commit 1f32804 into openmc-dev:develop Jun 12, 2024
18 checks passed
@paulromano paulromano deleted the thermal-skew-fix branch June 12, 2024 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants