From 1af80b1d39abec972fb25818a2cc8674c73b490c Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Mon, 26 Oct 2020 21:31:26 -0600 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Paul Romano --- include/openmc/boundary_condition.h | 23 ++++++++--------------- src/boundary_condition.cpp | 18 ++++++++++-------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/include/openmc/boundary_condition.h b/include/openmc/boundary_condition.h index d40c645695..c03e19e50f 100644 --- a/include/openmc/boundary_condition.h +++ b/include/openmc/boundary_condition.h @@ -13,13 +13,12 @@ class Surface; //! A class that tells particles what to do after they strike an outer boundary. //============================================================================== -class BoundaryCondition -{ +class BoundaryCondition { public: //! Perform tracking operations for a particle that strikes the boundary. //! \param p The particle that struck the boundary. This class is not meant //! to directly modify anything about the particle, but it will do so - //! indirectly by calling the particle's appropriate cross*bc function. + //! indirectly by calling the particle's appropriate cross_*_bc function. //! \param surf The specific surface on the boundary the particle struck. virtual void handle_particle(Particle& p, const Surface& surf) const = 0; @@ -32,8 +31,7 @@ public: //! A BC that kills particles, indicating they left the problem. //============================================================================== -class VacuumBC : public BoundaryCondition -{ +class VacuumBC : public BoundaryCondition { public: void handle_particle(Particle& p, const Surface& surf) const override; @@ -45,8 +43,7 @@ public: //! A BC that returns particles via specular reflection. //============================================================================== -class ReflectiveBC : public BoundaryCondition -{ +class ReflectiveBC : public BoundaryCondition { public: void handle_particle(Particle& p, const Surface& surf) const override; @@ -58,8 +55,7 @@ public: //! A BC that returns particles via diffuse reflection. //============================================================================== -class WhiteBC : public BoundaryCondition -{ +class WhiteBC : public BoundaryCondition { public: void handle_particle(Particle& p, const Surface& surf) const override; @@ -71,8 +67,7 @@ public: //! A BC that moves particles to another part of the problem. //============================================================================== -class PeriodicBC : public BoundaryCondition -{ +class PeriodicBC : public BoundaryCondition { public: PeriodicBC(int i_surf, int j_surf) : i_surf_(i_surf), j_surf_(j_surf) @@ -89,8 +84,7 @@ protected: //! A BC that moves particles to another part of the problem without rotation. //============================================================================== -class TranslationalPeriodicBC : public PeriodicBC -{ +class TranslationalPeriodicBC : public PeriodicBC { public: TranslationalPeriodicBC(int i_surf, int j_surf); @@ -108,8 +102,7 @@ protected: //! Currently only rotations about the z-axis are supported. //============================================================================== -class RotationalPeriodicBC : public PeriodicBC -{ +class RotationalPeriodicBC : public PeriodicBC { public: RotationalPeriodicBC(int i_surf, int j_surf); diff --git a/src/boundary_condition.cpp b/src/boundary_condition.cpp index 67496187f6..bc01c21994 100644 --- a/src/boundary_condition.cpp +++ b/src/boundary_condition.cpp @@ -190,12 +190,12 @@ RotationalPeriodicBC::RotationalPeriodicBC(int i_surf, int j_surf) // Make sure both surfaces intersect the origin if (std::abs(surf1.evaluate({0, 0, 0})) > FP_COINCIDENT) { throw std::invalid_argument(fmt::format("Rotational periodic BCs are only " - "supported for rotations about the origin, but surface{} does not " + "supported for rotations about the origin, but surface {} does not " "intersect the origin.", surf1.id_)); } if (std::abs(surf2.evaluate({0, 0, 0})) > FP_COINCIDENT) { throw std::invalid_argument(fmt::format("Rotational periodic BCs are only " - "supported for rotations about the origin, but surface{} does not " + "supported for rotations about the origin, but surface {} does not " "intersect the origin.", surf2.id_)); } @@ -253,14 +253,16 @@ RotationalPeriodicBC::handle_particle(Particle& p, const Surface& surf) const // Rotate the particle's position and direction about the z-axis. Position r = p.r(); Direction u = p.u(); + double cos_theta = std::cos(theta); + double sin_theta = std::sin(theta); Position new_r = { - std::cos(theta)*r[0] - std::sin(theta)*r[1], - std::sin(theta)*r[0] + std::cos(theta)*r[1], - r[2]}; + cos_theta*r.x - sin_theta*r.y, + sin_theta*r.x + cos_theta*r.y, + r.z}; Direction new_u = { - std::cos(theta)*u[0] - std::sin(theta)*u[1], - std::sin(theta)*u[0] + std::cos(theta)*u[1], - u[2]}; + cos_theta*u.x - sin_theta*u.y, + sin_theta*u.x + cos_theta*u.y, + u.z}; // Pass the new location, direction, and surface to the particle. p.cross_periodic_bc(surf, new_r, new_u, new_surface);