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

openmc-dev / openmc / 4812163747

pending completion
4812163747

push

github

GitHub
Merge pull request #2494 from aprilnovak/delete-tally

1 of 2 new or added lines in 1 file covered. (50.0%)

124 existing lines in 19 files now uncovered.

42440 of 50752 relevant lines covered (83.62%)

78971666.53 hits per line

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

0.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/constants.h"
13
#include "openmc/memory.h" // for unique_ptr
14
#include "openmc/particle.h"
15
#include "openmc/position.h"
16
#include "openmc/vector.h"
17

18
namespace openmc {
19

20
//==============================================================================
21
// Global variables
22
//==============================================================================
23

24
class Surface;
25

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

31
//==============================================================================
32
//! Coordinates for an axis-aligned cuboid that bounds a geometric object.
33
//==============================================================================
34

35
struct BoundingBox {
36
  double xmin = -INFTY;
37
  double xmax = INFTY;
38
  double ymin = -INFTY;
39
  double ymax = INFTY;
40
  double zmin = -INFTY;
41
  double zmax = INFTY;
42

43
  inline BoundingBox operator&(const BoundingBox& other)
44
  {
45
    BoundingBox result = *this;
46
    return result &= other;
47
  }
48

49
  inline BoundingBox operator|(const BoundingBox& other)
50
  {
51
    BoundingBox result = *this;
52
    return result |= other;
53
  }
54

55
  // intersect operator
56
  inline BoundingBox& operator&=(const BoundingBox& other)
57
  {
58
    xmin = std::max(xmin, other.xmin);
59
    xmax = std::min(xmax, other.xmax);
60
    ymin = std::max(ymin, other.ymin);
61
    ymax = std::min(ymax, other.ymax);
62
    zmin = std::max(zmin, other.zmin);
63
    zmax = std::min(zmax, other.zmax);
64
    return *this;
65
  }
66

67
  // union operator
68
  inline BoundingBox& operator|=(const BoundingBox& other)
69
  {
UNCOV
70
    xmin = std::min(xmin, other.xmin);
×
UNCOV
71
    xmax = std::max(xmax, other.xmax);
×
UNCOV
72
    ymin = std::min(ymin, other.ymin);
×
UNCOV
73
    ymax = std::max(ymax, other.ymax);
×
UNCOV
74
    zmin = std::min(zmin, other.zmin);
×
UNCOV
75
    zmax = std::max(zmax, other.zmax);
×
UNCOV
76
    return *this;
×
77
  }
78
};
79

80
//==============================================================================
81
//! A geometry primitive used to define regions of 3D space.
82
//==============================================================================
83

84
class Surface {
85
public:
86
  int id_;                                          //!< Unique ID
87
  std::string name_;                                //!< User-defined name
88
  std::shared_ptr<BoundaryCondition> bc_ {nullptr}; //!< Boundary condition
89
  GeometryType geom_type_;   //!< Geometry type indicator (CSG or DAGMC)
90
  bool surf_source_ {false}; //!< Activate source banking for the surface?
91

92
  explicit Surface(pugi::xml_node surf_node);
93
  Surface();
94

95
  virtual ~Surface() {}
96

97
  //! Determine which side of a surface a point lies on.
98
  //! \param r The 3D Cartesian coordinate of a point.
99
  //! \param u A direction used to "break ties" and pick a sense when the
100
  //!   point is very close to the surface.
101
  //! \return true if the point is on the "positive" side of the surface and
102
  //!   false otherwise.
103
  bool sense(Position r, Direction u) const;
104

105
  //! Determine the direction of a ray reflected from the surface.
106
  //! \param[in] r The point at which the ray is incident.
107
  //! \param[in] u Incident direction of the ray
108
  //! \param[inout] p Pointer to the particle
109
  //! \return Outgoing direction of the ray
110
  virtual Direction reflect(Position r, Direction u, Particle* p) const;
111

112
  virtual Direction diffuse_reflect(
113
    Position r, Direction u, uint64_t* seed) const;
114

115
  //! Evaluate the equation describing the surface.
116
  //!
117
  //! Surfaces can be described by some function f(x, y, z) = 0.  This member
118
  //! function evaluates that mathematical function.
119
  //! \param r A 3D Cartesian coordinate.
120
  virtual double evaluate(Position r) const = 0;
121

122
  //! Compute the distance between a point and the surface along a ray.
123
  //! \param r A 3D Cartesian coordinate.
124
  //! \param u The direction of the ray.
125
  //! \param coincident A hint to the code that the given point should lie
126
  //!   exactly on the surface.
127
  virtual double distance(Position r, Direction u, bool coincident) const = 0;
128

129
  //! Compute the local outward normal direction of the surface.
130
  //! \param r A 3D Cartesian coordinate.
131
  //! \return Normal direction
132
  virtual Direction normal(Position r) const = 0;
133

134
  //! Write all information needed to reconstruct the surface to an HDF5 group.
135
  //! \param group_id An HDF5 group id.
136
  void to_hdf5(hid_t group_id) const;
137

138
  //! Get the BoundingBox for this surface.
139
  virtual BoundingBox bounding_box(bool /*pos_side*/) const { return {}; }
140

141
protected:
142
  virtual void to_hdf5_inner(hid_t group_id) const = 0;
143
};
144

145
class CSGSurface : public Surface {
146
public:
147
  explicit CSGSurface(pugi::xml_node surf_node);
148
  CSGSurface();
149
};
150

151
//==============================================================================
152
//! A plane perpendicular to the x-axis.
153
//
154
//! The plane is described by the equation \f$x - x_0 = 0\f$
155
//==============================================================================
156

157
class SurfaceXPlane : public CSGSurface {
158
public:
159
  explicit SurfaceXPlane(pugi::xml_node surf_node);
160
  double evaluate(Position r) const override;
161
  double distance(Position r, Direction u, bool coincident) const override;
162
  Direction normal(Position r) const override;
163
  void to_hdf5_inner(hid_t group_id) const override;
164
  BoundingBox bounding_box(bool pos_side) const override;
165

166
  double x0_;
167
};
168

169
//==============================================================================
170
//! A plane perpendicular to the y-axis.
171
//
172
//! The plane is described by the equation \f$y - y_0 = 0\f$
173
//==============================================================================
174

175
class SurfaceYPlane : public CSGSurface {
176
public:
177
  explicit SurfaceYPlane(pugi::xml_node surf_node);
178
  double evaluate(Position r) const override;
179
  double distance(Position r, Direction u, bool coincident) const override;
180
  Direction normal(Position r) const override;
181
  void to_hdf5_inner(hid_t group_id) const override;
182
  BoundingBox bounding_box(bool pos_side) const override;
183

184
  double y0_;
185
};
186

187
//==============================================================================
188
//! A plane perpendicular to the z-axis.
189
//
190
//! The plane is described by the equation \f$z - z_0 = 0\f$
191
//==============================================================================
192

193
class SurfaceZPlane : public CSGSurface {
194
public:
195
  explicit SurfaceZPlane(pugi::xml_node surf_node);
196
  double evaluate(Position r) const override;
197
  double distance(Position r, Direction u, bool coincident) const override;
198
  Direction normal(Position r) const override;
199
  void to_hdf5_inner(hid_t group_id) const override;
200
  BoundingBox bounding_box(bool pos_side) const override;
201

202
  double z0_;
203
};
204

205
//==============================================================================
206
//! A general plane.
207
//
208
//! The plane is described by the equation \f$A x + B y + C z - D = 0\f$
209
//==============================================================================
210

211
class SurfacePlane : public CSGSurface {
212
public:
213
  explicit SurfacePlane(pugi::xml_node surf_node);
214
  double evaluate(Position r) const override;
215
  double distance(Position r, Direction u, bool coincident) const override;
216
  Direction normal(Position r) const override;
217
  void to_hdf5_inner(hid_t group_id) const override;
218

219
  double A_, B_, C_, D_;
220
};
221

222
//==============================================================================
223
//! A cylinder aligned along the x-axis.
224
//
225
//! The cylinder is described by the equation
226
//! \f$(y - y_0)^2 + (z - z_0)^2 - R^2 = 0\f$
227
//==============================================================================
228

229
class SurfaceXCylinder : public CSGSurface {
230
public:
231
  explicit SurfaceXCylinder(pugi::xml_node surf_node);
232
  double evaluate(Position r) const override;
233
  double distance(Position r, Direction u, bool coincident) const override;
234
  Direction normal(Position r) const override;
235
  void to_hdf5_inner(hid_t group_id) const override;
236
  BoundingBox bounding_box(bool pos_side) const override;
237

238
  double y0_, z0_, radius_;
239
};
240

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

248
class SurfaceYCylinder : public CSGSurface {
249
public:
250
  explicit SurfaceYCylinder(pugi::xml_node surf_node);
251
  double evaluate(Position r) const override;
252
  double distance(Position r, Direction u, bool coincident) const override;
253
  Direction normal(Position r) const override;
254
  void to_hdf5_inner(hid_t group_id) const override;
255
  BoundingBox bounding_box(bool pos_side) const override;
256

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

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

267
class SurfaceZCylinder : public CSGSurface {
268
public:
269
  explicit SurfaceZCylinder(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
  BoundingBox bounding_box(bool pos_side) const override;
275

276
  double x0_, y0_, radius_;
277
};
278

279
//==============================================================================
280
//! A sphere.
281
//
282
//! The cylinder is described by the equation
283
//! \f$(x - x_0)^2 + (y - y_0)^2 + (z - z_0)^2 - R^2 = 0\f$
284
//==============================================================================
285

286
class SurfaceSphere : public CSGSurface {
287
public:
288
  explicit SurfaceSphere(pugi::xml_node surf_node);
289
  double evaluate(Position r) const override;
290
  double distance(Position r, Direction u, bool coincident) const override;
291
  Direction normal(Position r) const override;
292
  void to_hdf5_inner(hid_t group_id) const override;
293
  BoundingBox bounding_box(bool pos_side) const override;
294

295
  double x0_, y0_, z0_, radius_;
296
};
297

298
//==============================================================================
299
//! A cone aligned along the x-axis.
300
//
301
//! The cylinder is described by the equation
302
//! \f$(y - y_0)^2 + (z - z_0)^2 - R^2 (x - x_0)^2 = 0\f$
303
//==============================================================================
304

305
class SurfaceXCone : public CSGSurface {
306
public:
307
  explicit SurfaceXCone(pugi::xml_node surf_node);
308
  double evaluate(Position r) const override;
309
  double distance(Position r, Direction u, bool coincident) const override;
310
  Direction normal(Position r) const override;
311
  void to_hdf5_inner(hid_t group_id) const override;
312

313
  double x0_, y0_, z0_, radius_sq_;
314
};
315

316
//==============================================================================
317
//! A cone aligned along the y-axis.
318
//
319
//! The cylinder is described by the equation
320
//! \f$(x - x_0)^2 + (z - z_0)^2 - R^2 (y - y_0)^2 = 0\f$
321
//==============================================================================
322

323
class SurfaceYCone : public CSGSurface {
324
public:
325
  explicit SurfaceYCone(pugi::xml_node surf_node);
326
  double evaluate(Position r) const override;
327
  double distance(Position r, Direction u, bool coincident) const override;
328
  Direction normal(Position r) const override;
329
  void to_hdf5_inner(hid_t group_id) const override;
330

331
  double x0_, y0_, z0_, radius_sq_;
332
};
333

334
//==============================================================================
335
//! A cone aligned along the z-axis.
336
//
337
//! The cylinder is described by the equation
338
//! \f$(x - x_0)^2 + (y - y_0)^2 - R^2 (z - z_0)^2 = 0\f$
339
//==============================================================================
340

341
class SurfaceZCone : public CSGSurface {
342
public:
343
  explicit SurfaceZCone(pugi::xml_node surf_node);
344
  double evaluate(Position r) const override;
345
  double distance(Position r, Direction u, bool coincident) const override;
346
  Direction normal(Position r) const override;
347
  void to_hdf5_inner(hid_t group_id) const override;
348

349
  double x0_, y0_, z0_, radius_sq_;
350
};
351

352
//==============================================================================
353
//! A general surface described by a quadratic equation.
354
//
355
//! \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 =
356
//! 0\f$
357
//==============================================================================
358

359
class SurfaceQuadric : public CSGSurface {
360
public:
361
  explicit SurfaceQuadric(pugi::xml_node surf_node);
362
  double evaluate(Position r) const override;
363
  double distance(Position r, Direction u, bool coincident) const override;
364
  Direction normal(Position r) const override;
365
  void to_hdf5_inner(hid_t group_id) const override;
366

367
  // Ax^2 + By^2 + Cz^2 + Dxy + Eyz + Fxz + Gx + Hy + Jz + K = 0
368
  double A_, B_, C_, D_, E_, F_, G_, H_, J_, K_;
369
};
370

371
//==============================================================================
372
//! A toroidal surface described by the quartic torus lies in the x direction
373
//
374
//! \f$(x-x_0)^2/B^2 + (\sqrt{(y-y_0)^2 + (z-z_0)^2} - A)^2/C^2 -1 \f$
375
//==============================================================================
376

377
class SurfaceXTorus : public CSGSurface {
378
public:
379
  explicit SurfaceXTorus(pugi::xml_node surf_node);
380
  double evaluate(Position r) const override;
381
  double distance(Position r, Direction u, bool coincident) const override;
382
  Direction normal(Position r) const override;
383
  void to_hdf5_inner(hid_t group_id) const override;
384

385
  double x0_, y0_, z0_, A_, B_, C_;
386
};
387

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

394
class SurfaceYTorus : public CSGSurface {
395
public:
396
  explicit SurfaceYTorus(pugi::xml_node surf_node);
397
  double evaluate(Position r) const override;
398
  double distance(Position r, Direction u, bool coincident) const override;
399
  Direction normal(Position r) const override;
400
  void to_hdf5_inner(hid_t group_id) const override;
401

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

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

411
class SurfaceZTorus : public CSGSurface {
412
public:
413
  explicit SurfaceZTorus(pugi::xml_node surf_node);
414
  double evaluate(Position r) const override;
415
  double distance(Position r, Direction u, bool coincident) const override;
416
  Direction normal(Position r) const override;
417
  void to_hdf5_inner(hid_t group_id) const override;
418

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

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

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

428
void free_memory_surfaces();
429

430
} // namespace openmc
431
#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