From 33ac79d856736481e7ee442723a2785437ed41a6 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 27 May 2021 11:44:26 +0200 Subject: [PATCH] #7727 Performance : Reduce amount of work Use objectsWithReferringPtrFields to find tieIn wells Avoid using descendantsOfType --- ...RicWellPathExportCompletionDataFeature.cpp | 8 ++- ...ellPathExportCompletionDataFeatureImpl.cpp | 28 ++++----- .../ProjectDataModel/RimWellPath.cpp | 57 ++++++++++--------- .../ProjectDataModel/RimWellPath.h | 4 +- 4 files changed, 50 insertions(+), 47 deletions(-) diff --git a/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionDataFeature.cpp b/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionDataFeature.cpp index 1797824b10..027d102fff 100644 --- a/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionDataFeature.cpp +++ b/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionDataFeature.cpp @@ -113,16 +113,18 @@ void RicWellPathExportCompletionDataFeature::prepareExportSettingsAndExportCompl std::vector allLaterals; { - std::set laterals; + std::set lateralSet; for ( auto t : topLevelWells ) { - auto laterals = t->wellPathLateralsRecursively(); + auto laterals = t->allWellPathLaterals(); for ( auto l : laterals ) { - allLaterals.push_back( l ); + lateralSet.insert( l ); } } + + allLaterals.assign( lateralSet.begin(), lateralSet.end() ); } for ( auto w : allLaterals ) diff --git a/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionDataFeatureImpl.cpp b/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionDataFeatureImpl.cpp index b21578fe44..ec80892c77 100644 --- a/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionDataFeatureImpl.cpp +++ b/ApplicationLibCode/Commands/CompletionExportCommands/RicWellPathExportCompletionDataFeatureImpl.cpp @@ -84,7 +84,7 @@ //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RicWellPathExportCompletionDataFeatureImpl::exportCompletions( const std::vector& topLevelWellPaths, +void RicWellPathExportCompletionDataFeatureImpl::exportCompletions( const std::vector& wellPaths, const std::vector& simWells, const RicExportCompletionDataSettingsUi& exportSettings ) { @@ -142,21 +142,21 @@ void RicWellPathExportCompletionDataFeatureImpl::exportCompletions( const std::v std::vector completions; { - caf::ProgressInfo progress( topLevelWellPaths.size(), "Extracting Completion Data For Well Paths" ); + caf::ProgressInfo progress( wellPaths.size(), "Extracting Completion Data For Well Paths" ); - for ( RimWellPath* topLevelWellPath : topLevelWellPaths ) + for ( RimWellPath* wellPath : wellPaths ) { std::vector allWellPathLaterals; - if ( topLevelWellPath->unitSystem() == exportSettings.caseToApply->eclipseCaseData()->unitsType() ) + if ( wellPath->unitSystem() == exportSettings.caseToApply->eclipseCaseData()->unitsType() ) { - allWellPathLaterals = topLevelWellPath->wellPathLateralsRecursively(); + allWellPathLaterals = wellPath->allWellPathLaterals(); } else { int caseId = exportSettings.caseToApply->caseId(); QString format = QString( "Unit systems for well path \"%1\" must match unit system of chosen eclipse case \"%2\"" ); - QString errMsg = format.arg( topLevelWellPath->name() ).arg( caseId ); + QString errMsg = format.arg( wellPath->name() ).arg( caseId ); RiaLogging::error( errMsg ); } @@ -165,15 +165,15 @@ void RicWellPathExportCompletionDataFeatureImpl::exportCompletions( const std::v std::map> completionsPerEclipseCellFracture; std::map> completionsPerEclipseCellPerforations; - for ( auto wellPath : allWellPathLaterals ) + for ( auto wellPathLateral : allWellPathLaterals ) { // Generate completion data if ( exportSettings.includePerforations ) { std::vector perforationCompletionData = - generatePerforationsCompdatValues( wellPath, - wellPath->perforationIntervalCollection()->perforations(), + generatePerforationsCompdatValues( wellPathLateral, + wellPathLateral->perforationIntervalCollection()->perforations(), exportSettings ); appendCompletionData( &completionsPerEclipseCellAllCompletionTypes, perforationCompletionData ); @@ -184,7 +184,7 @@ void RicWellPathExportCompletionDataFeatureImpl::exportCompletions( const std::v { std::vector fishbonesCompletionData = RicFishbonesTransmissibilityCalculationFeatureImp:: - generateFishboneCompdatValuesUsingAdjustedCellVolume( wellPath, exportSettings ); + generateFishboneCompdatValuesUsingAdjustedCellVolume( wellPathLateral, exportSettings ); appendCompletionData( &completionsPerEclipseCellAllCompletionTypes, fishbonesCompletionData ); appendCompletionData( &completionsPerEclipseCellFishbones, fishbonesCompletionData ); @@ -196,7 +196,7 @@ void RicWellPathExportCompletionDataFeatureImpl::exportCompletions( const std::v std::vector* reportItems = &fractureDataReportItems; std::vector fractureCompletionData = RicExportFractureCompletionsImpl:: - generateCompdatValuesForWellPath( wellPath, + generateCompdatValuesForWellPath( wellPathLateral, exportSettings.caseToApply(), reportItems, fractureTransmissibilityExportInformationStream.get(), @@ -281,7 +281,7 @@ void RicWellPathExportCompletionDataFeatureImpl::exportCompletions( const std::v } else if ( exportSettings.fileSplit == RicExportCompletionDataSettingsUi::ExportSplit::SPLIT_ON_WELL ) { - for ( auto wellPath : topLevelWellPaths ) + for ( auto wellPath : wellPaths ) { std::vector completionsForWell; for ( const auto& completion : completions ) @@ -324,7 +324,7 @@ void RicWellPathExportCompletionDataFeatureImpl::exportCompletions( const std::v for ( const auto& completionType : completionTypes ) { - for ( auto wellPath : topLevelWellPaths ) + for ( auto wellPath : wellPaths ) { std::vector completionsForWell; for ( const auto& completion : completions ) @@ -408,7 +408,7 @@ void RicWellPathExportCompletionDataFeatureImpl::exportCompletions( const std::v if ( exportSettings.includeMsw ) { - RicWellPathExportMswCompletionsImpl::exportWellSegmentsForAllCompletions( exportSettings, topLevelWellPaths ); + RicWellPathExportMswCompletionsImpl::exportWellSegmentsForAllCompletions( exportSettings, wellPaths ); } } diff --git a/ApplicationLibCode/ProjectDataModel/RimWellPath.cpp b/ApplicationLibCode/ProjectDataModel/RimWellPath.cpp index f46fe5c8ed..5d9bf44f40 100644 --- a/ApplicationLibCode/ProjectDataModel/RimWellPath.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimWellPath.cpp @@ -1012,18 +1012,11 @@ std::vector RimWellPath::allCompletionsRec { std::vector allCompletions; - auto tieInWells = wellPathLateralsRecursively(); - tieInWells.push_back( const_cast( this ) ); - - for ( auto w : tieInWells ) + auto laterals = allWellPathLaterals(); + for ( auto w : laterals ) { - std::vector completionCollections; - w->descendantsOfType( completionCollections ); - for ( auto collection : completionCollections ) - { - std::vector completions = collection->allCompletions(); - allCompletions.insert( allCompletions.end(), completions.begin(), completions.end() ); - } + auto completions = w->completions()->allCompletions(); + allCompletions.insert( allCompletions.end(), completions.begin(), completions.end() ); } return allCompletions; @@ -1124,6 +1117,8 @@ const RimWellPath* RimWellPath::topLevelWellPath() const { if ( m_wellPathTieIn() && m_wellPathTieIn->parentWell() ) { + if ( m_wellPathTieIn->parentWell() == this ) return this; + return m_wellPathTieIn()->parentWell()->topLevelWellPath(); } @@ -1133,32 +1128,38 @@ const RimWellPath* RimWellPath::topLevelWellPath() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimWellPath::updateAfterAddingToWellPathGroup() +void RimWellPath::wellPathLateralsRecursively( std::vector& wellPathLaterals ) const { + wellPathLaterals.push_back( const_cast( this ) ); + + std::vector referringObjects; + this->objectsWithReferringPtrFields( referringObjects ); + for ( auto obj : referringObjects ) + { + if ( auto tieIn = dynamic_cast( obj ) ) + { + auto tieInWellPath = tieIn->childWell(); + if ( tieInWellPath ) + { + if ( std::find( wellPathLaterals.begin(), wellPathLaterals.end(), tieInWellPath ) == wellPathLaterals.end() ) + { + tieInWellPath->wellPathLateralsRecursively( wellPathLaterals ); + } + } + } + } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RimWellPath::wellPathLateralsRecursively() const +std::vector RimWellPath::allWellPathLaterals() const { - std::vector tieInWells; + std::vector laterals; - auto wellPathColl = RimTools::wellPathCollection(); - if ( wellPathColl ) - { - wellPathColl->allWellPaths(); + this->wellPathLateralsRecursively( laterals ); - for ( auto w : wellPathColl->allWellPaths() ) - { - if ( w->topLevelWellPath() == this ) - { - tieInWells.push_back( w ); - } - } - } - - return tieInWells; + return laterals; } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/RimWellPath.h b/ApplicationLibCode/ProjectDataModel/RimWellPath.h index 21bb28db7d..ebec75ccc7 100644 --- a/ApplicationLibCode/ProjectDataModel/RimWellPath.h +++ b/ApplicationLibCode/ProjectDataModel/RimWellPath.h @@ -161,8 +161,7 @@ public: bool isMultiLateralWellPath() const; RimWellPath* topLevelWellPath(); const RimWellPath* topLevelWellPath() const; - void updateAfterAddingToWellPathGroup(); - std::vector wellPathLateralsRecursively() const; + std::vector allWellPathLaterals() const; RimWellPathTieIn* wellPathTieIn() const; void connectWellPaths( RimWellPath* childWell, double tieInMeasuredDepth ); @@ -214,6 +213,7 @@ private: private: static size_t simulationWellBranchCount( const QString& simWellName ); + void wellPathLateralsRecursively( std::vector& wellPathLaterals ) const; private: // Geometry and data