-
Notifications
You must be signed in to change notification settings - Fork 598
Refactor ParticleType to use PDG Monte Carlo numbering scheme #3756
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
Open
paulromano
wants to merge
28
commits into
openmc-dev:develop
Choose a base branch
from
paulromano:particle-type-pdg
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,404
−561
Conversation
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
Contributor
|
Nice feature |
GuySten
approved these changes
Jan 29, 2026
Contributor
GuySten
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Contributor
Author
|
Thanks for reviewing @GuySten. I'd like to get a review from @amandalund before we merge. |
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