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

openmc-dev / openmc / 13076146263

31 Jan 2025 03:51PM UTC coverage: 84.909% (+0.05%) from 84.863%
13076146263

Pull #3288

github

web-flow
Merge e9066cabf into d9c8e594c
Pull Request #3288: Random Ray Source Region Refactor

277 of 289 new or added lines in 7 files covered. (95.85%)

2 existing lines in 1 file now uncovered.

50184 of 59103 relevant lines covered (84.91%)

34628929.3 hits per line

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

87.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()
6,885✔
24
{
25
  FlatSourceDomain::batch_reset();
6,885✔
26
#pragma omp parallel for
3,645✔
27
  for (int64_t sr = 0; sr < n_source_regions_; sr++) {
3,272,200✔
28
    source_regions_.centroid_iteration(sr) = {0.0, 0.0, 0.0};
3,268,960✔
29
    source_regions_.mom_matrix(sr) = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
3,268,960✔
30
  }
31
#pragma omp parallel for
3,645✔
32
  for (int64_t se = 0; se < n_source_elements_; se++) {
6,297,160✔
33
    source_regions_.flux_moments_new(se) = {0.0, 0.0, 0.0};
6,293,920✔
34
  }
35
}
6,885✔
36

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

41
  double inverse_k_eff = 1.0 / k_eff;
6,885✔
42

43
#pragma omp parallel for
3,645✔
44
  for (int64_t sr = 0; sr < n_source_regions_; sr++) {
3,272,200✔
45
    int material = source_regions_.material(sr);
3,268,960✔
46
    MomentMatrix invM = source_regions_.mom_matrix(sr).inverse();
3,268,960✔
47

48
    for (int g_out = 0; g_out < negroups_; g_out++) {
9,562,880✔
49
      double sigma_t = sigma_t_[material * negroups_ + g_out];
6,293,920✔
50

51
      double scatter_flat = 0.0f;
6,293,920✔
52
      double fission_flat = 0.0f;
6,293,920✔
53
      MomentArray scatter_linear = {0.0, 0.0, 0.0};
6,293,920✔
54
      MomentArray fission_linear = {0.0, 0.0, 0.0};
6,293,920✔
55

56
      for (int g_in = 0; g_in < negroups_; g_in++) {
33,762,560✔
57
        // Handles for the flat and linear components of the flux
58
        double flux_flat = source_regions_.scalar_flux_old(sr, g_in);
27,468,640✔
59
        MomentArray flux_linear = source_regions_.flux_moments_old(sr, g_in);
27,468,640✔
60

61
        // Handles for cross sections
62
        double sigma_s =
63
          sigma_s_[material * negroups_ * negroups_ + g_out * negroups_ + g_in];
27,468,640✔
64
        double nu_sigma_f = nu_sigma_f_[material * negroups_ + g_in];
27,468,640✔
65
        double chi = chi_[material * negroups_ + g_out];
27,468,640✔
66

67
        // Compute source terms for flat and linear components of the flux
68
        scatter_flat += sigma_s * flux_flat;
27,468,640✔
69
        fission_flat += nu_sigma_f * flux_flat * chi;
27,468,640✔
70
        scatter_linear += sigma_s * flux_linear;
27,468,640✔
71
        fission_linear += nu_sigma_f * flux_linear * chi;
27,468,640✔
72
      }
73

74
      // Compute the flat source term
75
      source_regions_.source(sr, g_out) =
12,587,840✔
76
        (scatter_flat + fission_flat * inverse_k_eff) / sigma_t;
6,293,920✔
77

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

89
  if (settings::run_mode == RunMode::FIXED_SOURCE) {
6,885✔
90
// Add external source to flat source term if in fixed source mode
91
#pragma omp parallel for
2,925✔
92
    for (int64_t se = 0; se < n_source_elements_; se++) {
5,203,400✔
93
      source_regions_.source(se) += source_regions_.external_source(se);
5,200,800✔
94
    }
95
  }
96

97
  simulation::time_update_src.stop();
6,885✔
98
}
6,885✔
99

100
void LinearSourceDomain::normalize_scalar_flux_and_volumes(
6,885✔
101
  double total_active_distance_per_iteration)
102
{
103
  double normalization_factor = 1.0 / total_active_distance_per_iteration;
6,885✔
104
  double volume_normalization_factor =
6,885✔
105
    1.0 / (total_active_distance_per_iteration * simulation::current_batch);
6,885✔
106

107
// Normalize flux to total distance travelled by all rays this iteration
108
#pragma omp parallel for
3,645✔
109
  for (int64_t se = 0; se < n_source_elements_; se++) {
6,297,160✔
110
    source_regions_.scalar_flux_new(se) *= normalization_factor;
6,293,920✔
111
    source_regions_.flux_moments_new(se) *= normalization_factor;
6,293,920✔
112
  }
113

114
// Accumulate cell-wise ray length tallies collected this iteration, then
115
// update the simulation-averaged cell-wise volume estimates
116
#pragma omp parallel for
3,645✔
117
  for (int64_t sr = 0; sr < n_source_regions_; sr++) {
3,272,200✔
118
    source_regions_.centroid_t(sr) += source_regions_.centroid_iteration(sr);
3,268,960✔
119
    source_regions_.mom_matrix_t(sr) += source_regions_.mom_matrix(sr);
3,268,960✔
120
    source_regions_.volume_t(sr) += source_regions_.volume(sr);
3,268,960✔
121
    source_regions_.volume_naive(sr) =
6,537,920✔
122
      source_regions_.volume(sr) * normalization_factor;
3,268,960✔
123
    source_regions_.volume(sr) =
6,537,920✔
124
      source_regions_.volume_t(sr) * volume_normalization_factor;
3,268,960✔
125
    if (source_regions_.volume_t(sr) > 0.0) {
3,268,960✔
126
      double inv_volume = 1.0 / source_regions_.volume_t(sr);
3,268,960✔
127
      source_regions_.centroid(sr) = source_regions_.centroid_t(sr);
3,268,960✔
128
      source_regions_.centroid(sr) *= inv_volume;
3,268,960✔
129
      source_regions_.mom_matrix(sr) = source_regions_.mom_matrix_t(sr);
3,268,960✔
130
      source_regions_.mom_matrix(sr) *= inv_volume;
3,268,960✔
131
    }
132
  }
133
}
6,885✔
134

135
void LinearSourceDomain::set_flux_to_flux_plus_source(
13,374,580✔
136
  int64_t sr, double volume, int g)
137
{
138
  source_regions_.scalar_flux_new(sr, g) /= volume;
13,374,580✔
139
  source_regions_.scalar_flux_new(sr, g) += source_regions_.source(sr, g);
13,374,580✔
140
  source_regions_.flux_moments_new(sr, g) *= (1.0 / volume);
13,374,580✔
141
}
13,374,580✔
142

NEW
143
void LinearSourceDomain::set_flux_to_old_flux(int64_t sr, int g)
×
144
{
NEW
145
  source_regions_.scalar_flux_new(g) = source_regions_.scalar_flux_old(g);
×
NEW
146
  source_regions_.flux_moments_new(g) = source_regions_.flux_moments_old(g);
×
147
}
148

149
void LinearSourceDomain::accumulate_iteration_flux()
2,805✔
150
{
151
  // Accumulate scalar flux
152
  FlatSourceDomain::accumulate_iteration_flux();
2,805✔
153

154
  // Accumulate scalar flux moments
155
#pragma omp parallel for
1,485✔
156
  for (int64_t se = 0; se < n_source_elements_; se++) {
2,417,480✔
157
    source_regions_.flux_moments_t(se) += source_regions_.flux_moments_new(se);
2,416,160✔
158
  }
159
}
2,805✔
160

UNCOV
161
double LinearSourceDomain::evaluate_flux_at_point(
×
162
  Position r, int64_t sr, int g) const
163
{
164
  double phi_flat = FlatSourceDomain::evaluate_flux_at_point(r, sr, g);
×
165

NEW
166
  Position local_r = r - source_regions_.centroid(sr);
×
NEW
167
  MomentArray phi_linear = source_regions_.flux_moments_t(sr, g);
×
UNCOV
168
  phi_linear *= 1.0 / (settings::n_batches - settings::n_inactive);
×
169

NEW
170
  MomentMatrix invM = source_regions_.mom_matrix(sr).inverse();
×
171
  MomentArray phi_solved = invM * phi_linear;
×
172

173
  return phi_flat + phi_solved.dot(local_r);
×
174
}
175

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