Skip to content

Commit

Permalink
Avoid crash for summary file with no time steps
Browse files Browse the repository at this point in the history
Do not try to create ESMRY file if there are no time steps in the summary data
Do not try to read "TIME" record if no time steps are present
  • Loading branch information
magnesj committed Dec 11, 2023
1 parent 681acfb commit f00553d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
24 changes: 17 additions & 7 deletions ApplicationLibCode/FileInterface/RifOpmCommonSummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ bool RifOpmCommonEclipseSummary::open( const QString& fileName, bool includeRest
{
auto temporarySummaryFile = std::make_unique<Opm::EclIO::ESmry>( smspecFileName.toStdString(), includeRestartFiles );

temporarySummaryFile->make_esmry_file();
if ( temporarySummaryFile->numberOfTimeSteps() > 0 )
{
temporarySummaryFile->make_esmry_file();
}

RifOpmCommonEclipseSummary::increaseEsmryFileCount();
}
Expand Down Expand Up @@ -214,15 +217,22 @@ void RifOpmCommonEclipseSummary::buildMetaData()

if ( m_enhancedReader )
{
keywords = m_enhancedReader->keywordList();
startOfSimulation = m_enhancedReader->startdate();
daysSinceStartOfSimulation = m_enhancedReader->get( "TIME" );
keywords = m_enhancedReader->keywordList();
startOfSimulation = m_enhancedReader->startdate();

if ( m_enhancedReader->numberOfTimeSteps() > 0 )
{
daysSinceStartOfSimulation = m_enhancedReader->get( "TIME" );
}
}
else if ( m_standardReader )
{
keywords = m_standardReader->keywordList();
startOfSimulation = m_standardReader->startdate();
daysSinceStartOfSimulation = m_standardReader->get( "TIME" );
keywords = m_standardReader->keywordList();
startOfSimulation = m_standardReader->startdate();
if ( m_standardReader->numberOfTimeSteps() > 0 )
{
daysSinceStartOfSimulation = m_standardReader->get( "TIME" );
}
}

const auto startAsTimeT = std::chrono::system_clock::to_time_t( startOfSimulation );
Expand Down
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions ApplicationLibCode/UnitTests/opm-summary-Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "opm/io/eclipse/ExtESmry.hpp"

#include <QDebug>
#include <QFile>

static const QString H5_TEST_DATA_DIRECTORY = QString( "%1/h5-file/" ).arg( TEST_DATA_DIR );

Expand Down Expand Up @@ -295,6 +296,20 @@ TEST( OpmSummaryTests, OpmComputeSegmentTopology )
}
}

TEST( OpmSummaryTests, OpenEmptySummaryFile )
{
QString SUMMARY_TEST_DATA_DIRECTORY = QString( "%1/SummaryData/empty-file/" ).arg( TEST_DATA_DIR );
QString rootPath = SUMMARY_TEST_DATA_DIRECTORY + "BLASTO_PRED-19";
QString smspecFilePath = rootPath + ".SMSPEC";

Opm::EclIO::ESmry eSmry( smspecFilePath.toStdString() );

// Test to verify that is is possible to read an empty summary file
// eSmry.make_esmry_file() will fail if the summary file is empty

EXPECT_TRUE( eSmry.numberOfTimeSteps() == 0 );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit f00553d

Please sign in to comment.