Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 00d83b0

Browse files
gridleypshriwise
authored andcommittedFeb 11, 2025·
minor simplification of csg/dag geometry type checking
1 parent 27ce2ce commit 00d83b0

File tree

7 files changed

+56
-80
lines changed

7 files changed

+56
-80
lines changed
 

‎include/openmc/cell.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,8 @@ class Cell {
349349

350350
vector<int32_t> offset_; //!< Distribcell offset table
351351

352-
// Accessors
353-
const GeometryType& geom_type() const { return geom_type_; }
354-
GeometryType& geom_type() { return geom_type_; }
355-
356-
private:
357-
GeometryType geom_type_; //!< Geometric representation type (CSG, DAGMC)
352+
// Right now, either CSG or DAGMC cells are used.
353+
virtual GeometryType geom_type() const = 0;
358354
};
359355

360356
struct CellInstanceItem {
@@ -368,7 +364,7 @@ class CSGCell : public Cell {
368364
public:
369365
//----------------------------------------------------------------------------
370366
// Constructors
371-
CSGCell();
367+
CSGCell() = default;
372368
explicit CSGCell(pugi::xml_node cell_node);
373369

374370
//----------------------------------------------------------------------------
@@ -395,6 +391,8 @@ class CSGCell : public Cell {
395391

396392
bool is_simple() const override { return region_.is_simple(); }
397393

394+
virtual GeometryType geom_type() const override { return GeometryType::CSG; }
395+
398396
protected:
399397
//! Returns the beginning position of a parenthesis block (immediately before
400398
//! two surface tokens) in the RPN given a starting position at the end of

‎include/openmc/dagmc.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class DAGSurface : public Surface {
5353

5454
inline void to_hdf5_inner(hid_t group_id) const override {};
5555

56+
virtual GeometryType geom_type() const override { return GeometryType::DAG; }
57+
5658
// Accessor methods
5759
moab::DagMC* dagmc_ptr() const { return dagmc_ptr_.get(); }
5860
int32_t dag_index() const { return dag_index_; }
@@ -77,6 +79,8 @@ class DAGCell : public Cell {
7779

7880
void to_hdf5_inner(hid_t group_id) const override;
7981

82+
virtual GeometryType geom_type() const override { return GeometryType::DAG; }
83+
8084
// Accessor methods
8185
moab::DagMC* dagmc_ptr() const { return dagmc_ptr_.get(); }
8286
int32_t dag_index() const { return dag_index_; }
@@ -164,6 +168,8 @@ class DAGUniverse : public Universe {
164168

165169
void to_hdf5(hid_t universes_group) const override;
166170

171+
virtual GeometryType geom_type() const override { return GeometryType::DAG; }
172+
167173
// Data Members
168174
std::shared_ptr<moab::DagMC>
169175
dagmc_instance_; //!< DAGMC Instance for this universe

‎include/openmc/surface.h

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -90,30 +90,26 @@ class Surface {
9090
//! Get the BoundingBox for this surface.
9191
virtual BoundingBox bounding_box(bool /*pos_side*/) const { return {}; }
9292

93-
// Accessors
94-
const GeometryType& geom_type() const { return geom_type_; }
95-
GeometryType& geom_type() { return geom_type_; }
96-
97-
private:
98-
GeometryType geom_type_; //!< Geometry type indicator (CSG or DAGMC)
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; }
99101

100102
protected:
101103
virtual void to_hdf5_inner(hid_t group_id) const = 0;
102104
};
103105

104-
class CSGSurface : public Surface {
105-
public:
106-
explicit CSGSurface(pugi::xml_node surf_node);
107-
CSGSurface();
108-
};
109-
110106
//==============================================================================
111107
//! A plane perpendicular to the x-axis.
112108
//
113109
//! The plane is described by the equation \f$x - x_0 = 0\f$
114110
//==============================================================================
115111

116-
class SurfaceXPlane : public CSGSurface {
112+
class SurfaceXPlane : public Surface {
117113
public:
118114
explicit SurfaceXPlane(pugi::xml_node surf_node);
119115
double evaluate(Position r) const override;
@@ -131,7 +127,7 @@ class SurfaceXPlane : public CSGSurface {
131127
//! The plane is described by the equation \f$y - y_0 = 0\f$
132128
//==============================================================================
133129

134-
class SurfaceYPlane : public CSGSurface {
130+
class SurfaceYPlane : public Surface {
135131
public:
136132
explicit SurfaceYPlane(pugi::xml_node surf_node);
137133
double evaluate(Position r) const override;
@@ -149,7 +145,7 @@ class SurfaceYPlane : public CSGSurface {
149145
//! The plane is described by the equation \f$z - z_0 = 0\f$
150146
//==============================================================================
151147

152-
class SurfaceZPlane : public CSGSurface {
148+
class SurfaceZPlane : public Surface {
153149
public:
154150
explicit SurfaceZPlane(pugi::xml_node surf_node);
155151
double evaluate(Position r) const override;
@@ -167,7 +163,7 @@ class SurfaceZPlane : public CSGSurface {
167163
//! The plane is described by the equation \f$A x + B y + C z - D = 0\f$
168164
//==============================================================================
169165

170-
class SurfacePlane : public CSGSurface {
166+
class SurfacePlane : public Surface {
171167
public:
172168
explicit SurfacePlane(pugi::xml_node surf_node);
173169
double evaluate(Position r) const override;
@@ -185,7 +181,7 @@ class SurfacePlane : public CSGSurface {
185181
//! \f$(y - y_0)^2 + (z - z_0)^2 - R^2 = 0\f$
186182
//==============================================================================
187183

188-
class SurfaceXCylinder : public CSGSurface {
184+
class SurfaceXCylinder : public Surface {
189185
public:
190186
explicit SurfaceXCylinder(pugi::xml_node surf_node);
191187
double evaluate(Position r) const override;
@@ -204,7 +200,7 @@ class SurfaceXCylinder : public CSGSurface {
204200
//! \f$(x - x_0)^2 + (z - z_0)^2 - R^2 = 0\f$
205201
//==============================================================================
206202

207-
class SurfaceYCylinder : public CSGSurface {
203+
class SurfaceYCylinder : public Surface {
208204
public:
209205
explicit SurfaceYCylinder(pugi::xml_node surf_node);
210206
double evaluate(Position r) const override;
@@ -223,7 +219,7 @@ class SurfaceYCylinder : public CSGSurface {
223219
//! \f$(x - x_0)^2 + (y - y_0)^2 - R^2 = 0\f$
224220
//==============================================================================
225221

226-
class SurfaceZCylinder : public CSGSurface {
222+
class SurfaceZCylinder : public Surface {
227223
public:
228224
explicit SurfaceZCylinder(pugi::xml_node surf_node);
229225
double evaluate(Position r) const override;
@@ -242,7 +238,7 @@ class SurfaceZCylinder : public CSGSurface {
242238
//! \f$(x - x_0)^2 + (y - y_0)^2 + (z - z_0)^2 - R^2 = 0\f$
243239
//==============================================================================
244240

245-
class SurfaceSphere : public CSGSurface {
241+
class SurfaceSphere : public Surface {
246242
public:
247243
explicit SurfaceSphere(pugi::xml_node surf_node);
248244
double evaluate(Position r) const override;
@@ -261,7 +257,7 @@ class SurfaceSphere : public CSGSurface {
261257
//! \f$(y - y_0)^2 + (z - z_0)^2 - R^2 (x - x_0)^2 = 0\f$
262258
//==============================================================================
263259

264-
class SurfaceXCone : public CSGSurface {
260+
class SurfaceXCone : public Surface {
265261
public:
266262
explicit SurfaceXCone(pugi::xml_node surf_node);
267263
double evaluate(Position r) const override;
@@ -279,7 +275,7 @@ class SurfaceXCone : public CSGSurface {
279275
//! \f$(x - x_0)^2 + (z - z_0)^2 - R^2 (y - y_0)^2 = 0\f$
280276
//==============================================================================
281277

282-
class SurfaceYCone : public CSGSurface {
278+
class SurfaceYCone : public Surface {
283279
public:
284280
explicit SurfaceYCone(pugi::xml_node surf_node);
285281
double evaluate(Position r) const override;
@@ -297,7 +293,7 @@ class SurfaceYCone : public CSGSurface {
297293
//! \f$(x - x_0)^2 + (y - y_0)^2 - R^2 (z - z_0)^2 = 0\f$
298294
//==============================================================================
299295

300-
class SurfaceZCone : public CSGSurface {
296+
class SurfaceZCone : public Surface {
301297
public:
302298
explicit SurfaceZCone(pugi::xml_node surf_node);
303299
double evaluate(Position r) const override;
@@ -315,7 +311,7 @@ class SurfaceZCone : public CSGSurface {
315311
//! 0\f$
316312
//==============================================================================
317313

318-
class SurfaceQuadric : public CSGSurface {
314+
class SurfaceQuadric : public Surface {
319315
public:
320316
explicit SurfaceQuadric(pugi::xml_node surf_node);
321317
double evaluate(Position r) const override;
@@ -333,7 +329,7 @@ class SurfaceQuadric : public CSGSurface {
333329
//! \f$(x-x_0)^2/B^2 + (\sqrt{(y-y_0)^2 + (z-z_0)^2} - A)^2/C^2 -1 \f$
334330
//==============================================================================
335331

336-
class SurfaceXTorus : public CSGSurface {
332+
class SurfaceXTorus : public Surface {
337333
public:
338334
explicit SurfaceXTorus(pugi::xml_node surf_node);
339335
double evaluate(Position r) const override;
@@ -350,7 +346,7 @@ class SurfaceXTorus : public CSGSurface {
350346
//! \f$(y-y_0)^2/B^2 + (\sqrt{(x-x_0)^2 + (z-z_0)^2} - A)^2/C^2 -1 \f$
351347
//==============================================================================
352348

353-
class SurfaceYTorus : public CSGSurface {
349+
class SurfaceYTorus : public Surface {
354350
public:
355351
explicit SurfaceYTorus(pugi::xml_node surf_node);
356352
double evaluate(Position r) const override;
@@ -367,7 +363,7 @@ class SurfaceYTorus : public CSGSurface {
367363
//! \f$(z-z_0)^2/B^2 + (\sqrt{(x-x_0)^2 + (y-y_0)^2} - A)^2/C^2 -1 \f$
368364
//==============================================================================
369365

370-
class SurfaceZTorus : public CSGSurface {
366+
class SurfaceZTorus : public Surface {
371367
public:
372368
explicit SurfaceZTorus(pugi::xml_node surf_node);
373369
double evaluate(Position r) const override;

‎include/openmc/universe.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ class Universe {
3838

3939
BoundingBox bounding_box() const;
4040

41-
const GeometryType& geom_type() const { return geom_type_; }
42-
GeometryType& geom_type() { return geom_type_; }
41+
/* By default, universes are CSG universes. The DAGMC
42+
* universe overrides standard behaviors, and in the future,
43+
* other things might too.
44+
*/
45+
virtual GeometryType geom_type() const { return GeometryType::CSG; }
4346

4447
unique_ptr<UniversePartitioner> partitioner_;
45-
46-
private:
47-
GeometryType geom_type_ = GeometryType::CSG;
4848
};
4949

5050
//==============================================================================

‎src/cell.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,8 @@ void Cell::to_hdf5(hid_t cell_group) const
249249
// CSGCell implementation
250250
//==============================================================================
251251

252-
// default constructor
253-
CSGCell::CSGCell()
254-
{
255-
geom_type() = GeometryType::CSG;
256-
}
257-
258252
CSGCell::CSGCell(pugi::xml_node cell_node)
259253
{
260-
geom_type() = GeometryType::CSG;
261-
262254
if (check_for_node(cell_node, "id")) {
263255
id_ = std::stoi(get_node_value(cell_node, "id"));
264256
} else {

‎src/dagmc.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@ void DAGUniverse::set_id()
129129

130130
void DAGUniverse::initialize()
131131
{
132-
geom_type() = GeometryType::DAG;
133-
134132
#ifdef OPENMC_UWUW
135133
// read uwuw materials from the .h5m file if present
136134
read_uwuw_materials();
@@ -661,10 +659,7 @@ void DAGUniverse::override_assign_material(std::unique_ptr<DAGCell>& c) const
661659
//==============================================================================
662660

663661
DAGCell::DAGCell(std::shared_ptr<moab::DagMC> dag_ptr, int32_t dag_idx)
664-
: Cell {}, dagmc_ptr_(dag_ptr), dag_index_(dag_idx)
665-
{
666-
geom_type() = GeometryType::DAG;
667-
};
662+
: Cell {}, dagmc_ptr_(dag_ptr), dag_index_(dag_idx) {};
668663

669664
std::pair<double, int32_t> DAGCell::distance(
670665
Position r, Direction u, int32_t on_surface, GeometryState* p) const
@@ -765,9 +760,7 @@ BoundingBox DAGCell::bounding_box() const
765760

766761
DAGSurface::DAGSurface(std::shared_ptr<moab::DagMC> dag_ptr, int32_t dag_idx)
767762
: Surface {}, dagmc_ptr_(dag_ptr), dag_index_(dag_idx)
768-
{
769-
geom_type() = GeometryType::DAG;
770-
} // empty constructor
763+
{} // empty constructor
771764

772765
moab::EntityHandle DAGSurface::mesh_handle() const
773766
{

‎src/surface.cpp

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,6 @@ void Surface::to_hdf5(hid_t group_id) const
187187
close_group(surf_group);
188188
}
189189

190-
CSGSurface::CSGSurface() : Surface {}
191-
{
192-
geom_type() = GeometryType::CSG;
193-
};
194-
CSGSurface::CSGSurface(pugi::xml_node surf_node) : Surface {surf_node}
195-
{
196-
geom_type() = GeometryType::CSG;
197-
};
198-
199190
//==============================================================================
200191
// Generic functions for x-, y-, and z-, planes.
201192
//==============================================================================
@@ -218,7 +209,7 @@ double axis_aligned_plane_distance(
218209
// SurfaceXPlane implementation
219210
//==============================================================================
220211

221-
SurfaceXPlane::SurfaceXPlane(pugi::xml_node surf_node) : CSGSurface(surf_node)
212+
SurfaceXPlane::SurfaceXPlane(pugi::xml_node surf_node) : Surface(surf_node)
222213
{
223214
read_coeffs(surf_node, id_, {&x0_});
224215
}
@@ -258,7 +249,7 @@ BoundingBox SurfaceXPlane::bounding_box(bool pos_side) const
258249
// SurfaceYPlane implementation
259250
//==============================================================================
260251

261-
SurfaceYPlane::SurfaceYPlane(pugi::xml_node surf_node) : CSGSurface(surf_node)
252+
SurfaceYPlane::SurfaceYPlane(pugi::xml_node surf_node) : Surface(surf_node)
262253
{
263254
read_coeffs(surf_node, id_, {&y0_});
264255
}
@@ -298,7 +289,7 @@ BoundingBox SurfaceYPlane::bounding_box(bool pos_side) const
298289
// SurfaceZPlane implementation
299290
//==============================================================================
300291

301-
SurfaceZPlane::SurfaceZPlane(pugi::xml_node surf_node) : CSGSurface(surf_node)
292+
SurfaceZPlane::SurfaceZPlane(pugi::xml_node surf_node) : Surface(surf_node)
302293
{
303294
read_coeffs(surf_node, id_, {&z0_});
304295
}
@@ -338,7 +329,7 @@ BoundingBox SurfaceZPlane::bounding_box(bool pos_side) const
338329
// SurfacePlane implementation
339330
//==============================================================================
340331

341-
SurfacePlane::SurfacePlane(pugi::xml_node surf_node) : CSGSurface(surf_node)
332+
SurfacePlane::SurfacePlane(pugi::xml_node surf_node) : Surface(surf_node)
342333
{
343334
read_coeffs(surf_node, id_, {&A_, &B_, &C_, &D_});
344335
}
@@ -457,7 +448,7 @@ Direction axis_aligned_cylinder_normal(
457448
//==============================================================================
458449

459450
SurfaceXCylinder::SurfaceXCylinder(pugi::xml_node surf_node)
460-
: CSGSurface(surf_node)
451+
: Surface(surf_node)
461452
{
462453
read_coeffs(surf_node, id_, {&y0_, &z0_, &radius_});
463454
}
@@ -500,7 +491,7 @@ BoundingBox SurfaceXCylinder::bounding_box(bool pos_side) const
500491
//==============================================================================
501492

502493
SurfaceYCylinder::SurfaceYCylinder(pugi::xml_node surf_node)
503-
: CSGSurface(surf_node)
494+
: Surface(surf_node)
504495
{
505496
read_coeffs(surf_node, id_, {&x0_, &z0_, &radius_});
506497
}
@@ -544,7 +535,7 @@ BoundingBox SurfaceYCylinder::bounding_box(bool pos_side) const
544535
//==============================================================================
545536

546537
SurfaceZCylinder::SurfaceZCylinder(pugi::xml_node surf_node)
547-
: CSGSurface(surf_node)
538+
: Surface(surf_node)
548539
{
549540
read_coeffs(surf_node, id_, {&x0_, &y0_, &radius_});
550541
}
@@ -587,7 +578,7 @@ BoundingBox SurfaceZCylinder::bounding_box(bool pos_side) const
587578
// SurfaceSphere implementation
588579
//==============================================================================
589580

590-
SurfaceSphere::SurfaceSphere(pugi::xml_node surf_node) : CSGSurface(surf_node)
581+
SurfaceSphere::SurfaceSphere(pugi::xml_node surf_node) : Surface(surf_node)
591582
{
592583
read_coeffs(surf_node, id_, {&x0_, &y0_, &z0_, &radius_});
593584
}
@@ -753,7 +744,7 @@ Direction axis_aligned_cone_normal(
753744
// SurfaceXCone implementation
754745
//==============================================================================
755746

756-
SurfaceXCone::SurfaceXCone(pugi::xml_node surf_node) : CSGSurface(surf_node)
747+
SurfaceXCone::SurfaceXCone(pugi::xml_node surf_node) : Surface(surf_node)
757748
{
758749
read_coeffs(surf_node, id_, {&x0_, &y0_, &z0_, &radius_sq_});
759750
}
@@ -785,7 +776,7 @@ void SurfaceXCone::to_hdf5_inner(hid_t group_id) const
785776
// SurfaceYCone implementation
786777
//==============================================================================
787778

788-
SurfaceYCone::SurfaceYCone(pugi::xml_node surf_node) : CSGSurface(surf_node)
779+
SurfaceYCone::SurfaceYCone(pugi::xml_node surf_node) : Surface(surf_node)
789780
{
790781
read_coeffs(surf_node, id_, {&x0_, &y0_, &z0_, &radius_sq_});
791782
}
@@ -817,7 +808,7 @@ void SurfaceYCone::to_hdf5_inner(hid_t group_id) const
817808
// SurfaceZCone implementation
818809
//==============================================================================
819810

820-
SurfaceZCone::SurfaceZCone(pugi::xml_node surf_node) : CSGSurface(surf_node)
811+
SurfaceZCone::SurfaceZCone(pugi::xml_node surf_node) : Surface(surf_node)
821812
{
822813
read_coeffs(surf_node, id_, {&x0_, &y0_, &z0_, &radius_sq_});
823814
}
@@ -849,7 +840,7 @@ void SurfaceZCone::to_hdf5_inner(hid_t group_id) const
849840
// SurfaceQuadric implementation
850841
//==============================================================================
851842

852-
SurfaceQuadric::SurfaceQuadric(pugi::xml_node surf_node) : CSGSurface(surf_node)
843+
SurfaceQuadric::SurfaceQuadric(pugi::xml_node surf_node) : Surface(surf_node)
853844
{
854845
read_coeffs(
855846
surf_node, id_, {&A_, &B_, &C_, &D_, &E_, &F_, &G_, &H_, &J_, &K_});
@@ -1009,7 +1000,7 @@ double torus_distance(double x1, double x2, double x3, double u1, double u2,
10091000
// SurfaceXTorus implementation
10101001
//==============================================================================
10111002

1012-
SurfaceXTorus::SurfaceXTorus(pugi::xml_node surf_node) : CSGSurface(surf_node)
1003+
SurfaceXTorus::SurfaceXTorus(pugi::xml_node surf_node) : Surface(surf_node)
10131004
{
10141005
read_coeffs(surf_node, id_, {&x0_, &y0_, &z0_, &A_, &B_, &C_});
10151006
}
@@ -1062,7 +1053,7 @@ Direction SurfaceXTorus::normal(Position r) const
10621053
// SurfaceYTorus implementation
10631054
//==============================================================================
10641055

1065-
SurfaceYTorus::SurfaceYTorus(pugi::xml_node surf_node) : CSGSurface(surf_node)
1056+
SurfaceYTorus::SurfaceYTorus(pugi::xml_node surf_node) : Surface(surf_node)
10661057
{
10671058
read_coeffs(surf_node, id_, {&x0_, &y0_, &z0_, &A_, &B_, &C_});
10681059
}
@@ -1115,7 +1106,7 @@ Direction SurfaceYTorus::normal(Position r) const
11151106
// SurfaceZTorus implementation
11161107
//==============================================================================
11171108

1118-
SurfaceZTorus::SurfaceZTorus(pugi::xml_node surf_node) : CSGSurface(surf_node)
1109+
SurfaceZTorus::SurfaceZTorus(pugi::xml_node surf_node) : Surface(surf_node)
11191110
{
11201111
read_coeffs(surf_node, id_, {&x0_, &y0_, &z0_, &A_, &B_, &C_});
11211112
}

0 commit comments

Comments
 (0)
Please sign in to comment.