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

openmc-dev / openmc / 13546000884

26 Feb 2025 02:19PM UTC coverage: 85.015% (-0.2%) from 85.186%
13546000884

Pull #3328

github

web-flow
Merge 67a173195 into e060534ff
Pull Request #3328: NCrystal becomes runtime rather than buildtime dependency

81 of 108 new or added lines in 6 files covered. (75.0%)

467 existing lines in 21 files now uncovered.

51062 of 60062 relevant lines covered (85.02%)

32488887.43 hits per line

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

33.33
/include/openmc/distribution_spatial.h
1
#ifndef OPENMC_DISTRIBUTION_SPATIAL_H
2
#define OPENMC_DISTRIBUTION_SPATIAL_H
3

4
#include "pugixml.hpp"
5

6
#include "openmc/distribution.h"
7
#include "openmc/mesh.h"
8
#include "openmc/position.h"
9
#include "openmc/span.h"
10

11
namespace openmc {
12

13
//==============================================================================
14
//! Probability density function for points in Euclidean space
15
//==============================================================================
16

17
class SpatialDistribution {
18
public:
19
  virtual ~SpatialDistribution() = default;
20

21
  //! Sample a position from the distribution
22
  virtual Position sample(uint64_t* seed) const = 0;
23

24
  static unique_ptr<SpatialDistribution> create(pugi::xml_node node);
25
};
26

27
//==============================================================================
28
//! Distribution of points specified by independent distributions in x,y,z
29
//==============================================================================
30

31
class CartesianIndependent : public SpatialDistribution {
32
public:
33
  explicit CartesianIndependent(pugi::xml_node node);
34

35
  //! Sample a position from the distribution
36
  //! \param seed Pseudorandom number seed pointer
37
  //! \return Sampled position
38
  Position sample(uint64_t* seed) const override;
39

40
  // Observer pointers
41
  Distribution* x() const { return x_.get(); }
42
  Distribution* y() const { return y_.get(); }
43
  Distribution* z() const { return z_.get(); }
44

45
private:
46
  UPtrDist x_; //!< Distribution of x coordinates
47
  UPtrDist y_; //!< Distribution of y coordinates
48
  UPtrDist z_; //!< Distribution of z coordinates
49
};
50

51
//==============================================================================
52
//! Distribution of points specified by cylindrical coordinates r,phi,z
53
//==============================================================================
54

55
class CylindricalIndependent : public SpatialDistribution {
56
public:
57
  explicit CylindricalIndependent(pugi::xml_node node);
58

59
  //! Sample a position from the distribution
60
  //! \param seed Pseudorandom number seed pointer
61
  //! \return Sampled position
62
  Position sample(uint64_t* seed) const override;
63

64
  Distribution* r() const { return r_.get(); }
65
  Distribution* phi() const { return phi_.get(); }
66
  Distribution* z() const { return z_.get(); }
67
  Position origin() const { return origin_; }
68

69
private:
70
  UPtrDist r_;      //!< Distribution of r coordinates
71
  UPtrDist phi_;    //!< Distribution of phi coordinates
72
  UPtrDist z_;      //!< Distribution of z coordinates
73
  Position origin_; //!< Cartesian coordinates of the cylinder center
74
};
75

76
//==============================================================================
77
//! Distribution of points specified by spherical coordinates r,cos_theta,phi
78
//==============================================================================
79

80
class SphericalIndependent : public SpatialDistribution {
81
public:
82
  explicit SphericalIndependent(pugi::xml_node node);
83

84
  //! Sample a position from the distribution
85
  //! \param seed Pseudorandom number seed pointer
86
  //! \return Sampled position
87
  Position sample(uint64_t* seed) const override;
88

89
  Distribution* r() const { return r_.get(); }
90
  Distribution* cos_theta() const { return cos_theta_.get(); }
91
  Distribution* phi() const { return phi_.get(); }
92
  Position origin() const { return origin_; }
93

94
private:
95
  UPtrDist r_;         //!< Distribution of r coordinates
96
  UPtrDist cos_theta_; //!< Distribution of cos_theta coordinates
97
  UPtrDist phi_;       //!< Distribution of phi coordinates
98
  Position origin_;    //!< Cartesian coordinates of the sphere center
99
};
100

101
//==============================================================================
102
//! Distribution of points within a mesh
103
//==============================================================================
104

105
class MeshSpatial : public SpatialDistribution {
106
public:
107
  explicit MeshSpatial(pugi::xml_node node);
108
  explicit MeshSpatial(int32_t mesh_id, span<const double> strengths);
109

110
  //! Sample a position from the distribution
111
  //! \param seed Pseudorandom number seed pointer
112
  //! \return Sampled position
113
  Position sample(uint64_t* seed) const override;
114

115
  //! Sample the mesh for an element and position within that element
116
  //! \param seed Pseudorandom number seed pointer
117
  //! \return Sampled element index and position within that element
118
  std::pair<int32_t, Position> sample_mesh(uint64_t* seed) const;
119

120
  //! Sample a mesh element
121
  //! \param seed Pseudorandom number seed pointer
122
  //! \return Sampled element index
123
  int32_t sample_element_index(uint64_t* seed) const;
124

125
  //! For unstructured meshes, ensure that elements are all linear tetrahedra
126
  void check_element_types() const;
127

128
  // Accessors
UNCOV
129
  const Mesh* mesh() const { return model::meshes.at(mesh_idx_).get(); }
×
130
  int32_t n_sources() const { return this->mesh()->n_bins(); }
131

132
  double total_strength() { return this->elem_idx_dist_.integral(); }
2,139✔
133

134
private:
135
  int32_t mesh_idx_ {C_NONE};
136
  DiscreteIndex elem_idx_dist_; //!< Distribution of
137
                                //!< mesh element indices
138
};
139

140
//==============================================================================
141
//! Distribution of points
142
//==============================================================================
143

144
class PointCloud : public SpatialDistribution {
145
public:
146
  explicit PointCloud(pugi::xml_node node);
147
  explicit PointCloud(
148
    std::vector<Position> point_cloud, span<const double> strengths);
149

150
  //! Sample a position from the distribution
151
  //! \param seed Pseudorandom number seed pointer
152
  //! \return Sampled position
153
  Position sample(uint64_t* seed) const override;
154

155
private:
156
  std::vector<Position> point_cloud_;
157
  DiscreteIndex point_idx_dist_; //!< Distribution of Position indices
158
};
159

160
//==============================================================================
161
//! Uniform distribution of points over a box
162
//==============================================================================
163

164
class SpatialBox : public SpatialDistribution {
165
public:
166
  explicit SpatialBox(pugi::xml_node node, bool fission = false);
167

168
  //! Sample a position from the distribution
169
  //! \param seed Pseudorandom number seed pointer
170
  //! \return Sampled position
171
  Position sample(uint64_t* seed) const override;
172

173
  // Properties
UNCOV
174
  bool only_fissionable() const { return only_fissionable_; }
×
UNCOV
175
  Position lower_left() const { return lower_left_; }
×
UNCOV
176
  Position upper_right() const { return upper_right_; }
×
177

178
private:
179
  Position lower_left_;           //!< Lower-left coordinates of box
180
  Position upper_right_;          //!< Upper-right coordinates of box
181
  bool only_fissionable_ {false}; //!< Only accept sites in fissionable region?
182
};
183

184
//==============================================================================
185
//! Distribution at a single point
186
//==============================================================================
187

188
class SpatialPoint : public SpatialDistribution {
189
public:
190
  SpatialPoint() : r_ {} {};
38,015✔
191
  SpatialPoint(Position r) : r_ {r} {};
192
  explicit SpatialPoint(pugi::xml_node node);
193

194
  //! Sample a position from the distribution
195
  //! \param seed Pseudorandom number seed pointer
196
  //! \return Sampled position
197
  Position sample(uint64_t* seed) const override;
198

199
  Position r() const { return r_; }
200

201
private:
202
  Position r_; //!< Single position at which sites are generated
203
};
204

205
using UPtrSpace = unique_ptr<SpatialDistribution>;
206

207
} // namespace openmc
208

209
#endif // OPENMC_DISTRIBUTION_SPATIAL_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