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

openmc-dev / openmc / 21887062786

10 Feb 2026 11:55PM UTC coverage: 81.899% (-0.1%) from 82.009%
21887062786

Pull #3493

github

web-flow
Merge 320b68711 into 3f20a5e22
Pull Request #3493: Implement vector fitting to replace external `vectfit` package

17361 of 24292 branches covered (71.47%)

Branch coverage included in aggregate %.

185 of 218 new or added lines in 3 files covered. (84.86%)

2770 existing lines in 69 files now uncovered.

56369 of 65733 relevant lines covered (85.75%)

51144917.16 hits per line

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

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

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

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

22
namespace openmc {
23

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

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

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

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

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

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

81
  // Close hdf5 file
82
  file_close(file_id);
30✔
83
}
30✔
84

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

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

93
  // Initialize the particle to be tracked
94
  Particle p;
30✔
95

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

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

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

109
  // Compute random number seed
110
  int64_t particle_seed;
111
  switch (previous_run_mode) {
30!
112
  case RunMode::EIGENVALUE:
30✔
113
  case RunMode::FIXED_SOURCE:
114
    particle_seed = (simulation::total_gen + overall_generation() - 1) *
30✔
115
                      settings::n_particles +
116
                    p.id();
30✔
117
    break;
30✔
UNCOV
118
  default:
×
UNCOV
119
    throw std::runtime_error {
×
UNCOV
120
      "Unexpected run mode: " +
×
UNCOV
121
      std::to_string(static_cast<int>(previous_run_mode))};
×
122
  }
123
  init_particle_seeds(particle_seed, p.seeds());
30✔
124

125
  // Force calculation of cross-sections by setting last energy to zero
126
  if (settings::run_CE) {
30!
127
    p.invalidate_neutron_xs();
30✔
128
  }
129

130
  // Prepare to write out particle track.
131
  if (p.write_track())
30✔
132
    add_particle_track(p);
10✔
133

134
  // Transport neutron
135
  transport_history_based_single_particle(p);
30✔
136

137
  // Write output if particle made it
138
  print_particle(p);
30✔
139

140
  if (settings::write_all_tracks) {
30✔
141
    close_track_file();
10✔
142
  }
143
}
30✔
144

145
} // 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