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

openmc-dev / openmc / 19058781736

04 Nov 2025 05:26AM UTC coverage: 82.008% (-3.1%) from 85.155%
19058781736

Pull #3252

github

web-flow
Merge b8a72730f into bd76fc056
Pull Request #3252: Adding vtkhdf option to write vtk data

16714 of 23236 branches covered (71.93%)

Branch coverage included in aggregate %.

61 of 66 new or added lines in 1 file covered. (92.42%)

3175 existing lines in 103 files now uncovered.

54243 of 63288 relevant lines covered (85.71%)

43393337.77 hits per line

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

66.67
/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

43
  explicit Surface(pugi::xml_node surf_node);
44
  Surface();
45

46
  virtual ~Surface() {}
43,513✔
47

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

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

64
  virtual Direction diffuse_reflect(
65
    Position r, Direction u, uint64_t* seed) const;
66

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

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

81
  //! Compute the local outward normal direction of the surface.
82
  //! \param r A 3D Cartesian coordinate.
83
  //! \return Normal direction
84
  virtual Direction normal(Position r) const = 0;
85

86
  //! Write all information needed to reconstruct the surface to an HDF5 group.
87
  //! \param group_id An HDF5 group id.
88
  void to_hdf5(hid_t group_id) const;
89

90
  //! Get the BoundingBox for this surface.
UNCOV
91
  virtual BoundingBox bounding_box(bool /*pos_side*/) const { return {}; }
×
92

93
  /* Must specify if this is a CSG or DAGMC-type surface. Only
94
   * the DAGMC surface should return the DAG type geometry, so
95
   * by default, this returns the CSG. The main difference is that
96
   * if the geom_type is found to be DAG in the geometry handling code,
97
   * some DAGMC-specific operations get carried out like resetting
98
   * the particle's intersection history when necessary.
99
   */
100
  virtual GeometryType geom_type() const { return GeometryType::CSG; }
891,233,942✔
101

102
protected:
103
  virtual void to_hdf5_inner(hid_t group_id) const = 0;
104
};
105

106
//==============================================================================
107
//! A plane perpendicular to the x-axis.
108
//
109
//! The plane is described by the equation \f$x - x_0 = 0\f$
110
//==============================================================================
111

112
class SurfaceXPlane : public Surface {
113
public:
114
  explicit SurfaceXPlane(pugi::xml_node surf_node);
115
  double evaluate(Position r) const override;
116
  double distance(Position r, Direction u, bool coincident) const override;
117
  Direction normal(Position r) const override;
118
  void to_hdf5_inner(hid_t group_id) const override;
119
  BoundingBox bounding_box(bool pos_side) const override;
120

121
  double x0_;
122
};
123

124
//==============================================================================
125
//! A plane perpendicular to the y-axis.
126
//
127
//! The plane is described by the equation \f$y - y_0 = 0\f$
128
//==============================================================================
129

130
class SurfaceYPlane : public Surface {
131
public:
132
  explicit SurfaceYPlane(pugi::xml_node surf_node);
133
  double evaluate(Position r) const override;
134
  double distance(Position r, Direction u, bool coincident) const override;
135
  Direction normal(Position r) const override;
136
  void to_hdf5_inner(hid_t group_id) const override;
137
  BoundingBox bounding_box(bool pos_side) const override;
138

139
  double y0_;
140
};
141

142
//==============================================================================
143
//! A plane perpendicular to the z-axis.
144
//
145
//! The plane is described by the equation \f$z - z_0 = 0\f$
146
//==============================================================================
147

148
class SurfaceZPlane : public Surface {
149
public:
150
  explicit SurfaceZPlane(pugi::xml_node surf_node);
151
  double evaluate(Position r) const override;
152
  double distance(Position r, Direction u, bool coincident) const override;
153
  Direction normal(Position r) const override;
154
  void to_hdf5_inner(hid_t group_id) const override;
155
  BoundingBox bounding_box(bool pos_side) const override;
156

157
  double z0_;
158
};
159

