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

openmc-dev / openmc / 18542382223

15 Oct 2025 08:54PM UTC coverage: 81.921% (-3.3%) from 85.204%
18542382223

Pull #3404

github

web-flow
Merge 578501b17 into e9077b137
Pull Request #3404: Ability to source electron/positrons directly

16594 of 23101 branches covered (71.83%)

Branch coverage included in aggregate %.

16 of 19 new or added lines in 4 files covered. (84.21%)

2215 existing lines in 79 files now uncovered.

53716 of 62726 relevant lines covered (85.64%)

43526789.79 hits per line

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

98.99
/include/openmc/particle_data.h
1
#ifndef OPENMC_PARTICLE_DATA_H
2
#define OPENMC_PARTICLE_DATA_H
3

4
#include "openmc/array.h"
5
#include "openmc/constants.h"
6
#include "openmc/position.h"
7
#include "openmc/random_lcg.h"
8
#include "openmc/tallies/filter_match.h"
9
#include "openmc/vector.h"
10

11
#ifdef OPENMC_DAGMC_ENABLED
12
#include "DagMC.hpp"
13
#endif
14

15
namespace openmc {
16

17
//==============================================================================
18
// Constants
19
//==============================================================================
20

21
// Since cross section libraries come with different numbers of delayed groups
22
// (e.g. ENDF/B-VII.1 has 6 and JEFF 3.1.1 has 8 delayed groups) and we don't
23
// yet know what cross section library is being used when the tallies.xml file
24
// is read in, we want to have an upper bound on the size of the array we
25
// use to store the bins for delayed group tallies.
26
constexpr int MAX_DELAYED_GROUPS {8};
27

28
constexpr double CACHE_INVALID {-1.0};
29

30
//==========================================================================
31
// Aliases and type definitions
32

33
//! Particle types
34
enum class ParticleType { neutron, photon, electron, positron };
35

36
//! Saved ("banked") state of a particle
37
//! NOTE: This structure's MPI type is built in initialize_mpi() of
38
//! initialize.cpp. Any changes made to the struct here must also be
39
//! made when building the Bank MPI type in initialize_mpi().
40
//! NOTE: This structure is also used on the python side, and is defined
41
//! in lib/core.py. Changes made to the type here must also be made to the
42
//! python defintion.
43
struct SourceSite {
44
  Position r;
45
  Direction u;
46
  double E;
47
  double time {0.0};
48
  double wgt {1.0};
49
  int delayed_group {0};
50
  int surf_id {SURFACE_NONE};
51
  ParticleType particle;
52

53
  // Extra attributes that don't show up in source written to file
54
  int parent_nuclide {-1};
55
  int64_t parent_id;
56
  int64_t progeny_id;
57
};
58

59
//! State of a particle used for particle track files
60
struct TrackState {
61
  Position r;           //!< Position in [cm]
62
  Direction u;          //!< Direction
63
  double E;             //!< Energy in [eV]
64
  double time {0.0};    //!< Time in [s]
65
  double wgt {1.0};     //!< Weight
66
  int cell_id;          //!< Cell ID
67
  int cell_instance;    //!< Cell instance
68
  int material_id {-1}; //!< Material ID (default value indicates void)
69
};
70

71
//! Full history of a single particle's track states
72
struct TrackStateHistory {
73
  ParticleType particle;
74
  std::vector<TrackState> states;
75
};
76

77
//! Saved ("banked") state of a particle, for nu-fission tallying
78
struct NuBank {
79
  double E;          //!< particle energy
80
  double wgt;        //!< particle weight
81
  int delayed_group; //!< particle delayed group
82
};
83

84
class LocalCoord {
85
public:
86
  void rotate(const vector<double>& rotation);
87

88
  //! clear data from a single coordinate level
89
  void reset();
90

91
  // accessors
92
  Position& r() { return r_; }
2,147,483,647✔
93
  const Position& r() const { return r_; }
2,147,483,647✔
94

95
  Direction& u() { return u_; }
2,147,483,647✔
96
  const Direction& u() const { return u_; }
2,147,483,647✔
97

98
  int& cell() { return cell_; }
2,147,483,647✔
99
  const int& cell() const { return cell_; }
2,147,483,647✔
100

101
  int& universe() { return universe_; }
2,147,483,647✔
102
  const int& universe() const { return universe_; }
9,540,949✔
103

104
  int& lattice() { return lattice_; }
839,791,626✔
105
  int lattice() const { return lattice_; }
2,147,483,647✔
106

107
  array<int, 3>& lattice_index() { return lattice_index_; }
2,147,483,647✔
108
  const array<int, 3>& lattice_index() const { return lattice_index_; }
2,147,483,647✔
109

110
  bool& rotated() { return rotated_; }
120,554,108✔
111
  const bool& rotated() const { return rotated_; }
87,088,593✔
112

113
private:
114
  // Data members
115
  Position r_;  //!< particle position
116
  Direction u_; //!< particle direction
117
  int cell_ {-1};
118
  int universe_ {-1};
119
  int lattice_ {-1};
120
  array<int, 3> lattice_index_ {{-1, -1, -1}};
121
  bool rotated_ {false}; //!< Is the level rotated?
122
};
123

124
//==============================================================================
125
//! Cached microscopic cross sections for a particular nuclide at the current
126
//! energy
127
//==============================================================================
128

129
struct NuclideMicroXS {
130
  // Microscopic cross sections in barns
131
  double total;      //!< total cross section
132
  double absorption; //!< absorption (disappearance)
133
  double fission;    //!< fission
134
  double nu_fission; //!< neutron production from fission
135

136
  double elastic;         //!< If sab_frac is not 1 or 0, then this value is
137
                          //!<   averaged over bound and non-bound nuclei
138
  double thermal;         //!< Bound thermal elastic & inelastic scattering
139
  double thermal_elastic; //!< Bound thermal elastic scattering
140
  double photon_prod;     //!< microscopic photon production xs
141

142
  // Cross sections for depletion reactions (note that these are not stored in
143
  // macroscopic cache)
144
  double reaction[DEPLETION_RX.size()];
145

146
  // Indicies and factors needed to compute cross sections from the data tables
147
  int index_grid;       //!< Index on nuclide energy grid
148
  int index_temp;       //!< Temperature index for nuclide
149
  double interp_factor; //!< Interpolation factor on nuc. energy grid
150
  int index_sab {-1};   //!< Index in sab_tables
151
  int index_temp_sab;   //!< Temperature index for sab_tables
152
  double sab_frac;      //!< Fraction of atoms affected by S(a,b)
153
  bool use_ptable;      //!< In URR range with probability tables?
154

155
  // Energy and temperature last used to evaluate these cross sections.  If
156
  // these values have changed, then the cross sections must be re-evaluated.
157
  double last_E {0.0};       //!< Last evaluated energy
158
  double last_sqrtkT {0.0};  //!< Last temperature in sqrt(Boltzmann constant
159
                             //!< * temperature (eV))
160
  double ncrystal_xs {-1.0}; //!< NCrystal cross section
161
};
162

163
//==============================================================================
164
//! Cached microscopic photon cross sections for a particular element at the
165
//! current energy
166
//==============================================================================
167

168
struct ElementMicroXS {
169
  int index_grid;         //!< index on element energy grid
170
  double last_E {0.0};    //!< last evaluated energy in [eV]
171
  double interp_factor;   //!< interpolation factor on energy grid
172
  double total;           //!< microscopic total photon xs
173
  double coherent;        //!< microscopic coherent xs
174
  double incoherent;      //!< microscopic incoherent xs
175
  double photoelectric;   //!< microscopic photoelectric xs
176
  double pair_production; //!< microscopic pair production xs
177
};
178

179
//==============================================================================
180
// MacroXS contains cached macroscopic cross sections for the material a
181
// particle is traveling through
182
//==============================================================================
183

184
struct MacroXS {
185
  double total;       //!< macroscopic total xs
186
  double absorption;  //!< macroscopic absorption xs
187
  double fission;     //!< macroscopic fission xs
188
  double nu_fission;  //!< macroscopic production xs
189
  double photon_prod; //!< macroscopic photon production xs
190

191
  // Photon cross sections
192
  double coherent;        //!< macroscopic coherent xs
193
  double incoherent;      //!< macroscopic incoherent xs
194
  double photoelectric;   //!< macroscopic photoelectric xs
195
  double pair_production; //!< macroscopic pair production xs
196
};
197

198
//==============================================================================
199
// Cache contains the cached data for an MGXS object
200
//==============================================================================
201

202
struct CacheDataMG {
203
  int material {-1}; //!< material index
204
  double sqrtkT;     //!< last temperature corresponding to t
205
  int t {0};         //!< temperature index
206
  int a {0};         //!< angle index
207
  Direction u;       //!< angle that corresponds to a
208
};
209

210
//==============================================================================
211
// Information about nearest boundary crossing
212
//==============================================================================
213

214
class BoundaryInfo {
215
public:
216
  void reset()
15,616,590✔
217
  {
218
    distance_ = INFINITY;
15,616,590✔
219
    surface_ = SURFACE_NONE;
15,616,590✔
220
    coord_level_ = 0;
15,616,590✔
221
    lattice_translation_ = {0, 0, 0};
15,616,590✔
222
  }
15,616,590✔
223
  double& distance() { return distance_; }
2,147,483,647✔
224
  const double& distance() const { return distance_; }
225

226
  int& surface() { return surface_; }
2,147,483,647✔
227
  const int& surface() const { return surface_; }
2,359,148✔
228

229
  int coord_level() const { return coord_level_; }
230
  int& coord_level() { return coord_level_; }
2,147,483,647✔
231

232
  array<int, 3>& lattice_translation() { return lattice_translation_; }
2,147,483,647✔
233
  const array<int, 3>& lattice_translation() const
2,054,367,672✔
234
  {
235
    return lattice_translation_;
2,054,367,672✔
236
  }
237

238
  // TODO: off-by-one
239
  int surface_index() const { return std::abs(surface()) - 1; }
2,359,148✔
240

241
private:
242
  // Data members
243
  double distance_ {INFINITY}; //!< distance to nearest boundary
244
  int surface_ {
245
    SURFACE_NONE};      //!< surface token, non-zero if boundary is surface
246
  int coord_level_ {0}; //!< coordinate level after crossing boundary
247
  array<int, 3> lattice_translation_ {
248
    0, 0, 0}; //!< which way lattice indices will change
249
};
250

251
/*
252
 * Contains all geometry state information for a particle.
253
 */
254
class GeometryState {
255
public:
256
  GeometryState();
257

258
  /*
259
   * GeometryState does not store any ID info, so give some reasonable behavior
260
   * here. The Particle class redefines this. This is only here for the error
261
   * reporting behavior that occurs in geometry.cpp. The explanation for
262
   * mark_as_lost is the same.
263
   */
264
  virtual void mark_as_lost(const char* message);
265
  void mark_as_lost(const std::string& message);
266
  void mark_as_lost(const std::stringstream& message);
267

268
  // resets all coordinate levels for the particle
269
  void clear()
429,305,909✔
270
  {
271
    for (auto& level : coord_) {
913,197,914✔
272
      level.reset();
483,892,005✔
273
    }
274
    n_coord_ = 1;
429,305,909✔
275

276
    for (auto& cell : cell_last_) {
913,197,914✔
277
      cell = C_NONE;
483,892,005✔
278
    }
279
    n_coord_last_ = 1;
429,305,909✔
280
  }
429,305,909✔
281

282
  //! moves the particle by the specified distance to its next location
283
  //! \param distance the distance the particle is moved
284
  void move_distance(double distance);
285

286
  void advance_to_boundary_from_void();
287

288
  // Initialize all internal state from position and direction
289
  void init_from_r_u(Position r_a, Direction u_a)
3,520,000✔
290
  {
291
    clear();
3,520,000✔
292
    surface() = SURFACE_NONE;
3,520,000✔
293
    material() = C_NONE;
3,520,000✔
294
    r() = r_a;
3,520,000✔
295
    u() = u_a;
3,520,000✔
296
    r_last_current() = r_a;
3,520,000✔
297
    r_last() = r_a;
3,520,000✔
298
    u_last() = u_a;
3,520,000✔
299
  }
3,520,000✔
300

301
  // Unique ID. This is not geometric info, but the
302
  // error reporting in geometry.cpp requires this.
303
  // We could save this to implement it in Particle,
304
  // but that would require virtuals.
305
  int64_t& id() { return id_; }
600,693,100✔
306
  const int64_t& id() const { return id_; }
7,281✔
307

308
  // Number of current coordinate levels
309
  int& n_coord() { return n_coord_; }
2,147,483,647✔
310
  const int& n_coord() const { return n_coord_; }
354,972,121✔
311

312
  // Offset for distributed properties
313
  int& cell_instance() { return cell_instance_; }
2,147,483,647✔
314
  const int& cell_instance() const { return cell_instance_; }
823,556,199✔
315

316
  // Coordinates for all nesting levels
317
  LocalCoord& coord(int i) { return coord_[i]; }
2,147,483,647✔
318
  const LocalCoord& coord(int i) const { return coord_[i]; }
2,147,483,647✔
UNCOV
319
  const vector<LocalCoord>& coord() const { return coord_; }
×
320

321
  // Innermost universe nesting coordinates
322
  LocalCoord& lowest_coord() { return coord_[n_coord_ - 1]; }
2,147,483,647✔
323
  const LocalCoord& lowest_coord() const { return coord_[n_coord_ - 1]; }
823,556,325✔
324

325
  // Last coordinates on all nesting levels, before crossing a surface
326
  int& n_coord_last() { return n_coord_last_; }
2,147,483,647✔
327
  const int& n_coord_last() const { return n_coord_last_; }
81,210,811✔
328
  int& cell_last(int i) { return cell_last_[i]; }
2,147,483,647✔
329
  const int& cell_last(int i) const { return cell_last_[i]; }
43,755,558✔
330

331
  // Coordinates at birth
332
  Position& r_born() { return r_born_; }
227,814,772✔
333
  const Position& r_born() const { return r_born_; }
60,658,268✔
334

335
  // Coordinates of last collision or reflective/periodic surface
336
  // crossing for current tallies
337
  Position& r_last_current() { return r_last_current_; }
2,147,483,647✔
338
  const Position& r_last_current() const { return r_last_current_; }
132,032,075✔
339

340
  // Previous direction and spatial coordinates before a collision
341
  Position& r_last() { return r_last_; }
2,147,483,647✔
342
  const Position& r_last() const { return r_last_; }
480,152,990✔
343
  Position& u_last() { return u_last_; }
2,147,483,647✔
344
  const Position& u_last() const { return u_last_; }
28,714,213✔
345

346
  // Accessors for position in global coordinates
347
  Position& r() { return coord_[0].r(); }
2,147,483,647✔
348
  const Position& r() const { return coord_[0].r(); }
693,831,724✔
349

350
  // Accessors for position in local coordinates
351
  Position& r_local() { return coord_[n_coord_ - 1].r(); }
2,147,483,647✔
352
  const Position& r_local() const { return coord_[n_coord_ - 1].r(); }
353

354
  // Accessors for direction in global coordinates
355
  Direction& u() { return coord_[0].u(); }
2,147,483,647✔
356
  const Direction& u() const { return coord_[0].u(); }
2,147,483,647✔
357

358
  // Accessors for direction in local coordinates
359
  Direction& u_local() { return coord_[n_coord_ - 1].u(); }
2,147,483,647✔
360
  const Direction& u_local() const { return coord_[n_coord_ - 1].u(); }
361

362
  // Surface token for the surface that the particle is currently on
363
  int& surface() { return surface_; }
2,147,483,647✔
364
  const int& surface() const { return surface_; }
23,742,147✔
365

366
  // Surface index based on the current value of the surface_ attribute
367
  int surface_index() const
1,530,020,318✔
368
  {
369
    // TODO: off-by-one
370
    return std::abs(surface_) - 1;
1,530,020,318✔
371
  }
372

373
  // Boundary information
374
  BoundaryInfo& boundary() { return boundary_; }
2,147,483,647✔
375

376
#ifdef OPENMC_DAGMC_ENABLED
377
  // DagMC state variables
378
  moab::DagMC::RayHistory& history() { return history_; }
371,933,715✔
379
  Direction& last_dir() { return last_dir_; }
242,306✔
380
#endif
381

382
  // material of current and last cell
383
  int& material() { return material_; }
2,147,483,647✔
384
  const int& material() const { return material_; }
2,147,483,647✔
385
  int& material_last() { return material_last_; }
2,147,483,647✔
386
  const int& material_last() const { return material_last_; }
987,349✔
387

388
  // temperature of current and last cell
389
  double& sqrtkT() { return sqrtkT_; }
2,147,483,647✔
390
  const double& sqrtkT() const { return sqrtkT_; }
277,320✔
391
  double& sqrtkT_last() { return sqrtkT_last_; }
2,147,483,647✔
392

393
  // density multiplier of the current and last cell
394
  double& density_mult() { return density_mult_; }
2,147,483,647✔
395
  const double& density_mult() const { return density_mult_; }
12,282,600✔
396
  double& density_mult_last() { return density_mult_last_; }
2,147,483,647✔
397

398
private:
399
  int64_t id_ {-1}; //!< Unique ID
400

401
  int n_coord_ {1};          //!< number of current coordinate levels
402
  int cell_instance_;        //!< offset for distributed properties
403
  vector<LocalCoord> coord_; //!< coordinates for all levels
404

405
  int n_coord_last_ {1};  //!< number of current coordinates
406
  vector<int> cell_last_; //!< coordinates for all levels
407

408
  Position r_born_;         //!< coordinates at birth
409
  Position r_last_current_; //!< coordinates of the last collision or
410
                            //!< reflective/periodic surface crossing for
411
                            //!< current tallies
412
  Position r_last_;         //!< previous coordinates
413
  Direction u_last_;        //!< previous direction coordinates
414

415
  int surface_ {
416
    SURFACE_NONE}; //!< surface token for surface the particle is currently on
417

418
  BoundaryInfo boundary_; //!< Info about the next intersection
419

420
  int material_ {-1};      //!< index for current material
421
  int material_last_ {-1}; //!< index for last material
422

423
  double sqrtkT_ {-1.0};     //!< sqrt(k_Boltzmann * temperature) in eV
424
  double sqrtkT_last_ {0.0}; //!< last temperature
425

426
  double density_mult_ {1.0};      //!< density multiplier
427
  double density_mult_last_ {1.0}; //!< last density multiplier
428

429
#ifdef OPENMC_DAGMC_ENABLED
430
  moab::DagMC::RayHistory history_;
431
  Direction last_dir_;
432
#endif
433
};
434

435
//============================================================================
436
//! Defines how particle data is laid out in memory
437
//============================================================================
438

439
/*
440
 * This class was added in order to separate the layout and access of particle
441
 * data from particle physics operations during a development effort to get
442
 * OpenMC running on GPUs. In the event-based Monte Carlo method, one creates
443
 * an array of particles on which actions like cross section lookup and surface
444
 * crossing are done en masse, which works best on vector computers of yore and
445
 * modern GPUs. It has been shown in the below publication [1] that arranging
446
 * particle data into a structure of arrays rather than an array of structures
447
 * enhances performance on GPUs. For instance, rather than having an
448
 * std::vector<Particle> where consecutive particle energies would be separated
449
 * by about 400 bytes, one would create a structure which has a single
450
 * std::vector<double> of energies.  The motivation here is that more coalesced
451
 * memory accesses occur, in the parlance of GPU programming.
452
 *
453
 * So, this class enables switching between the array-of-structures and
454
 * structure- of-array data layout at compile time. In GPU branches of the
455
 * code, our Particle class inherits from a class that provides an array of
456
 * particle energies, and can access them using the E() method (defined below).
457
 * In the CPU code, we inherit from this class which gives the conventional
458
 * layout of particle data, useful for history-based tracking.
459
 *
460
 * As a result, we always use the E(), r_last(), etc. methods to access
461
 * particle data in order to keep a unified interface between
462
 * structure-of-array and array-of-structure code on either CPU or GPU code
463
 * while sharing the same physics code on each codebase.
464
 *
465
 * [1] Hamilton, Steven P., Stuart R. Slattery, and Thomas M. Evans.
466
 *   “Multigroup Monte Carlo on GPUs: Comparison of History- and Event-Based
467
 *   Algorithms.” Annals of Nuclear Energy 113 (March 2018): 506–18.
468
 *   https://doi.org/10.1016/j.anucene.2017.11.032.
469
 */
470
class ParticleData : public GeometryState {
471
private:
472
  //==========================================================================
473
  // Data members -- see public: below for descriptions
474

475
  vector<NuclideMicroXS> neutron_xs_;
476
  vector<ElementMicroXS> photon_xs_;
477
  MacroXS macro_xs_;
478
  CacheDataMG mg_xs_cache_;
479

480
  ParticleType type_ {ParticleType::neutron};
481

482
  double E_;
483
  double E_last_;
484
  int g_ {0};
485
  int g_last_;
486

487
  double wgt_ {1.0};
488
  double wgt_born_ {1.0};
489
  double wgt_ww_born_ {-1.0};
490
  double mu_;
491
  double time_ {0.0};
492
  double time_last_ {0.0};
493
  double wgt_last_ {1.0};
494

495
  bool fission_ {false};
496
  TallyEvent event_;
497
  int event_nuclide_;
498
  int event_mt_;
499
  int delayed_group_ {0};
500
  int parent_nuclide_ {-1};
501

502
  int n_bank_ {0};
503
  double bank_second_E_ {0.0};
504
  double wgt_bank_ {0.0};
505
  int n_delayed_bank_[MAX_DELAYED_GROUPS];
506

507
  int cell_born_ {-1};
508

509
  // Iterated Fission Probability
510
  double lifetime_ {0.0}; //!< neutron lifetime [s]
511

512
  int n_collision_ {0};
513

514
  bool write_track_ {false};
515

516
  uint64_t seeds_[N_STREAMS];
517
  int stream_;
518

519
  vector<SourceSite> secondary_bank_;
520

521
  int64_t current_work_;
522

523
  vector<double> flux_derivs_;
524

525
  vector<FilterMatch> filter_matches_;
526

527
  vector<TrackStateHistory> tracks_;
528

529
  vector<NuBank> nu_bank_;
530

531
  vector<double> pht_storage_;
532

533
  double keff_tally_absorption_ {0.0};
534
  double keff_tally_collision_ {0.0};
535
  double keff_tally_tracklength_ {0.0};
536
  double keff_tally_leakage_ {0.0};
537

538
  bool trace_ {false};
539

540
  double collision_distance_;
541

542
  int n_event_ {0};
543

544
  int n_split_ {0};
545
  double ww_factor_ {0.0};
546

547
  int64_t n_progeny_ {0};
548

549
public:
550
  //----------------------------------------------------------------------------
551
  // Constructors
552
  ParticleData();
553

554
  //==========================================================================
555
  // Methods and accessors
556

557
  // Cross section caches
558
  NuclideMicroXS& neutron_xs(int i)
2,147,483,647✔
559
  {
560
    return neutron_xs_[i];
2,147,483,647✔
561
  } // Microscopic neutron cross sections
562
  const NuclideMicroXS& neutron_xs(int i) const { return neutron_xs_[i]; }
439,412,505✔
563

564
  // Microscopic photon cross sections
565
  ElementMicroXS& photon_xs(int i) { return photon_xs_[i]; }
181,053,374✔
566

567
  // Macroscopic cross sections
UNCOV
568
  MacroXS& macro_xs() { return macro_xs_; }
×
569
  const MacroXS& macro_xs() const { return macro_xs_; }
1,190,332✔
570

571
  // Multigroup macroscopic cross sections
572
  CacheDataMG& mg_xs_cache() { return mg_xs_cache_; }
2,147,483,647✔
573
  const CacheDataMG& mg_xs_cache() const { return mg_xs_cache_; }
2,063,937,414✔
574

575
  // Particle type (n, p, e, gamma, etc)
576
  ParticleType& type() { return type_; }
2,147,483,647✔
577
  const ParticleType& type() const { return type_; }
2,147,483,647✔
578

579
  // Current particle energy, energy before collision,
580
  // and corresponding multigroup group indices. Energy
581
  // units are eV.
582
  double& E() { return E_; }
2,147,483,647✔
583
  const double& E() const { return E_; }
2,147,483,647✔
584
  double& E_last() { return E_last_; }
2,147,483,647✔
585
  const double& E_last() const { return E_last_; }
511,778,340✔
586
  int& g() { return g_; }
2,147,483,647✔
587
  const int& g() const { return g_; }
2,147,483,647✔
588
  int& g_last() { return g_last_; }
2,147,483,647✔
589
  const int& g_last() const { return g_last_; }
2,768,568✔
590

591
  // Statistic weight of particle. Setting to zero indicates that the particle
592
  // is dead.
593
  double& wgt() { return wgt_; }
2,147,483,647✔
594
  double wgt() const { return wgt_; }
17,506✔
595

596
  // Statistic weight of particle at birth
597
  double& wgt_born() { return wgt_born_; }
220,546,234✔
598
  double wgt_born() const { return wgt_born_; }
599

600
  // Weight window value at birth
601
  double& wgt_ww_born() { return wgt_ww_born_; }
293,307,608✔
602
  const double& wgt_ww_born() const { return wgt_ww_born_; }
603

604
  // Statistic weight of particle at last collision
605
  double& wgt_last() { return wgt_last_; }
2,147,483,647✔
606
  const double& wgt_last() const { return wgt_last_; }
22,675,641✔
607

608
  // Whether particle is alive
609
  bool alive() const { return wgt_ != 0.0; }
2,147,483,647✔
610

611
  // Polar scattering angle after a collision
612
  double& mu() { return mu_; }
2,147,483,647✔
613
  const double& mu() const { return mu_; }
100,746,088✔
614

615
  // Tracks the time of a particle as it traverses the problem.
616
  // Units are seconds.
617
  double& time() { return time_; }
2,147,483,647✔
618
  const double& time() const { return time_; }
13,151,792✔
619
  double& time_last() { return time_last_; }
2,147,483,647✔
620
  const double& time_last() const { return time_last_; }
13,134,286✔
621

622
  // Particle lifetime
623
  double& lifetime() { return lifetime_; }
2,147,483,647✔
624
  const double& lifetime() const { return lifetime_; }
1,352,626✔
625

626
  // What event took place, described in greater detail below
627
  TallyEvent& event() { return event_; }
2,147,483,647✔
628
  const TallyEvent& event() const { return event_; }
623,744✔
629
  bool& fission() { return fission_; }            // true if implicit fission
2,147,483,647✔
630
  int& event_nuclide() { return event_nuclide_; } // index of collision nuclide
2,147,483,647✔
631
  const int& event_nuclide() const { return event_nuclide_; }
18,003,865✔
632
  int& event_mt() { return event_mt_; } // MT number of collision
2,147,483,647✔
633
  const int& event_mt() const { return event_mt_; }
18,105,483✔
634
  int& delayed_group() { return delayed_group_; } // delayed group
450,122,855✔
635
  const int& delayed_group() const { return delayed_group_; }
1,352,626✔
636
  const int& parent_nuclide() const { return parent_nuclide_; }
70,631✔
637
  int& parent_nuclide() { return parent_nuclide_; } // Parent nuclide
227,814,772✔
638

639
  // Post-collision data
640
  double& bank_second_E()
2,147,483,647✔
641
  {
642
    return bank_second_E_;
2,147,483,647✔
643
  } // energy of last reaction secondaries
644
  const double& bank_second_E() const { return bank_second_E_; }
21,319,847✔
645

646
  int& n_bank() { return n_bank_; }        // number of banked fission sites
2,147,483,647✔
647
  double& wgt_bank() { return wgt_bank_; } // weight of banked fission sites
2,147,483,647✔
648
  int* n_delayed_bank()
1,253,890✔
649
  {
650
    return n_delayed_bank_;
1,253,890✔
651
  } // number of delayed fission sites
652
  int& n_delayed_bank(int i)
1,048,728,318✔
653
  {
654
    return n_delayed_bank_[i];
1,048,728,318✔
655
  } // number of delayed fission sites
656

657
  // Index of cell particle is born in
658
  int& cell_born() { return cell_born_; }
683,221,379✔
659
  const int& cell_born() const { return cell_born_; }
3,208,755✔
660

661
  // Total number of collisions suffered by particle
662
  int& n_collision() { return n_collision_; }
2,147,483,647✔
663
  const int& n_collision() const { return n_collision_; }
3,208,755✔
664

665
  // whether this track is to be written
666
  bool& write_track() { return write_track_; }
2,147,483,647✔
667

668
  // RNG state
669
  uint64_t& seeds(int i) { return seeds_[i]; }
847,284,097✔
670
  uint64_t* seeds() { return seeds_; }
163,937,947✔
671
  int& stream() { return stream_; }
2,147,483,647✔
672

673
  // secondary particle bank
674
  SourceSite& secondary_bank(int i) { return secondary_bank_[i]; }
675
  decltype(secondary_bank_)& secondary_bank() { return secondary_bank_; }
416,965,349✔
676

677
  // Current simulation work index
678
  int64_t& current_work() { return current_work_; }
165,013,566✔
679
  const int64_t& current_work() const { return current_work_; }
2,705,609✔
680

681
  // Used in tally derivatives
682
  double& flux_derivs(int i) { return flux_derivs_[i]; }
2,867,810✔
683
  const double& flux_derivs(int i) const { return flux_derivs_[i]; }
2,140,666✔
684

685
  // Matches of tallies
686
  decltype(filter_matches_)& filter_matches() { return filter_matches_; }
2,147,483,647✔
687
  FilterMatch& filter_matches(int i) { return filter_matches_[i]; }
8,374,377✔
688

689
  // Tracks to output to file
690
  decltype(tracks_)& tracks() { return tracks_; }
27,396✔
691

692
  // Bank of recently fissioned particles
693
  decltype(nu_bank_)& nu_bank() { return nu_bank_; }
267,550,570✔
694
  NuBank& nu_bank(int i) { return nu_bank_[i]; }
1,773,582✔
695

696
  // Interim pulse height tally storage
697
  vector<double>& pht_storage() { return pht_storage_; }
324,149,942✔
698

699
  // Global tally accumulators
700
  double& keff_tally_absorption() { return keff_tally_absorption_; }
458,309,302✔
701
  double& keff_tally_collision() { return keff_tally_collision_; }
2,147,483,647✔
702
  double& keff_tally_tracklength() { return keff_tally_tracklength_; }
2,147,483,647✔
703
  double& keff_tally_leakage() { return keff_tally_leakage_; }
357,662,284✔
704

705
  // Shows debug info
706
  bool& trace() { return trace_; }
2,147,483,647✔
707

708
  // Distance to the next collision
709
  double& collision_distance() { return collision_distance_; }
2,147,483,647✔
710

711
  // Number of events particle has undergone
712
  int& n_event() { return n_event_; }
2,147,483,647✔
713

714
  // Number of times variance reduction has caused a particle split
715
  int n_split() const { return n_split_; }
716
  int& n_split() { return n_split_; }
178,533,623✔
717

718
  // Particle-specific factor for on-the-fly weight window adjustment
719
  double ww_factor() const { return ww_factor_; }
720
  double& ww_factor() { return ww_factor_; }
280,381,255✔
721

722
  // Number of progeny produced by this particle
723
  int64_t& n_progeny() { return n_progeny_; }
434,869,787✔
724

725
  //! Gets the pointer to the particle's current PRN seed
726
  uint64_t* current_seed() { return seeds_ + stream_; }
2,147,483,647✔
727
  const uint64_t* current_seed() const { return seeds_ + stream_; }
728

729
  //! Force recalculation of neutron xs by setting last energy to zero
730
  void invalidate_neutron_xs()
50,046,527✔
731
  {
732
    for (auto& micro : neutron_xs_)
250,699,641✔
733
      micro.last_E = 0.0;
200,653,114✔
734
  }
50,046,527✔
735

736
  //! Get track information based on particle's current state
737
  TrackState get_track_state() const;
738

739
  void zero_delayed_bank()
2,147,483,647✔
740
  {
741
    for (int& n : n_delayed_bank_) {
2,147,483,647✔
742
      n = 0;
2,147,483,647✔
743
    }
744
  }
2,147,483,647✔
745

746
  void zero_flux_derivs()
267,841,547✔
747
  {
748
    for (double& d : flux_derivs_) {
267,873,547✔
749
      d = 0;
32,000✔
750
    }
751
  }
267,841,547✔
752
};
753

754
} // namespace openmc
755

756
#endif // OPENMC_PARTICLE_DATA_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