-
Notifications
You must be signed in to change notification settings - Fork 599
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
Conversation
|
Nice feature |
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.
|
Thanks for reviewing @GuySten. I'd like to get a review from @amandalund before we merge. |
amandalund
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.
Nice improvement @paulromano, this looks good to me!
Co-authored-by: Amanda Lund <alund1187@gmail.com>
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