Skip to content

Commit bcc2a4c

Browse files
authored
simplify mechanism to detect if geometry entity is DAG (#3269)
1 parent 06a8852 commit bcc2a4c

File tree

7 files changed

+56
-80
lines changed

7 files changed

+56
-80
lines changed

include/openmc/cell.h

+5-7
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

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class DAGSurface : public Surface {
5454

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

57+
virtual GeometryType geom_type() const override { return GeometryType::DAG; }
58+
5759
// Accessor methods
5860
moab::DagMC* dagmc_ptr() const { return dagmc_ptr_.get(); }
5961
int32_t dag_index() const { return dag_index_; }
@@ -78,6 +80,8 @@ class DAGCell : public Cell {
7880

7981
void to_hdf5_inner(hid_t group_id) const override;
8082

83+
virtual GeometryType geom_type() const override { return GeometryType::DAG; }
84+
8185
// Accessor methods
8286
moab::DagMC* dagmc_ptr() const { return dagmc_ptr_.get(); }
8387
int32_t dag_index() const { return dag_index_; }
@@ -165,6 +169,8 @@ class DAGUniverse : public Universe {
165169

166170
void to_hdf5(hid_t universes_group) const override;
167171

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

include/openmc/surface.h

+23-27
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

+5-5
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

-8
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

+2-9
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
{

0 commit comments

Comments
 (0)