Skip to content

Commit

Permalink
WIP Rv order dependency from cell_to_face_
Browse files Browse the repository at this point in the history
  • Loading branch information
aritorto committed May 14, 2024
1 parent 8e49526 commit c83b921
Showing 1 changed file with 75 additions and 85 deletions.
160 changes: 75 additions & 85 deletions opm/grid/cpgrid/CpGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3396,7 +3396,7 @@ bool CpGrid::isRefinedFaceInInteriorLgr(const std::array<int,3>& cells_per_dim,
bool isKface = (faceIdxInLgr < refined_k_faces);
bool isIface = (faceIdxInLgr >= refined_k_faces) && (faceIdxInLgr < refined_k_faces + refined_i_faces);
bool isJface = (faceIdxInLgr >= refined_k_faces + refined_i_faces);

const auto& ijk = getRefinedFaceIJK(cells_per_dim, faceIdxInLgr, elemLgr_ptr);
return ((ijk[0]%cells_per_dim[0] > 0 && isIface) || (ijk[1]%cells_per_dim[1]>0 && isJface) || (ijk[2]%cells_per_dim[2]>0 && isKface));
}
Expand All @@ -3414,7 +3414,7 @@ bool CpGrid::isRefinedNewBornCornerOnLgrBoundary(const std::array<int,3>& cells_
bool isOnParentCell_J_FACE = isOnParentCell_J_FACEfalse_and_newBornCorn || isOnParentCell_J_FACEtrue_and_newBornCorn;
bool isOnParentCell_K_FACE = isOnParentCell_K_FACEfalse_and_newBornCorn || isOnParentCell_K_FACEtrue_and_newBornCorn;
return (isOnParentCell_I_FACE || isOnParentCell_J_FACE || isOnParentCell_K_FACE);
}
}

