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

openmc-dev / openmc / 22210404096

20 Feb 2026 03:44AM UTC coverage: 81.804% (+0.08%) from 81.721%
22210404096

Pull #3809

github

web-flow
Merge d39f3220e into 53ce1910f
Pull Request #3809: Implement tally filter for filtering by reaction

17328 of 24423 branches covered (70.95%)

Branch coverage included in aggregate %.

125 of 149 new or added lines in 11 files covered. (83.89%)

1322 existing lines in 33 files now uncovered.

57670 of 67257 relevant lines covered (85.75%)

45506622.43 hits per line

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

96.8
/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,
5,788✔
24
  int n_pol, int n_azi, size_t n_groups, size_t n_d_groups)
5,788✔
25
  : n_g_(n_groups), n_dg_(n_d_groups)
5,788✔
26
{
27
  size_t n_ang = n_pol * n_azi;
5,788✔
28

29
  // check to make sure scatter format is OK before we allocate
30
  if (scatter_format != AngleDistributionType::HISTOGRAM &&
5,788✔
31
      scatter_format != AngleDistributionType::TABULAR &&
392!
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_};
5,788✔
37
  total = tensor::zeros<double>(shape);
5,788✔
38
  absorption = tensor::zeros<double>(shape);
5,788✔
39
  inverse_velocity = tensor::zeros<double>(shape);
5,788✔
40
  if (fissionable) {
5,788✔
41
    fission = tensor::zeros<double>(shape);
2,134✔
42
    nu_fission = tensor::zeros<double>(shape);
2,134✔
43
    prompt_nu_fission = tensor::zeros<double>(shape);
2,134✔
44
    kappa_fission = tensor::zeros<double>(shape);
2,134✔
45
  }
46

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

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

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

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

65
  for (int a = 0; a < n_ang; a++) {
11,744✔
66
    if (scatter_format == AngleDistributionType::HISTOGRAM) {
5,956✔
67
      scatter.emplace_back(new ScattDataHistogram);
112✔
68
    } else if (scatter_format == AngleDistributionType::TABULAR) {
5,844✔
69
      scatter.emplace_back(new ScattDataTabular);
5,368✔
70
    } else if (scatter_format == AngleDistributionType::LEGENDRE) {
476!
71
      scatter.emplace_back(new ScattDataLegendre);
476✔
72
    }
73
  }
74
}
5,788✔
75

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

78
void XsData::from_hdf5(hid_t xsdata_grp, bool fissionable,
3,139✔
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;
3,139✔
85
  size_t energy_groups = total.shape(1);
3,139✔
86

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

96
  // Get scattering data
97
  scatter_from_hdf5(
3,139✔
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++)
14,099✔
103
    if (absorption.data()[i] == 0.0)
10,960!
UNCOV
104
      absorption.data()[i] = 1.e-10;
×
105

106
  // Get or calculate the total x/s
107
  if (object_exists(xsdata_grp, "total")) {
3,139!
108
    read_nd_tensor(xsdata_grp, "total", total);
3,139✔
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++)
14,099✔
120
    if (total.data()[i] == 0.0)
10,960!
UNCOV
121
      total.data()[i] = 1.e-10;
×
122
}
3,139✔
123

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

126
void XsData::fission_vector_beta_from_hdf5(
42✔
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_});
42✔
133
  read_nd_tensor(xsdata_grp, "chi", temp_chi, true);
42✔
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++) {
84✔
137
    tensor::View<double> row = temp_chi.slice(a);
42✔
138
    row /= row.sum();
42✔
139
  }
42✔
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++)
84✔
144
    for (size_t gin = 0; gin < n_g_; gin++)
126✔
145
      chi_prompt.slice(a, gin) = temp_chi.slice(a);
84✔
146

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

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

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

168
    // prompt_nu_fission = (1 - sum_of_beta) * nu_fission
169
    auto beta_sum = temp_beta.sum(1);
28✔
170
    for (size_t a = 0; a < n_ang; a++)
56✔
171
      for (size_t g = 0; g < n_g_; g++)
