#928 Refactoring and simplification of code

This commit is contained in:
Magne Sjaastad 2016-10-21 08:48:33 +02:00
parent dbb928c8b1
commit 1fd5ffb522
7 changed files with 88 additions and 40 deletions

View File

@ -143,7 +143,7 @@ bool RifEclipseInputFileTools::openGridFile(const QString& fileName, RigCaseData
CVF_ASSERT(eclipseCase);
std::vector< RifKeywordAndFilePos > keywordsAndFilePos;
findKeywordsOnFile(fileName, keywordsAndFilePos);
findKeywordsOnFile(fileName, &keywordsAndFilePos);
qint64 coordPos = -1;
qint64 zcornPos = -1;
@ -241,7 +241,7 @@ bool RifEclipseInputFileTools::openGridFile(const QString& fileName, RigCaseData
if (readFaultData)
{
cvf::Collection<RigFault> faults;
RifEclipseInputFileTools::readFaults(fileName, faults, keywordsAndFilePos);
RifEclipseInputFileTools::readFaults(fileName, keywordsAndFilePos, &faults);
RigMainGrid* mainGrid = eclipseCase->mainGrid();
mainGrid->setFaults(faults);
@ -281,7 +281,7 @@ std::map<QString, QString> RifEclipseInputFileTools::readProperties(const QStri
caf::ProgressInfo startProgress(knownKeywordSet.size(), "Scanning for known properties");
std::vector<RifKeywordAndFilePos> fileKeywords;
RifEclipseInputFileTools::findKeywordsOnFile(fileName, fileKeywords);
RifEclipseInputFileTools::findKeywordsOnFile(fileName, &fileKeywords);
mainProgress.setProgress(1);
caf::ProgressInfo progress(fileKeywords.size(), "Reading properties");
@ -332,7 +332,7 @@ std::map<QString, QString> RifEclipseInputFileTools::readProperties(const QStri
// https://bugreports.qt-project.org/browse/QTBUG-9814
//
//--------------------------------------------------------------------------------------------------
void RifEclipseInputFileTools::findKeywordsOnFile(const QString &fileName, std::vector< RifKeywordAndFilePos >& keywords)
void RifEclipseInputFileTools::findKeywordsOnFile(const QString &fileName, std::vector< RifKeywordAndFilePos >* keywords)
{
char buf[1024];
@ -356,7 +356,7 @@ void RifEclipseInputFileTools::findKeywordsOnFile(const QString &fileName, std::
filepos = data.pos() - lineLength;
keyPos.filePos = filepos;
keyPos.keyword = line.left(8).trimmed();
keywords.push_back(keyPos);
keywords->push_back(keyPos);
//qDebug() << keyPos.keyword << " - " << keyPos.filePos;
}
}
@ -366,7 +366,7 @@ void RifEclipseInputFileTools::findKeywordsOnFile(const QString &fileName, std::
//--------------------------------------------------------------------------------------------------
/// Reads the property data requested into the \a reservoir, overwriting any previous
/// propeties with the same name.
/// properties with the same name.
//--------------------------------------------------------------------------------------------------
bool RifEclipseInputFileTools::readProperty(const QString& fileName, RigCaseData* caseData, const QString& eclipseKeyWord, const QString& resultName)
{
@ -626,7 +626,7 @@ bool RifEclipseInputFileTools::readPropertyAtFilePosition(const QString& fileNam
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifEclipseInputFileTools::readFaults(const QString& fileName, cvf::Collection<RigFault>& faults, const std::vector<RifKeywordAndFilePos>& fileKeywords)
void RifEclipseInputFileTools::readFaults(const QString& fileName, const std::vector<RifKeywordAndFilePos>& fileKeywords, cvf::Collection<RigFault>* faults)
{
QFile data(fileName);
if (!data.open(QFile::ReadOnly))
@ -675,7 +675,7 @@ void RifEclipseInputFileTools::readFaults(const QString& fileName, cvf::Collecti
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifEclipseInputFileTools::readFaultsInGridSection(const QString& fileName, cvf::Collection<RigFault>& faults, std::vector<QString>& filenamesWithFaults)
void RifEclipseInputFileTools::readFaultsInGridSection(const QString& fileName, cvf::Collection<RigFault>* faults, std::vector<QString>* filenamesWithFaults)
{
QFile data(fileName);
if (!data.open(QFile::ReadOnly))
@ -748,7 +748,7 @@ qint64 RifEclipseInputFileTools::findKeyword(const QString& keyword, QFile& file
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifEclipseInputFileTools::readFaultsAndParseIncludeStatementsRecursively(QFile& file, qint64 startPos, cvf::Collection<RigFault>& faults, std::vector<QString>& filenamesWithFaults, bool* isEditKeywordDetected)
bool RifEclipseInputFileTools::readFaultsAndParseIncludeStatementsRecursively(QFile& file, qint64 startPos, cvf::Collection<RigFault>* faults, std::vector<QString>* filenamesWithFaults, bool* isEditKeywordDetected)
{
QString line;
@ -824,7 +824,7 @@ bool RifEclipseInputFileTools::readFaultsAndParseIncludeStatementsRecursively(QF
if (!line.contains("/"))
{
readFaults(file, file.pos(), faults, isEditKeywordDetected);
filenamesWithFaults.push_back(file.fileName());
filenamesWithFaults->push_back(file.fileName());
}
}
@ -866,7 +866,7 @@ cvf::StructGridInterface::FaceEnum RifEclipseInputFileTools::faceEnumFromText(co
/// Parse content of this keyword until end of file or
/// end of keyword when a single line with '/' is found
//--------------------------------------------------------------------------------------------------
void RifEclipseInputFileTools::readFaults(QFile &data, qint64 filePos, cvf::Collection<RigFault> &faults, bool* isEditKeywordDetected)
void RifEclipseInputFileTools::readFaults(QFile &data, qint64 filePos, cvf::Collection<RigFault>* faults, bool* isEditKeywordDetected)
{
if (!data.seek(filePos))
{
@ -936,22 +936,22 @@ void RifEclipseInputFileTools::readFaults(QFile &data, qint64 filePos, cvf::Coll
if (!(fault && fault->name() == name))
{
if (findFaultByName(faults, name) == cvf::UNDEFINED_SIZE_T)
if (findFaultByName(*faults, name) == cvf::UNDEFINED_SIZE_T)
{
RigFault* newFault = new RigFault;
newFault->setName(name);
faults.push_back(newFault);
faults->push_back(newFault);
}
size_t faultIndex = findFaultByName(faults, name);
size_t faultIndex = findFaultByName(*faults, name);
if (faultIndex == cvf::UNDEFINED_SIZE_T)
{
CVF_ASSERT(faultIndex != cvf::UNDEFINED_SIZE_T);
continue;
}
fault = faults.at(faultIndex);
fault = faults->at(faultIndex);
}
CVF_ASSERT(fault);

View File

@ -63,18 +63,18 @@ public:
static bool readPropertyAtFilePosition (const QString& fileName, RigCaseData* eclipseCase, const QString& eclipseKeyWord, qint64 filePos, const QString& resultName );
static void readFaultsInGridSection(const QString& fileName, cvf::Collection<RigFault>& faults, std::vector<QString>& filenamesWithFaults);
static void readFaults(const QString& fileName, cvf::Collection<RigFault>& faults, const std::vector< RifKeywordAndFilePos >& fileKeywords);
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 readFaults(QFile &data, qint64 filePos, cvf::Collection<RigFault> &faults, bool* isEditKeywordDetected);
static void findKeywordsOnFile(const QString &fileName, std::vector< RifKeywordAndFilePos >& keywords);
static void readFaults(QFile &data, qint64 filePos, cvf::Collection<RigFault>* faults, bool* isEditKeywordDetected);
static void findKeywordsOnFile(const QString &fileName, std::vector< RifKeywordAndFilePos >* keywords);
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);
static bool readFaultsAndParseIncludeStatementsRecursively(QFile& file, qint64 startPos, cvf::Collection<RigFault>& faults, std::vector<QString>& filenamesWithFaults, bool* isEditKeywordDetected);
static bool readFaultsAndParseIncludeStatementsRecursively(QFile& file, qint64 startPos, cvf::Collection<RigFault>* faults, std::vector<QString>* filenamesWithFaults, bool* isEditKeywordDetected);
static cvf::StructGridInterface::FaceEnum faceEnumFromText(const QString& faceString);

View File

@ -37,6 +37,7 @@
#include <iostream>
#include <map>
#include <cmath> // Needed for HUGE_VAL on Linux
#include "RifEclipseInputFileTools.h"
//--------------------------------------------------------------------------------------------------
@ -384,18 +385,12 @@ bool RifReaderEclipseOutput::open(const QString& fileName, RigCaseData* eclipseC
if (isFaultImportEnabled())
{
foreach (QString fname, fileSet)
{
if (fname.endsWith(".DATA"))
{
cvf::Collection<RigFault> faults;
cvf::Collection<RigFault> faults;
RifReaderOpmParserInput::readFaults(fname, faults);
importFaultsOpmParser(fileSet, &faults);
RigMainGrid* mainGrid = eclipseCase->mainGrid();
mainGrid->setFaults(faults);
}
}
RigMainGrid* mainGrid = eclipseCase->mainGrid();
mainGrid->setFaults(faults);
}
progInfo.incrementProgress();
@ -438,6 +433,56 @@ bool RifReaderEclipseOutput::open(const QString& fileName, RigCaseData* eclipseC
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifReaderEclipseOutput::importFaultsOpmParser(const QStringList& fileSet, cvf::Collection<RigFault>* faults) const
{
foreach(QString fname, fileSet)
{
if (fname.endsWith(".DATA"))
{
RifReaderOpmParserInput::readFaults(fname, faults);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifReaderEclipseOutput::importFaults(const QStringList& fileSet, cvf::Collection<RigFault>* faults)
{
if (this->filenamesWithFaults().size() > 0)
{
std::vector< RifKeywordAndFilePos > fileKeywords;
for (size_t i = 0; i < this->filenamesWithFaults().size(); i++)
{
QString faultFilename = this->filenamesWithFaults()[i];
RifEclipseInputFileTools::readFaults(faultFilename, fileKeywords, faults);
}
}
else
{
foreach(QString fname, fileSet)
{
if (fname.endsWith(".DATA"))
{
cvf::Collection<RigFault> faults;
std::vector<QString> filenamesWithFaults;
RifEclipseInputFileTools::readFaultsInGridSection(fname, &faults, &filenamesWithFaults);
std::sort(filenamesWithFaults.begin(), filenamesWithFaults.end());
std::vector<QString>::iterator last = std::unique(filenamesWithFaults.begin(), filenamesWithFaults.end());
filenamesWithFaults.erase(last, filenamesWithFaults.end());
this->setFilenamesWithFaults(filenamesWithFaults);
}
}
}
}
void RifReaderEclipseOutput::transferNNCData( const ecl_grid_type * mainEclGrid , const ecl_file_type * init_file, RigMainGrid * mainGrid)
{
if (!m_ecl_init_file ) return;

View File

@ -48,6 +48,7 @@ public:
virtual ~RifReaderEclipseOutput();
bool open(const QString& fileName, RigCaseData* eclipseCase);
virtual bool openAndReadActiveCellData(const QString& fileName, const std::vector<QDateTime>& mainCaseTimeSteps, RigCaseData* eclipseCase);
void close();
@ -66,6 +67,8 @@ private:
static RigWellResultPoint createWellResultPoint(const RigGridBase* grid, const well_conn_type* ert_connection, int ertBranchId, int ertSegmentId, const char* wellName);
void importFaultsOpmParser(const QStringList& fileSet, cvf::Collection<RigFault>* faults) const;
void importFaults(const QStringList& fileSet, cvf::Collection<RigFault>* faults);
void openInitFile();

View File

@ -138,7 +138,7 @@ void RifReaderOpmParserInput::importGridPropertiesFaults(const QString& fileName
if (caseData->mainGrid())
{
cvf::Collection<RigFault> faults;
importFaults(*deck, faults);
importFaults(*deck, &faults);
if (faults.size() > 0)
{
caseData->mainGrid()->setFaults(faults);
@ -198,7 +198,7 @@ void RifReaderOpmParserInput::importGridPropertiesFaults(const QString& fileName
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifReaderOpmParserInput::readFaults(const QString& fileName, cvf::Collection<RigFault>& faults)
void RifReaderOpmParserInput::readFaults(const QString& fileName, cvf::Collection<RigFault>* faults)
{
{
std::string errorMessage;
@ -231,7 +231,7 @@ void RifReaderOpmParserInput::readFaults(const QString& fileName, cvf::Collectio
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifReaderOpmParserInput::importFaults(const Opm::Deck& deck, cvf::Collection<RigFault>& faults)
void RifReaderOpmParserInput::importFaults(const Opm::Deck& deck, cvf::Collection<RigFault>* faults)
{
{
std::string errorMessage;
@ -267,22 +267,22 @@ void RifReaderOpmParserInput::importFaults(const Opm::Deck& deck, cvf::Collectio
if (!(fault && fault->name() == name))
{
if (findFaultByName(faults, name) == cvf::UNDEFINED_SIZE_T)
if (findFaultByName(*faults, name) == cvf::UNDEFINED_SIZE_T)
{
RigFault* newFault = new RigFault;
newFault->setName(name);
faults.push_back(newFault);
faults->push_back(newFault);
}
size_t faultIndex = findFaultByName(faults, name);
size_t faultIndex = findFaultByName(*faults, name);
if (faultIndex == cvf::UNDEFINED_SIZE_T)
{
CVF_ASSERT(faultIndex != cvf::UNDEFINED_SIZE_T);
continue;
}
fault = faults.at(faultIndex);
fault = faults->at(faultIndex);
}
CVF_ASSERT(fault);

View File

@ -48,12 +48,12 @@ class RifReaderOpmParserInput
public:
static void importGridPropertiesFaults(const QString& fileName, RigCaseData* eclipseCase);
static void readFaults(const QString& fileName, cvf::Collection<RigFault>& faults);
static void readFaults(const QString& fileName, cvf::Collection<RigFault>* faults);
static std::vector<std::string> knownPropertyKeywords();
private:
static void importFaults(const Opm::Deck& deck, cvf::Collection<RigFault>& faults);
static void importFaults(const Opm::Deck& deck, cvf::Collection<RigFault>* faults);
static std::vector<std::string> allParserConfigKeys();
static size_t findFaultByName(const cvf::Collection<RigFault>& faults, const QString& name);
static cvf::StructGridInterface::FaceEnum faceEnumFromText(const QString& faceString);

View File

@ -265,7 +265,7 @@ void RimEclipseInputCase::loadAndSyncronizeInputProperties()
if (isExistingFile)
{
std::vector< RifKeywordAndFilePos > fileKeywords;
RifEclipseInputFileTools::findKeywordsOnFile(filenames[i], fileKeywords);
RifEclipseInputFileTools::findKeywordsOnFile(filenames[i], &fileKeywords);
for_all(fileKeywords, fkIt) fileKeywordSet.insert(fileKeywords[fkIt].keyword);
}