Move reflective/white BCs to a new class

This commit is contained in:
Sterling Harper 2020-10-17 20:34:41 -06:00
parent 0f214eb130
commit 05ea9ea585
6 changed files with 39 additions and 11 deletions

View file

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

View file

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

View file

@ -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<BoundaryCondition> new_bc_ {nullptr};
std::string name_; //!< User-defined name
explicit Surface(pugi::xml_node surf_node);

View file

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

View file

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

View file

@ -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<ReflectiveBC>();
} else if (surf_bc == "white") {
bc_ = BoundaryType::WHITE;
new_bc_ = std::make_shared<WhiteBC>();
} else if (surf_bc == "periodic") {
bc_ = BoundaryType::PERIODIC;
} else {