Skip to content

Avoid writing subnormal nuclide densities to XML - #3144

Merged
pshriwise merged 1 commit into
openmc-dev:developfrom
paulromano:avoid-subnormal
Oct 10, 2024
Merged

pshriwise merged 1 commit into
openmc-dev:developfrom
paulromano:avoid-subnormal

Conversation

@paulromano

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@pshriwise pshriwise left a comment

Copy link
Copy Markdown
Contributor

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
@paulromano
paulromano deleted the avoid-subnormal branch October 10, 2024 18:40
apingegno pushed a commit to apingegno/openmc that referenced this pull request May 7, 2026
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