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

openmc-dev / openmc / 22109060455

17 Feb 2026 05:38PM UTC coverage: 81.693% (-0.03%) from 81.721%
22109060455

Pull #3813

github

web-flow
Merge d2d368c60 into 977ade79a
Pull Request #3813: Check for positive radii

16733 of 23304 branches covered (71.8%)

Branch coverage included in aggregate %.

4 of 11 new or added lines in 1 file covered. (36.36%)

1361 existing lines in 48 files now uncovered.

56648 of 66521 relevant lines covered (85.16%)

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

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

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

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

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

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

65
  for (int a = 0; a < n_ang; a++) {
10,032✔
66
    if (scatter_format == AngleDistributionType::HISTOGRAM) {
5,088✔
67
      scatter.emplace_back(new ScattDataHistogram);
96✔
68
    } else if (scatter_format == AngleDistributionType::TABULAR) {
4,992✔
69
      scatter.emplace_back(new ScattDataTabular);
4,584✔
70
    } else if (scatter_format == AngleDistributionType::LEGENDRE) {
408!
71
      scatter.emplace_back(new ScattDataLegendre);
408✔
72
    }
73
  }
74
}
4,944✔
75

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

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

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

96
  // Get scattering data
97
  scatter_from_hdf5(
2,682✔
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++)
12,072✔
103
    if (absorption.data()[i] == 0.0)
9,390!
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,682!
108
    read_nd_tensor(xsdata_grp, "total", total);
2,682✔
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++)
12,072✔
120
    if (total.data()[i] == 0.0)
9,390!
UNCOV
121
      total.data()[i] = 1.e-10;
×
122
}
2,682✔
123

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

270
void XsData::fission_matrix_beta_from_hdf5(
24✔
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_});
24✔
278
  read_nd_tensor(xsdata_grp, "nu-fission", temp_matrix, true);
24✔
279

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

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

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

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

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

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

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

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

351
    // chi_delayed = beta * nu-fission matrix, expanded across delayed groups
352
    for (size_t a = 0; a < n_ang; a++)
24✔
353
      for (size_t d = 0; d < n_dg_; d++)
36✔
354
        for (size_t gin = 0; gin < n_g_; gin++)
72✔
355
          for (size_t gout = 0; gout < n_g_; gout++)
144✔
356
            chi_delayed(a, d, gin, gout) =
96✔
357
              temp_beta(a, d, gin) * temp_matrix(a, gin, gout);
96✔
358
  }
12✔
359

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

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

376
void XsData::fission_matrix_no_beta_from_hdf5(hid_t xsdata_grp, size_t n_ang)
12✔
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_});
12✔
383
  read_nd_tensor(xsdata_grp, "prompt-nu-fission", temp_matrix_p, true);
12✔
384

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

388
  // chi_prompt is the nu-fission matrix normalized over outgoing groups
389
  for (size_t a = 0; a < n_ang; a++)
24✔
390
    for (size_t gin = 0; gin < n_g_; gin++)
36✔
391
      for (size_t gout = 0; gout < n_g_; gout++)
72✔
392
        chi_prompt(a, gin, gout) =
48✔
393
          temp_matrix_p(a, gin, gout) / prompt_nu_fission(a, gin);
48✔
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_});
12✔
398
  read_nd_tensor(xsdata_grp, "delayed-nu-fission", temp_matrix_d, true);
12✔
399

400
  // delayed_nu_fission is the sum over outgoing groups
401
  delayed_nu_fission = temp_matrix_d.sum(3);
12✔
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++)
24✔
406
    for (size_t d = 0; d < n_dg_; d++)
36✔
407
      for (size_t gin = 0; gin < n_g_; gin++)
72✔
408
        for (size_t gout = 0; gout < n_g_; gout++)
144✔
409
          chi_delayed(a, d, gin, gout) =
96✔
410
            temp_matrix_d(a, d, gin, gout) / delayed_nu_fission(a, d, gin);
96✔
411
}
12✔
412

413
void XsData::fission_matrix_no_delayed_from_hdf5(hid_t xsdata_grp, size_t n_ang)
48✔
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_});
48✔
421
  read_nd_tensor(xsdata_grp, "nu-fission", temp_matrix, true);
