Repository navigation
Refactor ParticleType to use PDG Monte Carlo numbering scheme - #3756
Merged
Merged
Conversation
paulromano
requested review from
amandalund,
ebknudsen,
nelsonag and
pshriwise
as code owners
January 29, 2026 04:56
Contributor
|
Nice feature |
Contributor
Author
|
Thanks for reviewing @GuySten. I'd like to get a review from @amandalund before we merge. |
amandalund
approved these changes
Feb 2, 2026
amandalund
left a comment
Contributor
There was a problem hiding this comment.
Nice improvement @paulromano, this looks good to me!
Co-authored-by: Amanda Lund <alund1187@gmail.com>
paulromano
enabled auto-merge (squash)
February 3, 2026 03:50
jon-proximafusion
pushed a commit
to shimwell/openmc
that referenced
this pull request
Apr 13, 2026
…-dev#3756) Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com> Co-authored-by: Amanda Lund <alund1187@gmail.com>
apingegno
pushed a commit
to apingegno/openmc
that referenced
this pull request
May 7, 2026
…-dev#3756) Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com> Co-authored-by: Amanda Lund <alund1187@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
Overview and Motivation
This PR refactors both the C++ and Python
ParticleTypeimplementations to use the Particle Data Group (PDG) Monte Carlo numbering scheme as the canonical representation of particle types. This allows OpenMC to refer to any particle type without requiring code changes toParticleTypeor associated logic throughout the codebase.Previously,
ParticleTypewas an enum class (C++) / IntEnum (Python) with a fixed set of particle types (neutron, photon, electron, positron). This approach required updating the enum and all related switch statements whenever support for a new particle type was added. The PDG numbering scheme naturally accommodates:Code changes
On the C++ side, this changes
ParticleTypeto be a class with a singleint32_tdata member storing the PDG number with constructors from int, string, or (Z, A, m). It has query methods (e.g.,is_neutron()), and factory methods (e.g.,photon()). Note that the factory methods represent a breaking change, i.e., instead of writingParticleType::neutronit is nowParticleType::neutron(). There were several places in our file formats where we were storing the particle as an integer from 0-3; in these cases we are now storing the PDG number, which required bumping the file versions.On the Python side,
ParticleTypechanges from an IntEnum to a normal class with flexible__init__(accepts str/int/ParticleType). The associated class constants are unchanged (ParticleType.NEUTRON, etc.).Note: Although the PR touches a lot of files, most of the changes are pretty trivial.
Checklist