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

openmc-dev / openmc / 12776996362

14 Jan 2025 09:49PM UTC coverage: 84.938% (+0.2%) from 84.729%
12776996362

Pull #3133

github

web-flow
Merge 0495246d9 into 549cc0973
Pull Request #3133: Kinetics parameters using Iterated Fission Probability

318 of 330 new or added lines in 10 files covered. (96.36%)

1658 existing lines in 66 files now uncovered.

50402 of 59340 relevant lines covered (84.94%)

33987813.96 hits per line

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

91.3
/src/physics_mg.cpp
1
#include "openmc/physics_mg.h"
2

3
#include <stdexcept>
4

5
#include "xtensor/xarray.hpp"
6
#include <fmt/core.h>
7

8
#include "openmc/bank.h"
9
#include "openmc/constants.h"
10
#include "openmc/eigenvalue.h"
11
#include "openmc/error.h"
12
#include "openmc/material.h"
13
#include "openmc/math_functions.h"
14
#include "openmc/message_passing.h"
15
#include "openmc/mgxs_interface.h"
16
#include "openmc/particle.h"
17
#include "openmc/physics_common.h"
18
#include "openmc/random_lcg.h"
19
#include "openmc/settings.h"
20
#include "openmc/simulation.h"
21
#include "openmc/tallies/tally.h"
22
#include "openmc/weight_windows.h"
23

