• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmc-dev / openmc / 22007957997

14 Feb 2026 12:50AM UTC coverage: 81.717% (-0.05%) from 81.763%
22007957997

Pull #3765

github

web-flow
Merge 6111ffe2e into 19c0aafdc
Pull Request #3765: Store atomic mass in ParticleType.

17526 of 24626 branches covered (71.17%)

Branch coverage included in aggregate %.

6 of 7 new or added lines in 2 files covered. (85.71%)

1820 existing lines in 34 files now uncovered.

56937 of 66497 relevant lines covered (85.62%)

44324210.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.0
/include/openmc/particle_type.h
1
//==============================================================================
2
// ParticleType class definition
3
//==============================================================================
4

5
#ifndef OPENMC_PARTICLE_TYPE_H
6
#define OPENMC_PARTICLE_TYPE_H
7

8
#include <cstddef>
9
#include <cstdint>
10
#include <string>
11
#include <string_view>
12
#include <type_traits>
13

14
#include "openmc/constants.h"
15
#include "openmc/error.h"
16

17
namespace openmc {
18

19
//------------------------------------------------------------------------------
20
// PDG constants (canonical particle identity as simple integers)
21
//------------------------------------------------------------------------------
22

23
inline constexpr int32_t PDG_NEUTRON = 2112;
24
inline constexpr int32_t PDG_PHOTON = 22;
25
inline constexpr int32_t PDG_ELECTRON = 11;
26
inline constexpr int32_t PDG_POSITRON = -11;
27
inline constexpr int32_t PDG_PROTON = 2212;
28
inline constexpr int32_t PDG_DEUTERON = 1000010020;
29
inline constexpr int32_t PDG_TRITON = 1000010030;
30
inline constexpr int32_t PDG_ALPHA = 1000020040;
31

32
//------------------------------------------------------------------------------
33
// ParticleType class (standard-layout, trivially copyable)
34
//------------------------------------------------------------------------------
35

36
class ParticleType {
37
public:
38
  //----------------------------------------------------------------------------
39
  // Constructors
40

41
  // Default constructor: defaults to neutron
42
  constexpr ParticleType() : pdg_number_(PDG_NEUTRON) {}
798,454,661✔
43

44
  // Constructor from PDG number
45
  constexpr explicit ParticleType(int32_t pdg_number) : pdg_number_(pdg_number)
2,147,483,647✔
46
  {}
2,147,483,647✔
47

48
  // Constructor from particle name string (e.g., "neutron", "photon", "Fe56")
49
  explicit ParticleType(std::string_view str);
50

51
  // Constructor from Z, A, and metastable state for nuclear particles
52
  constexpr ParticleType(int Z, int A, int m = 0)
53
    : pdg_number_(1000000000 + Z * 10000 + A * 10 + m)
54
  {}
55

56
  //----------------------------------------------------------------------------
57
  // Accessors
58

59
  // Accessor for the underlying PDG number
60
  constexpr int32_t pdg_number() const { return pdg_number_; }
2,147,483,647✔
61

62
  //----------------------------------------------------------------------------
63
  // Methods
64

65
  // Get particle mass in [u]
66
  double mass() const
2,091,184,171✔
67
  {
68
    int32_t p = std::abs(pdg_number_);
2,091,184,171✔
69
    if (ATOMIC_MASS.count(p)) {
2,091,184,171!
70
      return ATOMIC_MASS[p];
2,091,184,171✔
71
    } else {
NEW
72
      fatal_error("Unknown mass for particle " + str());
×
73
    }
74
  }
75

76
  // Convert to string representation
77
  std::string str() const;
78

79
  // Check if this represents a nucleus (vs elementary particle)
80
  constexpr bool is_nucleus() const
×
81
  {
82
    // PDG nuclear codes are >= 1000000000 (100ZZZAAAI format)
83
    return pdg_number_ >= 1000000000;
×
84
  }
85

86
  // Get transport index (0-3 for transportable particles, C_NONE otherwise)
87
  constexpr int transport_index() const;
88

89
  // Check if this is a neutron
90
  constexpr bool is_neutron() const { return pdg_number_ == PDG_NEUTRON; }
2,147,483,647✔
91

92
  // Check if this is a photon
93
  constexpr bool is_photon() const { return pdg_number_ == PDG_PHOTON; }
219,893,813✔
94

95
  constexpr bool is_transportable() const
238,052✔
96
  {
97
    return this->transport_index() != C_NONE;
238,052✔
98
  }
99

100
  //----------------------------------------------------------------------------
101
  // Static factory methods
102

103
  static constexpr ParticleType neutron() { return ParticleType {PDG_NEUTRON}; }
128,905,999✔
104
  static constexpr ParticleType photon() { return ParticleType {PDG_PHOTON}; }
53,236,626✔
105
  static constexpr ParticleType electron()
2,147,483,647✔
106
  {
107
    return ParticleType {PDG_ELECTRON};
2,147,483,647✔
108
  }
109
  static constexpr ParticleType positron()
2,147,483,647✔
110
  {
111
    return ParticleType {PDG_POSITRON};
2,147,483,647✔
112
  }
113
  static constexpr ParticleType proton() { return ParticleType {PDG_PROTON}; }
114
  static constexpr ParticleType deuteron()
115
  {
116
    return ParticleType {PDG_DEUTERON};
117
  }
118
  static constexpr ParticleType triton() { return ParticleType {PDG_TRITON}; }
119
  static constexpr ParticleType alpha() { return ParticleType {PDG_ALPHA}; }
120

121
private:
122
  int32_t pdg_number_;
123
};
124

125
//------------------------------------------------------------------------------
126
// Static assertions to ensure standard-layout and trivially copyable
127
//------------------------------------------------------------------------------
128

129
static_assert(std::is_standard_layout_v<ParticleType>,
130
  "ParticleType must be standard-layout");
131
static_assert(std::is_trivially_copyable_v<ParticleType>,
132
  "ParticleType must be trivially copyable");
133
static_assert(sizeof(ParticleType) == sizeof(int32_t),
134
  "ParticleType must be same size as int32_t");
135

136
//------------------------------------------------------------------------------
137
// Comparison operators (free functions for symmetry)
138
//------------------------------------------------------------------------------
139

140
constexpr bool operator==(ParticleType lhs, ParticleType rhs)
2,147,483,647✔
141
{
142
  return lhs.pdg_number() == rhs.pdg_number();
2,147,483,647✔
143
}
144

145
constexpr bool operator!=(ParticleType lhs, ParticleType rhs)
62,954,773✔
146
{
147
  return lhs.pdg_number() != rhs.pdg_number();
62,954,773✔
148
}
149

150
constexpr bool operator<(ParticleType lhs, ParticleType rhs)
151
{
152
  return lhs.pdg_number() < rhs.pdg_number();
153
}
154

155
//------------------------------------------------------------------------------
156
// ParticleType member function implementations (inline)
157
//------------------------------------------------------------------------------
158

159
constexpr int ParticleType::transport_index() const
2,147,483,647✔
160
{
161
  switch (pdg_number_) {
2,147,483,647!
162
  case PDG_NEUTRON:
2,147,483,647✔
163
    return 0;
2,147,483,647✔
164
  case PDG_PHOTON:
89,777,774✔
165
    return 1;
89,777,774✔
166
  case PDG_ELECTRON:
146,787,980✔
167
    return 2;
146,787,980✔
168
  case PDG_POSITRON:
239,046✔
169
    return 3;
239,046✔
170
  default:
×
171
    return C_NONE;
×
172
  }
173
}
174

175
//------------------------------------------------------------------------------
176
// Legacy conversion helpers
177
//------------------------------------------------------------------------------
178

179
// Legacy enum code (0..3) to ParticleType conversion
180
ParticleType legacy_particle_index_to_type(int code);
181

182
} // namespace openmc
183

184
#endif // OPENMC_PARTICLE_TYPE_H
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc