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

openmc-dev / openmc / 14840340664

05 May 2025 03:38PM UTC coverage: 85.195% (-0.009%) from 85.204%
14840340664

Pull #3392

github

web-flow
Merge 5bc1ec35f into 1e7d8324e
Pull Request #3392: Map Compton subshell data to atomic relaxation data

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

330 existing lines in 19 files now uncovered.

52194 of 61264 relevant lines covered (85.2%)

37398320.1 hits per line

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

0.0
/include/openmc/random_ray/flat_source_domain.h
1
#ifndef OPENMC_RANDOM_RAY_FLAT_SOURCE_DOMAIN_H
2
#define OPENMC_RANDOM_RAY_FLAT_SOURCE_DOMAIN_H
3

4
#include "openmc/constants.h"
5
#include "openmc/openmp_interface.h"
6
#include "openmc/position.h"
7
#include "openmc/random_ray/parallel_map.h"
8
#include "openmc/random_ray/source_region.h"
9
#include "openmc/source.h"
10
#include <unordered_map>
11
#include <unordered_set>
12

13
namespace openmc {
14

15
/*
16
 * The FlatSourceDomain class encompasses data and methods for storing
17
 * scalar flux and source region for all flat source regions in a
18
 * random ray simulation domain.
19
 */
20

21
class FlatSourceDomain {
22
public:
23
  //----------------------------------------------------------------------------
24
  // Constructors and Destructors
25
  FlatSourceDomain();
UNCOV
26
  virtual ~FlatSourceDomain() = default;
×
UNCOV
27

×
UNCOV
28
  //----------------------------------------------------------------------------
×
29
  // Methods
30
  virtual void update_neutron_source(double k_eff);
31
  double compute_k_eff(double k_eff_old) const;
32
  virtual void normalize_scalar_flux_and_volumes(
33
    double total_active_distance_per_iteration);
34

35
  int64_t add_source_to_scalar_flux();
36
  virtual void batch_reset();
37
  void convert_source_regions_to_tallies();
38
  void reset_tally_volumes();
39
  void random_ray_tally();
40
  virtual void accumulate_iteration_flux();
41
  void output_to_vtk() const;
42
  void convert_external_sources();
43
  void count_external_source_regions();
44
  void set_adjoint_sources(const vector<double>& forward_flux);
45
  void flux_swap();
46
  virtual double evaluate_flux_at_point(Position r, int64_t sr, int g) const;
47
  double compute_fixed_source_normalization_factor() const;
48
  void flatten_xs();
49
  void transpose_scattering_matrix();
50
  void serialize_final_fluxes(vector<double>& flux);
51
  void apply_meshes();
52
  void apply_mesh_to_cell_instances(int32_t i_cell, int32_t mesh_idx,
53
    int target_material_id, const vector<int32_t>& instances,
54
    bool is_target_void);
55
  void apply_mesh_to_cell_and_children(int32_t i_cell, int32_t mesh_idx,
56
    int32_t target_material_id, bool is_target_void);
57
  void prepare_base_source_regions();
58
  SourceRegionHandle get_subdivided_source_region_handle(
59
    int64_t sr, int mesh_bin, Position r, double dist, Direction u);
60
  void finalize_discovered_source_regions();
61
  void apply_transport_stabilization();
62
  int64_t n_source_regions() const
63
  {
UNCOV
64
    return source_regions_.n_source_regions();
×
65
  }
UNCOV
66
  int64_t n_source_elements() const
×
67
  {
UNCOV
68
    return source_regions_.n_source_regions() * negroups_;
×
69
  }
UNCOV
70

×
71
  //----------------------------------------------------------------------------
72
  // Static Data members
73
  static bool volume_normalized_flux_tallies_;
74
  static bool adjoint_; // If the user wants outputs based on the adjoint flux
75
  static double
76
    diagonal_stabilization_rho_; // Adjusts strength of diagonal stabilization
77
                                 // for transport corrected MGXS data
78

79
  // Static variables to store source region meshes and domains
80
  static std::unordered_map<int, vector<std::pair<Source::DomainType, int>>>
81
    mesh_domain_map_;
82

83
  //----------------------------------------------------------------------------
84
  // Static data members
85
  static RandomRayVolumeEstimator volume_estimator_;
86

87
  //----------------------------------------------------------------------------
88
  // Public Data members
89
  bool mapped_all_tallies_ {false}; // If all source regions have been visited
90

91
  int64_t n_external_source_regions_ {0}; // Total number of source regions with
92
                                          // non-zero external source terms
93

94
  // 1D array representing source region starting offset for each OpenMC Cell
95
  // in model::cells
96
  vector<int64_t> source_region_offsets_;
97

98
  // 2D arrays stored in 1D representing values for all materials x energy
99
  // groups
100
  int n_materials_;
101
  vector<double> sigma_t_;
102
  vector<double> nu_sigma_f_;
103
  vector<double> sigma_f_;
104
  vector<double> chi_;
105

106
  // 3D arrays stored in 1D representing values for all materials x energy
107
  // groups x energy groups
108
  vector<double> sigma_s_;
109

110
  // The abstract container holding all source region-specific data
111
  SourceRegionContainer source_regions_;
112

113
  // Base source region container. When source region subdivision via mesh
114
  // is in use, this container holds the original (non-subdivided) material
115
  // filled cell instance source regions. These are useful as they can be
116
  // initialized with external source and mesh domain information ahead of time.
117
  // Then, dynamically discovered source regions can be initialized by cloning
118
  // their base region.
119
  SourceRegionContainer base_source_regions_;
120

121
  // Parallel hash map holding all source regions discovered during
122
  // a single iteration. This is a threadsafe data structure that is cleaned
123
  // out after each iteration and stored in the "source_regions_" container.
124
  // It is keyed with a SourceRegionKey, which combines the base source
125
  // region index and the mesh bin.
126
  ParallelMap<SourceRegionKey, SourceRegion, SourceRegionKey::HashFunctor>
127
    discovered_source_regions_;
128

129
  // Map that relates a SourceRegionKey to the index at which the source
130
  // region can be found in the "source_regions_" container.
131
  std::unordered_map<SourceRegionKey, int64_t, SourceRegionKey::HashFunctor>
132
    source_region_map_;
133

134
  // Map that relates a SourceRegionKey to the external source index. This map
135
  // is used to check if there are any point sources within a subdivided source
136
  // region at the time it is discovered.
137
  std::unordered_map<SourceRegionKey, int64_t, SourceRegionKey::HashFunctor>
138
    point_source_map_;
139

140
  // If transport corrected MGXS data is being used, there may be negative
141
  // in-group scattering cross sections that can result in instability in MOC
142
  // and random ray if used naively. This flag enables a stabilization
143
  // technique.
144
  bool is_transport_stabilization_needed_ {false};
145

146
protected:
147
  //----------------------------------------------------------------------------
148
  // Methods
149
  void apply_external_source_to_source_region(
150
    Discrete* discrete, double strength_factor, SourceRegionHandle& srh);
151
  void apply_external_source_to_cell_instances(int32_t i_cell,
152
    Discrete* discrete, double strength_factor, int target_material_id,
153
    const vector<int32_t>& instances);
154
  void apply_external_source_to_cell_and_children(int32_t i_cell,
155
    Discrete* discrete, double strength_factor, int32_t target_material_id);
156
  virtual void set_flux_to_flux_plus_source(int64_t sr, double volume, int g);
157
  void set_flux_to_source(int64_t sr, int g);
158
  virtual void set_flux_to_old_flux(int64_t sr, int g);
159

160
  //----------------------------------------------------------------------------
161
  // Private data members
162
  int negroups_; // Number of energy groups in simulation
163

164
  double
165
    simulation_volume_; // Total physical volume of the simulation domain, as
166
                        // defined by the 3D box of the random ray source
167

168
  // Volumes for each tally and bin/score combination. This intermediate data
169
  // structure is used when tallying quantities that must be normalized by
170
  // volume (i.e., flux). The vector is index by tally index, while the inner 2D
171
  // xtensor is indexed by bin index and score index in a similar manner to the
172
  // results tensor in the Tally class, though without the third dimension, as
173
  // SUM and SUM_SQ do not need to be tracked.
174
  vector<xt::xtensor<double, 2>> tally_volumes_;
175

176
}; // class FlatSourceDomain
177

178
//============================================================================
179
//! Non-member functions
180
//============================================================================
181

182
// Returns the inputted value in big endian byte ordering. If the system is
183
// little endian, the byte ordering is flipped. If the system is big endian,
184
// the inputted value is returned as is. This function is necessary as
185
// .vtk binary files use big endian byte ordering.
186
template<typename T>
187
T convert_to_big_endian(T in)
188
{
189
  // 4 byte integer
190
  uint32_t test = 1;
191

192
  // 1 byte pointer to first byte of test integer
193
  uint8_t* ptr = reinterpret_cast<uint8_t*>(&test);
194

195
  // If the first byte of test is 0, then the system is big endian. In this
196
  // case, we don't have to do anything as .vtk files are big endian
197
  if (*ptr == 0)
198
    return in;
199

200
  // Otherwise, the system is in little endian, so we need to flip the
201
  // endianness
202
  uint8_t* orig = reinterpret_cast<uint8_t*>(&in);
203
  uint8_t swapper[sizeof(T)];
204
  for (int i = 0; i < sizeof(T); i++) {
205
    swapper[i] = orig[sizeof(T) - i - 1];
206
  }
207
  T out = *reinterpret_cast<T*>(&swapper);
208
  return out;
209
}
210

211
} // namespace openmc
212

213
#endif // OPENMC_RANDOM_RAY_FLAT_SOURCE_DOMAIN_H
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