Fix extremely large yields from Bremsstrahlung - #3386
Merged
paulromano merged 2 commits intoMay 3, 2025
Conversation
Contributor
Author
|
Not sure why the tests failed to build. That doesn't appear related to my change though. |
Contributor
|
Thanks @HunterBelanger. I just submitted a separate PR #3388 that should fix that build error in CI that you're seeing. |
paulromano
approved these changes
May 2, 2025
paulromano
enabled auto-merge (squash)
May 3, 2025 01:45
apingegno
pushed a commit
to apingegno/openmc
that referenced
this pull request
May 7, 2026
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
My work on #2919 has been delayed for quite a while, because I noticed that when using photon transport on Windows, the memory would increase without bound. I am not super well versed with debugging tools on Windows, but was finally able to find the time to learn a bit about it, and find the error.
It turns out that the number of secondary photons being produced from Bremsstrahlung could occasionally be on the order of 10^8, very quickly leaking to a bad_alloc. The reason for this was the
yieldarray was being initialized withxt::empty, which does not initialize the values, and on Windows, this means you get an array with random bits in it. When setting the yields for each energy, the loop that begins at line 772 skips the first energy. Therefore, if that first entry was initialized with a random yield of 10^8 for example, we could produce that many secondaries at some collisions. My fix was simply to initialize the yields array withxt::zeros, so that it starts at a physically valid value, and is then translated correctly at the end of the function to -500, facilitating log-log interpolation. Making this change allowed photon transport calculations to actually run on Windows without memory problems.I do not believe that this was posing real problems on Linux systems, as I think GCC and Clang ensure new allocations are zeroed out first.
Checklist