Relying on the same enum to describe the Geometry type of different classes.

This commit is contained in:
Patrick Shriwise 2020-11-06 10:56:59 -06:00
parent 4b5aa24a1e
commit 956cf08481
5 changed files with 46 additions and 28 deletions

View file

@ -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<int32_t>::max()};
constexpr int32_t OP_RIGHT_PAREN {std::numeric_limits<int32_t>::max() - 1};
@ -78,7 +73,7 @@ public:
BoundingBox bounding_box() const;
UniverseType type_ = UniverseType::CSG;
GeometryType type_ = GeometryType::CSG;
unique_ptr<UniversePartitioner> 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<int32_t, vector<int32_t>> 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};

View file

@ -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<moab::DagMC> dagmc_ptr_; //!< Pointer to DagMC instance
int32_t dag_index_; //!< DagMC index of surface

View file

@ -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<double, int32_t>
DAGCell::distance(Position r, Direction u, int32_t on_surface, Particle* p) const

View file

@ -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;

View file

@ -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
//==============================================================================