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

openmc-dev / openmc / 13461947318

21 Feb 2025 05:24PM UTC coverage: 85.019% (+0.05%) from 84.969%
13461947318

Pull #3140

github

web-flow
Merge ece247ada into 2b788ea6e
Pull Request #3140: Add Versioning Support from `version.txt`

8 of 8 new or added lines in 2 files covered. (100.0%)

1293 existing lines in 43 files now uncovered.

50627 of 59548 relevant lines covered (85.02%)

35584918.67 hits per line

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

88.78
/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()
7,565✔
24
{
25
  FlatSourceDomain::batch_reset();
7,565✔
26
#pragma omp parallel for
4,005✔
27
  for (int64_t sr = 0; sr < n_source_regions_; sr++) {
3,825,480✔
28
    source_regions_.centroid_iteration(sr) = {0.0, 0.0, 0.0};
3,821,920✔
29
    source_regions_.mom_matrix(sr) = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
3,821,920✔
30
  }
31
#pragma omp parallel for
4,005✔
32
  for (int64_t se = 0; se < n_source_elements_; se++) {
6,850,440✔
33
    source_regions_.flux_moments_new(se) = {0.0, 0.0, 0.0};
6,846,880✔
34
  }
35
}
7,565✔
36

37
void LinearSourceDomain::update_neutron_source(double k_eff)
7,565✔
38
{
39
  simulation::time_update_src.start();
7,565✔
40

41
  double inverse_k_eff = 1.0 / k_eff;
7,565✔
42

43
#pragma omp parallel for
4,005✔
44
  for (int64_t sr = 0; sr < n_source_regions_; sr++) {
3,825,480✔
45
    int material = source_regions_.material(sr);
3,821,920✔
46
    if (material == MATERIAL_VOID) {
3,821,920✔
47
      continue;
320,000✔
48
    }
49
    MomentMatrix invM = source_regions_.mom_matrix(sr).inverse();
3,501,920✔
50

51
    for (int g_out = 0; g_out < negroups_; g_out++) {
10,028,800✔
52
      double sigma_t = sigma_t_[material * negroups_ + g_out];
6,526,880✔
53

54
      double scatter_flat = 0.0f;
6,526,880✔
55
      double fission_flat = 0.0f;
6,526,880✔
56
      MomentArray scatter_linear = {0.0, 0.0, 0.0};
6,526,880✔
57
      MomentArray fission_linear = {0.0, 0.0, 0.0};
6,526,880✔
58

59
      for (int g_in = 0; g_in < negroups_; g_in++) {
34,228,480✔
60
        // Handles for the flat and linear components of the flux
61
        double flux_flat = source_regions_.scalar_flux_old(sr, g_in);
27,701,600✔
62
        MomentArray flux_linear = source_regions_.flux_moments_old(sr, g_in);
27,701,600✔
63

64
        // Handles for cross sections
65
        double sigma_s =
66
          sigma_s_[material * negroups_ * negroups_ + g_out * negroups_ + g_in];
27,701,600✔
67
        double nu_sigma_f = nu_sigma_f_[material * negroups_ + g_in];
27,701,600✔
68
        double chi = chi_[material * negroups_ + g_out];
27,701,600✔
69

70
        // Compute source terms for flat and linear components of the flux
71
        scatter_flat += sigma_s * flux_flat;
27,701,600✔
72
        fission_flat += nu_sigma_f * flux_flat * chi;
27,701,600✔
73
        scatter_linear += sigma_s * flux_linear;
27,701,600✔
74
        fission_linear += nu_sigma_f * flux_linear * chi;
27,701,600✔
75
      }
76

77
      // Compute the flat source term
78
      source_regions_.source(sr, g_out) =
13,053,760✔
79
        (scatter_flat + fission_flat * inverse_k_eff) / sigma_t;
6,526,880✔
80

81
      // Compute the linear source terms
82
      // In the first 10 iterations when the centroids and spatial moments
83
      // are not well known, we will leave the source gradients as zero
84
      // so as to avoid causing any numerical instability.
85
      if (simulation::current_batch > 10) {
6,526,880✔
86
        source_regions_.source_gradients(sr, g_out) =
5,309,280✔
87
          invM * ((scatter_linear + fission_linear * inverse_k_eff) / sigma_t);
10,618,560✔
88
      }
89
    }
90
  }
91

92
  if (settings::run_mode == RunMode::FIXED_SOURCE) {
7,565✔
93
// Add external source to flat source term if in fixed source mode
94
#pragma omp parallel for
3,285✔
95
    for (int64_t se = 0; se < n_source_elements_; se++) {
5,756,680✔
96
      source_regions_.source(se) += source_regions_.external_source(se);
5,753,760✔
97
    }
98
  }
99

100
  simulation::time_update_src.stop();
7,565✔
101
}
7,565✔
102

103
void LinearSourceDomain::normalize_scalar_flux_and_volumes(
7,565✔
104
  double total_active_distance_per_iteration)
