Skip to content

Commit 15d1419

Browse files
committed
WIP correct cell to face for level and leaf grids
1 parent ccf53fa commit 15d1419

6 files changed

Lines changed: 130 additions & 28 deletions

File tree

opm/grid/cpgrid/CpGrid.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2203,7 +2203,8 @@ bool CpGrid::refineAndUpdateGrid(bool throwOnFailure,
22032203
markedElemAndEquivRefinedCorn_to_corner,
22042204
cornerInMarkedElemWithEquivRefinedCorner,
22052205
cells_per_dim_vec,
2206-
cellRefinements);
2206+
cellRefinements,
2207+
withoutFaults);
22072208

22082209
// Update leaf grid geometries
22092210
// --- Adapted corners ---

opm/grid/cpgrid/LgrFaultHelpers.cpp

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,7 @@ void addVertices(const Dune::cpgrid::CpGridData&
728728
}
729729

730730
for (const auto& [parentFace, boundInfo] : parentCellFace_to_boundaryFaceInfo) {
731-
for (const auto& vertex : boundInfo.foundNewVertices) {
732-
std::cout<< vertex[0] << " " << vertex[1] << " " << vertex[2] << " new vertex for parentFace "<< parentFace << std::endl;
731+
for (const auto& vertex : boundInfo.foundNewVertices) {
733732
newVertex_to_newGridVertexIdx[vertex] = numVertices;
734733
newGridVertices[numVertices] = Dune::cpgrid::Geometry<0, 3>(vertex);
735734
newGridBoundaryVertex_to_parentFace[numVertices] = parentFace;
@@ -1438,8 +1437,8 @@ void makeCellRefinementsNeighborsAware(std::vector<std::shared_ptr<Dune::cpgrid:
14381437

14391438
for (std::size_t faceIdx = 0; faceIdx < faceInMarkedElemAndRefinedFaces.size(); ++faceIdx) {
14401439

1441-
if (faceInMarkedElemAndRefinedFaces[faceIdx].size()<=1)
1442-
continue;
1440+
// if (faceInMarkedElemAndRefinedFaces[faceIdx].size()<=1)
1441+
// continue;
14431442

14441443
for (std::size_t cellRefCount = 0; cellRefCount < faceInMarkedElemAndRefinedFaces[faceIdx].size(); ++cellRefCount) {
14451444

@@ -1484,5 +1483,73 @@ std::optional<int> getNeighborCellRefVertexIdx(const Dune::cpgrid::CpGridData& n
14841483
}
14851484

14861485

1486+
std::optional<int> getNeighborCellRefFaceIdx(const Dune::cpgrid::CpGridData& neighborCellRef,
1487+
const std::vector<int>& neighborFaceList,
1488+
const Dune::cpgrid::CpGridData& cellRef,
1489+
int faceIdxInCellRef)
1490+
{
1491+
std::set<Dune::FieldVector<double,3>, FieldVectorLess> faceCoords{};
1492+
for (const auto& vertexIdx : cellRef.faceToPoint(faceIdxInCellRef)){
1493+
faceCoords.insert(Dune::cpgrid::Entity<3>(cellRef, vertexIdx, true).geometry().center());
1494+
}
1495+
1496+
/* for (const auto& faceIdx : neighborFaceList) {
1497+
std::set<Dune::FieldVector<double,3>, FieldVectorLess> neighborFaceCoords{};
1498+
for (const auto& vIdx : neighborCellRef.faceToPoint(faceIdx)){
1499+
neighborFaceCoords.insert(Dune::cpgrid::Entity<3>(neighborCellRef, vIdx, true).geometry().center());
1500+
}
1501+
1502+
if (faceCoords.size() == neighborFaceCoords.size()) {
1503+
bool isClose = false;
1504+
for (const auto& v : faceCoords) {
1505+
for (const auto& w : neighborFaceCoords) {
1506+
isClose = areClose(v,w);
1507+
1508+
}
1509+
}
1510+
}
1511+
return faceIdx;
1512+
}
1513+
return std::nullopt;*/
1514+
1515+
1516+
for (const auto& faceIdx : neighborFaceList) {
1517+
std::set<Dune::FieldVector<double,3>, FieldVectorLess> neighborFaceCoords;
1518+
1519+
for (const auto& vIdx : neighborCellRef.faceToPoint(faceIdx)) {
1520+
// std::cout<< vIdx << " adding vertex index in neighborList "<< std::endl;
1521+
neighborFaceCoords.insert(
1522+
Dune::cpgrid::Entity<3>(neighborCellRef, vIdx, true).geometry().center());
1523+
}
1524+
1525+
if (faceCoords.size() != neighborFaceCoords.size())
1526+
continue;
1527+
1528+
bool sameFace = true;
1529+
1530+
for (const auto& v : faceCoords) {
1531+
bool found = false;
1532+
1533+
for (const auto& w : neighborFaceCoords) {
1534+
if (areClose(v, w)) {
1535+
found = true;
1536+
break;
1537+
}
1538+
}
1539+
1540+
if (!found) {
1541+
sameFace = false;
1542+
break;
1543+
}
1544+
}
1545+
1546+
if (sameFace)
1547+
return faceIdx;
1548+
}
1549+
1550+
return std::nullopt;
1551+
}
1552+
1553+
14871554
} // namespace Lgr
14881555
} // namespace Opm

opm/grid/cpgrid/LgrFaultHelpers.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,6 @@ computeFaceOverlapVertices(const Face&
457457
if (isVertexInsideFace(currentPoint, gridData1, face1_edges, face1_normal)) {
458458
overlapFaceVertices.insert(currentPoint);
459459
gridData2_vertex_to_vertexIdx[currentPoint] = face2_to_point[i];
460-
// std::cout<< currentPoint[0] << " " << currentPoint[1] << " " << currentPoint[2] << " currentPoint " << face2_to_point[i] << std::endl;
461460
}
462461
}
463462
if (overlapFaceVertices.size() == face2_to_point.size()) {
@@ -695,6 +694,12 @@ std::optional<int> getNeighborCellRefVertexIdx(const Dune::cpgrid::CpGridData& n
695694
const std::vector<int>& faceList,
696695
const Dune::FieldVector<double,3>& vertex);
697696

697+
std::optional<int> getNeighborCellRefFaceIdx(const Dune::cpgrid::CpGridData& neighborCellRef,
698+
const std::vector<int>& neighborFaceList,
699+
const Dune::cpgrid::CpGridData& cellRef,
700+
int faceIdxInCellRef);
701+
702+
698703
} // namespace Lgr
699704
} // namespace Opm
700705

opm/grid/cpgrid/LgrHelpers.cpp

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,13 +1161,6 @@ void identifyRefinedFacesPerLevel(const Dune::cpgrid::CpGridData& current_data,
11611161
// - If the marked face appears only in one marked element -> then, we store this face now.
11621162
// - If the marked face appears in two marked elements -> we distinguish between
11631163
// both marked elements sharing that face belonging to the same level, or not.
1164-
1165-
for (std::size_t f =0; f<cellRefinements[elemIdx].boundaryRefinedFace_to_parentFace.size();++f)
1166-
{
1167-
std::cout<< f << " face with parent face "<< cellRefinements[elemIdx].boundaryRefinedFace_to_parentFace[f] <<
1168-
" for elemIdx: " << elemIdx <<std::endl;
1169-
}
1170-
11711164
const auto markedFace = getParentFaceWhereNewRefinedFaceLiesOn(face,
11721165
markedElem_to_itsLgr[elemIdx],
11731166
cellRefinements[elemIdx].boundaryRefinedFace_to_parentFace);
@@ -1258,7 +1251,16 @@ void identifyLeafGridFaces(const Dune::cpgrid::CpGridData& current_data,
12581251
cellRefinementsInfo[elem].boundaryRefinedFace_to_parentFace);
12591252

12601253
assert(!faceInMarkedElemAndRefinedFaces[markedFace].empty());
1261-
int lastLgr = faceInMarkedElemAndRefinedFaces[markedFace].back().first;
1254+
int lastLgr = -1;
1255+
if (faceInMarkedElemAndRefinedFaces[markedFace].size()==1){
1256+
lastLgr = faceInMarkedElemAndRefinedFaces[markedFace].back().first;
1257+
}
1258+
else {
1259+
lastLgr = std::max( faceInMarkedElemAndRefinedFaces[markedFace][0].first,
1260+
faceInMarkedElemAndRefinedFaces[markedFace][1].first);
1261+
}
1262+
1263+
12621264
if (lastLgr == elem) {
12631265
// Store only at last appearance
12641266
insertBidirectional(elemLgrAndElemLgrFace_to_adaptedFace, // map a_to_b
@@ -1354,7 +1356,6 @@ int getParentFaceWhereNewRefinedFaceLiesOn(int faceIdxInLgr,
13541356
if (refinedFace_to_parentFace[faceIdxInLgr] != -1 /* invalid index */) {
13551357
return refinedFace_to_parentFace[faceIdxInLgr];
13561358
}
1357-
std::cout<< faceIdxInLgr << " refined face has no parent face " << std::endl;
13581359
OPM_THROW(std::logic_error, "Cannot find index of parent face where the new refined face lies on.");
13591360
}
13601361

@@ -1479,7 +1480,8 @@ void populateRefinedCells(const Dune::cpgrid::CpGridData& current_data,
14791480
const std::map<std::array<int,2>,int>& markedElemAndEquivRefinedCorn_to_corner,
14801481
const std::vector<std::vector<std::array<int,2>>>& cornerInMarkedElemWithEquivRefinedCorner,
14811482
const std::vector<std::array<int,3>>& cells_per_dim_vec,
1482-
const std::vector<CellRefinementBoundaryInfo>& cellRefinementsInfo)
1483+
const std::vector<CellRefinementBoundaryInfo>& cellRefinementsInfo,
1484+
bool withoutFaults)
14831485
{
14841486
// --- Refined cells ---
14851487
for (std::size_t shiftedLevel = 0; shiftedLevel < refined_cell_count_vec.size(); ++shiftedLevel) {
@@ -1554,11 +1556,37 @@ void populateRefinedCells(const Dune::cpgrid::CpGridData& current_data,
15541556
markedElem_to_itsLgr[elemLgr],
15551557
cellRefinementsInfo[elemLgr].boundaryRefinedFace_to_parentFace);
15561558
// Get the last LGR (marked element) where the marked face appeared.
1557-
const int& lastLgrWhereMarkedFaceAppeared = faceInMarkedElemAndRefinedFaces[markedFace].back().first;
1558-
const auto& lastAppearanceLgrEquivFace = replaceLgr1FaceIdxByLgr2FaceIdx(cells_per_dim_vec[shiftedLevel],
1559-
preAdaptFace,
1560-
markedElem_to_itsLgr[elemLgr],
1561-
cells_per_dim_vec[assignRefinedLevel[lastLgrWhereMarkedFaceAppeared] - preAdaptMaxLevel -1]);
1559+
// const int& lastLgrWhereMarkedFaceAppeared = faceInMarkedElemAndRefinedFaces[markedFace].back().first;
1560+
1561+
assert( faceInMarkedElemAndRefinedFaces[markedFace].size() == 2);
1562+
const auto& [p1, faces1] = faceInMarkedElemAndRefinedFaces[markedFace][0];
1563+
const auto& [p2, faces2] = faceInMarkedElemAndRefinedFaces[markedFace][1];
1564+
1565+
std::cout<< p1 << " p1 vs p2 " << p2 <<std::endl;
1566+
1567+
int lastAppearanceLgrEquivFace = -1;
1568+
1569+
int lastLgrWhereMarkedFaceAppeared = (p1 == elemLgr)? p2 : p1;
1570+
const auto& lastFaces = (p1 == elemLgr)? faces2 : faces1;
1571+
1572+
// if (withoutFaults) {
1573+
lastAppearanceLgrEquivFace = replaceLgr1FaceIdxByLgr2FaceIdx(cells_per_dim_vec[shiftedLevel],
1574+
preAdaptFace,
1575+
markedElem_to_itsLgr[elemLgr],
1576+
cells_per_dim_vec[assignRefinedLevel[lastLgrWhereMarkedFaceAppeared] - preAdaptMaxLevel -1]);
1577+
// }
1578+
/* else {
1579+
const auto candidateNeigh = getNeighborCellRefFaceIdx( *markedElem_to_itsLgr[lastLgrWhereMarkedFaceAppeared],
1580+
lastFaces,
1581+
*markedElem_to_itsLgr[elemLgr],
1582+
preAdaptFace);
1583+
assert(candidateNeigh.has_value());
1584+
lastAppearanceLgrEquivFace = candidateNeigh.value();
1585+
}
1586+
assert(lastAppearanceLgrEquivFace>=0);*/
1587+
1588+
1589+
15621590
refinedFace = elemLgrAndElemLgrFace_to_refinedLevelAndRefinedFace.at({lastLgrWhereMarkedFaceAppeared, lastAppearanceLgrEquivFace})[1];
15631591
aux_refined_cell_to_face.push_back({refinedFace, face.orientation()});
15641592
}

opm/grid/cpgrid/LgrHelpers.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,8 @@ void populateRefinedCells(const Dune::cpgrid::CpGridData& current_data,
563563
const std::map<std::array<int,2>,int>& markedElemAndEquivRefinedCorn_to_corner,
564564
const std::vector<std::vector<std::array<int,2>>>& cornerInMarkedElemWithEquivRefinedCorner,
565565
const std::vector<std::array<int,3>>& cells_per_dim_vec,
566-
const std::vector<CellRefinementBoundaryInfo>& cellRefinementsInfo);
566+
const std::vector<CellRefinementBoundaryInfo>& cellRefinementsInfo,
567+
bool withoutFaults);
567568

568569
/// @brief Map a refined boundary face from one single-cell refinement to a neighboring refinement.
569570
///

tests/cpgrid/lgr/compute_new_vertices_of_overlapping_intersections_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void checkNewRefinedFaces(const Dune::CpGrid& grid,
150150
}
151151
}
152152

153-
BOOST_AUTO_TEST_CASE(parentCellWithMoreThanOne_I_FACE_trueOriented_nonTrivialOverlap, *boost::unit_test::disabled())
153+
BOOST_AUTO_TEST_CASE(parentCellWithMoreThanOne_I_FACE_trueOriented_nonTrivialOverlap)// , *boost::unit_test::disabled())
154154
{
155155
// Level zero grid dims = 2x1x1
156156
//
@@ -342,7 +342,7 @@ PORO
342342
/* lgr_name_vec = */ {"LGR1"});
343343
}
344344

345-
BOOST_AUTO_TEST_CASE(parentCellWithMoreThanOne_I_FACE_trueOriented_trivialOverlap, *boost::unit_test::disabled())
345+
BOOST_AUTO_TEST_CASE(parentCellWithMoreThanOne_I_FACE_trueOriented_trivialOverlap)//, *boost::unit_test::disabled())
346346
{
347347
// Level zero grid dims = 2x1x1
348348
//
@@ -454,7 +454,7 @@ PORO
454454
}
455455

456456

457-
BOOST_AUTO_TEST_CASE(parentCellWithMoreThanOne_I_FACE_false, *boost::unit_test::disabled())
457+
BOOST_AUTO_TEST_CASE(parentCellWithMoreThanOne_I_FACE_false)//, *boost::unit_test::disabled())
458458
{
459459
// Level zero grid dims = 2x1x1
460460
//
@@ -637,7 +637,7 @@ PORO
637637
/* lgr_name_vec = */ {"LGR1"});
638638
}
639639

640-
BOOST_AUTO_TEST_CASE(parentCellWithMoreThanSixIntersections_J_FACE_true, *boost::unit_test::disabled())
640+
BOOST_AUTO_TEST_CASE(parentCellWithMoreThanSixIntersections_J_FACE_true)//, *boost::unit_test::disabled())
641641
{
642642
// Level zero grid dims = 1x2x1
643643
//
@@ -822,7 +822,7 @@ PORO
822822
}
823823

824824

825-
BOOST_AUTO_TEST_CASE(parentCellWithMoreThanSixIntersections_J_FACE_false, *boost::unit_test::disabled())
825+
BOOST_AUTO_TEST_CASE(parentCellWithMoreThanSixIntersections_J_FACE_false)//, *boost::unit_test::disabled())
826826
{
827827
// Level zero grid dims = 1x2x1
828828
//
@@ -1006,7 +1006,7 @@ PORO
10061006
}
10071007

10081008

1009-
BOOST_AUTO_TEST_CASE(neighboringSingleCellRefinementsDifferentLgrs,*boost::unit_test::disabled())
1009+
BOOST_AUTO_TEST_CASE(neighboringSingleCellRefinementsDifferentLgrs)//,*boost::unit_test::disabled())
10101010
{
10111011
// Level zero grid dims = 2x1x1
10121012
//

0 commit comments

Comments
 (0)