mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#5989 Add parser for facies properties csv file
This commit is contained in:
committed by
Magne Sjaastad
parent
ee20ec4107
commit
d443f97a1a
@@ -53,6 +53,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RifEclipseInputPropertyLoader.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifSurfaceReader.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifRoffReader.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifColorLegendData.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifFaciesPropertiesReader.h
|
||||
|
||||
# HDF5 file reader is directly included in ResInsight main CmakeList.txt
|
||||
#${CMAKE_CURRENT_LIST_DIR}/RifHdf5Reader.h
|
||||
@@ -110,6 +111,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RifEclipseInputPropertyLoader.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifSurfaceReader.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifRoffReader.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifColorLegendData.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifFaciesPropertiesReader.cpp
|
||||
|
||||
# HDF5 file reader is directly included in ResInsight main CmakeList.txt
|
||||
#${CMAKE_CURRENT_LIST_DIR}/RifHdf5Reader.cpp
|
||||
|
||||
171
ApplicationCode/FileInterface/RifFaciesPropertiesReader.cpp
Normal file
171
ApplicationCode/FileInterface/RifFaciesPropertiesReader.cpp
Normal file
@@ -0,0 +1,171 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2020- Equinor 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 "RifFaciesPropertiesReader.h"
|
||||
|
||||
#include "RifFileParseTools.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QTextStream>
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
void RifFaciesPropertiesReader::readFaciesProperties( std::vector<RifFaciesProperties>& faciesProperties,
|
||||
const QStringList& filePaths )
|
||||
{
|
||||
for ( const QString& filePath : filePaths )
|
||||
{
|
||||
try
|
||||
{
|
||||
readFaciesProperties( faciesProperties, filePath );
|
||||
}
|
||||
catch ( FileParseException& )
|
||||
{
|
||||
// Delete all facies properties and rethrow exception
|
||||
faciesProperties.clear();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifFaciesPropertiesReader::readFaciesProperties( std::vector<RifFaciesProperties>& faciesProperties,
|
||||
const QString& filePath )
|
||||
{
|
||||
QFile file( filePath );
|
||||
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
||||
{
|
||||
throw FileParseException( QString( "Unable to open file: %1" ).arg( filePath ) );
|
||||
}
|
||||
|
||||
QTextStream in( &file );
|
||||
int lineNumber = 1;
|
||||
while ( !in.atEnd() )
|
||||
{
|
||||
QString line = in.readLine();
|
||||
if ( !isEmptyLine( line ) && !isCommentLine( line ) )
|
||||
{
|
||||
RifFaciesProperties faciesProp = parseFaciesProperties( line, lineNumber, filePath );
|
||||
faciesProperties.push_back( faciesProp );
|
||||
}
|
||||
|
||||
lineNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifFaciesProperties
|
||||
RifFaciesPropertiesReader::parseFaciesProperties( const QString& line, int lineNumber, const QString& filePath )
|
||||
{
|
||||
QStringList tokens = tokenize( line, "," );
|
||||
|
||||
if ( tokens.size() != 8 )
|
||||
{
|
||||
throw FileParseException( QString( "Incomplete data on line %1: %2" ).arg( lineNumber ).arg( filePath ) );
|
||||
}
|
||||
|
||||
// Check for unexpected empty tokens
|
||||
QStringList nameOfNonEmptyTokens;
|
||||
nameOfNonEmptyTokens << "Field Name"
|
||||
<< "Formation Name"
|
||||
<< "Facies Name"
|
||||
<< "Porosity"
|
||||
<< "Young's Modulus"
|
||||
<< "Poisson's Ratio"
|
||||
<< "K-Ic"
|
||||
<< "Proppant Embedment";
|
||||
verifyNonEmptyTokens( tokens, nameOfNonEmptyTokens, lineNumber, filePath );
|
||||
|
||||
RifFaciesProperties faciesProperties;
|
||||
faciesProperties.fieldName = tokens[0];
|
||||
faciesProperties.formationName = tokens[1];
|
||||
faciesProperties.faciesName = tokens[2];
|
||||
faciesProperties.porosity = parseDouble( tokens[3], "Porosity", lineNumber, filePath );
|
||||
faciesProperties.youngsModulus = parseDouble( tokens[4], "Young's Modulus", lineNumber, filePath );
|
||||
faciesProperties.poissonsRatio = parseDouble( tokens[5], "Poisson's Ratio", lineNumber, filePath );
|
||||
faciesProperties.K_Ic = parseDouble( tokens[6], "K-Ic", lineNumber, filePath );
|
||||
faciesProperties.proppantEmbedment = parseDouble( tokens[7], "Proppant Embedment", lineNumber, filePath );
|
||||
|
||||
return faciesProperties;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QStringList RifFaciesPropertiesReader::tokenize( const QString& line, const QString& separator )
|
||||
{
|
||||
return RifFileParseTools::splitLineAndTrim( line, separator );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RifFaciesPropertiesReader::parseDouble( const QString& token,
|
||||
const QString& propertyName,
|
||||
int lineNumber,
|
||||
const QString& filePath )
|
||||
{
|
||||
bool isOk = false;
|
||||
double value = token.toDouble( &isOk );
|
||||
if ( !isOk )
|
||||
{
|
||||
throw FileParseException(
|
||||
QString( "Invalid number for '%1' on line %2: %3" ).arg( propertyName ).arg( lineNumber ).arg( filePath ) );
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifFaciesPropertiesReader::isEmptyLine( const QString& line )
|
||||
{
|
||||
return line.trimmed().isEmpty();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifFaciesPropertiesReader::isCommentLine( const QString& line )
|
||||
{
|
||||
return line.trimmed().startsWith( "#" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RifFaciesPropertiesReader::verifyNonEmptyTokens( const QStringList& tokens,
|
||||
const QStringList& nameOfNonEmptyTokens,
|
||||
int lineNumber,
|
||||
const QString& filePath )
|
||||
{
|
||||
for ( int i = 0; i < nameOfNonEmptyTokens.size(); ++i )
|
||||
{
|
||||
if ( tokens[i].isEmpty() )
|
||||
{
|
||||
throw FileParseException(
|
||||
QString( "Unexpected empty '%1' on line %2: %3" ).arg( nameOfNonEmptyTokens[i] ).arg( lineNumber ).arg( filePath ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
58
ApplicationCode/FileInterface/RifFaciesPropertiesReader.h
Normal file
58
ApplicationCode/FileInterface/RifFaciesPropertiesReader.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2020- Equinor 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 <vector>
|
||||
|
||||
#include <QString>
|
||||
|
||||
struct RifFaciesProperties
|
||||
{
|
||||
QString fieldName;
|
||||
QString formationName;
|
||||
QString faciesName;
|
||||
double porosity;
|
||||
double youngsModulus;
|
||||
double poissonsRatio;
|
||||
double K_Ic;
|
||||
double proppantEmbedment;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RifFaciesPropertiesReader
|
||||
{
|
||||
public:
|
||||
static void readFaciesProperties( std::vector<RifFaciesProperties>& faciesProperties, const QStringList& filePaths );
|
||||
|
||||
private:
|
||||
static void readFaciesProperties( std::vector<RifFaciesProperties>& faciesProperties, const QString& filePath );
|
||||
static RifFaciesProperties parseFaciesProperties( const QString& line, int lineNumber, const QString& filePath );
|
||||
static QStringList tokenize( const QString& line, const QString& separator );
|
||||
static void verifyNonEmptyTokens( const QStringList& tokens,
|
||||
const QStringList& nameOfNonEmptyTokens,
|
||||
int lineNumber,
|
||||
const QString& filePath );
|
||||
|
||||
static double parseDouble( const QString& token, const QString& propertyName, int lineNumber, const QString& filePath );
|
||||
|
||||
static bool isEmptyLine( const QString& line );
|
||||
static bool isCommentLine( const QString& line );
|
||||
};
|
||||
Reference in New Issue
Block a user