Roff: support import of N grid files and 1 grid file with N property files

* Add utility to check is roff file contains grid data

* Import of multiple grid files or 1 grid file with N property files

* Fix build errors for using RifRoffFileTools from Commands
- Move template implementation to cpp-file
- Add roffcpp to link libraries in CMake for Commands

* Improve/fix import of single grid file with N property files

* Fix missing add of roff case Id
This commit is contained in:
Jørgen Herje
2023-04-19 15:52:57 +02:00
committed by GitHub
parent 643ccd67b8
commit 67264da0a8
7 changed files with 219 additions and 51 deletions

View File

@@ -42,6 +42,32 @@
using namespace std::chrono;
//--------------------------------------------------------------------------------------------------
/// NOTE: Moved from header file due to compile header when using RifRoffFileTools from
/// ApplicationLibCode/Commands
//--------------------------------------------------------------------------------------------------
template <typename IN, typename OUT>
static void convertToReservoirIndexOrder( int nx, int ny, int nz, const std::vector<IN>& in, std::vector<OUT>& out )
{
CAF_ASSERT( static_cast<size_t>( nx * ny * nz ) == in.size() );
out.resize( in.size(), -1 );
int outIdx = 0;
for ( int k = 0; k < nz; k++ )
{
for ( int j = 0; j < ny; j++ )
{
for ( int i = 0; i < nx; i++ )
{
int inIdx = i * ny * nz + j * nz + ( nz - k - 1 );
out[outIdx] = static_cast<OUT>( in[inIdx] );
outIdx++;
}
}
}
}
//--------------------------------------------------------------------------------------------------
/// Constructor
//--------------------------------------------------------------------------------------------------
@@ -520,6 +546,37 @@ std::pair<bool, std::map<QString, QString>> RifRoffFileTools::createInputPropert
return std::make_pair( true, keywordMapping );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifRoffFileTools::hasGridData( const QString& filename )
{
// Check if arrayTypes contains grid info
// - Alt 1. Look for tag "cornerLines" and its data with keyword "cornerLines.data" - actual representation of grid data
// - Alt 2. Look for tag "filedata" and its filetype with keyword "filedata.filetype" - should be equal "grid" (not as robust, rather
// look for "cornerLines" which is grid representation)
std::ifstream stream( filename.toStdString(), std::ios::binary );
if ( !stream.good() )
{
RiaLogging::error( "Unable to open roff file" );
return false;
}
roff::Reader reader( stream );
reader.parse();
const std::vector<std::pair<std::string, roff::Token::Kind>> arrayTypes = reader.getNamedArrayTypes();
const std::string cornerLinesDataKeyword = "cornerLines.data";
auto cornerLinesDataItr = std::find_if( arrayTypes.begin(),
arrayTypes.end(),
[&cornerLinesDataKeyword]( const auto& arrayType )
{ return arrayType.first == cornerLinesDataKeyword; } );
return cornerLinesDataItr != arrayTypes.end();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -53,6 +53,8 @@ public:
static std::pair<bool, std::map<QString, QString>> createInputProperties( const QString& fileName, RigEclipseCaseData* eclipseCase );
static bool hasGridData( const QString& filename );
private:
static void interpretSplitenzData( int nz,
float zoffset,
@@ -81,26 +83,4 @@ private:
const std::string& keyword,
roff::Token::Kind token,
roff::Reader& reader );
template <typename IN, typename OUT>
static void convertToReservoirIndexOrder( int nx, int ny, int nz, const std::vector<IN>& in, std::vector<OUT>& out )
{
CAF_ASSERT( static_cast<size_t>( nx ) * ny * nz == in.size() );
out.resize( in.size(), -1 );
int outIdx = 0;
for ( int k = 0; k < nz; k++ )
{
for ( int j = 0; j < ny; j++ )
{
for ( int i = 0; i < nx; i++ )
{
int inIdx = i * ny * nz + j * nz + ( nz - k - 1 );
out[outIdx] = static_cast<OUT>( in[inIdx] );
outIdx++;
}
}
}
}
};