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

openmc-dev / openmc / 21139931957

19 Jan 2026 01:50PM UTC coverage: 81.835% (-0.2%) from 82.058%
21139931957

Pull #2693

github

web-flow
Merge 1258e263b into 5847b0de2
Pull Request #2693: Add reactivity control to coupled transport-depletion analyses

17180 of 23968 branches covered (71.68%)

Branch coverage included in aggregate %.

78 of 84 new or added lines in 4 files covered. (92.86%)

345 existing lines in 27 files now uncovered.

55616 of 64987 relevant lines covered (85.58%)

50201535.92 hits per line

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

88.13
/src/random_ray/linear_source_domain.cpp
1
#include "openmc/random_ray/linear_source_domain.h"
2

3
#include "openmc/cell.h"
4
#include "openmc/geometry.h"
5
#include "openmc/material.h"
6
#include "openmc/message_passing.h"
7
#include "openmc/mgxs_interface.h"
8
#include "openmc/output.h"
9
#include "openmc/plot.h"
10
#include "openmc/random_ray/random_ray.h"
11
#include "openmc/simulation.h"
12
#include "openmc/tallies/filter.h"
13
#include "openmc/tallies/tally.h"
14
#include "openmc/tallies/tally_scoring.h"
15
#include "openmc/timer.h"
16