48✔
422

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

426
  // chi_prompt is the nu-fission matrix normalized over outgoing groups
427
  for (size_t a = 0; a < n_ang; a++)
96✔
428
    for (size_t gin = 0; gin < n_g_; gin++)
144✔
429
      for (size_t gout = 0; gout < n_g_; gout++)
288✔
430
        chi_prompt(a, gin, gout) =
192✔
431
          temp_matrix(a, gin, gout) / prompt_nu_fission(a, gin);
192✔
432
}
48✔
433

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

436
void XsData::fission_from_hdf5(
981✔
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);
981✔
441
  read_nd_tensor(xsdata_grp, "kappa-fission", kappa_fission);
981✔
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,077✔
446
      object_exists(xsdata_grp, "chi-prompt")) {
96✔
447
    if (n_dg_ == 0) {
897✔
448
      fission_vector_no_delayed_from_hdf5(xsdata_grp, n_ang);
849✔
449
    } else {
450
      if (object_exists(xsdata_grp, "beta")) {
48✔
451
        fission_vector_beta_from_hdf5(xsdata_grp, n_ang, is_isotropic);
36✔
452
      } else {
453
        fission_vector_no_beta_from_hdf5(xsdata_grp, n_ang);
12✔
454
      }
455
    }
456
  } else {
457
    if (n_dg_ == 0) {
84✔
458
      fission_matrix_no_delayed_from_hdf5(xsdata_grp, n_ang);
48✔
459
    } else {
460
      if (object_exists(xsdata_grp, "beta")) {
36✔
461
        fission_matrix_beta_from_hdf5(xsdata_grp, n_ang, is_isotropic);
24✔
462
      } else {
463
        fission_matrix_no_beta_from_hdf5(xsdata_grp, n_ang);
12✔
464
      }
465
    }
466
  }
467

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

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

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

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

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

501
  double_4dvec input_scatt(n_ang, double_3dvec(n_g_));
5,364✔
502
  tensor::Tensor<double> temp_arr = tensor::zeros<double>({length});
2,682✔
503
  read_nd_tensor(scatt_grp, "scatter_matrix", temp_arr, true);
2,682✔
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) {
2,682✔
509
    order_dim = std::min(order_data - 1, settings::max_order) + 1;
2,586✔
510
  } else {
511
    order_dim = order_data;
96✔
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,682✔
517
  for (size_t a = 0; a < n_ang; a++) {
5,436✔
518
    for (size_t gin = 0; gin < n_g_; gin++) {
12,144✔
519
      input_scatt[a][gin].resize(gmax(a, gin) - gmin(a, gin) + 1);
9,390✔
520
      for (size_t i_gout = 0; i_gout < input_scatt[a][gin].size(); i_gout++) {
49,296✔
521
        input_scatt[a][gin][i_gout].resize(order_dim);
39,906✔
522
        for (size_t l = 0; l < order_dim; l++) {
87,840✔
523
          input_scatt[a][gin][i_gout][l] = temp_arr[temp_idx++];
47,934✔
524
        }
525
        // Adjust index for the orders we didnt take
526
        temp_idx += (order_data - order_dim);
39,906✔
527
      }
528
    }
529
  }
530

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

537
    // convert the flat temp_arr to a jagged array for passing to scatt data
538
    size_t temp_idx = 0;
576✔
539
    for (size_t a = 0; a < n_ang; a++) {
1,152✔
540
      for (size_t gin = 0; gin < n_g_; gin++) {
5,040✔
541
        temp_mult[a][gin].resize(gmax(a, gin) - gmin(a, gin) + 1);
4,464✔
542
        for (size_t i_gout = 0; i_gout < temp_mult[a][gin].size(); i_gout++) {
33,660✔
543
          temp_mult[a][gin][i_gout] = temp_arr[temp_idx++];
29,196✔
544
        }
545
      }
546
    }
547
  } else {
548
    // Use a default: multiplicities are 1.0.
549
    for (size_t a = 0; a < n_ang; a++) {
4,284✔
550
      for (size_t gin = 0; gin < n_g_; gin++) {
7,104✔
551
        temp_mult[a][gin].resize(gmax(a, gin) - gmin(a, gin) + 1);
4,926✔
552
        for (size_t i_gout = 0; i_gout < temp_mult[a][gin].size(); i_gout++) {
15,636✔
553
          temp_mult[a][gin][i_gout] = 1.;
10,710✔
554
        }
555
      }
556
    }
557
  }
