Skip to content

Commit ffac6bc

Browse files
committed
Fix search corner/refined faces
1 parent 45dbfce commit ffac6bc

4 files changed

Lines changed: 804 additions & 901 deletions

File tree

CMakeLists_files.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ list(APPEND TEST_SOURCE_FILES
113113
tests/cpgrid/lgr/addLgrs_in_allActiveCartesianGrid_test.cpp
114114
tests/cpgrid/lgr/addLgrsOnDistributedGrid_test.cpp
115115
tests/cpgrid/lgr/autoRefine_test.cpp
116-
tests/cpgrid/lgr/compute_new_vertices_of_overlapping_intersections_test.cpp
116+
tests/cpgrid/lgr/lgrs_and_faults_test.cpp
117117
tests/cpgrid/lgr/global_refine_test.cpp
118118
tests/cpgrid/lgr/id_entity_entityrep_test.cpp
119119
tests/cpgrid/lgr/level_and_grid_cartesianIndexMappers_test.cpp

opm/grid/cpgrid/LgrHelpers.cpp

Lines changed: 111 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,20 @@ void populateRefinedFaces(std::vector<Dune::cpgrid::EntityVariableBase<Dune::cpg
12781278
const std::vector<std::vector<std::array<int,2>>>& cornerInMarkedElemWithEquivRefinedCorner,
12791279
const std::map<std::array<int,2>,int>& markedElemAndEquivRefinedCorn_to_corner)
12801280
{
1281+
1282+
auto findCornerIdx = [&](const Dune::FieldVector<double,3>& w) {
1283+
for (const auto& [_, lastCellAndCorner] : vanishedRefinedCorner_to_itsLastAppearance) {
1284+
const auto v = Dune::cpgrid::Entity<3>(*markedElem_to_itsLgr[lastCellAndCorner[0]], lastCellAndCorner[1], true).geometry().center();
1285+
if (!Opm::Lgr::areClose(w,v)) {
1286+
continue;
1287+
}
1288+
else {
1289+
return lastCellAndCorner;
1290+
}
1291+
}
1292+
return std::array<int,2>{-1,-1};
1293+
};
1294+
12811295
for (std::size_t shiftedLevel = 0; shiftedLevel < refined_face_count_vec.size(); ++shiftedLevel) {
12821296
// Store the refined faces
12831297
refined_faces_vec[shiftedLevel].resize(refined_face_count_vec[shiftedLevel]);
@@ -1309,6 +1323,8 @@ void populateRefinedFaces(std::vector<Dune::cpgrid::EntityVariableBase<Dune::cpg
13091323
// Face_to_point
13101324
for (std::size_t corn = 0; corn < preAdapt_face_to_point.size(); ++corn) {
13111325
const auto& elemLgrCorn = preAdapt_face_to_point[corn];
1326+
1327+
13121328
std::size_t refinedCorn = 0; // It'll be rewritten.
13131329
// Corner is stored in adapted_corners
13141330
if (auto candidate = elemLgrAndElemLgrCorner_to_refinedLevelAndRefinedCorner.find({elemLgr, elemLgrCorn});
@@ -1323,20 +1339,22 @@ void populateRefinedFaces(std::vector<Dune::cpgrid::EntityVariableBase<Dune::cpg
13231339
corner_candidate != markedElemAndEquivRefinedCorn_to_corner.end()) {
13241340
lastAppearanceLgr_lgrEquivCorner = cornerInMarkedElemWithEquivRefinedCorner[corner_candidate->second].back();
13251341
}
1326-
else {
1327-
// To locate vanished corners, we need a while-loop, since {elemLgr, elemLgrcorner} leads to
1328-
// {neighboringElemLgr, neighboringElemLgrCornerIdx}, which might have also vanished.
1329-
// Then, use the lastest appearance of the current corner, meaning, the first (and unique one - by construction) that
1330-
// gives elemLgrAndElemLgrCorner_to_refinedCorner.count(lastAppearanceLgr_lgrCorner) == 1).
1331-
// This corner lies on the area occupied by a coarse face that got refined and belonged to two marked elements.
1332-
// Get the index of this corner with respect to the greatest marked element index, using find instead of count.
1333-
lastAppearanceLgr_lgrEquivCorner = vanishedRefinedCorner_to_itsLastAppearance.at({elemLgr, elemLgrCorn});
1342+
else if(auto corner_candidate_2 = vanishedRefinedCorner_to_itsLastAppearance.find({elemLgr, elemLgrCorn});
1343+
corner_candidate_2 != vanishedRefinedCorner_to_itsLastAppearance.end()) {
1344+
1345+
lastAppearanceLgr_lgrEquivCorner = corner_candidate_2->second; // vanishedRefinedCorner_to_itsLastAppearance.at({elemLgr, elemLgrCorn});
13341346
while (elemLgrAndElemLgrCorner_to_refinedLevelAndRefinedCorner.find(lastAppearanceLgr_lgrEquivCorner) ==
13351347
elemLgrAndElemLgrCorner_to_refinedLevelAndRefinedCorner.end()) {
13361348
const auto& tempLgr_lgrCorner = lastAppearanceLgr_lgrEquivCorner;
13371349
lastAppearanceLgr_lgrEquivCorner = vanishedRefinedCorner_to_itsLastAppearance.at(tempLgr_lgrCorner);
13381350
}
13391351
}
1352+
else {
1353+
const Dune::FieldVector<double,3> vertex = Dune::cpgrid::Entity<3>(*markedElem_to_itsLgr[elemLgr], elemLgrCorn, true).geometry().center();
1354+
lastAppearanceLgr_lgrEquivCorner = findCornerIdx(vertex);
1355+
assert(lastAppearanceLgr_lgrEquivCorner[0]>=0);
1356+
assert(lastAppearanceLgr_lgrEquivCorner[1]>=0);
1357+
}
13401358
refinedCorn = elemLgrAndElemLgrCorner_to_refinedLevelAndRefinedCorner.at(lastAppearanceLgr_lgrEquivCorner)[1];
13411359
}
13421360
aux_refined_face_to_point[face].push_back(refinedCorn);
@@ -1369,6 +1387,19 @@ void populateRefinedCells(const Dune::cpgrid::CpGridData& current_data,
13691387
const std::vector<std::vector<std::array<int,2>>>& cornerInMarkedElemWithEquivRefinedCorner,
13701388
const std::vector<CellRefinementBoundaryInfo>& cellRefinementsInfo)
13711389
{
1390+
auto findCornerIdx = [&](const Dune::FieldVector<double,3>& w) {
1391+
for (const auto& [_, lastCellAndCorner] : vanishedRefinedCorner_to_itsLastAppearance) {
1392+
const auto v = Dune::cpgrid::Entity<3>(*markedElem_to_itsLgr[lastCellAndCorner[0]], lastCellAndCorner[1], true).geometry().center();
1393+
if (!Opm::Lgr::areClose(w,v)) {
1394+
continue;
1395+
}
1396+
else { std::cout<< v[0]<< " " << v[1] << " " << v[2] <<std::endl;
1397+
return lastCellAndCorner;
1398+
}
1399+
}
1400+
return std::array<int,2>{-1,-1};
1401+
};
1402+
13721403
// --- Refined cells ---
13731404
for (std::size_t shiftedLevel = 0; shiftedLevel < refined_cell_count_vec.size(); ++shiftedLevel) {
13741405

@@ -1408,16 +1439,21 @@ void populateRefinedCells(const Dune::cpgrid::CpGridData& current_data,
14081439
lastAppearanceLgr_lgrCorner = cornerInMarkedElemWithEquivRefinedCorner[candidate->second].back();
14091440
}
14101441
else {
1411-
// To locate vanished corners, we need a while-loop, since {elemLgr, elemLgrcorner} leads to
1412-
// {neighboringElemLgr, neighboringElemLgrCornerIdx}, which might have also vanished.
1413-
// Then, use the lastest appearance of the current corner, meaning, the first (and unique one - by construction) that
1414-
// gives elemLgrAndElemLgrCorner_to_adaptedCorner.count( lastAppearanceLgr_lgrCorner ) == 1).
1415-
// This corner lies on the area occupied by a coarse face that got refined and belonged to two marked elements.
1416-
// Get the index of this corner with respect to the greatest marked element index.
1417-
lastAppearanceLgr_lgrCorner = vanishedRefinedCorner_to_itsLastAppearance.at({elemLgr, preAdaptCorn});
1418-
while (elemLgrAndElemLgrCorner_to_refinedLevelAndRefinedCorner.find(lastAppearanceLgr_lgrCorner) == elemLgrAndElemLgrCorner_to_refinedLevelAndRefinedCorner.end()) {
1419-
const auto& tempLgr_lgrCorner = lastAppearanceLgr_lgrCorner;
1420-
lastAppearanceLgr_lgrCorner = vanishedRefinedCorner_to_itsLastAppearance.at(tempLgr_lgrCorner);
1442+
if(auto corner_candidate_2 = vanishedRefinedCorner_to_itsLastAppearance.find({elemLgr, preAdaptCorn});
1443+
corner_candidate_2 != vanishedRefinedCorner_to_itsLastAppearance.end()) {
1444+
1445+
lastAppearanceLgr_lgrCorner = corner_candidate_2->second; // vanishedRefinedCorner_to_itsLastAppearance.at({elemLgr, elemLgrCorn});
1446+
while (elemLgrAndElemLgrCorner_to_refinedLevelAndRefinedCorner.find(lastAppearanceLgr_lgrCorner) ==
1447+
elemLgrAndElemLgrCorner_to_refinedLevelAndRefinedCorner.end()) {
1448+
const auto& tempLgr_lgrCorner = lastAppearanceLgr_lgrCorner;
1449+
lastAppearanceLgr_lgrCorner = vanishedRefinedCorner_to_itsLastAppearance.at(tempLgr_lgrCorner);
1450+
}
1451+
}
1452+
else {
1453+
const auto vertex = Dune::cpgrid::Entity<3>(*markedElem_to_itsLgr[elemLgr], preAdaptCorn, true).geometry().center();
1454+
lastAppearanceLgr_lgrCorner = findCornerIdx(vertex);
1455+
assert(lastAppearanceLgr_lgrCorner[0]>=0);
1456+
assert(lastAppearanceLgr_lgrCorner[1]>=0);
14211457
}
14221458
}
14231459
refinedCorn = elemLgrAndElemLgrCorner_to_refinedLevelAndRefinedCorner.at(lastAppearanceLgr_lgrCorner)[1];
@@ -1511,6 +1547,19 @@ void populateLeafGridFaces(const Dune::cpgrid::CpGridData& current_data,
15111547
[[maybe_unused]] const std::vector<std::array<int,3>>& cells_per_dim_vec,
15121548
[[maybe_unused]] const int& preAdaptMaxLevel)
15131549
{
1550+
auto findCornerIdx = [&](const Dune::FieldVector<double,3>& w) {
1551+
for (const auto& [_, lastCellAndCorner] : vanishedRefinedCorner_to_itsLastAppearance) {
1552+
const auto v = Dune::cpgrid::Entity<3>(*markedElem_to_itsLgr[lastCellAndCorner[0]], lastCellAndCorner[1], true).geometry().center();
1553+
if (!Opm::Lgr::areClose(w,v)) {
1554+
continue;
1555+
}
1556+
else { std::cout<< v[0]<< " " << v[1] << " " << v[2] <<std::endl;
1557+
return lastCellAndCorner;
1558+
}
1559+
}
1560+
return std::array<int,2>{-1,-1};
1561+
};
1562+
15141563
adapted_faces.resize(face_count);
15151564
mutable_face_tags.resize(face_count);
15161565
mutable_face_normals.resize(face_count);
@@ -1564,16 +1613,22 @@ void populateLeafGridFaces(const Dune::cpgrid::CpGridData& current_data,
15641613
elemLgrCorn);
15651614
assert(!isNewRefinedCornInInteriorLgr);
15661615
#endif
1567-
// To locate vanished corners, we need a while-loop, since {elemLgr, elemLgrcorner} leads to
1568-
// {neighboringElemLgr, neighboringElemLgrCornerIdx}, which might have also vanished.
1569-
// Then, use the lastest appearance of the current corner, meaning, the first (and unique one - by construction) that
1570-
// gives elemLgrAndElemLgrCorner_to_adaptedCorner.count(lastAppearanceLgr_lgrEquivCorner) == 1).
1571-
// This corner lies on the area occupied by a coarse face that got refined and belonged to two marked elements.
1572-
// Get the index of this corner with respect to the greatest marked element index, using find instead of count.
1573-
lastAppearanceLgr_lgrEquivCorner = vanishedRefinedCorner_to_itsLastAppearance.at({elemLgr, elemLgrCorn});
1574-
while (elemLgrAndElemLgrCorner_to_adaptedCorner.find( lastAppearanceLgr_lgrEquivCorner ) == elemLgrAndElemLgrCorner_to_adaptedCorner.end()) {
1575-
const auto& tempLgr_lgrCorner = lastAppearanceLgr_lgrEquivCorner;
1576-
lastAppearanceLgr_lgrEquivCorner = vanishedRefinedCorner_to_itsLastAppearance.at(tempLgr_lgrCorner);
1616+
1617+
if(auto corner_candidate_2 = vanishedRefinedCorner_to_itsLastAppearance.find({elemLgr, elemLgrCorn});
1618+
corner_candidate_2 != vanishedRefinedCorner_to_itsLastAppearance.end()) {
1619+
1620+
lastAppearanceLgr_lgrEquivCorner = corner_candidate_2->second; // vanishedRefinedCorner_to_itsLastAppearance.at({elemLgr, elemLgrCorn});
1621+
while (elemLgrAndElemLgrCorner_to_adaptedCorner.find(lastAppearanceLgr_lgrEquivCorner) ==
1622+
elemLgrAndElemLgrCorner_to_adaptedCorner.end()) {
1623+
const auto& tempLgr_lgrCorner = lastAppearanceLgr_lgrEquivCorner;
1624+
lastAppearanceLgr_lgrEquivCorner = vanishedRefinedCorner_to_itsLastAppearance.at(tempLgr_lgrCorner);
1625+
}
1626+
}
1627+
else {
1628+
const auto vertex = Dune::cpgrid::Entity<3>(*markedElem_to_itsLgr[elemLgr], elemLgrCorn, true).geometry().center();
1629+
lastAppearanceLgr_lgrEquivCorner = findCornerIdx(vertex);
1630+
assert(lastAppearanceLgr_lgrEquivCorner[0]>=0);
1631+
assert(lastAppearanceLgr_lgrEquivCorner[1]>=0);
15771632
}
15781633
}
15791634
} // end-if(elemLgr>-1)
@@ -1606,6 +1661,19 @@ void populateLeafGridCells(const Dune::cpgrid::CpGridData& current_data,
16061661
const std::vector<std::vector<std::array<int,2>>>& cornerInMarkedElemWithEquivRefinedCorner,
16071662
const std::vector<CellRefinementBoundaryInfo>& cellRefinementsInfo)
16081663
{
1664+
auto findCornerIdx = [&](const Dune::FieldVector<double,3>& w) {
1665+
for (const auto& [_, lastCellAndCorner] : vanishedRefinedCorner_to_itsLastAppearance) {
1666+
const auto v = Dune::cpgrid::Entity<3>(*markedElem_to_itsLgr[lastCellAndCorner[0]], lastCellAndCorner[1], true).geometry().center();
1667+
if (!Opm::Lgr::areClose(w,v)) {
1668+
continue;
1669+
}
1670+
else { std::cout<< v[0]<< " " << v[1] << " " << v[2] <<std::endl;
1671+
return lastCellAndCorner;
1672+
}
1673+
}
1674+
return std::array<int,2>{-1,-1};
1675+
};
1676+
16091677
// Store the adapted cells. Main difficulty: to lookup correctly the indices of the corners and faces of each cell.
16101678
adapted_cells.resize(cell_count);
16111679
adapted_cell_to_point.resize(cell_count);
@@ -1647,16 +1715,21 @@ void populateLeafGridCells(const Dune::cpgrid::CpGridData& current_data,
16471715
lastAppearanceLgr_lgrEquivCorner = cornerInMarkedElemWithEquivRefinedCorner[candidate->second].back();
16481716
}
16491717
else {
1650-
// To locate vanished corners, we need a while-loop, since {elemLgr, elemLgrcorner} leads to
1651-
// {neighboringElemLgr, neighboringElemLgrCornerIdx}, which might have also vanished.
1652-
// Then, use the lastest appearance of the current corner, meaning, the first (and unique one - by construction) that
1653-
// gives elemLgrAndElemLgrCorner_to_adaptedCorner.count( lastAppearanceLgr_lgrEquivCorner ) == 1).
1654-
// This corner lies on the area occupied by a coarse face that got refined and belonged to two marked elements.
1655-
// Get the index of this corner with respect to the greatest marked element index.
1656-
lastAppearanceLgr_lgrEquivCorner = vanishedRefinedCorner_to_itsLastAppearance.at({elemLgr, preAdaptCorn});
1657-
while (elemLgrAndElemLgrCorner_to_adaptedCorner.find(lastAppearanceLgr_lgrEquivCorner) == elemLgrAndElemLgrCorner_to_adaptedCorner.end()) {
1658-
const auto& tempLgr_lgrCorner = lastAppearanceLgr_lgrEquivCorner;
1659-
lastAppearanceLgr_lgrEquivCorner = vanishedRefinedCorner_to_itsLastAppearance.at(tempLgr_lgrCorner);
1718+
if(auto corner_candidate_2 = vanishedRefinedCorner_to_itsLastAppearance.find({elemLgr, preAdaptCorn});
1719+
corner_candidate_2 != vanishedRefinedCorner_to_itsLastAppearance.end()) {
1720+
1721+
lastAppearanceLgr_lgrEquivCorner = corner_candidate_2->second; // vanishedRefinedCorner_to_itsLastAppearance.at({elemLgr, elemLgrCorn});
1722+
while (elemLgrAndElemLgrCorner_to_adaptedCorner.find(lastAppearanceLgr_lgrEquivCorner) ==
1723+
elemLgrAndElemLgrCorner_to_adaptedCorner.end()) {
1724+
const auto& tempLgr_lgrCorner = lastAppearanceLgr_lgrEquivCorner;
1725+
lastAppearanceLgr_lgrEquivCorner = vanishedRefinedCorner_to_itsLastAppearance.at(tempLgr_lgrCorner);
1726+
}
1727+
}
1728+
else {
1729+
const auto vertex = Dune::cpgrid::Entity<3>(*markedElem_to_itsLgr[elemLgr], preAdaptCorn, true).geometry().center();
1730+
lastAppearanceLgr_lgrEquivCorner = findCornerIdx(vertex);
1731+
assert(lastAppearanceLgr_lgrEquivCorner[0]>=0);
1732+
assert(lastAppearanceLgr_lgrEquivCorner[1]>=0);
16601733
}
16611734
}
16621735
}

opm/grid/cpgrid/LgrHelpers.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,6 @@ void populateRefinedFaces(std::vector<Dune::cpgrid::EntityVariableBase<Dune::cpg
464464
const std::vector<std::vector<std::array<int,2>>>& cornerInMarkedElemWithEquivRefinedCorner,
465465
const std::map<std::array<int,2>,int>& markedElemAndEquivRefinedCorn_to_corner);
466466

467-
468467
/// @brief Define the cells, cell_to_point_, global_cell_, cell_to_face_, face_to_cell_, for each refined level grid.
469468
void populateRefinedCells(const Dune::cpgrid::CpGridData& current_data,
470469
std::vector<Dune::cpgrid::EntityVariableBase<Dune::cpgrid::Geometry<3,3>>>& refined_cells_vec,

0 commit comments

Comments
 (0)