84✔
172
        prompt_nu_fission(a, g) = temp_nufiss(a, g) * (1.0 - beta_sum(a));
56✔
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++)
56✔
177
      for (size_t d = 0; d < n_dg_; d++)
140✔
178
        for (size_t g = 0; g < n_g_; g++)
336✔
179
          delayed_nu_fission(a, d, g) = temp_beta(a, d) * temp_nufiss(a, g);
224✔
180
  } else if (beta_ndims == ndim_target + 1) {
42!
181
    tensor::Tensor<double> temp_beta =
182
      tensor::zeros<double>({n_ang, n_dg_, n_g_});
14✔
183
    read_nd_tensor(xsdata_grp, "beta", temp_beta, true);
14✔
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);
14✔
188
    for (size_t a = 0; a < n_ang; a++)
28✔
189
      for (size_t g = 0; g < n_g_; g++)
42✔
190
        prompt_nu_fission(a, g) = temp_nufiss(a, g) * (1.0 - beta_sum(a, g));
28✔
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++)
28✔
195
      for (size_t d = 0; d < n_dg_; d++)
42✔
196
        for (size_t g = 0; g < n_g_; g++)
84✔
197
          delayed_nu_fission(a, d, g) = temp_beta(a, d, g) * temp_nufiss(a, g);
56✔
198
  }
14✔
199
}
42✔
200

201
void XsData::fission_vector_no_beta_from_hdf5(hid_t xsdata_grp, size_t n_ang)
14✔
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_});
14✔
207
  read_nd_tensor(xsdata_grp, "chi-prompt", temp_chi_p, true);
14✔
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++) {
28✔
211
    tensor::View<double> row = temp_chi_p.slice(a);
14✔
212
    row /= row.sum();
14✔
213
  }
14✔
214

215
  // Get chi-delayed
216
  tensor::Tensor<double> temp_chi_d =
217
    tensor::zeros<double>({n_ang, n_dg_, n_g_});
14✔
218
  read_nd_tensor(xsdata_grp, "chi-delayed", temp_chi_d, true);
14✔
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++)
28✔
223
    for (size_t d = 0; d < n_dg_; d++) {
42✔
224
      tensor::View<double> row = temp_chi_d.slice(a, d);
28✔
225
      row /= row.sum();
28✔
226
    }
28✔
227

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

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

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

244
void XsData::fission_vector_no_delayed_from_hdf5(hid_t xsdata_grp, size_t n_ang)
990✔
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_});
990✔
251
  read_nd_tensor(xsdata_grp, "chi", temp_chi, true);
990✔
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++) {
2,064✔
255
    tensor::View<double> row = temp_chi.slice(a);
1,074✔
256
    row /= row.sum();
1,074✔
257
  }
1,074✔
258

259
  // Replicate the energy spectrum across all incoming groups
260
  for (size_t a = 0; a < n_ang; a++)
2,064✔
261
    for (size_t gin = 0; gin < n_g_; gin++)
5,442✔
262
      chi_prompt.slice(a, gin) = temp_chi.slice(a);
4,368✔
263

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

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

270
void XsData::fission_matrix_beta_from_hdf5(
28✔
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 =
277
    tensor::zeros<double>({n_ang, n_g_, n_g_});
28✔
278
  read_nd_tensor(xsdata_grp, "nu-fission", temp_matrix, true);
28✔
279

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

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

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

299
    // chi_prompt = (1 - beta_total) * nu-fission matrix (unnormalized)
300
    for (size_t a = 0; a < n_ang; a++)
28✔
301
      for (size_t gin = 0; gin < n_g_; gin++)
42✔
302
        for (size_t gout = 0; gout < n_g_; gout++)
84✔
303
          chi_prompt(a, gin, gout) =
56✔
304
            (1.0 - beta_sum(a)) * temp_matrix(a, gin, gout);
56✔
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++)
28✔
309
      for (size_t d = 0; d < n_dg_; d++)
42✔
310
        for (size_t g = 0; g < n_g_; g++)
