Skip to content

Commit

Permalink
Support for loading only active cell geometry (#11624)
Browse files Browse the repository at this point in the history
* Only load active cells for main grid, skip LGRs for now
* Handle wells with inactive cells
* Validate mapaxes transform before using it.
* Add log message
* Additional guarding when trying to find the geometrical location of a simulation cell
* Add extra safeguarding for init/restart file access in opm common. Only support unified restart files.
  • Loading branch information
jonjenssen authored Aug 28, 2024
1 parent 27c46a6 commit 0572069
Show file tree
Hide file tree
Showing 24 changed files with 670 additions and 78 deletions.
6 changes: 4 additions & 2 deletions ApplicationLibCode/Application/RiaPreferencesGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ RifReaderSettings RiaPreferencesGrid::gridOnlyReaderSettings()
false, // useResultIndexFile
true, // skipWellData
false, // import summary data
"" // include prefix
"", // include prefix,
false // only active cells
};
return rs;
}
Expand All @@ -174,7 +175,8 @@ RifReaderSettings RiaPreferencesGrid::readerSettings()
m_useResultIndexFile,
m_skipWellData,
true, // import summary data
m_includeFileAbsolutePathPrefix };
m_includeFileAbsolutePathPrefix,
m_onlyLoadActiveCells };
return rs;
}

Expand Down
2 changes: 2 additions & 0 deletions ApplicationLibCode/FileInterface/CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RifRevealCsvSectionSummaryReader.h
${CMAKE_CURRENT_LIST_DIR}/RifStimPlanCsvSummaryReader.h
${CMAKE_CURRENT_LIST_DIR}/RifReaderOpmCommon.h
${CMAKE_CURRENT_LIST_DIR}/RifReaderOpmCommonActive.h
${CMAKE_CURRENT_LIST_DIR}/RifEclipseReportKeywords.h
${CMAKE_CURRENT_LIST_DIR}/RifInpExportTools.h
${CMAKE_CURRENT_LIST_DIR}/RifFaultReactivationModelExporter.h
Expand Down Expand Up @@ -188,6 +189,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RifRevealCsvSectionSummaryReader.cpp
${CMAKE_CURRENT_LIST_DIR}/RifStimPlanCsvSummaryReader.cpp
${CMAKE_CURRENT_LIST_DIR}/RifReaderOpmCommon.cpp
${CMAKE_CURRENT_LIST_DIR}/RifReaderOpmCommonActive.cpp
${CMAKE_CURRENT_LIST_DIR}/RifInpExportTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RifFaultReactivationModelExporter.cpp
${CMAKE_CURRENT_LIST_DIR}/RifThermalToStimPlanFractureXmlOutput.cpp
Expand Down
24 changes: 23 additions & 1 deletion ApplicationLibCode/FileInterface/RifReaderEclipseWell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ size_t RifReaderEclipseWell::localGridCellIndexFromErtConnection( const RigGridB
return cvf::UNDEFINED_SIZE_T;
}

if ( ( cellI < 0 ) || ( cellJ < 0 ) )
{
return cvf::UNDEFINED_SIZE_T;
}

return grid->cellIndexFromIJK( cellI, cellJ, cellK );
}