160
//==============================================================================
161
//! A general plane.
162
//
163
//! The plane is described by the equation \f$A x + B y + C z - D = 0\f$
164
//==============================================================================
165

166
class SurfacePlane : public Surface {
167
public:
168
  explicit SurfacePlane(pugi::xml_node surf_node);
169
  double evaluate(Position r) const override;
170
  double distance(Position r, Direction u, bool coincident) const override;
171
  Direction normal(Position r) const override;
172
  void to_hdf5_inner(hid_t group_id) const override;
173

174
  double A_, B_, C_, D_;
175
};
176

177
//==============================================================================
178
//! A cylinder aligned along the x-axis.
179
//
180
//! The cylinder is described by the equation
181
//! \f$(y - y_0)^2 + (z - z_0)^2 - R^2 = 0\f$
182
//==============================================================================
183

184
class SurfaceXCylinder : public Surface {
185
public:
186
  explicit SurfaceXCylinder(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
  void to_hdf5_inner(hid_t group_id) const override;
191
  BoundingBox bounding_box(bool pos_side) const override;
192

193
  double y0_, z0_, radius_;
194
};
195

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

203
class SurfaceYCylinder : public Surface {
204
public:
205
  explicit SurfaceYCylinder(pugi::xml_node surf_node);
206
  double evaluate(Position r) const override;
207
  double distance(Position r, Direction u, bool coincident) const override;
208
  Direction normal(Position r) const override;
209
  void to_hdf5_inner(hid_t group_id) const override;
210
  BoundingBox bounding_box(bool pos_side) const override;
211

212
  double x0_, z0_, radius_;
213
};
214

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

222
class SurfaceZCylinder : public Surface {
223
public:
224
  explicit SurfaceZCylinder(pugi::xml_node surf_node);
225
  double evaluate(Position r) const override;
226
  double distance(Position r, Direction u, bool coincident) const override;
227
  Direction normal(Position r) const override;
228
  void to_hdf5_inner(hid_t group_id) const override;
229
  BoundingBox bounding_box(bool pos_side) const override;
230

231
  double x0_, y0_, radius_;
232
};
233

234
//==============================================================================
235
//! A sphere.
236
//
237
//! The cylinder is described by the equation
238
//! \f$(x - x_0)^2 + (y - y_0)^2 + (z - z_0)^2 - R^2 = 0\f$
239
//==============================================================================
240

241
class SurfaceSphere : public Surface {
242
public:
243
  explicit SurfaceSphere(pugi::xml_node surf_node);
244
  double evaluate(Position r) const override;
245
  double distance(Position r, Direction u, bool coincident) const override;
246
  Direction normal(Position r) const override;
247
  void to_hdf5_inner(hid_t group_id) const override;
248
  BoundingBox bounding_box(bool pos_side) const override;
249

250
  double x0_, y0_, z0_, radius_;
251
};
252

253
//==============================================================================
254
//! A cone aligned along the x-axis.
255
//
256
//! The cylinder is described by the equation
257
//! \f$(y - y_0)^2 + (z - z_0)^2 - R^2 (x - x_0)^2 = 0\f$
258
//==============================================================================
259

260
class SurfaceXCone : public Surface {
261
public:
262
  explicit SurfaceXCone(pugi::xml_node surf_node);
263
  double evaluate(Position r) const override;
264
  double distance(Position r, Direction u, bool coincident) const override;
265
  Direction normal(Position r) const override;
266
  void to_hdf5_inner(hid_t group_id) const override;
267

268
  double x0_, y0_, z0_, radius_sq_;
269
};
270

271
//==============================================================================
272
//! A cone aligned along the y-axis.
273
//
274
//! The cylinder is described by the equation
275
//! \f$(x - x_0)^2 + (z - z_0)^2 - R^2 (y - y_0)^2 = 0\f$
276
//==============================================================================
277

278
class SurfaceYCone : public Surface {
279
public:
280
  explicit SurfaceYCone(pugi::xml_node surf_node);
281
  double evaluate(Position r) const override;
282
  double distance(Position r, Direction u, bool coincident) const override;
283
  Direction normal(Position r) const override;
284
  void to_hdf5_inner(hid_t group_id) const override;
285

286
  double x0_, y0_, z0_, radius_sq_;
287
};
288

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

296
class SurfaceZCone : public Surface {
297
public:
298
  explicit SurfaceZCone(pugi::xml_node surf_node);
299
  double evaluate(Position r) const override;
300
  double distance(Position r, Direction u, bool coincident) const override;
301
  Direction normal(Position r) const override;
302
  void to_hdf5_inner(hid_t group_id) const override;
303

304
  double x0_, y0_, z0_, radius_sq_;
305
};
306

307
//==============================================================================
308
//! A general surface described by a quadratic equation.
309
//
310
//! \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 =
311
//! 0\f$
312
//==============================================================================
313

314
class SurfaceQuadric : public Surface {
315
public:
316
  explicit SurfaceQuadric(pugi::xml_node surf_node);
317
  double evaluate(Position r) const override;
318
  double distance(Position r, Direction u, bool coincident) const override;
319
  Direction normal(Position r) const override;
320
  void to_hdf5_inner(hid_t group_id) const override;
321

322
  // Ax^2 + By^2 + Cz^2 + Dxy + Eyz + Fxz + Gx + Hy + Jz + K = 0
323
  double A_, B_, C_, D_, E_, F_, G_, H_, J_, K_;
324
};
325

326
//==============================================================================
327
//! A toroidal surface described by the quartic torus lies in the x direction
328
//
329
//! \f$(x-x_0)^2/B^2 + (\sqrt{(y-y_0)^2 + (z-z_0)^2} - A)^2/C^2 -1 \f$
330
//==============================================================================
331

332
class SurfaceXTorus : public Surface {
333
public:
334
  explicit SurfaceXTorus(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

340
  double x0_, y0_, z0_, A_, B_, C_;
341
};
342

343
//==============================================================================
344
//! A toroidal surface described by the quartic torus lies in the y direction
345
//
346
//! \f$(y-y_0)^2/B^2 + (\sqrt{(x-x_0)^2 + (z-z_0)^2} - A)^2/C^2 -1 \f$
347
//==============================================================================
348

349
class SurfaceYTorus : public Surface {
350
public:
351
  explicit SurfaceYTorus(pugi::xml_node surf_node);
352
  double evaluate(Position r) const override;
353
  double distance(Position r, Direction u, bool coincident) const override;
354
  Direction normal(Position r) const override;
355
  void to_hdf5_inner(hid_t group_id) const override;
356

357
  double x0_, y0_, z0_, A_, B_, C_;
358
};
359

360
//==============================================================================
361
//! A toroidal surface described by the quartic torus lies in the z direction
362
//
363
//! \f$(z-z_0)^2/B^2 + (\sqrt{(x-x_0)^2 + (y-y_0)^2} - A)^2/C^2 -1 \f$
364
//==============================================================================
365

366
class SurfaceZTorus : public Surface {
367
public:
368
  explicit SurfaceZTorus(pugi::xml_node surf_node);
369
  double evaluate(Position r) const override;
370
  double distance(Position r, Direction u, bool coincident) const override;
371
  Direction normal(Position r) const override;
372
  void to_hdf5_inner(hid_t group_id) const override;
373

374
  double x0_, y0_, z0_, A_, B_, C_;
375
};
376

377
//==============================================================================
378
// Non-member functions
379
//==============================================================================
380

381
void read_surfaces(pugi::xml_node node);
382

383
void free_memory_surfaces();
384

385
} // namespace openmc
386
#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