• 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

42.86
/include/openmc/lattice.h
1
#ifndef OPENMC_LATTICE_H
2
#define OPENMC_LATTICE_H
3

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

8
#include "hdf5.h"
9
#include "pugixml.hpp"
10

11
#include "openmc/array.h"
12
#include "openmc/constants.h"
13
#include "openmc/memory.h"
14
#include "openmc/position.h"
15
#include "openmc/vector.h"
16

17
namespace openmc {
18

19
//==============================================================================
20
// Module constants
21
//==============================================================================
22

23
constexpr int32_t NO_OUTER_UNIVERSE {-1};
24

25
enum class LatticeType { rect, hex };
26

27
//==============================================================================
28
// Global variables
29
//==============================================================================
30

31
class Lattice;
32

33
namespace model {
34
extern std::unordered_map<int32_t, int32_t> lattice_map;
35
extern vector<unique_ptr<Lattice>> lattices;
36
} // namespace model
37

38
//==============================================================================
39
//! \class Lattice
40
//! \brief Abstract type for ordered array of universes.
41
//==============================================================================
42

43
class LatticeIter;
44
class ReverseLatticeIter;
45

46
class Lattice {
47
public:
48
  int32_t id_;       //!< Universe ID number
49
  std::string name_; //!< User-defined name
50
  LatticeType type_;
51
  vector<int32_t> universes_;         //!< Universes filling each lattice tile
52
  int32_t outer_ {NO_OUTER_UNIVERSE}; //!< Universe tiled outside the lattice
53
  vector<int32_t> offsets_;           //!< Distribcell offset table
54

55
  explicit Lattice(pugi::xml_node lat_node);
56

57
  virtual ~Lattice() {}
58

59
  virtual const int32_t& operator[](const array<int, 3>& i_xyz) = 0;
60

61
  virtual LatticeIter begin();
62
  virtual LatticeIter end();
63
  virtual int32_t& back();
64

65
  virtual ReverseLatticeIter rbegin();
66
  virtual ReverseLatticeIter rend();
67

68
  //! Convert internal universe values from IDs to indices using universe_map.
69
  void adjust_indices();
70

71
  //! Allocate offset table for distribcell.
72
  void allocate_offset_table(int n_maps)
1,552✔
73
  {
74
    offsets_.resize(n_maps * universes_.size());
1,552✔
75
    std::fill(offsets_.begin(), offsets_.end(), C_NONE);
1,552✔
76
  }
1,552✔
77

78
  //! Populate the distribcell offset tables.
79
  int32_t fill_offset_table(int32_t offset, int32_t target_univ_id, int map,
80
    std::unordered_map<int32_t, int32_t>& univ_count_memo);
81

82
  //! \brief Check lattice indices.
83
  //! \param i_xyz[3] The indices for a lattice tile.
84
  //! \return true if the given indices fit within the lattice bounds.  False
85
  //!   otherwise.
86
  virtual bool are_valid_indices(const array<int, 3>& i_xyz) const = 0;
87

88
  //! \brief Find the next lattice surface crossing
89
  //! \param r A 3D Cartesian coordinate.
90
  //! \param u A 3D Cartesian direction.
91
  //! \param i_xyz The indices for a lattice tile.
92
  //! \return The distance to the next crossing and an array indicating how the
93
  //!   lattice indices would change after crossing that boundary.
94
  virtual std::pair<double, array<int, 3>> distance(
95
    Position r, Direction u, const array<int, 3>& i_xyz) const = 0;
96

97
  //! \brief Find the lattice tile indices for a given point.
98
  //! \param r A 3D Cartesian coordinate.
99
  //! \param u Direction of a particle
100
  //! \param result resulting indices to save to
101
  virtual void get_indices(
102
    Position r, Direction u, array<int, 3>& result) const = 0;
103

104
  //! \brief Compute the the flat index for a set of lattice cell indices
105
  //! \param i_xyz The indices for a lattice cell.
106
  //! \return Flat index into the universes vector.
107
  virtual int get_flat_index(const array<int, 3>& i_xyz) const = 0;
108

109
  //! \brief Get coordinates local to a lattice tile.
110
  //! \param r A 3D Cartesian coordinate.
111
  //! \param i_xyz The indices for a lattice tile.
112
  //! \return Local 3D Cartesian coordinates.
113
  virtual Position get_local_position(
114
    Position r, const array<int, 3>& i_xyz) const = 0;
115

116
  //! \brief Check flattened lattice index.
117
  //! \param indx The index for a lattice tile.
118
  //! \return true if the given index fit within the lattice bounds.  False
119
  //!   otherwise.
120
  virtual bool is_valid_index(int indx) const
121
  {
122
    return (indx >= 0) && (indx < universes_.size());
123
  }
124

125
  //! \brief Get the distribcell offset for a lattice tile.
126
  //! \param The map index for the target cell.
127
  //! \param i_xyz[3] The indices for a lattice tile.
128
  //! \return Distribcell offset i.e. the largest instance number for the target
129
  //!  cell found in the geometry tree under this lattice tile.
130
  virtual int32_t& offset(int map, const array<int, 3>& i_xyz) = 0;
131

132
  //! \brief Get the distribcell offset for a lattice tile.
133
  //! \param The map index for the target cell.
134
  //! \param indx The index for a lattice tile.
135
  //! \return Distribcell offset i.e. the largest instance number for the target
136
  //!  cell found in the geometry tree for this lattice index.
137
  virtual int32_t offset(int map, int indx) const = 0;
138

139
  //! \brief Convert an array index to a useful human-readable string.
140
  //! \param indx The index for a lattice tile.
141
  //! \return A string representing the lattice tile.
142
  virtual std::string index_to_string(int indx) const = 0;
143

144
  //! \brief Write lattice information to an HDF5 group.
145
  //! \param group_id An HDF5 group id.
146
  void to_hdf5(hid_t group_id) const;
147

148
protected:
149
  bool is_3d_; //!< Has divisions along the z-axis?
150

151
  virtual void to_hdf5_inner(hid_t group_id) const = 0;
152
};
153

154
//==============================================================================
155
//! An iterator over lattice universes.
156
//==============================================================================
157

158
class LatticeIter {
159
public:
160
  int indx_; //!< An index to a Lattice universes or offsets array.
161

162
  LatticeIter(Lattice& lat, int indx) : indx_(indx), lat_(lat) {}
163

UNCOV
164
  bool operator==(const LatticeIter& rhs) { return (indx_ == rhs.indx_); }
×
165

UNCOV
166
  bool operator!=(const LatticeIter& rhs) { return !(*this == rhs); }
×
167

UNCOV
168
  int32_t& operator*() { return lat_.universes_[indx_]; }
×
169

UNCOV
170
  LatticeIter& operator++()
×
171
  {
172
    while (indx_ < lat_.end().indx_) {
×
173
      ++indx_;
×
174
      if (lat_.is_valid_index(indx_))
×
UNCOV
175
        return *this;
×
176
    }
177
    indx_ = lat_.end().indx_;
×
UNCOV
178
    return *this;
×
179
  }
180

181
protected:
182
  Lattice& lat_;
183
};
184

185
//==============================================================================
186
//! A reverse iterator over lattice universes.
187
//==============================================================================
188

189
class ReverseLatticeIter : public LatticeIter {
190
public:
191
  ReverseLatticeIter(Lattice& lat, int indx) : LatticeIter {lat, indx} {}
192

193
  ReverseLatticeIter& operator++()
313,538,364✔
194
  {
195
    while (indx_ > lat_.begin().indx_ - 1) {
313,538,364✔
196
      --indx_;
313,538,364✔
197
      if (lat_.is_valid_index(indx_))
313,538,364✔
198
        return *this;
313,538,364✔
199
    }
200
    indx_ = -1;
×
UNCOV
201
    return *this;
×
202
  }
203
};
204

205
//==============================================================================
206

207
class RectLattice : public Lattice {
208
public:
209
  explicit RectLattice(pugi::xml_node lat_node);
210

211
  const int32_t& operator[](const array<int, 3>& i_xyz) override;
212

213
  bool are_valid_indices(const array<int, 3>& i_xyz) const override;
214

215
  std::pair<double, array<int, 3>> distance(
216
    Position r, Direction u, const array<int, 3>& i_xyz) const override;
217

218
  void get_indices(
219
    Position r, Direction u, array<int, 3>& result) const override;
220

221
  int get_flat_index(const array<int, 3>& i_xyz) const override;
222

223
  Position get_local_position(
224
    Position r, const array<int, 3>& i_xyz) const override;
225

226
  int32_t& offset(int map, const array<int, 3>& i_xyz) override;
227

228
  int32_t offset(int map, int indx) const override;
229

230
  std::string index_to_string(int indx) const override;
231

232
  void to_hdf5_inner(hid_t group_id) const override;
233

234
private:
235
  array<int, 3> n_cells_; //!< Number of cells along each axis
236
  Position lower_left_;   //!< Global lower-left corner of the lattice
237
  Position pitch_;        //!< Lattice tile width along each axis
238
};
239

240
//==============================================================================
241

242
class HexLattice : public Lattice {
243
public:
244
  explicit HexLattice(pugi::xml_node lat_node);
245

246
  const int32_t& operator[](const array<int, 3>& i_xyz) override;
247

248
  LatticeIter begin() override;
249

250
  ReverseLatticeIter rbegin() override;
251

252
  LatticeIter end() override;
253

254
  int32_t& back() override;
255

256
  ReverseLatticeIter rend() override;
257

258
  bool are_valid_indices(const array<int, 3>& i_xyz) const override;
259

260
  std::pair<double, array<int, 3>> distance(
261
    Position r, Direction u, const array<int, 3>& i_xyz) const override;
262

263
  void get_indices(
264
    Position r, Direction u, array<int, 3>& result) const override;
265

266
  int get_flat_index(const array<int, 3>& i_xyz) const override;
267

268
  Position get_local_position(
269
    Position r, const array<int, 3>& i_xyz) const override;
270

271
  bool is_valid_index(int indx) const override;
272

273
  int32_t& offset(int map, const array<int, 3>& i_xyz) override;
274

275
  int32_t offset(int map, int indx) const override;
276

277
  std::string index_to_string(int indx) const override;
278

279
  void to_hdf5_inner(hid_t group_id) const override;
280

281
private:
282
  enum class Orientation {
283
    y, //!< Flat side of lattice parallel to y-axis
284
    x  //!< Flat side of lattice parallel to x-axis
285
  };
286

287
  //! Fill universes_ vector for 'y' orientation
288
  void fill_lattice_y(const vector<std::string>& univ_words);
289

290
  //! Fill universes_ vector for 'x' orientation
291
  void fill_lattice_x(const vector<std::string>& univ_words);
292

293
  int n_rings_;             //!< Number of radial tile positions
294
  int n_axial_;             //!< Number of axial tile positions
295
  Orientation orientation_; //!< Orientation of lattice
296
  Position center_;         //!< Global center of lattice
297
  array<double, 2> pitch_;  //!< Lattice tile width and height
298
};
299

300
//==============================================================================
301
// Non-member functions
302
//==============================================================================
303

304
void read_lattices(pugi::xml_node node);
305

306
} //  namespace openmc
307
#endif // OPENMC_LATTICE_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