diff --git a/ApplicationLibCode/FileInterface/RifReaderOpmCommon.cpp b/ApplicationLibCode/FileInterface/RifReaderOpmCommon.cpp index c8dc20b25e..34afd08973 100644 --- a/ApplicationLibCode/FileInterface/RifReaderOpmCommon.cpp +++ b/ApplicationLibCode/FileInterface/RifReaderOpmCommon.cpp @@ -189,7 +189,7 @@ bool RifReaderOpmCommon::importGrid( RigMainGrid* mainGrid, RigEclipseCaseData* localGrid->setGridName( lgr_names[lgrIdx] ); mainGrid->addLocalGrid( localGrid ); - localGrid->setIndexToStartOfCells( totalCellCount ); + localGrid->setIndexToGlobalStartOfCells( totalCellCount ); totalCellCount += lgrGrids[lgrIdx].totalNumberOfCells(); } diff --git a/ApplicationLibCode/FileInterface/RifReaderOpmCommonActive.cpp b/ApplicationLibCode/FileInterface/RifReaderOpmCommonActive.cpp index 179246b086..f77e7dbf53 100644 --- a/ApplicationLibCode/FileInterface/RifReaderOpmCommonActive.cpp +++ b/ApplicationLibCode/FileInterface/RifReaderOpmCommonActive.cpp @@ -75,7 +75,8 @@ bool RifReaderOpmCommonActive::importGrid( RigMainGrid* /* mainGrid*/, RigEclips else if ( gridUnitStr.starts_with( 'C' ) ) m_gridUnit = 3; - auto totalCellCount = opmGrid.totalActiveCells() + 1; // add one inactive cell used as placeholder for all inactive cells + auto totalCellCount = opmGrid.totalNumberOfCells(); + auto totalNativeCellCount = opmGrid.totalActiveCells() + 1; // add one inactive cell used as placeholder for all inactive cells auto globalMatrixActiveSize = opmGrid.activeCells(); auto globalFractureActiveSize = opmGrid.activeFracCells(); @@ -98,11 +99,11 @@ 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 ); activeGrid->addLocalGrid( localGrid ); - localGrid->setIndexToStartOfCells( totalCellCount ); - - totalCellCount += lgrGrids[lgrIdx].totalActiveCells(); + totalCellCount += lgrGrids[lgrIdx].totalNumberOfCells(); + totalNativeCellCount += lgrGrids[lgrIdx].totalActiveCells() + 1; } // active cell information @@ -123,23 +124,53 @@ bool RifReaderOpmCommonActive::importGrid( RigMainGrid* /* mainGrid*/, RigEclips // TODO - loop over all grids - activeGrid->transferActiveInformation( 0, - eclipseCaseData, - opmGrid.totalActiveCells(), - opmGrid.activeCells(), - opmGrid.activeFracCells(), - opmGrid.active_indexes(), - opmGrid.active_frac_indexes() ); + size_t anInactiveCellIndex = activeGrid->transferActiveInformation( 0, + eclipseCaseData, + opmGrid.totalActiveCells(), + opmGrid.activeCells(), + opmGrid.activeFracCells(), + opmGrid.active_indexes(), + opmGrid.active_frac_indexes(), + 0 ); + + 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 ); + } + + eclipseCaseData->activeCellInfo( RiaDefines::PorosityModelType::MATRIX_MODEL )->computeDerivedData(); + eclipseCaseData->activeCellInfo( RiaDefines::PorosityModelType::FRACTURE_MODEL )->computeDerivedData(); } // grid geometry { - RiaLogging::info( QString( "Loading %0 active of %1 total cells." ) + RiaLogging::info( QString( "Loading %0 active of %1 total cells in main grid." ) .arg( QString::fromStdString( RiaStdStringTools::formatThousandGrouping( opmGrid.totalActiveCells() ) ) ) .arg( QString::fromStdString( RiaStdStringTools::formatThousandGrouping( opmGrid.totalNumberOfCells() ) ) ) ); auto task = progInfo.task( "Loading Active Cell Main Grid Geometry", 1 ); transferActiveGeometry( opmGrid, activeGrid, eclipseCaseData ); + + bool hasParentInfo = ( lgr_parent_names.size() >= (size_t)numLGRs ); + + auto task = progInfo.task( "Loading Active Cell LGR Grid Geometry ", 1 ); + + for ( int lgrIdx = 0; lgrIdx < numLGRs; lgrIdx++ ) + { + RigGridBase* parentGrid = hasParentInfo ? activeGrid->gridByName( lgr_parent_names[lgrIdx] ) : activeGrid; + + RigLocalGrid* localGrid = static_cast( activeGrid->gridById( lgrIdx + 1 ) ); + localGrid->setParentGrid( parentGrid ); + + transferActiveGeometry( opmGrid, lgrGrids[lgrIdx], mainGrid, localGrid, eclipseCaseData ); + } } activeGrid->initAllSubGridsParentGridPointer(); diff --git a/ApplicationLibCode/FileInterface/RifReaderOpmCommonActive.h b/ApplicationLibCode/FileInterface/RifReaderOpmCommonActive.h index 99a2d3224c..e3cfef4e39 100644 --- a/ApplicationLibCode/FileInterface/RifReaderOpmCommonActive.h +++ b/ApplicationLibCode/FileInterface/RifReaderOpmCommonActive.h @@ -35,4 +35,9 @@ public: protected: bool importGrid( RigMainGrid* mainGrid, RigEclipseCaseData* caseData ) override; void transferActiveGeometry( Opm::EclIO::EGrid& opmMainGrid, RigActiveCellGrid* riMainGrid, RigEclipseCaseData* caseData ); + void transferActiveGeometry( Opm::EclIO::EGrid& opmMainGrid, + Opm::EclIO::EGrid& opmGrid, + RigMainGrid* mainGrid, + RigGridBase* localGrid, + RigEclipseCaseData* eclipseCaseData ); }; diff --git a/ApplicationLibCode/ReservoirDataModel/RigActiveCellGrid.cpp b/ApplicationLibCode/ReservoirDataModel/RigActiveCellGrid.cpp index e5a7179161..576b35f884 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigActiveCellGrid.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigActiveCellGrid.cpp @@ -40,17 +40,19 @@ RigActiveCellGrid::~RigActiveCellGrid() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RigActiveCellGrid::transferActiveInformation( int gridIndex, - RigEclipseCaseData* eclipseCaseData, - size_t totalActiveCells, - size_t matrixActiveCells, - size_t fractureActiveCells, - const std::vector& activeMatrixIndexes, - const std::vector& activeFracIndexes ) +size_t RigActiveCellGrid::transferActiveInformation( int gridIndex, + RigEclipseCaseData* eclipseCaseData, + size_t totalActiveCells, + size_t matrixActiveCells, + size_t fractureActiveCells, + const std::vector& activeMatrixIndexes, + const std::vector& activeFracIndexes, + size_t inactiveCellIndex ) { if ( gridIndex == 0 ) { m_globalToNativeMap.clear(); + inactiveCellIndex = 0; } const auto totalCells = activeMatrixIndexes.size(); @@ -59,7 +61,7 @@ void RigActiveCellGrid::transferActiveInformation( int gridI m_globalToNativeMap.resize( cellStartIndex + totalCells ); size_t activeCells = cellStartIndex; - size_t anInactiveCellIdx = cellStartIndex; + size_t anInactiveCellIdx = inactiveCellIndex; for ( size_t i = 0; i < totalCells; i++ ) { @@ -107,9 +109,6 @@ void RigActiveCellGrid::transferActiveInformation( int gridI fractureActiveCellInfo->setCellResultIndex( activeCellIndex, fractureActiveIndex ); } } - - activeCellInfo->computeDerivedData(); - fractureActiveCellInfo->computeDerivedData(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ReservoirDataModel/RigActiveCellGrid.h b/ApplicationLibCode/ReservoirDataModel/RigActiveCellGrid.h index 96d95ec8e8..00f7017baf 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigActiveCellGrid.h +++ b/ApplicationLibCode/ReservoirDataModel/RigActiveCellGrid.h @@ -28,13 +28,14 @@ public: RigActiveCellGrid(); ~RigActiveCellGrid() override; - void transferActiveInformation( int gridIndex, // 0 - main grid, 1 - first LGR... - RigEclipseCaseData* eclipseCaseData, - size_t totalActiveCells, - size_t matrixActiveCells, - size_t fractureActiveCells, - const std::vector& activeMatrixIndexes, - const std::vector& activeFracIndexes ); + size_t transferActiveInformation( int gridIndex, // 0 - main grid, 1 - first LGR... + RigEclipseCaseData* eclipseCaseData, + size_t totalActiveCells, + size_t matrixActiveCells, + size_t fractureActiveCells, + const std::vector& activeMatrixIndexes, + const std::vector& activeFracIndexes, + size_t inactiveCellIndex ); size_t cellIndexFromIJK( size_t i, size_t j, size_t k ) const override; size_t cellIndexFromIJKUnguarded( size_t i, size_t j, size_t k ) const override; diff --git a/ApplicationLibCode/ReservoirDataModel/RigGridBase.cpp b/ApplicationLibCode/ReservoirDataModel/RigGridBase.cpp index d90cedf3da..f743a738d7 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigGridBase.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigGridBase.cpp @@ -30,7 +30,7 @@ RigGridBase::RigGridBase( RigMainGrid* mainGrid ) : m_gridPointDimensions( 0, 0, 0 ) - , m_indexToStartOfCells( 0 ) + , m_indexToGlobalStartOfCells( 0 ) , m_mainGrid( mainGrid ) { if ( mainGrid == nullptr ) @@ -84,9 +84,9 @@ RigCell& RigGridBase::cell( size_t gridLocalCellIndex ) { CVF_ASSERT( m_mainGrid ); - CVF_ASSERT( m_indexToStartOfCells + gridLocalCellIndex < m_mainGrid->globalCellCount() ); + CVF_ASSERT( m_indexToGlobalStartOfCells + gridLocalCellIndex < m_mainGrid->globalCellCount() ); - return m_mainGrid->reservoirCells()[m_indexToStartOfCells + gridLocalCellIndex]; + return m_mainGrid->reservoirCells()[m_indexToGlobalStartOfCells + gridLocalCellIndex]; } //-------------------------------------------------------------------------------------------------- @@ -96,9 +96,9 @@ const RigCell& RigGridBase::cell( size_t gridLocalCellIndex ) const { CVF_ASSERT( m_mainGrid ); - CVF_ASSERT( m_indexToStartOfCells + gridLocalCellIndex < m_mainGrid->globalCellCount() ); + CVF_ASSERT( m_indexToGlobalStartOfCells + gridLocalCellIndex < m_mainGrid->globalCellCount() ); - return m_mainGrid->reservoirCells()[m_indexToStartOfCells + gridLocalCellIndex]; + return m_mainGrid->reservoirCells()[m_indexToGlobalStartOfCells + gridLocalCellIndex]; } //-------------------------------------------------------------------------------------------------- @@ -439,9 +439,13 @@ void RigGridBase::characteristicCellSizes( double* iSize, double* jSize, double* //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -size_t RigGridBase::reservoirCellIndex( size_t gridLocalCellIndex ) const +size_t RigGridBase::localCellIndexToNative( size_t gridLocalCellIndex ) const { - return m_indexToStartOfCells + gridLocalCellIndex; + if ( !m_mainGrid ) return globalCellIndexToNative( gridLocalCellIndex ); + + return m_mainGrid->globalCellIndexToNative( m_indexToGlobalStartOfCells + gridLocalCellIndex ); + + return m_indexToGlobalStartOfCells + gridLocalCellIndex; } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ReservoirDataModel/RigGridBase.h b/ApplicationLibCode/ReservoirDataModel/RigGridBase.h index 8ad74e9a0c..a512e25230 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigGridBase.h +++ b/ApplicationLibCode/ReservoirDataModel/RigGridBase.h @@ -58,6 +58,7 @@ public: // Cell index naming: // - global cell index is the cell index in the IJK global grid + // - local cell index is the cell index in the local IJK grid // - native cell index is the cell index in the cell array, which is the same index if all cells are present, // but could be different if i.e. only active cells are loaded @@ -72,8 +73,8 @@ public: void characteristicCellSizes( double* iSize, double* jSize, double* kSize ) const override; - size_t reservoirCellIndex( size_t gridLocalCellIndex ) const; - void setIndexToStartOfCells( size_t indexToStartOfCells ) { m_indexToStartOfCells = indexToStartOfCells; } + size_t localCellIndexToNative( size_t gridLocalCellIndex ) const; + void setIndexToGlobalStartOfCells( size_t indexToGlobalStartOfCells ) { m_indexToGlobalStartOfCells = indexToGlobalStartOfCells; } void setGridIndex( size_t index ) { m_gridIndex = index; } size_t gridIndex() const { return m_gridIndex; } @@ -135,7 +136,7 @@ private: std::string m_gridName; cvf::Vec3st m_gridPointDimensions; cvf::Vec3st m_cellCount; - size_t m_indexToStartOfCells; ///< Index into the global cell array stored in main-grid where this grids cells starts. + size_t m_indexToGlobalStartOfCells; ///< Index into the global cell array stored in main-grid where this grids cells starts. size_t m_gridIndex; ///< The LGR index of this grid. Starts with 1. Main grid has index 0. int m_gridId; ///< The LGR id of this grid. Main grid has id 0. RigMainGrid* m_mainGrid;