mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1356 Application code for reading of HDF data into ResInsight
This commit is contained in:
@@ -193,6 +193,13 @@ if(RESINSIGHT_ENABLE_HDF5)
|
||||
${HDF5_LIBRARIES}
|
||||
)
|
||||
|
||||
list( APPEND CPP_SOURCES
|
||||
FileInterface/RifHdf5Reader.h
|
||||
FileInterface/RifHdf5Reader.cpp
|
||||
)
|
||||
|
||||
source_group( "FileInterface" FILES FileInterface/RifHdf5Reader.h FileInterface/RifHdf5Reader.cpp )
|
||||
|
||||
add_definitions(-DUSE_HDF5)
|
||||
# TODO add_subdirectory(HDF/Hdf5Reader)
|
||||
message( STATUS "Linking HD5 libraries : ${HDF5_LIBRARIES}" )
|
||||
|
||||
@@ -20,6 +20,10 @@ ${CEE_CURRENT_LIST_DIR}RifReaderMockModel.h
|
||||
${CEE_CURRENT_LIST_DIR}RifReaderSettings.h
|
||||
${CEE_CURRENT_LIST_DIR}RifEclipseSummaryAddress.h
|
||||
${CEE_CURRENT_LIST_DIR}RifReaderOpmParserInput.h
|
||||
${CEE_CURRENT_LIST_DIR}RifHdf5ReaderInterface.h
|
||||
|
||||
# HDF5 file reader is directly included in ResInsight main CmakeList.txt
|
||||
#${CEE_CURRENT_LIST_DIR}RifHdf5Reader.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
@@ -38,6 +42,10 @@ ${CEE_CURRENT_LIST_DIR}RifReaderMockModel.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RifReaderSettings.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RifEclipseSummaryAddress.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RifReaderOpmParserInput.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RifHdf5ReaderInterface.cpp
|
||||
|
||||
# HDF5 file reader is directly included in ResInsight main CmakeList.txt
|
||||
#${CEE_CURRENT_LIST_DIR}RifHdf5Reader.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
|
||||
102
ApplicationCode/FileInterface/RifHdf5Reader.cpp
Normal file
102
ApplicationCode/FileInterface/RifHdf5Reader.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RifHdf5Reader.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QDateTime>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifHdf5Reader::RifHdf5Reader(const QString& fileName)
|
||||
: m_fileName(fileName)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifHdf5Reader::~RifHdf5Reader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifHdf5Reader::dynamicResult(const QString& result, size_t stepIndex, std::vector<double>* values) const
|
||||
{
|
||||
QStringList myProps = propertyNames();
|
||||
|
||||
// if (std::find(begin(myProps), end(myProps), result) != end(myProps))
|
||||
if (myProps.indexOf(result) != -1)
|
||||
{
|
||||
for (size_t i = 0; i < 16336; i++)
|
||||
{
|
||||
values->push_back(i);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<QDateTime> RifHdf5Reader::timeSteps() const
|
||||
{
|
||||
std::vector<QDateTime> times;
|
||||
|
||||
QDateTime dt;
|
||||
times.push_back(dt);
|
||||
times.push_back(dt.addDays(1));
|
||||
times.push_back(dt.addDays(2));
|
||||
|
||||
return times;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QStringList RifHdf5Reader::propertyNames() const
|
||||
{
|
||||
QStringList myProps;
|
||||
|
||||
myProps.push_back("msj1");
|
||||
myProps.push_back("msj2");
|
||||
myProps.push_back("msj3");
|
||||
|
||||
return myProps;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifHdf5Reader::resultNames(QStringList* resultNames, std::vector<size_t>* resultDataItemCounts)
|
||||
{
|
||||
*resultNames = propertyNames();
|
||||
|
||||
for (size_t i = 0; i < propertyNames().size(); i++)
|
||||
{
|
||||
resultDataItemCounts->push_back(16336);
|
||||
}
|
||||
}
|
||||
48
ApplicationCode/FileInterface/RifHdf5Reader.h
Normal file
48
ApplicationCode/FileInterface/RifHdf5Reader.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RifHdf5ReaderInterface.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RifHdf5Reader : public RifHdf5ReaderInterface
|
||||
{
|
||||
public:
|
||||
explicit RifHdf5Reader(const QString& fileName);
|
||||
virtual ~RifHdf5Reader();
|
||||
|
||||
bool dynamicResult(const QString& result, size_t stepIndex, std::vector<double>* values) const;
|
||||
|
||||
|
||||
std::vector<QDateTime> timeSteps() const;
|
||||
|
||||
|
||||
virtual QStringList propertyNames() const override;
|
||||
|
||||
|
||||
virtual void resultNames(QStringList* resultNames, std::vector<size_t>* resultDataItemCounts) override;
|
||||
|
||||
private:
|
||||
QString m_fileName;
|
||||
};
|
||||
20
ApplicationCode/FileInterface/RifHdf5ReaderInterface.cpp
Normal file
20
ApplicationCode/FileInterface/RifHdf5ReaderInterface.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RifHdf5ReaderInterface.h"
|
||||
|
||||
39
ApplicationCode/FileInterface/RifHdf5ReaderInterface.h
Normal file
39
ApplicationCode/FileInterface/RifHdf5ReaderInterface.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
class QString;
|
||||
class QDateTime;
|
||||
class QStringList;
|
||||
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RifHdf5ReaderInterface
|
||||
{
|
||||
public:
|
||||
virtual std::vector<QDateTime> timeSteps() const = 0;
|
||||
virtual QStringList propertyNames() const = 0;
|
||||
virtual void resultNames(QStringList* resultNames, std::vector<size_t>* resultDataItemCounts) = 0;
|
||||
virtual bool dynamicResult(const QString& result, size_t stepIndex, std::vector<double>* values) const = 0;
|
||||
};
|
||||
@@ -20,12 +20,18 @@
|
||||
|
||||
#include "RifReaderEclipseOutput.h"
|
||||
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "RifEclipseInputFileTools.h"
|
||||
#include "RifEclipseOutputFileTools.h"
|
||||
#include "RifEclipseRestartFilesetAccess.h"
|
||||
#include "RifEclipseUnifiedRestartFileAccess.h"
|
||||
#include "RifReaderOpmParserInput.h"
|
||||
|
||||
#ifdef USE_HDF5
|
||||
#include "RifHdf5Reader.h"
|
||||
#endif
|
||||
|
||||
#include "RigActiveCellInfo.h"
|
||||
#include "RigCaseCellResultsData.h"
|
||||
#include "RigEclipseCaseData.h"
|
||||
@@ -438,6 +444,83 @@ bool RifReaderEclipseOutput::open(const QString& fileName, RigEclipseCaseData* e
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifReaderEclipseOutput::setHdf5FileName(const QString& fileName)
|
||||
{
|
||||
CVF_ASSERT(m_eclipseCase);
|
||||
|
||||
RigCaseCellResultsData* matrixModelResults = m_eclipseCase->results(RifReaderInterface::MATRIX_RESULTS);
|
||||
CVF_ASSERT(matrixModelResults);
|
||||
|
||||
std::unique_ptr<RifHdf5ReaderInterface> myReader;
|
||||
#ifdef USE_HDF5
|
||||
myReader = std::unique_ptr<RifHdf5ReaderInterface>(new RifHdf5Reader(fileName));
|
||||
#endif // USE_HDF5
|
||||
|
||||
if (!myReader) return;
|
||||
|
||||
std::vector<QDateTime> hdfTimeSteps = myReader->timeSteps();
|
||||
if (m_timeSteps.size() > 0)
|
||||
{
|
||||
if (hdfTimeSteps.size() != m_timeSteps.size())
|
||||
{
|
||||
RiaLogging::error("HDF: Time step count does not match");
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m_timeSteps.size(); i++)
|
||||
{
|
||||
if (hdfTimeSteps[i] != m_timeSteps[i])
|
||||
{
|
||||
RiaLogging::error("HDF: Time steps does not match");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use time steps from HDF to define the time steps
|
||||
m_timeSteps = hdfTimeSteps;
|
||||
}
|
||||
|
||||
std::vector<int> reportNumbers;
|
||||
if (m_dynamicResultsAccess.notNull())
|
||||
{
|
||||
reportNumbers = m_dynamicResultsAccess->reportNumbers();
|
||||
}
|
||||
|
||||
QStringList resultNames;
|
||||
std::vector<size_t> resultNamesDataItemCounts;
|
||||
myReader->resultNames(&resultNames, &resultNamesDataItemCounts);
|
||||
if (resultNames.size() != static_cast<int>(resultNamesDataItemCounts.size()))
|
||||
{
|
||||
RiaLogging::error("HDF: Result name vectors and result name data item count does not match");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
size_t activeCellCount = 0;
|
||||
matrixModelResults->activeCellInfo()->gridActiveCellCounts(0, activeCellCount);
|
||||
|
||||
for (int i = 0; i < resultNames.size(); ++i)
|
||||
{
|
||||
if (activeCellCount != resultNamesDataItemCounts[i])
|
||||
{
|
||||
RiaLogging::error("HDF: Number of active cells does not match");
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t resIndex = matrixModelResults->addEmptyScalarResult(RimDefines::DYNAMIC_NATIVE, resultNames[i], false);
|
||||
matrixModelResults->setTimeStepDates(resIndex, m_timeSteps, reportNumbers);
|
||||
}
|
||||
}
|
||||
|
||||
m_hdfReaderInterface = std::move(myReader);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -855,6 +938,16 @@ bool RifReaderEclipseOutput::staticResult(const QString& result, PorosityModelRe
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifReaderEclipseOutput::dynamicResult(const QString& result, PorosityModelResultType matrixOrFracture, size_t stepIndex, std::vector<double>* values)
|
||||
{
|
||||
#ifdef USE_HDF5
|
||||
if (m_hdfReaderInterface)
|
||||
{
|
||||
if (m_hdfReaderInterface->dynamicResult(result, stepIndex, values))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (m_dynamicResultsAccess.isNull())
|
||||
{
|
||||
m_dynamicResultsAccess = createDynamicResultsAccess();
|
||||
|
||||
@@ -27,12 +27,15 @@
|
||||
#include <QList>
|
||||
#include <QDateTime>
|
||||
|
||||
#include <memory>
|
||||
|
||||
class RifEclipseOutputFileTools;
|
||||
class RifEclipseRestartDataAccess;
|
||||
class RigGridBase;
|
||||
class RigMainGrid;
|
||||
class RifHdf5ReaderInterface;
|
||||
class RigActiveCellInfo;
|
||||
class RigFault;
|
||||
class RigGridBase;
|
||||
class RigMainGrid;
|
||||
|
||||
struct RigWellResultPoint;
|
||||
|
||||
@@ -52,6 +55,7 @@ public:
|
||||
virtual ~RifReaderEclipseOutput();
|
||||
|
||||
bool open(const QString& fileName, RigEclipseCaseData* eclipseCase);
|
||||
void setHdf5FileName(const QString& fileName);
|
||||
|
||||
virtual bool openAndReadActiveCellData(const QString& fileName, const std::vector<QDateTime>& mainCaseTimeSteps, RigEclipseCaseData* eclipseCase);
|
||||
void close();
|
||||
@@ -97,4 +101,6 @@ private:
|
||||
|
||||
ecl_file_type* m_ecl_init_file; // File access to static results
|
||||
cvf::ref<RifEclipseRestartDataAccess> m_dynamicResultsAccess; // File access to dynamic results
|
||||
|
||||
std::unique_ptr<RifHdf5ReaderInterface> m_hdfReaderInterface;
|
||||
};
|
||||
|
||||
@@ -70,7 +70,8 @@ RimEclipseResultCase::RimEclipseResultCase()
|
||||
flipYAxis.xmlCapability()->setIOWritable(true);
|
||||
//flipYAxis.uiCapability()->setUiHidden(true);
|
||||
|
||||
|
||||
CAF_PDM_InitField(&m_sourSimFileName, "SourSimFileName", QString(), "SourSim File Name", "", "", "");
|
||||
//m_sourSimFileName.uiCapability()->setUiReadOnly(true);
|
||||
|
||||
m_activeCellInfoIsReadFromFile = false;
|
||||
m_gridAndWellDataIsReadFromFile = false;
|
||||
@@ -141,6 +142,12 @@ bool RimEclipseResultCase::openEclipseGridFile()
|
||||
m_flowDiagSolutions.push_back(new RimFlowDiagSolution());
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_sourSimFileName().isEmpty())
|
||||
{
|
||||
RifReaderEclipseOutput* outReader = dynamic_cast<RifReaderEclipseOutput*>(readerInterface.p());
|
||||
outReader->setHdf5FileName(m_sourSimFileName());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -410,6 +417,20 @@ void RimEclipseResultCase::setCaseInfo(const QString& userDescription, const QSt
|
||||
proj->assignCaseIdToCase(this);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimEclipseResultCase::setSourSimFileName(const QString& fileName)
|
||||
{
|
||||
m_sourSimFileName = fileName;
|
||||
|
||||
RifReaderEclipseOutput* rifReaderOutput = dynamic_cast<RifReaderEclipseOutput*>(results(RifReaderInterface::FRACTURE_RESULTS)->readerInterface());
|
||||
if (rifReaderOutput)
|
||||
{
|
||||
rifReaderOutput->setHdf5FileName(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -42,6 +42,7 @@ public:
|
||||
|
||||
void setGridFileName(const QString& caseFileName);
|
||||
void setCaseInfo(const QString& userDescription, const QString& caseFileName);
|
||||
void setSourSimFileName(const QString& fileName);
|
||||
|
||||
virtual bool openEclipseGridFile();
|
||||
bool openAndReadActiveCellData(RigEclipseCaseData* mainEclipseCase);
|
||||
@@ -68,6 +69,7 @@ private:
|
||||
// Fields:
|
||||
caf::PdmField<QString> caseFileName;
|
||||
caf::PdmChildArrayField<RimFlowDiagSolution*> m_flowDiagSolutions;
|
||||
caf::PdmField<QString> m_sourSimFileName;
|
||||
|
||||
|
||||
// Obsolete field
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#ifdef USE_HDF5
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "H5Cpp.h"
|
||||
@@ -129,3 +131,4 @@ TEST(HDFTests, BasicFileRead)
|
||||
|
||||
}
|
||||
|
||||
#endif //USE_HDF5
|
||||
@@ -461,3 +461,25 @@ TEST(RigReservoirTest, WellTest)
|
||||
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RigReservoirTest, WellTest)
|
||||
{
|
||||
cvf::ref<RifReaderEclipseOutput> readerInterfaceEcl = new RifReaderEclipseOutput;
|
||||
cvf::ref<RigEclipseCaseData> reservoir = new RigEclipseCaseData;
|
||||
|
||||
// Location of test dataset received from Håkon Høgstøl in July 2011 with 10k active cells
|
||||
#ifdef WIN32
|
||||
QString filename("d:/Models/Statoil/soursim/PKMUNK_NOV_TEST_SS.GRID");
|
||||
QString sourSim("d:/Models/Statoil/soursim/result.sourres");
|
||||
#else
|
||||
QString filename("/mnt/hgfs/Statoil/testcase_juli_2011/data/TEST10K_FLT_LGR_NNC.EGRID");
|
||||
QString sourSim("d:/Models/Statoil/soursim/result.sourres");
|
||||
#endif
|
||||
|
||||
bool result = readerInterfaceEcl->open(filename, reservoir.p());
|
||||
EXPECT_TRUE(result);
|
||||
|
||||
readerInterfaceEcl->setHdf5FileName(sourSim);
|
||||
}
|
||||
Reference in New Issue
Block a user