558
  close_group(scatt_grp);
2,682✔
559

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

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

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

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

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

589
void XsData::combine(
2,262✔
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,956✔
594
    XsData* that = those_xs[i];
2,694✔
595
    if (!equiv(*that))
2,694!
UNCOV
596
      fatal_error("Cannot combine the XsData objects!");
×
597
    double scalar = scalars[i];
2,694✔
598
    total += scalar * that->total;
2,694✔
599
    absorption += scalar * that->absorption;
2,694✔
600
    if (i == 0) {
2,694✔
601
      inverse_velocity = that->inverse_velocity;
2,262✔
602
    }
603
    if (!that->prompt_nu_fission.empty()) {
2,694✔
604
      nu_fission += scalar * that->nu_fission;
993✔
605
      prompt_nu_fission += scalar * that->prompt_nu_fission;
993✔
606
      kappa_fission += scalar * that->kappa_fission;
993✔
607
      fission += scalar * that->fission;
993✔
608
      delayed_nu_fission += scalar * that->delayed_nu_fission;
993✔
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);
993✔
613
        size_t n_ang = chi_prompt.shape(0);
993✔
614
        size_t n_g = chi_prompt.shape(1);
993✔
615
        for (size_t a = 0; a < n_ang; a++)
2,058✔
616
          for (size_t gin = 0; gin < n_g; gin++)
5,100✔
617
            for (size_t gout = 0; gout < n_g; gout++)
77,280✔
618
              chi_prompt(a, gin, gout) +=
73,245✔
619
                scalar * pnf_sum(a) * that->chi_prompt(a, gin, gout);
73,245✔
620
      }
993✔
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);
993✔
625
        size_t n_ang = chi_delayed.shape(0);
993✔
626
        size_t n_dg = chi_delayed.shape(1);
993✔
627
        size_t n_g = chi_delayed.shape(2);
993✔
628
        for (size_t a = 0; a < n_ang; a++)
2,058✔
629
          for (size_t d = 0; d < n_dg; d++)
1,281✔
630
            for (size_t gin = 0; gin < n_g; gin++)
648✔
631
              for (size_t gout = 0; gout < n_g; gout++)
1,296✔
632
                chi_delayed(a, d, gin, gout) +=
864✔
633
                  scalar * dnf_sum(a, d) * that->chi_delayed(a, d, gin, gout);
864✔
634
      }
993✔
635
    }
636
    decay_rate += scalar * that->decay_rate;
2,694✔
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,262✔
642
    size_t n_g = chi_prompt.shape(1);
2,262✔
643
    for (size_t a = 0; a < n_ang; a++)
3,183✔
644
      for (size_t gin = 0; gin < n_g; gin++) {
4,668✔
645
        tensor::View<double> row = chi_prompt.slice(a, gin);
3,747✔
646
        row /= row.sum();
3,747✔
647
      }
3,747✔
648
  }
649
  // Normalize chi_delayed so it sums to 1 over outgoing groups
650
  {
651
    size_t n_ang = chi_delayed.shape(0);
2,262✔
652
    size_t n_dg = chi_delayed.shape(1);
2,262✔
653
    size_t n_g = chi_delayed.shape(2);
2,262✔
654
    for (size_t a = 0; a < n_ang; a++)
3,183✔
655
      for (size_t d = 0; d < n_dg; d++)
1,137✔
656
        for (size_t gin = 0; gin < n_g; gin++) {
648✔
657
          tensor::View<double> row = chi_delayed.slice(a, d, gin);
432✔
658
          row /= row.sum();
432✔
659
        }
432✔
660
  }
661

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

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

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

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