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

openmc-dev / openmc / 11051541459

26 Sep 2024 11:45AM UTC coverage: 84.794% (+0.07%) from 84.729%
11051541459

push

github

web-flow
Correct failure due to progress bar values  (#3143)

2 of 2 new or added lines in 1 file covered. (100.0%)

66 existing lines in 10 files now uncovered.

49444 of 58311 relevant lines covered (84.79%)

34090457.21 hits per line

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

83.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

10
namespace openmc {
11

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

16
class SpatialDistribution {
17
public:
18
  virtual ~SpatialDistribution() = default;
45,512✔
UNCOV
19

×
20
  //! Sample a position from the distribution
45,512✔
21
  virtual Position sample(uint64_t* seed) const = 0;
22

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2,271,071✔
131
  double total_strength() { return this->elem_idx_dist_.integral(); }
7✔
132

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

139
//==============================================================================
140
//! Uniform distribution of points over a box
141
//==============================================================================
142

143
class SpatialBox : public SpatialDistribution {
144
public:
145
  explicit SpatialBox(pugi::xml_node node, bool fission = false);
146

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

152
  // Properties
153
  bool only_fissionable() const { return only_fissionable_; }
2,287✔
154
  Position lower_left() const { return lower_left_; }
155
  Position upper_right() const { return upper_right_; }
156

157
private:
158
  Position lower_left_;           //!< Lower-left coordinates of box
159
  Position upper_right_;          //!< Upper-right coordinates of box
160
  bool only_fissionable_ {false}; //!< Only accept sites in fissionable region?
161
};
162

163
//==============================================================================
164
//! Distribution at a single point
165
//==============================================================================
166

167
class SpatialPoint : public SpatialDistribution {
168
public:
169
  SpatialPoint() : r_ {} {};
170
  SpatialPoint(Position r) : r_ {r} {};
171
  explicit SpatialPoint(pugi::xml_node node);
172

173
  //! Sample a position from the distribution
174
  //! \param seed Pseudorandom number seed pointer
175
  //! \return Sampled position
176
  Position sample(uint64_t* seed) const override;
177

178
  Position r() const { return r_; }
179

180
private:
181
  Position r_; //!< Single position at which sites are generated
182
};
183

184
using UPtrSpace = unique_ptr<SpatialDistribution>;
185

186
} // namespace openmc
187

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