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

openmc-dev / openmc / 22920521397

10 Mar 2026 07:28PM UTC coverage: 81.221% (-0.5%) from 81.721%
22920521397

Pull #3810

github

web-flow
Merge c81063b52 into 1dc4aa988
Pull Request #3810: Implementation of migration area score

17031 of 24387 branches covered (69.84%)

Branch coverage included in aggregate %.

37 of 52 new or added lines in 5 files covered. (71.15%)

2537 existing lines in 86 files now uncovered.

57019 of 66784 relevant lines covered (85.38%)

35780397.68 hits per line

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

96.02
/src/xsdata.cpp
1
#include "openmc/xsdata.h"
2

3
#include <algorithm>
4
#include <cmath>
5
#include <cstdlib>
6
#include <numeric>
7

8
#include "openmc/tensor.h"
9

10
#include "openmc/constants.h"
11
#include "openmc/error.h"
12
#include "openmc/math_functions.h"
13
#include "openmc/mgxs_interface.h"
14
#include "openmc/random_lcg.h"
15
#include "openmc/settings.h"
16

17
namespace openmc {
18

19
//==============================================================================
20
// XsData class methods
21
//==============================================================================
22

23
XsData::XsData(bool fissionable, AngleDistributionType scatter_format,
4,130✔
24
  int n_pol, int n_azi, size_t n_groups, size_t n_d_groups)
4,130✔
25
  : n_g_(n_groups), n_dg_(n_d_groups)
4,130✔
26
{
27
  size_t n_ang = n_pol * n_azi;
4,130✔
28

29
  // check to make sure scatter format is OK before we allocate
30
  if (scatter_format != AngleDistributionType::HISTOGRAM &&
4,130✔
31
      scatter_format != AngleDistributionType::TABULAR &&
4,130!
32
      scatter_format != AngleDistributionType::LEGENDRE) {
UNCOV
33
    fatal_error("Invalid scatter_format!");
×
34
  }
35
  // allocate all [temperature][angle][in group] quantities
36
  vector<size_t> shape {n_ang, n_g_};
4,130✔
37
  total = tensor::zeros<double>(shape);
4,130✔
38
  absorption = tensor::zeros<double>(shape);
4,130✔
39
  inverse_velocity = tensor::zeros<double>(shape);
4,130✔
40
  if (fissionable) {
4,130✔
41
    fission = tensor::zeros<double>(shape);
1,524✔
42
    nu_fission = tensor::zeros<double>(shape);
1,524✔
43
    prompt_nu_fission = tensor::zeros<double>(shape);
1,524✔
44
    kappa_fission = tensor::zeros<double>(shape);
3,048✔
45
  }
46

47
  // allocate decay_rate; [temperature][angle][delayed group]
48
  shape[1] = n_dg_;
4,130✔
49
  decay_rate = tensor::zeros<double>(shape);
4,130✔
50

51
  if (fissionable) {
4,130✔
52
    shape = {n_ang, n_dg_, n_g_};
1,524✔
53
    // allocate delayed_nu_fission; [temperature][angle][delay group][in group]
54
    delayed_nu_fission = tensor::zeros<double>(shape);
1,524✔
55

56
    // chi_prompt; [temperature][angle][in group][out group]
57
    shape = {n_ang, n_g_, n_g_};
1,524✔
58
    chi_prompt = tensor::zeros<double>(shape);
1,524✔
59

60
    // chi_delayed; [temperature][angle][delay group][in group][out group]
61
    shape = {n_ang, n_dg_, n_g_, n_g_};
1,524✔
62
    chi_delayed = tensor::zeros<double>(shape);
3,048✔
63
  }
64

65
  for (int a = 0; a < n_ang; a++) {
8,380✔
66
    if (scatter_format == AngleDistributionType::HISTOGRAM) {
4,250✔
67
      scatter.emplace_back(new ScattDataHistogram);
80✔
68
    } else if (scatter_format == AngleDistributionType::TABULAR) {
4,170✔
69
      scatter.emplace_back(new ScattDataTabular);
3,830✔
70
    } else if (scatter_format == AngleDistributionType::LEGENDRE) {
340✔
71
      scatter.emplace_back(new ScattDataLegendre);
340✔
72
    }
73
  }
74
}
4,130✔
75

76
//==============================================================================
77

78
void XsData::from_hdf5(hid_t xsdata_grp, bool fissionable,
2,240✔
79
  AngleDistributionType scatter_format,
80
  AngleDistributionType final_scatter_format, int order_data, bool is_isotropic,
81
  int n_pol, int n_azi)
82
{
83
  // Reconstruct the dimension information so it doesn't need to be passed
84
  size_t n_ang = n_pol * n_azi;
2,240✔
85
  size_t energy_groups = total.shape(1);
2,240!
86

87
  // Set the fissionable-specific data
88
  if (fissionable) {
2,240✔
89
    fission_from_hdf5(xsdata_grp, n_ang, is_isotropic);
817✔
90
  }
91
  // Get the non-fission-specific data
92
  read_nd_tensor(xsdata_grp, "decay-rate", decay_rate);
2,240✔
93
  read_nd_tensor(xsdata_grp, "absorption", absorption, true);
2,240✔
94
  read_nd_tensor(xsdata_grp, "inverse-velocity", inverse_velocity);
2,240✔
95

96
  // Get scattering data
97
  scatter_from_hdf5(
2,240✔
98
    xsdata_grp, n_ang, scatter_format, final_scatter_format, order_data);
99

100
  // Replace zero absorption values with a small number to avoid
101
  // division by zero in tally methods
102
  for (size_t i = 0; i < absorption.size(); i++)
10,064✔
103
    if (absorption.data()[i] == 0.0)
7,824!
UNCOV
104
      absorption.data()[i] = 1.e-10;
×
105

106
  // Get or calculate the total x/s
107
  if (object_exists(xsdata_grp, "total")) {
2,240!
108
    read_nd_tensor(xsdata_grp, "total", total);
2,240✔
109
  } else {
UNCOV
110
    for (size_t a = 0; a < n_ang; a++) {
×
111
      for (size_t gin = 0; gin < energy_groups; gin++) {
×
112
        total(a, gin) = absorption(a, gin) + scatter[a]->scattxs[gin];
×
113
      }
114
    }
115
  }
116

117
  // Replace zero total cross sections with a small number to avoid
118
  // division by zero in tally methods
119
  for (size_t i = 0; i < total.size(); i++)
10,064✔
120
    if (total.data()[i] == 0.0)
7,824!
UNCOV
121
      total.data()[i] = 1.e-10;
×
122
}
2,240✔
123

124
//==============================================================================
125

126
void XsData::fission_vector_beta_from_hdf5(
30✔
127
  hid_t xsdata_grp, size_t n_ang, bool is_isotropic)
128
{
129
  // Data is provided as nu-fission and chi with a beta for delayed info
130

131
  // Get chi
132
  tensor::Tensor<double> temp_chi = tensor::zeros<double>({n_ang, n_g_});
30✔
133
  read_nd_tensor(xsdata_grp, "chi", temp_chi, true);
30✔
134

135
  // Normalize chi so it sums to 1 over outgoing groups for each angle
136
  for (size_t a = 0; a < n_ang; a++) {
60✔
137
    tensor::View<double> row = temp_chi.slice(a);
30✔
138
    row /= row.sum();
30✔
139
  }
30✔
140

141
  // Replicate the energy spectrum across all incoming groups — the
142
  // spectrum is independent of the incoming neutron energy
143
  for (size_t a = 0; a < n_ang; a++)
60✔
144
    for (size_t gin = 0; gin < n_g_; gin++)
90✔
145
      chi_prompt.slice(a, gin) = temp_chi.slice(a);
180✔
146

147
  // Same spectrum for delayed neutrons, replicated across delayed groups
148
  for (size_t a = 0; a < n_ang; a++)
60✔
149
    for (size_t d = 0; d < n_dg_; d++)
130✔
150
      for (size_t gin = 0; gin < n_g_; gin++)
300✔
151
        chi_delayed.slice(a, d, gin) = temp_chi.slice(a);
600✔
152

153
  // Get nu-fission
154
  tensor::Tensor<double> temp_nufiss = tensor::zeros<double>({n_ang, n_g_});
30✔
155
  read_nd_tensor(xsdata_grp, "nu-fission", temp_nufiss, true);
30✔
156

157
  // Get beta (strategy will depend upon the number of dimensions in beta)
158
  hid_t beta_dset = open_dataset(xsdata_grp, "beta");
30✔
159
  int beta_ndims = dataset_ndims(beta_dset);
30✔
160
  close_dataset(beta_dset);
30✔
161
  int ndim_target = 1;
30✔
162
  if (!is_isotropic)
30!
UNCOV
163
    ndim_target += 2;
×
164
  if (beta_ndims == ndim_target) {
30✔
165
    tensor::Tensor<double> temp_beta = tensor::zeros<double>({n_ang, n_dg_});
20✔
166
    read_nd_tensor(xsdata_grp, "beta", temp_beta, true);
20✔
167

168
    // prompt_nu_fission = (1 - sum_of_beta) * nu_fission
169
    auto beta_sum = temp_beta.sum(1);
20✔
170
    for (size_t a = 0; a < n_ang; a++)
40✔
171
      for (size_t g = 0; g < n_g_; g++)
60✔
172
        prompt_nu_fission(a, g) = temp_nufiss(a, g) * (1.0 - beta_sum(a));
40✔
173

174
    // Delayed nu-fission is the outer product of the delayed neutron
175
    // fraction (beta) and the fission production rate (nu-fission)
176
    for (size_t a = 0; a < n_ang; a++)
40✔
177
      for (size_t d = 0; d < n_dg_; d++)
100✔
178
        for (size_t g = 0; g < n_g_; g++)
240✔
179
          delayed_nu_fission(a, d, g) = temp_beta(a, d) * temp_nufiss(a, g);
160✔
180
  } else if (beta_ndims == ndim_target + 1) {
50!
181
    tensor::Tensor<double> temp_beta =
10✔
182
      tensor::zeros<double>({n_ang, n_dg_, n_g_});
10✔
183
    read_nd_tensor(xsdata_grp, "beta", temp_beta, true);
10✔
184

185
    // prompt_nu_fission = (1 - sum_of_beta) * nu_fission
186
    // Here beta is energy-dependent, so sum over delayed groups (axis 1)
187
    auto beta_sum = temp_beta.sum(1);
10✔
188
    for (size_t a = 0; a < n_ang; a++)
20✔
189
      for (size_t g = 0; g < n_g_; g++)
30✔
190
        prompt_nu_fission(a, g) = temp_nufiss(a, g) * (1.0 - beta_sum(a, g));
20✔
191

192
    // Delayed nu-fission: beta is already energy-dependent [n_ang, n_dg, n_g],
193
    // so scale each delayed group's beta by the total nu-fission for that group
194
    for (size_t a = 0; a < n_ang; a++)
20✔
195
      for (size_t d = 0; d < n_dg_; d++)
30✔
196
        for (size_t g = 0; g < n_g_; g++)
60✔
197
          delayed_nu_fission(a, d, g) = temp_beta(a, d, g) * temp_nufiss(a, g);
40✔
198
  }
20✔
199
}
60✔
200

201
void XsData::fission_vector_no_beta_from_hdf5(hid_t xsdata_grp, size_t n_ang)
10✔
202
{
203
  // Data is provided separately as prompt + delayed nu-fission and chi
204

205
  // Get chi-prompt
206
  tensor::Tensor<double> temp_chi_p = tensor::zeros<double>({n_ang, n_g_});
10✔
207
  read_nd_tensor(xsdata_grp, "chi-prompt", temp_chi_p, true);
10✔
208

209
  // Normalize prompt chi so it sums to 1 over outgoing groups for each angle
210
  for (size_t a = 0; a < n_ang; a++) {
20✔
211
    tensor::View<double> row = temp_chi_p.slice(a);
10✔
212
    row /= row.sum();
10✔
213
  }
10✔
214

215
  // Get chi-delayed
216
  tensor::Tensor<double> temp_chi_d =
10✔
217
    tensor::zeros<double>({n_ang, n_dg_, n_g_});
10✔
218
  read_nd_tensor(xsdata_grp, "chi-delayed", temp_chi_d, true);
10✔
219

220
  // Normalize delayed chi so it sums to 1 over outgoing groups for each
221
  // angle and delayed group
222
  for (size_t a = 0; a < n_ang; a++)
20✔
223
    for (size_t d = 0; d < n_dg_; d++) {
30✔
224
      tensor::View<double> row = temp_chi_d.slice(a, d);
20✔
225
      row /= row.sum();
20✔
226
    }
20✔
227

228
  // Replicate the prompt spectrum across all incoming groups
229
  for (size_t a = 0; a < n_ang; a++)
20✔
230
    for (size_t gin = 0; gin < n_g_; gin++)
30✔
231
      chi_prompt.slice(a, gin) = temp_chi_p.slice(a);
60✔
232

233
  // Replicate the delayed spectrum across all incoming groups
234
  for (size_t a = 0; a < n_ang; a++)
20✔
235
    for (size_t d = 0; d < n_dg_; d++)
30✔
236
      for (size_t gin = 0; gin < n_g_; gin++)
60✔
237
        chi_delayed.slice(a, d, gin) = temp_chi_d.slice(a, d);
120✔
238

239
  // Get prompt and delayed nu-fission directly
240
  read_nd_tensor(xsdata_grp, "prompt-nu-fission", prompt_nu_fission, true);
10✔
241
  read_nd_tensor(xsdata_grp, "delayed-nu-fission", delayed_nu_fission, true);
10✔
242
}
20✔
243

244
void XsData::fission_vector_no_delayed_from_hdf5(hid_t xsdata_grp, size_t n_ang)
707✔
245
{
246
  // No beta is provided and there is no prompt/delay distinction.
247
  // Therefore, the code only considers the data as prompt.
248

249
  // Get chi
250
  tensor::Tensor<double> temp_chi = tensor::zeros<double>({n_ang, n_g_});
707✔
251
  read_nd_tensor(xsdata_grp, "chi", temp_chi, true);
707✔
252

253
  // Normalize chi so it sums to 1 over outgoing groups for each angle
254
  for (size_t a = 0; a < n_ang; a++) {
1,474✔
255
    tensor::View<double> row = temp_chi.slice(a);
767✔
256
    row /= row.sum();
767✔
257
  }
767✔
258

259
  // Replicate the energy spectrum across all incoming groups
260
  for (size_t a = 0; a < n_ang; a++)
1,474✔
261
    for (size_t gin = 0; gin < n_g_; gin++)
3,886✔
262
      chi_prompt.slice(a, gin) = temp_chi.slice(a);
9,357✔
263

264
  // Get nu-fission directly
265
  read_nd_tensor(xsdata_grp, "nu-fission", prompt_nu_fission, true);
707✔
266
}
707✔
267

268
//==============================================================================
269

270
void XsData::fission_matrix_beta_from_hdf5(
20✔
271
  hid_t xsdata_grp, size_t n_ang, bool is_isotropic)
272
{
273
  // Data is provided as nu-fission and chi with a beta for delayed info
274

275
  // Get nu-fission matrix
276
  tensor::Tensor<double> temp_matrix =
20✔
277
    tensor::zeros<double>({n_ang, n_g_, n_g_});
20✔
278
  read_nd_tensor(xsdata_grp, "nu-fission", temp_matrix, true);
20✔
279

280
  // Get beta (strategy will depend upon the number of dimensions in beta)
281
  hid_t beta_dset = open_dataset(xsdata_grp, "beta");
20✔
282
  int beta_ndims = dataset_ndims(beta_dset);
20✔
283
  close_dataset(beta_dset);
20✔
284
  int ndim_target = 1;
20✔
285
  if (!is_isotropic)
20!
UNCOV
286
    ndim_target += 2;
×
287
  if (beta_ndims == ndim_target) {
20✔
288
    tensor::Tensor<double> temp_beta = tensor::zeros<double>({n_ang, n_dg_});
10✔
289
    read_nd_tensor(xsdata_grp, "beta", temp_beta, true);
10✔
290

291
    auto beta_sum = temp_beta.sum(1);
10✔
292
    auto matrix_gout_sum = temp_matrix.sum(2);
10✔
293

294
    // prompt_nu_fission = sum_gout(matrix) * (1 - beta_total)
295
    for (size_t a = 0; a < n_ang; a++)
20✔
296
      for (size_t g = 0; g < n_g_; g++)
30✔
297
        prompt_nu_fission(a, g) = matrix_gout_sum(a, g) * (1.0 - beta_sum(a));
20✔
298

299
    // chi_prompt = (1 - beta_total) * nu-fission matrix (unnormalized)
300
    for (size_t a = 0; a < n_ang; a++)
20✔
301
      for (size_t gin = 0; gin < n_g_; gin++)
30✔
302
        for (size_t gout = 0; gout < n_g_; gout++)
60✔
303
          chi_prompt(a, gin, gout) =
40✔
304
            (1.0 - beta_sum(a)) * temp_matrix(a, gin, gout);
40✔
305

306
    // Delayed nu-fission is the outer product of the delayed neutron
307
    // fraction (beta) and the total fission rate summed over outgoing groups
308
    for (size_t a = 0; a < n_ang; a++)
20✔
309
      for (size_t d = 0; d < n_dg_; d++)
30✔
310
        for (size_t g = 0; g < n_g_; g++)
60✔
311
          delayed_nu_fission(a, d, g) = temp_beta(a, d) * matrix_gout_sum(a, g);
40✔
312

313
    // chi_delayed = beta * nu-fission matrix, expanded across delayed groups
314
    for (size_t a = 0; a < n_ang; a++)
20✔
315
      for (size_t d = 0; d < n_dg_; d++)
30✔
316
        for (size_t gin = 0; gin < n_g_; gin++)
60✔
317
          for (size_t gout = 0; gout < n_g_; gout++)
120✔
318
            chi_delayed(a, d, gin, gout) =
80✔
319
              temp_beta(a, d) * temp_matrix(a, gin, gout);
80✔
320

321
  } else if (beta_ndims == ndim_target + 1) {
40!
322
    tensor::Tensor<double> temp_beta =
10✔
323
      tensor::zeros<double>({n_ang, n_dg_, n_g_});
10✔
324
    read_nd_tensor(xsdata_grp, "beta", temp_beta, true);
10✔
325

326
    auto beta_sum = temp_beta.sum(1);
10✔
327
    auto matrix_gout_sum = temp_matrix.sum(2);
10✔
328

329
    // prompt_nu_fission = sum_gout(matrix) * (1 - beta_total)
330
    // Here beta is energy-dependent, so beta_sum is 2D [n_ang, n_g]
331
    for (size_t a = 0; a < n_ang; a++)
20✔
332
      for (size_t g = 0; g < n_g_; g++)
30✔
333
        prompt_nu_fission(a, g) =
20✔
334
          matrix_gout_sum(a, g) * (1.0 - beta_sum(a, g));
20✔
335

336
    // chi_prompt = (1 - beta_sum) * nu-fission matrix (unnormalized)
337
    for (size_t a = 0; a < n_ang; a++)
20✔
338
      for (size_t gin = 0; gin < n_g_; gin++)
30✔
339
        for (size_t gout = 0; gout < n_g_; gout++)
60✔
340
          chi_prompt(a, gin, gout) =
40✔
341
            (1.0 - beta_sum(a, gin)) * temp_matrix(a, gin, gout);
40✔
342

343
    // Delayed nu-fission: beta is energy-dependent [n_ang, n_dg, n_g],
344
    // scale by total fission rate summed over outgoing groups
345
    for (size_t a = 0; a < n_ang; a++)
20✔
346
      for (size_t d = 0; d < n_dg_; d++)
30✔
347
        for (size_t g = 0; g < n_g_; g++)
60✔
348
          delayed_nu_fission(a, d, g) =
40✔
349
            temp_beta(a, d, g) * matrix_gout_sum(a, g);
40✔
350

351
    // chi_delayed = beta * nu-fission matrix, expanded across delayed groups
352
    for (size_t a = 0; a < n_ang; a++)
20✔
353
      for (size_t d = 0; d < n_dg_; d++)
30✔
354
        for (size_t gin = 0; gin < n_g_; gin++)
60✔
355
          for (size_t gout = 0; gout < n_g_; gout++)
120✔
356
            chi_delayed(a, d, gin, gout) =
80✔
357
              temp_beta(a, d, gin) * temp_matrix(a, gin, gout);
80✔
358
  }
30✔
359

360
  // Normalize chi_prompt so it sums to 1 over outgoing groups
361
  for (size_t a = 0; a < n_ang; a++)
40✔
362
    for (size_t gin = 0; gin < n_g_; gin++) {
60✔
363
      tensor::View<double> row = chi_prompt.slice(a, gin);
40✔
364
      row /= row.sum();
40✔
365
    }
40✔
366

367
  // Normalize chi_delayed so it sums to 1 over outgoing groups
368
  for (size_t a = 0; a < n_ang; a++)
40✔
369
    for (size_t d = 0; d < n_dg_; d++)
60✔
370
      for (size_t gin = 0; gin < n_g_; gin++) {
120✔
371
        tensor::View<double> row = chi_delayed.slice(a, d, gin);
80✔
372
        row /= row.sum();
80✔
373
      }
80✔
374
}
20✔
375

376
void XsData::fission_matrix_no_beta_from_hdf5(hid_t xsdata_grp, size_t n_ang)
10✔
377
{
378
  // Data is provided separately as prompt + delayed nu-fission and chi
379

380
  // Get the prompt nu-fission matrix
381
  tensor::Tensor<double> temp_matrix_p =
10✔
382
    tensor::zeros<double>({n_ang, n_g_, n_g_});
10✔
383
  read_nd_tensor(xsdata_grp, "prompt-nu-fission", temp_matrix_p, true);
10✔
384

385
  // prompt_nu_fission is the sum over outgoing groups
386
  prompt_nu_fission = temp_matrix_p.sum(2);
10✔
387

388
  // chi_prompt is the nu-fission matrix normalized over outgoing groups
389
  for (size_t a = 0; a < n_ang; a++)
20✔
390
    for (size_t gin = 0; gin < n_g_; gin++)
30✔
391
      for (size_t gout = 0; gout < n_g_; gout++)
60✔
392
        chi_prompt(a, gin, gout) =
40✔
393
          temp_matrix_p(a, gin, gout) / prompt_nu_fission(a, gin);
40✔
394

395
  // Get the delayed nu-fission matrix
396
  tensor::Tensor<double> temp_matrix_d =
10✔
397
    tensor::zeros<double>({n_ang, n_dg_, n_g_, n_g_});
10✔
398
  read_nd_tensor(xsdata_grp, "delayed-nu-fission", temp_matrix_d, true);
10✔
399

400
  // delayed_nu_fission is the sum over outgoing groups
401
  delayed_nu_fission = temp_matrix_d.sum(3);
10✔
402

403
  // chi_delayed is the delayed nu-fission matrix normalized over outgoing
404
  // groups
405
  for (size_t a = 0; a < n_ang; a++)
20✔
406
    for (size_t d = 0; d < n_dg_; d++)
30✔
407
      for (size_t gin = 0; gin < n_g_; gin++)
60✔
408
        for (size_t gout = 0; gout < n_g_; gout++)
120✔
409
          chi_delayed(a, d, gin, gout) =
80✔
410
            temp_matrix_d(a, d, gin, gout) / delayed_nu_fission(a, d, gin);
80✔
411
}
20✔
412

413
void XsData::fission_matrix_no_delayed_from_hdf5(hid_t xsdata_grp, size_t n_ang)
40✔
414
{
415
  // No beta is provided and there is no prompt/delay distinction.
416
  // Therefore, the code only considers the data as prompt.
417

418
  // Get nu-fission matrix
419
  tensor::Tensor<double> temp_matrix =
40✔
420
    tensor::zeros<double>({n_ang, n_g_, n_g_});
40✔
421
  read_nd_tensor(xsdata_grp, "nu-fission", temp_matrix, true);
40✔
422

423
  // prompt_nu_fission is the sum over outgoing groups
424
  prompt_nu_fission = temp_matrix.sum(2);
40✔
425

426
  // chi_prompt is the nu-fission matrix normalized over outgoing groups
427
  for (size_t a = 0; a < n_ang; a++)
80✔
428
    for (size_t gin = 0; gin < n_g_; gin++)
120✔
429
      for (size_t gout = 0; gout < n_g_; gout++)
240✔
430
        chi_prompt(a, gin, gout) =
160✔
431
          temp_matrix(a, gin, gout) / prompt_nu_fission(a, gin);
160✔
432
}
40✔
433

434
//==============================================================================
435

436
void XsData::fission_from_hdf5(
817✔
437
  hid_t xsdata_grp, size_t n_ang, bool is_isotropic)
438
{
439
  // Get the fission and kappa_fission data xs; these are optional
440
  read_nd_tensor(xsdata_grp, "fission", fission);
817✔
441
  read_nd_tensor(xsdata_grp, "kappa-fission", kappa_fission);
817✔
442

443
  // Get the data; the strategy for doing so depends on if the data is provided
444
  // as a nu-fission matrix or a set of chi and nu-fission vectors
445
  if (object_exists(xsdata_grp, "chi") ||
897✔
446
      object_exists(xsdata_grp, "chi-prompt")) {
80✔
447
    if (n_dg_ == 0) {
747✔
448
      fission_vector_no_delayed_from_hdf5(xsdata_grp, n_ang);
707✔
449
    } else {
450
      if (object_exists(xsdata_grp, "beta")) {
40✔
451
        fission_vector_beta_from_hdf5(xsdata_grp, n_ang, is_isotropic);
30✔
452
      } else {
453
        fission_vector_no_beta_from_hdf5(xsdata_grp, n_ang);
10✔
454
      }
455
    }
456
  } else {
457
    if (n_dg_ == 0) {
70✔
458
      fission_matrix_no_delayed_from_hdf5(xsdata_grp, n_ang);
40✔
459
    } else {
460
      if (object_exists(xsdata_grp, "beta")) {
30✔
461
        fission_matrix_beta_from_hdf5(xsdata_grp, n_ang, is_isotropic);
20✔
462
      } else {
463
        fission_matrix_no_beta_from_hdf5(xsdata_grp, n_ang);
10✔
464
      }
465
    }
466
  }
467

468
  // Combine prompt_nu_fission and delayed_nu_fission into nu_fission
469
  if (n_dg_ == 0) {
817✔
470
    nu_fission = prompt_nu_fission;
747✔
471
  } else {
472
    nu_fission = prompt_nu_fission + delayed_nu_fission.sum(1);
210✔
473
  }
474
}
817✔
475

476
//==============================================================================
477

478
void XsData::scatter_from_hdf5(hid_t xsdata_grp, size_t n_ang,
2,240✔
479
  AngleDistributionType scatter_format,
480
  AngleDistributionType final_scatter_format, int order_data)
481
{
482
  if (!object_exists(xsdata_grp, "scatter_data")) {
2,240!
UNCOV
483
    fatal_error("Must provide scatter_data group!");
×
484
  }
485
  hid_t scatt_grp = open_group(xsdata_grp, "scatter_data");
2,240✔
486

487
  // Get the outgoing group boundary indices
488
  tensor::Tensor<int> gmin = tensor::zeros<int>({n_ang, n_g_});
2,240✔
489
  read_nd_tensor(scatt_grp, "g_min", gmin, true);
2,240✔
490
  tensor::Tensor<int> gmax = tensor::zeros<int>({n_ang, n_g_});
2,240✔
491
  read_nd_tensor(scatt_grp, "g_max", gmax, true);
2,240✔
492

493
  // Make gmin and gmax start from 0 vice 1 as they do in the library
494
  gmin -= 1;
2,240✔
495
  gmax -= 1;
2,240✔
496

497
  // Now use this info to find the length of a vector to hold the flattened
498
  // data.
499
  size_t length = order_data * (gmax - gmin + 1).sum();
4,480✔
500

501
  double_4dvec input_scatt(n_ang, double_3dvec(n_g_));
3,148✔
502
  tensor::Tensor<double> temp_arr = tensor::zeros<double>({length});
2,240✔
503
  read_nd_tensor(scatt_grp, "scatter_matrix", temp_arr, true);
2,240✔
504

505
  // Compare the number of orders given with the max order of the problem;
506
  // strip off the superfluous orders if needed
507
  int order_dim;
2,240✔
508
  if (scatter_format == AngleDistributionType::LEGENDRE) {
2,240✔
509
    order_dim = std::min(order_data - 1, settings::max_order) + 1;
2,170✔
510
  } else {
511
    order_dim = order_data;
512
  }
513

514
  // convert the flattened temp_arr to a jagged array for passing to
515
  // scatt data
516
  size_t temp_idx = 0;
2,240✔
517
  for (size_t a = 0; a < n_ang; a++) {
4,540✔
518
    for (size_t gin = 0; gin < n_g_; gin++) {
10,124✔
519
      input_scatt[a][gin].resize(gmax(a, gin) - gmin(a, gin) + 1);
7,824✔
520
      for (size_t i_gout = 0; i_gout < input_scatt[a][gin].size(); i_gout++) {
41,062✔
521
        input_scatt[a][gin][i_gout].resize(order_dim);
33,238✔
522
        for (size_t l = 0; l < order_dim; l++) {
73,166✔
523
          input_scatt[a][gin][i_gout][l] = temp_arr[temp_idx++];
39,928✔
524
        }
525
        // Adjust index for the orders we didnt take
526
        temp_idx += (order_data - order_dim);
33,238✔
527
      }
528
    }
529
  }
530

531
  // Get multiplication matrix
532
  double_3dvec temp_mult(n_ang, double_2dvec(n_g_));
3,148✔
533
  if (object_exists(scatt_grp, "multiplicity_matrix")) {
2,240✔
534
    temp_arr.resize({length / order_data});
480✔
535
    read_nd_tensor(scatt_grp, "multiplicity_matrix", temp_arr);
480✔
536

537
    // convert the flat temp_arr to a jagged array for passing to scatt data
538
    size_t temp_idx = 0;
539
    for (size_t a = 0; a < n_ang; a++) {
960✔
540
      for (size_t gin = 0; gin < n_g_; gin++) {
4,200✔
541
        temp_mult[a][gin].resize(gmax(a, gin) - gmin(a, gin) + 1);
3,720✔
542
        for (size_t i_gout = 0; i_gout < temp_mult[a][gin].size(); i_gout++) {
28,050✔
543
          temp_mult[a][gin][i_gout] = temp_arr[temp_idx++];
24,330✔
544
        }
545
      }
546
    }
547
  } else {
548
    // Use a default: multiplicities are 1.0.
549
    for (size_t a = 0; a < n_ang; a++) {
3,580✔
550
      for (size_t gin = 0; gin < n_g_; gin++) {
5,924✔
551
        temp_mult[a][gin].resize(gmax(a, gin) - gmin(a, gin) + 1);
4,104✔
552
        for (size_t i_gout = 0; i_gout < temp_mult[a][gin].size(); i_gout++) {
13,012✔
553
          temp_mult[a][gin][i_gout] = 1.;
8,908✔
554
        }
555
      }
556
    }
557
  }
558
  close_group(scatt_grp);
2,240✔
559

560
  // Finally, convert the Legendre data to tabular, if needed
561
  if (scatter_format == AngleDistributionType::LEGENDRE &&
2,240✔
562
      final_scatter_format == AngleDistributionType::TABULAR) {
2,240✔
563
    for (size_t a = 0; a < n_ang; a++) {
4,070✔
564
      ScattDataLegendre legendre_scatt;
2,050✔
565
      tensor::Tensor<int> in_gmin(gmin.slice(a));
2,050✔
566
      tensor::Tensor<int> in_gmax(gmax.slice(a));
2,050✔
567

568
      legendre_scatt.init(in_gmin, in_gmax, temp_mult[a], input_scatt[a]);
2,050✔
569

570
      // Now create a tabular version of legendre_scatt
571
      convert_legendre_to_tabular(
2,050✔
572
        legendre_scatt, *static_cast<ScattDataTabular*>(scatter[a].get()));
2,050✔
573

574
      scatter_format = final_scatter_format;
2,050✔
575
    }
4,100✔
576
  } else {
577
    // We are sticking with the current representation
578
    // Initialize the ScattData object with this data
579
    for (size_t a = 0; a < n_ang; a++) {
470✔
580
      tensor::Tensor<int> in_gmin(gmin.slice(a));
250✔
581
      tensor::Tensor<int> in_gmax(gmax.slice(a));
250✔
582
      scatter[a]->init(in_gmin, in_gmax, temp_mult[a], input_scatt[a]);
250✔
583
    }
500✔
584
  }
585
}
8,960✔
586

587
//==============================================================================
588

589
void XsData::combine(
1,890✔
590
  const vector<XsData*>& those_xs, const vector<double>& scalars)
591
{
592
  // Combine the non-scattering data
593
  for (size_t i = 0; i < those_xs.size(); i++) {
4,140✔
594
    XsData* that = those_xs[i];
2,250✔
595
    if (!equiv(*that))
2,250!
UNCOV
596
      fatal_error("Cannot combine the XsData objects!");
×
597
    double scalar = scalars[i];
2,250✔
598
    total += scalar * that->total;
2,250✔
599
    absorption += scalar * that->absorption;
2,250✔
600
    if (i == 0) {
2,250✔
601
      inverse_velocity = that->inverse_velocity;
1,890✔
602
    }
603
    if (!that->prompt_nu_fission.empty()) {
2,250✔
604
      nu_fission += scalar * that->nu_fission;
827✔
605
      prompt_nu_fission += scalar * that->prompt_nu_fission;
827✔
606
      kappa_fission += scalar * that->kappa_fission;
827✔
607
      fission += scalar * that->fission;
827✔
608
      delayed_nu_fission += scalar * that->delayed_nu_fission;
827✔
609
      // Accumulate chi_prompt weighted by total prompt nu-fission
610
      // (summed over energy groups) for this constituent
611
      {
827✔
612
        auto pnf_sum = that->prompt_nu_fission.sum(1);
827✔
613
        size_t n_ang = chi_prompt.shape(0);
827!
614
        size_t n_g = chi_prompt.shape(1);
827!
615
        for (size_t a = 0; a < n_ang; a++)
1,714✔
616
          for (size_t gin = 0; gin < n_g; gin++)
4,246✔
617
            for (size_t gout = 0; gout < n_g; gout++)
64,372✔
618
              chi_prompt(a, gin, gout) +=
61,013✔
619
                scalar * pnf_sum(a) * that->chi_prompt(a, gin, gout);
61,013✔
620
      }
827✔
621
      // Accumulate chi_delayed weighted by total delayed nu-fission
622
      // (summed over energy groups) for this constituent
623
      {
827✔
624
        auto dnf_sum = that->delayed_nu_fission.sum(2);
827✔
625
        size_t n_ang = chi_delayed.shape(0);
827!
626
        size_t n_dg = chi_delayed.shape(1);
827!
627
        size_t n_g = chi_delayed.shape(2);
827!
628
        for (size_t a = 0; a < n_ang; a++)
1,714✔
629
          for (size_t d = 0; d < n_dg; d++)
1,067✔
630
            for (size_t gin = 0; gin < n_g; gin++)
540✔
631
              for (size_t gout = 0; gout < n_g; gout++)
1,080✔
632
                chi_delayed(a, d, gin, gout) +=
720✔
633
                  scalar * dnf_sum(a, d) * that->chi_delayed(a, d, gin, gout);
720✔
634
      }
827✔
635
    }
636
    decay_rate += scalar * that->decay_rate;
4,500✔
637
  }
638

639
  // Normalize chi_prompt so it sums to 1 over outgoing groups
640
  {
1,890✔
641
    size_t n_ang = chi_prompt.shape(0);
1,890✔
642
    size_t n_g = chi_prompt.shape(1);
1,890✔
643
    for (size_t a = 0; a < n_ang; a++)
2,657✔
644
      for (size_t gin = 0; gin < n_g; gin++) {
3,886✔
645
        tensor::View<double> row = chi_prompt.slice(a, gin);
3,119✔
646
        row /= row.sum();
3,119✔
647
      }
3,119✔
648
  }
649
  // Normalize chi_delayed so it sums to 1 over outgoing groups
650
  {
1,890✔
651
    size_t n_ang = chi_delayed.shape(0);
1,890✔
652
    size_t n_dg = chi_delayed.shape(1);
1,890✔
653
    size_t n_g = chi_delayed.shape(2);
1,890✔
654
    for (size_t a = 0; a < n_ang; a++)
2,657✔
655
      for (size_t d = 0; d < n_dg; d++)
947✔
656
        for (size_t gin = 0; gin < n_g; gin++) {
540✔
657
          tensor::View<double> row = chi_delayed.slice(a, d, gin);
360✔
658
          row /= row.sum();
360✔
659
        }
360✔
660
  }
661

662
  // Allow the ScattData object to combine itself
663
  for (size_t a = 0; a < total.shape(0); a++) {
7,680!
664
    // Build vector of the scattering objects to incorporate
665
    vector<ScattData*> those_scatts(those_xs.size());
1,950✔
666
    for (size_t i = 0; i < those_xs.size(); i++) {
4,260✔
667
      those_scatts[i] = those_xs[i]->scatter[a].get();
2,310✔
668
    }
669

670
    // Now combine these guys
671
    scatter[a]->combine(those_scatts, scalars);
1,950✔
672
  }
1,950✔
673
}
1,890✔
674

675
//==============================================================================
676

677
bool XsData::equiv(const XsData& that)
2,250✔
678
{
679
  return (absorption.shape() == that.absorption.shape());
2,250✔
680
}
681

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