• 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/scattdata.h
1
//! \file scattdata.h
2
//! A collection of multi-group scattering data classes
3

4
#ifndef OPENMC_SCATTDATA_H
5
#define OPENMC_SCATTDATA_H
6

7
#include "xtensor/xtensor.hpp"
8

9
#include "openmc/constants.h"
10
#include "openmc/vector.h"
11

12
namespace openmc {
13

14
// forward declarations so we can name our friend functions
15
class ScattDataLegendre;
16
class ScattDataTabular;
17

18
//==============================================================================
19
// SCATTDATA contains all the data needed to describe the scattering energy and
20
// angular distribution data
21
//==============================================================================
22

23
class ScattData {
24
public:
UNCOV
25
  virtual ~ScattData() = default;
×
26

×
UNCOV
27
protected:
×
28
  //! \brief Initializes the attributes of the base class.
29
  void base_init(int order, const xt::xtensor<int, 1>& in_gmin,
30
    const xt::xtensor<int, 1>& in_gmax, const double_2dvec& in_energy,
31
    const double_2dvec& in_mult);
32

33
  //! \brief Combines microscopic ScattDatas into a macroscopic one.
34
  void base_combine(size_t max_order, size_t order_dim,
35
    const vector<ScattData*>& those_scatts, const vector<double>& scalars,
36
    xt::xtensor<int, 1>& in_gmin, xt::xtensor<int, 1>& in_gmax,
37
    double_2dvec& sparse_mult, double_3dvec& sparse_scatter);
38

39
public:
40
  double_2dvec energy;            // Normalized p0 matrix for sampling Eout
41
  double_2dvec mult;              // nu-scatter multiplication (nu-scatt/scatt)
42
  double_3dvec dist;              // Angular distribution
43
  xt::xtensor<int, 1> gmin;       // minimum outgoing group
44
  xt::xtensor<int, 1> gmax;       // maximum outgoing group
45
  xt::xtensor<double, 1> scattxs; // Isotropic Sigma_{s,g_{in}}
46

47
  //! \brief Calculates the value of normalized f(mu).
48
  //!
49
  //! The value of f(mu) is normalized as in the integral of f(mu)dmu across
50
  //! [-1,1] is 1.
51
  //!
52
  //! @param gin Incoming energy group of interest.
53
  //! @param gout Outgoing energy group of interest.
54
  //! @param mu Cosine of the change-in-angle of interest.
55
  //! @return The value of f(mu).
56
  virtual double calc_f(int gin, int gout, double mu) = 0;
57

58
  //! \brief Samples the outgoing energy and angle from the ScattData info.
59
  //!
60
  //! @param gin Incoming energy group.
61
  //! @param gout Sampled outgoing energy group.
62
  //! @param mu Sampled cosine of the change-in-angle.
63
  //! @param wgt Weight of the particle to be adjusted.
64
  //! @param seed Pseudorandom number seed pointer
65
  virtual void sample(
66
    int gin, int& gout, double& mu, double& wgt, uint64_t* seed) = 0;
67

68
  //! \brief Initializes the ScattData object from a given scatter and
69
  //!   multiplicity matrix.
70
  //!
71
  //! @param in_gmin List of minimum outgoing groups for every incoming group
72
  //! @param in_gmax List of maximum outgoing groups for every incoming group
73
  //! @param in_mult Input sparse multiplicity matrix
74
  //! @param coeffs Input sparse scattering matrix
75
  virtual void init(const xt::xtensor<int, 1>& in_gmin,
76
    const xt::xtensor<int, 1>& in_gmax, const double_2dvec& in_mult,
77
    const double_3dvec& coeffs) = 0;
78

79
  //! \brief Combines the microscopic data.
80
  //!
81
  //! @param those_scatts Microscopic objects to combine.
82
  //! @param scalars Scalars to multiply the microscopic data by.
83
  virtual void combine(
84
    const vector<ScattData*>& those_scatts, const vector<double>& scalars) = 0;
85

86
  //! \brief Getter for the dimensionality of the scattering order.
87
  //!
88
  //! If Legendre this is the "n" in "Pn"; for Tabular, this is the number
89
  //! of points, and for Histogram this is the number of bins.
90
  //!
91
  //! @return The order.
92
  virtual size_t get_order() = 0;
93

94
  //! \brief Builds a dense scattering matrix from the constituent parts
95
  //!
96
  //! @param max_order If Legendre this is the maximum value of "n" in "Pn"
97
  //!   requested; ignored otherwise.
98
  //! @return The dense scattering matrix.
99
  virtual xt::xtensor<double, 3> get_matrix(size_t max_order) = 0;
100

101
  //! \brief Samples the outgoing energy from the ScattData info.
102
  //!
103
  //! @param gin Incoming energy group.
104
  //! @param gout Sampled outgoing energy group.
105
  //! @param i_gout Sampled outgoing energy group index.
106
  //! @param seed Pseudorandom number seed pointer
107
  void sample_energy(int gin, int& gout, int& i_gout, uint64_t* seed);
108

109
  //! \brief Provides a cross section value given certain parameters
110
  //!
111
  //! @param xstype Type of cross section requested, according to the
112
  //!   enumerated constants.
113
  //! @param gin Incoming energy group.
114
  //! @param gout Outgoing energy group; use nullptr if irrelevant, or if a
115
  //!   sum is requested.
116
  //! @param mu Cosine of the change-in-angle, for scattering quantities;
117
  //!   use nullptr if irrelevant.
118
  //! @return Requested cross section value.
119
  double get_xs(MgxsType xstype, int gin, const int* gout, const double* mu);
120
};
121

122
//==============================================================================
123
// ScattDataLegendre represents the angular distributions as Legendre kernels
124
//==============================================================================
125

126
class ScattDataLegendre : public ScattData {
127

128
protected:
129
  // Maximal value for rejection sampling from a rectangle
130
  double_2dvec max_val;
131

132
  // Friend convert_legendre_to_tabular so it has access to protected
133
  // parameters
134
  friend void convert_legendre_to_tabular(
135
    ScattDataLegendre& leg, ScattDataTabular& tab);
136

137
public:
138
  void init(const xt::xtensor<int, 1>& in_gmin,
139
    const xt::xtensor<int, 1>& in_gmax, const double_2dvec& in_mult,
140
    const double_3dvec& coeffs) override;
141

142
  void combine(const vector<ScattData*>& those_scatts,
143
    const vector<double>& scalars) override;
144

145
  //! \brief Find the maximal value of the angular distribution to use as a
146
  // bounding box with rejection sampling.
147
  void update_max_val();
148

149
  double calc_f(int gin, int gout, double mu) override;
150

151
  void sample(
152
    int gin, int& gout, double& mu, double& wgt, uint64_t* seed) override;
153

154
  size_t get_order() override { return dist[0][0].size() - 1; };
155

156
  xt::xtensor<double, 3> get_matrix(size_t max_order) override;
157
};
158

159
//==============================================================================
160
// ScattDataHistogram represents the angular distributions as a histogram, as it
161
// would be if it came from a "mu" tally in OpenMC
162
//==============================================================================
163

164
class ScattDataHistogram : public ScattData {
165

166
protected:
167
  xt::xtensor<double, 1> mu; // Angle distribution mu bin boundaries
168
  double dmu;                // Quick storage of the mu spacing
169
  double_3dvec fmu;          // The angular distribution histogram
170

171
public:
172
  void init(const xt::xtensor<int, 1>& in_gmin,
173
    const xt::xtensor<int, 1>& in_gmax, const double_2dvec& in_mult,
174
    const double_3dvec& coeffs) override;
175

176
  void combine(const vector<ScattData*>& those_scatts,
177
    const vector<double>& scalars) override;
178

179
  double calc_f(int gin, int gout, double mu) override;
180

181
  void sample(
182
    int gin, int& gout, double& mu, double& wgt, uint64_t* seed) override;
183

184
  size_t get_order() override { return dist[0][0].size(); };
185

186
  xt::xtensor<double, 3> get_matrix(size_t max_order) override;
187
};
188

189
//==============================================================================
190
// ScattDataTabular represents the angular distributions as a table of mu and
191
// f(mu)
192
//==============================================================================
193

194
class ScattDataTabular : public ScattData {
195

196
protected:
197
  xt::xtensor<double, 1> mu; // Angle distribution mu grid points
198
  double dmu;                // Quick storage of the mu spacing
199
  double_3dvec fmu;          // The angular distribution function
200

201
  // Friend convert_legendre_to_tabular so it has access to protected
202
  // parameters
203
  friend void convert_legendre_to_tabular(
204
    ScattDataLegendre& leg, ScattDataTabular& tab);
205

206
public:
207
  void init(const xt::xtensor<int, 1>& in_gmin,
208
    const xt::xtensor<int, 1>& in_gmax, const double_2dvec& in_mult,
209
    const double_3dvec& coeffs) override;
210

211
  void combine(const vector<ScattData*>& those_scatts,
212
    const vector<double>& scalars) override;
213

214
  double calc_f(int gin, int gout, double mu) override;
215

216
  void sample(
217
    int gin, int& gout, double& mu, double& wgt, uint64_t* seed) override;
218

219
  size_t get_order() override { return dist[0][0].size(); };
220

221
  xt::xtensor<double, 3> get_matrix(size_t max_order) override;
222
};
223

224
//==============================================================================
225
// Function to convert Legendre functions to tabular
226
//==============================================================================
227

228
//! \brief Converts a ScattDatalegendre to a ScattDataHistogram
229
//!
230
//! @param leg The initial ScattDataLegendre object.
231
//! @param leg The resultant ScattDataTabular object.
232
//! @param n_mu The number of mu points to use when building the
233
//!   ScattDataTabular object.
234
void convert_legendre_to_tabular(
235
  ScattDataLegendre& leg, ScattDataTabular& tab, int n_mu);
236

237
} // namespace openmc
238
#endif // OPENMC_SCATTDATA_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