Skip to content

Fix extremely large yields from Bremsstrahlung - #3386

Merged
paulromano merged 2 commits into
openmc-dev:developfrom
HunterBelanger:fix/bremsstrahlung_init
May 3, 2025
Merged

Fix extremely large yields from Bremsstrahlung#3386
paulromano merged 2 commits into
openmc-dev:developfrom
HunterBelanger:fix/bremsstrahlung_init

Conversation

@HunterBelanger

Copy link
Copy Markdown
Contributor

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 yield array was being initialized with xt::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 with xt::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

  • 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)

@HunterBelanger

Copy link
Copy Markdown
Contributor Author

Not sure why the tests failed to build. That doesn't appear related to my change though.

@paulromano

Copy link
Copy Markdown
Contributor

Thanks @HunterBelanger. I just submitted a separate PR #3388 that should fix that build error in CI that you're seeing.

@paulromano
paulromano enabled auto-merge (squash) May 3, 2025 01:45
@paulromano
paulromano merged commit a921280 into openmc-dev:develop May 3, 2025
@HunterBelanger
HunterBelanger deleted the fix/bremsstrahlung_init branch May 5, 2025 16:29
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>
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.

2 participants