From 45b7dfb5a03b0e48620a7c1ac376e2dce57fca84 Mon Sep 17 00:00:00 2001 From: aprilnovak Date: Thu, 15 Oct 2020 16:26:36 -0500 Subject: [PATCH] Move implementation of get_indices_from_bin to StructuredMesh base class. Refs #1695 --- include/openmc/mesh.h | 6 +----- src/mesh.cpp | 35 ++++++++++++++--------------------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index cfcc137e8..9f1b80c03 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -122,7 +122,7 @@ public: // //! \param[in] bin Mesh bin //! \param[out] ijk Mesh indices - virtual void get_indices_from_bin(int bin, int* ijk) const = 0; + virtual void get_indices_from_bin(int bin, int* ijk) const; //! Get mesh index in a particular direction //! @@ -160,8 +160,6 @@ public: int get_bin(Position r) const override; - void get_indices_from_bin(int bin, int* ijk) const override; - int get_index_in_direction(Position r, int i) const override; int n_bins() const override; @@ -219,8 +217,6 @@ public: int get_bin(Position r) const override; - void get_indices_from_bin(int bin, int* ijk) const override; - int get_index_in_direction(Position r, int i) const override; int n_bins() const override; diff --git a/src/mesh.cpp b/src/mesh.cpp index fd5b30466..17a87c47d 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -126,6 +126,20 @@ int StructuredMesh::get_bin_from_indices(const int* ijk) const } } +void StructuredMesh::get_indices_from_bin(int bin, int* ijk) const +{ + if (n_dimension_ == 1) { + ijk[0] = bin + 1; + } else if (n_dimension_ == 2) { + ijk[0] = bin % shape_[0] + 1; + ijk[1] = bin / shape_[0] + 1; + } else if (n_dimension_ == 3) { + ijk[0] = bin % shape_[0] + 1; + ijk[1] = (bin % (shape_[0] * shape_[1])) / shape_[0] + 1; + ijk[2] = bin / (shape_[0] * shape_[1]) + 1; + } +} + //============================================================================== // RegularMesh implementation //============================================================================== @@ -228,20 +242,6 @@ int RegularMesh::get_index_in_direction(Position r, int i) const return std::ceil((r[i] - lower_left_[i]) / width_[i]); } -void RegularMesh::get_indices_from_bin(int bin, int* ijk) const -{ - if (n_dimension_ == 1) { - ijk[0] = bin + 1; - } else if (n_dimension_ == 2) { - ijk[0] = bin % shape_[0] + 1; - ijk[1] = bin / shape_[0] + 1; - } else if (n_dimension_ == 3) { - ijk[0] = bin % shape_[0] + 1; - ijk[1] = (bin % (shape_[0] * shape_[1])) / shape_[0] + 1; - ijk[2] = bin / (shape_[0] * shape_[1]) + 1; - } -} - int RegularMesh::n_bins() const { int n_bins = 1; @@ -1178,13 +1178,6 @@ int RectilinearMesh::get_index_in_direction(Position r, int i) const return lower_bound_index(grid_[i].begin(), grid_[i].end(), r[i]) + 1; } -void RectilinearMesh::get_indices_from_bin(int bin, int* ijk) const -{ - ijk[0] = bin % shape_[0] + 1; - ijk[1] = (bin % (shape_[0] * shape_[1])) / shape_[0] + 1; - ijk[2] = bin / (shape_[0] * shape_[1]) + 1; -} - int RectilinearMesh::n_bins() const { return xt::prod(shape_)();