Skip to content

Commit

Permalink
Keep only one getIJK
Browse files Browse the repository at this point in the history
  • Loading branch information
aritorto committed Sep 30, 2024
1 parent de130b7 commit 266320c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
3 changes: 1 addition & 2 deletions opm/grid/cpgrid/CpGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,7 @@ void CpGrid::computeGlobalCellLgr(const int& level, const std::array<int,3>& sta
// and it's stored in cell_to_idxInParentCell_.
auto idx_in_parent_cell = currentData()[level]-> cell_to_idxInParentCell_[element.index()];
// Find ijk.
std::array<int,3> childIJK = {0,0,0};
currentData()[level]-> getInParentCellIJK(idx_in_parent_cell, cells_per_dim, childIJK);
std::array<int,3> childIJK = currentData()[level]-> getIJK(idx_in_parent_cell, cells_per_dim);
// The corresponding lgrIJK can be computed as follows:
const std::array<int,3>& lgrIJK = { ( (parentIJK[0] - startIJK[0])*cells_per_dim[0] ) + childIJK[0], // Shift parent index according to the startIJK of the LGR.
( (parentIJK[1] - startIJK[1])*cells_per_dim[1] ) + childIJK[1],
Expand Down
3 changes: 1 addition & 2 deletions opm/grid/cpgrid/CpGridData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1713,8 +1713,7 @@ void CpGridData::computeCommunicationInterfaces([[maybe_unused]] int noExistingP
std::array<Dune::FieldVector<double,3>,8> CpGridData::getReferenceRefinedCorners(int idx_in_parent_cell, const std::array<int,3>& cells_per_dim) const
{
// Refined cells in parent cell: k*cells_per_dim[0]*cells_per_dim[1] + j*cells_per_dim[0] + i
std::array<int,3> ijk = {0,0,0};
getInParentCellIJK(idx_in_parent_cell, cells_per_dim, ijk);
std::array<int,3> ijk = getIJK(idx_in_parent_cell, cells_per_dim);

std::array<Dune::FieldVector<double,3>,8> corners_in_parent_reference_elem = { // corner '0'
{{ double(ijk[0])/cells_per_dim[0], double(ijk[1])/cells_per_dim[1], double(ijk[2])/cells_per_dim[2] },
Expand Down
25 changes: 9 additions & 16 deletions opm/grid/cpgrid/CpGridData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,35 +303,28 @@ class CpGridData
/// @param [out] ijk Cartesian index triplet
void getIJK(int c, std::array<int,3>& ijk) const
{
int gc = global_cell_[c];
ijk[0] = gc % logical_cartesian_size_[0]; gc /= logical_cartesian_size_[0];
ijk[1] = gc % logical_cartesian_size_[1];
ijk[2] = gc / logical_cartesian_size_[1];
ijk = getIJK(global_cell_[c], logical_cartesian_size_);
}

/// @brief Extract in-parent-cell Cartesian index triplet (i,j,k) of a refined cell.
/// @brief Extract Cartesian index triplet (i,j,k) given an index between 0 and NXxNYxNZ -1
/// where NX, NY, and NZ is the total amoung of cells in each direction x-,y-,and z- respectively.
///
/// - If refinement has been done via LGRs, there amount of children of each parent cell in each
/// direction (x,y,and z) is given by std::array<int,3> cells_per_dim. In this case, CpGrid::adapt(/* with args */)
/// has been called.
/// - If refinement has been done via adapt() (without arguments) the default amount of children of each parent
/// cell in each direction is cells_per_dim = {2,2,2}.
///
/// @param [in] idx_in_parent_cell Integer between 0 and cells_per_dim[0]*cells_per_dim[1]*cells_per_dim[2]-1
/// (total amount of children of a parent cell minus one since starting index is zero).
/// @param [in] idx Integer between 0 and cells_per_dim[0]*cells_per_dim[1]*cells_per_dim[2]-1
/// @param [in] cells_per_dim
/// @param [out] ijk In-parent-cell Cartesian index triplet
void getInParentCellIJK(int idx_in_parent_cell, const std::array<int,3>& cells_per_dim, std::array<int,3>& ijk) const
/// @return Cartesian index triplet.
std::array<int,3> getIJK(int idx_in_parent_cell, const std::array<int,3>& cells_per_dim) const
{
// idx_in_parent_cell = k*cells_per_dim_[0]*cells_per_dim_[1] + j*cells_per_dim_[0] + i
// idx = k*cells_per_dim_[0]*cells_per_dim_[1] + j*cells_per_dim_[0] + i
// with 0<= i < cells_per_dim_[0], 0<= j < cells_per_dim_[1], 0<= k <cells_per_dim_[2].
assert(cells_per_dim[0]);
assert(cells_per_dim[1]);
assert(cells_per_dim[2]);

std::array<int,3> ijk = {0,0,0};
ijk[0] = idx_in_parent_cell % cells_per_dim[0]; idx_in_parent_cell /= cells_per_dim[0];
ijk[1] = idx_in_parent_cell % cells_per_dim[1];
ijk[2] = idx_in_parent_cell /cells_per_dim[1];
return ijk;
}

/// @brief Determine if a finite amount of patches (of cells) are disjoint, namely, they do not share any corner nor face.
Expand Down

0 comments on commit 266320c

Please sign in to comment.