84✔
311
          delayed_nu_fission(a, d, g) = temp_beta(a, d) * matrix_gout_sum(a, g);
56✔
312

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

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

326
    auto beta_sum = temp_beta.sum(1);
14✔
327
    auto matrix_gout_sum = temp_matrix.sum(2);
14✔
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++)
28✔
332
      for (size_t g = 0; g < n_g_; g++)
42✔
333
        prompt_nu_fission(a, g) =
28✔
334
          matrix_gout_sum(a, g) * (1.0 - beta_sum(a, g));
28✔
335

336
    // chi_prompt = (1 - beta_sum) * nu-fission matrix (unnormalized)
337
    for (size_t a = 0; a < n_ang; a++)
28✔
338
      for (size_t gin = 0; gin < n_g_; gin++)
42✔
339
        for (size_t gout = 0; gout < n_g_; gout++)
84✔
340
          chi_prompt(a, gin, gout) =
56✔
341
            (1.0 - beta_sum(a, gin)) * temp_matrix(a, gin, gout);
56✔
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++)
28✔
346
      for (size_t d = 0; d < n_dg_; d++)
42✔
347
        for (size_t g = 0; g < n_g_; g++)
84✔
348
          delayed_nu_fission(a, d, g) =
56✔
349
            temp_beta(a, d, g) * matrix_gout_sum(a, g);
56✔
350

351
    // chi_delayed = beta * nu-fission matrix, expanded across delayed groups
352
    for (size_t a = 0; a < n_ang; a++)
28✔
353
      for (size_t d = 0; d < n_dg_; d++)
42✔
354
        for (size_t gin = 0; gin < n_g_; gin++)
84✔
355
          for (size_t gout = 0; gout < n_g_; gout++)
168✔
356
            chi_delayed(a, d, gin, gout) =
112✔
357
              temp_beta(a, d, gin) * temp_matrix(a, gin, gout);
112✔
358
  }
14✔
359

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

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

376
void XsData::fission_matrix_no_beta_from_hdf5(hid_t xsdata_grp, size_t n_ang)
14✔
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 =
382
    tensor::zeros<double>({n_ang, n_g_, n_g_});
14✔
383
  read_nd_tensor(xsdata_grp, "prompt-nu-fission", temp_matrix_p, true);
14✔
384

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

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

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

400
  // delayed_nu_fission is the sum over outgoing groups
401
  delayed_nu_fission = temp_matrix_d.sum(3);
14✔
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++)
28✔
406
    for (size_t d = 0; d < n_dg_; d++)
42✔
407
      for (size_t gin = 0; gin < n_g_; gin++)
84✔
408
        for (size_t gout = 0; gout < n_g_; gout++)
168✔
409
          chi_delayed(a, d, gin, gout) =
112✔
410
            temp_matrix_d(a, d, gin, gout) / delayed_nu_fission(a, d, gin);
112✔
411
}
14✔
412

413
void XsData::fission_matrix_no_delayed_from_hdf5(hid_t xsdata_grp, size_t n_ang)
56✔
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 =
420
    tensor::zeros<double>({n_ang, n_g_, n_g_});
56✔
421
  read_nd_tensor(xsdata_grp, "nu-fission", temp_matrix, true);
56✔
422

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

426
  // chi_prompt is the nu-fission matrix normalized over outgoing groups
427
  for (size_t a = 0; a < n_ang; a++)
112✔
428
    for (size_t gin = 0; gin < n_g_; gin++)
168✔
429
      for (size_t gout = 0; gout < n_g_; gout++)
336✔
430
        chi_prompt(a, gin, gout) =
224✔
431
          temp_matrix(a, gin, gout) / prompt_nu_fission(a, gin);
224✔
432
}
56✔
433

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

436
void XsData::fission_from_hdf5(
1,144✔
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);
1,144✔
441
  read_nd_tensor(xsdata_grp, "kappa-fission", kappa_fission);
