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

openmc-dev / openmc / 19058781736

04 Nov 2025 05:26AM UTC coverage: 82.008% (-3.1%) from 85.155%
19058781736

Pull #3252

github

web-flow
Merge b8a72730f into bd76fc056
Pull Request #3252: Adding vtkhdf option to write vtk data

16714 of 23236 branches covered (71.93%)

Branch coverage included in aggregate %.

61 of 66 new or added lines in 1 file covered. (92.42%)

3175 existing lines in 103 files now uncovered.

54243 of 63288 relevant lines covered (85.71%)

43393337.77 hits per line

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

33.33
/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();
26
  virtual ~FlatSourceDomain() = default;
914✔
27

28
  //----------------------------------------------------------------------------
29
  // Methods
30
  virtual void update_single_neutron_source(SourceRegionHandle& srh);
31
  virtual void update_all_neutron_sources();
32
  void compute_k_eff();
33
  virtual void normalize_scalar_flux_and_volumes(
34
    double total_active_distance_per_iteration);
35

36
  int64_t add_source_to_scalar_flux();
37
  virtual void batch_reset();
38
  void convert_source_regions_to_tallies(int64_t start_sr_id);
39
  void reset_tally_volumes();
40
  void random_ray_tally();
41
  virtual void accumulate_iteration_flux();
42
  void output_to_vtk() const;
43
  void convert_external_sources();
44
  void count_external_source_regions();
45
  void set_adjoint_sources();
46
  void flux_swap();
47
  virtual double evaluate_flux_at_point(Position r, int64_t sr, int g) const;
48
  double compute_fixed_source_normalization_factor() const;
49
  void flatten_xs();
50
  void transpose_scattering_matrix();
51
  void serialize_final_fluxes(vector<double>& flux);
52
  void apply_meshes();
53
  void apply_mesh_to_cell_instances(int32_t i_cell, int32_t mesh_idx,
54
    int target_material_id, const vector<int32_t>& instances,
55
    bool is_target_void);
56
  void apply_mesh_to_cell_and_children(int32_t i_cell, int32_t mesh_idx,
57
    int32_t target_material_id, bool is_target_void);
58
  SourceRegionHandle get_subdivided_source_region_handle(
59
    SourceRegionKey sr_key, Position r, Direction u);
60
  void finalize_discovered_source_regions();
61
  void apply_transport_stabilization();
62
  int64_t n_source_regions() const
177,678,564✔
63
  {
64
    return source_regions_.n_source_regions();
177,678,564✔
65
  }
66
  int64_t n_source_elements() const
113,871,074✔
67
  {
68
    return source_regions_.n_source_regions() * negroups_;
113,871,074✔
69
  }
70
  int64_t lookup_base_source_region_idx(const GeometryState& p) const;
71
  SourceRegionKey lookup_source_region_key(const GeometryState& p) const;
72
  int64_t lookup_mesh_bin(int64_t sr, Position r) const;
73
  int lookup_mesh_idx(int64_t sr) const;
74

75
  //----------------------------------------------------------------------------
76
  // Static Data members
77
  static bool volume_normalized_flux_tallies_;
78
  static bool adjoint_; // If the user wants outputs based on the adjoint flux
79
  static double
80
    diagonal_stabilization_rho_; // Adjusts strength of diagonal stabilization
81
                                 // for transport corrected MGXS data
82

83
  // Static variables to store source region meshes and domains
84
  static std::unordered_map<int, vector<std::pair<Source::DomainType, int>>>
85
    mesh_domain_map_;
86

87
  //----------------------------------------------------------------------------
88
  // Static data members
89
  static RandomRayVolumeEstimator volume_estimator_;
90

91
  //----------------------------------------------------------------------------
92
  // Public Data members
93
  double k_eff_ {1.0};              // Eigenvalue
94
  bool mapped_all_tallies_ {false}; // If all source regions have been visited
95

96
  int64_t n_external_source_regions_ {0}; // Total number of source regions with
97
                                          // non-zero external source terms
98

99
  // 1D array representing source region starting offset for each OpenMC Cell
100
  // in model::cells
101
  vector<int64_t> source_region_offsets_;
102

103
  // 2D arrays stored in 1D representing values for all materials x energy
104
  // groups
105
  int n_materials_;
106
  vector<double> sigma_t_;
107
  vector<double> nu_sigma_f_;
108
  vector<double> sigma_f_;
109
  vector<double> chi_;
110

111
  // 3D arrays stored in 1D representing values for all materials x energy
112
  // groups x energy groups
113
  vector<double> sigma_s_;
114

115
  // The abstract container holding all source region-specific data
116
  SourceRegionContainer source_regions_;
117

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

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

131
  // Map that relates a SourceRegionKey to the external source index. This map
132
  // is used to check if there are any point sources within a subdivided source
133
  // region at the time it is discovered.
134
  std::unordered_map<SourceRegionKey, vector<int>, SourceRegionKey::HashFunctor>
135
    external_point_source_map_;
136

137
  // Map that relates a base source region index to the external source index.
138
  // This map is used to check if there are any volumetric sources within a
139
  // subdivided source region at the time it is discovered.
140
  std::unordered_map<int64_t, vector<int>> external_volumetric_source_map_;
141

142
  // Map that relates a base source region index to a mesh index. This map
143
  // is used to check which subdivision mesh is present in a source region.
144
  std::unordered_map<int64_t, int> mesh_map_;
145

146
  // If transport corrected MGXS data is being used, there may be negative
147
  // in-group scattering cross sections that can result in instability in MOC
148
  // and random ray if used naively. This flag enables a stabilization
149
  // technique.
150
  bool is_transport_stabilization_needed_ {false};
151

152
protected:
153
  //----------------------------------------------------------------------------
154
  // Methods
155
  void apply_external_source_to_source_region(
156
    int src_idx, SourceRegionHandle& srh);
157
  void apply_external_source_to_cell_instances(int32_t i_cell, int src_idx,
158
    int target_material_id, const vector<int32_t>& instances);
159
  void apply_external_source_to_cell_and_children(
160
    int32_t i_cell, int src_idx, int32_t target_material_id);
161
  virtual void set_flux_to_flux_plus_source(int64_t sr, double volume, int g);
162
  void set_flux_to_source(int64_t sr, int g);
163
  virtual void set_flux_to_old_flux(int64_t sr, int g);
164

165
  //----------------------------------------------------------------------------
166
  // Private data members
167
  int negroups_; // Number of energy groups in simulation
168

169
  double
170
    simulation_volume_; // Total physical volume of the simulation domain, as
171
                        // defined by the 3D box of the random ray source
172

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

181
}; // class FlatSourceDomain
182

183
//============================================================================
184
//! Non-member functions
185
//============================================================================
186

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

197
  // 1 byte pointer to first byte of test integer
UNCOV
198
  uint8_t* ptr = reinterpret_cast<uint8_t*>(&test);
×
199

200
  // If the first byte of test is 0, then the system is big endian. In this
201
  // case, we don't have to do anything as .vtk files are big endian
UNCOV
202
  if (*ptr == 0)
×
UNCOV
203
    return in;
×
204

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

216
} // namespace openmc
217

218
#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

© 2026 Coveralls, Inc