Skip to content

Refactor ParticleType to use PDG Monte Carlo numbering scheme - #3756

Merged
paulromano merged 29 commits into
openmc-dev:developfrom
paulromano:particle-type-pdg
Feb 3, 2026
Merged

paulromano merged 29 commits into
openmc-dev:developfrom
paulromano:particle-type-pdg

Conversation

@paulromano

Copy link
Copy Markdown
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
Copy Markdown
Contributor

Nice feature

@GuySten GuySten left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Comment thread openmc/weight_windows.py Outdated
@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
Copy Markdown
Contributor Author

Thanks for reviewing @GuySten. I'd like to get a review from @amandalund before we merge.

@amandalund amandalund left a comment

Copy link
Copy Markdown
Contributor

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!

Comment thread include/openmc/particle_type.h Outdated
Comment thread openmc/particle_type.py
Co-authored-by: Amanda Lund <alund1187@gmail.com>
@paulromano
paulromano enabled auto-merge (squash) February 3, 2026 03:50
@paulromano
paulromano merged commit b41e22f into openmc-dev:develop Feb 3, 2026
16 checks passed
@paulromano
paulromano deleted the particle-type-pdg branch February 3, 2026 15:56
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>
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.

4 participants