mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#926 Eclipse Input Data : Import custom keyword data
This commit is contained in:
@@ -48,75 +48,6 @@ QString gridKeyword("GRID");
|
||||
QString pathsKeyword("PATHS");
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t findOrCreateResult(const QString& newResultName, RigCaseData* reservoir)
|
||||
{
|
||||
size_t resultIndex = reservoir->results(RifReaderInterface::MATRIX_RESULTS)->findScalarResultIndex(newResultName);
|
||||
if (resultIndex == cvf::UNDEFINED_SIZE_T)
|
||||
{
|
||||
resultIndex = reservoir->results(RifReaderInterface::MATRIX_RESULTS)->addEmptyScalarResult(RimDefines::INPUT_PROPERTY, newResultName, false);
|
||||
}
|
||||
|
||||
return resultIndex;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Read all double values from input file. To reduce memory footprint, the alternative method
|
||||
/// readDoubleValuesForActiveCells() can be used, and will skip all cell values for inactive cells
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool readDoubleValues(RigCaseData* reservoir, size_t resultIndex, ecl_kw_type* eclKeyWordData)
|
||||
{
|
||||
if (resultIndex == cvf::UNDEFINED_SIZE_T) return false;
|
||||
|
||||
std::vector< std::vector<double> >& newPropertyData = reservoir->results(RifReaderInterface::MATRIX_RESULTS)->cellScalarResults(resultIndex);
|
||||
newPropertyData.push_back(std::vector<double>());
|
||||
newPropertyData[0].resize(ecl_kw_get_size(eclKeyWordData), HUGE_VAL);
|
||||
ecl_kw_get_data_as_double(eclKeyWordData, newPropertyData[0].data());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool readDoubleValuesForActiveCells(RigCaseData* reservoir, size_t resultIndex, ecl_kw_type* eclKeyWordData)
|
||||
{
|
||||
if (resultIndex == cvf::UNDEFINED_SIZE_T) return false;
|
||||
|
||||
std::vector< std::vector<double> >& newPropertyData = reservoir->results(RifReaderInterface::MATRIX_RESULTS)->cellScalarResults(resultIndex);
|
||||
newPropertyData.push_back(std::vector<double>());
|
||||
|
||||
RigActiveCellInfo* activeCellInfo = reservoir->activeCellInfo(RifReaderInterface::MATRIX_RESULTS);
|
||||
if (activeCellInfo->reservoirCellCount() > 0 && activeCellInfo->reservoirCellCount() != activeCellInfo->reservoirActiveCellCount())
|
||||
{
|
||||
std::vector<double> valuesAllCells;
|
||||
valuesAllCells.resize(ecl_kw_get_size(eclKeyWordData), HUGE_VAL);
|
||||
ecl_kw_get_data_as_double(eclKeyWordData, valuesAllCells.data());
|
||||
|
||||
newPropertyData[0].resize(activeCellInfo->reservoirActiveCellCount(), HUGE_VAL);
|
||||
std::vector<double>& valuesActiveCells = newPropertyData[0];
|
||||
|
||||
for (size_t gcIdx = 0; gcIdx < activeCellInfo->reservoirCellCount(); gcIdx++)
|
||||
{
|
||||
size_t activeCellResultIndex = activeCellInfo->cellResultIndex(gcIdx);
|
||||
if (activeCellResultIndex != cvf::UNDEFINED_SIZE_T)
|
||||
{
|
||||
valuesActiveCells[activeCellResultIndex] = valuesAllCells[gcIdx];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
newPropertyData[0].resize(ecl_kw_get_size(eclKeyWordData), HUGE_VAL);
|
||||
ecl_kw_get_data_as_double(eclKeyWordData, newPropertyData[0].data());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Constructor
|
||||
@@ -268,18 +199,11 @@ bool RifEclipseInputFileTools::openGridFile(const QString& fileName, RigCaseData
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Read known properties from the input file
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<QString, QString> RifEclipseInputFileTools::readProperties(const QString &fileName, RigCaseData* caseData)
|
||||
std::map<QString, QString> RifEclipseInputFileTools::readProperties(const QString& fileName, RigCaseData* caseData)
|
||||
{
|
||||
CVF_ASSERT(caseData);
|
||||
|
||||
std::set<QString> knownKeywordSet;
|
||||
{
|
||||
const std::vector<QString>& knownKeywords = RifEclipseInputFileTools::knownPropertyKeywords();
|
||||
for( size_t fkIt = 0; fkIt < knownKeywords.size(); ++fkIt) knownKeywordSet.insert(knownKeywords[fkIt]);
|
||||
}
|
||||
|
||||
caf::ProgressInfo mainProgress(2, "Reading Eclipse Input properties");
|
||||
caf::ProgressInfo startProgress(knownKeywordSet.size(), "Scanning for known properties");
|
||||
|
||||
std::vector<RifKeywordAndFilePos> fileKeywords;
|
||||
RifEclipseInputFileTools::findKeywordsOnFile(fileName, &fileKeywords);
|
||||
@@ -297,25 +221,22 @@ std::map<QString, QString> RifEclipseInputFileTools::readProperties(const QStri
|
||||
std::map<QString, QString> newResults;
|
||||
for (size_t i = 0; i < fileKeywords.size(); ++i)
|
||||
{
|
||||
//std::cout << fileKeywords[i].keyword.toLatin1().data() << std::endl;
|
||||
if (knownKeywordSet.count(fileKeywords[i].keyword))
|
||||
if (!isValidDataKeyword(fileKeywords[i].keyword)) continue;
|
||||
|
||||
fseek(gridFilePointer, fileKeywords[i].filePos, SEEK_SET);
|
||||
|
||||
ecl_kw_type* eclipseKeywordData = ecl_kw_fscanf_alloc_current_grdecl__(gridFilePointer, false, ECL_FLOAT_TYPE);
|
||||
if (eclipseKeywordData)
|
||||
{
|
||||
fseek(gridFilePointer, fileKeywords[i].filePos, SEEK_SET);
|
||||
ecl_kw_type* eclipseKeywordData = ecl_kw_fscanf_alloc_current_grdecl__(gridFilePointer, false , ECL_FLOAT_TYPE);
|
||||
if (eclipseKeywordData)
|
||||
QString newResultName = caseData->results(RifReaderInterface::MATRIX_RESULTS)->makeResultNameUnique(fileKeywords[i].keyword);
|
||||
if (readDataFromKeyword(eclipseKeywordData, caseData, newResultName))
|
||||
{
|
||||
QString newResultName = caseData->results(RifReaderInterface::MATRIX_RESULTS)->makeResultNameUnique(fileKeywords[i].keyword);
|
||||
|
||||
size_t resultIndex = findOrCreateResult(newResultName, caseData);
|
||||
if (resultIndex != cvf::UNDEFINED_SIZE_T)
|
||||
{
|
||||
readDoubleValues(caseData, resultIndex, eclipseKeywordData);
|
||||
}
|
||||
|
||||
ecl_kw_free(eclipseKeywordData);
|
||||
newResults[newResultName] = fileKeywords[i].keyword;
|
||||
}
|
||||
|
||||
ecl_kw_free(eclipseKeywordData);
|
||||
}
|
||||
|
||||
progress.setProgress(i);
|
||||
}
|
||||
|
||||
@@ -323,6 +244,65 @@ std::map<QString, QString> RifEclipseInputFileTools::readProperties(const QStri
|
||||
return newResults;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Reads the property data requested into the \a reservoir, overwriting any previous
|
||||
/// properties with the same name.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifEclipseInputFileTools::readProperty(const QString& fileName, RigCaseData* caseData, const QString& eclipseKeyWord, const QString& resultName)
|
||||
{
|
||||
CVF_ASSERT(caseData);
|
||||
|
||||
if (!isValidDataKeyword(eclipseKeyWord)) return false;
|
||||
|
||||
FILE* filePointer = util_fopen(fileName.toLatin1().data(), "r");
|
||||
if (!filePointer) return false;
|
||||
|
||||
ecl_kw_type* eclipseKeywordData = ecl_kw_fscanf_alloc_grdecl_dynamic__(filePointer, eclipseKeyWord.toLatin1().data(), false, ECL_FLOAT_TYPE);
|
||||
bool isOk = false;
|
||||
if (eclipseKeywordData)
|
||||
{
|
||||
isOk = readDataFromKeyword(eclipseKeywordData, caseData, resultName);
|
||||
|
||||
ecl_kw_free(eclipseKeywordData);
|
||||
}
|
||||
|
||||
util_fclose(filePointer);
|
||||
|
||||
return isOk;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifEclipseInputFileTools::readDataFromKeyword(ecl_kw_type* eclipseKeywordData, RigCaseData* caseData, const QString& resultName)
|
||||
{
|
||||
bool mathingItemCount = false;
|
||||
{
|
||||
int itemCount = ecl_kw_get_size(eclipseKeywordData);
|
||||
if (itemCount == caseData->mainGrid()->cellCount())
|
||||
{
|
||||
mathingItemCount = true;
|
||||
}
|
||||
if (itemCount == caseData->activeCellInfo(RifReaderInterface::MATRIX_RESULTS)->reservoirActiveCellCount())
|
||||
{
|
||||
mathingItemCount = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!mathingItemCount) return false;
|
||||
|
||||
size_t resultIndex = RifEclipseInputFileTools::findOrCreateResult(resultName, caseData);
|
||||
if (resultIndex == cvf::UNDEFINED_SIZE_T) return false;
|
||||
|
||||
std::vector< std::vector<double> >& newPropertyData = caseData->results(RifReaderInterface::MATRIX_RESULTS)->cellScalarResults(resultIndex);
|
||||
newPropertyData.push_back(std::vector<double>());
|
||||
newPropertyData[0].resize(ecl_kw_get_size(eclipseKeywordData), HUGE_VAL);
|
||||
ecl_kw_get_data_as_double(eclipseKeywordData, newPropertyData[0].data());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Read all the keywords from a file
|
||||
//
|
||||
@@ -432,36 +412,33 @@ void RifEclipseInputFileTools::parseAndReadPathAliasKeyword(const QString &fileN
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Reads the property data requested into the \a reservoir, overwriting any previous
|
||||
/// properties with the same name.
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifEclipseInputFileTools::readProperty(const QString& fileName, RigCaseData* caseData, const QString& eclipseKeyWord, const QString& resultName)
|
||||
const std::vector<QString>& RifEclipseInputFileTools::invalidPropertyDataKeywords()
|
||||
{
|
||||
CVF_ASSERT(caseData);
|
||||
|
||||
FILE* filePointer = util_fopen(fileName.toLatin1().data(), "r");
|
||||
if (!filePointer) return false;
|
||||
|
||||
ecl_kw_type* eclipseKeywordData = ecl_kw_fscanf_alloc_grdecl_dynamic__( filePointer , eclipseKeyWord.toLatin1().data() , false , ECL_FLOAT_TYPE);
|
||||
bool isOk = false;
|
||||
if (eclipseKeywordData)
|
||||
static std::vector<QString> keywords;
|
||||
static bool isInitialized = false;
|
||||
if (!isInitialized)
|
||||
{
|
||||
size_t resultIndex = findOrCreateResult(resultName, caseData);
|
||||
if (resultIndex != cvf::UNDEFINED_SIZE_T)
|
||||
{
|
||||
isOk = readDoubleValues(caseData, resultIndex, eclipseKeywordData);
|
||||
}
|
||||
// Related to geometry
|
||||
keywords.push_back("COORD");
|
||||
keywords.push_back("ZCORN");
|
||||
keywords.push_back("SPECGRID");
|
||||
keywords.push_back("MAPAXES");
|
||||
|
||||
ecl_kw_free(eclipseKeywordData);
|
||||
keywords.push_back(faultsKeyword);
|
||||
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
util_fclose(filePointer);
|
||||
return isOk;
|
||||
return keywords;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
const std::vector<QString>& RifEclipseInputFileTools::knownPropertyKeywords()
|
||||
{
|
||||
static std::vector<QString> knownKeywords;
|
||||
@@ -513,6 +490,7 @@ const std::vector<QString>& RifEclipseInputFileTools::knownPropertyKeywords()
|
||||
}
|
||||
return knownKeywords;
|
||||
}
|
||||
*/
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@@ -788,6 +766,37 @@ qint64 RifEclipseInputFileTools::findKeyword(const QString& keyword, QFile& file
|
||||
return -1;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t RifEclipseInputFileTools::findOrCreateResult(const QString& newResultName, RigCaseData* reservoir)
|
||||
{
|
||||
size_t resultIndex = reservoir->results(RifReaderInterface::MATRIX_RESULTS)->findScalarResultIndex(newResultName);
|
||||
if (resultIndex == cvf::UNDEFINED_SIZE_T)
|
||||
{
|
||||
resultIndex = reservoir->results(RifReaderInterface::MATRIX_RESULTS)->addEmptyScalarResult(RimDefines::INPUT_PROPERTY, newResultName, false);
|
||||
}
|
||||
|
||||
return resultIndex;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifEclipseInputFileTools::isValidDataKeyword(const QString& keyword)
|
||||
{
|
||||
const std::vector<QString>& keywordsToSkip = RifEclipseInputFileTools::invalidPropertyDataKeywords();
|
||||
for (const QString keywordToSkip : keywordsToSkip)
|
||||
{
|
||||
if (keywordToSkip == keyword.toUpper())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -23,11 +23,15 @@
|
||||
#include "cvfBase.h"
|
||||
#include "cvfObject.h"
|
||||
#include "cvfLibCore.h"
|
||||
|
||||
#include "RifReaderInterface.h"
|
||||
#include "RigFault.h"
|
||||
|
||||
#include "ert/ecl/ecl_kw.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <QString>
|
||||
#include "RifReaderInterface.h"
|
||||
#include "RigFault.h"
|
||||
|
||||
|
||||
class RigCaseData;
|
||||
@@ -60,7 +64,7 @@ public:
|
||||
// Returns map of assigned resultName and Eclipse Keyword.
|
||||
static std::map<QString, QString> readProperties(const QString& fileName, RigCaseData* eclipseCase);
|
||||
static bool readProperty (const QString& fileName, RigCaseData* eclipseCase, const QString& eclipseKeyWord, const QString& resultName );
|
||||
|
||||
|
||||
static void readFaultsInGridSection(const QString& fileName, cvf::Collection<RigFault>* faults, std::vector<QString>* filenamesWithFaults);
|
||||
static void readFaults(const QString& fileName, const std::vector< RifKeywordAndFilePos >& fileKeywords, cvf::Collection<RigFault>* faults);
|
||||
static void parseAndReadFaults(const QString& fileName, cvf::Collection<RigFault>* faults);
|
||||
@@ -70,7 +74,6 @@ public:
|
||||
|
||||
static void parseAndReadPathAliasKeyword(const QString &fileName, std::vector< std::pair<QString, QString> >* pathAliasDefinitions);
|
||||
|
||||
static const std::vector<QString>& knownPropertyKeywords();
|
||||
|
||||
static bool writePropertyToTextFile(const QString& fileName, RigCaseData* eclipseCase, size_t timeStep, const QString& resultName, const QString& eclipseKeyWord);
|
||||
static bool writeBinaryResultToTextFile(const QString& fileName, RigCaseData* eclipseCase, RifReaderInterface::PorosityModelResultType porosityModel, size_t timeStep, const QString& resultName, const QString& eclipseKeyWord, const double undefinedValue);
|
||||
@@ -85,10 +88,16 @@ public:
|
||||
static cvf::StructGridInterface::FaceEnum faceEnumFromText(const QString& faceString);
|
||||
|
||||
private:
|
||||
static bool readDataFromKeyword(ecl_kw_type* eclipseKeywordData, RigCaseData* caseData, const QString& resultName);
|
||||
static void writeDataToTextFile(QFile* file, const QString& eclipseKeyWord, const std::vector<double>& resultData);
|
||||
static void findGridKeywordPositions(const std::vector< RifKeywordAndFilePos >& keywords, qint64* coordPos, qint64* zcornPos, qint64* specgridPos, qint64* actnumPos, qint64* mapaxesPos);
|
||||
|
||||
static size_t findFaultByName(const cvf::Collection<RigFault>& faults, const QString& name);
|
||||
|
||||
static qint64 findKeyword(const QString& keyword, QFile& file, qint64 startPos);
|
||||
static size_t findOrCreateResult(const QString& newResultName, RigCaseData* reservoir);
|
||||
static bool isValidDataKeyword(const QString& keyword);
|
||||
|
||||
private:
|
||||
static const std::vector<QString>& invalidPropertyDataKeywords();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user