From 0ec612ae8663f65830edbeef9289fe0ad6ed3260 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 26 Jan 2021 20:34:31 +0100 Subject: [PATCH] Create LGR : Use all well cells if no completions are defined (#7285) * #7274 Create LGR : Use all well cells if no completions are defined * #7263 Create LGR : Not working in console mode Guard access to RiaApplication * Add pytest for create_lgr_for_completion * Add pytest for create_lgr_for_completion * #7289 Script : Add execute of last used script * #7291 Python : Guard access to RiaMainWindow --- .../RiaCompletionTypeCalculationScheduler.cpp | 26 ++++++-- .../RiaCompletionTypeCalculationScheduler.h | 8 +-- .../ExportCommands/RicExportLgrFeature.cpp | 59 ++++++++++++++++--- .../ExportCommands/RicExportLgrFeature.h | 3 + .../Commands/RicCreateTemporaryLgrFeature.cpp | 10 +++- .../code_names_and_values_mismatch.roff | 0 .../RifRoffReader/code_names_missing.roff | 0 .../code_values_integer_wrong.roff | 0 .../RifRoffReader/code_values_missing.roff | 0 .../TestData/RifRoffReader/facies_info.roff | 0 .../Python/rips/tests/test_commands.py | 15 +++++ 11 files changed, 101 insertions(+), 20 deletions(-) mode change 100644 => 100755 ApplicationLibCode/UnitTests/TestData/RifRoffReader/code_names_and_values_mismatch.roff mode change 100644 => 100755 ApplicationLibCode/UnitTests/TestData/RifRoffReader/code_names_missing.roff mode change 100644 => 100755 ApplicationLibCode/UnitTests/TestData/RifRoffReader/code_values_integer_wrong.roff mode change 100644 => 100755 ApplicationLibCode/UnitTests/TestData/RifRoffReader/code_values_missing.roff mode change 100644 => 100755 ApplicationLibCode/UnitTests/TestData/RifRoffReader/facies_info.roff diff --git a/ApplicationLibCode/Application/RiaCompletionTypeCalculationScheduler.cpp b/ApplicationLibCode/Application/RiaCompletionTypeCalculationScheduler.cpp index f2c6e6de03..1cc4c0b9ed 100644 --- a/ApplicationLibCode/Application/RiaCompletionTypeCalculationScheduler.cpp +++ b/ApplicationLibCode/Application/RiaCompletionTypeCalculationScheduler.cpp @@ -33,11 +33,11 @@ #include "RiuViewer.h" #include "cafPdmUiTreeView.h" +#include "cafProgressState.h" #include #include -#include "cafProgressState.h" #include //-------------------------------------------------------------------------------------------------- @@ -112,8 +112,13 @@ void RiaCompletionTypeCalculationScheduler::slotRecalculateCompletionType() std::set uniqueCases( m_eclipseCasesToRecalculate.begin(), m_eclipseCasesToRecalculate.end() ); - Rim3dView* activeView = RiaApplication::instance()->activeReservoirView(); - QModelIndex mi = RiuMainWindow::instance()->projectTreeView()->treeView()->currentIndex(); + Rim3dView* activeView = RiaApplication::instance()->activeReservoirView(); + + QModelIndex mi; + if ( RiuMainWindow::instance() ) + { + mi = RiuMainWindow::instance()->projectTreeView()->treeView()->currentIndex(); + } for ( RimEclipseCase* eclipseCase : uniqueCases ) { @@ -138,10 +143,13 @@ void RiaCompletionTypeCalculationScheduler::slotRecalculateCompletionType() if ( activeView && activeView->viewer() ) { RiaApplication::instance()->setActiveReservoirView( activeView ); - RiuMainWindow::instance()->setActiveViewer( activeView->viewer()->layoutWidget() ); + if ( RiuMainWindow::instance() ) + { + RiuMainWindow::instance()->setActiveViewer( activeView->viewer()->layoutWidget() ); + } } - if ( mi.isValid() ) + if ( mi.isValid() && RiuMainWindow::instance() ) { RiuMainWindow::instance()->projectTreeView()->treeView()->setCurrentIndex( mi ); } @@ -155,6 +163,14 @@ RiaCompletionTypeCalculationScheduler::~RiaCompletionTypeCalculationScheduler() delete m_recalculateCompletionTypeTimer; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiaCompletionTypeCalculationScheduler::RiaCompletionTypeCalculationScheduler() + : m_recalculateCompletionTypeTimer( nullptr ) +{ +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/Application/RiaCompletionTypeCalculationScheduler.h b/ApplicationLibCode/Application/RiaCompletionTypeCalculationScheduler.h index 63654cf02a..9ea5fb94c3 100644 --- a/ApplicationLibCode/Application/RiaCompletionTypeCalculationScheduler.h +++ b/ApplicationLibCode/Application/RiaCompletionTypeCalculationScheduler.h @@ -27,6 +27,9 @@ class QTimer; class RimEclipseCase; +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- class RiaCompletionTypeCalculationScheduler : public QObject { Q_OBJECT; @@ -40,10 +43,7 @@ private slots: void slotRecalculateCompletionType(); private: - RiaCompletionTypeCalculationScheduler() - : m_recalculateCompletionTypeTimer( nullptr ) - { - } + RiaCompletionTypeCalculationScheduler(); ~RiaCompletionTypeCalculationScheduler() override; RiaCompletionTypeCalculationScheduler( const RiaCompletionTypeCalculationScheduler& o ) = delete; diff --git a/ApplicationLibCode/Commands/ExportCommands/RicExportLgrFeature.cpp b/ApplicationLibCode/Commands/ExportCommands/RicExportLgrFeature.cpp index 0bf9e1f533..43f76b32b2 100644 --- a/ApplicationLibCode/Commands/ExportCommands/RicExportLgrFeature.cpp +++ b/ApplicationLibCode/Commands/ExportCommands/RicExportLgrFeature.cpp @@ -476,6 +476,13 @@ std::vector { auto intersectingCells = cellsIntersectingCompletions( eclipseCase, wellPath, timeStep, completionTypes, &isIntersectingOtherLgrs ); + + if ( intersectingCells.empty() ) + { + // Find all grid cells intersected by well path + intersectingCells = allIntersectedCells( eclipseCase, wellPath ); + } + auto newLgrs = buildLgrsPerMainCell( firstLgrId + (int)lgrs.size(), eclipseCase, wellPath, @@ -494,13 +501,15 @@ std::vector timeStep, completionTypes, wellsIntersectingOtherLgrs ); - - auto newLgrs = buildLgrsPerCompletion( firstLgrId + (int)lgrs.size(), - eclipseCase, - intersectingCells, - lgrCellCounts, - lgrNameFactory ); - lgrs.insert( lgrs.end(), newLgrs.begin(), newLgrs.end() ); + if ( !intersectingCells.empty() ) + { + auto newLgrs = buildLgrsPerCompletion( firstLgrId + (int)lgrs.size(), + eclipseCase, + intersectingCells, + lgrCellCounts, + lgrNameFactory ); + lgrs.insert( lgrs.end(), newLgrs.begin(), newLgrs.end() ); + } } else if ( splitType == Lgr::LGR_PER_WELL ) { @@ -511,11 +520,23 @@ std::vector auto intersectingCells = cellsIntersectingCompletions( eclipseCase, wellPath, timeStep, completionTypes, &isIntersectingOtherLgrs ); - lgrs.push_back( buildLgr( lgrId, lgrName, eclipseCase, wellPath->name(), intersectingCells, lgrCellCounts ) ); + + if ( intersectingCells.empty() ) + { + // Find all grid cells intersected by well path + intersectingCells = allIntersectedCells( eclipseCase, wellPath ); + } + + if ( !intersectingCells.empty() ) + { + lgrs.push_back( + buildLgr( lgrId, lgrName, eclipseCase, wellPath->name(), intersectingCells, lgrCellCounts ) ); + } if ( isIntersectingOtherLgrs ) wellsIntersectingOtherLgrs->push_back( wellPath->name() ); } } + return lgrs; } @@ -745,6 +766,28 @@ std::map> return completionToCells; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RicExportLgrFeature::allIntersectedCells( RimEclipseCase* eclipseCase, + const RimWellPath* wellPath ) +{ + std::vector cells; + + const RigMainGrid* mainGrid = eclipseCase->mainGrid(); + + auto globalCellIndices = + RigWellPathIntersectionTools::findIntersectedGlobalCellIndices( eclipseCase->eclipseCaseData(), + wellPath->wellPathGeometry()->wellPathPoints() ); + + for ( const auto& globalCellIndex : globalCellIndices ) + { + cells.push_back( RigCompletionDataGridCell( globalCellIndex, mainGrid ) ); + } + + return cells; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/Commands/ExportCommands/RicExportLgrFeature.h b/ApplicationLibCode/Commands/ExportCommands/RicExportLgrFeature.h index 36dab88db0..33038992ca 100644 --- a/ApplicationLibCode/Commands/ExportCommands/RicExportLgrFeature.h +++ b/ApplicationLibCode/Commands/ExportCommands/RicExportLgrFeature.h @@ -228,6 +228,9 @@ private: const std::set& completionTypes, QStringList* wellsIntersectingOtherLgrs ); + static std::vector allIntersectedCells( RimEclipseCase* eclipseCase, + const RimWellPath* wellPath ); + static int firstAvailableLgrId( const RigMainGrid* mainGrid ); static const RigGridBase* hostGrid( const RigMainGrid* mainGrid, size_t reservoirCellIndex ); }; diff --git a/ApplicationLibCode/Commands/RicCreateTemporaryLgrFeature.cpp b/ApplicationLibCode/Commands/RicCreateTemporaryLgrFeature.cpp index a367453399..6dfbc6684f 100644 --- a/ApplicationLibCode/Commands/RicCreateTemporaryLgrFeature.cpp +++ b/ApplicationLibCode/Commands/RicCreateTemporaryLgrFeature.cpp @@ -114,9 +114,13 @@ void RicCreateTemporaryLgrFeature::createLgrsForWellPaths( std::vectorclearAllSelections(); + if ( guiApp ) guiApp->clearAllSelections(); deleteAllCachedData( eclipseCase ); RimProject::current()->mainPlotCollection()->deleteAllCachedData(); @@ -124,7 +128,7 @@ void RicCreateTemporaryLgrFeature::updateViews( RimEclipseCase* eclipseCase ) RimProject::current()->mainPlotCollection()->wellLogPlotCollection()->reloadAllPlots(); - eclipseCase->createDisplayModelAndUpdateAllViews(); + if ( guiApp ) eclipseCase->createDisplayModelAndUpdateAllViews(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/UnitTests/TestData/RifRoffReader/code_names_and_values_mismatch.roff b/ApplicationLibCode/UnitTests/TestData/RifRoffReader/code_names_and_values_mismatch.roff old mode 100644 new mode 100755 diff --git a/ApplicationLibCode/UnitTests/TestData/RifRoffReader/code_names_missing.roff b/ApplicationLibCode/UnitTests/TestData/RifRoffReader/code_names_missing.roff old mode 100644 new mode 100755 diff --git a/ApplicationLibCode/UnitTests/TestData/RifRoffReader/code_values_integer_wrong.roff b/ApplicationLibCode/UnitTests/TestData/RifRoffReader/code_values_integer_wrong.roff old mode 100644 new mode 100755 diff --git a/ApplicationLibCode/UnitTests/TestData/RifRoffReader/code_values_missing.roff b/ApplicationLibCode/UnitTests/TestData/RifRoffReader/code_values_missing.roff old mode 100644 new mode 100755 diff --git a/ApplicationLibCode/UnitTests/TestData/RifRoffReader/facies_info.roff b/ApplicationLibCode/UnitTests/TestData/RifRoffReader/facies_info.roff old mode 100644 new mode 100755 diff --git a/GrpcInterface/Python/rips/tests/test_commands.py b/GrpcInterface/Python/rips/tests/test_commands.py index bdb7070de4..3c0c56d6f5 100644 --- a/GrpcInterface/Python/rips/tests/test_commands.py +++ b/GrpcInterface/Python/rips/tests/test_commands.py @@ -8,3 +8,18 @@ sys.path.insert(1, os.path.join(sys.path[0], '../../')) import rips import dataroot + +def test_create_lgr_well(rips_instance, initialize_test): + case = rips_instance.project.load_case( + dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID") + assert(case.name == "TEST10K_FLT_LGR_NNC") + assert(len(case.grids()) == 2) + + well_files=[dataroot.PATH + "/TEST10K_FLT_LGR_NNC/wellpath_a.dev"] + rips_instance.project.import_well_paths(well_path_files=well_files) + + time_step=5 + well_path_names=["Well Path A"] + case.create_lgr_for_completion(time_step, well_path_names, refinement_i=2, refinement_j=3,refinement_k=1, split_type="LGR_PER_WELL") + assert(len(case.grids()) == 3) +