17
namespace openmc {
18

19
//==============================================================================
20
// LinearSourceDomain implementation
21
//==============================================================================
22

23
void LinearSourceDomain::batch_reset()
6,250✔
24
{
25
  FlatSourceDomain::batch_reset();
6,250✔
26
#pragma omp parallel for
3,125✔
27
  for (int64_t sr = 0; sr < n_source_regions(); sr++) {
13,100,550✔
28
    source_regions_.centroid_iteration(sr) = {0.0, 0.0, 0.0};
13,097,425✔
29
    source_regions_.mom_matrix(sr) = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
13,097,425✔
30
  }
31
#pragma omp parallel for
3,125✔
32
  for (int64_t se = 0; se < n_source_elements(); se++) {
15,061,470✔
33
    source_regions_.flux_moments_new(se) = {0.0, 0.0, 0.0};
15,058,345✔
34
  }
35
}
6,250✔
36

37
void LinearSourceDomain::update_single_neutron_source(SourceRegionHandle& srh)
26,941,270✔
38
{
39
  // Reset all source regions to zero (important for void regions)
40
  for (int g = 0; g < negroups_; g++) {
57,866,540✔
41
    srh.source(g) = 0.0;
30,925,270✔
42
  }
43

44
  // Add scattering + fission source
45
  int material = srh.material();
26,941,270✔
46
  double density_mult = srh.density_mult();
26,941,270✔
47
  if (material != MATERIAL_VOID) {
26,941,270✔
48
    double inverse_k_eff = 1.0 / k_eff_;
26,541,270✔
49
    MomentMatrix invM = srh.mom_matrix().inverse();
26,541,270✔
50

51
    for (int g_out = 0; g_out < negroups_; g_out++) {
57,066,540✔
52
      double sigma_t = sigma_t_[material * negroups_ + g_out] * density_mult;
30,525,270✔
53

54
      double scatter_flat = 0.0f;
30,525,270✔
55
      double fission_flat = 0.0f;
30,525,270✔
56
      MomentArray scatter_linear = {0.0, 0.0, 0.0};
30,525,270✔
57
      MomentArray fission_linear = {0.0, 0.0, 0.0};
30,525,270✔
58

59
      for (int g_in = 0; g_in < negroups_; g_in++) {
99,386,940✔
60
        // Handles for the flat and linear components of the flux
61
        double flux_flat = srh.scalar_flux_old(g_in);
68,861,670✔
62
        MomentArray flux_linear = srh.flux_moments_old(g_in);
68,861,670✔
63

64
        // Handles for cross sections
65
        double sigma_s = sigma_s_[material * negroups_ * negroups_ +
68,861,670✔
66
                                  g_out * negroups_ + g_in] *
68,861,670✔
67
                         density_mult;
68,861,670✔
68
        double nu_sigma_f =
69
          nu_sigma_f_[material * negroups_ + g_in] * density_mult;
68,861,670✔
70
        double chi = chi_[material * negroups_ + g_out];
68,861,670✔
71

72
        // Compute source terms for flat and linear components of the flux
73
        scatter_flat += sigma_s * flux_flat;
68,861,670✔
74
        scatter_linear += sigma_s * flux_linear;
68,861,670✔
75
        if (settings::create_fission_neutrons) {
68,861,670!
76
          fission_flat += nu_sigma_f * flux_flat * chi;
68,861,670✔
77
          fission_linear += nu_sigma_f * flux_linear * chi;
68,861,670✔
78
        }
79
      }
80

81
      // Compute the flat source term
82
      srh.source(g_out) =
61,050,540✔
83
        (scatter_flat + fission_flat * inverse_k_eff) / sigma_t;
30,525,270✔
84

85
      // Compute the linear source terms. In the first 10 iterations when the
86
      // centroids and spatial moments are not well known, we will leave the
87
      // source gradients as zero so as to avoid causing any numerical
88
      // instability. If a negative source is encountered, this region must be
89
      // very small/noisy or have poorly developed spatial moments, so we zero
90
      // the source gradients (effectively making this a flat source region
91
      // temporarily), so as to improve stability.
92
      if (simulation::current_batch > 10 && srh.source(g_out) >= 0.0) {
30,525,270✔
93
        srh.source_gradients(g_out) =
18,690,020✔
94
          invM * ((scatter_linear + fission_linear * inverse_k_eff) / sigma_t);
37,380,040✔
95
      } else {
96
        srh.source_gradients(g_out) = {0.0, 0.0, 0.0};
11,835,250✔
97
      }
98
    }
99
  }
100

101
  // Add external source if in fixed source mode
102
  if (settings::run_mode == RunMode::FIXED_SOURCE) {
26,941,270✔
103
    for (int g = 0; g < negroups_; g++) {
56,080,540✔
104
      srh.source(g) += srh.external_source(g);
29,345,270✔
105
    }
106
  }
107
}
26,941,270✔
108

109
void LinearSourceDomain::normalize_scalar_flux_and_volumes(
6,250✔
110
  double total_active_distance_per_iteration)
111
{
112
  double normalization_factor = 1.0 / total_active_distance_per_iteration;
6,250✔
113
  double volume_normalization_factor =
6,250✔
114
    1.0 / (total_active_distance_per_iteration * simulation::current_batch);
6,250✔
115

116
// Normalize flux to total distance travelled by all rays this iteration
117
#pragma omp parallel for
3,125✔
118
  for (int64_t se = 0; se < n_source_elements(); se++) {
15,450,690✔
119
    source_regions_.scalar_flux_new(se) *= normalization_factor;
15,447,565✔
120
    source_regions_.flux_moments_new(se) *= normalization_factor;
15,447,565✔
121
  }
122

123
// Accumulate cell-wise ray length tallies collected this iteration, then
124
// update the simulation-averaged cell-wise volume estimates
125
#pragma omp parallel for
3,125✔
126
  for (int64_t sr = 0; sr < n_source_regions(); sr++) {
13,458,690✔
127
    source_regions_.centroid_t(sr) += source_regions_.centroid_iteration(sr);
13,455,565✔
128
    source_regions_.mom_matrix_t(sr) += source_regions_.mom_matrix(sr);
13,455,565✔
129
    source_regions_.volume_t(sr) += source_regions_.volume(sr);
13,455,565✔
130
    source_regions_.volume_sq_t(sr) += source_regions_.volume_sq(sr);
13,455,565✔
131
    source_regions_.volume_naive(sr) =
26,911,130✔
132
      source_regions_.volume(sr) * normalization_factor;
13,455,565✔
133
    source_regions_.volume(sr) =
26,911,130✔
134
      source_regions_.volume_t(sr) * volume_normalization_factor;
13,455,565✔
135
    source_regions_.volume_sq(sr) =
26,911,130✔
136
      source_regions_.volume_sq_t(sr) / source_regions_.volume_t(sr);
13,455,565✔
137
    if (source_regions_.volume_t(sr) > 0.0) {
13,455,565✔
138
      double inv_volume = 1.0 / source_regions_.volume_t(sr);
13,455,560✔
139
      source_regions_.centroid(sr) = source_regions_.centroid_t(sr);
13,455,560✔
140
      source_regions_.centroid(sr) *= inv_volume;
13,455,560✔
141
      source_regions_.mom_matrix(sr) = source_regions_.mom_matrix_t(sr);
13,455,560✔
142
      source_regions_.mom_matrix(sr) *= inv_volume;
13,455,560✔
143
    }
144
  }
145
}
6,250✔
146

147
void LinearSourceDomain::set_flux_to_flux_plus_source(
28,263,590✔
148
  int64_t sr, double volume, int g)
149
{
150
  int material = source_regions_.material(sr);
28,263,590✔
151
  if (material == MATERIAL_VOID) {
28,263,590✔
152
    FlatSourceDomain::set_flux_to_flux_plus_source(sr, volume, g);
400,000✔
153
  } else {
154
    source_regions_.scalar_flux_new(sr, g) /= volume;
27,863,590✔
155
    source_regions_.scalar_flux_new(sr, g) += source_regions_.source(sr, g);
27,863,590✔
156
  }
157
  // If a source region is small, then the moments are likely noisy, so we zero
158
  // them. This is reasonable, given that small regions can get by with a flat
159
  // source approximation anyhow.
160
  if (source_regions_.is_small(sr)) {
28,263,590✔
161
    source_regions_.flux_moments_new(sr, g) = {0.0, 0.0, 0.0};
2,871,140✔
162
  } else {
163
    source_regions_.flux_moments_new(sr, g) *= (1.0 / volume);
25,392,450✔
164
  }
165
}
28,263,590✔
166

167
void LinearSourceDomain::set_flux_to_old_flux(int64_t sr, int g)
1,240✔
168
{
169
  source_regions_.scalar_flux_new(sr, g) =
2,480✔
170
    source_regions_.scalar_flux_old(sr, g);
1,240✔
171
  source_regions_.flux_moments_new(sr, g) =
2,480✔
172
    source_regions_.flux_moments_old(sr, g);
1,240✔
173
}
1,240✔
174

175
void LinearSourceDomain::accumulate_iteration_flux()
2,600✔
176
{
177
  // Accumulate scalar flux
178
  FlatSourceDomain::accumulate_iteration_flux();
2,600✔
179

180
  // Accumulate scalar flux moments
181
#pragma omp parallel for
1,300✔
182
  for (int64_t se = 0; se < n_source_elements(); se++) {
6,586,800✔
183
    source_regions_.flux_moments_t(se) += source_regions_.flux_moments_new(se);
6,585,500✔
184
  }
185
}
2,600✔
186

187
double LinearSourceDomain::evaluate_flux_at_point(
×
188
  Position r, int64_t sr, int g) const
189
{
190
  double phi_flat = FlatSourceDomain::evaluate_flux_at_point(r, sr, g);
×
191

UNCOV
192
  Position local_r = r - source_regions_.centroid(sr);
×
193
  MomentArray phi_linear = source_regions_.flux_moments_t(sr, g);
×
194
  phi_linear *= 1.0 / (settings::n_batches - settings::n_inactive);
×
195

196
  MomentMatrix invM = source_regions_.mom_matrix(sr).inverse();
×
UNCOV
197
  MomentArray phi_solved = invM * phi_linear;
×
198

UNCOV
199
  return phi_flat + phi_solved.dot(local_r);
×
200
}
201

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