From 50ee4efa07136b62c102f47b48accfb2f4efdbd2 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Sat, 16 Mar 2024 11:11:58 +0100 Subject: [PATCH 01/11] Check flag before rebuilding summary address nodes --- ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCase.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCase.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCase.cpp index 7171f50e21..0f89af928b 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCase.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCase.cpp @@ -406,6 +406,9 @@ void RimSummaryCase::refreshMetaData() //-------------------------------------------------------------------------------------------------- void RimSummaryCase::onCalculationUpdated() { + // NB! Performance critical method + if ( !m_showSubNodesInTree ) return; + // Delete all calculated address objects m_dataVectorFolders->deleteCalculatedObjects(); From c12b9658174ff3ffbc84857e1a1bb8971c134ffd Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Sat, 16 Mar 2024 17:17:21 +0100 Subject: [PATCH 02/11] Performance: Use vector instead of set and map locally in thread vector is faster than set and map. The content of these local vectors are inserted into set/map containing data for the complete file. --- .../FileInterface/RifOpmCommonSummary.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ApplicationLibCode/FileInterface/RifOpmCommonSummary.cpp b/ApplicationLibCode/FileInterface/RifOpmCommonSummary.cpp index 6b411262b9..bfad38a75b 100644 --- a/ApplicationLibCode/FileInterface/RifOpmCommonSummary.cpp +++ b/ApplicationLibCode/FileInterface/RifOpmCommonSummary.cpp @@ -398,9 +398,9 @@ std::pair, std::map threadAddresses; - std::map threadAddressToKeywordMap; - std::vector threadInvalidKeywords; + std::vector threadAddresses; + std::vector> threadAddressToKeywordMap; + std::vector threadInvalidKeywords; #pragma omp for for ( int index = 0; index < (int)keywords.size(); index++ ) @@ -418,8 +418,8 @@ std::pair, std::map Date: Sat, 16 Mar 2024 17:18:35 +0100 Subject: [PATCH 03/11] Performance: Skip looking for restart summary filenames for opm-common opm-common handles the traversal of restart cases internally --- .../Summary/RimFileSummaryCase.cpp | 23 ++++++++++++------- .../Summary/RimFileSummaryCase.h | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimFileSummaryCase.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimFileSummaryCase.cpp index 550fb6bf63..e4815a8c2b 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimFileSummaryCase.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimFileSummaryCase.cpp @@ -20,14 +20,12 @@ #include "RiaApplication.h" #include "RiaLogging.h" - -#include "RicfCommandObject.h" +#include "RiaPreferencesSummary.h" #include "RifEclipseSummaryTools.h" #include "RifMultipleSummaryReaders.h" #include "RifOpmCommonSummary.h" #include "RifProjectSummaryDataWriter.h" -#include "RifReaderEclipseRft.h" #include "RifReaderEclipseSummary.h" #include "RifReaderOpmRft.h" #include "RifSummaryReaderMultipleFiles.h" @@ -36,7 +34,6 @@ #include "RimProject.h" #include "RimRftCase.h" #include "RimSummaryCalculationCollection.h" -#include "RimTools.h" #include "cafPdmFieldScriptingCapability.h" #include "cafPdmObjectScriptingCapability.h" @@ -102,8 +99,18 @@ QString RimFileSummaryCase::caseName() const //-------------------------------------------------------------------------------------------------- void RimFileSummaryCase::createSummaryReaderInterfaceThreadSafe( RiaThreadSafeLogger* threadSafeLogger ) { - m_fileSummaryReader = - RimFileSummaryCase::findRelatedFilesAndCreateReader( summaryHeaderFilename(), m_includeRestartFiles, threadSafeLogger ); + bool lookForRestartFiles = false; + + if ( RiaPreferencesSummary::current()->summaryDataReader() == RiaPreferencesSummary::SummaryReaderMode::LIBECL ) + { + // It is only the libecl reader that requires manual search for referenced restart files + // opm-common reader handles restart files internally based on m_includeRestartFiles in RifOpmCommonEclipseSummary::openFileReader + // + // The performance of the function looking for restart files is bad, and will affect the performance significantly + lookForRestartFiles = m_includeRestartFiles; + } + + m_fileSummaryReader = RimFileSummaryCase::findRelatedFilesAndCreateReader( summaryHeaderFilename(), lookForRestartFiles, threadSafeLogger ); m_multiSummaryReader = new RifMultipleSummaryReaders; m_multiSummaryReader->addReader( m_fileSummaryReader.p() ); @@ -159,10 +166,10 @@ void RimFileSummaryCase::createRftReaderInterface() /// //-------------------------------------------------------------------------------------------------- RifSummaryReaderInterface* RimFileSummaryCase::findRelatedFilesAndCreateReader( const QString& headerFileName, - bool includeRestartFiles, + bool lookForRestartFiles, RiaThreadSafeLogger* threadSafeLogger ) { - if ( includeRestartFiles ) + if ( lookForRestartFiles ) { std::vector warnings; std::vector restartFileInfos = RifEclipseSummaryTools::getRestartFiles( headerFileName, warnings ); diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimFileSummaryCase.h b/ApplicationLibCode/ProjectDataModel/Summary/RimFileSummaryCase.h index 927e6c3a78..dacc7e5670 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimFileSummaryCase.h +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimFileSummaryCase.h @@ -61,7 +61,7 @@ class RimFileSummaryCase : public RimSummaryCase void onProjectBeingSaved(); static RifSummaryReaderInterface* - findRelatedFilesAndCreateReader( const QString& headerFileName, bool includeRestartFiles, RiaThreadSafeLogger* threadSafeLogger ); + findRelatedFilesAndCreateReader( const QString& headerFileName, bool lookForRestartFiles, RiaThreadSafeLogger* threadSafeLogger ); protected: void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override; From f02922386044ed0485d6eb2dadccf80b53ce82f6 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Sun, 17 Mar 2024 09:27:07 +0100 Subject: [PATCH 04/11] Performance: Skip double call to rebuildCaseMetaData This function is called in RiaApplication::loadProject() --- .../ProjectDataModel/RimSummaryCalculationCollection.cpp | 8 -------- .../ProjectDataModel/RimSummaryCalculationCollection.h | 1 - 2 files changed, 9 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.cpp b/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.cpp index f2de3ba444..d32da62161 100644 --- a/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.cpp @@ -93,11 +93,3 @@ void RimSummaryCalculationCollection::rebuildCaseMetaData() ensureValidCalculationIds(); updateDataDependingOnCalculations(); } - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimSummaryCalculationCollection::initAfterRead() -{ - rebuildCaseMetaData(); -} diff --git a/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.h b/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.h index e4953189ba..eea4c734c5 100644 --- a/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.h +++ b/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.h @@ -43,5 +43,4 @@ class RimSummaryCalculationCollection : public RimUserDefinedCalculationCollecti private: void updateDataDependingOnCalculations(); - void initAfterRead() override; }; From 106ac09b3b4d2943599e07fb4b0d91e7eabbbd9e Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Sun, 17 Mar 2024 09:27:39 +0100 Subject: [PATCH 05/11] Move adding of case realization parameters to OpenMP loop --- .../Summary/RimSummaryCaseMainCollection.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCaseMainCollection.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCaseMainCollection.cpp index bd193480c2..a3e17a81bd 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCaseMainCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCaseMainCollection.cpp @@ -460,6 +460,7 @@ void RimSummaryCaseMainCollection::loadFileSummaryCaseData( std::vectorcreateSummaryReaderInterfaceThreadSafe( &threadSafeLogger ); + addCaseRealizationParametersIfFound( *fileSummaryCase, fileSummaryCase->summaryHeaderFilename() ); } progInfo.setProgress( cIdx ); @@ -482,7 +483,6 @@ void RimSummaryCaseMainCollection::loadFileSummaryCaseData( std::vectorcreateRftReaderInterface(); - addCaseRealizationParametersIfFound( *fileSummaryCase, fileSummaryCase->summaryHeaderFilename() ); } } } @@ -648,9 +648,13 @@ void RimSummaryCaseMainCollection::updateAutoShortName() // // https://github.com/OPM/ResInsight/issues/7438 - for ( auto s : allSummaryCases() ) + auto sumCases = allSummaryCases(); + +#pragma omp parallel for + for ( int cIdx = 0; cIdx < static_cast( sumCases.size() ); ++cIdx ) { - s->updateAutoShortName(); + auto sumCase = sumCases[cIdx]; + sumCase->updateAutoShortName(); } } From d41f7379d20df3ccdcaf9ae7f0534fc7be677121 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 18 Mar 2024 09:46:22 +0100 Subject: [PATCH 06/11] Add file path tests --- .../UnitTests/RiaFilePathTools-Test.cpp | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/ApplicationLibCode/UnitTests/RiaFilePathTools-Test.cpp b/ApplicationLibCode/UnitTests/RiaFilePathTools-Test.cpp index 0b311c00da..96654aeb0b 100644 --- a/ApplicationLibCode/UnitTests/RiaFilePathTools-Test.cpp +++ b/ApplicationLibCode/UnitTests/RiaFilePathTools-Test.cpp @@ -1,5 +1,6 @@ #include "gtest/gtest.h" +#include "RiaEnsembleNameTools.h" #include "RiaFilePathTools.h" #include @@ -112,3 +113,90 @@ TEST( RiaFilePathTools, removeDuplicatePathSeparators ) EXPECT_STRCASEEQ( expectedPath.toLatin1(), resultRootPath.toLatin1() ); } } + +//-------------------------------------------------------------------------------------------------- +TEST( RiaFilePathTools, splitIntoComponets ) +{ + { + QString testPath( "e:/models/from_equinor_sftp/drogon3d_ahm/realization-0/iter-3/eclipse/model/DROGON-0.SMSPEC" ); + + auto words = RiaFilePathTools::splitPathIntoComponents( testPath ); + + EXPECT_EQ( 8, words.size() ); + + EXPECT_EQ( QString( "models" ), words[0] ); + EXPECT_EQ( QString( "from_equinor_sftp" ), words[1] ); + EXPECT_EQ( QString( "drogon3d_ahm" ), words[2] ); + EXPECT_EQ( QString( "realization-0" ), words[3] ); + EXPECT_EQ( QString( "iter-3" ), words[4] ); + EXPECT_EQ( QString( "eclipse" ), words[5] ); + EXPECT_EQ( QString( "model" ), words[6] ); + EXPECT_EQ( QString( "DROGON-0.SMSPEC" ), words[7] ); + } + + { + QString testPath( "/home/builder/models/realization-0/iter-3/eclipse/model/DROGON-0.SMSPEC" ); + + auto words = RiaFilePathTools::splitPathIntoComponents( testPath ); + + EXPECT_EQ( 8, words.size() ); + + EXPECT_EQ( QString( "home" ), words[0] ); + EXPECT_EQ( QString( "builder" ), words[1] ); + EXPECT_EQ( QString( "models" ), words[2] ); + EXPECT_EQ( QString( "realization-0" ), words[3] ); + EXPECT_EQ( QString( "iter-3" ), words[4] ); + EXPECT_EQ( QString( "eclipse" ), words[5] ); + EXPECT_EQ( QString( "model" ), words[6] ); + EXPECT_EQ( QString( "DROGON-0.SMSPEC" ), words[7] ); + } +} + +//-------------------------------------------------------------------------------------------------- +TEST( RiaFilePathTools, EnsembleName ) +{ + { + QString testPath1( "e:/models/from_equinor_sftp/drogon3d_ahm/realization-0/iter-3/eclipse/model/DROGON-0.SMSPEC" ); + QString testPath2( "e:/models/from_equinor_sftp/drogon3d_ahm/realization-1/iter-3/eclipse/model/DROGON-1.SMSPEC" ); + QStringList allPaths = { testPath1, testPath2 }; + + auto ensembleName = + RiaEnsembleNameTools::findSuitableEnsembleName( allPaths, RiaEnsembleNameTools::EnsembleGroupingMode::FMU_FOLDER_STRUCTURE ); + + EXPECT_EQ( QString( "iter-3" ), ensembleName ); + } +} + +//-------------------------------------------------------------------------------------------------- +TEST( RiaFilePathTools, RealizationName ) +{ + { + QString testPath0( "e:/models/from_equinor_sftp/drogon3d_ahm/realization-0/iter-3/eclipse/model/DROGON-0.SMSPEC" ); + QString testPath1( "e:/models/from_equinor_sftp/drogon3d_ahm/realization-1/iter-3/eclipse/model/DROGON-1.SMSPEC" ); + QStringList allPaths = { testPath0, testPath1 }; + + QString fileName = "DROGON-0.SMSPEC"; + + auto name = RiaEnsembleNameTools::uniqueShortName( testPath1, allPaths, fileName ); + + EXPECT_EQ( QString( "real-1" ), name ); + } +} + +//-------------------------------------------------------------------------------------------------- +TEST( RiaFilePathTools, keyPathComponentsForEachFilePath ) +{ + { + QString testPath0( "e:/models/from_equinor_sftp/drogon3d_ahm/realization-0/iter-3/eclipse/model/DROGON-0.SMSPEC" ); + QString testPath1( "e:/models/from_equinor_sftp/drogon3d_ahm/realization-1/iter-3/eclipse/model/DROGON-1.SMSPEC" ); + QStringList allPaths = { testPath0, testPath1 }; + + auto keyComponents = RiaFilePathTools::keyPathComponentsForEachFilePath( allPaths ); + + auto test0 = keyComponents[testPath0]; + EXPECT_EQ( QString( "realization-0" ), test0.front() ); + + auto test1 = keyComponents[testPath1]; + EXPECT_EQ( QString( "realization-1" ), test1.front() ); + } +} From 207fd2afac751b761c05e9dc18bffc8a62ff1c8b Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 18 Mar 2024 09:46:45 +0100 Subject: [PATCH 07/11] Remove unused code --- ApplicationLibCode/Application/Tools/RiaFilePathTools.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ApplicationLibCode/Application/Tools/RiaFilePathTools.cpp b/ApplicationLibCode/Application/Tools/RiaFilePathTools.cpp index 49f17ed845..e9af52296d 100644 --- a/ApplicationLibCode/Application/Tools/RiaFilePathTools.cpp +++ b/ApplicationLibCode/Application/Tools/RiaFilePathTools.cpp @@ -330,16 +330,10 @@ std::map RiaFilePathTools::keyPathComponentsForEachFilePat { std::map allComponents; - std::multiset allPathComponents; for ( auto fileName : filePaths ) { QStringList pathComponentsForFile = splitPathIntoComponents( fileName, true ); allComponents[fileName] = pathComponentsForFile; - - for ( auto pathComponent : pathComponentsForFile ) - { - allPathComponents.insert( pathComponent ); - } } auto topNode = std::unique_ptr( new PathNode( "", nullptr ) ); From 41f51fac819ddec1114548d8b86f18546cb3da42 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 18 Mar 2024 09:51:25 +0100 Subject: [PATCH 08/11] Performance: Avoid using cdUp() function when splitting path into strings --- .../Application/Tools/RiaFilePathTools.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ApplicationLibCode/Application/Tools/RiaFilePathTools.cpp b/ApplicationLibCode/Application/Tools/RiaFilePathTools.cpp index e9af52296d..351c03611e 100644 --- a/ApplicationLibCode/Application/Tools/RiaFilePathTools.cpp +++ b/ApplicationLibCode/Application/Tools/RiaFilePathTools.cpp @@ -206,7 +206,12 @@ QStringList RiaFilePathTools::splitPathIntoComponents( const QString& inputPath, QStringList components; - QDir dir( path ); + auto indexOfLastSeparator = path.lastIndexOf( separator() ); + auto indexOfDrive = path.indexOf( ':' ); + + QString pathWithoutDrive = path.mid( indexOfDrive + 1, indexOfLastSeparator - ( indexOfDrive + 1 ) ); + + components = pathWithoutDrive.split( separator(), Qt::SkipEmptyParts ); QFileInfo fileInfo( path ); @@ -214,18 +219,14 @@ QStringList RiaFilePathTools::splitPathIntoComponents( const QString& inputPath, { QString extension = fileInfo.completeSuffix(); path = path.replace( QString( ".%1" ).arg( extension ), "" ); - components.push_front( extension ); - components.push_front( fileInfo.baseName() ); + components.push_back( extension ); + components.push_back( fileInfo.baseName() ); } else { components.push_back( fileInfo.fileName() ); } - while ( dir.cdUp() ) - { - components.push_front( dir.dirName() ); - } return components; } From bf25f9d767d517e6868c15ba4410311ba7feceb3 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 18 Mar 2024 09:55:55 +0100 Subject: [PATCH 09/11] Emit nameChanged when name is changed --- .../ProjectDataModel/Summary/RimSummaryCaseCollection.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCaseCollection.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCaseCollection.cpp index 6e5fc541e7..762aec578a 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCaseCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCaseCollection.cpp @@ -248,7 +248,9 @@ void RimSummaryCaseCollection::ensureNameIsUpdated() RiaEnsembleNameTools::EnsembleGroupingMode groupingMode = RiaEnsembleNameTools::EnsembleGroupingMode::FMU_FOLDER_STRUCTURE; QString ensembleName = RiaEnsembleNameTools::findSuitableEnsembleName( fileNames, groupingMode ); - m_name = ensembleName; + if ( m_name == ensembleName ) return; + + m_name = ensembleName; caseNameChanged.send(); } } From ee135508f3f6829a50cd670dc2e1184fcdc1e28c Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 18 Mar 2024 10:07:32 +0100 Subject: [PATCH 10/11] Skip work if no data is supposed to be displayed --- .../ProjectDataModel/RimSummaryCalculationCollection.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.cpp b/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.cpp index d32da62161..75d01c6cc4 100644 --- a/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.cpp @@ -58,6 +58,8 @@ void RimSummaryCalculationCollection::updateDataDependingOnCalculations() { if ( !summaryCase ) continue; + if ( !summaryCase->showRealizationDataSources() ) continue; + if ( auto reader = summaryCase->summaryReader() ) { reader->buildMetaData(); From 4b207017ee3a1e6b28df69c6574fd8839a69fc80 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 18 Mar 2024 10:20:59 +0100 Subject: [PATCH 11/11] Build fix --- ApplicationLibCode/Application/Tools/RiaFilePathTools.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ApplicationLibCode/Application/Tools/RiaFilePathTools.cpp b/ApplicationLibCode/Application/Tools/RiaFilePathTools.cpp index 351c03611e..9cb625acd1 100644 --- a/ApplicationLibCode/Application/Tools/RiaFilePathTools.cpp +++ b/ApplicationLibCode/Application/Tools/RiaFilePathTools.cpp @@ -204,14 +204,12 @@ QStringList RiaFilePathTools::splitPathIntoComponents( const QString& inputPath, { auto path = QDir::cleanPath( inputPath ); - QStringList components; - auto indexOfLastSeparator = path.lastIndexOf( separator() ); auto indexOfDrive = path.indexOf( ':' ); QString pathWithoutDrive = path.mid( indexOfDrive + 1, indexOfLastSeparator - ( indexOfDrive + 1 ) ); - components = pathWithoutDrive.split( separator(), Qt::SkipEmptyParts ); + QStringList components = RiaTextStringTools::splitSkipEmptyParts( pathWithoutDrive, separator() ); QFileInfo fileInfo( path );