24
namespace openmc {
25

26
void collision_mg(Particle& p)
1,939,604,940✔
27
{
28
  // Add to the collision counter for the particle
29
  p.n_collision()++;
1,939,604,940✔
30

31
  if (settings::weight_window_checkpoint_collision)
1,939,604,940✔
32
    apply_weight_windows(p);
1,939,604,940✔
33

34
  // Sample the reaction type
35
  sample_reaction(p);
1,939,604,940✔
36

37
  // Display information about collision
38
  if ((settings::verbosity >= 10) || p.trace()) {
1,939,604,940✔
UNCOV
39
    write_message(fmt::format("    Energy Group = {}", p.g()), 1);
×
40
  }
41
}
1,939,604,940✔
42

43
void sample_reaction(Particle& p)
1,939,604,940✔
44
{
45
  // Create fission bank sites. Note that while a fission reaction is sampled,
46
  // it never actually "happens", i.e. the weight of the particle does not
47
  // change when sampling fission sites. The following block handles all
48
  // absorption (including fission)
49

50
  if (model::materials[p.material()]->fissionable()) {
1,939,604,940✔
51
    if (settings::run_mode == RunMode::EIGENVALUE ||
1,937,955,456✔
UNCOV
52
        (settings::run_mode == RunMode::FIXED_SOURCE &&
×
53
          settings::create_fission_neutrons)) {
54
      create_fission_sites(p);
1,937,955,456✔
55
    }
56
  }
57

58
  // If survival biasing is being used, the following subroutine adjusts the
59
  // weight of the particle. Otherwise, it checks to see if absorption occurs.
60
  if (p.macro_xs().absorption > 0.) {
1,939,604,940✔
61
    absorption(p);
1,939,604,940✔
62
  }
63
  if (!p.alive())
1,939,604,940✔
64
    return;
120,885,540✔
65

66
  // Sample a scattering event to determine the energy of the exiting neutron
67
  scatter(p);
1,818,719,400✔
68

69
  // Play Russian roulette if survival biasing is turned on
70
  if (settings::survival_biasing) {
1,818,719,400✔
71
    if (p.wgt() < settings::weight_cutoff) {
4,596,048✔
72
      russian_roulette(p, settings::weight_survive);
155,124✔
73
    }
74
  }
75
}
76

77
void scatter(Particle& p)
1,818,719,400✔
78
{
79
  data::mg.macro_xs_[p.material()].sample_scatter(p.g_last(), p.g(), p.mu(),
2,147,483,647✔
80
    p.wgt(), p.current_seed(), p.mg_xs_cache().t, p.mg_xs_cache().a);
1,818,719,400✔
81

82
  // Rotate the angle
83
  p.u() = rotate_angle(p.u(), p.mu(), nullptr, p.current_seed());
1,818,719,400✔
84

85
  // Update energy value for downstream compatability (in tallying)
86
  p.E() = data::mg.energy_bin_avg_[p.g()];
1,818,719,400✔
87

88
  // Set event component
89
  p.event() = TallyEvent::SCATTER;
1,818,719,400✔
90
}
1,818,719,400✔
91

92
void create_fission_sites(Particle& p)
1,937,955,456✔
93
{
94
  // If uniform fission source weighting is turned on, we increase or decrease
95
  // the expected number of fission sites produced
96
  double weight = settings::ufs_on ? ufs_get_weight(p) : 1.0;
1,937,955,456✔
97

98
  // Determine the expected number of neutrons produced
99
  double nu_t = p.wgt() / simulation::keff * weight * p.macro_xs().nu_fission /
1,937,955,456✔
100
                p.macro_xs().total;
1,937,955,456✔
101

102
  // Sample the number of neutrons produced
103
  int nu = static_cast<int>(nu_t);
1,937,955,456✔
104
  if (prn(p.current_seed()) <= (nu_t - int(nu_t))) {
1,937,955,456✔
105
    nu++;
121,148,676✔
106
  }
107

108
  // If no neutrons were produced then don't continue
109
  if (nu == 0)
1,937,955,456✔
110
    return;
1,816,805,988✔
111

112
  // Initialize the counter of delayed neutrons encountered for each delayed
113
  // group.
114
  double nu_d[MAX_DELAYED_GROUPS] = {0.};
121,149,468✔
115

116
  // Clear out particle's nu fission bank
117
  p.nu_bank().clear();
121,149,468✔
118

119
  p.fission() = true;
121,149,468✔
120

121
  // Determine whether to place fission sites into the shared fission bank
122
  // or the secondary particle bank.
123
  bool use_fission_bank = (settings::run_mode == RunMode::EIGENVALUE);
121,149,468✔
124

125
  // Counter for the number of fission sites successfully stored to the shared
126
  // fission bank or the secondary particle bank
127
  int n_sites_stored;
128

129
  for (n_sites_stored = 0; n_sites_stored < nu; n_sites_stored++) {
242,300,544✔
130
    // Initialize fission site object with particle data
131
    SourceSite site;
121,151,076✔
132
    site.r = p.r();
121,151,076✔
133
    site.particle = ParticleType::neutron;
121,151,076✔
134
    site.wgt = 1. / weight;
121,151,076✔
135
    site.parent_id = p.id();
121,151,076✔
136
    site.progeny_id = p.n_progeny()++;
121,151,076✔
137

138
    // Sample the cosine of the angle, assuming fission neutrons are emitted
139
    // isotropically
140
    double mu = 2. * prn(p.current_seed()) - 1.;
121,151,076✔
141

142
    // Sample the azimuthal angle uniformly in [0, 2.pi)
143
    double phi = 2. * PI * prn(p.current_seed());
121,151,076✔
144
    site.u.x = mu;
121,151,076✔
145
    site.u.y = std::sqrt(1. - mu * mu) * std::cos(phi);
121,151,076✔
146
    site.u.z = std::sqrt(1. - mu * mu) * std::sin(phi);
121,151,076✔
147

148
    // Sample secondary energy distribution for the fission reaction
149
    int dg;
150
    int gout;
151
    data::mg.macro_xs_[p.material()].sample_fission_energy(
363,453,228✔
152
      p.g(), dg, gout, p.current_seed(), p.mg_xs_cache().t, p.mg_xs_cache().a);
242,302,152✔
153

154
    // Store the energy and delayed groups on the fission bank
155
    site.E = gout;
121,151,076✔
156

157
    // We add 1 to the delayed_group bc in MG, -1 is prompt, but in the rest
158
    // of the code, 0 is prompt.
159
    site.delayed_group = dg + 1;
121,151,076✔
160

161
    // Store fission site in bank
162
    if (use_fission_bank) {
121,151,076✔
163
      int64_t idx = simulation::fission_bank.thread_safe_append(site);
121,151,076✔
164
      if (idx == -1) {
121,151,076✔
UNCOV
165
        warning(
×
166
          "The shared fission bank is full. Additional fission sites created "
167
          "in this generation will not be banked. Results may be "
168
          "non-deterministic.");
169

170
        // Decrement number of particle progeny as storage was unsuccessful.
171
        // This step is needed so that the sum of all progeny is equal to the
172
        // size of the shared fission bank.
UNCOV
173
        p.n_progeny()--;
×
174

175
        // Break out of loop as no more sites can be added to fission bank
UNCOV
176
        break;
×
177
      }
178
    } else {
UNCOV
179
      p.secondary_bank().push_back(site);
×
180
    }
181

182
    // Set the delayed group on the particle as well
183
    p.delayed_group() = dg + 1;
121,151,076✔
184

185
    // Increment the number of neutrons born delayed
186
    if (p.delayed_group() > 0) {
121,151,076✔
187
      nu_d[dg]++;
1,680✔
188
    }
189

190
    // Write fission particles to nuBank
191
    p.nu_bank().emplace_back();
121,151,076✔
192
    NuBank* nu_bank_entry = &p.nu_bank().back();
121,151,076✔
193
    nu_bank_entry->wgt = site.wgt;
121,151,076✔
194
    nu_bank_entry->E = site.E;
121,151,076✔
195
    nu_bank_entry->delayed_group = site.delayed_group;
121,151,076✔
196
  }
197

198
  // If shared fission bank was full, and no fissions could be added,
199
  // set the particle fission flag to false.
200
  if (n_sites_stored == 0) {
121,149,468✔
UNCOV
201
    p.fission() = false;
×
UNCOV
202
    return;
×
203
  }
204

205
  // Set nu to the number of fission sites successfully stored. If the fission
206
  // bank was not found to be full then these values are already equivalent.
207
  nu = n_sites_stored;
121,149,468✔
208

209
  // Store the total weight banked for analog fission tallies
210
  p.n_bank() = nu;
121,149,468✔
211
  p.wgt_bank() = nu / weight;
121,149,468✔
212
  for (size_t d = 0; d < MAX_DELAYED_GROUPS; d++) {
1,090,345,212✔
213
    p.n_delayed_bank(d) = nu_d[d];
969,195,744✔
214
  }
215
}
216

217
void absorption(Particle& p)
1,939,604,940✔
218
{
219
  if (settings::survival_biasing) {
1,939,604,940✔
220
    // Determine weight absorbed in survival biasing
221
    double wgt_absorb = p.wgt() * p.macro_xs().absorption / p.macro_xs().total;
4,596,048✔
222

223
    // Adjust weight of particle by the probability of absorption
224
    p.wgt() -= wgt_absorb;
4,596,048✔
225

226
    // Score implicit absorpion estimate of keff
227
    p.keff_tally_absorption() +=
4,596,048✔
228
      wgt_absorb * p.macro_xs().nu_fission / p.macro_xs().absorption;
4,596,048✔
229
  } else {
230
    if (p.macro_xs().absorption > prn(p.current_seed()) * p.macro_xs().total) {
1,935,008,892✔
231
      p.keff_tally_absorption() +=
241,771,080✔
232
        p.wgt() * p.macro_xs().nu_fission / p.macro_xs().absorption;
120,885,540✔
233
      p.wgt() = 0.0;
120,885,540✔
234
      p.event() = TallyEvent::ABSORB;
120,885,540✔
235
    }
236
  }
237
}
1,939,604,940✔
238

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

© 2025 Coveralls, Inc