diff --git a/ApplicationLibCode/FileInterface/RifOpmGridTools.cpp b/ApplicationLibCode/FileInterface/RifOpmGridTools.cpp index b7eef1dcc1..9c3886ccf6 100644 --- a/ApplicationLibCode/FileInterface/RifOpmGridTools.cpp +++ b/ApplicationLibCode/FileInterface/RifOpmGridTools.cpp @@ -100,16 +100,6 @@ void RifOpmGridTools::importCoordinatesForRadialGrid( const std::string& gridFil } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -size_t RifOpmGridTools::cellCount( const std::string& gridFilePath ) -{ - Opm::EclIO::EGrid opmGrid( gridFilePath ); - - return opmGrid.totalNumberOfCells(); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/FileInterface/RifOpmGridTools.h b/ApplicationLibCode/FileInterface/RifOpmGridTools.h index 50df2896b3..d196f74a40 100644 --- a/ApplicationLibCode/FileInterface/RifOpmGridTools.h +++ b/ApplicationLibCode/FileInterface/RifOpmGridTools.h @@ -45,12 +45,10 @@ class RifOpmGridTools // If the grid is radial, the coordinates are imported and adjusted to fit the host cells static void importCoordinatesForRadialGrid( const std::string& gridFilePath, RigMainGrid* mainGrid ); - static size_t cellCount( const std::string& gridFilePath ); - static bool importGrid( const std::string& gridFilePath, RigMainGrid* mainGrid, RigEclipseCaseData* caseData ); + static bool importGrid( const std::string& gridFilePath, RigMainGrid* mainGrid, RigEclipseCaseData* caseData ); static std::vector> activeCellsFromActnumKeyword( Opm::EclIO::EGrid& grid ); -private: static void transferCoordinates( Opm::EclIO::EGrid& opmMainGrid, Opm::EclIO::EGrid& opmGrid, RigMainGrid* riMainGrid, RigGridBase* riGrid ); static void transferCoordinatesCartesian( Opm::EclIO::EGrid& opmMainGrid, Opm::EclIO::EGrid& opmGrid, diff --git a/ApplicationLibCode/FileInterface/RifReaderOpmCommon.cpp b/ApplicationLibCode/FileInterface/RifReaderOpmCommon.cpp index 287fdd8cfb..39a5530236 100644 --- a/ApplicationLibCode/FileInterface/RifReaderOpmCommon.cpp +++ b/ApplicationLibCode/FileInterface/RifReaderOpmCommon.cpp @@ -38,6 +38,7 @@ #include "opm/input/eclipse/Parser/Parser.hpp" #include "opm/input/eclipse/Schedule/Well/Connection.hpp" #include "opm/input/eclipse/Schedule/Well/Well.hpp" +#include "opm/io/eclipse/EGrid.hpp" #include "opm/io/eclipse/EInit.hpp" #include "opm/io/eclipse/ERst.hpp" #include "opm/io/eclipse/RestartFileView.hpp" @@ -65,7 +66,7 @@ RifReaderOpmCommon::~RifReaderOpmCommon() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RifReaderOpmCommon::open( const QString& fileName, RigEclipseCaseData* eclipseCase ) +bool RifReaderOpmCommon::open( const QString& fileName, RigEclipseCaseData* caseData ) { caf::ProgressInfo progress( 100, "Reading Grid" ); @@ -76,7 +77,7 @@ bool RifReaderOpmCommon::open( const QString& fileName, RigEclipseCaseData* ecli { m_gridFileName = fileName.toStdString(); - if ( !RifOpmGridTools::importGrid( m_gridFileName, eclipseCase->mainGrid(), eclipseCase ) ) + if ( !RifOpmGridTools::importGrid( m_gridFileName, caseData->mainGrid(), caseData ) ) { RiaLogging::error( "Failed to open grid file " + fileName ); @@ -92,14 +93,14 @@ bool RifReaderOpmCommon::open( const QString& fileName, RigEclipseCaseData* ecli importFaults( fileSet, &faults ); - RigMainGrid* mainGrid = eclipseCase->mainGrid(); + RigMainGrid* mainGrid = caseData->mainGrid(); mainGrid->setFaults( faults ); } } { auto task = progress.task( "Reading Results Meta data", 50 ); - buildMetaData( eclipseCase ); + buildMetaData( caseData ); } return true; @@ -113,6 +114,53 @@ bool RifReaderOpmCommon::open( const QString& fileName, RigEclipseCaseData* ecli return true; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RifReaderOpmCommon::importGrid( RigMainGrid* mainGrid, RigEclipseCaseData* caseData ) +{ + Opm::EclIO::EGrid opmGrid( m_gridFileName ); + + const auto& dims = opmGrid.dimension(); + mainGrid->setGridPointDimensions( cvf::Vec3st( dims[0] + 1, dims[1] + 1, dims[2] + 1 ) ); + + RigCell defaultCell; + defaultCell.setHostGrid( mainGrid ); + auto cellCount = opmGrid.totalNumberOfCells(); + mainGrid->globalCellArray().resize( cellCount, defaultCell ); + mainGrid->nodes().resize( 8 * cellCount ); + + RifOpmGridTools::transferCoordinatesCartesian( opmGrid, opmGrid, mainGrid, mainGrid, caseData ); + + auto opmMapAxes = opmGrid.get_mapaxes(); + if ( opmMapAxes.size() == 6 ) + { + std::array mapAxes; + for ( size_t i = 0; i < opmMapAxes.size(); ++i ) + { + mapAxes[i] = opmMapAxes[i]; + } + + // Set the map axes transformation matrix on the main grid + mainGrid->setMapAxes( mapAxes ); + mainGrid->setUseMapAxes( true ); + + auto transform = mainGrid->mapAxisTransform(); + + // Invert the transformation matrix to convert from file coordinates to domain coordinates + transform.invert(); + +#pragma omp parallel for + for ( long i = 0; i < static_cast( mainGrid->nodes().size() ); i++ ) + { + auto& n = mainGrid->nodes()[i]; + n.transformPoint( transform ); + } + } + + return true; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/FileInterface/RifReaderOpmCommon.h b/ApplicationLibCode/FileInterface/RifReaderOpmCommon.h index 457d69d12f..6b2100702b 100644 --- a/ApplicationLibCode/FileInterface/RifReaderOpmCommon.h +++ b/ApplicationLibCode/FileInterface/RifReaderOpmCommon.h @@ -28,6 +28,8 @@ class EInit; class ERst; } // namespace Opm::EclIO +class RigMainGrid; + //================================================================================================== // // @@ -38,13 +40,14 @@ class RifReaderOpmCommon : public RifReaderInterface RifReaderOpmCommon(); ~RifReaderOpmCommon() override; - bool open( const QString& fileName, RigEclipseCaseData* eclipseCase ) override; + bool open( const QString& fileName, RigEclipseCaseData* caseData ) override; bool staticResult( const QString& result, RiaDefines::PorosityModelType matrixOrFracture, std::vector* values ) override; bool dynamicResult( const QString& result, RiaDefines::PorosityModelType matrixOrFracture, size_t stepIndex, std::vector* values ) override; private: - void buildMetaData( RigEclipseCaseData* eclipseCase ); + void buildMetaData( RigEclipseCaseData* caseData ); + bool importGrid( RigMainGrid* mainGrid, RigEclipseCaseData* caseData ); struct TimeDataFile {