• 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/filter.h
1
#ifndef OPENMC_TALLIES_FILTER_H
2
#define OPENMC_TALLIES_FILTER_H
3

4
#include <cstdint>
5
#include <string>
6
#include <unordered_map>
7

8
#include "pugixml.hpp"
9
#include <gsl/gsl-lite.hpp>
10

11
#include "openmc/constants.h"
12
#include "openmc/hdf5_interface.h"
13
#include "openmc/memory.h"
14
#include "openmc/particle.h"
15
#include "openmc/tallies/filter_match.h"
16
#include "openmc/vector.h"
17

18
namespace openmc {
19

20
enum class FilterType {
21
  AZIMUTHAL,
22
  CELLBORN,
23
  CELLFROM,
24
  CELL,
25
  CELL_INSTANCE,
26
  COLLISION,
27
  DELAYED_GROUP,
28
  DISTRIBCELL,
29
  ENERGY_FUNCTION,
30
  ENERGY,
31
  ENERGY_OUT,
32
  LEGENDRE,
33
  MATERIAL,
34
  MATERIALFROM,
35
  MESH,
36
  MESHBORN,
37
  MESH_SURFACE,
38
  MU,
39
  MUSURFACE,
40
  PARTICLE,
41
  POLAR,
42
  SPHERICAL_HARMONICS,
43
  SPATIAL_LEGENDRE,
44
  SURFACE,
45
  TIME,
46
  UNIVERSE,
47
  ZERNIKE,
48
  ZERNIKE_RADIAL
49
};
50

51
//==============================================================================
52
//! Modifies tally score events.
53
//==============================================================================
54

55
class Filter {
56
public:
57
  //----------------------------------------------------------------------------
58
  // Constructors, destructors, factory functions
59

60
  Filter();
61
  virtual ~Filter();
62

63
  //! Create a new tally filter
64
  //
65
  //! \tparam T Type of the filter
66
  //! \param[in] id  Unique ID for the filter. If none is passed, an ID is
67
  //!    automatically assigned
68
  //! \return Pointer to the new filter object
69
  template<typename T>
70
  static T* create(int32_t id = -1);
71

72
  //! Create a new tally filter
73
  //
74
  //! \param[in] type  Type of the filter
75
  //! \param[in] id  Unique ID for the filter. If none is passed, an ID is
76
  //!    automatically assigned
77
  //! \return Pointer to the new filter object
78
  static Filter* create(const std::string& type, int32_t id = -1);
79

80
  //! Create a new tally filter from an XML node
81
  //
82
  //! \param[in] node XML node
83
  //! \return Pointer to the new filter object
84
  static Filter* create(pugi::xml_node node);
85

86
  //! Uses an XML input to fill the filter's data fields.
87
  virtual void from_xml(pugi::xml_node node) = 0;
88

89
  //----------------------------------------------------------------------------
90
  // Methods
91

92
  virtual std::string type_str() const = 0;
93
  virtual FilterType type() const = 0;
94

95
  //! Matches a tally event to a set of filter bins and weights.
96
  //!
97
  //! \param[in] p Particle being tracked
98
  //! \param[in] estimator Tally estimator being used
99
  //! \param[out] match will contain the matching bins and corresponding
100
  //!   weights; note that there may be zero matching bins
101
  virtual void get_all_bins(
102
    const Particle& p, TallyEstimator estimator, FilterMatch& match) const = 0;
103

104
  //! Writes data describing this filter to an HDF5 statepoint group.
UNCOV
105
  virtual void to_statepoint(hid_t filter_group) const
×
106
  {
107
    write_dataset(filter_group, "type", type_str());
×
UNCOV
108
    write_dataset(filter_group, "n_bins", n_bins_);
×
109
  }
110

111
  //! Return a string describing a filter bin for the tallies.out file.
112
  //
113
  //! For example, an `EnergyFilter` might return the string
114
  //! "Incoming Energy [0.625E-6, 20.0)".
115
  virtual std::string text_label(int bin) const = 0;
116

117
  //----------------------------------------------------------------------------
118
  // Accessors
119

120
  //! Get unique ID of filter
121
  //! \return Unique ID
122
  int32_t id() const { return id_; }
126,997✔
123

124
  //! Assign a unique ID to the filter
125
  //! \param[in]  Unique ID to assign. A value of -1 indicates that an ID should
126
  //!   be automatically assigned
127
  void set_id(int32_t id);
128

129
  //! Get number of bins
130
  //! \return Number of bins
131
  int n_bins() const { return n_bins_; }
132

133
  gsl::index index() const { return index_; }
134

135
  //----------------------------------------------------------------------------
136
  // Data members
137

138
protected:
139
  int n_bins_;
140

141
private:
142
  int32_t id_ {C_NONE};
143
  gsl::index index_;
144
};
145

146
//==============================================================================
147
// Global variables
148
//==============================================================================
149

150
namespace model {
151
extern "C" int32_t n_filters;
152
extern std::unordered_map<int, int> filter_map;
153
extern vector<unique_ptr<Filter>> tally_filters;
154
} // namespace model
155

156
//==============================================================================
157
// Non-member functions
158
//==============================================================================
159

160
//! Make sure index corresponds to a valid filter
161
int verify_filter(int32_t index);
162

163
//==============================================================================
164
// Filter implementation
165
//==============================================================================
166

167
template<typename T>
168
T* Filter::create(int32_t id)
169
{
170
  static_assert(std::is_base_of<Filter, T>::value,
171
    "Type specified is not derived from openmc::Filter");
172
  // Create filter and add to filters vector
173
  auto filter = make_unique<T>();
174
  auto ptr_out = filter.get();
175
  model::tally_filters.emplace_back(std::move(filter));
176
  // Assign ID
177
  model::tally_filters.back()->set_id(id);
178

179
  return ptr_out;
180
}
181

182
} // namespace openmc
183
#endif // OPENMC_TALLIES_FILTER_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