1,144✔
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") ||
1,256✔
446
      object_exists(xsdata_grp, "chi-prompt")) {
112✔
447
    if (n_dg_ == 0) {
1,046✔
448
      fission_vector_no_delayed_from_hdf5(xsdata_grp, n_ang);
990✔
449
    } else {
450
      if (object_exists(xsdata_grp, "beta")) {
56✔
451
        fission_vector_beta_from_hdf5(xsdata_grp, n_ang, is_isotropic);
42✔
452
      } else {
453
        fission_vector_no_beta_from_hdf5(xsdata_grp, n_ang);
14✔
454
      }
455
    }
456
  } else {
457
    if (n_dg_ == 0) {
98✔
458
      fission_matrix_no_delayed_from_hdf5(xsdata_grp, n_ang);
56✔
459
    } else {
460
      if (object_exists(xsdata_grp, "beta")) {
42✔
461
        fission_matrix_beta_from_hdf5(xsdata_grp, n_ang, is_isotropic);
28✔
462
      } else {
463
        fission_matrix_no_beta_from_hdf5(xsdata_grp, n_ang);
14✔
464
      }
465
    }
466
  }
467

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

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

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

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

493
  // Make gmin and gmax start from 0 vice 1 as they do in the library
494
  gmin -= 1;
3,139✔
495
  gmax -= 1;
3,139✔
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();
3,139✔
500

501
  double_4dvec input_scatt(n_ang, double_3dvec(n_g_));
6,278✔
502
  tensor::Tensor<double> temp_arr = tensor::zeros<double>({length});
3,139✔
503
  read_nd_tensor(scatt_grp, "scatter_matrix", temp_arr, true);
3,139✔
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;
508
  if (scatter_format == AngleDistributionType::LEGENDRE) {
3,139✔
509
    order_dim = std::min(order_data - 1, settings::max_order) + 1;
3,027✔
510
  } else {
511
    order_dim = order_data;
112✔
512
  }
513

514
  // convert the flattened temp_arr to a jagged array for passing to
515
  // scatt data
516
  size_t temp_idx = 0;
3,139✔
517
  for (size_t a = 0; a < n_ang; a++) {
6,362✔
518
    for (size_t gin = 0; gin < n_g_; gin++) {
14,183✔
519
      input_scatt[a][gin].resize(gmax(a, gin) - gmin(a, gin) + 1);
10,960✔
520
      for (size_t i_gout = 0; i_gout < input_scatt[a][gin].size(); i_gout++) {
57,508✔
521
        input_scatt[a][gin][i_gout].resize(order_dim);
46,548✔
522
        for (size_t l = 0; l < order_dim; l++) {
102,462✔
523
          input_scatt[a][gin][i_gout][l] = temp_arr[temp_idx++];
55,914✔
524
        }
525
        // Adjust index for the orders we didnt take
526
        temp_idx += (order_data - order_dim);
46,548✔
527
      }
528
    }
529
  }
530

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

537
    // convert the flat temp_arr to a jagged array for passing to scatt data
538
    size_t temp_idx = 0;
673✔
539
    for (size_t a = 0; a < n_ang; a++) {
1,346✔
540
      for (size_t gin = 0; gin < n_g_; gin++) {
5,883✔
541
        temp_mult[a][gin].resize(gmax(a, gin) - gmin(a, gin) + 1);
5,210✔
542
        for (size_t i_gout = 0; i_gout < temp_mult[a][gin].size(); i_gout++) {
39,276✔
543
          temp_mult[a][gin][i_gout] = temp_arr[temp_idx++];
34,066✔
544
        }
545
      }
546
    }
547
  } else {
548
    // Use a default: multiplicities are 1.0.
549
    for (size_t a = 0; a < n_ang; a++) {
5,016✔
550
      for (size_t gin = 0; gin < n_g_; gin++) {
8,300✔
551
        temp_mult[a][gin].resize(gmax(a, gin) - gmin(a, gin) + 1);
5,750✔
552
        for (size_t i_gout = 0; i_gout < temp_mult[a][gin].size(); i_gout++) {
18,232✔
553
          temp_mult[a][gin][i_gout] = 1.;
12,482✔
554
        }
555
      }
556
    }
557
  }
558
  close_group(scatt_grp);
