Skip to content

Conversation

@paulromano
Copy link
Contributor

Description

Overview and Motivation

This PR refactors both the C++ and Python ParticleType implementations 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 to ParticleType or associated logic throughout the codebase.

Previously, ParticleType was 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:

  • Elementary particles (e.g., neutron = 2112, photon = 22)
  • Nuclear codes in 100ZZZAAAM format (e.g., He4 = 1000020040, U235 = 1000922350)

Code changes

On the C++ side, this changes ParticleType to be a class with a single int32_t data 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 writing ParticleType::neutron it is now ParticleType::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, ParticleType changes 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

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

@makeclean
Copy link
Contributor

Nice feature

Copy link
Contributor

@GuySten GuySten left a 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.

@GuySten GuySten added the Merging Soon PR will be merged in < 24 hrs if no further comments are made. label Jan 30, 2026
@paulromano
Copy link
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

Labels

Merging Soon PR will be merged in < 24 hrs if no further comments are made.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants