Skip to content

Commit

Permalink
Merge pull request #194 from OPM/dev
Browse files Browse the repository at this point in the history
Copy up dev to master for release 1.2.0
  • Loading branch information
JacobStoren committed Jul 2, 2014
2 parents 4b975b8 + e1e6d60 commit 02b2c26
Show file tree
Hide file tree
Showing 150 changed files with 5,044 additions and 839 deletions.
24 changes: 19 additions & 5 deletions ApplicationCode/Application/RiaApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,15 +699,15 @@ bool RiaApplication::openInputEclipseCaseFromFileNames(const QStringList& fileNa
//--------------------------------------------------------------------------------------------------
void RiaApplication::createMockModel()
{
openEclipseCase("Result Mock Debug Model Simple", "Result Mock Debug Model Simple");
openEclipseCase(RimDefines::mockModelBasic(), RimDefines::mockModelBasic());
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication::createResultsMockModel()
{
openEclipseCase("Result Mock Debug Model With Results", "Result Mock Debug Model With Results");
openEclipseCase(RimDefines::mockModelBasicWithResults(), RimDefines::mockModelBasicWithResults());
}


Expand All @@ -716,15 +716,24 @@ void RiaApplication::createResultsMockModel()
//--------------------------------------------------------------------------------------------------
void RiaApplication::createLargeResultsMockModel()
{
openEclipseCase("Result Mock Debug Model Large With Results", "Result Mock Debug Model Large With Results");
openEclipseCase(RimDefines::mockModelLargeWithResults(), RimDefines::mockModelLargeWithResults());
}


//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication::createMockModelCustomized()
{
openEclipseCase(RimDefines::mockModelCustomized(), RimDefines::mockModelCustomized());
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication::createInputMockModel()
{
openInputEclipseCaseFromFileNames(QStringList("Input Mock Debug Model Simple"));
openInputEclipseCaseFromFileNames(QStringList(RimDefines::mockModelBasicInputCase()));
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -834,7 +843,12 @@ bool RiaApplication::parseArguments()

bool parseOk = progOpt.parse(cvfqt::Utils::toStringVector(arguments));

if (!parseOk || progOpt.hasOption("help") || progOpt.hasOption("?"))
// If positional parameter functionality is to be supported, the test for existence of positionalParameters must be removed
// This is based on a pull request by @andlaus https://github.com/OPM/ResInsight/pull/162
if (!parseOk ||
progOpt.hasOption("help") ||
progOpt.hasOption("?") ||
progOpt.positionalParameters().size() > 0)
{
#if defined(_MSC_VER) && defined(_WIN32)
showFormattedTextInMessageBox(m_helpText);
Expand Down
1 change: 1 addition & 0 deletions ApplicationCode/Application/RiaApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class RiaApplication : public QApplication
void createMockModel();
void createResultsMockModel();
void createLargeResultsMockModel();
void createMockModelCustomized();
void createInputMockModel();

QString defaultFileDialogDirectory(const QString& dialogName);
Expand Down
5 changes: 3 additions & 2 deletions ApplicationCode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ set( APPLICATION_FILES
set( USER_INTERFACE_FILES
UserInterface/RiuCursors.cpp
UserInterface/RiuMainWindow.cpp
UserInterface/RiuPreferencesDialog.cpp
UserInterface/RiuResultInfoPanel.cpp
UserInterface/RiuViewer.cpp
UserInterface/RiuSimpleHistogramWidget.cpp
Expand All @@ -59,6 +58,7 @@ set( SOCKET_INTERFACE_FILES
SocketInterface/RiaPropertyDataCommands.cpp
SocketInterface/RiaWellDataCommands.cpp
SocketInterface/RiaSocketTools.cpp
SocketInterface/RiaSocketDataTransfer.cpp
)


Expand Down Expand Up @@ -98,7 +98,6 @@ set ( QT_MOC_HEADERS
ProjectDataModel/RimMimeData.h

UserInterface/RiuMainWindow.h
UserInterface/RiuPreferencesDialog.h
UserInterface/RiuResultInfoPanel.h
UserInterface/RiuViewer.h
UserInterface/RiuProcessMonitor.h
Expand Down Expand Up @@ -155,6 +154,8 @@ list( REMOVE_ITEM RAW_SOURCES
Application/RiaImageCompareReporter.cpp
Application/RiaRegressionTest.cpp

SocketInterface/RiaSocketDataTransfer.cpp

FileInterface/RifEclipseInputFileTools.cpp
FileInterface/RifEclipseOutputFileTools.cpp
FileInterface/RifEclipseRestartFilesetAccess.cpp
Expand Down
167 changes: 114 additions & 53 deletions ApplicationCode/FileInterface/RifEclipseInputFileTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@
/////////////////////////////////////////////////////////////////////////////////

#include "RifEclipseInputFileTools.h"

#include "RifReaderEclipseOutput.h"
#include "RigCaseCellResultsData.h"

#include "RigCaseData.h"

#include "cafProgressInfo.h"

#include <vector>
#include <cmath>
#include <fstream>
#include <iostream>
#include <vector>

#include <QFile>
#include <QFileInfo>
Expand All @@ -34,10 +36,8 @@
#include <QDebug>

#include "ecl_grid.h"
#include "well_state.h"
#include "util.h"
#include <fstream>

#include "well_state.h"


QString includeKeyword("INCLUDE");
Expand All @@ -46,6 +46,73 @@ QString editKeyword("EDIT");
QString gridKeyword("GRID");


//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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());
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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->globalCellCount() > 0 && activeCellInfo->globalCellCount() != activeCellInfo->globalActiveCellCount())
{
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->globalActiveCellCount(), HUGE_VAL);
std::vector<double>& valuesActiveCells = newPropertyData[0];

size_t acIdx = 0;
for (size_t gcIdx = 0; gcIdx < activeCellInfo->globalCellCount(); 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());
}
}


//--------------------------------------------------------------------------------------------------
/// Constructor
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -197,9 +264,9 @@ bool RifEclipseInputFileTools::openGridFile(const QString& fileName, RigCaseData
//--------------------------------------------------------------------------------------------------
/// Read known properties from the input file
//--------------------------------------------------------------------------------------------------
std::map<QString, QString> RifEclipseInputFileTools::readProperties(const QString &fileName, RigCaseData *reservoir)
std::map<QString, QString> RifEclipseInputFileTools::readProperties(const QString &fileName, RigCaseData* caseData)
{
CVF_ASSERT(reservoir);
CVF_ASSERT(caseData);

std::set<QString> knownKeywordSet;
{
Expand Down Expand Up @@ -231,19 +298,18 @@ std::map<QString, QString> RifEclipseInputFileTools::readProperties(const QStri
if (knownKeywordSet.count(fileKeywords[i].keyword))
{
fseek(gridFilePointer, fileKeywords[i].filePos, SEEK_SET);
ecl_kw_type* eclKeyWordData = ecl_kw_fscanf_alloc_current_grdecl__(gridFilePointer, false , ECL_FLOAT_TYPE);
if (eclKeyWordData)
ecl_kw_type* eclipseKeywordData = ecl_kw_fscanf_alloc_current_grdecl__(gridFilePointer, false , ECL_FLOAT_TYPE);
if (eclipseKeywordData)
{
QString newResultName = reservoir->results(RifReaderInterface::MATRIX_RESULTS)->makeResultNameUnique(fileKeywords[i].keyword);

size_t resultIndex = reservoir->results(RifReaderInterface::MATRIX_RESULTS)->addEmptyScalarResult(RimDefines::INPUT_PROPERTY, newResultName, false); // Should really merge with inputProperty object information because we need to use PropertyName, and not keyword
QString newResultName = caseData->results(RifReaderInterface::MATRIX_RESULTS)->makeResultNameUnique(fileKeywords[i].keyword);

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());
size_t resultIndex = findOrCreateResult(newResultName, caseData);
if (resultIndex != cvf::UNDEFINED_SIZE_T)
{
readDoubleValues(caseData, resultIndex, eclipseKeywordData);
}

ecl_kw_free(eclKeyWordData);
ecl_kw_free(eclipseKeywordData);
newResults[newResultName] = fileKeywords[i].keyword;
}
}
Expand Down Expand Up @@ -300,30 +366,24 @@ void RifEclipseInputFileTools::findKeywordsOnFile(const QString &fileName, std::
/// Reads the property data requested into the \a reservoir, overwriting any previous
/// propeties with the same name.
//--------------------------------------------------------------------------------------------------
bool RifEclipseInputFileTools::readProperty(const QString& fileName, RigCaseData* eclipseCase, const QString& eclipseKeyWord, const QString& resultName)
bool RifEclipseInputFileTools::readProperty(const QString& fileName, RigCaseData* caseData, const QString& eclipseKeyWord, const QString& resultName)
{
CVF_ASSERT(eclipseCase);
CVF_ASSERT(caseData);

FILE* filePointer = util_fopen(fileName.toLatin1().data(), "r");
if (!filePointer) return false;

ecl_kw_type* eclKeyWordData = ecl_kw_fscanf_alloc_grdecl_dynamic__( filePointer , eclipseKeyWord.toLatin1().data() , false , ECL_FLOAT_TYPE);
ecl_kw_type* eclipseKeywordData = ecl_kw_fscanf_alloc_grdecl_dynamic__( filePointer , eclipseKeyWord.toLatin1().data() , false , ECL_FLOAT_TYPE);
bool isOk = false;
if (eclKeyWordData)
if (eclipseKeywordData)
{
QString newResultName = resultName;
size_t resultIndex = eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->findScalarResultIndex(newResultName);
if (resultIndex == cvf::UNDEFINED_SIZE_T)
size_t resultIndex = findOrCreateResult(resultName, caseData);
if (resultIndex != cvf::UNDEFINED_SIZE_T)
{
resultIndex = eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->addEmptyScalarResult(RimDefines::INPUT_PROPERTY, newResultName, false);
isOk = readDoubleValues(caseData, resultIndex, eclipseKeywordData);
}

std::vector< std::vector<double> >& newPropertyData = eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->cellScalarResults(resultIndex);
newPropertyData.resize(1);
newPropertyData[0].resize(ecl_kw_get_size(eclKeyWordData), HUGE_VAL);
ecl_kw_get_data_as_double(eclKeyWordData, newPropertyData[0].data());
isOk = true;
ecl_kw_free(eclKeyWordData);
ecl_kw_free(eclipseKeywordData);
}

util_fclose(filePointer);
Expand Down Expand Up @@ -535,31 +595,25 @@ void RifEclipseInputFileTools::findGridKeywordPositions(const std::vector< RifKe
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifEclipseInputFileTools::readPropertyAtFilePosition(const QString& fileName, RigCaseData* eclipseCase, const QString& eclipseKeyWord, qint64 filePos, const QString& resultName)
bool RifEclipseInputFileTools::readPropertyAtFilePosition(const QString& fileName, RigCaseData* caseData, const QString& eclipseKeyWord, qint64 filePos, const QString& resultName)
{
CVF_ASSERT(eclipseCase);
CVF_ASSERT(caseData);

FILE* filePointer = util_fopen(fileName.toLatin1().data(), "r");
if (!filePointer) return false;

fseek(filePointer, filePos, SEEK_SET);
ecl_kw_type* eclKeyWordData = ecl_kw_fscanf_alloc_current_grdecl__(filePointer, false , ECL_FLOAT_TYPE);
ecl_kw_type* eclipseKeywordData = ecl_kw_fscanf_alloc_current_grdecl__(filePointer, false , ECL_FLOAT_TYPE);
bool isOk = false;
if (eclKeyWordData)
if (eclipseKeywordData)
{
QString newResultName = resultName;
size_t resultIndex = eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->findScalarResultIndex(newResultName);
if (resultIndex == cvf::UNDEFINED_SIZE_T)
size_t resultIndex = findOrCreateResult(resultName, caseData);
if (resultIndex != cvf::UNDEFINED_SIZE_T)
{
resultIndex = eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->addEmptyScalarResult(RimDefines::INPUT_PROPERTY, newResultName, false);
isOk = readDoubleValues(caseData, resultIndex, eclipseKeywordData);
}

std::vector< std::vector<double> >& newPropertyData = eclipseCase->results(RifReaderInterface::MATRIX_RESULTS)->cellScalarResults(resultIndex);
newPropertyData.resize(1);
newPropertyData[0].resize(ecl_kw_get_size(eclKeyWordData), HUGE_VAL);
ecl_kw_get_data_as_double(eclKeyWordData, newPropertyData[0].data());
isOk = true;
ecl_kw_free(eclKeyWordData);
ecl_kw_free(eclipseKeywordData);
}

util_fclose(filePointer);
Expand Down Expand Up @@ -671,13 +725,13 @@ qint64 RifEclipseInputFileTools::findKeyword(const QString& keyword, QFile& file
do
{
line = file.readLine();
line = line.trimmed();

if (line.startsWith("--", Qt::CaseInsensitive))
{
continue;
}

line = line.trimmed();

if (line.startsWith(keyword, Qt::CaseInsensitive))
{
return file.pos();
Expand Down Expand Up @@ -706,6 +760,8 @@ bool RifEclipseInputFileTools::readFaultsAndParseIncludeStatementsRecursively(QF
do
{
line = file.readLine();
line = line.trimmed();

if (line.startsWith("--", Qt::CaseInsensitive))
{
continue;
Expand All @@ -720,14 +776,19 @@ bool RifEclipseInputFileTools::readFaultsAndParseIncludeStatementsRecursively(QF
return false;
}


line = line.trimmed();
if (line.startsWith(includeKeyword, Qt::CaseInsensitive))
{
QString nextLine = file.readLine();
line = file.readLine();
line = line.trimmed();

while (line.startsWith("--", Qt::CaseInsensitive))
{
line = file.readLine();
line = line.trimmed();
}

int firstQuote = nextLine.indexOf("'");
int lastQuote = nextLine.lastIndexOf("'");
int firstQuote = line.indexOf("'");
int lastQuote = line.lastIndexOf("'");

if (!(firstQuote < 0 || lastQuote < 0 || firstQuote == lastQuote))
{
Expand All @@ -738,7 +799,7 @@ bool RifEclipseInputFileTools::readFaultsAndParseIncludeStatementsRecursively(QF
}

// Read include file name, and both relative and absolute path is supported
QString includeFilename = nextLine.mid(firstQuote + 1, lastQuote - firstQuote - 1);
QString includeFilename = line.mid(firstQuote + 1, lastQuote - firstQuote - 1);
QFileInfo fi(currentFileFolder, includeFilename);
if (fi.exists())
{
Expand Down
8 changes: 8 additions & 0 deletions ApplicationCode/FileInterface/RifReaderMockModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,11 @@ void RifReaderMockModel::populateReservoir(RigCaseData* eclipseCase)
m_reservoirBuilder.populateReservoir(eclipseCase);
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifReaderMockModel::enableWellData(bool enableWellData)
{
m_reservoirBuilder.enableWellData(enableWellData);
}

Loading

0 comments on commit 02b2c26

Please sign in to comment.