From 008a73fa361308987e7141dcdb98be327bbc5b2d Mon Sep 17 00:00:00 2001 From: aprilnovak Date: Thu, 15 Oct 2020 17:18:32 -0500 Subject: [PATCH] Move n_bins and n_surface_bins implementations to StructuredMesh base class. Refs #1695 --- include/openmc/mesh.h | 12 ++++-------- src/mesh.cpp | 32 ++++++++++---------------------- 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index 98f0e7a83..f3f84ac6b 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -107,6 +107,10 @@ public: int get_bin(Position r) const override; + int n_bins() const override; + + int n_surface_bins() const override; + //! Get bin given mesh indices // //! \param[in] Array of mesh indices @@ -175,10 +179,6 @@ public: int get_index_in_direction(double r, int i) const override; - int n_bins() const override; - - int n_surface_bins() const override; - std::pair, std::vector> plot(Position plot_ll, Position plot_ur) const override; @@ -217,10 +217,6 @@ public: int get_index_in_direction(double r, int i) const override; - int n_bins() const override; - - int n_surface_bins() const override; - std::pair, std::vector> plot(Position plot_ll, Position plot_ur) const override; diff --git a/src/mesh.cpp b/src/mesh.cpp index 68a116e3a..ca7eb53ab 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -152,6 +152,16 @@ int StructuredMesh::get_bin(Position r) const return get_bin_from_indices(ijk.data()); } +int StructuredMesh::n_bins() const +{ + return xt::prod(shape_)(); +} + +int StructuredMesh::n_surface_bins() const +{ + return 4 * n_dimension_ * n_bins(); +} + bool StructuredMesh::intersects(Position& r0, Position r1, int* ijk) const { switch(n_dimension_) { @@ -486,18 +496,6 @@ int RegularMesh::get_index_in_direction(double r, int i) const return std::ceil((r - lower_left_[i]) / width_[i]); } -int RegularMesh::n_bins() const -{ - int n_bins = 1; - for (auto dim : shape_) n_bins *= dim; - return n_bins; -} - -int RegularMesh::n_surface_bins() const -{ - return 4 * n_dimension_ * n_bins(); -} - void RegularMesh::bins_crossed(const Particle& p, std::vector& bins, std::vector& lengths) const { @@ -1167,16 +1165,6 @@ int RectilinearMesh::get_index_in_direction(double r, int i) const return lower_bound_index(grid_[i].begin(), grid_[i].end(), r) + 1; } -int RectilinearMesh::n_bins() const -{ - return xt::prod(shape_)(); -} - -int RectilinearMesh::n_surface_bins() const -{ - return 4 * n_dimension_ * n_bins(); -} - std::pair, std::vector> RectilinearMesh::plot(Position plot_ll, Position plot_ur) const {