bool CpGrid::newRefinedCornerLaysOnEdge(const std::array<int,3>& cells_per_dim, int cornerIdxInLgr) const
{
Expand Down Expand Up @@ -3452,30 +3452,29 @@ bool CpGrid::isRefinedFaceOnLgrBoundary(const std::array<int,3>& cells_per_dim,

int refined_k_faces = cells_per_dim[0]*cells_per_dim[1]*(cells_per_dim[2]+1);
int refined_i_faces = (cells_per_dim[0]+1)*cells_per_dim[1]*cells_per_dim[2];

bool isKface = (faceIdxInLgr < refined_k_faces);
bool isIface = (faceIdxInLgr >= refined_k_faces) && (faceIdxInLgr < refined_k_faces + refined_i_faces);
bool isJface = (faceIdxInLgr >= refined_k_faces + refined_i_faces);

bool isOnParentCell_I_FACE = isIface && (ijk[0] % cells_per_dim[0] == 0) && (ijk[1]<cells_per_dim[1]) && (ijk[2]<cells_per_dim[2]);
bool isOnParentCell_J_FACE = isJface && (ijk[1] % cells_per_dim[1] == 0) && (ijk[0]<cells_per_dim[0]) && (ijk[2]<cells_per_dim[2]);
bool isOnParentCell_K_FACE = isKface && (ijk[2] % cells_per_dim[2] == 0) && (ijk[0]<cells_per_dim[0]) && (ijk[1]<cells_per_dim[1]);

return (isOnParentCell_I_FACE || isOnParentCell_J_FACE || isOnParentCell_K_FACE);
}

std::array<int,2> CpGrid::getParentFacesAssocWithNewRefinedCornLayingOnEdge(const std::array<int,3>& cells_per_dim, int cornerIdxInLgr, int elemLgr) const
{
assert(newRefinedCornerLaysOnEdge(cells_per_dim, cornerIdxInLgr));

/** This needs to be modified for a general current_view_data_ that does not necessarily coincide with level 0 grid (data_[0]).
Alternatively, the order of cell_to_face_ in Geometry::refine has to be refactored. Currently,
{{K_FACE, false}, {J_FACE, false}, {I_FACE, false}, {I_FACE, true}, {J_FACE, true}, {K_FACE, true}}**/
// parentCell_to_face = {{I_FACE, false}, {I_FACE, true}, {J_FACE, false}, {J_FACE, true}, {K_FACE, false}, {K_FACE, true}}
const auto& parentCell_to_face = this->data_[0]->cell_to_face_[cpgrid::EntityRep<0>(elemLgr, true)];

const auto& parentCell_to_face = current_view_data_->cell_to_face_[cpgrid::EntityRep<0>(elemLgr, true)];
if(parentCell_to_face.size()>6){
OPM_THROW(std::logic_error, "The associted parent cell has more than six faces. Refinment/Adaptivity not supported yet.");
}
// Corners Order defined in Geometry::refine (j*(cells_per_dim[0]+1)*(cells_per_dim[2]+1)) + (i*(cells_per_dim[2]+1)) + k
const auto& ijk = getRefinedCornerIJK(cells_per_dim, cornerIdxInLgr);
// Edges laying on bottom face
// Edges laying on bottom face
bool isNewBornOnEdge01 = (ijk[0] % cells_per_dim[0] != 0) && (ijk[1] == 0) && (ijk[2] == 0);
bool isNewBornOnEdge23 = (ijk[0] % cells_per_dim[0] != 0) && (ijk[1] == cells_per_dim[1]) && ( ijk[2] == 0);
bool isNewBornOnEdge02 = (ijk[0] == 0) && (ijk[1] % cells_per_dim[1] != 0) && (ijk[2] == 0);
Expand All @@ -3493,97 +3492,88 @@ std::array<int,2> CpGrid::getParentFacesAssocWithNewRefinedCornLayingOnEdge(cons
bool isNewBornOnEdge46 = (ijk[0] == 0) && (ijk[1] % cells_per_dim[1] != 0) && (ijk[2] == cells_per_dim[2]);
bool isNewBornOnEdge57 = (ijk[0] == cells_per_dim[0]) && (ijk[1] % cells_per_dim[1] != 0) && (ijk[2] == cells_per_dim[2]);

// Corners Order defined in Geometry::refine (j*(cells_per_dim[0]+1)*(cells_per_dim[2]+1)) + (i*(cells_per_dim[2]+1)) + k

// Edges laying on the bottom face
if (isNewBornOnEdge01) { // J_FACE false, K_FACE false
return {parentCell_to_face[2].index(), parentCell_to_face[4].index()};
}
if (isNewBornOnEdge23) { // J_FACE true, K_FACE false
return {parentCell_to_face[3].index(), parentCell_to_face[4].index()};
}
if (isNewBornOnEdge02) { // I_FACE false, K_FACE false
return {parentCell_to_face[0].index(), parentCell_to_face[4].index()};
}
if (isNewBornOnEdge13) { // I_FACE true, K_FACE false
return {parentCell_to_face[1].index(), parentCell_to_face[4].index()};
}

// Edges connecting bottom and top faces
if (isNewBornOnEdge04) { // I_FACE false, J_FACE false
return {parentCell_to_face[0].index(), parentCell_to_face[2].index()};
}
if (isNewBornOnEdge26) { // I_FACE false, J_FACE true
return {parentCell_to_face[0].index(), parentCell_to_face[3].index()};
}
if (isNewBornOnEdge15) { // I_FACE true, J_FACE false
return {parentCell_to_face[1].index(), parentCell_to_face[2].index()};
}
if (isNewBornOnEdge37) { // I_FACE true, J_FACE true
return {parentCell_to_face[1].index(), parentCell_to_face[3].index()};
}
std::vector<int> auxFaces;
auxFaces.reserve(2);

// Edges laying on the top face
if (isNewBornOnEdge45) { // J_FACE false, K_FACE true
return {parentCell_to_face[2].index(), parentCell_to_face[5].index()};
}
if (isNewBornOnEdge67) { // J_FACE true, K_FACE true
return {parentCell_to_face[3].index(), parentCell_to_face[5].index()};
}
if (isNewBornOnEdge46) { // I_FACE false, K_FACE true
return {parentCell_to_face[0].index(), parentCell_to_face[5].index()};
}
if (isNewBornOnEdge57) { // I_FACE true, K_FACE true
return {parentCell_to_face[1].index(), parentCell_to_face[5].index()};
for (const auto& face : parentCell_to_face) {
const auto& faceEntity = Dune::cpgrid::EntityRep<1>(face.index(), true);
const auto& faceTag = current_view_data_->face_tag_[faceEntity];
// Add I_FACE false
bool addIfalse = isNewBornOnEdge02 || isNewBornOnEdge04 || isNewBornOnEdge26 || isNewBornOnEdge46;
if( addIfalse && (faceTag == 0) && (!face.orientation())) {
auxFaces.push_back(face.index());
}
// Add J_FACE false
bool addJfalse = isNewBornOnEdge01 || isNewBornOnEdge04 || isNewBornOnEdge15 || isNewBornOnEdge45;
if( addJfalse && (faceTag == 1) && (!face.orientation())) {
auxFaces.push_back(face.index());
}
// Add K_FACE false
bool addKfalse = isNewBornOnEdge01 || isNewBornOnEdge13 || isNewBornOnEdge23 || isNewBornOnEdge02;
if( addKfalse && (faceTag == 2) && (!face.orientation())) {
auxFaces.push_back(face.index());
}
// Add I_FACE true
bool addItrue = isNewBornOnEdge13 || isNewBornOnEdge15 || isNewBornOnEdge37 || isNewBornOnEdge57;
if( addItrue && (faceTag == 0) && (face.orientation())) {
auxFaces.push_back(face.index());
}
// Add J_FACE true
bool addJtrue = isNewBornOnEdge23|| isNewBornOnEdge26 || isNewBornOnEdge37 || isNewBornOnEdge67;
if( addJtrue && (faceTag == 1) && (face.orientation())) {
auxFaces.push_back(face.index());
}
// Add K_FACE true
bool addKtrue = isNewBornOnEdge45 || isNewBornOnEdge67 || isNewBornOnEdge46 || isNewBornOnEdge57;
if(addKtrue && (faceTag == 2) && (face.orientation())) {
auxFaces.push_back(face.index());
}
}
else {
OPM_THROW(std::logic_error, "Cannot find parent face indices.");
}
return {auxFaces[0], auxFaces[1]};
}


int CpGrid::getParentFaceWhereNewRefinedCornerLaysOn(const std::array<int,3>& cells_per_dim,
int cornerIdxInLgr, int parentCellIdxOnLevel0) const
{
assert(isRefinedNewBornCornerOnLgrBoundary(cells_per_dim, cornerIdxInLgr));

/** This needs to be modified for a general current_view_data_ that does not necessarily coincide with level 0 grid (data_[0]).
Alternatively, the order of cell_to_face_ in Geometry::refine has to be refactored. Currently,
{{K_FACE, false}, {J_FACE, false}, {I_FACE, false}, {I_FACE, true}, {J_FACE, true}, {K_FACE, true}}**/
// parentCell_to_face = {{I_FACE, false}, {I_FACE, true}, {J_FACE, false}, {J_FACE, true}, {K_FACE, false}, {K_FACE, true}}
const auto& parentCell_to_face = this->data_[0]->cell_to_face_[cpgrid::EntityRep<0>(parentCellIdxOnLevel0, true)];

const auto& parentCell_to_face = current_view_data_->cell_to_face_[cpgrid::EntityRep<0>(parentCellIdxOnLevel0, true)];
if(parentCell_to_face.size()>6){
OPM_THROW(std::logic_error, "The associted parent cell has more than six faces. Refinment/Adaptivity not supported yet.");
}
const auto& ijk = getRefinedCornerIJK(cells_per_dim, cornerIdxInLgr);

bool isOnParentCell_I_FACEfalse_and_newBornCorn = ( (ijk[0] == 0) && ((ijk[1] % cells_per_dim[1] != 0) || (ijk[2] % cells_per_dim[2] !=0) ));
bool isOnParentCell_I_FACEtrue_and_newBornCorn = ( (ijk[0] == cells_per_dim[0]) && ((ijk[1] % cells_per_dim[1] != 0) || (ijk[2] % cells_per_dim[2] !=0) ));
bool isOnParentCell_J_FACEfalse_and_newBornCorn = ( (ijk[1] == 0) && ((ijk[0] % cells_per_dim[0] != 0) || (ijk[2] % cells_per_dim[2] !=0) ));
bool isOnParentCell_J_FACEtrue_and_newBornCorn = ( (ijk[1] == cells_per_dim[1]) && ((ijk[0] % cells_per_dim[0] != 0) || (ijk[2] % cells_per_dim[2] !=0) ));
bool isOnParentCell_K_FACEfalse_and_newBornCorn = ( (ijk[2] == 0) && ((ijk[1] % cells_per_dim[1] != 0) || (ijk[0] % cells_per_dim[0] !=0) ));
bool isOnParentCell_K_FACEtrue_and_newBornCorn = ( (ijk[2] == cells_per_dim[2]) && ((ijk[1] % cells_per_dim[1] != 0) || (ijk[0] % cells_per_dim[0] !=0) ));


if (isOnParentCell_I_FACEfalse_and_newBornCorn) {
return parentCell_to_face[0].index();
}
if (isOnParentCell_I_FACEtrue_and_newBornCorn) {
return parentCell_to_face[1].index();
}
if (isOnParentCell_J_FACEfalse_and_newBornCorn) {
return parentCell_to_face[2].index();
}
if (isOnParentCell_J_FACEtrue_and_newBornCorn) {
return parentCell_to_face[3].index();
}
if (isOnParentCell_K_FACEfalse_and_newBornCorn) {
return parentCell_to_face[4].index();
}
if (isOnParentCell_K_FACEtrue_and_newBornCorn) {
return parentCell_to_face[5].index();
int selectedFace = 0;
for (const auto& face : parentCell_to_face) {
const auto& faceEntity = Dune::cpgrid::EntityRep<1>(face.index(), true);
const auto& faceTag = current_view_data_->face_tag_[faceEntity];
if (isOnParentCell_I_FACEfalse_and_newBornCorn && (faceTag == 0) && !face.orientation()) { // I_FACE false
selectedFace = face.index();
}
if (isOnParentCell_I_FACEtrue_and_newBornCorn && (faceTag == 0) && face.orientation()) { // I_FACE true
selectedFace = face.index();
}
if (isOnParentCell_J_FACEfalse_and_newBornCorn && (faceTag == 1) && !face.orientation()) { // J_FACE false
selectedFace = face.index();
}
if (isOnParentCell_J_FACEtrue_and_newBornCorn && (faceTag == 1) && face.orientation()) { // J_FACE true
selectedFace = face.index();
}
if (isOnParentCell_K_FACEfalse_and_newBornCorn && (faceTag == 2) && !face.orientation()) { // K_FACE false
selectedFace = face.index();
}
if (isOnParentCell_K_FACEtrue_and_newBornCorn && (faceTag == 2) && face.orientation()) { // K_FACE true
selectedFace = face.index();
}
}
else {
OPM_THROW(std::logic_error, "Cannot find parent face index.");
}
return selectedFace;
}

int CpGrid::getParentFaceWhereNewRefinedFaceLaysOn(const std::array<int,3>& cells_per_dim,
Expand Down

0 comments on commit c83b921

Please sign in to comment.