Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for patch 2024.03.1 #11363

Merged
merged 14 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ApplicationLibCode/Application/RiaResultNames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ bool RiaResultNames::isFlowResultWithBothPosAndNegValues( const QString& resultN
return false;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaResultNames::isCategoryResult( const QString& resultName )
{
if ( resultName.endsWith( "NUM", Qt::CaseInsensitive ) ) return true;
if ( resultName.startsWith( "FIP", Qt::CaseInsensitive ) ) return true;

return false;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions ApplicationLibCode/Application/RiaResultNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace RiaResultNames
bool isPerCellFaceResult( const QString& resultName );
bool isLogarithmicResult( const QString& resultName );
bool isFlowResultWithBothPosAndNegValues( const QString& resultName );
bool isCategoryResult( const QString& resultName );

QString undefinedResultName();
QString undefinedGridFaultName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "RiaCellDividingTools.h"
#include "RiaLogging.h"
#include "RiaResultNames.h"
#include "RiaStringEncodingTools.h"
#include "RiaTextStringTools.h"

Expand Down Expand Up @@ -439,7 +440,7 @@ bool RifEclipseInputFileTools::exportKeywords( const QString& resul
if ( resultValues.empty() ) continue;

double defaultExportValue = 0.0;
if ( keyword.endsWith( "NUM" ) )
if ( RiaResultNames::isCategoryResult( keyword ) )
{
defaultExportValue = 1.0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "RifEclipseInputPropertyLoader.h"

#include "RiaLogging.h"
#include "RiaResultNames.h"

#include "RifEclipseInputFileTools.h"
#include "RifEclipseKeywordContent.h"
Expand Down Expand Up @@ -177,8 +178,8 @@ bool RifEclipseInputPropertyLoader::appendNewInputPropertyResult( RigEclipseCase
return false;
}

bool endsWithNum = eclipseKeyword.ends_with( "NUM" );
auto dataType = endsWithNum ? RiaDefines::ResultDataType::INTEGER : RiaDefines::ResultDataType::FLOAT;
bool isCategory = RiaResultNames::isCategoryResult( resultName );
auto dataType = isCategory ? RiaDefines::ResultDataType::INTEGER : RiaDefines::ResultDataType::FLOAT;

RigEclipseResultAddress resAddr( RiaDefines::ResultCatType::INPUT_PROPERTY, dataType, resultName );
caseData->results( RiaDefines::PorosityModelType::MATRIX_MODEL )->createResultEntry( resAddr, false );
Expand Down
47 changes: 33 additions & 14 deletions ApplicationLibCode/FileInterface/RifHdf5SummaryExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
//--------------------------------------------------------------------------------------------------
bool RifHdf5SummaryExporter::ensureHdf5FileIsCreatedMultithreaded( const std::vector<std::string>& smspecFileNames,
const std::vector<std::string>& h5FileNames,
bool createHdfIfNotPresent,
int threadCount )
{
if ( smspecFileNames.empty() ) return true;
Expand All @@ -61,7 +62,7 @@ bool RifHdf5SummaryExporter::ensureHdf5FileIsCreatedMultithreaded( const std::ve
const auto& smspecFileName = smspecFileNames[cIdx];
const auto& h5FileName = h5FileNames[cIdx];

RifHdf5SummaryExporter::ensureHdf5FileIsCreated( smspecFileName, h5FileName, hdfFilesCreatedCount );
RifHdf5SummaryExporter::ensureHdf5FileIsCreated( smspecFileName, h5FileName, createHdfIfNotPresent, hdfFilesCreatedCount );
}

if ( hdfFilesCreatedCount > 0 )
Expand All @@ -78,29 +79,47 @@ bool RifHdf5SummaryExporter::ensureHdf5FileIsCreatedMultithreaded( const std::ve
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifHdf5SummaryExporter::ensureHdf5FileIsCreated( const std::string& smspecFileName, const std::string& h5FileName, size_t& hdfFilesCreatedCount )
bool RifHdf5SummaryExporter::ensureHdf5FileIsCreated( const std::string& smspecFileName,
const std::string& h5FileName,
bool createHdfIfNotPresent,
size_t& hdfFilesCreatedCount )
{
if ( !std::filesystem::exists( smspecFileName ) ) return false;

{
// Check if we have write permission in the folder
QFileInfo info( QString::fromStdString( smspecFileName ) );
// If an H5 file is present, and the SMSPEC file is newer than the H5 file, the H5 file will be recreated.
// If no H5 file is present, the H5 file will be created if the flag createHdfIfNotPresent is set to true.
//
// NB! Always make sure the logic is consistent with the logic in RifOpmCommonEclipseSummary::open

if ( !info.isWritable() ) return true;
}
if ( !std::filesystem::exists( smspecFileName ) ) return false;

bool exportIsRequired = false;

bool h5FileExists = std::filesystem::exists( h5FileName );
if ( !h5FileExists )
{
bool h5FileExists = std::filesystem::exists( h5FileName );
if ( !h5FileExists )
if ( createHdfIfNotPresent )
{
exportIsRequired = true;
}
else if ( RiaFilePathTools::isFirstOlderThanSecond( h5FileName, smspecFileName ) )
}
else if ( RiaFilePathTools::isFirstOlderThanSecond( h5FileName, smspecFileName ) )
{
// If both files are present, check if the SMSPEC file is newer than the H5 file. If the SMSPEC file is newer, we abort if it is not
// possible to write to the H5 file

// Check if we have write permission in the folder
QFileInfo info( QString::fromStdString( smspecFileName ) );

if ( !info.isWritable() )
{
exportIsRequired = true;
QString txt =
QString( "HDF is older than SMSPEC, but export to file %1 failed due to missing write permissions. Aborting operation." )
.arg( QString::fromStdString( h5FileName ) );
RiaLogging::error( txt );

return false;
}

exportIsRequired = true;
}

if ( exportIsRequired )
Expand All @@ -127,7 +146,7 @@ bool RifHdf5SummaryExporter::ensureHdf5FileIsCreated( const std::string& smspecF
}
catch ( std::exception& e )
{
QString txt = QString( "HDF export to file %1 failed : %3" ).arg( QString::fromStdString( smspecFileName ), e.what() );
QString txt = QString( "HDF export to file %1 failed : %2" ).arg( QString::fromStdString( smspecFileName ), e.what() );

RiaLogging::error( txt );

Expand Down
6 changes: 5 additions & 1 deletion ApplicationLibCode/FileInterface/RifHdf5SummaryExporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ class RifHdf5SummaryExporter
public:
static bool ensureHdf5FileIsCreatedMultithreaded( const std::vector<std::string>& smspecFileNames,
const std::vector<std::string>& h5FileNames,
bool createHdfIfNotPresent,
int threadCount );

static bool ensureHdf5FileIsCreated( const std::string& smspecFileName, const std::string& h5FileName, size_t& hdfFilesCreatedCount );
static bool ensureHdf5FileIsCreated( const std::string& smspecFileName,
const std::string& h5FileName,
bool createHdfIfNotPresent,
size_t& hdfFilesCreatedCount );

private:
static bool writeGeneralSection( RifHdf5Exporter& exporter, Opm::EclIO::ESmry& sourceSummaryData );
Expand Down
85 changes: 54 additions & 31 deletions ApplicationLibCode/FileInterface/RifOpmCommonSummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,50 +84,73 @@ size_t RifOpmCommonEclipseSummary::numberOfEnhancedSummaryFileCreated()
//--------------------------------------------------------------------------------------------------
bool RifOpmCommonEclipseSummary::open( const QString& fileName, bool includeRestartFiles, RiaThreadSafeLogger* threadSafeLogger )
{
if ( m_createEsmryFiles )
// If an ESMRY file is present, and the SMSPEC file is newer than the ESMRY file, the ESMRY file will be recreated.
// If no ESMRY file is present, the ESMRY file will be created if the flag m_createEsmryFiles is set to true.
//
// NB! Always make sure the logic is consistent with the logic in RifHdf5SummaryExporter::ensureHdf5FileIsCreated

bool writeDataToEsmry = false;

auto candidateEsmryFileName = enhancedSummaryFilename( fileName );

// Make sure to check the smspec file name, as it is supported to import ESMRY files without any SMSPEC data
auto smspecFileName = smspecSummaryFilename( fileName );

if ( !QFile::exists( candidateEsmryFileName ) && QFile::exists( smspecFileName ) && m_createEsmryFiles )
{
writeDataToEsmry = true;
}

if ( RiaFilePathTools::isFirstOlderThanSecond( candidateEsmryFileName.toStdString(), smspecFileName.toStdString() ) )
{
auto candidateEsmryFileName = enhancedSummaryFilename( fileName );
QString root = QFileInfo( smspecFileName ).canonicalPath();

// Make sure to check the smspec file name, as it is supported to import ESMRY files without any SMSPEC data
auto smspecFileName = smspecSummaryFilename( fileName );
const QString smspecFileNameShort = QFileInfo( smspecFileName ).fileName();
const QString esmryFileNameShort = QFileInfo( candidateEsmryFileName ).fileName();

if ( QFile::exists( candidateEsmryFileName ) && QFile::exists( smspecFileName ) &&
RiaFilePathTools::isFirstOlderThanSecond( candidateEsmryFileName.toStdString(), smspecFileName.toStdString() ) )
{
QString root = QFileInfo( smspecFileName ).canonicalPath();
RiaLogging::debug(
QString( " %3 : %1 is older than %2, recreating %1." ).arg( esmryFileNameShort ).arg( smspecFileNameShort ).arg( root ) );

const QString smspecFileNameShort = QFileInfo( smspecFileName ).fileName();
const QString esmryFileNameShort = QFileInfo( candidateEsmryFileName ).fileName();
// Check if we have write permission in the folder
QFileInfo info( smspecFileName );

RiaLogging::debug(
QString( " %3 : %1 is older than %2, recreating %1." ).arg( esmryFileNameShort ).arg( smspecFileNameShort ).arg( root ) );
if ( !info.isWritable() )
{
QString txt =
QString( "ESMRY is older than SMSPEC, but export to file %1 failed due to missing write permissions. Aborting operation." )
.arg( candidateEsmryFileName );
RiaLogging::error( txt );

std::filesystem::remove( candidateEsmryFileName.toStdString() );
return false;
}

if ( !QFile::exists( candidateEsmryFileName ) && QFile::exists( smspecFileName ) )
{
try
{
auto temporarySummaryFile = std::make_unique<Opm::EclIO::ESmry>( smspecFileName.toStdString(), includeRestartFiles );
std::filesystem::remove( candidateEsmryFileName.toStdString() );

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

RifOpmCommonEclipseSummary::increaseEsmryFileCount();
}
catch ( std::exception& )
if ( writeDataToEsmry )
{
try
{
auto temporarySummaryFile = std::make_unique<Opm::EclIO::ESmry>( smspecFileName.toStdString(), includeRestartFiles );

if ( temporarySummaryFile->numberOfTimeSteps() > 0 )
{
if ( threadSafeLogger )
{
QString txt = QString( "Warning, could not open summary file : %1" ).arg( smspecFileName );
threadSafeLogger->warning( txt );
}
temporarySummaryFile->make_esmry_file();
}

return false;
RifOpmCommonEclipseSummary::increaseEsmryFileCount();
}
catch ( std::exception& )
{
if ( threadSafeLogger )
{
QString txt = QString( "Warning, could not open summary file : %1" ).arg( smspecFileName );
threadSafeLogger->warning( txt );
}

return false;
}
}

Expand Down
20 changes: 10 additions & 10 deletions ApplicationLibCode/FileInterface/RifReaderEclipseSummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,18 @@ bool RifReaderEclipseSummary::open( const QString& headerFileName, RiaThreadSafe
( h5FileFound || ( prefSummary->summaryDataReader() == RiaPreferencesSummary::SummaryReaderMode::HDF5_OPM_COMMON ) ) )
{
#ifdef USE_HDF5
if ( prefSummary->createH5SummaryDataFiles() )
{
size_t createdH5FileCount = 0;
RifHdf5SummaryExporter::ensureHdf5FileIsCreated( headerFileName.toStdString(), h5FileName.toStdString(), createdH5FileCount );
size_t createdH5FileCount = 0;
RifHdf5SummaryExporter::ensureHdf5FileIsCreated( headerFileName.toStdString(),
h5FileName.toStdString(),
prefSummary->createH5SummaryDataFiles(),
createdH5FileCount );

if ( createdH5FileCount > 0 )
{
QString txt = QString( "Created %1 " ).arg( h5FileName );
if ( threadSafeLogger ) threadSafeLogger->info( txt );
}
h5FileFound = QFile::exists( h5FileName );
if ( createdH5FileCount > 0 )
{
QString txt = QString( "Created %1 " ).arg( h5FileName );
if ( threadSafeLogger ) threadSafeLogger->info( txt );
}
h5FileFound = QFile::exists( h5FileName );

if ( h5FileFound )
{
Expand Down
2 changes: 0 additions & 2 deletions ApplicationLibCode/ProjectDataModel/RimEclipseResultCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,6 @@ void RimEclipseResultCase::ensureRftDataIsImported()

if ( rftFileInfo.exists() )
{
RiaLogging::info( QString( "RFT file found" ) );

if ( m_useOpmRftReader )
{
m_readerOpmRft = new RifReaderOpmRft( rftFileInfo.filePath() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,8 @@ bool RimEclipseResultDefinition::isCompletionTypeSelected() const
//--------------------------------------------------------------------------------------------------
bool RimEclipseResultDefinition::hasCategoryResult() const
{
if ( RiaResultNames::isCategoryResult( m_resultVariable() ) ) return true;

if ( auto* gridCellResults = currentGridCellResults() )
{
const auto addresses = gridCellResults->existingResults();
Expand Down
Loading