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

openmc-dev / openmc / 13291505710

12 Feb 2025 05:41PM UTC coverage: 84.973%. First build
13291505710

Pull #3133

github

web-flow
Merge b7865aa48 into 18c311241
Pull Request #3133: Kinetics parameters using Iterated Fission Probability

327 of 340 new or added lines in 13 files covered. (96.18%)

50529 of 59465 relevant lines covered (84.97%)

35150205.77 hits per line

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

98.53
/src/ifp.cpp
1
#include "openmc/ifp.h"
2

3
#include "openmc/bank.h"
4
#include "openmc/message_passing.h"
5
#include "openmc/particle.h"
6
#include "openmc/particle_data.h"
7
#include "openmc/settings.h"
8
#include "openmc/simulation.h"
9
#include "openmc/vector.h"
10

11
namespace openmc {
12

13
bool is_beta_effective_or_both()
1,334,437✔
14
{
15
  if (settings::ifp_parameter == IFPParameter::BetaEffective ||
1,334,437✔
16
      settings::ifp_parameter == IFPParameter::Both) {
1,334,437✔
17
    return true;
1,334,437✔
18
  }
NEW
19
  return false;
×
20
}
21

22
bool is_generation_time_or_both()
1,152,897✔
23
{
24
  if (settings::ifp_parameter == IFPParameter::GenerationTime ||
1,152,897✔
25
      settings::ifp_parameter == IFPParameter::Both) {
1,152,897✔
26
    return true;
1,152,897✔
27
  }
NEW
28
  return false;
×
29
}
30

31
void ifp(const Particle& p, const SourceSite& site, int64_t idx)
242,100✔
32
{
33
  if (is_beta_effective_or_both()) {
242,100✔
34
    const auto& delayed_groups =
35
      simulation::ifp_source_delayed_group_bank[p.current_work() - 1];
242,100✔
36
    vector<int> updated_delayed_groups =
37
      _ifp(site.delayed_group, delayed_groups);
242,100✔
38
    simulation::ifp_fission_delayed_group_bank[idx] = updated_delayed_groups;
242,100✔
39
  }
242,100✔
40
  if (is_generation_time_or_both()) {
242,100✔
41
    const auto& lifetimes =
42
      simulation::ifp_source_lifetime_bank[p.current_work() - 1];
242,100✔
43
    vector<double> updated_lifetimes = _ifp(p.lifetime(), lifetimes);
242,100✔
44
    simulation::ifp_fission_lifetime_bank[idx] = updated_lifetimes;
242,100✔
45
  }
242,100✔
46
}
242,100✔
47

48
void resize_simulation_ifp_banks()
17✔
49
{
50
  if (is_beta_effective_or_both()) {
17✔
51
    simulation::ifp_source_delayed_group_bank.resize(simulation::work_per_rank);
17✔
52
    simulation::ifp_fission_delayed_group_bank.resize(
17✔
53
      3 * simulation::work_per_rank);
17✔
54
  }
55
  if (is_generation_time_or_both()) {
17✔
56
    simulation::ifp_source_lifetime_bank.resize(simulation::work_per_rank);
17✔
57
    simulation::ifp_fission_lifetime_bank.resize(3 * simulation::work_per_rank);
17✔
58
  }
59
}
17✔
60

61
void initialize_ifp_pointers(int64_t i_bank,
242,100✔
62
  const vector<int>*& delayed_groups_ptr, const vector<double>*& lifetimes_ptr)
63
{
64
  if (is_beta_effective_or_both()) {
242,100✔
65
    delayed_groups_ptr = &simulation::ifp_fission_delayed_group_bank[i_bank];
242,100✔
66
  }
67
  if (is_generation_time_or_both()) {
242,100✔
68
    lifetimes_ptr = &simulation::ifp_fission_lifetime_bank[i_bank];
242,100✔
69
  }
70
}
242,100✔
71

72
void add_ifp_data(int64_t idx, vector<vector<int>>& delayed_groups,
240,084✔
73
  const vector<int>* const& delayed_groups_ptr,
74
  vector<vector<double>>& lifetimes, const vector<double>* const& lifetimes_ptr)
75
{
76
  if (is_beta_effective_or_both()) {
240,084✔
77
    delayed_groups[idx] = *delayed_groups_ptr;
240,084✔
78
  }
79
  if (is_generation_time_or_both()) {
240,084✔
80
    lifetimes[idx] = *lifetimes_ptr;
240,084✔
81
  }
82
}
240,084✔
83

84
void retrieve_ifp_data_from_fission_banks(int64_t idx, int i_bank,
516✔
85
  vector<vector<int>>& delayed_groups, vector<vector<double>>& lifetimes)
86
{
87
  if (is_beta_effective_or_both()) {
516✔
88
    delayed_groups[idx] = simulation::ifp_fission_delayed_group_bank[i_bank];
516✔
89
  }
90
  if (is_generation_time_or_both()) {
516✔
91
    lifetimes[idx] = simulation::ifp_fission_lifetime_bank[i_bank];
516✔
92
  }
93
}
516✔
94

95
#ifdef OPENMC_MPI
96

97
void broadcast_ifp_n_generation(int& n_generation,
200✔
98
  const vector<vector<int>>& delayed_groups,
99
  const vector<vector<double>>& lifetimes)
100
{
101
  if (mpi::rank == 0) {
200✔
102
    if (is_beta_effective_or_both()) {
100✔
103
      n_generation = static_cast<int>(delayed_groups[0].size());
100✔
104
    } else {
105
      n_generation = static_cast<int>(lifetimes[0].size());
106
    }
107
  }
108
  MPI_Bcast(&n_generation, 1, MPI_INT, 0, mpi::intracomm);
200✔
109
}
200✔
110

111
void send_ifp_info(int64_t idx, int64_t n, int n_generation, int neighbor,
95✔
112
  vector<MPI_Request>& requests, const vector<vector<int>>& delayed_groups,
113
  vector<int>& send_delayed_groups, const vector<vector<double>>& lifetimes,
114
  vector<double>& send_lifetimes)
115
{
116
  // Copy data in send buffers
117
  for (int i = idx; i < idx + n; i++) {
1,390✔
118
    if (is_beta_effective_or_both()) {
1,295✔
119
      std::copy(delayed_groups[i].begin(), delayed_groups[i].end(),
1,295✔
120
        send_delayed_groups.begin() + i * n_generation);
2,590✔
121
    }
122
    if (is_generation_time_or_both()) {
1,295✔
123
      std::copy(lifetimes[i].begin(), lifetimes[i].end(),
1,295✔
124
        send_lifetimes.begin() + i * n_generation);
2,590✔
125
    }
126
  }
127
  // Send delayed groups
128
  if (is_beta_effective_or_both()) {
95✔
129
    requests.emplace_back();
95✔
130
    MPI_Isend(&send_delayed_groups[n_generation * idx],
95✔
131
      n_generation * static_cast<int>(n), MPI_INT, neighbor, mpi::rank,
132
      mpi::intracomm, &requests.back());
95✔
133
  }
134
  // Send lifetimes
135
  if (is_generation_time_or_both()) {
95✔
136
    requests.emplace_back();
95✔
137
    MPI_Isend(&send_lifetimes[n_generation * idx],
95✔
138
      n_generation * static_cast<int>(n), MPI_DOUBLE, neighbor, mpi::rank,
139
      mpi::intracomm, &requests.back());
95✔
140
  }
141
}
95✔
142

143
void receive_ifp_data(int64_t idx, int64_t n, int n_generation, int neighbor,
95✔
144
  vector<MPI_Request>& requests, vector<int>& delayed_groups,
145
  vector<double>& lifetimes, vector<DeserializationInfo>& deserialization)
146
{
147
  // Receive delayed groups
148
  if (is_beta_effective_or_both()) {
95✔
149
    requests.emplace_back();
95✔
150
    MPI_Irecv(&delayed_groups[n_generation * idx],
95✔
151
      n_generation * static_cast<int>(n), MPI_INT, neighbor, neighbor,
152
      mpi::intracomm, &requests.back());
95✔
153
  }
154
  // Receive lifetimes
155
  if (is_generation_time_or_both()) {
95✔
156
    requests.emplace_back();
95✔
157
    MPI_Irecv(&lifetimes[n_generation * idx],
95✔
158
      n_generation * static_cast<int>(n), MPI_DOUBLE, neighbor, neighbor,
159
      mpi::intracomm, &requests.back());
95✔
160
  }
161
  // Deserialization info to reconstruct data later
162
  DeserializationInfo info = {idx, n};
95✔
163
  deserialization.push_back(info);
95✔
164
}
95✔
165

166
void copy_partial_ifp_data_to_source_banks(int64_t idx, int n, int64_t i_bank,
200✔
167
  const vector<vector<int>>& delayed_groups,
168
  const vector<vector<double>>& lifetimes)
169
{
170
  if (is_beta_effective_or_both()) {
200✔
171
    std::copy(&delayed_groups[idx], &delayed_groups[idx + n],
200✔
172
      &simulation::ifp_source_delayed_group_bank[i_bank]);
200✔
173
  }
174
  if (is_generation_time_or_both()) {
200✔
175
    std::copy(&lifetimes[idx], &lifetimes[idx + n],
200✔
176
      &simulation::ifp_source_lifetime_bank[i_bank]);
200✔
177
  }
178
}
200✔
179

180
void deserialize_ifp_info(int n_generation,
200✔
181
  const vector<DeserializationInfo>& deserialization,
182
  const vector<int>& delayed_groups, const vector<double>& lifetimes)
183
{
184
  for (auto info : deserialization) {
295✔
185
    int64_t index_local = info.index_local;
95✔
186
    int64_t n = info.n;
95✔
187

188
    for (int i = index_local; i < index_local + n; i++) {
1,390✔
189
      if (is_beta_effective_or_both()) {
1,295✔
190
        vector<int> delayed_groups_received(
191
          delayed_groups.begin() + n_generation * i,
192
          delayed_groups.begin() + n_generation * (i + 1));
1,295✔
193
        simulation::ifp_source_delayed_group_bank[i] = delayed_groups_received;
1,295✔
194
      }
1,295✔
195
      if (is_generation_time_or_both()) {
1,295✔
196
        vector<double> lifetimes_received(lifetimes.begin() + n_generation * i,
197
          lifetimes.begin() + n_generation * (i + 1));
1,295✔
198
        simulation::ifp_source_lifetime_bank[i] = lifetimes_received;
1,295✔
199
      }
1,295✔
200
    }
201
  }
202
}
200✔
203

204
#endif
205

206
void copy_complete_ifp_data_to_source_banks(
140✔
207
  const vector<vector<int>>& delayed_groups,
208
  const vector<vector<double>>& lifetimes)
209
{
210
  if (is_beta_effective_or_both()) {
140✔
211
    std::copy(delayed_groups.data(),
280✔
212
      delayed_groups.data() + settings::n_particles,
140✔
213
      simulation::ifp_source_delayed_group_bank.begin());
214
  }
215
  if (is_generation_time_or_both()) {
140✔
216
    std::copy(lifetimes.data(), lifetimes.data() + settings::n_particles,
140✔
217
      simulation::ifp_source_lifetime_bank.begin());
218
  }
219
}
140✔
220

221
void allocate_temporary_vector_ifp(vector<vector<int>>& delayed_groups,
340✔
222
  vector<int>*& delayed_groups_ptr, vector<vector<double>>& lifetimes,
223
  vector<double>*& lifetimes_ptr)
224
{
225
  if (is_beta_effective_or_both()) {
340✔
226
    delayed_groups.resize(simulation::fission_bank.size());
340✔
227
    delayed_groups_ptr = delayed_groups.data();
340✔
228
  }
229
  if (is_generation_time_or_both()) {
340✔
230
    lifetimes.resize(simulation::fission_bank.size());
340✔
231
    lifetimes_ptr = lifetimes.data();
340✔
232
  }
233
}
340✔
234

235
void sort_ifp_data_from_fission_banks(int64_t i_bank, int64_t idx,
242,100✔
236
  vector<int>*& delayed_groups_ptr, vector<double>*& lifetimes_ptr)
237
{
238
  if (is_beta_effective_or_both()) {
242,100✔
239
    const auto& delayed_groups =
240
      simulation::ifp_fission_delayed_group_bank[i_bank];
242,100✔
241
    delayed_groups_ptr[idx] = delayed_groups;
242,100✔
242
  }
243
  if (is_generation_time_or_both()) {
242,100✔
244
    const auto& lifetimes = simulation::ifp_fission_lifetime_bank[i_bank];
242,100✔
245
    lifetimes_ptr[idx] = lifetimes;
242,100✔
246
  }
247
}
242,100✔
248

249
void copy_ifp_data_to_fission_banks(
340✔
250
  vector<int>* const& delayed_groups_ptr, vector<double>* const& lifetimes_ptr)
251
{
252
  if (is_beta_effective_or_both()) {
340✔
253
    std::copy(delayed_groups_ptr,
340✔
254
      delayed_groups_ptr + simulation::fission_bank.size(),
340✔
255
      simulation::ifp_fission_delayed_group_bank.data());
256
  }
257
  if (is_generation_time_or_both()) {
340✔
258
    std::copy(lifetimes_ptr, lifetimes_ptr + simulation::fission_bank.size(),
340✔
259
      simulation::ifp_fission_lifetime_bank.data());
260
  }
261
}
340✔
262

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