Skip to content

Commit 1c8eab2

Browse files
committed
WIP Update containers after neighbor-aware-correction
1 parent 45c5f23 commit 1c8eab2

9 files changed

Lines changed: 231 additions & 162 deletions

opm/grid/cpgrid/CpGrid.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,7 +2003,8 @@ bool CpGrid::refineAndUpdateGrid(bool throwOnFailure,
20032003
preAdapt_level_to_leaf_cells_vec[preAdaptLevel].resize(data[preAdaptLevel]->size(0), -1);
20042004
}
20052005

2006-
Opm::Lgr::ParentAwareCellRefinements parentAwareCellRefinements(currentLeafData().size(0));
2006+
std::vector<Opm::Lgr::CellRefinementBoundaryInfo> cellRefinements(currentLeafData().size(0)); // if a cell has been refined, then
2007+
// its cell-refinement info is stored in gridCellRefinements[ element.index() ]
20072008

20082009
// Ignore marked aquifer cells/connections in globalRefine()/adapt(); throw in addLgrsUpdateLeafView()/autoRef().
20092010
Opm::Lgr::filterMarkedAquiferCellsAndConnections(*this, throwOnFailure);
@@ -2027,7 +2028,7 @@ bool CpGrid::refineAndUpdateGrid(bool throwOnFailure,
20272028
preAdapt_level_to_leaf_cells_vec,
20282029
/* Additional parameters */
20292030
cells_per_dim_vec,
2030-
parentAwareCellRefinements);
2031+
cellRefinements);
20312032

20322033
#if HAVE_MPI
20332034
auto global_markedElem_count = comm().sum(markedElem_count);
@@ -2098,7 +2099,7 @@ bool CpGrid::refineAndUpdateGrid(bool throwOnFailure,
20982099
cornerInMarkedElemWithEquivRefinedCorner,
20992100
faceInMarkedElemAndRefinedFaces,
21002101
cells_per_dim_vec,
2101-
parentAwareCellRefinements);
2102+
cellRefinements);
21022103

21032104
// --- Adapted corners and PreAdapt corners relations ---
21042105
std::map<std::array<int,2>,int> elemLgrAndElemLgrCorner_to_adaptedCorner;
@@ -2118,7 +2119,7 @@ bool CpGrid::refineAndUpdateGrid(bool throwOnFailure,
21182119
vanishedRefinedCorner_to_itsLastAppearance,
21192120
faceInMarkedElemAndRefinedFaces,
21202121
cells_per_dim_vec,
2121-
parentAwareCellRefinements);
2122+
cellRefinements);
21222123

21232124
// FACES
21242125
// Stablish relationships between PreAdapt faces and refined or adapted ones ---
@@ -2135,7 +2136,7 @@ bool CpGrid::refineAndUpdateGrid(bool throwOnFailure,
21352136
markedElem_to_itsLgr,
21362137
assignRefinedLevel,
21372138
faceInMarkedElemAndRefinedFaces,
2138-
parentAwareCellRefinements.refinedFace_to_parentFace);
2139+
cellRefinements);
21392140

21402141
// --- Adapted faces and PreAdapt faces relations ---
21412142
std::map< std::array<int,2>, int > elemLgrAndElemLgrFace_to_adaptedFace;
@@ -2149,7 +2150,7 @@ bool CpGrid::refineAndUpdateGrid(bool throwOnFailure,
21492150
markedElem_to_itsLgr,
21502151
assignRefinedLevel,
21512152
faceInMarkedElemAndRefinedFaces,
2152-
parentAwareCellRefinements.refinedFace_to_parentFace);
2153+
cellRefinements);
21532154

21542155
// Set refined level grids geometries
21552156
// --- Refined corners ---
@@ -2191,7 +2192,7 @@ bool CpGrid::refineAndUpdateGrid(bool throwOnFailure,
21912192
markedElemAndEquivRefinedCorn_to_corner,
21922193
cornerInMarkedElemWithEquivRefinedCorner,
21932194
cells_per_dim_vec,
2194-
parentAwareCellRefinements.refinedFace_to_parentFace);
2195+
cellRefinements);
21952196

