Skip to content

Commit ca21cb4

Browse files
committed
WIP building levels aware of neighbor-cell-ref
1 parent 15d1419 commit ca21cb4

5 files changed

Lines changed: 212 additions & 49 deletions

File tree

opm/grid/cpgrid/CpGrid.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,8 @@ bool CpGrid::refineAndUpdateGrid(bool throwOnFailure,
22492249
cornerInMarkedElemWithEquivRefinedCorner,
22502250
cells_per_dim_vec,
22512251
preAdaptMaxLevel,
2252-
cellRefinements);
2252+
cellRefinements,
2253+
withoutFaults);
22532254

22542255
for (int level = 0; level < levels; ++level) {
22552256
const int refinedLevelGridIdx = level + preAdaptMaxLevel +1;

opm/grid/cpgrid/LgrFaultHelpers.cpp

Lines changed: 131 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -718,10 +718,12 @@ void addVertices(const Dune::cpgrid::CpGridData&
718718
const auto& oldGridVertices = *(oldGrid.getGeometry().geomVector(std::integral_constant<int,3>()));
719719
Dune::cpgrid::EntityVariableBase<Dune::cpgrid::Geometry<0,3>>& newGridVertices = *(newGridGeomData.geometries.geomVector(std::integral_constant<int,3>()));
720720

721+
int newVerticesCount = 0;
721722
for (const auto& [parentFace, boundInfo] : parentCellFace_to_boundaryFaceInfo) {
722-
newGridVertices.resize(numVertices + boundInfo.foundNewVertices.size());
723+
newVerticesCount += boundInfo.foundNewVertices.size();
723724
}
724-
725+
newGridVertices.resize(numVertices + newVerticesCount);
726+
725727
// add the "old" vertices (the parent-cell-face-aware are includeed here)
726728
for (int i = 0; i < oldGrid.size(3); ++i) {
727729
newGridVertices[i] = oldGridVertices.get(i);
@@ -732,7 +734,6 @@ void addVertices(const Dune::cpgrid::CpGridData&
732734
newVertex_to_newGridVertexIdx[vertex] = numVertices;
733735
newGridVertices[numVertices] = Dune::cpgrid::Geometry<0, 3>(vertex);
734736
newGridBoundaryVertex_to_parentFace[numVertices] = parentFace;
735-
736737
++numVertices;
737738
}
738739
}
@@ -965,8 +966,8 @@ void addFaces(int
965966

966967
int newGrid_num_points = 0;
967968
int newGrid_face_count = 0;
968-
969-
for (int i = 0; i < oldGrid.numFaces(); ++i) {
969+
970+
for (int i = 0; i < oldGrid.numFaces(); ++i) {
970971

971972
const auto faceToCellSize = oldGrid.faceToCell(i).size();
972973

@@ -1071,15 +1072,124 @@ void addFaces(int
10711072
}
10721073
}
10731074
}
1075+
}
1076+
1077+
1078+
1079+
1080+
/* for (int i = 0; i < oldGrid.numFaces(); ++i) {
1081+
1082+
const auto faceToCellSize = oldGrid.faceToCell(i).size();
1083+
std::vector<int> newFaceIndices{};
1084+
1085+
if (faceToCellSize == 2) { // inner face->strore it
1086+
const auto face = Dune::cpgrid::EntityRep<1>(i, true);
1087+
1088+
old_to_new_faceIdxList[i] = std::vector<int>{newGrid_face_count};
1089+
new_to_old_faceIdx[newGrid_face_count] = i;
1090+
1091+
newGridFaces[newGrid_face_count] = (*oldGrid.getGeometry().geomVector(std::integral_constant<int,1>()))[face];
1092+
mutable_newGridFaceTags[newGrid_face_count] = oldGrid.faceTag(i);
1093+
mutable_newGridFaceNormals[newGrid_face_count] = oldGrid.faceNormals(i);
1094+
1095+
std::vector<int> faceToPoint{};
1096+
faceToPoint.reserve(oldGrid.faceToPoint(i).size());
1097+
for (const auto& vertexIdx : oldGrid.faceToPoint(i)) {
1098+
faceToPoint.push_back(vertexIdx);
1099+
}
1100+
newGrid_num_points += faceToPoint.size();
1101+
aux_newGrid_face_to_point[newGrid_face_count] = faceToPoint;
1102+
1103+
const auto& faceToCell = oldGrid.faceToCell(i);
1104+
newGridGeomData.face_to_cell.appendRow(faceToCell.begin(), faceToCell.end());
1105+
1106+
++newGrid_face_count;
1107+
}
10741108
}
1109+
for (int i = 0; i < oldGrid.numFaces(); ++i) {
1110+
const auto faceToCellSize = oldGrid.faceToCell(i).size();
1111+
if (faceToCellSize==2)
1112+
continue;
1113+
1114+
std::vector<int> newFaceIndices{};
1115+
1116+
for (const auto& [parentFaceIdx, boundaryFaceInfo] : boundaryFacesInfo) {
1117+
const auto& newFacesInfo = boundaryFaceInfo.vanishedCellRefFace_to_newRefinedFaces[i];
1118+
for (const auto& [grid2_faceIdx, newFaceToCoord] : newFacesInfo) {
1119+
1120+
const auto overlapIt = boundaryFaceInfo.overlapFaces.find(grid2_faceIdx);
1121+
assert(overlapIt != boundaryFaceInfo.overlapFaces.end());
1122+
const auto& overlapFacesInfo = overlapIt->second;
1123+
1124+
newFaceIndices.push_back(newGrid_face_count);
1125+
old_to_new_faceIdxList[i].push_back(newGrid_face_count);
1126+
new_to_old_faceIdx[newGrid_face_count] = i;
1127+
newGridBoundaryFace_to_parentFace[newGrid_face_count] = parentFaceIdx;
1128+
1129+
const auto [faceCenter, faceArea, faceNormal] = computeFaceCenterAreaNormal(newFaceToCoord);
1130+
1131+
newGridFaces[newGrid_face_count] = Dune::cpgrid::Geometry<2,3>(faceCenter, faceArea);
1132+
mutable_newGridFaceTags[newGrid_face_count] = oldGrid.faceTag(i); // shared tag
1133+
mutable_newGridFaceNormals[newGrid_face_count] = faceNormal;
1134+
1135+
std::vector<int> faceToPoint{};
1136+
faceToPoint.reserve(newFaceToCoord.size());
1137+
1138+
for (const auto& vertex : newFaceToCoord) {
1139+
int vertexIdx = -1; // invalid to be rewritten
1140+
// check if vertex (is new) and has already been stored
1141+
auto it = newVertex_to_newGridVertexIdx.find(vertex);
1142+
if (it != newVertex_to_newGridVertexIdx.end()) {
1143+
vertexIdx = it->second;
1144+
}
1145+
else { // otherwise, vertex existed already in gridData1 (before "correction")
1146+
auto iit = boundaryFaceInfo.boundaryVertex_to_vertexIdx.find(vertex);
1147+
assert( iit != boundaryFaceInfo.boundaryVertex_to_vertexIdx.end());
1148+
vertexIdx = iit->second;
1149+
}
1150+
assert(vertexIdx>=0);
1151+
faceToPoint.push_back(vertexIdx);
1152+
}
1153+
newGrid_num_points += faceToPoint.size();
1154+
aux_newGrid_face_to_point[newGrid_face_count] = faceToPoint;
1155+
1156+
const auto& face_to_cell = oldGrid.faceToCell(i);
1157+
newGridGeomData.face_to_cell.appendRow(face_to_cell.begin(), face_to_cell.end());
1158+
++newGrid_face_count;
1159+
}
1160+
if (newFacesInfo.empty()) { std::cout<< "empty for face i: " << i << std::endl;
1161+
const auto face = Dune::cpgrid::EntityRep<1>(i, true);
1162+
1163+
old_to_new_faceIdxList[i] = std::vector<int>{newGrid_face_count};
1164+
new_to_old_faceIdx[newGrid_face_count] = i;
1165+
1166+
newGridFaces[newGrid_face_count] = (*oldGrid.getGeometry().geomVector(std::integral_constant<int,1>()))[face];
1167+
mutable_newGridFaceTags[newGrid_face_count] = oldGrid.faceTag(i);
1168+
mutable_newGridFaceNormals[newGrid_face_count] = oldGrid.faceNormals(i);
1169+
1170+
std::vector<int> faceToPoint{};
1171+
faceToPoint.reserve(oldGrid.faceToPoint(i).size());
1172+
for (const auto& vertexIdx : oldGrid.faceToPoint(i)) {
1173+
faceToPoint.push_back(vertexIdx);
1174+
}
1175+
newGrid_num_points += faceToPoint.size();
1176+
aux_newGrid_face_to_point[newGrid_face_count] = faceToPoint;
1177+
1178+
const auto& faceToCell = oldGrid.faceToCell(i);
1179+
newGridGeomData.face_to_cell.appendRow(faceToCell.begin(), faceToCell.end());
1180+
1181+
++newGrid_face_count;
1182+
}
1183+
1184+
}
1185+
}*/
10751186
newGridGeomData.face_to_point.reserve(newGrid_face_count, newGrid_num_points);
10761187
for (int face = 0; face < newGrid_face_count; ++face) {
10771188
newGridGeomData.face_to_point.appendRow(aux_newGrid_face_to_point[face].begin(),
10781189
aux_newGrid_face_to_point[face].end());
10791190
}
10801191
}
10811192

1082-
10831193
void addCells(GeomData& geomData,
10841194
const Dune::cpgrid::CpGridData& gridData)
10851195
{
@@ -1155,7 +1265,7 @@ void makeCellRefinementParentFaceAware(bool
11551265
int numVertices = cellRefGrid.size(3);
11561266
const auto& parentCellToPoint = parentGrid.cellToPoint(parentCellElem.index());
11571267
std::map<int,int> correctedCellRefDataVertexIdx_to_parentGridVertexIdx{};
1158-
1268+
11591269
addVertices(numVertices,
11601270
cellRefGrid,
11611271
parentGrid_vertex_to_vertexIdx,
@@ -1327,21 +1437,21 @@ makeCellRefinementNeighborsAware(const Dune::cpgrid::Entity<0>& parentCell,
13271437
int numFaces = cellRefGrid.numFaces();
13281438

13291439
for (const auto& parentFace : parentCellToFace) {
1330-
1440+
13311441
const auto faceToCell = parentGrid.faceToCell(parentFace.index());
13321442

1333-
if (faceToCell.size() == 1 || (faceInMarkedElemAndRefinedFaces[parentFace.index()].size()<=1)){
1443+
if (faceToCell.size() == 1) { // || (faceInMarkedElemAndRefinedFaces[parentFace.index()].size()<=1)){
13341444
// face at parent grid boundary does need to be corrected (cell refinement is already parentCellFaces aware).
13351445
continue;
13361446
}
1337-
1447+
13381448
assert(faceToCell.size() == 2);
13391449
assert(faceInMarkedElemAndRefinedFaces[parentFace.index()].size() == 2);
13401450

13411451
const auto& [p1, refinedFaces1] = faceInMarkedElemAndRefinedFaces[parentFace.index()][0];
13421452
const auto& [p2, refinedFaces2] = faceInMarkedElemAndRefinedFaces[parentFace.index()][1];
13431453

1344-
int cellRefIdx = (p1 == parentCell.index())? p1 : p2;
1454+
// int cellRefIdx = (p1 == parentCell.index())? p1 : p2;
13451455
int neighborCellRefIdx = (p1 == parentCell.index())? p2 : p1;
13461456

13471457
const auto& cellRefFaces = (p1 == parentCell.index())? refinedFaces1 : refinedFaces2;
@@ -1392,8 +1502,6 @@ makeCellRefinementNeighborsAware(const Dune::cpgrid::Entity<0>& parentCell,
13921502
boundaryInfo.newVertex_to_newGridVertexIdx,
13931503
cellRefGridBoundaryInfo.boundaryRefinedVertex_to_parentFace,
13941504
cellRefGridBoundaryInfo.boundaryRefinedVertexCoincidesWithParentVertex);
1395-
1396-
std::cout<< numFaces << " numfaces before neighbor aware" << std::endl;
13971505

13981506
addFaces(numFaces,
13991507
cellRefGrid,
@@ -1407,7 +1515,7 @@ makeCellRefinementNeighborsAware(const Dune::cpgrid::Entity<0>& parentCell,
14071515

14081516
addCells(neighborAwareGeomData, cellRefGrid);
14091517

1410-
std::cout<< neighborAwareCellRef.numFaces() << " numFaces after addition " << std::endl;
1518+
14111519

14121520
return {neighborAwareCellRef_ptr, boundaryInfo};
14131521
}
@@ -1418,6 +1526,8 @@ void makeCellRefinementsNeighborsAware(std::vector<std::shared_ptr<Dune::cpgrid:
14181526
std::vector<std::vector<std::pair<int, std::vector<int>>>>& faceInMarkedElemAndRefinedFaces,
14191527
std::vector<BoundaryInfo>& boundaryInfoCellRefs) // needs to be updated
14201528
{
1529+
const auto cellRefsBeforeCorrection = cellRefs; // copy on propose
1530+
14211531
for (int elemIdx = 0; elemIdx < parentGrid.size(0); ++elemIdx) {
14221532
auto& cellRef = cellRefs[elemIdx];
14231533
if (cellRef == nullptr)
@@ -1426,7 +1536,7 @@ void makeCellRefinementsNeighborsAware(std::vector<std::shared_ptr<Dune::cpgrid:
14261536
const auto& parentCell = Dune::cpgrid::Entity<0>(parentGrid, elemIdx, true);
14271537

14281538
auto [correctedCellRef, correctedBoundaryInfo ] = makeCellRefinementNeighborsAware(parentCell,
1429-
cellRefs, // to get neighbor information
1539+
cellRefsBeforeCorrection, // to get neighbor information
14301540
parentGrid,
14311541
*cellRef,
14321542
cellRefsBoundaryInfo[elemIdx],
@@ -1468,7 +1578,7 @@ bool areClose(const Dune::FieldVector<double,3>& v,
14681578

14691579

14701580
std::optional<int> getNeighborCellRefVertexIdx(const Dune::cpgrid::CpGridData& neighborCellRef,
1471-
const std::vector<int>& faceList,
1581+
const std::vector<int>& faceList,
14721582
const Dune::FieldVector<double,3>& vertex)
14731583
{
14741584
for (const auto& faceIdx : faceList) {
@@ -1493,7 +1603,7 @@ std::optional<int> getNeighborCellRefFaceIdx(const Dune::cpgrid::CpGridData& nei
14931603
faceCoords.insert(Dune::cpgrid::Entity<3>(cellRef, vertexIdx, true).geometry().center());
14941604
}
14951605

1496-
/* for (const auto& faceIdx : neighborFaceList) {
1606+
for (const auto& faceIdx : neighborFaceList) {
14971607
std::set<Dune::FieldVector<double,3>, FieldVectorLess> neighborFaceCoords{};
14981608
for (const auto& vIdx : neighborCellRef.faceToPoint(faceIdx)){
14991609
neighborFaceCoords.insert(Dune::cpgrid::Entity<3>(neighborCellRef, vIdx, true).geometry().center());
@@ -1510,16 +1620,14 @@ std::optional<int> getNeighborCellRefFaceIdx(const Dune::cpgrid::CpGridData& nei
15101620
}
15111621
return faceIdx;
15121622
}
1513-
return std::nullopt;*/
1623+
return std::nullopt;
15141624

15151625

1516-
for (const auto& faceIdx : neighborFaceList) {
1626+
/* for (const auto& faceIdx : neighborFaceList) {
15171627
std::set<Dune::FieldVector<double,3>, FieldVectorLess> neighborFaceCoords;
15181628
15191629
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());
1630+
neighborFaceCoords.insert(Dune::cpgrid::Entity<3>(neighborCellRef, vIdx, true).geometry().center());
15231631
}
15241632
15251633
if (faceCoords.size() != neighborFaceCoords.size())
@@ -1547,7 +1655,7 @@ std::optional<int> getNeighborCellRefFaceIdx(const Dune::cpgrid::CpGridData& nei
15471655
return faceIdx;
15481656
}
15491657
1550-
return std::nullopt;
1658+
return std::nullopt;*/
15511659
}
15521660

15531661

0 commit comments

Comments
 (0)