Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up a couple of friend declarations in CpGridData.hpp #761

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions opm/grid/cpgrid/CpGridData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,31 @@ void CpGridData::computeCommunicationInterfaces([[maybe_unused]] int noExistingP
#endif
}

int CpGridData::numFaces() const
{
return face_to_cell_.size();
}

int CpGridData::numFaceVertices(int face_idx) const
{
return face_to_point_[face_idx].size();
}

int CpGridData::faceVertex(int face_idx, int local_vertex_index) const
{
return face_to_point_[face_idx][local_vertex_index];
}

int CpGridData::numFaceCells(Dune::cpgrid::EntityRep<1> face) const
{
return face_to_cell_[face].size();
}

int CpGridData::faceCell(Dune::cpgrid::EntityRep<1> face, int local_cell_index) const
{
return face_to_cell_[face][local_cell_index].index();
}

std::array<Dune::FieldVector<double,3>,8> CpGridData::getReferenceRefinedCorners(int idxInParentCell, 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
Expand Down
31 changes: 15 additions & 16 deletions opm/grid/cpgrid/CpGridData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@ void refinePatch_and_check(Dune::CpGrid&,
void check_global_refine(const Dune::CpGrid&,
const Dune::CpGrid&);

void fieldProp_check(const Dune::CpGrid& grid, Opm::EclipseGrid eclGrid, std::string deck_string);

void testInactiveCellsLgrs(const std::string&,
const std::vector<std::array<int,3>>&,
const std::vector<std::array<int,3>>&,
const std::vector<std::array<int,3>>&,
const std::vector<std::string>&);

namespace Dune
{
namespace cpgrid
Expand Down Expand Up @@ -180,14 +172,6 @@ class CpGridData
friend
void ::check_global_refine(const Dune::CpGrid&,
const Dune::CpGrid&);
friend
void ::fieldProp_check(const Dune::CpGrid& grid, Opm::EclipseGrid eclGrid, std::string deck_string);
friend
void ::testInactiveCellsLgrs(const std::string&,
const std::vector<std::array<int,3>>&,
const std::vector<std::array<int,3>>&,
const std::vector<std::array<int,3>>&,
const std::vector<std::string>&);

private:
CpGridData(const CpGridData& g);
Expand Down Expand Up @@ -309,6 +293,21 @@ class CpGridData
ijk[2] = gc / logical_cartesian_size_[1];
}

/// Total amount of faces on the grid.
int numFaces() const;

/// Given a face index, total amount of its corners/points/vertices.
int numFaceVertices(int face_idx) const;

/// Given a face index and the local index of a vertex (0,..., numFaceVertices() -1), returns the vertex index (on the grid).
int faceVertex(int face_idx, int local_vertex_index) const;

/// Given a face index, total amount of its cells (1 or 2 maximum).
int numFaceCells(Dune::cpgrid::EntityRep<1> face) const;

/// Given a face index and the local index of a cell (0,1 maximum), returns the cell index (on the grid).
int faceCell(Dune::cpgrid::EntityRep<1> face, int local_cell_index) const;

/// @brief Determine if a finite amount of patches (of cells) are disjoint, namely, they do not share any corner nor face.
///
/// @param [in] startIJK_vec Vector of Cartesian triplet indices where each patch starts.
Expand Down
26 changes: 21 additions & 5 deletions opm/grid/cpgrid/Entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ class Entity : public EntityRep<codim>
/// \brief Get equivalent element on the level grid where the entity was born, if grid = leaf-grid-view. Otherwise, return itself.
Entity<0> getEquivLevelElem() const;

/// \brief Get equivalent element on the leaf grid. If grid = leaf-grid-view, return itself. Requirement: isLeaf().
Entity<0> getEquivLeafElem() const;

/// \brief Get Cartesian Index in the level grid view where the Entity was born.
int getLevelCartesianIdx() const;

Expand Down Expand Up @@ -470,7 +473,7 @@ int Entity<codim>::level() const
template<int codim>
bool Entity<codim>::isLeaf() const
{
if (pgrid_ -> parent_to_children_cells_.empty()){ // LGR cells
if (pgrid_ -> parent_to_children_cells_.empty()){ // Then pgrid_ must be the leaf grid view, therefore entity is leaf.
return true;
}
else {
Expand Down Expand Up @@ -611,13 +614,26 @@ Dune::cpgrid::Entity<0> Dune::cpgrid::Entity<codim>::getEquivLevelElem() const
}
}

template<int codim>
Dune::cpgrid::Entity<0> Dune::cpgrid::Entity<codim>::getEquivLeafElem() const
{
// Check if the element belongs to the leaf grid view or the level zero grid.
if (isLeaf()) {
const int& entityLeafIdx = pgrid_-> level_to_leaf_cells_[this->index()];
// leaf_to_level_cells_ [leaf idx] = {level where the entity was born, equivalent cell idx in that level}
return Dune::cpgrid::Entity<0>( *((*(pgrid_ -> level_data_ptr_)).back()).get(), entityLeafIdx, true);
}
else {
return *this;
}
}

template<int codim>
int Dune::cpgrid::Entity<codim>::getLevelCartesianIdx() const
{
const auto entityLevel = this -> level();
const auto level = (*(pgrid_ -> level_data_ptr_))[entityLevel].get();
const auto& elemInLevel = this->getLevelElem(); // throws when the entity does not belong to the leaf grid view.
return level -> global_cell_[elemInLevel.index()];
const auto level_data = (*(pgrid_ -> level_data_ptr_))[this->level()].get();
// getLevelElem() throws when the entity does not belong to the leaf grid view.
return level_data -> global_cell_[this->getLevelElem().index()];
}

} // namespace cpgrid
Expand Down
Loading