105
{
106
  double normalization_factor = 1.0 / total_active_distance_per_iteration;
7,565✔
107
  double volume_normalization_factor =
7,565✔
108
    1.0 / (total_active_distance_per_iteration * simulation::current_batch);
7,565✔
109

110
// Normalize flux to total distance travelled by all rays this iteration
111
#pragma omp parallel for
4,005✔
112
  for (int64_t se = 0; se < n_source_elements_; se++) {
6,850,440✔
113
    source_regions_.scalar_flux_new(se) *= normalization_factor;
6,846,880✔
114
    source_regions_.flux_moments_new(se) *= normalization_factor;
6,846,880✔
115
  }
116

117
// Accumulate cell-wise ray length tallies collected this iteration, then
118
// update the simulation-averaged cell-wise volume estimates
119
#pragma omp parallel for
4,005✔
120
  for (int64_t sr = 0; sr < n_source_regions_; sr++) {
3,825,480✔
121
    source_regions_.centroid_t(sr) += source_regions_.centroid_iteration(sr);
3,821,920✔
122
    source_regions_.mom_matrix_t(sr) += source_regions_.mom_matrix(sr);
3,821,920✔
123
    source_regions_.volume_t(sr) += source_regions_.volume(sr);
3,821,920✔
124
    source_regions_.volume_sq_t(sr) += source_regions_.volume_sq(sr);
3,821,920✔
125
    source_regions_.volume_naive(sr) =
7,643,840✔
126
      source_regions_.volume(sr) * normalization_factor;
3,821,920✔
127
    source_regions_.volume(sr) =
7,643,840✔
128
      source_regions_.volume_t(sr) * volume_normalization_factor;
3,821,920✔
129
    source_regions_.volume_sq(sr) =
7,643,840✔
130
      (source_regions_.volume_sq_t(sr) / source_regions_.volume_t(sr)) *
3,821,920✔
131
      volume_normalization_factor;
132
    if (source_regions_.volume_t(sr) > 0.0) {
3,821,920✔
133
      double inv_volume = 1.0 / source_regions_.volume_t(sr);
3,821,920✔
134
      source_regions_.centroid(sr) = source_regions_.centroid_t(sr);
3,821,920✔
135
      source_regions_.centroid(sr) *= inv_volume;
3,821,920✔
136
      source_regions_.mom_matrix(sr) = source_regions_.mom_matrix_t(sr);
3,821,920✔
137
      source_regions_.mom_matrix(sr) *= inv_volume;
3,821,920✔
138
    }
139
  }
140
}
7,565✔
141

142
void LinearSourceDomain::set_flux_to_flux_plus_source(
14,549,620✔
143
  int64_t sr, double volume, int g)
144
{
145
  int material = source_regions_.material(sr);
14,549,620✔
146
  if (material == MATERIAL_VOID) {
14,549,620✔
147
    FlatSourceDomain::set_flux_to_flux_plus_source(sr, volume, g);
680,000✔
148
  } else {
149
    source_regions_.scalar_flux_new(sr, g) /= volume;
13,869,620✔
150
    source_regions_.scalar_flux_new(sr, g) += source_regions_.source(sr, g);
13,869,620✔
151
  }
152
  source_regions_.flux_moments_new(sr, g) *= (1.0 / volume);
14,549,620✔
153
}
14,549,620✔
154

UNCOV
155
void LinearSourceDomain::set_flux_to_old_flux(int64_t sr, int g)
×
156
{
UNCOV
157
  source_regions_.scalar_flux_new(g) = source_regions_.scalar_flux_old(g);
×
UNCOV
158
  source_regions_.flux_moments_new(g) = source_regions_.flux_moments_old(g);
×
159
}
160

161
void LinearSourceDomain::accumulate_iteration_flux()
3,145✔
162
{
163
  // Accumulate scalar flux
164
  FlatSourceDomain::accumulate_iteration_flux();
3,145✔
165

166
  // Accumulate scalar flux moments
167
#pragma omp parallel for
1,665✔
168
  for (int64_t se = 0; se < n_source_elements_; se++) {
2,694,120✔
169
    source_regions_.flux_moments_t(se) += source_regions_.flux_moments_new(se);
2,692,640✔
170
  }
171
}
3,145✔
172

173
double LinearSourceDomain::evaluate_flux_at_point(
×
174
  Position r, int64_t sr, int g) const
175
{
UNCOV
176
  double phi_flat = FlatSourceDomain::evaluate_flux_at_point(r, sr, g);
×
177

UNCOV
178
  Position local_r = r - source_regions_.centroid(sr);
×
UNCOV
179
  MomentArray phi_linear = source_regions_.flux_moments_t(sr, g);
×
UNCOV
180
  phi_linear *= 1.0 / (settings::n_batches - settings::n_inactive);
×
181

UNCOV
182
  MomentMatrix invM = source_regions_.mom_matrix(sr).inverse();
×
UNCOV
183
  MomentArray phi_solved = invM * phi_linear;
×
184

UNCOV
185
  return phi_flat + phi_solved.dot(local_r);
×
186
}
187

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

© 2025 Coveralls, Inc