Privatize grid cell array

This commit is contained in:
jonjenssen
2024-10-23 20:43:08 +02:00
committed by jonjenssen
parent 69878f54d3
commit 88118ee4e1
49 changed files with 418 additions and 326 deletions

View File

@@ -668,7 +668,7 @@ bool RifEclipseOutputFileTools::assignActiveCellData( std::vector<std::vector<in
}
// Check if number of cells is matching
if ( eclipseCaseData->mainGrid()->globalCellArray().size() != reservoirCellCount )
if ( eclipseCaseData->mainGrid()->reservoirCells().size() != reservoirCellCount )
{
return false;
}

View File

@@ -161,12 +161,12 @@ bool RifReaderEclipseOutput::transferGridCellData( RigMainGrid* mainGrid
CVF_ASSERT( activeCellInfo && fractureActiveCellInfo );
int cellCount = ecl_grid_get_global_size( localEclGrid );
size_t cellStartIndex = mainGrid->globalCellArray().size();
size_t cellStartIndex = mainGrid->reservoirCells().size();
size_t nodeStartIndex = mainGrid->nodes().size();
RigCell defaultCell;
defaultCell.setHostGrid( localGrid );
mainGrid->globalCellArray().resize( cellStartIndex + cellCount, defaultCell );
mainGrid->reservoirCells().resize( cellStartIndex + cellCount, defaultCell );
mainGrid->nodes().resize( nodeStartIndex + cellCount * 8, cvf::Vec3d( 0, 0, 0 ) );
@@ -175,7 +175,7 @@ bool RifReaderEclipseOutput::transferGridCellData( RigMainGrid* mainGrid
#pragma omp parallel for
for ( int gridLocalCellIndex = 0; gridLocalCellIndex < cellCount; ++gridLocalCellIndex )
{
RigCell& cell = mainGrid->globalCellArray()[cellStartIndex + gridLocalCellIndex];
RigCell& cell = mainGrid->cell( cellStartIndex + gridLocalCellIndex );
cell.setGridLocalCellIndex( gridLocalCellIndex );
@@ -303,7 +303,7 @@ bool RifReaderEclipseOutput::transferGeometry( const ecl_grid_type* mainEclGrid,
// Reserve room for the cells and nodes and fill them with data
mainGrid->globalCellArray().reserve( totalCellCount );
mainGrid->reservoirCells().reserve( totalCellCount );
mainGrid->nodes().reserve( 8 * totalCellCount );
caf::ProgressInfo progInfo( 3 + numLGRs, "" );

View File

@@ -197,7 +197,7 @@ bool RifReaderOpmCommon::importGrid( RigMainGrid* mainGrid, RigEclipseCaseData*
activeCellInfo->setReservoirCellCount( totalCellCount );
fractureActiveCellInfo->setReservoirCellCount( totalCellCount );
mainGrid->globalCellArray().reserve( (size_t)totalCellCount );
mainGrid->reservoirCells().reserve( (size_t)totalCellCount );
mainGrid->nodes().reserve( (size_t)totalCellCount * 8 );
activeCellInfo->setGridCount( 1 + numLGRs );
@@ -411,7 +411,7 @@ void RifReaderOpmCommon::transferGeometry( Opm::EclIO::EGrid& opmMainGrid,
RigEclipseCaseData* eclipseCaseData )
{
int cellCount = opmGrid.totalNumberOfCells();
size_t cellStartIndex = mainGrid->globalCellArray().size();
size_t cellStartIndex = mainGrid->reservoirCells().size();
size_t nodeStartIndex = mainGrid->nodes().size();
const bool invalidateLongPyramidCells = invalidateLongThinCells();
@@ -419,7 +419,7 @@ void RifReaderOpmCommon::transferGeometry( Opm::EclIO::EGrid& opmMainGrid,
RigCell defaultCell;
defaultCell.setHostGrid( localGrid );
mainGrid->globalCellArray().resize( cellStartIndex + cellCount, defaultCell );
mainGrid->reservoirCells().resize( cellStartIndex + cellCount, defaultCell );
mainGrid->nodes().resize( nodeStartIndex + cellCount * 8, cvf::Vec3d( 0, 0, 0 ) );
@@ -456,7 +456,7 @@ void RifReaderOpmCommon::transferGeometry( Opm::EclIO::EGrid& opmMainGrid,
}
auto riReservoirIndex = localGrid->cellIndexFromIJK( opmIJK[0], opmIJK[1], opmIJK[2] );
RigCell& cell = mainGrid->globalCellArray()[cellStartIndex + riReservoirIndex];
RigCell& cell = mainGrid->cell( cellStartIndex + riReservoirIndex );
cell.setGridLocalCellIndex( riReservoirIndex );
// parent cell index

View File

@@ -99,15 +99,25 @@ bool RifReaderOpmCommonActive::importGrid( RigMainGrid* /* mainGrid*/, RigEclips
localGrid->setGridPointDimensions( cvf::Vec3st( lgrDims[0] + 1, lgrDims[1] + 1, lgrDims[2] + 1 ) );
localGrid->setGridId( lgrIdx + 1 );
localGrid->setGridName( lgr_names[lgrIdx] );
localGrid->setIndexToGlobalStartOfCells( totalCellCount );
localGrid->setIndexToStartOfCells( totalCellCount );
activeGrid->addLocalGrid( localGrid );
totalCellCount += lgrGrids[lgrIdx].totalNumberOfCells();
totalNativeCellCount += lgrGrids[lgrIdx].totalActiveCells() + 1;
}
activeGrid->setTotalCellCount( totalCellCount );
// active cell information
{
RigActiveCellInfo* activeCellInfo = eclipseCaseData->activeCellInfo( RiaDefines::PorosityModelType::MATRIX_MODEL );
RigActiveCellInfo* fractureActiveCellInfo = eclipseCaseData->activeCellInfo( RiaDefines::PorosityModelType::FRACTURE_MODEL );
activeCellInfo->setReservoirCellCount( totalCellCount );
fractureActiveCellInfo->setReservoirCellCount( totalCellCount );
activeCellInfo->setGridCount( 1 + numLGRs );
fractureActiveCellInfo->setGridCount( 1 + numLGRs );
auto task = progInfo.task( "Getting Active Cell Information", 1 );
for ( int lgrIdx = 0; lgrIdx < numLGRs; lgrIdx++ )
@@ -122,29 +132,28 @@ bool RifReaderOpmCommonActive::importGrid( RigMainGrid* /* mainGrid*/, RigEclips
updateActiveCellInfo( eclipseCaseData, opmGrid, lgrGrids, activeGrid );
}
size_t anInactiveCellIndex = activeGrid->transferActiveInformation( 0,
eclipseCaseData,
opmGrid.totalActiveCells(),
opmGrid.activeCells(),
opmGrid.activeFracCells(),
opmGrid.active_indexes(),
opmGrid.active_frac_indexes(),
0 );
globalMatrixActiveSize = opmGrid.activeCells();
globalFractureActiveSize = opmGrid.activeFracCells();
activeCellInfo->setGridActiveCellCounts( 0, globalMatrixActiveSize );
fractureActiveCellInfo->setGridActiveCellCounts( 0, globalFractureActiveSize );
transferActiveCells( opmGrid, 0, eclipseCaseData, 0, 0 );
size_t cellCount = opmGrid.totalNumberOfCells();
for ( int lgrIdx = 0; lgrIdx < numLGRs; lgrIdx++ )
{
activeGrid->transferActiveInformation( lgrIdx + 1,
eclipseCaseData,
lgrGrids[lgrIdx].totalActiveCells(),
lgrGrids[lgrIdx].activeCells(),
lgrGrids[lgrIdx].activeFracCells(),
lgrGrids[lgrIdx].active_indexes(),
lgrGrids[lgrIdx].active_frac_indexes(),
anInactiveCellIndex );
auto& lgrGrid = lgrGrids[lgrIdx];
transferActiveCells( lgrGrid, cellCount, eclipseCaseData, globalMatrixActiveSize, globalFractureActiveSize );
cellCount += lgrGrid.totalNumberOfCells();
globalMatrixActiveSize += lgrGrid.activeCells();
globalFractureActiveSize += lgrGrid.activeFracCells();
activeCellInfo->setGridActiveCellCounts( lgrIdx + 1, lgrGrid.activeCells() );
fractureActiveCellInfo->setGridActiveCellCounts( lgrIdx + 1, lgrGrid.activeFracCells() );
}
eclipseCaseData->activeCellInfo( RiaDefines::PorosityModelType::MATRIX_MODEL )->computeDerivedData();
eclipseCaseData->activeCellInfo( RiaDefines::PorosityModelType::FRACTURE_MODEL )->computeDerivedData();
activeCellInfo->computeDerivedData();
fractureActiveCellInfo->computeDerivedData();
}
// grid geometry
@@ -158,7 +167,7 @@ bool RifReaderOpmCommonActive::importGrid( RigMainGrid* /* mainGrid*/, RigEclips
bool hasParentInfo = ( lgr_parent_names.size() >= (size_t)numLGRs );
auto task = progInfo.task( "Loading Active Cell LGR Grid Geometry ", 1 );
auto task2 = progInfo.task( "Loading Active Cell LGR Grid Geometry ", 1 );
for ( int lgrIdx = 0; lgrIdx < numLGRs; lgrIdx++ )
{
@@ -328,12 +337,11 @@ void RifReaderOpmCommonActive::transferActiveGeometry( Opm::EclIO::EGrid& opmMa
for ( size_t i = 0; i < 8; i++ )
defaultCell.cornerIndices()[i] = 0;
const auto newCellCount = cellStartIndex + cellCount + 1;
activeGrid->reservoirCells().resize( newCellCount, defaultCell );
activeGrid->reservoirCells()[newCellCount - 1].setInvalid( true );
activeGrid->nodes().resize( (newCellCount)*8, cvf::Vec3d( 0, 0, 0 ) );
const auto newNodeCount = nodeStartIndex + 8 * cellCount;
activeGrid->nodes().resize( newNodeCount, cvf::Vec3d( 0, 0, 0 ) );
auto& riNodes = activeGrid->nodes();
auto& riCells = activeGrid->nativeCells();
opmGrid.loadData();
opmGrid.load_grid_data();
@@ -351,6 +359,20 @@ void RifReaderOpmCommonActive::transferActiveGeometry( Opm::EclIO::EGrid& opmMa
// use same mapping as resdata
const size_t cellMappingECLRi[8] = { 0, 1, 3, 2, 4, 5, 7, 6 };
std::map<int, int> activeCellMap;
int nativeIdx = 0;
// non-parallell loop to set up and initialize things so that we can run in parallell later
for ( int opmCellIndex = 0; opmCellIndex < static_cast<int>( opmGrid.totalNumberOfCells() ); opmCellIndex++ )
{
if ( ( activeMatIndexes[opmCellIndex] < 0 ) && ( activeFracIndexes[opmCellIndex] < 0 ) ) continue;
auto opmIJK = opmGrid.ijk_from_global_index( opmCellIndex );
auto localIndex = localGrid->cellIndexFromIJK( opmIJK[0], opmIJK[1], opmIJK[2] );
riCells[cellStartIndex + localIndex] = defaultCell;
activeCellMap[opmCellIndex] = nativeIdx++;
}
#pragma omp parallel for
for ( int opmCellIndex = 0; opmCellIndex < static_cast<int>( opmGrid.totalNumberOfCells() ); opmCellIndex++ )
{
@@ -368,9 +390,9 @@ void RifReaderOpmCommonActive::transferActiveGeometry( Opm::EclIO::EGrid& opmMa
yCenterCoordOpm = yCenter;
}
auto nativeIndex = activeGrid->cellIndexFromIJK( opmIJK[0], opmIJK[1], opmIJK[2] );
RigCell& cell = activeGrid->nativeCell( cellStartIndex + nativeIndex );
cell.setGridLocalCellIndex( nativeIndex );
auto localIndex = localGrid->cellIndexFromIJK( opmIJK[0], opmIJK[1], opmIJK[2] );
RigCell& cell = riCells[cellStartIndex + localIndex];
cell.setGridLocalCellIndex( localIndex );
// parent cell index
if ( ( hostCellGlobalIndices.size() > (size_t)opmCellIndex ) && hostCellGlobalIndices[opmCellIndex] >= 0 )
@@ -389,7 +411,8 @@ void RifReaderOpmCommonActive::transferActiveGeometry( Opm::EclIO::EGrid& opmMa
opmGrid.getCellCorners( opmCellIndex, opmX, opmY, opmZ );
// Each cell has 8 nodes, use active cell index and multiply to find first node index for cell
auto riNodeStartIndex = nodeStartIndex + nativeIndex * 8;
auto localNodeIndex = activeCellMap[opmCellIndex] * 8;
auto riNodeStartIndex = nodeStartIndex + localNodeIndex;
for ( size_t opmNodeIndex = 0; opmNodeIndex < 8; opmNodeIndex++ )
{
@@ -425,6 +448,4 @@ void RifReaderOpmCommonActive::transferActiveGeometry( Opm::EclIO::EGrid& opmMa
cell.setInvalid( cell.isLongPyramidCell() );
}
}
if ( riNodes.size() > 1 ) riNodes[riNodes.size() - 1] = riNodes[0];
}

View File

@@ -188,19 +188,19 @@ bool RifRoffFileTools::openGridFile( const QString& fileName, RigEclipseCaseData
fractureActiveCellInfo->setReservoirCellCount( totalCellCount );
// Reserve room for the cells and nodes and fill them with data
mainGrid->globalCellArray().reserve( totalCellCount );
mainGrid->reservoirCells().reserve( totalCellCount );
mainGrid->nodes().reserve( 8 * totalCellCount );
int progTicks = 100;
caf::ProgressInfo progInfo( progTicks, "" );
int cellCount = static_cast<int>( totalCellCount );
size_t cellStartIndex = mainGrid->globalCellArray().size();
size_t cellStartIndex = mainGrid->reservoirCells().size();
size_t nodeStartIndex = mainGrid->nodes().size();
RigCell defaultCell;
defaultCell.setHostGrid( mainGrid );
mainGrid->globalCellArray().resize( cellStartIndex + cellCount, defaultCell );
mainGrid->reservoirCells().resize( cellStartIndex + cellCount, defaultCell );
mainGrid->nodes().resize( nodeStartIndex + static_cast<size_t>( cellCount ) * 8, cvf::Vec3d( 0, 0, 0 ) );
@@ -220,7 +220,7 @@ bool RifRoffFileTools::openGridFile( const QString& fileName, RigEclipseCaseData
#pragma omp for
for ( int gridLocalCellIndex = 0; gridLocalCellIndex < cellCount; ++gridLocalCellIndex )
{
RigCell& cell = mainGrid->globalCellArray()[cellStartIndex + gridLocalCellIndex];
RigCell& cell = mainGrid->cell( cellStartIndex + gridLocalCellIndex );
cell.setGridLocalCellIndex( gridLocalCellIndex );