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

openmc-dev / openmc / 26245425348

21 May 2026 06:30PM UTC coverage: 81.319% (-0.06%) from 81.382%
26245425348

Pull #3553

github

web-flow
Merge f76231f92 into 7d09a1260
Pull Request #3553: adding mesh tally amalgamation algorithm

17993 of 26103 branches covered (68.93%)

Branch coverage included in aggregate %.

59110 of 68712 relevant lines covered (86.03%)

48523054.24 hits per line

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

89.57
/src/particle_restart.cpp
1
#include "openmc/particle_restart.h"
2

3
#include "openmc/array.h"
4
#include "openmc/bank.h"
5
#include "openmc/constants.h"
6
#include "openmc/hdf5_interface.h"
7
#include "openmc/mgxs_interface.h"
8
#include "openmc/nuclide.h"
9
#include "openmc/output.h"
10
#include "openmc/particle.h"
11
#include "openmc/photon.h"
12
#include "openmc/random_lcg.h"
13
#include "openmc/settings.h"
14
#include "openmc/simulation.h"
15
#include "openmc/tallies/derivative.h"
16
#include "openmc/tallies/tally.h"
17
#include "openmc/track_output.h"
18

19
#include <algorithm> // for copy
20
#include <stdexcept>
21
#include <string>
22

23
namespace openmc {
24

25
void read_particle_restart(Particle& p, RunMode& previous_run_mode)
44✔
26
{
27
  // Write meessage
28
  write_message(
44✔
29
    5, "Loading particle restart file {}", settings::path_particle_restart);
30

31
  // Open file
32
  hid_t file_id = file_open(settings::path_particle_restart, 'r');
44✔
33

34
  // Read data from file
35
  bool legacy_particle_codes = true;
44✔
36
  if (attribute_exists(file_id, "version")) {
44!
37
    array<int, 2> version;
44✔
38
    read_attribute(file_id, "version", version);
44✔
39
    if (version[0] > VERSION_PARTICLE_RESTART[0] ||
44!
40
        (version[0] == VERSION_PARTICLE_RESTART[0] && version[1] >= 1)) {
44!
41
      legacy_particle_codes = false;
42
    }
43
  }
44

45
  read_dataset(file_id, "current_batch", simulation::current_batch);
44✔
46
  read_dataset(file_id, "generations_per_batch", settings::gen_per_batch);
44✔
47
  read_dataset(file_id, "current_generation", simulation::current_gen);
44✔
48
  read_dataset(file_id, "n_particles", settings::n_particles);
44✔
49
  std::string mode;
44✔
50
  read_dataset(file_id, "run_mode", mode);
44✔
51
  if (mode == "eigenvalue") {
44✔
52
    previous_run_mode = RunMode::EIGENVALUE;
11✔
53
  } else if (mode == "fixed source") {
33!
54
    previous_run_mode = RunMode::FIXED_SOURCE;
33✔
55
  }
56
  read_dataset(file_id, "id", p.id());
44✔
57
  int type;
44✔
58
  read_dataset(file_id, "type", type);
44✔
59
  p.type() = legacy_particle_codes ? legacy_particle_index_to_type(type)
44!
60
                                   : ParticleType {type};
44✔
61
  read_dataset(file_id, "weight", p.wgt());
44✔
62
  read_dataset(file_id, "energy", p.E());
44✔
63
  read_dataset(file_id, "xyz", p.r());
44✔
64
  read_dataset(file_id, "uvw", p.u());
44✔
65
  read_dataset(file_id, "time", p.time());
44✔
66

67
  // Set energy group and average energy in multi-group mode
68
  if (!settings::run_CE) {
44!
69
    p.g() = p.E();
×
70
    p.E() = data::mg.energy_bin_avg_[p.g()];
×
71
  }
72

73
  // Set particle last attributes
74
  p.wgt_last() = p.wgt();
44✔
75
  p.r_last_current() = p.r();
44✔
76
  p.r_last() = p.r();
44✔
77
  p.u_last() = p.u();
44✔
78
  p.E_last() = p.E();
44✔
79
  p.g_last() = p.g();
44✔
80
  p.time_last() = p.time();
44✔
81

82
  // Close hdf5 file
83
  file_close(file_id);
44✔
84
}
44✔
85

86
void run_particle_restart()
44✔
87
{
88
  // Set verbosity high
89
  settings::verbosity = 10;
44✔
90

91
  // Initialize nuclear data (energy limits, log grid, etc.)
92
  initialize_data();
44✔
93

94
  // Initialize the particle to be tracked
95
  Particle p;
44✔
96

97
  // Read in the restart information
98
  RunMode previous_run_mode;
44✔
99
  read_particle_restart(p, previous_run_mode);
44✔
100

101
  // write track if that was requested on command line
102
  if (settings::write_all_tracks) {
44✔
103
    open_track_file();
11✔
104
    p.write_track() = true;
11✔
105
  }
106

107
  // Set all tallies to 0 for now (just tracking errors)
108
  model::tallies.clear();
44✔
109

110
  // Allocate progeny_per_particle if needed for shared secondary mode
111
  // (event_death() writes to this array). Set current_work to 0 since we
112
  // only have one particle being restarted.
113
  if (settings::use_shared_secondary_bank) {
44✔
114
    p.current_work() = 0;
11✔
115
    simulation::progeny_per_particle.resize(1, 0);
11✔
116
  }
117

118
  // Compute random number seed
119
  int64_t particle_seed = compute_transport_seed(p.id());
44✔
120
  init_particle_seeds(particle_seed, p.seeds());
44✔
121

122
  // Force calculation of cross-sections by setting last energy to zero
123
  if (settings::run_CE) {
44!
124
    p.invalidate_neutron_xs();
44✔
125
  }
126

127
  // Prepare to write out particle track.
128
  if (p.write_track())
44✔
129
    add_particle_track(p);
11✔
130

131
  // Transport neutron
132
  transport_history_based_single_particle(p);
44✔
133

134
  // Write output if particle made it
135
  print_particle(p);
44✔
136

137
  if (settings::write_all_tracks) {
44✔
138
    close_track_file();
11✔
139
  }
140
}
44✔
141

142
} // namespace openmc
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