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

Avoid writing subnormal nuclide densities to XML #3144

Merged
merged 1 commit into from
Oct 10, 2024

Conversation

paulromano
Copy link
Contributor

Description

Sometimes depleting a model can result in extremely low nuclide densities that are represented as subnormal floating point values. If these end up getting written to XML, OpenMC crashes trying to read them in because std::stod will throw an exception on a subnormal float. This PR fixes this by explicitly converting subnormal values to zero when exporting XML.

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)

@shimwell
Copy link
Member

This looks good to me and solves the issue.

Slightly related question, why do we write out these zero value nuclides at all. Would another approach be to not write out a nuclide if the value is zero. Are we reading in h5 cross sections that are not needed?

@paulromano
Copy link
Contributor Author

@shimwell That's a very good point. Perhaps this is something we should intercept at the time add_nuclide is called. That is, if you call mat.add_nuclide(nuc, num) and num is either 0 or a subnormal, you'll get a warning and the nuclide won't get added. In any case, I propose we handle that as a separate PR.

@pshriwise
Copy link
Contributor

Would removal of these up front in add_nuclide potentially mess with depletion composition expectations (even if the composition components are neglibigle). I'm thinking of generating Material objects from depletion results as an example. I wonder if it might instead be better to catch this at the time we write the XML and display a single warning then?

@paulromano
Copy link
Contributor Author

@pshriwise yeah, there are possibly situations where it could cause weirdness, so I'd like us to think through them more (and as part of a separate issue/PR). The change here is strictly to ensure that OpenMC doesn't crash but otherwise doesn't meaningfully change current behavior.

@paulromano paulromano requested a review from shimwell October 4, 2024 18:42
Copy link
Contributor

@pshriwise pshriwise left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @paulromano

@pshriwise pshriwise merged commit b4a796e into openmc-dev:develop Oct 10, 2024
16 checks passed
@paulromano paulromano deleted the avoid-subnormal branch October 10, 2024 18:40
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.

3 participants