From 05ea9ea585baca72ff80326713a31352bc748f83 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Sat, 17 Oct 2020 20:34:41 -0600 Subject: [PATCH] Move reflective/white BCs to a new class --- CMakeLists.txt | 1 + include/openmc/particle.h | 2 +- include/openmc/surface.h | 2 ++ src/boundary_condition.cpp | 29 +++++++++++++++++++++++++++++ src/particle.cpp | 14 ++++---------- src/surface.cpp | 2 ++ 6 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 src/boundary_condition.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a59e6f7e3a..5e99b6151e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -225,6 +225,7 @@ target_compile_options(faddeeva PRIVATE ${cxxflags}) list(APPEND libopenmc_SOURCES src/bank.cpp + src/boundary_condition.cpp src/bremsstrahlung.cpp src/dagmc.cpp src/cell.cpp diff --git a/include/openmc/particle.h b/include/openmc/particle.h index 9168dd6e0a..48570c4ea9 100644 --- a/include/openmc/particle.h +++ b/include/openmc/particle.h @@ -244,7 +244,7 @@ public: void cross_vacuum_bc(const Surface& surf); //! Cross a reflective boundary condition. - void cross_reflective_bc(const Surface& surf); + void cross_reflective_bc(const Surface& surf, Direction new_u); //! Cross a periodic boundary condition. void cross_periodic_bc(const Surface& surf); diff --git a/include/openmc/surface.h b/include/openmc/surface.h index cef5f4f880..010d9dfa28 100644 --- a/include/openmc/surface.h +++ b/include/openmc/surface.h @@ -10,6 +10,7 @@ #include "hdf5.h" #include "pugixml.hpp" +#include "openmc/boundary_condition.h" #include "openmc/constants.h" #include "openmc/particle.h" #include "openmc/position.h" @@ -95,6 +96,7 @@ public: int id_; //!< Unique ID BoundaryType bc_; //!< Boundary condition + std::shared_ptr new_bc_ {nullptr}; std::string name_; //!< User-defined name explicit Surface(pugi::xml_node surf_node); diff --git a/src/boundary_condition.cpp b/src/boundary_condition.cpp new file mode 100644 index 0000000000..d9c463ca09 --- /dev/null +++ b/src/boundary_condition.cpp @@ -0,0 +1,29 @@ +#include "openmc/boundary_condition.h" +#include "openmc/surface.h" + +namespace openmc { + +void +ReflectiveBC::handle_particle(Particle& p, const Surface& surf) const +{ + Direction u = surf.reflect(p.r(), p.u(), &p); + u /= u.norm(); + + p.cross_reflective_bc(surf, u); +} + +void +WhiteBC::handle_particle(Particle& p, const Surface& surf) const +{ + Direction u = surf.diffuse_reflect(p.r(), p.u(), p.current_seed()); + u /= u.norm(); + + p.cross_reflective_bc(surf, u); +} + +//void +//PeriodicBC::handle_particle(Particle& p, const Surface& surf) const +//{ +//} + +} // namespace openmc diff --git a/src/particle.cpp b/src/particle.cpp index 2097ba0da3..ba68ce2eb8 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -414,8 +414,6 @@ Particle::cross_surface() } if (surf->bc_ == Surface::BoundaryType::VACUUM && (settings::run_mode != RunMode::PLOTTING)) { - // ======================================================================= - // PARTICLE LEAKS OUT OF PROBLEM cross_vacuum_bc(*surf); @@ -425,7 +423,7 @@ Particle::cross_surface() surf->bc_ == Surface::BoundaryType::WHITE) && (settings::run_mode != RunMode::PLOTTING)) { - cross_reflective_bc(*surf); + surf->new_bc_->handle_particle(*this, *surf); return; @@ -515,7 +513,7 @@ Particle::cross_vacuum_bc(const Surface& surf) } void -Particle::cross_reflective_bc(const Surface& surf) +Particle::cross_reflective_bc(const Surface& surf, Direction new_u) { // Do not handle reflective boundary conditions on lower universes if (n_coord_ != 1) { @@ -542,12 +540,8 @@ Particle::cross_reflective_bc(const Surface& surf) this->r() = r; } - Direction u = (surf.bc_ == Surface::BoundaryType::REFLECT) ? - surf.reflect(this->r(), this->u(), this) : - surf.diffuse_reflect(this->r(), this->u(), this->current_seed()); - - // Make sure new particle direction is normalized - this->u() = u / u.norm(); + // Set the new particle direction + this->u() = new_u; // Reassign particle's cell and surface coord_[0].cell = cell_last_[n_coord_last_ - 1]; diff --git a/src/surface.cpp b/src/surface.cpp index f2faa3efee..6296e128b4 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -134,8 +134,10 @@ Surface::Surface(pugi::xml_node surf_node) } else if (surf_bc == "reflective" || surf_bc == "reflect" || surf_bc == "reflecting") { bc_ = BoundaryType::REFLECT; + new_bc_ = std::make_shared(); } else if (surf_bc == "white") { bc_ = BoundaryType::WHITE; + new_bc_ = std::make_shared(); } else if (surf_bc == "periodic") { bc_ = BoundaryType::PERIODIC; } else {