From 593a4addcfe07fdb403d120a971608ddbe51922f Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Sun, 18 Oct 2020 12:33:36 -0600 Subject: [PATCH] Remove the old Surface::bc_ attribute --- include/openmc/boundary_condition.h | 16 ++++++---- include/openmc/surface.h | 16 ++-------- src/particle.cpp | 4 +-- src/surface.cpp | 48 +++++++++-------------------- 4 files changed, 29 insertions(+), 55 deletions(-) diff --git a/include/openmc/boundary_condition.h b/include/openmc/boundary_condition.h index 3dfc2fc747..7524856c46 100644 --- a/include/openmc/boundary_condition.h +++ b/include/openmc/boundary_condition.h @@ -9,12 +9,6 @@ namespace openmc { // Global variables //============================================================================== -//class BoundaryCondition; -// -//namespace model { -// extern std::vector> boundary_conditions; -//} // namespace model - class Particle; class Surface; @@ -23,6 +17,8 @@ class BoundaryCondition public: virtual void handle_particle(Particle& p, const Surface& surf) const = 0; + + virtual std::string type() const = 0; }; class VacuumBC : public BoundaryCondition @@ -30,6 +26,8 @@ class VacuumBC : public BoundaryCondition public: void handle_particle(Particle& p, const Surface& surf) const override; + + std::string type() const override {return "vacuum";} }; class ReflectiveBC : public BoundaryCondition @@ -37,6 +35,8 @@ class ReflectiveBC : public BoundaryCondition public: void handle_particle(Particle& p, const Surface& surf) const override; + + std::string type() const override {return "reflective";} }; class WhiteBC : public BoundaryCondition @@ -44,6 +44,8 @@ class WhiteBC : public BoundaryCondition public: void handle_particle(Particle& p, const Surface& surf) const override; + + std::string type() const override {return "white";} }; class PeriodicBC : public BoundaryCondition @@ -53,6 +55,8 @@ public: : i_surf_(i_surf), j_surf_(j_surf) {}; + std::string type() const override {return "periodic";} + protected: int i_surf_; int j_surf_; diff --git a/include/openmc/surface.h b/include/openmc/surface.h index 14fbe047b0..1e16c4919b 100644 --- a/include/openmc/surface.h +++ b/include/openmc/surface.h @@ -85,19 +85,9 @@ class Surface { public: - // Types of available boundary conditions on a surface - enum class BoundaryType { - TRANSMIT, - VACUUM, - REFLECT, - PERIODIC, - WHITE - }; - - int id_; //!< Unique ID - BoundaryType bc_; //!< Boundary condition - std::shared_ptr new_bc_ {nullptr}; - std::string name_; //!< User-defined name + int id_; //!< Unique ID + std::string name_; //!< User-defined name + std::shared_ptr bc_ {nullptr}; //!< Boundary condition explicit Surface(pugi::xml_node surf_node); Surface(); diff --git a/src/particle.cpp b/src/particle.cpp index b2e4013502..b2902238d7 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -414,8 +414,8 @@ Particle::cross_surface() } // Handle any applicable boundary conditions. - if (surf->new_bc_ && settings::run_mode != RunMode::PLOTTING) { - surf->new_bc_->handle_particle(*this, *surf); + if (surf->bc_ && settings::run_mode != RunMode::PLOTTING) { + surf->bc_->handle_particle(*this, *surf); return; } diff --git a/src/surface.cpp b/src/surface.cpp index 5eba9d2100..af3b0aa371 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -126,28 +126,20 @@ Surface::Surface(pugi::xml_node surf_node) std::string surf_bc = get_node_value(surf_node, "boundary", true, true); if (surf_bc == "transmission" || surf_bc == "transmit" ||surf_bc.empty()) { - bc_ = BoundaryType::TRANSMIT; - + // Leave the bc_ a nullptr } else if (surf_bc == "vacuum") { - bc_ = BoundaryType::VACUUM; - new_bc_ = std::make_shared(); - + bc_ = std::make_shared(); } else if (surf_bc == "reflective" || surf_bc == "reflect" || surf_bc == "reflecting") { - bc_ = BoundaryType::REFLECT; - new_bc_ = std::make_shared(); + bc_ = std::make_shared(); } else if (surf_bc == "white") { - bc_ = BoundaryType::WHITE; - new_bc_ = std::make_shared(); + bc_ = std::make_shared(); } else if (surf_bc == "periodic") { - bc_ = BoundaryType::PERIODIC; + // periodic BC's are handled separately } else { fatal_error(fmt::format("Unknown boundary condition \"{}\" specified " "on surface {}", surf_bc, id_)); } - - } else { - bc_ = BoundaryType::TRANSMIT; } } @@ -212,22 +204,10 @@ CSGSurface::to_hdf5(hid_t group_id) const hid_t surf_group = create_group(group_id, group_name); - switch(bc_) { - case BoundaryType::TRANSMIT : - write_string(surf_group, "boundary_type", "transmission", false); - break; - case BoundaryType::VACUUM : - write_string(surf_group, "boundary_type", "vacuum", false); - break; - case BoundaryType::REFLECT : - write_string(surf_group, "boundary_type", "reflective", false); - break; - case BoundaryType::WHITE : - write_string(surf_group, "boundary_type", "white", false); - break; - case BoundaryType::PERIODIC : - write_string(surf_group, "boundary_type", "periodic", false); - break; + if (bc_) { + write_string(surf_group, "boundary_type", bc_->type(), false); + } else { + write_string(surf_group, "boundary_type", "transmission", false); } if (!name_.empty()) { @@ -1173,11 +1153,11 @@ void read_surfaces(pugi::xml_node node) double dot_prod = norm1.dot(norm2); if (std::abs(1.0 - dot_prod) < FP_PRECISION) { - surf1.new_bc_ = std::make_shared(i_surf, j_surf); - surf2.new_bc_ = surf1.new_bc_; + surf1.bc_ = std::make_shared(i_surf, j_surf); + surf2.bc_ = surf1.bc_; } else { - surf1.new_bc_ = std::make_shared(i_surf, j_surf); - surf2.new_bc_ = surf1.new_bc_; + surf1.bc_ = std::make_shared(i_surf, j_surf); + surf2.bc_ = surf1.bc_; } } @@ -1185,7 +1165,7 @@ void read_surfaces(pugi::xml_node node) // surface bool boundary_exists = false; for (const auto& surf : model::surfaces) { - if (surf->bc_ != Surface::BoundaryType::TRANSMIT) { + if (surf->bc_) { boundary_exists = true; break; }