From 956cf08481c1d712ecd05494fb57eff6a686a561 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 6 Nov 2020 10:56:59 -0600 Subject: [PATCH] Relying on the same enum to describe the Geometry type of different classes. --- include/openmc/cell.h | 12 +++--------- include/openmc/surface.h | 13 +++++++++++-- src/cell.cpp | 16 ++++++++++++---- src/dagmc.cpp | 2 +- src/surface.cpp | 31 +++++++++++++++++++------------ 5 files changed, 46 insertions(+), 28 deletions(-) diff --git a/include/openmc/cell.h b/include/openmc/cell.h index d8de483867..21ba3ddcd4 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -31,11 +31,6 @@ enum class Fill { LATTICE }; -enum class UniverseType { - CSG, - DAG -}; - // TODO: Convert to enum constexpr int32_t OP_LEFT_PAREN {std::numeric_limits::max()}; constexpr int32_t OP_RIGHT_PAREN {std::numeric_limits::max() - 1}; @@ -78,7 +73,7 @@ public: BoundingBox bounding_box() const; - UniverseType type_ = UniverseType::CSG; + GeometryType type_ = GeometryType::CSG; unique_ptr partitioner_; }; @@ -178,8 +173,6 @@ public: //! \param[in] name Cell name void set_name(const std::string& name) { name_ = name; }; - - //! Get all cell instances contained by this cell //! \return Map with cell indexes as keys and instances as values std::unordered_map> get_contained_cells() const; @@ -195,10 +188,11 @@ public: int32_t id_; //!< Unique ID std::string name_; //!< User-defined name - Fill type_; //!< Material, universe, or lattice + Fill type_; //!< Material, universe, or lattice int32_t universe_; //!< Universe # this cell is in int32_t fill_; //!< Universe # filling this cell int32_t n_instances_{0}; //!< Number of instances of this cell + GeometryType geom_type_; //!< Geometric representation type (CSG, DAGMC) //! \brief Index corresponding to this cell in distribcell arrays int distribcell_index_{C_NONE}; diff --git a/include/openmc/surface.h b/include/openmc/surface.h index 8b4e416052..28590b4493 100644 --- a/include/openmc/surface.h +++ b/include/openmc/surface.h @@ -30,7 +30,16 @@ namespace model { } // namespace model //============================================================================== -//! Coordinates for an axis-aligned cuboid bounding a geometric object. +// Constants +//============================================================================== + +enum class GeometryType { + CSG, + DAG +}; + +//============================================================================== +//! Coordinates for an axis-aligned cube that bounds a geometric object. //============================================================================== struct BoundingBox @@ -166,7 +175,7 @@ public: Direction normal(Position r) const; Direction reflect(Position r, Direction u, Particle* p) const; - void to_hdf5_inner(hid_t group_id) const override; + inline void to_hdf5_inner(hid_t group_id) const override {}; std::shared_ptr dagmc_ptr_; //!< Pointer to DagMC instance int32_t dag_index_; //!< DagMC index of surface diff --git a/src/cell.cpp b/src/cell.cpp index 10c1669cba..c5d53dda4a 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -195,10 +195,10 @@ Universe::to_hdf5(hid_t universes_group) const auto group = create_group(universes_group, fmt::format("universe {}", id_)); switch(type_) { - case UniverseType::CSG : + case GeometryType::CSG : write_string(group, "geom_type", "csg", false); break; - case UniverseType::DAG : + case GeometryType::DAG : write_string(group, "geom_type", "dagmc", false); break; } @@ -355,10 +355,15 @@ Cell::to_hdf5(hid_t cell_group) const { // CSGCell implementation //============================================================================== -CSGCell::CSGCell() {} // empty constructor +// default constructor +CSGCell::CSGCell() { + geom_type_ = GeometryType::CSG; +} CSGCell::CSGCell(pugi::xml_node cell_node) { + geom_type_ = GeometryType::CSG; + if (check_for_node(cell_node, "id")) { id_ = std::stoi(get_node_value(cell_node, "id")); } else { @@ -800,7 +805,10 @@ CSGCell::contains_complex(Position r, Direction u, int32_t on_surface) const // DAGMC Cell implementation //============================================================================== #ifdef DAGMC -DAGCell::DAGCell() : Cell{} { simple_ = true; }; +DAGCell::DAGCell() : Cell{} { + geom_type_ = GeometryType::DAG; + simple_ = true; +}; std::pair DAGCell::distance(Position r, Direction u, int32_t on_surface, Particle* p) const diff --git a/src/dagmc.cpp b/src/dagmc.cpp index e0bc322eea..97398374c0 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -241,7 +241,7 @@ DAGUniverse::DAGUniverse(const std::string& filename, bool auto_ids) } void DAGUniverse::initialize() { - type_ = UniverseType::DAG; + type_ = GeometryType::DAG; // determine the next cell id int32_t next_cell_id = 0; diff --git a/src/surface.cpp b/src/surface.cpp index c2c20d0bfa..92e50a76bb 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -203,12 +203,17 @@ Surface::to_hdf5(hid_t group_id) const { hid_t surf_group = create_group(group_id, fmt::format("surface {}", id_)); - write_string(surf_group, "geom_type", "csg", false); + if (geom_type_ == GeometryType::DAG) { + write_string(surf_group, "geom_type", "dagmc", false); + } + else if (geom_type_ == GeometryType::CSG) { + write_string(surf_group, "geom_type", "csg", false); - if (bc_) { - write_string(surf_group, "boundary_type", bc_->type(), false); - } else { - write_string(surf_group, "boundary_type", "transmission", false); + if (bc_) { + write_string(surf_group, "boundary_type", bc_->type(), false); + } else { + write_string(surf_group, "boundary_type", "transmission", false); + } } if (!name_.empty()) { @@ -220,14 +225,20 @@ Surface::to_hdf5(hid_t group_id) const close_group(surf_group); } -CSGSurface::CSGSurface() : Surface{} {}; -CSGSurface::CSGSurface(pugi::xml_node surf_node) : Surface{surf_node} {}; +CSGSurface::CSGSurface() : Surface{} { + geom_type_ = GeometryType::CSG; +}; +CSGSurface::CSGSurface(pugi::xml_node surf_node) : Surface{surf_node} { + geom_type_ = GeometryType::CSG; +}; //============================================================================== // DAGSurface implementation //============================================================================== #ifdef DAGMC -DAGSurface::DAGSurface() : Surface{} {} // empty constructor +DAGSurface::DAGSurface() : Surface{} { + geom_type_ = GeometryType::DAG; +} // empty constructor double DAGSurface::evaluate(Position r) const { @@ -274,10 +285,6 @@ Direction DAGSurface::reflect(Position r, Direction u, Particle* p) const return p->last_dir(); } -void DAGSurface::to_hdf5_inner(hid_t group_id) const { - write_string(group_id, "geom_type", "dagmc", false); -} - #endif //==============================================================================