21962197
// Update leaf grid geometries
21972198
// --- Adapted corners ---
@@ -2216,7 +2217,7 @@ bool CpGrid::refineAndUpdateGrid(bool throwOnFailure,
22162217
cornerInMarkedElemWithEquivRefinedCorner,
22172218
cells_per_dim_vec,
22182219
preAdaptMaxLevel,
2219-
parentAwareCellRefinements.coincideWithCoarseCorner);
2220+
cellRefinements);
22202221
// --- Adapted cells ---
22212222
Opm::Lgr::populateLeafGridCells(currentLeafData(),
22222223
adapted_cells,
@@ -2236,7 +2237,7 @@ bool CpGrid::refineAndUpdateGrid(bool throwOnFailure,
22362237
cornerInMarkedElemWithEquivRefinedCorner,
22372238
cells_per_dim_vec,
22382239
preAdaptMaxLevel,
2239-
parentAwareCellRefinements.refinedFace_to_parentFace);
2240+
cellRefinements);
22402241

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

opm/grid/cpgrid/CpGridData.cpp

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,11 +1784,12 @@ bool CpGridData::hasNNCs(const std::vector<int>& cellIndices) const
17841784
return hasNNC;
17851785
}
17861786

1787-
std::tuple< const std::shared_ptr<CpGridData>,
1788-
const std::vector<std::array<int,2>>,
1789-
std::unordered_map<int,int>, // extraRefCornIdx_to_parentFaceIdx
1790-
std::vector<int>,
1791-
std::vector<bool>>
1787+
/*std::tuple< const std::shared_ptr<CpGridData>,
1788+
const std::vector<std::array<int,2>>, // parentBoundaryVertexIdx_to_correctedCellRefGridBoundaryVertexIdx
1789+
std::unordered_map<int,int>, // refinedBoundaryCornIdx_to_parentFaceIdx
1790+
std::vector<int>, // refinedFace_to_parentFace
1791+
std::vector<bool>> // coincideWithCoarseCorner*/
1792+
std::pair<std::shared_ptr<CpGridData>, Opm::Lgr::CellRefinementBoundaryInfo>
17921793
CpGridData::refineSingleCell(const std::array<int,3>& cells_per_dim,
17931794
const int& parent_idx,
17941795
std::vector<std::vector<std::pair<int, std::vector<int>>>>& faceInMarkedElemAndRefinedFaces) const
@@ -1798,14 +1799,7 @@ CpGridData::refineSingleCell(const std::array<int,3>& cells_per_dim,
17981799
std::shared_ptr<CpGridData> cellRefGrid_ptr = std::make_shared<CpGridData>(cellRef_data); // ccobj_
17991800
auto& cellRefGrid = *cellRefGrid_ptr;
18001801
Opm::Lgr::GeomData cellRefGeomData(cellRefGrid);
1801-
1802-
/*DefaultGeometryPolicy& cellRef_geometries = cellRefGrid.geometry_;
1803-
std::vector<std::array<int,8>>& refined_cell_to_point = cellRefGrid.cell_to_point_;
1804-
cpgrid::OrientedEntityTable<0,1>& refined_cell_to_face = cellRefGrid.cell_to_face_;
1805-
Opm::SparseTable<int>& refined_face_to_point = cellRefGrid.face_to_point_;
1806-
cpgrid::OrientedEntityTable<1,0>& refined_face_to_cell = refined_grid.face_to_cell_;
1807-
cpgrid::EntityVariable<enum face_tag,1>& refined_face_tags = refined_grid.face_tag_;
1808-
cpgrid::SignedEntityVariable<Dune::FieldVector<double,3>,1>& refined_face_normals = refined_grid.face_normals_;*/
1802+
18091803

18101804
const auto& parentCellToPoint = this->cell_to_point_[parent_idx];
18111805
Opm::Lgr::containsEightDifferentCorners(parentCellToPoint); // refinement supported only for hexahedron
@@ -1863,12 +1857,16 @@ CpGridData::refineSingleCell(const std::array<int,3>& cells_per_dim,
18631857
for (const auto& [parentGridVertexIdx, equivRefVertexIdx] : parentBoundaryVertexIdx_to_correctedCellRefGridBoundaryVertexIdx) {
18641858
coincideWithParentGridVertex[equivRefVertexIdx] = true;
18651859
}
1860+
1861+
Opm::Lgr::CellRefinementBoundaryInfo cellRefinementBoundaryInfo{
1862+
.parentVertex_to_boundaryRefinedVertex = parentBoundaryVertexIdx_to_correctedCellRefGridBoundaryVertexIdx,
1863+
.boundaryRefinedVertex_to_parentFace = correctedCellRefGridBoundaryVertexIdx_to_parentGridFaceIdx,
1864+
.boundaryRefinedFace_to_parentFace = correctedCellRefGridBoundaryFaceIdx_to_parentGridFaceIdx,
1865+
.boundaryRefinedVertexCoincidesWithParentVertex = coincideWithParentGridVertex,
1866+
.parentCellhasSingleFacePerType = hasOnlyOneFacePerType
1867+
};
18661868

1867-
return {cellRefGrid_ptr,
1868-
parentBoundaryVertexIdx_to_correctedCellRefGridBoundaryVertexIdx,
1869-
correctedCellRefGridBoundaryVertexIdx_to_parentGridFaceIdx,
1870-
correctedCellRefGridBoundaryFaceIdx_to_parentGridFaceIdx,
1871-
coincideWithParentGridVertex};
1869+
return {cellRefGrid_ptr, cellRefinementBoundaryInfo};
18721870
}
18731871
else {
18741872
// To store the corrected cell-refinement: aware of multiple parent-cell-faces of the same type (same tag and same orientation).
@@ -1895,12 +1893,17 @@ CpGridData::refineSingleCell(const std::array<int,3>& cells_per_dim,
18951893
for (const auto& [parentGridVertexIdx, equivRefVertexIdx] : parentBoundaryVertexIdx_to_correctedCellRefGridBoundaryVertexIdx) {
18961894
coincideWithParentGridVertex[equivRefVertexIdx] = true;
18971895
}
1896+
1897+
1898+
Opm::Lgr::CellRefinementBoundaryInfo cellRefinementBoundaryInfo{
1899+
.parentVertex_to_boundaryRefinedVertex = parentBoundaryVertexIdx_to_correctedCellRefGridBoundaryVertexIdx,
1900+
.boundaryRefinedVertex_to_parentFace = correctedCellRefGridBoundaryVertexIdx_to_parentGridFaceIdx,
1901+
.boundaryRefinedFace_to_parentFace = correctedCellRefGridBoundaryFaceIdx_to_parentGridFaceIdx,
1902+
.boundaryRefinedVertexCoincidesWithParentVertex = coincideWithParentGridVertex,
1903+
.parentCellhasSingleFacePerType = hasOnlyOneFacePerType
1904+
};
18981905

1899-
return {correctedCellRefGrid_ptr,
1900-
parentBoundaryVertexIdx_to_correctedCellRefGridBoundaryVertexIdx,
1901-
correctedCellRefGridBoundaryVertexIdx_to_parentGridFaceIdx,
1902-
correctedCellRefGridBoundaryFaceIdx_to_parentGridFaceIdx,
1903-
coincideWithParentGridVertex};
1906+
return {correctedCellRefGrid_ptr, cellRefinementBoundaryInfo};
19041907
}
19051908
}
19061909

opm/grid/cpgrid/CpGridData.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class EclipseState;
8282

8383
namespace Lgr{
8484
struct GeomData;
85+
struct CellRefinementBoundaryInfo;
8586
}
8687
}
8788

