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

openmc-dev / openmc / 30830380864

03 Aug 2026 04:03PM UTC coverage: 81.48% (+0.05%) from 81.429%
30830380864

Pull #3971

github

web-flow
Merge 13d0297e2 into 5982acdf8
Pull Request #3971: Delta tracking

18827 of 27241 branches covered (69.11%)

Branch coverage included in aggregate %.

597 of 645 new or added lines in 20 files covered. (92.56%)

60852 of 70549 relevant lines covered (86.25%)

50385682.17 hits per line

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

85.86
/src/majorant.cpp
1
#include <fmt/core.h>
2

3
#include "openmc/capi.h"
4
#include "openmc/constants.h"
5
#include "openmc/geometry.h"
6
#include "openmc/interpolate.h"
7
#include "openmc/majorant.h"
8
#include "openmc/material.h"
9
#include "openmc/nuclide.h"
10
#include "openmc/photon.h"
11
#include "openmc/search.h"
12
#include "openmc/settings.h"
13
#include "openmc/simulation.h"
14
#include "openmc/thermal.h"
15
#include "openmc/timer.h"
16
#include "openmc/universe.h"
17

18
namespace openmc {
19

20
//==============================================================================
21
// Global variables
22
//==============================================================================
23

24
namespace data {
25
std::unique_ptr<NeutronMajorant> n_majorant;
26
std::unique_ptr<PhotonMajorant> p_majorant;
27

28
} // namespace data
29

30
//==============================================================================
31
// Majorant implementation
32
//==============================================================================
33

34
Majorant::Majorant(int i_universe) : maj_universe_(i_universe)
195!
35
{
36
  if (maj_universe_ == C_NONE || maj_universe_ >= model::universes.size()) {
195!
NEW
37
    fatal_error(fmt::format("Invalid majorant universe: {}", maj_universe_));
×
38
  }
39

40
  // First, find unique cells contained in this universe.
41
  std::unordered_set<int> unique_mat_cells;
195✔
42

43
  const auto& maj_uni = model::universes[maj_universe_];
195✔
44
  for (int i_cell : maj_uni->cells_) {
390✔
45
    const auto& uni_cell = model::cells[i_cell];
195!
46

47
    // If the cell is filled with a material, it won't have any sub-cells.
48
    if (uni_cell->type_ == Fill::MATERIAL) {
195!
NEW
49
      if (unique_mat_cells.count(i_cell) == 0) {
×
50
        unique_mat_cells.emplace(i_cell);
195!
51
      }
52
    } else {
53
      // This cell is filled with a universe or lattice. Need to get the list of
54
      // cells and cell instances.
55
      const auto contained_cells = uni_cell->get_contained_cells();
195✔
56
      for (const auto& [i_con_cell, contained_instances] : contained_cells) {
585!
57
        if (unique_mat_cells.count(i_con_cell) == 0) {
390!
58
          unique_mat_cells.emplace(i_con_cell);
390✔
59
        }
60
      }
61
    }
195✔
62
  }
63

64
  // Next, find all materials contained in the majorant's universe. This also
65
  // obtains the maximum density multiplier applied to that material.
66
  std::unordered_set<int> unique_materials;
195✔
67
  for (int i_cell : unique_mat_cells) {
585✔
68
    auto& cell = model::cells[i_cell];
390✔
69

70
    for (int instance = 0; instance < cell->n_instances(); ++instance) {
1,950✔
71
      int i_material = cell->material(instance);
1,560!
72
      // Skip over void materials.
73
      if (i_material == MATERIAL_VOID) {
1,560!
NEW
74
        continue;
×
75
      }
76

77
      // Check to see if we've found the contained material yet. If not, add
78
      // to the set of materials discovered and add to the map of density
79
      // multipliers.
80
      if (unique_materials.count(i_material) == 0) {
1,560✔
81
        unique_materials.emplace(i_material);
390✔
82
        max_density_mult_[i_material] = cell->density_mult(instance);
390✔
83
      } else {
84
        // We've found this material already. Need to take the maximum density
85
        // multiplier.
86
        max_density_mult_.at(i_material) = std::max(
2,340✔
87
          max_density_mult_.at(i_material), cell->density_mult(instance));
2,340✔
88
      }
89
    }
90
  }
91

92
  // Insert the elements from the set.
93
  contained_materials_.assign(unique_materials.begin(), unique_materials.end());
195✔
94
}
390✔
95

96
void Majorant::compute_majorant()
195✔
97
{
98
  // Fill with zeros.
99
  xs_.resize(grid_.energy.size(), 0.0);
195✔
100

101
  vector<double> material_maj_xs;
195✔
102
  for (int i_material : contained_materials_) {
585✔
103
    // Populate the per-material majorant cross section. We pass in
104
    // 'material_maj_xs' instead of returning a vector with the per-material
105
    // majorant every time to avoid costly reallocations and copy operations,
106
    // which have a fairly large impact on the time it takes to build the
107
    // majorant. The function 'fill_material_maj_xs(...)' is responsible for
108
    // resizing 'material_maj_xs' and populating each value at a given energy
109
    // grid point.
110
    fill_material_maj_xs(i_material, max_density_mult_.at(i_material),
390✔
111
      grid_.energy, material_maj_xs);
390✔
112

113
    // Compute the full majorant by taking the max over each material cross
114
    // section.
115
    for (int i_energy = 0; i_energy < xs_.size(); ++i_energy) {
23,903,520✔
116
      xs_[i_energy] = std::max(xs_[i_energy], material_maj_xs[i_energy]);
38,235,450✔
117
    }
118
  }
119
}
195✔
120

121
void Majorant::post_process_grid()
195✔
122
{
123
  // Fetch the minimum and maximum transport energies from the superclass.
124
  const double E_min = min_transport_energy();
195✔
125
  const double E_max = max_transport_energy();
195✔
126

127
  std::sort(grid_.energy.begin(), grid_.energy.end());
195✔
128
  auto unique_end = std::unique(grid_.energy.begin(), grid_.energy.end());
195✔
129
  grid_.energy.resize(std::distance(grid_.energy.begin(), unique_end));
195✔
130

131
  // Remove all values below the minimum neutron energy.
132
  auto min_it = grid_.energy.begin();
195✔
133
  while (*min_it < E_min) {
195✔
134
    min_it++;
136,320✔
135
  }
136
  grid_.energy.erase(grid_.energy.begin(), min_it + 1);
195✔
137

138
  // Insert the minimum neutron energy at the beginning.
139
  grid_.energy.insert(grid_.energy.begin(), E_min);
195✔
140

141
  // Remove all values above the maximum neutron energy.
142
  auto max_it = --grid_.energy.end();
195✔
143
  while (*max_it > E_max) {
195✔
144
    max_it--;
34,410✔
145
  }
146
  grid_.energy.erase(max_it - 1, grid_.energy.end());
195✔
147

148
  // Insert the maximum neutron energy at the end.
149
  grid_.energy.insert(grid_.energy.end(), E_max);
195✔
150
}
195✔
151

152
//==============================================================================
153
// NeutronMajorant implementation
154
//==============================================================================
155

156
NeutronMajorant::NeutronMajorant(int i_universe) : Majorant(i_universe) {}
150✔
157

158
double NeutronMajorant::calculate_neutron_xs(double energy) const
21,429,298✔
159
{
160
  const int i_grid = get_i_grid(energy, grid_);
21,429,298✔
161
  return interpolate_lin_lin(grid_.energy[i_grid], grid_.energy[i_grid + 1],
21,429,298✔
162
    xs_[i_grid], xs_[i_grid + 1], energy);
21,429,298✔
163
}
164

165
void NeutronMajorant::compute_unionized_grid()
150✔
166
{
167
  // This function generates a unionized cross section grid between smooth cross
168
  // sections and URR probability table grids.
169
  std::unordered_set<int> processed_nuclides;
150✔
170
  for (int i_mat : contained_materials_) {
450✔
171
    const auto& mat = model::materials[i_mat];
300✔
172
    for (auto i_nuclide : mat->nuclide_) {
900✔
173
      // Only unionize nuclides we haven't checked yet.
174
      if (processed_nuclides.count(i_nuclide) > 0) {
600✔
175
        continue;
150✔
176
      }
177

178
      const auto& nuclide = data::nuclides[i_nuclide];
450✔
179
      // ======================================================================
180
      // Unionizing the URR energy grids.
181
      if (nuclide->urr_present_ && settings::urr_ptables_on) {
450!
182
        for (const auto& nuc_urr : nuclide->urr_data_) {
300✔
183
          grid_.energy.insert(
150✔
184
            grid_.energy.end(), nuc_urr.energy_.begin(), nuc_urr.energy_.end());
150✔
185
        }
186
      }
187

188
      // ======================================================================
189
      // Unionize the smooth cross section energy grids.
190
      for (const auto& nuc_grid : nuclide->grid_) {
900✔
191
        grid_.energy.insert(
450✔
192
          grid_.energy.end(), nuc_grid.energy.begin(), nuc_grid.energy.end());
450✔
193
      }
194

195
      processed_nuclides.insert(i_nuclide);
450✔
196
    }
197
  }
198

199
  // Post-process the energy grid now that all points from nuclides are
200
  // included. This sorts the energy points, removes duplicates, and removes all
201
  // energies exceeding neutron transport bounds.
202
  post_process_grid();
150✔
203

204
  // Initialize the grid for fast lookups. This only applies to neutrons.
205
  grid_.init();
150✔
206
}
150✔
207

208
void NeutronMajorant::fill_material_maj_xs(int i_material,
300✔
209
  double max_density_mult, const vector<double>& to_grid,
210
  vector<double>& mat_maj) const
211
{
212
  const auto& mat = *model::materials[i_material];
300✔
213

214
  mat_maj.resize(to_grid.size());
300✔
215

216
#pragma omp parallel for
180✔
217
  for (int i_energy = 0; i_energy < to_grid.size(); ++i_energy) {
9,510,360✔
218
    mat_maj[i_energy] = 0.0;
9,510,240✔
219
    const double union_energy = to_grid[i_energy];
9,510,240✔
220

221
    int mat_sab_table_idx = 0;
9,510,240✔
222
    bool check_sab = (mat.thermal_tables_.size() > 0);
9,510,240✔
223

224
    for (int i = 0; i < mat.nuclide_.size(); ++i) {
28,530,720✔
225
      // ======================================================================
226
      // CHECK FOR S(A,B) TABLE
227
      int i_sab = C_NONE;
19,020,480✔
228
      double sab_frac = 0.0;
19,020,480✔
229

230
      // Check if this nuclide matches one of the S(a,b) tables specified.
231
      // This relies on thermal_tables_ being sorted by .index_nuclide
232
      if (check_sab) {
19,020,480✔
233
        const auto& sab {mat.thermal_tables_[mat_sab_table_idx]};
4,755,120!
234
        if (i == sab.index_nuclide) {
4,755,120!
235
          // Get index in sab_tables
236
          i_sab = sab.index_table;
4,755,120✔
237
          sab_frac = sab.fraction;
4,755,120✔
238

239
          // If particle energy is greater than the highest energy for the
240
          // S(a,b) table, then don't use the S(a,b) table
241
          if (union_energy > data::thermal_scatt[i_sab]->energy_max_) {
4,755,120✔
242
            i_sab = C_NONE;
4,675,080✔
243
          }
244

245
          // Increment position in thermal_tables_
246
          ++mat_sab_table_idx;
4,755,120✔
247

248
          // Don't check for S(a,b) tables if there are no more left
249
          if (mat_sab_table_idx == mat.thermal_tables_.size()) {
4,755,120!
250
            check_sab = false;
4,755,120✔
251
          }
252
        }
253
      }
254

255
      // ======================================================================
256
      // Compute the maximum smooth total cross section. This is either the
257
      // free gas cross section at energies larger than the Bragg edge, or
258
      // the bound cross section in the thermal scattering region.
259
      double micro_smooth_tot_xs = 0.0;
19,020,480✔
260
      if (i_sab >= 0) {
19,020,480✔
261
        // Thermal scattering cross sections using S(a,b) tables.
262
        micro_smooth_tot_xs = calculate_max_sab_micro_tot_xs(
80,040✔
263
          mat.nuclide_[i], i_sab, sab_frac, union_energy);
80,040✔
264
      } else {
265
        // Free gas smooth cross section
266
        micro_smooth_tot_xs =
18,940,440✔
267
          calculate_max_smooth_micro_xs(mat.nuclide_[i], union_energy);
18,940,440✔
268
      }
269

270
      // ======================================================================
271
      // Compute the URR cross section. This shouldn't intersect with the
272
      // S(a,b) cross section.
273
      double micro_urr_xs = calculate_max_urr_micro_xs(
19,020,480✔
274
        mat.nuclide_[i], union_energy, micro_smooth_tot_xs);
19,020,480✔
275

276
      // ======================================================================
277
      // Accumulate the macroscopic cross section.
278
      mat_maj[i_energy] += std::max(micro_smooth_tot_xs, micro_urr_xs) *
19,026,240✔
279
                           mat.atom_density(i, max_density_mult);
19,020,480✔
280
    }
281
  }
282
}
300✔
283

284
double NeutronMajorant::calculate_max_smooth_micro_xs(
47,351,100✔
285
  int i_nuclide, double energy) const
286
{
287
  const auto& nuc = *data::nuclides[i_nuclide];
47,351,100✔
288

289
  double max_smooth_tot_xs = 0.0;
47,351,100✔
290
  for (int i_temp = 0; i_temp < nuc.kTs_.size(); ++i_temp) {
94,702,200✔
291
    const auto& nuc_grid = nuc.grid_[i_temp];
47,351,100✔
292
    int i_grid = get_i_grid(energy, nuc_grid);
47,351,100✔
293
    auto total = nuc.xs_[i_temp].slice(openmc::tensor::all, 0);
47,351,100✔
294
    double xs = interpolate_lin_lin(nuc_grid.energy[i_grid],
47,351,100✔
295
      nuc_grid.energy[i_grid + 1], total[i_grid], total[i_grid + 1], energy);
47,351,100!
296
    max_smooth_tot_xs = std::max(max_smooth_tot_xs, xs);
94,702,200!
297
  }
47,351,100✔
298

299
  return max_smooth_tot_xs;
47,351,100✔
300
}
301

302
double NeutronMajorant::calculate_max_urr_micro_xs(
47,551,200✔
303
  int i_nuclide, double energy, double smooth_xs) const
304
{
305
  const auto& nuc = *data::nuclides[i_nuclide];
47,551,200✔
306
  if (!nuc.urr_present_) {
47,551,200✔
307
    return 0.0;
308
  }
309

310
  double max_urr_xs = 0.0;
11,887,800✔
311
  for (const auto& urr : nuc.urr_data_) {
23,775,600✔
312
    if (!(urr.energy_in_bounds(energy - MAJORANT_URR_TOL) ||
11,887,800✔
313
          urr.energy_in_bounds(energy + MAJORANT_URR_TOL))) {
11,873,550✔
314
      continue;
11,873,400✔
315
    }
316

317
    int i_energy;
14,400✔
318
    if (energy <= urr.energy_.front()) {
14,400✔
319
      i_energy = 0;
320
    } else if (energy >= urr.energy_.back()) {
14,250✔
321
      i_energy = urr.energy_.size() - 2;
150✔
322
    } else {
323
      i_energy =
14,100✔
324
        lower_bound_index(&urr.energy_.front(), &urr.energy_.back(), energy);
14,100✔
325
    }
326

327
    // Find the maximum URR cross sections for the two bounding energy points.
328
    double max_urr_xs_E0 = 0.0;
14,400✔
329
    double max_urr_xs_E1 = 0.0;
14,400✔
330
    for (int i_cdf = 0; i_cdf < urr.n_cdf(); ++i_cdf) {
604,800!
331
      max_urr_xs_E0 =
576,000✔
332
        std::max(max_urr_xs_E0, urr.xs_values_(i_energy, i_cdf).total);
288,000!
333
      max_urr_xs_E1 =
576,000✔
334
        std::max(max_urr_xs_E1, urr.xs_values_(i_energy + 1, i_cdf).total);
576,000!
335
    }
336
    // Handle the rare case where the points could be negative.
337
    max_urr_xs_E0 = std::max(max_urr_xs_E0, 0.0);
14,400!
338
    max_urr_xs_E1 = std::max(max_urr_xs_E1, 0.0);
14,400!
339

340
    // Interpolate the bounding energy points.
341
    double interp_urr_xs = 0.0;
14,400✔
342
    if (urr.interp_ == Interpolation::lin_lin) {
14,400!
343
      interp_urr_xs = interpolate_lin_lin(urr.energy_[i_energy],
14,400✔
344
        urr.energy_[i_energy + 1], max_urr_xs_E0, max_urr_xs_E1, energy);
14,400✔
NEW
345
    } else if (urr.interp_ == Interpolation::log_log) {
×
NEW
346
      interp_urr_xs = interpolate_log_log(urr.energy_[i_energy],
×
NEW
347
        urr.energy_[i_energy + 1], max_urr_xs_E0, max_urr_xs_E1, energy);
×
348
    }
349

350
    // Multiply by the smooth cross section (after interpolation) if required.
351
    if (urr.multiply_smooth_) {
14,400!
352
      interp_urr_xs *= smooth_xs;
14,400✔
353
    }
354

355
    max_urr_xs = std::max(max_urr_xs, interp_urr_xs);
28,800!
356
  }
357

358
  return max_urr_xs;
11,887,800✔
359
}
360

361
double NeutronMajorant::calculate_max_sab_micro_tot_xs(
200,100✔
362
  int i_nuclide, int i_sab, double sab_frac, double energy) const
363
{
364
  const auto& nuc = *data::nuclides[i_nuclide];
200,100✔
365
  const auto& thermal = *data::thermal_scatt[i_sab];
200,100✔
366

367
  // Loop over the nuclide's temperature grid to ensure we're consistent.
368
  double max_sab_total = 0.0;
200,100✔
369
  for (int i_nuc_temp = 0; i_nuc_temp < nuc.kTs_.size(); ++i_nuc_temp) {
400,200✔
370
    double nuc_kT = nuc.kTs_[i_nuc_temp] * nuc.kTs_[i_nuc_temp];
200,100!
371

372
    // Compute the elastic and inelastic scattering cross sections. The S(a,b)
373
    // cross sections are interpolated to match the nuclide temperature point.
374
    double thermal_elastic;
200,100✔
375
    double thermal_inelastic;
200,100✔
376
    const auto& tkTs = thermal.kTs_;
200,100✔
377
    if (tkTs.size() > 1) {
200,100!
NEW
378
      if (nuc_kT < tkTs.front()) {
×
NEW
379
        thermal.data_.front().calculate_xs(
×
380
          energy, &thermal_elastic, &thermal_inelastic);
NEW
381
      } else if (nuc_kT > tkTs.back()) {
×
NEW
382
        thermal.data_.back().calculate_xs(
×
383
          energy, &thermal_elastic, &thermal_inelastic);
384
      } else {
385
        // Find temperatures that bound the actual temperature
386
        int i_sab_temp = 0;
387
        while (
NEW
388
          tkTs[i_sab_temp + 1] < nuc_kT && i_sab_temp + 1 < tkTs.size() - 1) {
×
389
          ++i_sab_temp;
390
        }
391
        // Interpolate the scattering cross sections to the nuclide temperature
392
        // grid point.
NEW
393
        double T0_elastic, T1_elastic, T0_inelastic, T1_inelastic;
×
NEW
394
        thermal.data_[i_sab_temp].calculate_xs(
×
395
          energy, &T0_elastic, &T0_inelastic);
NEW
396
        thermal.data_[i_sab_temp + 1].calculate_xs(
×
397
          energy, &T1_elastic, &T1_inelastic);
NEW
398
        thermal_elastic = interpolate_lin_lin(tkTs[i_sab_temp],
×
NEW
399
          tkTs[i_sab_temp + 1], T0_elastic, T1_elastic, nuc_kT);
×
NEW
400
        thermal_inelastic = interpolate_lin_lin(tkTs[i_sab_temp],
×
NEW
401
          tkTs[i_sab_temp + 1], T0_inelastic, T1_inelastic, nuc_kT);
×
402
      }
403
    } else {
404
      thermal.data_[0].calculate_xs(
200,100✔
405
        energy, &thermal_elastic, &thermal_inelastic);
406
    }
407

408
    // Compute the free gas total and elastic cross sections interpolated on the
409
    // majorant grid.
410
    const auto& nuc_grid = nuc.grid_[i_nuc_temp];
200,100✔
411
    int i_grid = get_i_grid(energy, nuc_grid);
200,100✔
412
    const auto& free_tot = nuc.xs_[i_nuc_temp].slice(openmc::tensor::all, 0);
200,100✔
413
    const auto& free_ela = nuc.reactions_[0]->xs_[i_nuc_temp].value;
200,100!
414
    double tot_xs =
200,100✔
415
      interpolate_lin_lin(nuc_grid.energy[i_grid], nuc_grid.energy[i_grid + 1],
200,100!
416
        free_tot[i_grid], free_tot[i_grid + 1], energy);
200,100!
417
    double ela_xs =
200,100✔
418
      interpolate_lin_lin(nuc_grid.energy[i_grid], nuc_grid.energy[i_grid + 1],
200,100✔
419
        free_ela[i_grid], free_ela[i_grid + 1], energy);
200,100✔
420

421
    double thermal_xs = sab_frac * (thermal_elastic + thermal_inelastic);
200,100✔
422
    double sab_corrected_total = tot_xs + thermal_xs - sab_frac * ela_xs;
200,100✔
423
    max_sab_total = std::max(sab_corrected_total, max_sab_total);
200,100!
424
  }
200,100✔
425

426
  return max_sab_total;
200,100✔
427
}
428

429
int NeutronMajorant::get_i_grid(
68,980,498✔
430
  double energy, const Nuclide::EnergyGrid& grid) const
431
{
432
  // Find energy index on energy grid
433
  int i_log_union =
68,980,498✔
434
    std::log(energy / data::energy_min[I_NEUTRON]) / simulation::log_spacing;
68,980,498✔
435

436
  int i_grid;
68,980,498✔
437
  if (energy <= grid.energy.front()) {
68,980,498✔
438
    i_grid = 0;
439
  } else if (energy >= grid.energy.back()) {
68,979,898✔
440
    i_grid = grid.energy.size() - 2;
300✔
441
  } else {
442
    // Determine bounding indices based on which equal log-spaced
443
    // interval the energy is in
444
    int i_low = grid.grid_index[i_log_union];
68,979,598!
445
    int i_high = grid.grid_index[i_log_union + 1] + 1;
68,979,598✔
446

447
    // This catches the very rare case where floating point comparisons fail.
448
    if (i_low >= grid.energy.size() || i_high >= grid.energy.size()) {
68,979,598!
NEW
449
      i_grid = grid.energy.size() - 2;
×
450
    } else {
451
      // Perform binary search over reduced range
452
      i_grid = i_low + lower_bound_index(
68,979,598✔
453
                         &grid.energy[i_low], &grid.energy[i_high], energy);
68,979,598✔
454
    }
455
  }
456

457
  // check for rare case where two energy points are the same
458
  if (grid.energy[i_grid] == grid.energy[i_grid + 1])
68,980,498!
NEW
459
    ++i_grid;
×
460

461
  return i_grid;
68,980,498✔
462
}
463

464
//==============================================================================
465
// PhotonMajorant implementation
466
//==============================================================================
467

468
PhotonMajorant::PhotonMajorant(int i_universe) : Majorant(i_universe) {}
45✔
469

470
void PhotonMajorant::compute_unionized_grid()
45✔
471
{
472
  // This function generates a unionized cross section grid for all elements.
473
  std::unordered_set<int> processed_elements;
45✔
474
  for (int i_mat : contained_materials_) {
135✔
475
    const auto& mat = model::materials[i_mat];
90✔
476
    for (int i = 0; i < mat->nuclide_.size(); ++i) {
270✔
477
      // Only unionize elements we haven't checked yet.
478
      if (processed_elements.count(mat->element_[i]) > 0) {
180✔
479
        continue;
45✔
480
      }
481

482
      const auto& element = data::elements[mat->element_[i]];
135✔
483
      grid_.energy.insert(
135✔
484
        grid_.energy.end(), element->energy_.begin(), element->energy_.end());
135✔
485

486
      processed_elements.insert(mat->element_[i]);
135✔
487
    }
488
  }
489

490
  // Post-process the energy grid now that all points from photon interactions
491
  // are included. This sorts the energy points, removes duplicates, and removes
492
  // all energies exceeding photon transport bounds.
493
  post_process_grid();
45✔
494
}
45✔
495

496
double PhotonMajorant::calculate_photon_xs(double energy) const
19,629,577✔
497
{
498
  double log_energy = std::log(energy);
19,629,577✔
499
  int i_grid = get_i_grid<vector<double>>(log_energy, grid_.energy);
19,629,577✔
500

501
  // calculate interpolation factor
502
  double f = (log_energy - grid_.energy[i_grid]) /
19,629,577✔
503
             (grid_.energy[i_grid + 1] - grid_.energy[i_grid]);
19,629,577✔
504

505
  // interpolate the total cross section
506
  return std::exp(xs_[i_grid] + f * (xs_[i_grid + 1] - xs_[i_grid]));
19,629,577✔
507
}
508

509
void PhotonMajorant::fill_material_maj_xs(int i_material,
90✔
510
  double max_density_mult, const vector<double>& to_grid,
511
  vector<double>& mat_maj) const
512
{
513
  const auto& mat = *model::materials[i_material];
90✔
514

515
  mat_maj.resize(to_grid.size());
90✔
516

517
#pragma omp parallel for
54✔
518
  for (int i_energy = 0; i_energy < to_grid.size(); ++i_energy) {
51,048✔
519
    mat_maj[i_energy] = 0.0;
51,012✔
520
    const double union_log_energy = to_grid[i_energy];
51,012✔
521

522
    for (int i = 0; i < mat.nuclide_.size(); ++i) {
153,036✔
523
      const int i_element = mat.element_[i];
102,024✔
524

525
      mat_maj[i_energy] +=
204,048✔
526
        calculate_elem_micro_tot_xs(i_element, union_log_energy) *
102,024✔
527
        mat.atom_density(i, max_density_mult);
102,024✔
528
    }
529
    mat_maj[i_energy] = std::log(mat_maj[i_energy]);
51,012✔
530
  }
531
}
90✔
532

533
double PhotonMajorant::calculate_elem_micro_tot_xs(
255,060✔
534
  int i_element, double log_energy) const
535
{
536
  const auto& elem = *data::elements[i_element];
255,060✔
537
  int i_grid = get_i_grid<tensor::Tensor<double>>(log_energy, elem.energy_);
255,060✔
538

539
  // calculate interpolation factor
540
  double f = (log_energy - elem.energy_(i_grid)) /
255,060✔
541
             (elem.energy_(i_grid + 1) - elem.energy_(i_grid));
255,060✔
542

543
  // Calculate microscopic coherent cross section
544
  double coherent =
255,060✔
545
    std::exp(elem.coherent_(i_grid) +
510,120✔
546
             f * (elem.coherent_(i_grid + 1) - elem.coherent_(i_grid)));
255,060✔
547

548
  // Calculate microscopic incoherent cross section
549
  double incoherent =
255,060✔
550
    std::exp(elem.incoherent_(i_grid) +
255,060✔
551
             f * (elem.incoherent_(i_grid + 1) - elem.incoherent_(i_grid)));
255,060✔
552

553
  // Calculate microscopic photoelectric cross section
554
  double photoelectric = 0.0;
255,060✔
555
  tensor::View<const double> xs_lower = elem.cross_sections_.slice(i_grid);
255,060✔
556
  tensor::View<const double> xs_upper = elem.cross_sections_.slice(i_grid + 1);
255,060✔
557

558
  for (int i = 0; i < xs_upper.size(); ++i)
5,356,260✔
559
    if (xs_lower(i) != 0)
2,423,070✔
560
      photoelectric += std::exp(xs_lower(i) + f * (xs_upper(i) - xs_lower(i)));
2,271,060✔
561

562
  // Calculate microscopic pair production cross section
563
  double pair_production =
255,060✔
564
    std::exp(elem.pair_production_total_(i_grid) +
255,060✔
565
             f * (elem.pair_production_total_(i_grid + 1) -
255,060✔
566
                   elem.pair_production_total_(i_grid)));
255,060✔
567

568
  // Calculate microscopic total cross section
569
  return coherent + incoherent + photoelectric + pair_production;
255,060✔
570
}
510,120✔
571

572
//! Create a majorant cross section for photons or neutrons.
573
void create_majorants()
150✔
574
{
575
  simulation::time_build_majorant.start();
150✔
576

577
  write_message("Constructing a neutron majorant cross section");
150✔
578
  data::n_majorant = std::make_unique<NeutronMajorant>(model::root_universe);
150✔
579
  data::n_majorant->compute_unionized_grid();
150✔
580
  data::n_majorant->compute_majorant();
150✔
581

582
  if (settings::photon_transport) {
150✔
583
    write_message("Constructing a photon majorant cross section");
45✔
584
    data::p_majorant = std::make_unique<PhotonMajorant>(model::root_universe);
45✔
585
    data::p_majorant->compute_unionized_grid();
45✔
586
    data::p_majorant->compute_majorant();
45✔
587
  }
588

589
  simulation::time_build_majorant.stop();
150✔
590
}
150✔
591

592
//! Reset the photon and neutron majorant cross sections.
593
void reset_majorants()
8,172✔
594
{
595
  openmc::data::n_majorant.reset(nullptr);
8,172✔
596
  openmc::data::p_majorant.reset(nullptr);
8,172✔
597
}
8,172✔
598
} // namespace openmc
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc