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

openmc-dev / openmc / 12776996362

14 Jan 2025 09:49PM UTC coverage: 84.938% (+0.2%) from 84.729%
12776996362

Pull #3133

github

web-flow
Merge 0495246d9 into 549cc0973
Pull Request #3133: Kinetics parameters using Iterated Fission Probability

318 of 330 new or added lines in 10 files covered. (96.36%)

1658 existing lines in 66 files now uncovered.

50402 of 59340 relevant lines covered (84.94%)

33987813.96 hits per line

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

25.0
/include/openmc/tallies/tally.h
1
#ifndef OPENMC_TALLIES_TALLY_H
2
#define OPENMC_TALLIES_TALLY_H
3

4
#include "openmc/constants.h"
5
#include "openmc/memory.h" // for unique_ptr
6
#include "openmc/tallies/filter.h"
7
#include "openmc/tallies/trigger.h"
8
#include "openmc/vector.h"
9

10
#include "pugixml.hpp"
11
#include "xtensor/xfixed.hpp"
12
#include "xtensor/xtensor.hpp"
13
#include <gsl/gsl-lite.hpp>
14

15
#include <string>
16
#include <unordered_map>
17

18
namespace openmc {
19

20
//==============================================================================
21
//! A user-specified flux-weighted (or current) measurement.
22
//==============================================================================
23

24
class Tally {
25
public:
26
  //----------------------------------------------------------------------------
27
  // Constructors, destructors, factory functions
28
  explicit Tally(int32_t id);
29
  explicit Tally(pugi::xml_node node);
30
  ~Tally();
31
  static Tally* create(int32_t id = -1);
32

33
  //----------------------------------------------------------------------------
34
  // Accessors
35

36
  void set_id(int32_t id);
37

38
  int id() const { return id_; }
39

40
  void set_active(bool active) { active_ = active; }
41

42
  void set_multiply_density(bool value) { multiply_density_ = value; }
43

44
  void set_writable(bool writable) { writable_ = writable; }
45

46
  void set_scores(pugi::xml_node node);
47

48
  void set_scores(const vector<std::string>& scores);
49

50
  std::vector<std::string> scores() const;
51

52
  int32_t n_scores() const { return scores_.size(); }
53

54
  void set_nuclides(pugi::xml_node node);
55

56
  void set_nuclides(const vector<std::string>& nuclides);
57

58
  const xt::xtensor<double, 3>& results() const { return results_; }
59

60
  //! returns vector of indices corresponding to the tally this is called on
UNCOV
61
  const vector<int32_t>& filters() const { return filters_; }
×
62

63
  //! returns a vector of filter types for the tally
64
  std::vector<FilterType> filter_types() const;
65

66
  //! returns a mapping of filter types to index into the tally's filters
67
  std::unordered_map<FilterType, int32_t> filter_indices() const;
68

69
  //! \brief Returns the tally filter at index i
70
  int32_t filters(int i) const { return filters_[i]; }
×
71

72
  //! \brief Return a const pointer to a filter instance based on type. Always
73
  //! returns the first matching filter type
74
  template<class T>
75
  const T* get_filter() const
76
  {
77
    const T* out;
78
    for (auto filter_idx : filters_) {
79
      if ((out = dynamic_cast<T*>(model::tally_filters[filter_idx].get())))
80
        return out;
81
    }
82
    return nullptr;
83
  }
84

85
  template<class T>
86
  const T* get_filter(int idx) const
87
  {
88
    if (const T* out = dynamic_cast<T*>(model::tally_filters[filters_.at(idx)]))
89
      return out;
90
    return nullptr;
91
  }
92

93
  //! \brief Check if this tally has a specified type of filter
94
  bool has_filter(FilterType filter_type) const;
95

96
  void set_filters(gsl::span<Filter*> filters);
97

98
  //! Given already-set filters, set the stride lengths
99
  void set_strides();
100

UNCOV
101
  int32_t strides(int i) const { return strides_[i]; }
×
102

103
  int32_t n_filter_bins() const { return n_filter_bins_; }
104

105
  bool multiply_density() const { return multiply_density_; }
993,237,618✔
106

107
  bool writable() const { return writable_; }
108

109
  //----------------------------------------------------------------------------
110
  // Other methods.
111

112
  void add_filter(Filter* filter);
113

114
  void init_triggers(pugi::xml_node node);
115

116
  void init_results();
117

118
  void reset();
119

120
  void accumulate();
121

122
  //! return the index of a score specified by name
123
  int score_index(const std::string& score) const;
124

125
  //! Tally results reshaped according to filter sizes
126
  xt::xarray<double> get_reshaped_data() const;
127

128
  //! A string representing the i-th score on this tally
129
  std::string score_name(int score_idx) const;
130

131
  //! A string representing the i-th nuclide on this tally
132
  std::string nuclide_name(int nuclide_idx) const;
133

134
  //----------------------------------------------------------------------------
135
  // Major public data members.
136

137
  int id_ {C_NONE}; //!< User-defined identifier
138

139
  std::string name_; //!< User-defined name
140

141
  TallyType type_ {TallyType::VOLUME}; //!< e.g. volume, surface current
142

143
  //! Event type that contributes to this tally
144
  TallyEstimator estimator_ {TallyEstimator::TRACKLENGTH};
145

146
  //! Whether this tally is currently being updated
147
  bool active_ {false};
148

149
  //! Number of realizations
150
  int n_realizations_ {0};
151

152
  vector<int> scores_; //!< Filter integrands (e.g. flux, fission)
153

154
  //! Index of each nuclide to be tallied.  -1 indicates total material.
155
  vector<int> nuclides_ {-1};
156

157
  //! Results for each bin -- the first dimension of the array is for the
158
  //! combination of filters (e.g. specific cell, specific energy group, etc.)
159
  //! and the second dimension of the array is for scores (e.g. flux, total
160
  //! reaction rate, fission reaction rate, etc.)
161
  xt::xtensor<double, 3> results_;
162

163
  //! True if this tally should be written to statepoint files
164
  bool writable_ {true};
165

166
  //----------------------------------------------------------------------------
167
  // Miscellaneous public members.
168

169
  // We need to have quick access to some filters.  The following gives indices
170
  // for various filters that could be in the tally or C_NONE if they are not
171
  // present.
172
  int energy_filter_ {C_NONE};
173
  int energyout_filter_ {C_NONE};
174
  int delayedgroup_filter_ {C_NONE};
175
  int cell_filter_ {C_NONE};
176

177
  vector<Trigger> triggers_;
178

179
  int deriv_ {C_NONE}; //!< Index of a TallyDerivative object for diff tallies.
180

181
private:
182
  //----------------------------------------------------------------------------
183
  // Private data.
184

185
  vector<int32_t> filters_; //!< Filter indices in global filters array
186

187
  //! Index strides assigned to each filter to support 1D indexing.
188
  vector<int32_t> strides_;
189

190
  int32_t n_filter_bins_ {0};
191

192
  //! Whether to multiply by atom density for reaction rates
193
  bool multiply_density_ {true};
194

195
  gsl::index index_;
196
};
197

198
//==============================================================================
199
// Global variable declarations
200
//==============================================================================
201

202
namespace model {
203
extern std::unordered_map<int, int> tally_map;
204
extern vector<unique_ptr<Tally>> tallies;
205
extern vector<int> active_tallies;
206
extern vector<int> active_analog_tallies;
207
extern vector<int> active_tracklength_tallies;
208
extern vector<int> active_collision_tallies;
209
extern vector<int> active_meshsurf_tallies;
210
extern vector<int> active_surface_tallies;
211
extern vector<int> active_pulse_height_tallies;
212
extern vector<int> pulse_height_cells;
213
} // namespace model
214

215
namespace simulation {
216
//! Global tallies (such as k-effective estimators)
217
extern xt::xtensor_fixed<double, xt::xshape<N_GLOBAL_TALLIES, 3>>
218
  global_tallies;
219

220
//! Number of realizations for global tallies
221
extern "C" int32_t n_realizations;
222
} // namespace simulation
223

224
extern double global_tally_absorption;
225
extern double global_tally_collision;
226
extern double global_tally_tracklength;
227
extern double global_tally_leakage;
228

229
//==============================================================================
230
// Non-member functions
231
//==============================================================================
232

233
//! Read tally specification from tallies.xml
234
void read_tallies_xml();
235

236
//! Read tally specification from an XML node
237
//! \param[in] root node of tallies XML element
238
void read_tallies_xml(pugi::xml_node root);
239

240
//! \brief Accumulate the sum of the contributions from each history within the
241
//! batch to a new random variable
242
void accumulate_tallies();
243

244
//! Determine which tallies should be active
245
void setup_active_tallies();
246

247
// Alias for the type returned by xt::adapt(...). N is the dimension of the
248
// multidimensional array
249
template<std::size_t N>
250
using adaptor_type =
251
  xt::xtensor_adaptor<xt::xbuffer_adaptor<double*&, xt::no_ownership>, N>;
252

253
#ifdef OPENMC_MPI
254
//! Collect all tally results onto master process
255
void reduce_tally_results();
256
#endif
257

258
void free_memory_tally();
259

260
} // namespace openmc
261

262
#endif // OPENMC_TALLIES_TALLY_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