Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Dec 17, 2023
1 parent 80c151b commit 8b5079b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 88 deletions.
138 changes: 53 additions & 85 deletions ApplicationLibCode/ProjectDataModel/RimEmCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,16 @@
#include "RiaLogging.h"
#include "RiaPreferences.h"

#include "RifInputPropertyLoader.h"
#include "RifRoffFileTools.h"

#include "RigActiveCellInfo.h"
#include "RigCaseCellResultsData.h"
#include "RigEclipseCaseData.h"
#include "RigEclipseResultAddress.h"
#include "RigMainGrid.h"
#include "RigReservoirBuilder.h"

#include "RimEclipseInputProperty.h"
#include "RimEclipseInputPropertyCollection.h"
#include "RimReservoirCellResultsStorage.h"
#include "H5Cpp.h"

#include "cafPdmObjectScriptingCapability.h"
#include "cafProgressInfo.h"

#include "H5Cpp.h"

#include <QDir>
#include <QFileInfo>
Expand All @@ -49,7 +41,6 @@ CAF_PDM_SOURCE_INIT( RimEmCase, "RimEmCase" );
///
//--------------------------------------------------------------------------------------------------
RimEmCase::RimEmCase()
: RimEclipseCase()
{
CAF_PDM_InitScriptableObject( "RimEmCase", ":/EclipseInput48x48.png" );
}
Expand Down Expand Up @@ -82,71 +73,65 @@ bool RimEmCase::openEclipseGridFile()
std::array<int, 3> numCells;
std::map<std::string, std::vector<float>> resultData;

if ( eclipseCaseData()->mainGrid()->gridPointDimensions() == cvf::Vec3st( 0, 0, 0 ) )
try
{
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 );

{
H5::Exception::dontPrint(); // Turn off auto-printing of failures to handle the errors appropriately
auto attr = mainFile.openAttribute( "description::OriginNED" );
H5::DataType type = attr.getDataType();
auto storageSize = attr.getStorageSize();
attr.read( type, originNED.data() );
}

H5::H5File mainFile( fileName.toStdString().c_str(),
H5F_ACC_RDONLY ); // initial date part is an attribute of SourSimRL main file
{
H5::Group group = mainFile.openGroup( "Mesh" );

{
auto attr = mainFile.openAttribute( "description::OriginNED" );
auto attr = group.openAttribute( "cell_sizes" );
H5::DataType type = attr.getDataType();
auto storageSize = attr.getStorageSize();
attr.read( type, originNED.data() );
attr.read( type, cellSizes.data() );
}

{
H5::Group group = mainFile.openGroup( "Mesh" );

{
auto attr = group.openAttribute( "cell_sizes" );
H5::DataType type = attr.getDataType();
auto storageSize = attr.getStorageSize();
attr.read( type, cellSizes.data() );
}
{
auto attr = group.openAttribute( "num_cells" );
H5::DataType type = attr.getDataType();
auto storageSize = attr.getStorageSize();
attr.read( type, numCells.data() );
}
{
auto attr = group.openAttribute( "origin" );
H5::DataType type = attr.getDataType();
auto storageSize = attr.getStorageSize();
attr.read( type, originMesh.data() );
}
auto attr = group.openAttribute( "num_cells" );
H5::DataType type = attr.getDataType();
auto storageSize = attr.getStorageSize();
attr.read( type, numCells.data() );
}

H5::Group group = mainFile.openGroup( "Data" );
auto numObj = group.getNumObjs();
for ( auto i = 0; i < numObj; i++ )
{
auto objName = group.getObjnameByIdx( i );
auto objType = group.getObjTypeByIdx( i );
auto attr = group.openAttribute( "origin" );
H5::DataType type = attr.getDataType();
auto storageSize = attr.getStorageSize();
attr.read( type, originMesh.data() );
}
}

