mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Add reservoir case for EM data
- read geometry definition from h5grid files - import cell results from h5grid files - create and import case using drag/drop of h5grid file into ResInsight
This commit is contained in:
@@ -269,6 +269,12 @@ RiaDefines::EclipseUnitSystem RiaDefines::fromDepthUnit( DepthUnitType depthUnit
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaDefines::ImportFileType RiaDefines::obtainFileTypeFromFileName( const QString& fileName )
|
||||
{
|
||||
if ( fileName.endsWith( "h5grid", Qt::CaseInsensitive ) )
|
||||
{
|
||||
// EM data must be detected first, since "h5grid" also matches "grid" and is interpreted as Eclipse file
|
||||
return ImportFileType::EM_H5GRID;
|
||||
}
|
||||
|
||||
if ( fileName.endsWith( "EGRID", Qt::CaseInsensitive ) )
|
||||
{
|
||||
return ImportFileType::ECLIPSE_EGRID_FILE;
|
||||
|
||||
@@ -134,8 +134,9 @@ enum class ImportFileType
|
||||
RESINSIGHT_PROJECT_FILE = 0x20,
|
||||
ROFF_FILE = 0x30,
|
||||
GEOMECH_INP_FILE = 0x40,
|
||||
EM_H5GRID = 0x80,
|
||||
ECLIPSE_RESULT_GRID = ECLIPSE_GRID_FILE | ECLIPSE_EGRID_FILE,
|
||||
ANY_ECLIPSE_FILE = ECLIPSE_RESULT_GRID | ECLIPSE_INPUT_FILE | ECLIPSE_SUMMARY_FILE | ROFF_FILE,
|
||||
ANY_ECLIPSE_FILE = ECLIPSE_RESULT_GRID | ECLIPSE_INPUT_FILE | ECLIPSE_SUMMARY_FILE | ROFF_FILE | EM_H5GRID,
|
||||
ANY_GEOMECH_FILE = GEOMECH_ODB_FILE | GEOMECH_INP_FILE,
|
||||
ANY_IMPORT_FILE = 0xFF
|
||||
};
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "RimEclipseInputCase.h"
|
||||
#include "RimEclipseResultCase.h"
|
||||
#include "RimEclipseView.h"
|
||||
#include "RimEmCase.h"
|
||||
#include "RimFileSummaryCase.h"
|
||||
#include "RimIdenticalGridCaseGroup.h"
|
||||
#include "RimMainPlotCollection.h"
|
||||
@@ -588,3 +589,56 @@ RimRoffCase* RiaImportEclipseCaseTools::openRoffCaseFromFileName( const QString&
|
||||
|
||||
return roffCase;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaImportEclipseCaseTools::openEmFilesFromFileNames( const QStringList& fileNames, bool createDefaultView, std::vector<int>& createdCaseIds )
|
||||
{
|
||||
if ( fileNames.empty() ) return false;
|
||||
|
||||
RimProject* project = RimProject::current();
|
||||
if ( !project ) return false;
|
||||
|
||||
RimEclipseCaseCollection* analysisModels = project->activeOilField() ? project->activeOilField()->analysisModels() : nullptr;
|
||||
if ( !analysisModels ) return false;
|
||||
|
||||
for ( auto fileName : fileNames )
|
||||
{
|
||||
auto* emCase = new RimEmCase();
|
||||
project->assignCaseIdToCase( emCase );
|
||||
emCase->setGridFileName( fileName );
|
||||
|
||||
bool gridImportSuccess = emCase->openEclipseGridFile();
|
||||
if ( !gridImportSuccess )
|
||||
{
|
||||
const auto errMsg = "Failed to import grid from file: " + fileName.toStdString();
|
||||
RiaLogging::error( errMsg.c_str() );
|
||||
delete emCase;
|
||||
continue;
|
||||
}
|
||||
|
||||
analysisModels->cases.push_back( emCase );
|
||||
analysisModels->updateConnectedEditors();
|
||||
|
||||
RimEclipseView* eclipseView = nullptr;
|
||||
if ( createDefaultView )
|
||||
{
|
||||
eclipseView = emCase->createAndAddReservoirView();
|
||||
|
||||
eclipseView->cellResult()->setResultType( RiaDefines::ResultCatType::INPUT_PROPERTY );
|
||||
eclipseView->loadDataAndUpdate();
|
||||
|
||||
emCase->updateAllRequiredEditors();
|
||||
if ( RiaGuiApplication::isRunning() )
|
||||
{
|
||||
if ( RiuMainWindow::instance() ) RiuMainWindow::instance()->selectAsCurrentItem( eclipseView->cellResult() );
|
||||
|
||||
// Make sure the call to setExpanded is done after the call to selectAsCurrentItem
|
||||
Riu3DMainWindowTools::setExpanded( eclipseView );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -59,6 +59,8 @@ public:
|
||||
static std::vector<int> openRoffCasesFromFileNames( const QStringList& fileNames, bool createDefaultView );
|
||||
static RimRoffCase* openRoffCaseFromFileName( const QString& fileName, bool createDefaultView );
|
||||
|
||||
static bool openEmFilesFromFileNames( const QStringList& fileNames, bool createDefaultView, std::vector<int>& createdCaseIds );
|
||||
|
||||
private:
|
||||
static int openEclipseCaseShowTimeStepFilterImpl( const QString& fileName,
|
||||
bool showTimeStepFilter,
|
||||
|
||||
@@ -60,6 +60,7 @@ RicImportGeneralDataFeature::OpenCaseResults
|
||||
QStringList eclipseInputFiles;
|
||||
QStringList eclipseSummaryFiles;
|
||||
QStringList roffFiles;
|
||||
QStringList emFiles;
|
||||
|
||||
for ( const QString& fileName : fileNames )
|
||||
{
|
||||
@@ -80,6 +81,10 @@ RicImportGeneralDataFeature::OpenCaseResults
|
||||
{
|
||||
roffFiles.push_back( fileName );
|
||||
}
|
||||
else if ( fileTypeAsInt & int( ImportFileType::EM_H5GRID ) )
|
||||
{
|
||||
emFiles.push_back( fileName );
|
||||
}
|
||||
}
|
||||
|
||||
OpenCaseResults results;
|
||||
@@ -120,6 +125,14 @@ RicImportGeneralDataFeature::OpenCaseResults
|
||||
RiaApplication::instance()->setLastUsedDialogDirectory( defaultDirectoryLabel( ImportFileType::ROFF_FILE ), defaultDir );
|
||||
}
|
||||
|
||||
if ( !emFiles.empty() )
|
||||
{
|
||||
if ( !RiaImportEclipseCaseTools::openEmFilesFromFileNames( emFiles, createDefaultView, results.createdCaseIds ) )
|
||||
{
|
||||
return OpenCaseResults();
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
@@ -133,6 +133,7 @@ set(SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimEclipseResultDefinitionTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimResultSelectionUi.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimPlotRectAnnotation.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimEmCase.h
|
||||
)
|
||||
|
||||
set(SOURCE_GROUP_SOURCE_FILES
|
||||
@@ -265,6 +266,7 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimEclipseResultDefinitionTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimResultSelectionUi.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimPlotRectAnnotation.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimEmCase.cpp
|
||||
)
|
||||
|
||||
if(RESINSIGHT_USE_QT_CHARTS)
|
||||
|
||||
247
ApplicationLibCode/ProjectDataModel/RimEmCase.cpp
Normal file
247
ApplicationLibCode/ProjectDataModel/RimEmCase.cpp
Normal file
@@ -0,0 +1,247 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) Ceetron Solutions AS
|
||||
//
|
||||
// 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 "RimEmCase.h"
|
||||
|
||||
#include "RiaDefines.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaPreferences.h"
|
||||
|
||||
#include "RigActiveCellInfo.h"
|
||||
#include "RigCaseCellResultsData.h"
|
||||
#include "RigEclipseCaseData.h"
|
||||
#include "RigEclipseResultAddress.h"
|
||||
#include "RigMainGrid.h"
|
||||
#include "RigReservoirBuilder.h"
|
||||
|
||||
#ifdef USE_HDF5
|
||||
#include "H5Cpp.h"
|
||||
#endif
|
||||
|
||||
#include "cafPdmObjectScriptingCapability.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
CAF_PDM_SOURCE_INIT( RimEmCase, "RimEmCase" );
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimEmCase::RimEmCase()
|
||||
{
|
||||
CAF_PDM_InitScriptableObject( "RimEmCase", ":/EclipseInput48x48.png" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimEmCase::~RimEmCase()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimEmCase::openEclipseGridFile()
|
||||
{
|
||||
if ( eclipseCaseData() )
|
||||
{
|
||||
// Early exit if reservoir data is created
|
||||
return true;
|
||||
}
|
||||
|
||||
setReservoirData( new RigEclipseCaseData( this ) );
|
||||
|
||||
auto emDataFromFile = readDataFromFile();
|
||||
|
||||
auto emData = emDataFromFile;
|
||||
|
||||
// Flip X and Y axis
|
||||
emData.cellSizes[0] = emDataFromFile.cellSizes[1];
|
||||
emData.cellSizes[1] = emDataFromFile.cellSizes[0];
|
||||
|
||||
emData.ijkNumCells[0] = emDataFromFile.ijkNumCells[1];
|
||||
emData.ijkNumCells[1] = emDataFromFile.ijkNumCells[0];
|
||||
|
||||
emData.originNED[0] = emDataFromFile.originNED[1];
|
||||
emData.originNED[1] = emDataFromFile.originNED[0];
|
||||
|
||||
{
|
||||
RigReservoirBuilder builder;
|
||||
|
||||
builder.setWorldCoordinates( cvf::Vec3d( emData.originNED[0], emData.originNED[1], emData.originNED[2] ),
|
||||
cvf::Vec3d( emData.originNED[0] + emData.cellSizes[0] * emData.ijkNumCells[0],
|
||||
emData.originNED[1] + emData.cellSizes[1] * emData.ijkNumCells[1],
|
||||
-( emData.originNED[2] + emData.cellSizes[2] * emData.ijkNumCells[2] ) ) );
|
||||
|
||||
builder.setIJKCount( cvf::Vec3st( emData.ijkNumCells[0], emData.ijkNumCells[1], emData.ijkNumCells[2] ) );
|
||||
builder.createGridsAndCells( eclipseCaseData() );
|
||||
}
|
||||
|
||||
results( RiaDefines::PorosityModelType::MATRIX_MODEL )->createPlaceholderResultEntries();
|
||||
|
||||
if ( RiaPreferences::current()->autocomputeDepthRelatedProperties )
|
||||
{
|
||||
results( RiaDefines::PorosityModelType::MATRIX_MODEL )->computeDepthRelatedResults();
|
||||
results( RiaDefines::PorosityModelType::FRACTURE_MODEL )->computeDepthRelatedResults();
|
||||
}
|
||||
|
||||
results( RiaDefines::PorosityModelType::MATRIX_MODEL )->computeCellVolumes();
|
||||
|
||||
for ( auto [resultName, data] : emData.resultData )
|
||||
{
|
||||
QString riResultName =
|
||||
eclipseCaseData()->results( RiaDefines::PorosityModelType::MATRIX_MODEL )->makeResultNameUnique( QString::fromStdString( resultName ) );
|
||||
|
||||
RigEclipseResultAddress resAddr( RiaDefines::ResultCatType::INPUT_PROPERTY, RiaDefines::ResultDataType::FLOAT, riResultName );
|
||||
eclipseCaseData()->results( RiaDefines::PorosityModelType::MATRIX_MODEL )->createResultEntry( resAddr, false );
|
||||
|
||||
auto newPropertyData =
|
||||
eclipseCaseData()->results( RiaDefines::PorosityModelType::MATRIX_MODEL )->modifiableCellScalarResultTimesteps( resAddr );
|
||||
|
||||
std::vector<double> reorganizedData;
|
||||
|
||||
// Switch cell size ordering from IJK to KJI to make the data layout fit internal ResInsight result ordering
|
||||
auto kjiNumCells = emData.ijkNumCells;
|
||||
kjiNumCells[0] = emData.ijkNumCells[2];
|
||||
kjiNumCells[2] = emData.ijkNumCells[0];
|
||||
|
||||
for ( int k = 0; k < kjiNumCells[0]; k++ )
|
||||
{
|
||||
for ( int i = 0; i < kjiNumCells[2]; i++ )
|
||||
{
|
||||
for ( int j = 0; j < kjiNumCells[1]; j++ )
|
||||
{
|
||||
reorganizedData.push_back( data[k + j * kjiNumCells[0] + i * kjiNumCells[0] * kjiNumCells[1]] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newPropertyData->push_back( reorganizedData );
|
||||
}
|
||||
|
||||
computeCachedData();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimEmCase::reloadEclipseGridFile()
|
||||
{
|
||||
setReservoirData( nullptr );
|
||||
openReserviorCase();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimEmCase::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
||||
{
|
||||
uiOrdering.add( &m_caseUserDescription );
|
||||
uiOrdering.add( &m_displayNameOption );
|
||||
uiOrdering.add( &m_caseId );
|
||||
uiOrdering.add( &m_caseFileName );
|
||||
|
||||
auto group = uiOrdering.addNewGroup( "Case Options" );
|
||||
group->add( &m_activeFormationNames );
|
||||
group->add( &m_flipXAxis );
|
||||
group->add( &m_flipYAxis );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimEmData RimEmCase::readDataFromFile()
|
||||
{
|
||||
#ifndef USE_HDF5
|
||||
return {};
|
||||
#else
|
||||
|
||||
QString fileName = gridFileName();
|
||||
|
||||
std::array<double, 3> originNED;
|
||||
std::array<double, 3> cellSizes;
|
||||
std::array<int, 3> ijkNumCells;
|
||||
std::map<std::string, std::vector<float>> resultData;
|
||||
|
||||
try
|
||||
{
|
||||
H5::Exception::dontPrint(); // Turn off auto-printing of failures to handle the errors appropriately
|
||||
|
||||
H5::H5File mainFile( fileName.toStdString().c_str(), H5F_ACC_RDONLY );
|
||||
|
||||
{
|
||||
auto attr = mainFile.openAttribute( "description::OriginNED" );
|
||||
H5::DataType type = attr.getDataType();
|
||||
attr.read( type, originNED.data() );
|
||||
}
|
||||
|
||||
{
|
||||
H5::Group group = mainFile.openGroup( "Mesh" );
|
||||
|
||||
{
|
||||
auto attr = group.openAttribute( "cell_sizes" );
|
||||
H5::DataType type = attr.getDataType();
|
||||
attr.read( type, cellSizes.data() );
|
||||
}
|
||||
{
|
||||
auto attr = group.openAttribute( "num_cells" );
|
||||
H5::DataType type = attr.getDataType();
|
||||
attr.read( type, ijkNumCells.data() );
|
||||
}
|
||||
}
|
||||
|
||||
H5::Group group = mainFile.openGroup( "Data" );
|
||||
auto numObj = group.getNumObjs();
|
||||
for ( size_t i = 0; i < numObj; i++ )
|
||||
{
|
||||
auto resultName = group.getObjnameByIdx( i );
|
||||
|
||||
std::vector<float> resultValues;
|
||||
H5::DataSet dataset = H5::DataSet( group.openDataSet( resultName ) );
|
||||
|
||||
hsize_t dims[3];
|
||||
H5::DataSpace dataspace = dataset.getSpace();
|
||||
dataspace.getSimpleExtentDims( dims, nullptr );
|
||||
|
||||
resultValues.resize( dims[0] * dims[1] * dims[2] );
|
||||
dataset.read( resultValues.data(), H5::PredType::NATIVE_FLOAT );
|
||||
|
||||
resultData[resultName] = resultValues;
|
||||
}
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
}
|
||||
|
||||
return { originNED, cellSizes, ijkNumCells, resultData };
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimEmCase::locationOnDisc() const
|
||||
{
|
||||
if ( gridFileName().isEmpty() ) return QString();
|
||||
|
||||
QFileInfo fi( gridFileName() );
|
||||
return fi.absolutePath();
|
||||
}
|
||||
58
ApplicationLibCode/ProjectDataModel/RimEmCase.h
Normal file
58
ApplicationLibCode/ProjectDataModel/RimEmCase.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) Ceetron Solutions AS
|
||||
//
|
||||
// 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 "RimEclipseCase.h"
|
||||
|
||||
#include "cafPdmChildField.h"
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObject.h"
|
||||
#include <array>
|
||||
|
||||
struct RimEmData
|
||||
{
|
||||
std::array<double, 3> originNED;
|
||||
std::array<double, 3> cellSizes;
|
||||
std::array<int, 3> ijkNumCells;
|
||||
std::map<std::string, std::vector<float>> resultData;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RimEmCase : public RimEclipseCase
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RimEmCase();
|
||||
~RimEmCase() override;
|
||||
|
||||
bool openEclipseGridFile() override;
|
||||
void reloadEclipseGridFile() override;
|
||||
|
||||
QString locationOnDisc() const override;
|
||||
|
||||
protected:
|
||||
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
|
||||
|
||||
private:
|
||||
RimEmData readDataFromFile();
|
||||
};
|
||||
@@ -100,6 +100,7 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifInpExportTools-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifGridCalculationIO-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifSummaryCalculationIO-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimEmReader-Test.cpp
|
||||
)
|
||||
|
||||
if(RESINSIGHT_ENABLE_GRPC)
|
||||
|
||||
106
ApplicationLibCode/UnitTests/RimEmReader-Test.cpp
Normal file
106
ApplicationLibCode/UnitTests/RimEmReader-Test.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) Ceetron Solutions AS
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef USE_HDF5
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "RigEclipseCaseData.h"
|
||||
|
||||
#include "RimEmCase.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
|
||||
#include "H5Cpp.h"
|
||||
#include <array>
|
||||
#include <memory>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( RigReservoirTest, DISABLED_TestImportGrid )
|
||||
{
|
||||
QString fileName( "f:/Models/emgs/BrickvilleProject/Horizons/test.h5grid" );
|
||||
|
||||
std::array<double, 3> originNED;
|
||||
std::array<double, 3> originMesh;
|
||||
std::array<double, 3> cellSizes;
|
||||
std::array<int, 3> numCells;
|
||||
std::map<std::string, std::vector<double>> resultData;
|
||||
|
||||
try
|
||||
{
|
||||
H5::Exception::dontPrint(); // Turn off auto-printing of failures to handle the errors appropriately
|
||||
|
||||
H5::H5File mainFile( fileName.toStdString().c_str(),
|
||||
H5F_ACC_RDONLY ); // initial date part is an attribute of SourSimRL main file
|
||||
|
||||
{
|
||||
auto attr = mainFile.openAttribute( "description::OriginNED" );
|
||||
H5::DataType type = attr.getDataType();
|
||||
attr.read( type, originNED.data() );
|
||||
}
|
||||
|
||||
{
|
||||
H5::Group group = mainFile.openGroup( "Mesh" );
|
||||
|
||||
{
|
||||
auto attr = group.openAttribute( "cell_sizes" );
|
||||
H5::DataType type = attr.getDataType();
|
||||
attr.read( type, cellSizes.data() );
|
||||
}
|
||||
{
|
||||
auto attr = group.openAttribute( "num_cells" );
|
||||
H5::DataType type = attr.getDataType();
|
||||
attr.read( type, numCells.data() );
|
||||
}
|
||||
{
|
||||
auto attr = group.openAttribute( "origin" );
|
||||
H5::DataType type = attr.getDataType();
|
||||
attr.read( type, originMesh.data() );
|
||||
}
|
||||
}
|
||||
|
||||
H5::Group group = mainFile.openGroup( "Data" );
|
||||
auto numObj = group.getNumObjs();
|
||||
for ( size_t i = 0; i < numObj; i++ )
|
||||
{
|
||||
auto objName = group.getObjnameByIdx( i );
|
||||
auto objType = group.getObjTypeByIdx( i );
|
||||
qDebug() << "objName " << QString::fromStdString( objName ) << " objType " << objType;
|
||||
|
||||
std::vector<double> resultValues;
|
||||
H5::DataSet dataset = H5::DataSet( group.openDataSet( objName ) );
|
||||
|
||||
hsize_t dims[3];
|
||||
H5::DataSpace dataspace = dataset.getSpace();
|
||||
dataspace.getSimpleExtentDims( dims, nullptr );
|
||||
|
||||
resultValues.resize( dims[0] * dims[1] * dims[2] );
|
||||
dataset.read( resultValues.data(), H5::PredType::NATIVE_DOUBLE );
|
||||
|
||||
resultData[objName] = resultValues;
|
||||
}
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#endif // USE_HDF5
|
||||
Reference in New Issue
Block a user