Expand All @@ -158,6 +163,17 @@ RigWellResultPoint RifReaderEclipseWell::createWellResultPoint( const RigEclipse

RigWellResultPoint resultPoint;

if ( ( grid->cellCount() == 0 ) || ( gridCellIndex > grid->cellCount() - 1 ) )
{
return resultPoint;
}

const RigCell& c = grid->cell( gridCellIndex );
if ( c.isInvalid() )
{
return resultPoint;
}

if ( gridCellIndex != cvf::UNDEFINED_SIZE_T )
{
int branchId = -1, segmentId = -1, outletBranchId = -1, outletSegmentId = -1;
Expand Down Expand Up @@ -857,11 +873,17 @@ void RifReaderEclipseWell::readWellCells( RifEclipseRestartDataAccess* restartDa
{
prevResPoint = wellResFrame.wellHead();
}
else
else if ( rpIdx > 0 )
{
prevResPoint = wellResultBranch.branchResultPoints()[rpIdx - 1];
}

if ( !prevResPoint.isCell() )
{
// When importing only active cells, this situation can occur if the well head is a inactive cell.
continue;
}

cvf::Vec3d lastConnectionPos = grids[prevResPoint.gridIndex()]->cell( prevResPoint.cellIndex() ).center();

SegmentPositionContribution
Expand Down
8 changes: 8 additions & 0 deletions ApplicationLibCode/FileInterface/RifReaderInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ const QString RifReaderInterface::faultIncludeFileAbsolutePathPrefix() const
return m_readerSettings.includeFileAbsolutePathPrefix;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifReaderInterface::onlyLoadActiveCells() const
{
return m_readerSettings.onlyLoadActiveCells;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions ApplicationLibCode/FileInterface/RifReaderInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class RifReaderInterface : public cvf::Object
bool includeInactiveCellsInFaultGeometry() const;
bool loadWellDataEnabled() const;
const QString faultIncludeFileAbsolutePathPrefix() const;
bool onlyLoadActiveCells() const;

void setReaderSettings( RifReaderSettings readerSettings );

Expand Down
39 changes: 28 additions & 11 deletions ApplicationLibCode/FileInterface/RifReaderOpmCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "RifOpmRadialGridTools.h"
#include "RifReaderEclipseWell.h"

#include "RigActiveCellGrid.h"
#include "RigActiveCellInfo.h"
#include "RigCaseCellResultsData.h"
#include "RigEclipseCaseData.h"
Expand Down Expand Up @@ -87,18 +88,16 @@ bool RifReaderOpmCommon::open( const QString& fileName, RigEclipseCaseData* ecli
return false;
}

if ( isFaultImportEnabled() )
{
auto task = progress.task( "Reading faults", 25 );

if ( isFaultImportEnabled() )
{
cvf::Collection<RigFault> faults;
cvf::Collection<RigFault> faults;

importFaults( fileSet, &faults );
importFaults( fileSet, &faults );

RigMainGrid* mainGrid = eclipseCaseData->mainGrid();
mainGrid->setFaults( faults );
}
RigMainGrid* mainGrid = eclipseCaseData->mainGrid();
mainGrid->setFaults( faults );
}

m_eclipseCaseData = eclipseCaseData;
Expand All @@ -108,9 +107,10 @@ bool RifReaderOpmCommon::open( const QString& fileName, RigEclipseCaseData* ecli
buildMetaData( eclipseCaseData, progress );
}

auto task = progress.task( "Handling NCC Result data", 25 );
if ( isNNCsEnabled() )
{
auto task = progress.task( "Handling NCC Result data", 25 );

caf::ProgressInfo nncProgress( 10, "" );
RigMainGrid* mainGrid = eclipseCaseData->mainGrid();

Expand Down Expand Up @@ -278,9 +278,11 @@ bool RifReaderOpmCommon::importGrid( RigMainGrid* mainGrid, RigEclipseCaseData*
mapAxes[i] = opmMapAxes[i];
}

double norm_denominator = mapAxes[2] * mapAxes[5] - mapAxes[4] * mapAxes[3];

// Set the map axes transformation matrix on the main grid
mainGrid->setMapAxes( mapAxes );
mainGrid->setUseMapAxes( true );
mainGrid->setUseMapAxes( norm_denominator != 0.0 );

auto transform = mainGrid->mapAxisTransform();

Expand Down Expand Up @@ -414,6 +416,7 @@ void RifReaderOpmCommon::transferGeometry( Opm::EclIO::EGrid& opmMainGrid,

RigCell defaultCell;
defaultCell.setHostGrid( localGrid );

mainGrid->globalCellArray().resize( cellStartIndex + cellCount, defaultCell );

mainGrid->nodes().resize( nodeStartIndex + cellCount * 8, cvf::Vec3d( 0, 0, 0 ) );
Expand Down Expand Up @@ -724,12 +727,26 @@ void RifReaderOpmCommon::setupInitAndRestartAccess()
{
if ( ( m_initFile == nullptr ) && !m_initFileName.empty() )
{
m_initFile = std::make_unique<EclIO::EInit>( m_initFileName );
try
{
m_initFile = std::make_unique<EclIO::EInit>( m_initFileName );
}
catch ( ... )
{
m_initFile = nullptr;
}
}

if ( ( m_restartFile == nullptr ) && !m_restartFileName.empty() )
{
m_restartFile = std::make_unique<EclIO::ERst>( m_restartFileName );
try
{
m_restartFile = std::make_unique<EclIO::ERst>( m_restartFileName );
}
catch ( ... )
{
m_restartFile = nullptr;
}
}
}

Expand Down
53 changes: 28 additions & 25 deletions ApplicationLibCode/FileInterface/RifReaderOpmCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class EGrid;
} // namespace Opm::EclIO

class RigMainGrid;
class RigActiveCellGrid;
class RigGridBase;
class RigEclipseCaseData;
class RigEclipseTimeStepInfo;
Expand All @@ -58,35 +59,37 @@ class RifReaderOpmCommon : public RifReaderInterface

std::vector<QDateTime> timeStepsOnFile( QString gridFileName );

private:
void buildMetaData( RigEclipseCaseData* caseData, caf::ProgressInfo& progress );
bool importGrid( RigMainGrid* mainGrid, RigEclipseCaseData* caseData );
void transferGeometry( Opm::EclIO::EGrid& opmMainGrid,
Opm::EclIO::EGrid& opmGrid,
RigMainGrid* riMainGrid,
RigGridBase* riGrid,
RigEclipseCaseData* caseData );
protected:
virtual bool importGrid( RigMainGrid* mainGrid, RigEclipseCaseData* caseData );

void transferActiveCells( Opm::EclIO::EGrid& opmGrid,
size_t cellStartIndex,
RigEclipseCaseData* eclipseCaseData,
size_t matrixActiveStartIndex,
size_t fractureActiveStartIndex );

void transferStaticNNCData( Opm::EclIO::EGrid& opmMainGrid, std::vector<Opm::EclIO::EGrid>& lgrGrids, RigMainGrid* mainGrid );
void transferDynamicNNCData( RigMainGrid* mainGrid );

void locateInitAndRestartFiles( QString gridFileName );
void setupInitAndRestartAccess();
bool verifyActiveCellInfo( int activeSizeMat, int activeSizeFrac );
void updateActiveCellInfo( RigEclipseCaseData* eclipseCaseData,
Opm::EclIO::EGrid& opmGrid,
std::vector<Opm::EclIO::EGrid>& lgrGrids,
RigMainGrid* mainGrid );

private:
void buildMetaData( RigEclipseCaseData* caseData, caf::ProgressInfo& progress );

std::vector<RigEclipseTimeStepInfo> createFilteredTimeStepInfos();
std::vector<std::vector<int>> readActiveCellInfoFromPorv( RigEclipseCaseData* eclipseCaseData, bool isDualPorosity );

bool verifyActiveCellInfo( int activeSizeMat, int activeSizeFrac );
std::vector<std::vector<int>> readActiveCellInfoFromPorv( RigEclipseCaseData* eclipseCaseData, bool isDualPorosity );
void updateActiveCellInfo( RigEclipseCaseData* eclipseCaseData,
Opm::EclIO::EGrid& opmGrid,
std::vector<Opm::EclIO::EGrid>& lgrGrids,
RigMainGrid* mainGrid );
void transferGeometry( Opm::EclIO::EGrid& opmMainGrid,
Opm::EclIO::EGrid& opmGrid,
RigMainGrid* riMainGrid,
RigGridBase* riGrid,
RigEclipseCaseData* caseData );
void transferDynamicNNCData( RigMainGrid* mainGrid );

void locateInitAndRestartFiles( QString gridFileName );
void setupInitAndRestartAccess();

struct TimeDataFile
{
Expand All @@ -99,22 +102,22 @@ class RifReaderOpmCommon : public RifReaderInterface

std::vector<TimeDataFile> readTimeSteps();

private:
protected:
enum class ActiveType
{
ACTIVE_MATRIX_VALUE = 1,
ACTIVE_FRACTURE_VALUE = 2
};

std::string m_gridFileName;
std::string m_initFileName;
std::string m_restartFileName;
int m_gridUnit;
std::string m_gridFileName;
int m_gridUnit;
std::vector<std::string> m_gridNames;

RigEclipseCaseData* m_eclipseCaseData;

private:
std::string m_initFileName;
std::string m_restartFileName;
std::unique_ptr<Opm::EclIO::ERst> m_restartFile;
std::unique_ptr<Opm::EclIO::EInit> m_initFile;

std::vector<std::string> m_gridNames;
};
Loading

0 comments on commit 0572069

Please sign in to comment.