///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2017 Statoil ASA // // ResInsight is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. // // See the GNU General Public License at // for more details. // ///////////////////////////////////////////////////////////////////////////////// #include "RigReservoirGridTools.h" #include "RiaGuiApplication.h" #include "RifReaderInterface.h" #include "RigActiveCellInfo.h" #include "RigCaseCellResultsData.h" #include "RigEclipseCaseData.h" #include "RigFemPartCollection.h" #include "RigFemPartGrid.h" #include "RigGeoMechCaseData.h" #include "RigMainGrid.h" #include "RimEclipseCase.h" #include "RimEclipseResultCase.h" #include "RimEclipseView.h" #include "RimGeoMechCase.h" #include "RimGridCollection.h" #include "RimMainPlotCollection.h" #include "RimWellLogPlotCollection.h" #include //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- int RigReservoirGridTools::gridCount( RimCase* rimCase ) { RigMainGrid* eclipseMainGrid = RigReservoirGridTools::eclipseMainGrid( rimCase ); RigFemPartCollection* geoMechPartCollection = RigReservoirGridTools::geoMechPartCollection( rimCase ); if ( eclipseMainGrid ) { return static_cast( eclipseMainGrid->gridCount() ); } else if ( geoMechPartCollection ) { return geoMechPartCollection->partCount(); } return 0; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- const cvf::StructGridInterface* RigReservoirGridTools::mainGrid( RimCase* rimCase ) { return gridByIndex( rimCase, 0 ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- const cvf::StructGridInterface* RigReservoirGridTools::gridByIndex( RimCase* rimCase, int gridIndex ) { RigMainGrid* eclipseMainGrid = RigReservoirGridTools::eclipseMainGrid( rimCase ); RigFemPartCollection* geoMechPartCollection = RigReservoirGridTools::geoMechPartCollection( rimCase ); if ( eclipseMainGrid ) { return eclipseMainGrid->gridByIndex( gridIndex ); } else if ( geoMechPartCollection ) { return geoMechPartCollection->part( gridIndex )->getOrCreateStructGrid(); } return nullptr; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- QString RigReservoirGridTools::gridName( RimCase* rimCase, int gridIndex ) { RigMainGrid* eclipseMainGrid = RigReservoirGridTools::eclipseMainGrid( rimCase ); RigFemPartCollection* geoMechPartCollection = RigReservoirGridTools::geoMechPartCollection( rimCase ); if ( eclipseMainGrid ) { return eclipseMainGrid->gridByIndex( gridIndex )->gridName().c_str(); } else if ( geoMechPartCollection ) { return QString::number( gridIndex ); } return ""; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- const RigActiveCellInfo* RigReservoirGridTools::activeCellInfo( Rim3dView* rimView ) { RimEclipseView* eclipseView = dynamic_cast( rimView ); if ( eclipseView ) { return eclipseView->currentActiveCellInfo(); } return nullptr; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RigReservoirGridTools::refreshEclipseCaseDataAndViews( RimEclipseCase* eclipseCase ) { RiaGuiApplication* guiApp = nullptr; if ( RiaGuiApplication::isRunning() ) { guiApp = RiaGuiApplication::instance(); } if ( guiApp ) RiaGuiApplication::clearAllSelections(); deleteAllCachedData( eclipseCase ); RimMainPlotCollection::current()->deleteAllCachedData(); computeCachedData( eclipseCase ); for ( auto view : eclipseCase->reservoirViews() ) { if ( view && view->gridCollection() ) { view->gridCollection()->syncFromMainEclipseGrid(); } } RimMainPlotCollection::current()->wellLogPlotCollection()->loadDataAndUpdateAllPlots(); if ( guiApp ) eclipseCase->createDisplayModelAndUpdateAllViews(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RigMainGrid* RigReservoirGridTools::eclipseMainGrid( RimCase* rimCase ) { RimEclipseCase* eclipseCase = dynamic_cast( rimCase ); if ( eclipseCase && eclipseCase->eclipseCaseData() ) { return eclipseCase->eclipseCaseData()->mainGrid(); } return nullptr; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RigFemPartCollection* RigReservoirGridTools::geoMechPartCollection( RimCase* rimCase ) { RimGeoMechCase* geoMechCase = dynamic_cast( rimCase ); if ( geoMechCase && geoMechCase->geoMechData() ) { return geoMechCase->geoMechData()->femParts(); } return nullptr; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RigReservoirGridTools::computeCachedData( RimEclipseCase* eclipseCase ) { if ( !eclipseCase ) return; RigCaseCellResultsData* cellResultsDataMatrix = eclipseCase->results( RiaDefines::PorosityModelType::MATRIX_MODEL ); RigCaseCellResultsData* cellResultsDataFracture = eclipseCase->results( RiaDefines::PorosityModelType::FRACTURE_MODEL ); RigEclipseCaseData* eclipseCaseData = eclipseCase->eclipseCaseData(); if ( eclipseCaseData ) { eclipseCaseData->mainGrid()->computeCachedData(); eclipseCase->computeActiveCellsBoundingBox(); } if ( cellResultsDataMatrix ) { cellResultsDataMatrix->computeDepthRelatedResults(); cellResultsDataMatrix->computeCellVolumes(); } if ( cellResultsDataFracture ) { cellResultsDataFracture->computeDepthRelatedResults(); } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RigReservoirGridTools::deleteAllCachedData( RimEclipseCase* eclipseCase ) { if ( !eclipseCase ) return; std::vector categoriesToExclude = { RiaDefines::ResultCatType::GENERATED }; RigCaseCellResultsData* cellResultsDataMatrix = eclipseCase->results( RiaDefines::PorosityModelType::MATRIX_MODEL ); if ( cellResultsDataMatrix ) { cellResultsDataMatrix->freeAllocatedResultsData( categoriesToExclude, std::nullopt ); } RigCaseCellResultsData* cellResultsDataFracture = eclipseCase->results( RiaDefines::PorosityModelType::FRACTURE_MODEL ); if ( cellResultsDataFracture ) { cellResultsDataFracture->freeAllocatedResultsData( categoriesToExclude, std::nullopt ); } RigEclipseCaseData* eclipseCaseData = eclipseCase->eclipseCaseData(); if ( eclipseCaseData ) { eclipseCaseData->clearWellCellsInGridCache(); eclipseCaseData->setVirtualPerforationTransmissibilities( nullptr ); } }