From 2f43a64d36eede0a0702f5754fc48b11363cee95 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 26 Mar 2021 13:52:26 +0100 Subject: [PATCH] #7512 Optimized summary reader : Release memory after writing LODSMRY Creating the LODSMRY file requires all data to be loaded into memory. Close this file object after the file has been written to disk. --- .../FileInterface/RifOpmCommonSummary.cpp | 40 +++++++++++++------ .../FileInterface/RifOpmCommonSummary.h | 5 ++- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/ApplicationLibCode/FileInterface/RifOpmCommonSummary.cpp b/ApplicationLibCode/FileInterface/RifOpmCommonSummary.cpp index 15f09d67d3..cf9f330f64 100644 --- a/ApplicationLibCode/FileInterface/RifOpmCommonSummary.cpp +++ b/ApplicationLibCode/FileInterface/RifOpmCommonSummary.cpp @@ -81,18 +81,7 @@ size_t RifOpmCommonEclipseSummary::numberOfLodFilesCreated() //-------------------------------------------------------------------------------------------------- bool RifOpmCommonEclipseSummary::open( const QString& headerFileName, bool includeRestartFiles ) { - try - { - m_eSmry = - std::make_unique( headerFileName.toStdString(), includeRestartFiles, m_useLodsmryFiles ); - } - catch ( std::exception& e ) - { - QString txt = QString( "Optimized Summary Reader error : %1" ).arg( e.what() ); - RiaLogging::error( txt ); - - return false; - } + if ( !openESmryFile( headerFileName, includeRestartFiles ) ) return false; if ( m_createLodsmryFiles && !includeRestartFiles ) { @@ -102,6 +91,12 @@ bool RifOpmCommonEclipseSummary::open( const QString& headerFileName, bool inclu if ( hasFileBeenCreated ) { RifOpmCommonEclipseSummary::increaseLodFileCount(); + + // If a LODSMRY file has been created, all data for all vectors has now been loaded into the summary file + // object. Close the file object to make sure allocated data is released, and create a new file object + // that will import only the meta data and no curve data. This is a relatively fast operation. + + if ( !openESmryFile( headerFileName, includeRestartFiles ) ) return false; } } @@ -199,6 +194,27 @@ void RifOpmCommonEclipseSummary::buildMetaData() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RifOpmCommonEclipseSummary::openESmryFile( const QString& headerFileName, bool includeRestartFiles ) +{ + try + { + m_eSmry = + std::make_unique( headerFileName.toStdString(), includeRestartFiles, m_useLodsmryFiles ); + } + catch ( std::exception& e ) + { + QString txt = QString( "Optimized Summary Reader error : %1" ).arg( e.what() ); + RiaLogging::error( txt ); + + return false; + } + + return true; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/FileInterface/RifOpmCommonSummary.h b/ApplicationLibCode/FileInterface/RifOpmCommonSummary.h index 9168daa22b..3817b74509 100644 --- a/ApplicationLibCode/FileInterface/RifOpmCommonSummary.h +++ b/ApplicationLibCode/FileInterface/RifOpmCommonSummary.h @@ -53,8 +53,8 @@ public: void useLodsmaryFiles( bool enable ); void createLodsmaryFiles( bool enable ); - - static void resetLodCount(); + + static void resetLodCount(); static size_t numberOfLodFilesCreated(); bool open( const QString& headerFileName, bool includeRestartFiles ); @@ -66,6 +66,7 @@ public: private: void buildMetaData(); + bool openESmryFile( const QString& headerFileName, bool includeRestartFiles ); static void increaseLodFileCount();