@@ -523,11 +524,13 @@ class CpGridData
523524
/// 2---3 | | TOP FACE
524525
/// | | 4---5
525526
/// 0---1 BOTTOM FACE
526-
std::tuple< const std::shared_ptr<CpGridData>,
527+
/*std::tuple< const std::shared_ptr<CpGridData>,
527528
const std::vector<std::array<int,2>>, // parent_to_refined_corners(~boundary_old_to_new_corners)
528529
std::unordered_map<int,int>,
529530
std::vector<int>,
530-
std::vector<bool>>
531+
std::vector<bool>>*/
532+
533+
std::pair<std::shared_ptr<CpGridData>, Opm::Lgr::CellRefinementBoundaryInfo>
531534
refineSingleCell(const std::array<int,3>& cells_per_dim,
532535
const int& parent_idx,
533536
std::vector<std::vector<std::pair<int, std::vector<int>>>>& faceInMarkedElemAndRefinedFaces) const;

opm/grid/cpgrid/LgrFaultHelpers.hpp

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace Lgr
6262
{
6363

6464

65-
// Warning: CellRefinementGeomData has reference members which
65+
// Warning: GeomData has reference members which
6666
// make the struct non-default-constructible and non-assignable.
6767
struct GeomData
6868
{
@@ -84,25 +84,101 @@ struct GeomData
8484
Dune::cpgrid::OrientedEntityTable<1,0>& face_to_cell;
8585
Dune::cpgrid::EntityVariable<enum face_tag,1>& face_tags;
8686
Dune::cpgrid::SignedEntityVariable<Dune::FieldVector<double,3>,1>& face_normals;
87+
};
88+
89+
90+
struct CellRefinementBoundaryInfo
91+
{
92+
93+
/* CellRefinementBoundaryInfo(int numVertices,
94+
int numFaces)
95+
: boundaryRefinedFace_to_parentFace(numFaces ),
96+
boundaryRefinedVertexCoincidesWithParentVertex(numVertices)
97+
{}*/
98+
99+
// Parent cell vertex index (including vertices of all parent cell faces) in parent grid,
100+
// mapped to cell refinement boundary vertex index.
101+
std::vector<std::array<int, 2>> parentVertex_to_boundaryRefinedVertex{};
102+
103+
// Vertex index at the boundary of the cell refinement grid,
104+
// to parent face index (in parent grid) where the vertex lies on.
105+
std::unordered_map<int, int> boundaryRefinedVertex_to_parentFace{};
106+
107+
// Face index at the boundary of cell refinement grid, to parent face index
108+
std::vector<int> boundaryRefinedFace_to_parentFace{};
109+
110+
// Whether a refined vertex is the same as an existing parent grid vertex.
111+
std::vector<bool> boundaryRefinedVertexCoincidesWithParentVertex{};
112+
113+
// True if the parent cell contains only one refined face for each face type.
114+
bool parentCellhasSingleFacePerType = true;
87115
};
88116

89-
117+
118+
/*struct GridCellRefinements
119+
{
120+
explicit GridCellRefinements(int gridCellCount)
121+
: cellRefinements(gridCellCount)
122+
{}
123+
124+
std::vector<CellRefinementBoundaryInfo> cellRefinements{};
125+
};
126+
*/
127+
/*struct ParentCellRefinementData
128+
{
129+
explicit ParentCellRefinementData(int parentCellCount)
130+
: cellRefinements(parentCellCount),
131+
hasSingleFacePerType(parentCellCount, true)
132+
{}
133+
134+
// Indexed by parent cell id.
135+
std::vector<CellRefinementInfo> cellRefinements;
136+
137+
// Indexed by parent cell id.
138+
std::vector<bool> hasSingleFacePerType;
139+
};
140+
141+
90142
91143
struct ParentAwareCellRefinements {
92144
93145
ParentAwareCellRefinements(int parentGridTotalCells)
94-
: extraRefinedCornIdx_to_parentFaceIdx(parentGridTotalCells),
146+
: parentBoundaryVertexIdx_to_cellRefGridBoundaryVertexIdx(parentGridTotalCells),
147+
extraRefinedCornIdx_to_parentFaceIdx(parentGridTotalCells),
95148
refinedFace_to_parentFace(parentGridTotalCells),
96149
coincideWithCoarseCorner(parentGridTotalCells),
97150
hasOnlyOneFacePerType(parentGridTotalCells, true)
98151
{}
99152
153+
std::vector<std::vector<std::array<int,2>>> parentBoundaryVertexIdx_to_cellRefGridBoundaryVertexIdx{};
100154
std::vector<std::unordered_map<int,int>> extraRefinedCornIdx_to_parentFaceIdx{}; // a few extra refined corners mapped to he parent face where they lie on
101155
std::vector<std::vector<int>> refinedFace_to_parentFace{};
102156
std::vector<std::vector<bool>> coincideWithCoarseCorner{}; //
103157
std::vector<bool> hasOnlyOneFacePerType{};
104158
};
105159
160+
struct CellRefinementInfo {
161+
162+
CellRefinementInfo(std::vector<std::array<int,2>> parent_to_cellRef_boundaryVertexIdx,
163+
std::unordered_map<int,int> cellRefVtx_to_parentFace,
164+
std::vector<int> refined_to_parent_face,
165+
std::vector<bool> coincideWithCoarseCorner,
166+
bool oneFacePerType)
167+
:
168+
parentBoundaryVertexIdx_to_cellRefGridBoundaryVertexIdx(std::move(parent_to_cellRef_boundaryVertexIdx)),
169+
extraRefinedCornIdx_to_parentFaceIdx(std::move(cellRefVtx_to_parentFace)),
170+
refinedFace_to_parentFace(std::move(refined_to_parent_face)),
171+
coincideWithParentGridVertex(std::move(coincideWithCoarseCorner)),
172+
hasOnlyOneFacePerType(oneFacePerType)
173+
{}
174+
175+
std::vector<std::array<int,2>> parentBoundaryVertexIdx_to_cellRefGridBoundaryVertexIdx{};
176+
std::unordered_map<int,int> extraRefinedCornIdx_to_parentFaceIdx{};
177+
std::vector<int> refinedFace_to_parentFace{};
178+
std::vector<bool> coincideWithParentGridVertex{};
179+
bool hasOnlyOneFacePerType = true;
180+
};
181+
*/
106182

107183
struct FieldVectorLess {
108184
bool operator()(const Dune::FieldVector<double,3>& v,

0 commit comments

Comments
 (0)