Skip to content

Commit

Permalink
Remove nonneeded copy, add cells_per_dim as funct arg
Browse files Browse the repository at this point in the history
  • Loading branch information
aritorto committed Sep 30, 2024
1 parent d54de16 commit 1dda48a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion opm/grid/cpgrid/CpGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ void CpGrid::computeGlobalCellLgr(const int& level, const std::array<int,3>& sta
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, childIJK);
currentData()[level]-> getInParentCellIJK(idx_in_parent_cell, cells_per_dim, childIJK);
// 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
10 changes: 2 additions & 8 deletions opm/grid/cpgrid/CpGridData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1710,17 +1710,11 @@ void CpGridData::computeCommunicationInterfaces([[maybe_unused]] int noExistingP
#endif
}

std::array<Dune::FieldVector<double,3>,8> CpGridData::getReferenceRefinedCorners(const int& idx_in_parent_cell, const std::array<int,3>& cells_per_dim) const
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};
int idx_copy = idx_in_parent_cell;
ijk[0] = idx_copy % cells_per_dim[0];
idx_copy -= ijk[0]; // k*cells_per_dim[0]*cells_per_dim[1] + j*cells_per_dim[0]
idx_copy /= cells_per_dim[0]; // k*cells_per_dim[1] + j
ijk[1] = idx_copy % cells_per_dim[1];
idx_copy -= ijk[1]; // k*cells_per_dim[1]
ijk[2] = idx_copy /cells_per_dim[1];
getInParentCellIJK(idx_in_parent_cell, cells_per_dim, ijk);

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
21 changes: 13 additions & 8 deletions opm/grid/cpgrid/CpGridData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,21 +312,26 @@ class CpGridData
/// @brief Extract in-parent-cell Cartesian index triplet (i,j,k) of a refined cell.
///
/// - 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 */)
/// 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}.
/// 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
/// @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] cells_per_dim
/// @param [out] ijk In-parent-cell Cartesian index triplet
void getInParentCellIJK(int idx_in_parent_cell, std::array<int,3>& ijk) const
void getInParentCellIJK(int idx_in_parent_cell, const std::array<int,3>& cells_per_dim, std::array<int,3>& ijk) const
{
// idx_in_parent_cell = 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].
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];
assert(cells_per_dim[0]);
assert(cells_per_dim[1]);
assert(cells_per_dim[2]);

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];
}

/// @brief Determine if a finite amount of patches (of cells) are disjoint, namely, they do not share any corner nor face.
Expand Down Expand Up @@ -401,7 +406,7 @@ class CpGridData
void postAdapt();

private:
std::array<Dune::FieldVector<double,3>,8> getReferenceRefinedCorners(const int& idx_in_parent_cell, const std::array<int,3>& cells_per_dim) const;
std::array<Dune::FieldVector<double,3>,8> getReferenceRefinedCorners(int idx_in_parent_cell, const std::array<int,3>& cells_per_dim) const;

/// @brief Compute amount of cells in each direction of a patch of cells. (Cartesian grid required).
///
Expand Down
2 changes: 1 addition & 1 deletion opm/grid/cpgrid/Entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ Dune::cpgrid::Geometry<3,3> Dune::cpgrid::Entity<codim>::geometryInFather() cons
if (!(this->hasFather())){
OPM_THROW(std::logic_error, "Entity has no father.");
}
const int& idx_in_parent_cell = pgrid_ -> cell_to_idxInParentCell_[this->index()];
auto idx_in_parent_cell = pgrid_ -> cell_to_idxInParentCell_[this->index()];
if (idx_in_parent_cell !=-1) {
const auto& cells_per_dim = (*(pgrid_ -> level_data_ptr_))[this->level()] -> cells_per_dim_;
const auto& auxArr = pgrid_ -> getReferenceRefinedCorners(idx_in_parent_cell, cells_per_dim);
Expand Down

0 comments on commit 1dda48a

Please sign in to comment.