Skip to content

Commit e32e54e

Browse files
committed
Fix getParentIntersectionFromLgrBoundaryFace using getOrigin()
Use intersection.inside().getOrigin() to obtain the level-0 ancestor of the inside cell, then match on intersection.indexInInside() directly: - If inside is a coarse (level-0) cell, getOrigin() returns the same cell and indexInInside() is already the correct level-0 face index. - If inside is a refined cell, getOrigin() returns its level-0 parent and indexInInside() equals the parent face index (fine cells inherit face directions from their parent). The guard `inside().level() * outside().level() == 0` skips the unhandled case where both cells are from different non-zero refinement levels.
1 parent 8f6abe5 commit e32e54e

1 file changed

Lines changed: 17 additions & 24 deletions

File tree

opm/grid/cpgrid/CpGrid.cpp

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,33 +1237,26 @@ int CpGrid::faceVertex(int face, int local_index) const
12371237
Dune::cpgrid::Intersection CpGrid::getParentIntersectionFromLgrBoundaryFace(const Dune::cpgrid::Intersection& intersection) const
12381238
{
12391239
if ( intersection.neighbor()) {
1240-
if ((intersection.inside().level() != intersection.outside().level())) {
1241-
// one coarse and one refined neighboring cell
1242-
/** Now, it could also be two refined cells. In that case, any of them will fit to search for the parent face */
1243-
const auto& cellIn = intersection.inside();
1244-
const auto& cellOut = intersection.outside();
1245-
1246-
// Identify the coarse and the refined neighboring cell
1247-
const auto coarseCell = (cellIn.level() == 0) ? cellIn : cellOut;
1248-
const auto refinedCell = (coarseCell == cellIn) ? cellOut : cellIn;
1249-
assert(coarseCell.level() != refinedCell.level());
1250-
1251-
// Get parent cell of the refined cell
1252-
const auto& parentCell = refinedCell.father();
1253-
1254-
// Get the index inside and orientation from the leaf grid (refined) face
1255-
const auto& intersectionIdxInInside = intersection.indexInInside();
1256-
1257-
for(const auto& parentIntersection : intersections(this->levelGridView(0), parentCell)){
1258-
// Get the inInsideIdx and orientation from the parent intersection
1259-
const auto& parentIdxInInside = parentIntersection.indexInInside();
1260-
if (parentIdxInInside == intersectionIdxInInside) {
1261-
return parentIntersection;
1240+
// Only handle intersections between cells at different levels where one of them
1241+
// is at level 0 (coarse/fine boundary). Skip same-level intersections and
1242+
// intersections between two different refined level grids (neither at level 0).
1243+
if (intersection.inside().level() != intersection.outside().level() &&
1244+
intersection.inside().level() * intersection.outside().level() == 0) {
1245+
// Get the equivalent level-0 cell if intersection.inside() is already at level 0,
1246+
// or the coarsest ancestor at level 0 if it is a refined cell.
1247+
// In both cases, intersection.indexInInside() is the correct face index to match:
1248+
// - coarse inside (level 0): indexInInside() is already the level-0 face index.
1249+
// - refined inside: fine cells inherit face directions from their parent, so
1250+
// indexInInside() equals the parent's face index.
1251+
const auto insideOrigin = intersection.inside().getOrigin();
1252+
for (const auto& originIntersection : intersections(this->levelGridView(0), insideOrigin)) {
1253+
if (originIntersection.indexInInside() == intersection.indexInInside()) {
1254+
return originIntersection;
12621255
}
12631256
}
1257+
OPM_THROW(std::invalid_argument, "Parent intersection not found for face with index: " + std::to_string(intersection.id()) +
1258+
" and index in inside: " + std::to_string(intersection.indexInInside()));
12641259
}
1265-
OPM_THROW(std::invalid_argument, "Parent intersection not found for face with index: " + std::to_string(intersection.id()) +
1266-
" and index in inside: " + std::to_string(intersection.indexInInside()));
12671260
}
12681261
OPM_THROW(std::invalid_argument, "Face is on the boundary of the grid");
12691262
}

0 commit comments

Comments
 (0)