From 9a36ea405aeeed940152882199219cdf6a35207c Mon Sep 17 00:00:00 2001 From: aprilnovak Date: Thu, 15 Oct 2020 17:14:32 -0500 Subject: [PATCH] Move get_bin implementation up to StructuredMesh base class. Refs #1695 --- include/openmc/mesh.h | 10 ++++------ src/mesh.cpp | 36 ++++++++++++------------------------ 2 files changed, 16 insertions(+), 30 deletions(-) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index e619c4370..98f0e7a83 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -105,6 +105,8 @@ public: StructuredMesh(pugi::xml_node node) : Mesh {node} {}; virtual ~StructuredMesh() = default; + int get_bin(Position r) const override; + //! Get bin given mesh indices // //! \param[in] Array of mesh indices @@ -171,9 +173,7 @@ public: void surface_bins_crossed(const Particle& p, std::vector& bins) const override; - int get_bin(Position r) const override; - - int get_index_in_direction(Position r, int i) const override; + int get_index_in_direction(double r, int i) const override; int n_bins() const override; @@ -215,9 +215,7 @@ public: void surface_bins_crossed(const Particle& p, std::vector& bins) const override; - int get_bin(Position r) const override; - - int get_index_in_direction(Position r, int i) const override; + int get_index_in_direction(double r, int i) const override; int n_bins() const override; diff --git a/src/mesh.cpp b/src/mesh.cpp index c4158df23..68a116e3a 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -140,6 +140,18 @@ void StructuredMesh::get_indices_from_bin(int bin, int* ijk) const } } +int StructuredMesh::get_bin(Position r) const +{ + // Determine indices + std::vector ijk(n_dimension_); + bool in_mesh; + get_indices(r, ijk.data(), &in_mesh); + if (!in_mesh) return -1; + + // Convert indices to bin + return get_bin_from_indices(ijk.data()); +} + bool StructuredMesh::intersects(Position& r0, Position r1, int* ijk) const { switch(n_dimension_) { @@ -469,18 +481,6 @@ RegularMesh::RegularMesh(pugi::xml_node node) volume_frac_ = 1.0/xt::prod(shape_)(); } -int RegularMesh::get_bin(Position r) const -{ - // Determine indices - std::vector ijk(n_dimension_); - bool in_mesh; - get_indices(r, ijk.data(), &in_mesh); - if (!in_mesh) return -1; - - // Convert indices to bin - return get_bin_from_indices(ijk.data()); -} - int RegularMesh::get_index_in_direction(double r, int i) const { return std::ceil((r - lower_left_[i]) / width_[i]); @@ -1162,18 +1162,6 @@ void RectilinearMesh::surface_bins_crossed(const Particle& p, } } -int RectilinearMesh::get_bin(Position r) const -{ - // Determine indices - int ijk[3]; - bool in_mesh; - get_indices(r, ijk, &in_mesh); - if (!in_mesh) return -1; - - // Convert indices to bin - return get_bin_from_indices(ijk); -} - int RectilinearMesh::get_index_in_direction(double r, int i) const { return lower_bound_index(grid_[i].begin(), grid_[i].end(), r) + 1;