Some clean up and fixes

This commit is contained in:
jonjenssen 2024-10-25 03:09:24 +02:00 committed by jonjenssen
parent 78d82acb41
commit db66ec82de
7 changed files with 58 additions and 33 deletions

View File

@ -429,7 +429,9 @@ private:
while ( gridIndex > 0 ) // is lgr while ( gridIndex > 0 ) // is lgr
{ {
const RigCell& connectionCell = m_mainGrid->cellByGridAndGridLocalCellIdx( gridIndex, gridCellIndex ); const RigCell& connectionCell = m_mainGrid->cellByGridAndGridLocalCellIdx( gridIndex, gridCellIndex );
RigGridBase* hostGrid = connectionCell.hostGrid(); if ( connectionCell.isInvalid() ) break;
RigGridBase* hostGrid = connectionCell.hostGrid();
RigLocalGrid* lgrHost = static_cast<RigLocalGrid*>( hostGrid ); RigLocalGrid* lgrHost = static_cast<RigLocalGrid*>( hostGrid );
gridIndex = lgrHost->parentGrid()->gridIndex(); gridIndex = lgrHost->parentGrid()->gridIndex();

View File

@ -147,9 +147,6 @@ bool RifReaderOpmCommon::importGrid( RigMainGrid* mainGrid, RigEclipseCaseData*
Opm::EclIO::EGrid opmGrid( m_gridFileName ); Opm::EclIO::EGrid opmGrid( m_gridFileName );
RigActiveCellInfo* activeCellInfo = eclipseCaseData->activeCellInfo( RiaDefines::PorosityModelType::MATRIX_MODEL );
RigActiveCellInfo* fractureActiveCellInfo = eclipseCaseData->activeCellInfo( RiaDefines::PorosityModelType::FRACTURE_MODEL );
const auto& dims = opmGrid.dimension(); const auto& dims = opmGrid.dimension();
mainGrid->setGridPointDimensions( cvf::Vec3st( dims[0] + 1, dims[1] + 1, dims[2] + 1 ) ); mainGrid->setGridPointDimensions( cvf::Vec3st( dims[0] + 1, dims[1] + 1, dims[2] + 1 ) );
mainGrid->setGridName( "Main grid" ); mainGrid->setGridName( "Main grid" );
@ -184,26 +181,24 @@ bool RifReaderOpmCommon::importGrid( RigMainGrid* mainGrid, RigEclipseCaseData*
const auto& lgrDims = lgrGrids[lgrIdx].dimension(); const auto& lgrDims = lgrGrids[lgrIdx].dimension();
localGrid->setGridPointDimensions( cvf::Vec3st( lgrDims[0] + 1, lgrDims[1] + 1, lgrDims[2] + 1 ) ); localGrid->setGridPointDimensions( cvf::Vec3st( lgrDims[0] + 1, lgrDims[1] + 1, lgrDims[2] + 1 ) );
localGrid->setGridId( lgrIdx + 1 ); localGrid->setGridId( lgrIdx + 1 );
localGrid->setGridName( lgr_names[lgrIdx] ); localGrid->setGridName( lgr_names[lgrIdx] );
mainGrid->addLocalGrid( localGrid );
localGrid->setIndexToStartOfCells( totalCellCount ); localGrid->setIndexToStartOfCells( totalCellCount );
mainGrid->addLocalGrid( localGrid );
totalCellCount += lgrGrids[lgrIdx].totalNumberOfCells(); totalCellCount += lgrGrids[lgrIdx].totalNumberOfCells();
} }
activeCellInfo->setReservoirCellCount( totalCellCount ); // active cell information
fractureActiveCellInfo->setReservoirCellCount( totalCellCount );
mainGrid->reservoirCells().reserve( (size_t)totalCellCount );
mainGrid->nodes().reserve( (size_t)totalCellCount * 8 );
activeCellInfo->setGridCount( 1 + numLGRs );
fractureActiveCellInfo->setGridCount( 1 + numLGRs );
{ {
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 ); auto task = progInfo.task( "Getting Active Cell Information", 1 );
for ( int lgrIdx = 0; lgrIdx < numLGRs; lgrIdx++ ) for ( int lgrIdx = 0; lgrIdx < numLGRs; lgrIdx++ )
@ -242,23 +237,24 @@ bool RifReaderOpmCommon::importGrid( RigMainGrid* mainGrid, RigEclipseCaseData*
fractureActiveCellInfo->computeDerivedData(); fractureActiveCellInfo->computeDerivedData();
} }
// grid geometry
{ {
auto task = progInfo.task( "Loading Main Grid Geometry", 1 ); auto task = progInfo.task( "Loading Main Grid Geometry", 1 );
transferGeometry( opmGrid, opmGrid, mainGrid, mainGrid, eclipseCaseData ); transferGeometry( opmGrid, opmGrid, mainGrid, mainGrid, eclipseCaseData );
}
bool hasParentInfo = ( lgr_parent_names.size() >= (size_t)numLGRs ); bool hasParentInfo = ( lgr_parent_names.size() >= (size_t)numLGRs );
auto task = progInfo.task( "Loading LGR Grid Geometry ", 1 ); auto task2 = progInfo.task( "Loading LGR Grid Geometry ", 1 );
for ( int lgrIdx = 0; lgrIdx < numLGRs; lgrIdx++ ) for ( int lgrIdx = 0; lgrIdx < numLGRs; lgrIdx++ )
{ {
RigGridBase* parentGrid = hasParentInfo ? mainGrid->gridByName( lgr_parent_names[lgrIdx] ) : mainGrid; RigGridBase* parentGrid = hasParentInfo ? mainGrid->gridByName( lgr_parent_names[lgrIdx] ) : mainGrid;
RigLocalGrid* localGrid = static_cast<RigLocalGrid*>( mainGrid->gridById( lgrIdx + 1 ) ); RigLocalGrid* localGrid = static_cast<RigLocalGrid*>( mainGrid->gridById( lgrIdx + 1 ) );
localGrid->setParentGrid( parentGrid ); localGrid->setParentGrid( parentGrid );
transferGeometry( opmGrid, lgrGrids[lgrIdx], mainGrid, localGrid, eclipseCaseData ); transferGeometry( opmGrid, lgrGrids[lgrIdx], mainGrid, localGrid, eclipseCaseData );
}
} }
mainGrid->initAllSubGridsParentGridPointer(); mainGrid->initAllSubGridsParentGridPointer();

View File

@ -77,7 +77,7 @@ bool RifReaderOpmCommonActive::importGrid( RigMainGrid* /* mainGrid*/, RigEclips
m_gridUnit = 3; m_gridUnit = 3;
auto totalCellCount = opmGrid.totalNumberOfCells(); auto totalCellCount = opmGrid.totalNumberOfCells();
auto totalNativeCellCount = opmGrid.totalActiveCells() + 1; // add one inactive cell used as placeholder for all inactive cells auto totalActiveCellCount = opmGrid.totalActiveCells();
auto globalMatrixActiveSize = opmGrid.activeCells(); auto globalMatrixActiveSize = opmGrid.activeCells();
auto globalFractureActiveSize = opmGrid.activeFracCells(); auto globalFractureActiveSize = opmGrid.activeFracCells();
@ -104,10 +104,10 @@ bool RifReaderOpmCommonActive::importGrid( RigMainGrid* /* mainGrid*/, RigEclips
activeGrid->addLocalGrid( localGrid ); activeGrid->addLocalGrid( localGrid );
totalCellCount += lgrGrids[lgrIdx].totalNumberOfCells(); totalCellCount += lgrGrids[lgrIdx].totalNumberOfCells();
totalNativeCellCount += lgrGrids[lgrIdx].totalActiveCells() + 1; totalActiveCellCount += lgrGrids[lgrIdx].totalActiveCells();
} }
activeGrid->setTotalCellCount( totalCellCount ); activeGrid->setTotalActiveCellCount( totalActiveCellCount );
// active cell information // active cell information
{ {
@ -180,10 +180,12 @@ bool RifReaderOpmCommonActive::importGrid( RigMainGrid* /* mainGrid*/, RigEclips
RigGridBase* parentGrid = hasParentInfo ? activeGrid->gridByName( lgr_parent_names[lgrIdx] ) : activeGrid; RigGridBase* parentGrid = hasParentInfo ? activeGrid->gridByName( lgr_parent_names[lgrIdx] ) : activeGrid;
RigActiveCellLocalGrid* localGrid = static_cast<RigActiveCellLocalGrid*>( activeGrid->gridById( lgrIdx + 1 ) ); RigActiveCellLocalGrid* localGrid = dynamic_cast<RigActiveCellLocalGrid*>( activeGrid->gridById( lgrIdx + 1 ) );
localGrid->setParentGrid( parentGrid ); if ( localGrid != nullptr )
{
transferActiveGeometry( opmGrid, lgrGrids[lgrIdx], activeGrid, localGrid, eclipseCaseData ); localGrid->setParentGrid( parentGrid );
transferActiveGeometry( opmGrid, lgrGrids[lgrIdx], activeGrid, localGrid, eclipseCaseData );
}
} }
} }
@ -328,7 +330,7 @@ void RifReaderOpmCommonActive::transferActiveGeometry( Opm::EclIO::EGrid& opmMa
RigEclipseCaseData* eclipseCaseData ) RigEclipseCaseData* eclipseCaseData )
{ {
int cellCount = opmGrid.totalActiveCells(); int cellCount = opmGrid.totalActiveCells();
size_t cellStartIndex = activeGrid->reservoirCells().size(); size_t cellStartIndex = activeGrid->totalCellCount();
size_t nodeStartIndex = activeGrid->nodes().size(); size_t nodeStartIndex = activeGrid->nodes().size();
const bool invalidateLongPyramidCells = invalidateLongThinCells(); const bool invalidateLongPyramidCells = invalidateLongThinCells();
@ -340,6 +342,7 @@ void RifReaderOpmCommonActive::transferActiveGeometry( Opm::EclIO::EGrid& opmMa
const auto newNodeCount = nodeStartIndex + 8 * cellCount; const auto newNodeCount = nodeStartIndex + 8 * cellCount;
activeGrid->nodes().resize( newNodeCount, cvf::Vec3d( 0, 0, 0 ) ); activeGrid->nodes().resize( newNodeCount, cvf::Vec3d( 0, 0, 0 ) );
activeGrid->setTotalCellCount( cellStartIndex + opmGrid.totalNumberOfCells() );
auto& riNodes = activeGrid->nodes(); auto& riNodes = activeGrid->nodes();
auto& riCells = activeGrid->nativeCells(); auto& riCells = activeGrid->nativeCells();

View File

@ -25,11 +25,14 @@
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RigActiveCellGrid::RigActiveCellGrid() RigActiveCellGrid::RigActiveCellGrid()
: m_totalCellCount( 0 )
, m_totalActiveCellCount( 0 )
{ {
m_invalidCell.setInvalid( true ); m_invalidCell.setInvalid( true );
for ( size_t i = 0; i < 8; i++ ) for ( size_t i = 0; i < 8; i++ )
m_invalidCell.cornerIndices()[i] = 0; m_invalidCell.cornerIndices()[i] = 0;
m_invalidCell.setHostGrid( this ); m_invalidCell.setHostGrid( this );
m_invalidCell.setSubGrid( nullptr );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -204,3 +207,19 @@ void RigActiveCellGrid::setTotalCellCount( size_t totalCellCount )
{ {
m_totalCellCount = totalCellCount; m_totalCellCount = totalCellCount;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
size_t RigActiveCellGrid::totalActiveCellCount() const
{
return m_totalActiveCellCount;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigActiveCellGrid::setTotalActiveCellCount( size_t totalActiveCellCount )
{
m_totalActiveCellCount = totalActiveCellCount;
}

View File

@ -47,16 +47,19 @@ public:
// size_t cellCount() const override; // size_t cellCount() const override;
size_t totalCellCount() const override; size_t totalCellCount() const override;
size_t totalActiveCellCount() const;
public: // only for use by file readers! public: // only for use by file readers!
std::map<size_t, RigCell>& nativeCells(); std::map<size_t, RigCell>& nativeCells();
const std::map<size_t, RigCell>& nativeCells() const; const std::map<size_t, RigCell>& nativeCells() const;
void setTotalCellCount( size_t totalCellCount ); void setTotalCellCount( size_t totalCellCount );
void setTotalActiveCellCount( size_t totalActiveCellCount );
private: private:
// std::vector<size_t> m_globalToNativeMap; // std::vector<size_t> m_globalToNativeMap;
// std::vector<size_t> m_nativeToGlobalMap; // std::vector<size_t> m_nativeToGlobalMap;
size_t m_totalCellCount; size_t m_totalCellCount;
size_t m_totalActiveCellCount;
RigCell m_invalidCell; RigCell m_invalidCell;
std::map<size_t, RigCell> m_nativeCells; std::map<size_t, RigCell> m_nativeCells;
}; };

View File

@ -1898,6 +1898,7 @@ void RigCaseCellResultsData::computeDepthRelatedResults()
for ( long cellIdx = 0; cellIdx < static_cast<long>( m_ownerMainGrid->totalCellCount() ); cellIdx++ ) for ( long cellIdx = 0; cellIdx < static_cast<long>( m_ownerMainGrid->totalCellCount() ); cellIdx++ )
{ {
const RigCell& cell = m_ownerMainGrid->cell( cellIdx ); const RigCell& cell = m_ownerMainGrid->cell( cellIdx );
if ( cell.isInvalid() ) continue;
size_t resultIndex = activeCellInfo()->cellResultIndex( cellIdx ); size_t resultIndex = activeCellInfo()->cellResultIndex( cellIdx );
if ( resultIndex == cvf::UNDEFINED_SIZE_T ) continue; if ( resultIndex == cvf::UNDEFINED_SIZE_T ) continue;

View File

@ -335,6 +335,7 @@ cvf::Vec3d RigCell::faceNormalWithAreaLength( cvf::StructGridInterface::FaceType
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
double RigCell::volume() const double RigCell::volume() const
{ {
if ( m_isInvalid ) return 0.0;
const std::vector<cvf::Vec3d>& nodeCoords = m_hostGrid->mainGrid()->nodes(); const std::vector<cvf::Vec3d>& nodeCoords = m_hostGrid->mainGrid()->nodes();
std::array<cvf::Vec3d, 8> hexCorners; std::array<cvf::Vec3d, 8> hexCorners;