3,139✔
559

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

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

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

574
      scatter_format = final_scatter_format;
2,873✔
575
    }
2,873✔
576
  } else {
2,831✔
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++) {
658✔
580
      tensor::Tensor<int> in_gmin(gmin.slice(a));
350✔
581
      tensor::Tensor<int> in_gmax(gmax.slice(a));
350✔
582
      scatter[a]->init(in_gmin, in_gmax, temp_mult[a], input_scatt[a]);
350✔
583
    }
350✔
584
  }
585
}
3,139✔
586

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

589
void XsData::combine(
2,649✔
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++) {
5,802✔
594
    XsData* that = those_xs[i];
3,153✔
595
    if (!equiv(*that))
3,153!
UNCOV
596
      fatal_error("Cannot combine the XsData objects!");
×
597
    double scalar = scalars[i];
3,153✔
598
    total += scalar * that->total;
3,153✔
599
    absorption += scalar * that->absorption;
3,153✔
600
    if (i == 0) {
3,153✔
601
      inverse_velocity = that->inverse_velocity;
2,649✔
602
    }
603
    if (!that->prompt_nu_fission.empty()) {
3,153✔
604
      nu_fission += scalar * that->nu_fission;
1,158✔
605
      prompt_nu_fission += scalar * that->prompt_nu_fission;
1,158✔
606
      kappa_fission += scalar * that->kappa_fission;
1,158✔
607
      fission += scalar * that->fission;
1,158✔
608
      delayed_nu_fission += scalar * that->delayed_nu_fission;
1,158✔
609
      // Accumulate chi_prompt weighted by total prompt nu-fission
610
      // (summed over energy groups) for this constituent
611
      {
612
        auto pnf_sum = that->prompt_nu_fission.sum(1);
1,158✔
613
        size_t n_ang = chi_prompt.shape(0);
1,158✔
614
        size_t n_g = chi_prompt.shape(1);
1,158✔
615
        for (size_t a = 0; a < n_ang; a++)
2,400✔
616
          for (size_t gin = 0; gin < n_g; gin++)
5,946✔
617
            for (size_t gout = 0; gout < n_g; gout++)
90,132✔
618
              chi_prompt(a, gin, gout) +=
85,428✔
619
                scalar * pnf_sum(a) * that->chi_prompt(a, gin, gout);
85,428✔
620
      }
1,158✔
621
      // Accumulate chi_delayed weighted by total delayed nu-fission
622
      // (summed over energy groups) for this constituent
623
      {
624
        auto dnf_sum = that->delayed_nu_fission.sum(2);
1,158✔
625
        size_t n_ang = chi_delayed.shape(0);
1,158✔
626
        size_t n_dg = chi_delayed.shape(1);
1,158✔
627
        size_t n_g = chi_delayed.shape(2);
1,158✔
628
        for (size_t a = 0; a < n_ang; a++)
2,400✔
629
          for (size_t d = 0; d < n_dg; d++)
1,494✔
630
            for (size_t gin = 0; gin < n_g; gin++)
756✔
631
              for (size_t gout = 0; gout < n_g; gout++)
1,512✔
632
                chi_delayed(a, d, gin, gout) +=
1,008✔
633
                  scalar * dnf_sum(a, d) * that->chi_delayed(a, d, gin, gout);
1,008✔
634
      }
1,158✔
635
    }
636
    decay_rate += scalar * that->decay_rate;
3,153✔
637
  }
638

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

662
  // Allow the ScattData object to combine itself
663
  for (size_t a = 0; a < total.shape(0); a++) {
5,382✔
664
    // Build vector of the scattering objects to incorporate
665
    vector<ScattData*> those_scatts(those_xs.size());
2,733✔
666
    for (size_t i = 0; i < those_xs.size(); i++) {
5,970✔
667
      those_scatts[i] = those_xs[i]->scatter[a].get();
3,237✔
668
    }
669

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

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

677
bool XsData::equiv(const XsData& that)
3,153✔
678
{
679
  return (absorption.shape() == that.absorption.shape());
3,153✔
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