From 8a11c565f3fc7bce70511ce74a0e356f04eced3e Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 4 Oct 2019 15:55:31 +0200 Subject: [PATCH 1/2] #4827 Completion Data : Support Eclipse input text files as data source --- .../RicExportFractureCompletionsImpl.cpp | 43 +++++++-- .../RicExportFractureCompletionsImpl.h | 3 + .../ProjectDataModel/RimEclipseCase.cpp | 24 ----- .../ProjectDataModel/RimEclipseCase.h | 1 - .../RigCaseCellResultsData.cpp | 95 ++++++++++++------- .../RigCaseCellResultsData.h | 8 ++ 6 files changed, 109 insertions(+), 65 deletions(-) diff --git a/ApplicationCode/Commands/CompletionExportCommands/RicExportFractureCompletionsImpl.cpp b/ApplicationCode/Commands/CompletionExportCommands/RicExportFractureCompletionsImpl.cpp index 8d5f7bab13..49f8dce40f 100644 --- a/ApplicationCode/Commands/CompletionExportCommands/RicExportFractureCompletionsImpl.cpp +++ b/ApplicationCode/Commands/CompletionExportCommands/RicExportFractureCompletionsImpl.cpp @@ -148,15 +148,22 @@ std::vector RicExportFractureCompletionsImpl::generateCompdat return fractureCompletions; } + auto cellResultsData = caseToApply->results( RiaDefines::MATRIX_MODEL ); + if ( !cellResultsData ) + { + return fractureCompletions; + } + { // Load the data required by computations to be able to use const access only inside OpenMP loop std::vector resultNames = RigEclipseToStimPlanCellTransmissibilityCalculator::requiredResultNames(); - if ( !caseToApply->loadStaticResultsByName( resultNames ) ) + bool loadingSucceeded = RicExportFractureCompletionsImpl::loadResultsByName( cellResultsData, resultNames ); + if ( !loadingSucceeded ) { QString msg; - msg += "Compdat Export : Required data missing. Required results "; + msg += "Compdat Export : One or more of the following required data missing :"; for ( const auto& r : resultNames ) { @@ -173,15 +180,13 @@ std::vector RicExportFractureCompletionsImpl::generateCompdat // Load the data required by fracture summary header std::vector resultNames{"TRANX", "TRANY", "TRANZ"}; - - caseToApply->loadStaticResultsByName( resultNames ); + RicExportFractureCompletionsImpl::loadResultsByName( cellResultsData, resultNames ); } { // Optional results std::vector resultNames = RigEclipseToStimPlanCellTransmissibilityCalculator::optionalResultNames(); - - caseToApply->loadStaticResultsByName( resultNames ); + RicExportFractureCompletionsImpl::loadResultsByName( cellResultsData, resultNames ); } if ( pdParams.performScaling ) @@ -812,3 +817,29 @@ void RicExportFractureCompletionsImpl::outputIntermediateResultsText( QTextStrea ( *outputStreamForIntermediateResultsText ) << "\n"; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicExportFractureCompletionsImpl::loadResultsByName( RigCaseCellResultsData* cellResultsData, + const std::vector& resultNames ) +{ + const std::vector resultCategorySearchOrder = {RiaDefines::STATIC_NATIVE, + RiaDefines::INPUT_PROPERTY, + RiaDefines::GENERATED}; + + bool foundDataForAllResults = true; + + if ( cellResultsData ) + { + for ( const auto& resultName : resultNames ) + { + if ( !cellResultsData->findAndLoadResultByName( resultName, resultCategorySearchOrder ) ) + { + foundDataForAllResults = false; + } + } + } + + return foundDataForAllResults; +} diff --git a/ApplicationCode/Commands/CompletionExportCommands/RicExportFractureCompletionsImpl.h b/ApplicationCode/Commands/CompletionExportCommands/RicExportFractureCompletionsImpl.h index 9abd3780a3..b1038afbe2 100644 --- a/ApplicationCode/Commands/CompletionExportCommands/RicExportFractureCompletionsImpl.h +++ b/ApplicationCode/Commands/CompletionExportCommands/RicExportFractureCompletionsImpl.h @@ -28,6 +28,7 @@ class RicWellPathFractureReportItem; class RigWellPath; class RigTransmissibilityCondenser; class RigEclipseToStimPlanCalculator; +class RigCaseCellResultsData; class RimEclipseCase; class RimFracture; @@ -147,4 +148,6 @@ private: RigTransmissibilityCondenser& transCondenser, const RigMainGrid* mainGrid, const RigFractureGrid* fractureGrid ); + + static bool loadResultsByName( RigCaseCellResultsData* cellResultsData, const std::vector& resultNames ); }; diff --git a/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp b/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp index 7caa618669..474a2f102a 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp @@ -699,30 +699,6 @@ const RigCaseCellResultsData* RimEclipseCase::results( RiaDefines::PorosityModel return nullptr; } -//-------------------------------------------------------------------------------------------------- -/// Convenience function used to pre-load data before const access of data -/// Used when implementing calculations in a parallelized loop -//-------------------------------------------------------------------------------------------------- -bool RimEclipseCase::loadStaticResultsByName( const std::vector& resultNames ) -{ - bool foundDataForAllResults = true; - - RigCaseCellResultsData* cellResultsData = this->results( RiaDefines::MATRIX_MODEL ); - if ( cellResultsData ) - { - for ( const auto& resultName : resultNames ) - { - if ( !cellResultsData->ensureKnownResultLoaded( - RigEclipseResultAddress( RiaDefines::STATIC_NATIVE, resultName ) ) ) - { - foundDataForAllResults = false; - } - } - } - - return foundDataForAllResults; -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimEclipseCase.h b/ApplicationCode/ProjectDataModel/RimEclipseCase.h index b6da43684f..8063bfaa74 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseCase.h +++ b/ApplicationCode/ProjectDataModel/RimEclipseCase.h @@ -81,7 +81,6 @@ public: RigCaseCellResultsData* results( RiaDefines::PorosityModelType porosityModel ); const RigCaseCellResultsData* results( RiaDefines::PorosityModelType porosityModel ) const; - bool loadStaticResultsByName( const std::vector& resultNames ); RimReservoirCellResultsStorage* resultsStorage( RiaDefines::PorosityModelType porosityModel ); const RimReservoirCellResultsStorage* resultsStorage( RiaDefines::PorosityModelType porosityModel ) const; diff --git a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp index 2910cf72e0..ff4d1a8e67 100644 --- a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp +++ b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp @@ -1064,6 +1064,19 @@ bool RigCaseCellResultsData::ensureKnownResultLoaded( const RigEclipseResultAddr return ( resultIndex != cvf::UNDEFINED_SIZE_T ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RigCaseCellResultsData::findAndLoadResultByName( + const QString& resultName, const std::vector& resultCategorySearchOrder ) +{ + RigEclipseResultAddress adr( resultName ); + + size_t resultIndex = findOrLoadKnownScalarResultByResultTypeOrder( adr, resultCategorySearchOrder ); + + return ( resultIndex != cvf::UNDEFINED_SIZE_T ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -1104,41 +1117,14 @@ size_t RigCaseCellResultsData::findOrLoadKnownScalarResult( const RigEclipseResu } else if ( resVarAddr.m_resultCatType == RiaDefines::UNDEFINED ) { - RigEclipseResultAddress resVarAddressWithType = resVarAddr; + std::vector searchOrder = {RiaDefines::STATIC_NATIVE, + RiaDefines::DYNAMIC_NATIVE, + RiaDefines::SOURSIMRL, + RiaDefines::GENERATED, + RiaDefines::INPUT_PROPERTY, + RiaDefines::FORMATION_NAMES}; - resVarAddressWithType.m_resultCatType = RiaDefines::STATIC_NATIVE; - - size_t scalarResultIndex = this->findOrLoadKnownScalarResult( resVarAddressWithType ); - - if ( scalarResultIndex == cvf::UNDEFINED_SIZE_T ) - { - resVarAddressWithType.m_resultCatType = RiaDefines::DYNAMIC_NATIVE; - scalarResultIndex = this->findOrLoadKnownScalarResult( resVarAddressWithType ); - } - - if ( scalarResultIndex == cvf::UNDEFINED_SIZE_T ) - { - resVarAddressWithType.m_resultCatType = RiaDefines::SOURSIMRL; - scalarResultIndex = this->findOrLoadKnownScalarResult( resVarAddressWithType ); - } - - if ( scalarResultIndex == cvf::UNDEFINED_SIZE_T ) - { - resVarAddressWithType.m_resultCatType = RiaDefines::GENERATED; - scalarResultIndex = this->findScalarResultIndexFromAddress( resVarAddressWithType ); - } - - if ( scalarResultIndex == cvf::UNDEFINED_SIZE_T ) - { - resVarAddressWithType.m_resultCatType = RiaDefines::INPUT_PROPERTY; - scalarResultIndex = this->findScalarResultIndexFromAddress( resVarAddressWithType ); - } - - if ( scalarResultIndex == cvf::UNDEFINED_SIZE_T ) - { - resVarAddressWithType.m_resultCatType = RiaDefines::FORMATION_NAMES; - scalarResultIndex = this->findScalarResultIndexFromAddress( resVarAddressWithType ); // Use Load ? - } + size_t scalarResultIndex = this->findOrLoadKnownScalarResultByResultTypeOrder( resVarAddr, searchOrder ); return scalarResultIndex; } @@ -1378,6 +1364,47 @@ size_t RigCaseCellResultsData::findOrLoadKnownScalarResult( const RigEclipseResu return scalarResultIndex; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +size_t RigCaseCellResultsData::findOrLoadKnownScalarResultByResultTypeOrder( + const RigEclipseResultAddress& resVarAddr, const std::vector& resultCategorySearchOrder ) +{ + std::set otherResultTypesToSearch = {RiaDefines::STATIC_NATIVE, + RiaDefines::DYNAMIC_NATIVE, + RiaDefines::SOURSIMRL, + RiaDefines::INPUT_PROPERTY, + RiaDefines::GENERATED, + RiaDefines::FORMATION_NAMES}; + + for ( const auto& resultType : resultCategorySearchOrder ) + { + otherResultTypesToSearch.erase( resultType ); + } + + std::vector resultTypesOrdered = resultCategorySearchOrder; + + for ( const auto& resultType : otherResultTypesToSearch ) + { + resultTypesOrdered.push_back( resultType ); + } + + for ( const auto& resultType : resultTypesOrdered ) + { + RigEclipseResultAddress resVarAddressWithType = resVarAddr; + resVarAddressWithType.m_resultCatType = resultType; + + size_t scalarResultIndex = this->findOrLoadKnownScalarResult( resVarAddressWithType ); + + if ( scalarResultIndex != cvf::UNDEFINED_SIZE_T ) + { + return scalarResultIndex; + } + } + + return cvf::UNDEFINED_SIZE_T; +} + //-------------------------------------------------------------------------------------------------- /// This method is intended to be used for multicase cross statistical calculations, when /// we need process one timestep at a time, freeing memory as we go. diff --git a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.h b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.h index 123088c657..9a909dc7aa 100644 --- a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.h +++ b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.h @@ -128,6 +128,10 @@ public: void ensureKnownResultLoadedForTimeStep( const RigEclipseResultAddress& resultAddress, size_t timeStepIndex ); bool ensureKnownResultLoaded( const RigEclipseResultAddress& resultAddress ); + + bool findAndLoadResultByName( const QString& resultName, + const std::vector& resultCategorySearchOrder ); + bool hasResultEntry( const RigEclipseResultAddress& resultAddress ) const; bool isResultLoaded( const RigEclipseResultAddress& resultAddress ) const; void createResultEntry( const RigEclipseResultAddress& resultAddress, bool needsToBeStored ); @@ -142,6 +146,10 @@ public: private: size_t findOrLoadKnownScalarResult( const RigEclipseResultAddress& resVarAddr ); + size_t findOrLoadKnownScalarResultByResultTypeOrder( + const RigEclipseResultAddress& resVarAddr, + const std::vector& resultCategorySearchOrder ); + size_t findOrLoadKnownScalarResultForTimeStep( const RigEclipseResultAddress& resVarAddr, size_t timeStepIndex ); size_t findOrCreateScalarResultIndex( const RigEclipseResultAddress& resVarAddr, bool needsToBeStored ); From 1f181fa17515e5f7e0f050488b9afc7c7e3abc9e Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 8 Oct 2019 08:01:25 +0200 Subject: [PATCH 2/2] #4827 Completion Data : Guard index out of range --- .../RicExportFractureCompletionsImpl.cpp | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/ApplicationCode/Commands/CompletionExportCommands/RicExportFractureCompletionsImpl.cpp b/ApplicationCode/Commands/CompletionExportCommands/RicExportFractureCompletionsImpl.cpp index 49f8dce40f..1f184486ee 100644 --- a/ApplicationCode/Commands/CompletionExportCommands/RicExportFractureCompletionsImpl.cpp +++ b/ApplicationCode/Commands/CompletionExportCommands/RicExportFractureCompletionsImpl.cpp @@ -163,7 +163,7 @@ std::vector RicExportFractureCompletionsImpl::generateCompdat if ( !loadingSucceeded ) { QString msg; - msg += "Compdat Export : One or more of the following required data missing :"; + msg += "Compdat Export : One or more of the following required data sources are missing :"; for ( const auto& r : resultNames ) { @@ -381,14 +381,23 @@ std::vector RicExportFractureCompletionsImpl::generateCompdat fracTemplate->name(), fracture->fractureMD() ); reportItem.setUnitSystem( fracTemplate->fractureTemplateUnit() ); - reportItem.setPressureDepletionParameters( performPressureDepletionScaling, - caseToApply->timeStepStrings()[pdParams.pressureScalingTimeStep], - caf::AppEnum::uiTextFromIndex( - pdParams.wbhpSource ), - pdParams.userWBHP, - currentWellPressure, - minPressureDrop, - maxPressureDrop ); + + if ( performPressureDepletionScaling ) + { + QString timeStepString; + if ( pdParams.pressureScalingTimeStep < caseToApply->timeStepStrings().size() ) + { + timeStepString = caseToApply->timeStepStrings()[pdParams.pressureScalingTimeStep]; + } + reportItem.setPressureDepletionParameters( performPressureDepletionScaling, + timeStepString, + caf::AppEnum::uiTextFromIndex( + pdParams.wbhpSource ), + pdParams.userWBHP, + currentWellPressure, + minPressureDrop, + maxPressureDrop ); + } RicExportFractureCompletionsImpl::calculateAndSetReportItemData( allCompletionsForOneFracture, eclToFractureCalc,