From 9874004e946527969fc5b683f64fd5839804ae98 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 1 Apr 2021 23:27:56 -0500 Subject: [PATCH] Moving the DAGMC surface implementation into the DAGMC files as well. --- include/openmc/dagmc.h | 16 ++++++++++++ include/openmc/surface.h | 21 --------------- src/dagmc.cpp | 51 +++++++++++++++++++++++++++++++++++++ src/surface.cpp | 55 ---------------------------------------- 4 files changed, 67 insertions(+), 76 deletions(-) diff --git a/include/openmc/dagmc.h b/include/openmc/dagmc.h index 1dc1c2bc37..c062467c4a 100644 --- a/include/openmc/dagmc.h +++ b/include/openmc/dagmc.h @@ -19,6 +19,22 @@ class UWUW; namespace openmc { +class DAGSurface : public Surface +{ +public: + DAGSurface(); + + double evaluate(Position r) const; + double distance(Position r, Direction u, bool coincident) const; + Direction normal(Position r) const; + Direction reflect(Position r, Direction u, Particle* p) const; + + 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 +}; + class DAGCell : public Cell { public: DAGCell(); diff --git a/include/openmc/surface.h b/include/openmc/surface.h index 2bebdc8ce6..d29bbee086 100644 --- a/include/openmc/surface.h +++ b/include/openmc/surface.h @@ -154,27 +154,6 @@ protected: virtual void to_hdf5_inner(hid_t group_id) const = 0; }; -//============================================================================== -//! A `Surface` representing a DAGMC-based surface in DAGMC. -//============================================================================== -#ifdef DAGMC -class DAGSurface : public Surface -{ -public: - DAGSurface(); - - double evaluate(Position r) const; - double distance(Position r, Direction u, bool coincident) const; - Direction normal(Position r) const; - Direction reflect(Position r, Direction u, Particle* p) const; - - 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 -}; -#endif - //============================================================================== //! A plane perpendicular to the x-axis. // diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 10d620d7d0..6a81ebd5f7 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -578,6 +578,57 @@ int32_t next_cell(DAGUniverse* dag_univ, DAGCell* cur_cell, DAGSurface* surf_xed return cur_cell->dagmc_ptr_->index_by_handle(new_vol) + dag_univ->cell_idx_offset_; } +//============================================================================== +// DAGSurface implementation +//============================================================================== +DAGSurface::DAGSurface() : Surface{} { + geom_type_ = GeometryType::DAG; +} // empty constructor + +double DAGSurface::evaluate(Position r) const +{ + return 0.0; +} + +double +DAGSurface::distance(Position r, Direction u, bool coincident) const +{ + moab::ErrorCode rval; + moab::EntityHandle surf = dagmc_ptr_->entity_by_index(2, dag_index_); + moab::EntityHandle hit_surf; + double dist; + double pnt[3] = {r.x, r.y, r.z}; + double dir[3] = {u.x, u.y, u.z}; + rval = dagmc_ptr_->ray_fire(surf, pnt, dir, hit_surf, dist, NULL, 0, 0); + MB_CHK_ERR_CONT(rval); + if (dist < 0.0) dist = INFTY; + return dist; +} + +Direction DAGSurface::normal(Position r) const +{ + moab::ErrorCode rval; + moab::EntityHandle surf = dagmc_ptr_->entity_by_index(2, dag_index_); + double pnt[3] = {r.x, r.y, r.z}; + double dir[3]; + rval = dagmc_ptr_->get_angle(surf, pnt, dir); + MB_CHK_ERR_CONT(rval); + return dir; +} + +Direction DAGSurface::reflect(Position r, Direction u, Particle* p) const +{ + Expects(p); + p->history_.reset_to_last_intersection(); + moab::ErrorCode rval; + moab::EntityHandle surf = dagmc_ptr_->entity_by_index(2, dag_index_); + double pnt[3] = {r.x, r.y, r.z}; + double dir[3]; + rval = dagmc_ptr_->get_angle(surf, pnt, dir, &p->history_); + MB_CHK_ERR_CONT(rval); + p->last_dir_ = u.reflect(dir); + return p->last_dir_; +} } #endif diff --git a/src/surface.cpp b/src/surface.cpp index 92e50a76bb..e0b88d24a5 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -232,61 +232,6 @@ CSGSurface::CSGSurface(pugi::xml_node surf_node) : Surface{surf_node} { geom_type_ = GeometryType::CSG; }; -//============================================================================== -// DAGSurface implementation -//============================================================================== -#ifdef DAGMC -DAGSurface::DAGSurface() : Surface{} { - geom_type_ = GeometryType::DAG; -} // empty constructor - -double DAGSurface::evaluate(Position r) const -{ - return 0.0; -} - -double -DAGSurface::distance(Position r, Direction u, bool coincident) const -{ - moab::ErrorCode rval; - moab::EntityHandle surf = dagmc_ptr_->entity_by_index(2, dag_index_); - moab::EntityHandle hit_surf; - double dist; - double pnt[3] = {r.x, r.y, r.z}; - double dir[3] = {u.x, u.y, u.z}; - rval = dagmc_ptr_->ray_fire(surf, pnt, dir, hit_surf, dist, NULL, 0, 0); - MB_CHK_ERR_CONT(rval); - if (dist < 0.0) dist = INFTY; - return dist; -} - -Direction DAGSurface::normal(Position r) const -{ - moab::ErrorCode rval; - moab::EntityHandle surf = dagmc_ptr_->entity_by_index(2, dag_index_); - double pnt[3] = {r.x, r.y, r.z}; - double dir[3]; - rval = dagmc_ptr_->get_angle(surf, pnt, dir); - MB_CHK_ERR_CONT(rval); - return dir; -} - -Direction DAGSurface::reflect(Position r, Direction u, Particle* p) const -{ - Expects(p); - p->history().reset_to_last_intersection(); - moab::ErrorCode rval; - moab::EntityHandle surf = dagmc_ptr_->entity_by_index(2, dag_index_); - double pnt[3] = {r.x, r.y, r.z}; - double dir[3]; - rval = dagmc_ptr_->get_angle(surf, pnt, dir, &p->history()); - MB_CHK_ERR_CONT(rval); - p->last_dir() = u.reflect(dir); - return p->last_dir(); -} - -#endif - //============================================================================== // Generic functions for x-, y-, and z-, planes. //==============================================================================