#7563 HDF5 Export : Add flag to generated HDF5, default off

Fixes by cmake-format

Try to fix copy constructor issues


Fix missing initialization


Unused variable
This commit is contained in:
Magne Sjaastad 2021-04-11 20:53:27 +02:00
parent 5e3aef5ca9
commit 3bc569e2a6
9 changed files with 93 additions and 58 deletions

View File

@ -431,6 +431,15 @@ RiaPreferences::RiaPreferences()
"" );
m_useOptimizedSummaryDataFile.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
CAF_PDM_InitField( &m_createH5SummaryDataFile,
"createH5SummaryDataFile",
false,
"Create H5 Summary Data Files [BETA]",
"",
"If not present, create summary file with extension '*.H5'",
"" );
m_createH5SummaryDataFile.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
CAF_PDM_InitFieldNoDefault( &m_summaryReader, "summaryReaderType", "Summary Data File Reader", "", "", "" );
}
@ -473,15 +482,15 @@ void RiaPreferences::defineEditorAttribute( const caf::PdmFieldHandle* field,
if ( field == &octaveShowHeaderInfoWhenExecutingScripts || field == &autocomputeDepthRelatedProperties ||
field == &loadAndShowSoil || field == &m_useShaders || field == &m_showHud ||
field == &m_appendClassNameToUiText || field == &m_appendFieldKeywordToToolTipText ||
field == &m_showTestToolbar || field == &m_includeFractureDebugInfoFile ||
field == &showLasCurveWithoutTvdWarning || field == &holoLensDisableCertificateVerification ||
field == &m_showProjectChangedDialog || field == &m_searchPlotTemplateFoldersRecursively ||
field == &m_showLegendBackground || field == &m_showSummaryTimeAsLongString ||
field == &m_showViewIdInProjectTree || field == &m_useMultipleThreadsWhenLoadingSummaryData ||
field == &m_enableFaultsByDefault || field == &m_showProgressBar || field == &m_openExportedPdfInViewer ||
field == &m_showInfoBox || field == &m_showGridBox || field == &m_useUndoRedo ||
field == &m_createOptimizedSummaryDataFile || field == &m_useOptimizedSummaryDataFile )
field == &m_appendClassNameToUiText || field == &m_appendFieldKeywordToToolTipText || field == &m_showTestToolbar ||
field == &m_includeFractureDebugInfoFile || field == &showLasCurveWithoutTvdWarning ||
field == &holoLensDisableCertificateVerification || field == &m_showProjectChangedDialog ||
field == &m_searchPlotTemplateFoldersRecursively || field == &m_showLegendBackground ||
field == &m_showSummaryTimeAsLongString || field == &m_showViewIdInProjectTree ||
field == &m_useMultipleThreadsWhenLoadingSummaryData || field == &m_enableFaultsByDefault ||
field == &m_showProgressBar || field == &m_openExportedPdfInViewer || field == &m_showInfoBox ||
field == &m_showGridBox || field == &m_useUndoRedo || field == &m_createOptimizedSummaryDataFile ||
field == &m_useOptimizedSummaryDataFile || field == &m_createH5SummaryDataFile )
{
caf::PdmUiCheckBoxEditorAttribute* myAttr = dynamic_cast<caf::PdmUiCheckBoxEditorAttribute*>( attribute );
if ( myAttr )
@ -617,6 +626,10 @@ void RiaPreferences::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering&
group->add( &m_createOptimizedSummaryDataFile );
group->add( &m_useOptimizedSummaryDataFile );
}
else if ( m_summaryReader == SummaryReaderMode::HDF5_OPM_COMMON )
{
group->add( &m_createH5SummaryDataFile );
}
}
}
@ -1251,6 +1264,14 @@ bool RiaPreferences::createOptimizedSummaryDataFiles() const
return m_createOptimizedSummaryDataFile();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaPreferences::createH5SummaryDataFiles() const
{
return m_createH5SummaryDataFile();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -150,6 +150,7 @@ public:
SummaryReaderMode summaryDataReader() const;
bool useOptimizedSummaryDataFiles() const;
bool createOptimizedSummaryDataFiles() const;
bool createH5SummaryDataFiles() const;
public: // Pdm Fields
caf::PdmField<bool> enableGrpcServer;
@ -258,6 +259,7 @@ private:
// Summary data
caf::PdmField<bool> m_createOptimizedSummaryDataFile;
caf::PdmField<bool> m_createH5SummaryDataFile;
caf::PdmField<bool> m_useOptimizedSummaryDataFile;
caf::PdmField<SummaryReaderModeType> m_summaryReader;

View File

@ -232,23 +232,19 @@ list(APPEND RI_LIBRARIES RigGeoMechDataModel)
#
if(RESINSIGHT_FOUND_HDF5)
set(HDF5_FILES
FileInterface/RifHdf5Reader.h
FileInterface/RifHdf5Reader.cpp
FileInterface/RifHdf5SummaryReader.h
FileInterface/RifHdf5SummaryReader.cpp
FileInterface/RifOpmHdf5Summary.h
FileInterface/RifOpmHdf5Summary.cpp
FileInterface/RifHdf5Exporter.h
FileInterface/RifHdf5Exporter.cpp
FileInterface/RifHdf5SummaryExporter.h
FileInterface/RifHdf5SummaryExporter.cpp
)
set(HDF5_FILES
FileInterface/RifHdf5Reader.h
FileInterface/RifHdf5Reader.cpp
FileInterface/RifHdf5SummaryReader.h
FileInterface/RifHdf5SummaryReader.cpp
FileInterface/RifOpmHdf5Summary.h
FileInterface/RifOpmHdf5Summary.cpp
FileInterface/RifHdf5Exporter.h
FileInterface/RifHdf5Exporter.cpp
FileInterface/RifHdf5SummaryExporter.h
FileInterface/RifHdf5SummaryExporter.cpp)
list(
APPEND
CPP_SOURCES
${HDF5_FILES})
list(APPEND CPP_SOURCES ${HDF5_FILES})
add_definitions(-DUSE_HDF5)
@ -263,9 +259,7 @@ if(RESINSIGHT_FOUND_HDF5)
include_directories(${HDF5_INCLUDE_DIRS})
endif() # MSVC
source_group(
"FileInterface\\HDF5"
FILES ${HDF5_FILES})
source_group("FileInterface\\HDF5" FILES ${HDF5_FILES})
endif()

View File

@ -131,29 +131,31 @@ bool RifHdf5Exporter::writeDataset( const std::string& groupName, const std::str
//--------------------------------------------------------------------------------------------------
H5::Group RifHdf5Exporter::findOrCreateGroup( H5::Group* parentGroup, const std::string& groupName )
{
H5::Group group;
if ( parentGroup )
{
try
{
group = parentGroup->openGroup( groupName );
auto group = parentGroup->openGroup( groupName );
return group;
}
catch ( ... )
{
group = parentGroup->createGroup( groupName );
return parentGroup->createGroup( groupName );
}
}
else
{
try
{
group = m_hdfFile->openGroup( groupName );
auto group = m_hdfFile->openGroup( groupName );
return group;
}
catch ( ... )
{
group = m_hdfFile->createGroup( groupName );
return m_hdfFile->createGroup( groupName );
}
}
return group;
return {};
}

View File

@ -18,25 +18,33 @@
#include "RifHdf5SummaryExporter.h"
#include <QDateTime>
#include "RifHdf5Exporter.h"
#include "RifSummaryReaderInterface.h"
#include "opm/io/eclipse/ESmry.hpp"
#include <QDateTime>
#include <QFile>
#include <QFileInfo>
#include <QString>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifHdf5SummaryExporter::writeSummaryDataToHdf( const std::string& hdfFileName, Opm::EclIO::ESmry& sourceSummaryData )
bool RifHdf5SummaryExporter::ensureHdf5FileIsCreated( const std::string& smspecFileName, const std::string& h5FileName )
{
auto timesteps = sourceSummaryData.numberOfTimeSteps();
if ( timesteps == 0 ) return false;
if ( !QFile::exists( QString::fromStdString( smspecFileName ) ) ) return false;
RifHdf5Exporter exporter( hdfFileName );
// TODO: Use time stamp of file to make sure the smspec file is older than the h5 file
if ( !QFile::exists( QString::fromStdString( h5FileName ) ) )
{
Opm::EclIO::ESmry sourceSummaryData( smspecFileName );
writeGeneralSection( exporter, sourceSummaryData );
writeSummaryVectors( exporter, sourceSummaryData );
RifHdf5Exporter exporter( h5FileName );
writeGeneralSection( exporter, sourceSummaryData );
writeSummaryVectors( exporter, sourceSummaryData );
}
return true;
}
@ -89,6 +97,8 @@ bool RifHdf5SummaryExporter::writeGeneralSection( RifHdf5Exporter& exporter, Opm
exporter.writeDataset( "general", "version", values );
}
return true;
}
//--------------------------------------------------------------------------------------------------

View File

@ -40,7 +40,7 @@ namespace EclIO
class RifHdf5SummaryExporter
{
public:
static bool writeSummaryDataToHdf( const std::string& hdfFileName, Opm::EclIO::ESmry& sourceSummaryData );
static bool ensureHdf5FileIsCreated( const std::string& smspecFileName, const std::string& h5FileName );
private:
static bool writeGeneralSection( RifHdf5Exporter& exporter, Opm::EclIO::ESmry& sourceSummaryData );

View File

@ -29,6 +29,7 @@
#include "RifReaderEclipseOutput.h"
#ifdef USE_HDF5
#include "RifHdf5SummaryExporter.h"
#include "RifOpmHdf5Summary.h"
#endif
@ -162,6 +163,15 @@ bool RifReaderEclipseSummary::open( const QString& headerFileName,
if ( RiaPreferences::current()->summaryDataReader() == RiaPreferences::SummaryReaderMode::HDF5_OPM_COMMON )
{
#ifdef USE_HDF5
if ( RiaPreferences::current()->createH5SummaryDataFiles() )
{
QFileInfo fi( headerFileName );
QString h5FilenameCandidate = fi.absolutePath() + "/" + fi.baseName() + ".h5";
RifHdf5SummaryExporter::ensureHdf5FileIsCreated( headerFileName.toStdString(),
h5FilenameCandidate.toStdString() );
}
auto hdfReader = std::make_unique<RifOpmHdf5Summary>();
isValid = hdfReader->open( headerFileName, false, threadSafeLogger );

View File

@ -16,24 +16,21 @@
#include "opm/io/eclipse/ESmry.hpp"
#include <numeric>
static const QString H5_TEST_DATA_DIRECTORY = QString( "%1/h5-file/" ).arg( TEST_DATA_DIR );
static const QString H5_TEST_DATA_DIRECTORY_2 = QString( "%1/h5-file/" ).arg( TEST_DATA_DIR );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST( DISABLED_HDFTests, WriteToHdf5SummaryExporter )
{
QString file_path = H5_TEST_DATA_DIRECTORY + "NORNE_ATW2013_RFTPLT_V2.SMSPEC";
// RifReaderEclipseSummary eclReader;
// eclReader.open( file_path, true, nullptr );
QString file_path = H5_TEST_DATA_DIRECTORY_2 + "NORNE_ATW2013_RFTPLT_V2.SMSPEC";
Opm::EclIO::ESmry esmry( file_path.toStdString() );
RifHdf5SummaryExporter exporter;
std::string exportFileName = "e:/project/scratch_export/hdf_complete.h5";
exporter.writeSummaryDataToHdf( exportFileName, esmry );
exporter.ensureHdf5FileIsCreated( exportFileName, exportFileName );
}
//--------------------------------------------------------------------------------------------------
@ -41,7 +38,7 @@ TEST( DISABLED_HDFTests, WriteToHdf5SummaryExporter )
//--------------------------------------------------------------------------------------------------
TEST( DISABLED_HDFTests, WriteDataToH5 )
{
QString file_path = H5_TEST_DATA_DIRECTORY + "NORNE_ATW2013_RFTPLT_V2.SMPEC";
QString file_path = H5_TEST_DATA_DIRECTORY_2 + "NORNE_ATW2013_RFTPLT_V2.SMPEC";
try
{
@ -57,13 +54,12 @@ TEST( DISABLED_HDFTests, WriteDataToH5 )
{
std::vector<int> values( 7 );
int day = 1;
int month = 2;
int year = 3;
int hour = 4;
int minute = 5;
int second = 6;
int unknown = 7;
int day = 1;
int month = 2;
int year = 3;
int hour = 4;
int minute = 5;
int second = 6;
values[0] = day;
values[1] = month;

View File

@ -63,7 +63,7 @@ namespace Opm {
const Location& location( ) const { return this->loc; }
operator Opm::EclIO::SummaryNode() const {
return { keyword_, category_, type_, name_, number_ };
return { keyword_, category_, type_, name_, number_, std::numeric_limits<size_t>::max() };
}
template<class Serializer>