From 1d07f498612987e6740d1b237db8c2afacc2f990 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Sat, 17 Oct 2020 20:59:58 -0600 Subject: [PATCH] Move all BCs to the new BoundaryCondtion class --- include/openmc/particle.h | 3 ++- src/boundary_condition.cpp | 31 +++++++++++++++++++++++++++---- src/particle.cpp | 29 +++++++---------------------- src/surface.cpp | 2 ++ 4 files changed, 38 insertions(+), 27 deletions(-) diff --git a/include/openmc/particle.h b/include/openmc/particle.h index 48570c4ea9..f122455fc7 100644 --- a/include/openmc/particle.h +++ b/include/openmc/particle.h @@ -247,7 +247,8 @@ public: void cross_reflective_bc(const Surface& surf, Direction new_u); //! Cross a periodic boundary condition. - void cross_periodic_bc(const Surface& surf); + void cross_periodic_bc(const Surface& surf, Position new_r, Direction new_u, + int new_surface); //! mark a particle as lost and create a particle restart file //! \param message A warning message to display diff --git a/src/boundary_condition.cpp b/src/boundary_condition.cpp index d9c463ca09..334f40b311 100644 --- a/src/boundary_condition.cpp +++ b/src/boundary_condition.cpp @@ -3,6 +3,12 @@ namespace openmc { +void +VacuumBC::handle_particle(Particle& p, const Surface& surf) const +{ + p.cross_vacuum_bc(surf); +} + void ReflectiveBC::handle_particle(Particle& p, const Surface& surf) const { @@ -21,9 +27,26 @@ WhiteBC::handle_particle(Particle& p, const Surface& surf) const p.cross_reflective_bc(surf, u); } -//void -//PeriodicBC::handle_particle(Particle& p, const Surface& surf) const -//{ -//} +void +PeriodicBC::handle_particle(Particle& p, const Surface& surf) const +{ + // Get a pointer to the partner periodic surface + auto surf_p = dynamic_cast(&surf); + auto other = dynamic_cast( + model::surfaces[surf_p->i_periodic_].get()); + + // Compute the new particle location and direction + Position r {p.r()}; + Direction u {p.u()}; + bool rotational = other->periodic_translate(surf_p, r, u); + + // Pick the particle's new surface + // TODO: off-by-one + int new_surface = rotational ? + surf_p->i_periodic_ + 1 : + ((p.surface_ > 0) ? surf_p->i_periodic_ + 1 : -(surf_p->i_periodic_ + 1)); + + p.cross_periodic_bc(surf, r, u, new_surface); +} } // namespace openmc diff --git a/src/particle.cpp b/src/particle.cpp index ba68ce2eb8..a7532f8c98 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -413,23 +413,9 @@ Particle::cross_surface() write_message(1, " Crossing surface {}", surf->id_); } - if (surf->bc_ == Surface::BoundaryType::VACUUM && (settings::run_mode != RunMode::PLOTTING)) { - - cross_vacuum_bc(*surf); - - return; - - } else if ((surf->bc_ == Surface::BoundaryType::REFLECT || - surf->bc_ == Surface::BoundaryType::WHITE) - && (settings::run_mode != RunMode::PLOTTING)) { - + // Handle any applicable boundary conditions. + if (surf->new_bc_ && settings::run_mode != RunMode::PLOTTING) { surf->new_bc_->handle_particle(*this, *surf); - - return; - - } else if (surf->bc_ == Surface::BoundaryType::PERIODIC && settings::run_mode != RunMode::PLOTTING) { - cross_periodic_bc(*surf); - return; } @@ -570,7 +556,8 @@ Particle::cross_reflective_bc(const Surface& surf, Direction new_u) } void -Particle::cross_periodic_bc(const Surface& surf) +Particle::cross_periodic_bc(const Surface& surf, Position new_r, + Direction new_u, int new_surface) { // Do not handle periodic boundary conditions on lower universes if (n_coord_ != 1) { @@ -596,13 +583,11 @@ Particle::cross_periodic_bc(const Surface& surf) model::surfaces[surf_p->i_periodic_].get()); // Adjust the particle's location and direction. - bool rotational = other->periodic_translate(surf_p, this->r(), this->u()); + r() = new_r; + u() = new_u; // Reassign particle's surface - // TODO: off-by-one - surface_ = rotational ? - surf_p->i_periodic_ + 1 : - ((surface_ > 0) ? surf_p->i_periodic_ + 1 : -(surf_p->i_periodic_ + 1)); + surface_ = new_surface; // Figure out what cell particle is in now n_coord_ = 1; diff --git a/src/surface.cpp b/src/surface.cpp index 6296e128b4..6957c85235 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -130,6 +130,7 @@ Surface::Surface(pugi::xml_node surf_node) } else if (surf_bc == "vacuum") { bc_ = BoundaryType::VACUUM; + new_bc_ = std::make_shared(); } else if (surf_bc == "reflective" || surf_bc == "reflect" || surf_bc == "reflecting") { @@ -140,6 +141,7 @@ Surface::Surface(pugi::xml_node surf_node) new_bc_ = std::make_shared(); } else if (surf_bc == "periodic") { bc_ = BoundaryType::PERIODIC; + new_bc_ = std::make_shared(); } else { fatal_error(fmt::format("Unknown boundary condition \"{}\" specified " "on surface {}", surf_bc, id_));