std::vector<float> resultValues;
H5::DataSet dataset = H5::DataSet( group.openDataSet( objName ) );
H5::Group group = mainFile.openGroup( "Data" );
auto numObj = group.getNumObjs();
for ( auto i = 0; i < numObj; i++ )
{
auto resultName = group.getObjnameByIdx( i );

hsize_t dims[3];
H5::DataSpace dataspace = dataset.getSpace();
dataspace.getSimpleExtentDims( dims, nullptr );
std::vector<float> resultValues;
H5::DataSet dataset = H5::DataSet( group.openDataSet( resultName ) );

resultValues.resize( dims[0] * dims[1] * dims[2] );
dataset.read( resultValues.data(), H5::PredType::NATIVE_FLOAT );
hsize_t dims[3];
H5::DataSpace dataspace = dataset.getSpace();
dataspace.getSimpleExtentDims( dims, nullptr );

resultData[objName] = resultValues;
}
}
catch ( ... )
{
resultValues.resize( dims[0] * dims[1] * dims[2] );
dataset.read( resultValues.data(), H5::PredType::NATIVE_FLOAT );

resultData[resultName] = resultValues;
}
}
catch ( ... )
{
}

if ( numCells[0] > 0 )
{
RigReservoirBuilder builder;

Expand Down Expand Up @@ -174,40 +159,37 @@ bool RimEmCase::openEclipseGridFile()

results( RiaDefines::PorosityModelType::MATRIX_MODEL )->computeCellVolumes();

for ( auto data : resultData )
for ( auto [resultName, data] : resultData )
{
QString newResultName =
eclipseCaseData()->results( RiaDefines::PorosityModelType::MATRIX_MODEL )->makeResultNameUnique( QString::fromStdString( data.first ) );
QString riResultName =
eclipseCaseData()->results( RiaDefines::PorosityModelType::MATRIX_MODEL )->makeResultNameUnique( QString::fromStdString( resultName ) );

RigEclipseResultAddress resAddr( RiaDefines::ResultCatType::INPUT_PROPERTY, RiaDefines::ResultDataType::FLOAT, newResultName );
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;

auto ordering = numCells;
ordering[0] = numCells[2];
ordering[2] = numCells[0];
auto kjiNumCells = numCells;
kjiNumCells[0] = numCells[2];
kjiNumCells[2] = numCells[0];

for ( size_t i = 0; i < ordering[0]; i++ )
for ( size_t k = 0; k < kjiNumCells[0]; k++ )
{
for ( size_t j = 0; j < ordering[1]; j++ )
for ( size_t j = 0; j < kjiNumCells[1]; j++ )
{
for ( size_t k = 0; k < ordering[2]; k++ )
for ( size_t i = 0; i < kjiNumCells[2]; i++ )
{
reorganizedData.push_back( data.second[i + j * ordering[0] + k * ordering[0] * ordering[1]] );
reorganizedData.push_back( data[k + j * kjiNumCells[0] + i * kjiNumCells[0] * kjiNumCells[1]] );
}
}
}

newPropertyData->push_back( reorganizedData );
}

// Read properties from input property collection
loadAndSynchronizeInputProperties( false );

return true;
}

Expand Down Expand Up @@ -246,17 +228,3 @@ QString RimEmCase::locationOnDisc() const
QFileInfo fi( gridFileName() );
return fi.absolutePath();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimEmCase::importAsciiInputProperties( const QStringList& fileNames )
{
bool importFaults = false;
RifInputPropertyLoader::loadAndSynchronizeInputProperties( m_inputPropertyCollection,
eclipseCaseData(),
std::vector<QString>( fileNames.begin(), fileNames.end() ),
importFaults );

return true;
}
3 changes: 0 additions & 3 deletions ApplicationLibCode/ProjectDataModel/RimEmCase.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@ class RimEmCase : public RimEclipseCase

bool openEclipseGridFile() override;
void reloadEclipseGridFile() override;
bool importAsciiInputProperties( const QStringList& fileNames ) override;

QString locationOnDisc() const override;

protected:
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;

private:
};

0 comments on commit 8b5079b

Please sign in to comment.