Move implementation of get_indices_from_bin to StructuredMesh base class. Refs #1695

This commit is contained in:
aprilnovak 2020-10-15 16:26:36 -05:00
parent 7d0838d27b
commit 45b7dfb5a0
2 changed files with 15 additions and 26 deletions

View file

@ -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;

View file

@ -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_)();