From 7351773b2957c0f415b5dc8ae8f6bd5a3a00bfdd Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 3 Apr 2019 10:48:06 -0500 Subject: [PATCH] Addressing comments from @paulromano. --- include/openmc/geometry.h | 2 +- src/geometry.cpp | 2 +- src/lattice.cpp | 20 +++++++++++--------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/openmc/geometry.h b/include/openmc/geometry.h index 43b595bc18..39f500b847 100644 --- a/include/openmc/geometry.h +++ b/include/openmc/geometry.h @@ -39,7 +39,7 @@ struct BoundaryInfo { //! Check two distances by coincidence tolerance //============================================================================== -bool coincident(const double& d1, const double& d2); +bool coincident(double d1, double d2); //============================================================================== //! Check for overlapping cells at a particle's position. diff --git a/src/geometry.cpp b/src/geometry.cpp index f4c24bcd5d..225a4970f4 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -32,7 +32,7 @@ std::vector overlap_check_count; // Non-member functions //============================================================================== -bool coincident(const double& d1, const double& d2) { +bool coincident(double d1, double d2) { return std::abs(d1 - d2) < FP_COINCIDENT; } diff --git a/src/lattice.cpp b/src/lattice.cpp index de077bbe69..87ec3c83fd 100644 --- a/src/lattice.cpp +++ b/src/lattice.cpp @@ -6,6 +6,7 @@ #include "openmc/cell.h" #include "openmc/error.h" +#include "openmc/geometry.h" #include "openmc/geometry_aux.h" #include "openmc/hdf5_interface.h" #include "openmc/string_utils.h" @@ -291,7 +292,7 @@ RectLattice::get_indices(Position r, Direction u) const double ix_ {(r.x - lower_left_.x) / pitch_.x}; long ix_close {std::lround(ix_)}; int ix; - if (std::abs(ix_ - ix_close) < FP_COINCIDENT) { + if (coincident(ix_, ix_close)) { ix = (u.x > 0) ? ix_close : ix_close - 1; } else { ix = std::floor(ix_); @@ -301,7 +302,7 @@ RectLattice::get_indices(Position r, Direction u) const double iy_ {(r.y - lower_left_.y) / pitch_.y}; long iy_close {std::lround(iy_)}; int iy; - if (std::abs(iy_ - iy_close) < FP_COINCIDENT) { + if (coincident(iy_, iy_close)) { iy = (u.y > 0) ? iy_close : iy_close - 1; } else { iy = std::floor(iy_); @@ -312,7 +313,7 @@ RectLattice::get_indices(Position r, Direction u) const if (is_3d_) { double iz_ {(r.z - lower_left_.z) / pitch_.z}; long iz_close {std::lround(iz_)}; - if (std::abs(iz_ - iz_close) < FP_COINCIDENT) { + if (coincident(iz_, iz_close)) { iz = (u.z > 0) ? iz_close : iz_close - 1; } else { iz = std::floor(iz_); @@ -711,18 +712,19 @@ std::array HexLattice::get_indices(Position r, Direction u) const { // result variables - int ix{}, ia{}, iz{}; + int ix = 0; + int ia = 0; + int iz = 0; // Offset the xyz by the lattice center. Position r_o {r.x - center_.x, r.y - center_.y, r.z}; if (is_3d_) {r_o.z -= center_.z;} - // Index the z direction. Same as the technique used in - // RectLattice::get_indices. + // Index the z direction, accounting for coincidence if (is_3d_) { double iz_ {r_o.z / pitch_[1] + 0.5 * n_axial_}; long iz_close {std::lround(iz_)}; - if (std::abs(iz_ - iz_close) < FP_COINCIDENT) { + if (coincident(iz_, iz_close)) { iz = (u.z > 0) ? iz_close : iz_close - 1; } else { iz = std::floor(iz_); @@ -769,14 +771,14 @@ HexLattice::get_indices(Position r, Direction u) const // calculate distance double d = r_t.x*r_t.x + r_t.y*r_t.y; // check for coincidence - bool on_boundary = std::abs(d - d_min) < FP_COINCIDENT; + bool on_boundary = coincident(d, d_min); if (d < d_min || on_boundary) { // normalize r_t and find dot product r_t /= std::sqrt(d); double dp = u.x * r_t.x + u.y * r_t.y; // do not update values if particle is on a // boundary and not moving into this cell - if (on_boundary && dp > dp_min) { continue; } + if (on_boundary && dp > dp_min) continue; // update values d_min = d; ix_chg = j;