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

openmc-dev / openmc / 17637711185

11 Sep 2025 07:44AM UTC coverage: 85.193% (-0.02%) from 85.209%
17637711185

Pull #3566

github

web-flow
Merge 03f6b5b26 into ca4295748
Pull Request #3566: Resolve merge conflicts for PR #3516 - Implement Virtual Lattice Method for Efficient Simulation of Dispersed Fuels

268 of 326 new or added lines in 9 files covered. (82.21%)

175 existing lines in 3 files now uncovered.

53205 of 62452 relevant lines covered (85.19%)

37768560.15 hits per line

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

30.0
/include/openmc/surface.h
1
#ifndef OPENMC_SURFACE_H
2
#define OPENMC_SURFACE_H
3

4
#include <limits> // For numeric_limits
5
#include <string>
6
#include <unordered_map>
7

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

11
#include "openmc/boundary_condition.h"
12
#include "openmc/bounding_box.h"
13
#include "openmc/constants.h"
14
#include "openmc/memory.h" // for unique_ptr
15
#include "openmc/particle.h"
16
#include "openmc/position.h"
17
#include "openmc/vector.h"
18

19
namespace openmc {
20

21
//==============================================================================
22
// Global variables
23
//==============================================================================
24

25
class Surface;
26

27
namespace model {
28
extern std::unordered_map<int, int> surface_map;
29
extern vector<unique_ptr<Surface>> surfaces;
30
} // namespace model
31

32
//==============================================================================
33
//! A geometry primitive used to define regions of 3D space.
34
//==============================================================================
35

36
class Surface {
37
public:
38
  int id_;                           //!< Unique ID
39
  std::string name_;                 //!< User-defined name
40
  unique_ptr<BoundaryCondition> bc_; //!< Boundary condition
41
  bool surf_source_ {false}; //!< Activate source banking for the surface?
42
  int triso_base_index_;
43
  int triso_particle_index_ = -1;
44
  bool is_triso_surface_ = false;
45

46
  explicit Surface(pugi::xml_node surf_node);
47
  Surface();
48

49
  virtual ~Surface() {}
35,966✔
50

×
51
  //! Determine which side of a surface a point lies on.
35,966✔
52
  //! \param r The 3D Cartesian coordinate of a point.
53
  //! \param u A direction used to "break ties" and pick a sense when the
54
  //!   point is very close to the surface.
55
  //! \return true if the point is on the "positive" side of the surface and
56
  //!   false otherwise.
57
  bool sense(Position r, Direction u) const;
58

59
  //! Determine the direction of a ray reflected from the surface.
60
  //! \param[in] r The point at which the ray is incident.
61
  //! \param[in] u Incident direction of the ray
62
  //! \param[inout] p Pointer to the particle. Only DAGMC uses this.
63
  //! \return Outgoing direction of the ray
64
  virtual Direction reflect(
65
    Position r, Direction u, GeometryState* p = nullptr) const;
66

67
  virtual Direction diffuse_reflect(
68
    Position r, Direction u, uint64_t* seed) const;
69

70
  //! Evaluate the equation describing the surface.
71
  //!
72
  //! Surfaces can be described by some function f(x, y, z) = 0.  This member
73
  //! function evaluates that mathematical function.
74
  //! \param r A 3D Cartesian coordinate.
75
  virtual double evaluate(Position r) const = 0;
76

77
  //! Compute the distance between a point and the surface along a ray.
78
  //! \param r A 3D Cartesian coordinate.
79
  //! \param u The direction of the ray.
80
  //! \param coincident A hint to the code that the given point should lie
81
  //!   exactly on the surface.
82
  virtual double distance(Position r, Direction u, bool coincident) const = 0;
83

84
  virtual bool triso_in_mesh(
85
    vector<double> mesh_center, vector<double> lattice_pitch) const
NEW
86
  {
×
87
    return {};
88
  };
NEW
89
  virtual void connect_to_triso_base(int triso_index, std::string key) {};
×
90
  virtual vector<double> get_center() const { return {}; };
NEW
91
  virtual double get_radius() const { return {}; };
×
NEW
92

×
UNCOV
93
  //! Compute the local outward normal direction of the surface.
×
94
  //! \param r A 3D Cartesian coordinate.
95
  //! \return Normal direction
96
  virtual Direction normal(Position r) const = 0;
97

98
  //! Write all information needed to reconstruct the surface to an HDF5 group.
99
  //! \param group_id An HDF5 group id.
100
  void to_hdf5(hid_t group_id) const;
101

102
  //! Get the BoundingBox for this surface.
103
  virtual BoundingBox bounding_box(bool /*pos_side*/) const { return {}; }
104

105
  /* Must specify if this is a CSG or DAGMC-type surface. Only
×
106
   * the DAGMC surface should return the DAG type geometry, so
107
   * by default, this returns the CSG. The main difference is that
108
   * if the geom_type is found to be DAG in the geometry handling code,
109
   * some DAGMC-specific operations get carried out like resetting
110
   * the particle's intersection history when necessary.
111
   */
112
  virtual GeometryType geom_type() const { return GeometryType::CSG; }
113

114
protected:
794,789,256✔
115
  virtual void to_hdf5_inner(hid_t group_id) const = 0;
116
};
117

118
//==============================================================================
119
//! A plane perpendicular to the x-axis.
120
//
121
//! The plane is described by the equation \f$x - x_0 = 0\f$
122
//==============================================================================
123

124
class SurfaceXPlane : public Surface {
125
public:
126
  explicit SurfaceXPlane(pugi::xml_node surf_node);
127
  double evaluate(Position r) const override;
128
  double distance(Position r, Direction u, bool coincident) const override;
129
  Direction normal(Position r) const override;
130
  void to_hdf5_inner(hid_t group_id) const override;
131
  bool triso_in_mesh(
132
    vector<double> mesh_center, vector<double> lattice_pitch) const override;
133
  BoundingBox bounding_box(bool pos_side) const override;
134

135
  double x0_;
136
};
137

138
//==============================================================================
139
//! A plane perpendicular to the y-axis.
140
//
141
//! The plane is described by the equation \f$y - y_0 = 0\f$
142
//==============================================================================
143

144
class SurfaceYPlane : public Surface {
145
public:
146
  explicit SurfaceYPlane(pugi::xml_node surf_node);
147
  double evaluate(Position r) const override;
148
  double distance(Position r, Direction u, bool coincident) const override;
149
  Direction normal(Position r) const override;
150
  void to_hdf5_inner(hid_t group_id) const override;
151
  bool triso_in_mesh(
152
    vector<double> mesh_center, vector<double> lattice_pitch) const override;
153
  BoundingBox bounding_box(bool pos_side) const override;
154

155
  double y0_;
156
};
157

158
//==============================================================================
159
//! A plane perpendicular to the z-axis.
160
//
161
//! The plane is described by the equation \f$z - z_0 = 0\f$
162
//==============================================================================
163

164
class SurfaceZPlane : public Surface {
165
public:
166
  explicit SurfaceZPlane(pugi::xml_node surf_node);
167
  double evaluate(Position r) const override;
168
  double distance(Position r, Direction u, bool coincident) const override;
169
  Direction normal(Position r) const override;
170
  void to_hdf5_inner(hid_t group_id) const override;
171
  bool triso_in_mesh(
172
    vector<double> mesh_center, vector<double> lattice_pitch) const override;
173
  BoundingBox bounding_box(bool pos_side) const override;
174

175
  double z0_;
176
};
177

178
//==============================================================================
179
//! A general plane.
180
//
181
//! The plane is described by the equation \f$A x + B y + C z - D = 0\f$
182
//==============================================================================
183

184
class SurfacePlane : public Surface {
185
public:
186
  explicit SurfacePlane(pugi::xml_node surf_node);
187
  double evaluate(Position r) const override;
188
  double distance(Position r, Direction u, bool coincident) const override;
189
  Direction normal(Position r) const override;
190
  bool triso_in_mesh(
191
    vector<double> mesh_center, vector<double> lattice_pitch) const override;
192
  void to_hdf5_inner(hid_t group_id) const override;
193

194
  double A_, B_, C_, D_;
195
};
196

197
//==============================================================================
198
//! A cylinder aligned along the x-axis.
199
//
200
//! The cylinder is described by the equation
201
//! \f$(y - y_0)^2 + (z - z_0)^2 - R^2 = 0\f$
202
//==============================================================================
203

204
class SurfaceXCylinder : public Surface {
205
public:
206
  explicit SurfaceXCylinder(pugi::xml_node surf_node);
207
  double evaluate(Position r) const override;
208
  double distance(Position r, Direction u, bool coincident) const override;
209
  Direction normal(Position r) const override;
210
  void to_hdf5_inner(hid_t group_id) const override;
211
  bool triso_in_mesh(
212
    vector<double> mesh_center, vector<double> lattice_pitch) const override;
213
  BoundingBox bounding_box(bool pos_side) const override;
214

215
  double y0_, z0_, radius_;
216
};
217

218
//==============================================================================
219
//! A cylinder aligned along the y-axis.
220
//
221
//! The cylinder is described by the equation
222
//! \f$(x - x_0)^2 + (z - z_0)^2 - R^2 = 0\f$
223
//==============================================================================
224

225
class SurfaceYCylinder : public Surface {
226
public:
227
  explicit SurfaceYCylinder(pugi::xml_node surf_node);
228
  double evaluate(Position r) const override;
229
  double distance(Position r, Direction u, bool coincident) const override;
230
  Direction normal(Position r) const override;
231
  void to_hdf5_inner(hid_t group_id) const override;
232
  bool triso_in_mesh(
233
    vector<double> mesh_center, vector<double> lattice_pitch) const override;
234
  BoundingBox bounding_box(bool pos_side) const override;
235

236
  double x0_, z0_, radius_;
237
};
238

239
//==============================================================================
240
//! A cylinder aligned along the z-axis.
241
//
242
//! The cylinder is described by the equation
243
//! \f$(x - x_0)^2 + (y - y_0)^2 - R^2 = 0\f$
244
//==============================================================================
245

246
class SurfaceZCylinder : public Surface {
247
public:
248
  explicit SurfaceZCylinder(pugi::xml_node surf_node);
249
  double evaluate(Position r) const override;
250
  double distance(Position r, Direction u, bool coincident) const override;
251
  Direction normal(Position r) const override;
252
  void to_hdf5_inner(hid_t group_id) const override;
253
  bool triso_in_mesh(
254
    vector<double> mesh_center, vector<double> lattice_pitch) const override;
255
  BoundingBox bounding_box(bool pos_side) const override;
256

257
  double x0_, y0_, radius_;
258
};
259

260
//==============================================================================
261
//! A sphere.
262
//
263
//! The cylinder is described by the equation
264
//! \f$(x - x_0)^2 + (y - y_0)^2 + (z - z_0)^2 - R^2 = 0\f$
265
//==============================================================================
266

267
class SurfaceSphere : public Surface {
268
public:
269
  explicit SurfaceSphere(pugi::xml_node surf_node);
270
  double evaluate(Position r) const override;
271
  double distance(Position r, Direction u, bool coincident) const override;
272
  Direction normal(Position r) const override;
273
  void to_hdf5_inner(hid_t group_id) const override;
274
  bool triso_in_mesh(
275
    vector<double> mesh_center, vector<double> lattice_pitch) const override;
276
  BoundingBox bounding_box(bool pos_side) const override;
277
  vector<double> get_center() const override;
278
  double get_radius() const override;
279
  void connect_to_triso_base(int triso_index, std::string key) override;
280

281
  double x0_, y0_, z0_, radius_;
282
  // int triso_base_index_ = -1;
283
};
284

285
//==============================================================================
286
//! A cone aligned along the x-axis.
287
//
288
//! The cylinder is described by the equation
289
//! \f$(y - y_0)^2 + (z - z_0)^2 - R^2 (x - x_0)^2 = 0\f$
290
//==============================================================================
291

292
class SurfaceXCone : public Surface {
293
public:
294
  explicit SurfaceXCone(pugi::xml_node surf_node);
295
  double evaluate(Position r) const override;
296
  double distance(Position r, Direction u, bool coincident) const override;
297
  Direction normal(Position r) const override;
298
  void to_hdf5_inner(hid_t group_id) const override;
299
  bool triso_in_mesh(
300
    vector<double> mesh_center, vector<double> lattice_pitch) const override;
301

302
  double x0_, y0_, z0_, radius_sq_;
303
};
304

305
//==============================================================================
306
//! A cone aligned along the y-axis.
307
//
308
//! The cylinder is described by the equation
309
//! \f$(x - x_0)^2 + (z - z_0)^2 - R^2 (y - y_0)^2 = 0\f$
310
//==============================================================================
311

312
class SurfaceYCone : public Surface {
313
public:
314
  explicit SurfaceYCone(pugi::xml_node surf_node);
315
  double evaluate(Position r) const override;
316
  double distance(Position r, Direction u, bool coincident) const override;
317
  Direction normal(Position r) const override;
318
  void to_hdf5_inner(hid_t group_id) const override;
319
  bool triso_in_mesh(
320
    vector<double> mesh_center, vector<double> lattice_pitch) const override;
321

322
  double x0_, y0_, z0_, radius_sq_;
323
};
324

325
//==============================================================================
326
//! A cone aligned along the z-axis.
327
//
328
//! The cylinder is described by the equation
329
//! \f$(x - x_0)^2 + (y - y_0)^2 - R^2 (z - z_0)^2 = 0\f$
330
//==============================================================================
331

332
class SurfaceZCone : public Surface {
333
public:
334
  explicit SurfaceZCone(pugi::xml_node surf_node);
335
  double evaluate(Position r) const override;
336
  double distance(Position r, Direction u, bool coincident) const override;
337
  Direction normal(Position r) const override;
338
  void to_hdf5_inner(hid_t group_id) const override;
339
  bool triso_in_mesh(
340
    vector<double> mesh_center, vector<double> lattice_pitch) const override;
341

342
  double x0_, y0_, z0_, radius_sq_;
343
};
344

345
//==============================================================================
346
//! A general surface described by a quadratic equation.
347
//
348
//! \f$A x^2 + B y^2 + C z^2 + D x y + E y z + F x z + G x + H y + J z + K =
349
//! 0\f$
350
//==============================================================================
351

352
class SurfaceQuadric : public Surface {
353
public:
354
  explicit SurfaceQuadric(pugi::xml_node surf_node);
355
  double evaluate(Position r) const override;
356
  double distance(Position r, Direction u, bool coincident) const override;
357
  Direction normal(Position r) const override;
358
  void to_hdf5_inner(hid_t group_id) const override;
359
  bool triso_in_mesh(
360
    vector<double> mesh_center, vector<double> lattice_pitch) const override;
361

362
  // Ax^2 + By^2 + Cz^2 + Dxy + Eyz + Fxz + Gx + Hy + Jz + K = 0
363
  double A_, B_, C_, D_, E_, F_, G_, H_, J_, K_;
364
};
365

366
//==============================================================================
367
//! A toroidal surface described by the quartic torus lies in the x direction
368
//
369
//! \f$(x-x_0)^2/B^2 + (\sqrt{(y-y_0)^2 + (z-z_0)^2} - A)^2/C^2 -1 \f$
370
//==============================================================================
371

372
class SurfaceXTorus : public Surface {
373
public:
374
  explicit SurfaceXTorus(pugi::xml_node surf_node);
375
  double evaluate(Position r) const override;
376
  double distance(Position r, Direction u, bool coincident) const override;
377
  Direction normal(Position r) const override;
378
  void to_hdf5_inner(hid_t group_id) const override;
379
  bool triso_in_mesh(
380
    vector<double> mesh_center, vector<double> lattice_pitch) const override;
381

382
  double x0_, y0_, z0_, A_, B_, C_;
383
};
384

385
//==============================================================================
386
//! A toroidal surface described by the quartic torus lies in the y direction
387
//
388
//! \f$(y-y_0)^2/B^2 + (\sqrt{(x-x_0)^2 + (z-z_0)^2} - A)^2/C^2 -1 \f$
389
//==============================================================================
390

391
class SurfaceYTorus : public Surface {
392
public:
393
  explicit SurfaceYTorus(pugi::xml_node surf_node);
394
  double evaluate(Position r) const override;
395
  double distance(Position r, Direction u, bool coincident) const override;
396
  Direction normal(Position r) const override;
397
  void to_hdf5_inner(hid_t group_id) const override;
398
  bool triso_in_mesh(
399
    vector<double> mesh_center, vector<double> lattice_pitch) const override;
400

401
  double x0_, y0_, z0_, A_, B_, C_;
402
};
403

404
//==============================================================================
405
//! A toroidal surface described by the quartic torus lies in the z direction
406
//
407
//! \f$(z-z_0)^2/B^2 + (\sqrt{(x-x_0)^2 + (y-y_0)^2} - A)^2/C^2 -1 \f$
408
//==============================================================================
409

410
class SurfaceZTorus : public Surface {
411
public:
412
  explicit SurfaceZTorus(pugi::xml_node surf_node);
413
  double evaluate(Position r) const override;
414
  double distance(Position r, Direction u, bool coincident) const override;
415
  Direction normal(Position r) const override;
416
  void to_hdf5_inner(hid_t group_id) const override;
417
  bool triso_in_mesh(
418
    vector<double> mesh_center, vector<double> lattice_pitch) const override;
419

420
  double x0_, y0_, z0_, A_, B_, C_;
421
};
422

423
//==============================================================================
424
// Non-member functions
425
//==============================================================================
426

427
void read_surfaces(pugi::xml_node node);
428

429
void free_memory_surfaces();
430

431
} // namespace openmc
432
#endif // OPENMC_SURFACE_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