mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#789 Add properties from standalone files to opm-parser Input Cases
This commit is contained in:
parent
4cb91128e7
commit
f7117ae0e2
@ -48,6 +48,7 @@ ${CEE_CURRENT_LIST_DIR}RicLaunchUnitTestsFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicExportToLasFileFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicImportInputEclipseCaseOpmFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicSnapshotViewToClipboardFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicAddOpmInputPropertyFeature.h
|
||||
|
||||
# General delete of any object in a child array field
|
||||
${CEE_CURRENT_LIST_DIR}RicDeleteItemExec.h
|
||||
@ -98,6 +99,7 @@ ${CEE_CURRENT_LIST_DIR}RicLaunchUnitTestsFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicExportToLasFileFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicImportInputEclipseCaseOpmFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicSnapshotViewToClipboardFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicAddOpmInputPropertyFeature.cpp
|
||||
|
||||
|
||||
# General delete of any object in a child array field
|
||||
|
115
ApplicationCode/Commands/RicAddOpmInputPropertyFeature.cpp
Normal file
115
ApplicationCode/Commands/RicAddOpmInputPropertyFeature.cpp
Normal file
@ -0,0 +1,115 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2016- Statoil 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 "RicAddOpmInputPropertyFeature.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RimEclipseInputCaseOpm.h"
|
||||
#include "RimEclipseInputPropertyCollection.h"
|
||||
#include "RiuMainWindow.h"
|
||||
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QStringList>
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicAddOpmInputPropertyFeature, "RicAddOpmInputPropertyFeature");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicAddOpmInputPropertyFeature::isCommandEnabled()
|
||||
{
|
||||
RimEclipseInputPropertyCollection* inputProp = selectedInputPropertyCollection();
|
||||
if (inputProp)
|
||||
{
|
||||
RimEclipseInputCaseOpm* inputCaseOpm = NULL;
|
||||
|
||||
inputProp->firstAnchestorOrThisOfType(inputCaseOpm);
|
||||
if (inputCaseOpm)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicAddOpmInputPropertyFeature::onActionTriggered(bool isChecked)
|
||||
{
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
QString defaultDir = app->defaultFileDialogDirectory("INPUT_FILES");
|
||||
QStringList fileNames = QFileDialog::getOpenFileNames(NULL, "Select Eclipse Input Property Files", defaultDir, "All Files (*.* *)");
|
||||
|
||||
if (fileNames.isEmpty()) return;
|
||||
|
||||
// Remember the directory to next time
|
||||
defaultDir = QFileInfo(fileNames.last()).absolutePath();
|
||||
app->setDefaultFileDialogDirectory("INPUT_FILES", defaultDir);
|
||||
|
||||
RimEclipseInputPropertyCollection* inputPropertyCollection = selectedInputPropertyCollection();
|
||||
if (inputPropertyCollection)
|
||||
{
|
||||
addEclipseInputProperty(fileNames, inputPropertyCollection);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicAddOpmInputPropertyFeature::setupActionLook(QAction* actionToSetup)
|
||||
{
|
||||
actionToSetup->setText("Add Input Property");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimEclipseInputPropertyCollection* RicAddOpmInputPropertyFeature::selectedInputPropertyCollection() const
|
||||
{
|
||||
std::vector<RimEclipseInputPropertyCollection*> selection;
|
||||
caf::SelectionManager::instance()->objectsByType(&selection);
|
||||
|
||||
return selection.size() > 0 ? selection[0] : NULL;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicAddOpmInputPropertyFeature::addEclipseInputProperty(const QStringList& fileNames, RimEclipseInputPropertyCollection* inputPropertyCollection)
|
||||
{
|
||||
CVF_ASSERT(inputPropertyCollection);
|
||||
|
||||
RimEclipseInputCaseOpm* inputCaseOpm = NULL;
|
||||
|
||||
inputPropertyCollection->firstAnchestorOrThisOfType(inputCaseOpm);
|
||||
if (inputCaseOpm)
|
||||
{
|
||||
inputCaseOpm->appendPropertiesFromStandaloneFiles(fileNames);
|
||||
}
|
||||
|
||||
inputPropertyCollection->updateConnectedEditors();
|
||||
}
|
||||
|
||||
|
45
ApplicationCode/Commands/RicAddOpmInputPropertyFeature.h
Normal file
45
ApplicationCode/Commands/RicAddOpmInputPropertyFeature.h
Normal file
@ -0,0 +1,45 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2015- Statoil ASA
|
||||
// Copyright (C) 2015- Ceetron Solutions AS
|
||||
//
|
||||
// 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 "cafCmdFeature.h"
|
||||
|
||||
class RimEclipseInputPropertyCollection;
|
||||
class QStringList;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicAddOpmInputPropertyFeature : public caf::CmdFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
protected:
|
||||
// Overrides
|
||||
virtual bool isCommandEnabled();
|
||||
virtual void onActionTriggered( bool isChecked );
|
||||
virtual void setupActionLook( QAction* actionToSetup );
|
||||
|
||||
private:
|
||||
RimEclipseInputPropertyCollection* selectedInputPropertyCollection() const;
|
||||
static void addEclipseInputProperty(const QStringList& fileNames, RimEclipseInputPropertyCollection* inputPropertyCollection);
|
||||
};
|
||||
|
||||
|
@ -49,7 +49,7 @@ void RifReaderOpmParserInput::importGridPropertiesFaults(const QString& fileName
|
||||
std::shared_ptr<const Opm::EclipseGrid> eclipseGrid;
|
||||
std::string errorMessage;
|
||||
|
||||
std::shared_ptr<const Opm::Deck> deck;
|
||||
std::shared_ptr<Opm::Deck> deck;
|
||||
|
||||
try
|
||||
{
|
||||
@ -119,6 +119,25 @@ void RifReaderOpmParserInput::importGridPropertiesFaults(const QString& fileName
|
||||
}
|
||||
}
|
||||
|
||||
if (caseData->results(RifReaderInterface::MATRIX_RESULTS)->resultCount() == 0)
|
||||
{
|
||||
// Eclipse3DProperties was not able to extract results. This is often the case when reading a GRDECL file directly
|
||||
// Parse for known keywords by analyzing the present keywords in the deck
|
||||
|
||||
RifReaderOpmParserPropertyReader propertyReader(deck);
|
||||
|
||||
std::set<std::string> keywordsOnFile = propertyReader.keywords();
|
||||
std::vector<std::string> predefKeywords = RifReaderOpmParserInput::knownPropertyKeywords();
|
||||
for (auto keyword : predefKeywords)
|
||||
{
|
||||
if (std::find(keywordsOnFile.begin(), keywordsOnFile.end(), keyword) != keywordsOnFile.end())
|
||||
{
|
||||
QString newResultName = caseData->results(RifReaderInterface::MATRIX_RESULTS)->makeResultNameUnique(QString::fromStdString(keyword));
|
||||
propertyReader.copyPropertyToCaseData(keyword, caseData, newResultName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (caseData->mainGrid())
|
||||
{
|
||||
cvf::Collection<RigFault> faults;
|
||||
@ -408,84 +427,6 @@ void RifReaderOpmParserInput::initUsingWarnings(Opm::ParseContext* parseContext)
|
||||
parseContext->update(Opm::InputError::WARN);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
bool RifReaderOpmParserInput::openGridFile(const QString& fileName, bool importProperties, RigCaseData* caseData, RimEclipseInputCaseOpm* rimInputCase)
|
||||
{
|
||||
RiuMainWindow::instance()->processMonitor()->addStringToLog(QString("Started grid reading from file : " + fileName + "\n"));
|
||||
|
||||
{
|
||||
std::shared_ptr<const Opm::EclipseGrid> eclipseGrid;
|
||||
std::string errorMessage;
|
||||
|
||||
try
|
||||
{
|
||||
Opm::Parser parser;
|
||||
|
||||
// A default ParseContext will set up all parsing errors to throw exceptions
|
||||
Opm::ParseContext parseContext;
|
||||
parseContext.addKey("PARSE_MISSING_SECTIONS");
|
||||
|
||||
// Treat all parsing errors as warnings
|
||||
parseContext.update(Opm::InputError::WARN);
|
||||
|
||||
auto deck = parser.parseFile(fileName.toStdString(), parseContext);
|
||||
|
||||
eclipseGrid = parser.parseGrid(*deck, parseContext);
|
||||
if (eclipseGrid && eclipseGrid->c_ptr())
|
||||
{
|
||||
RifReaderEclipseOutput::transferGeometry(eclipseGrid->c_ptr(), caseData);
|
||||
|
||||
if (importProperties)
|
||||
{
|
||||
std::map<QString, QString> allPropertiesOnFile;
|
||||
RifReaderOpmParserPropertyReader::readAllProperties(deck, caseData, &allPropertiesOnFile);
|
||||
for (auto it = allPropertiesOnFile.begin(); it != allPropertiesOnFile.end(); ++it)
|
||||
{
|
||||
RimEclipseInputProperty* inputProperty = new RimEclipseInputProperty;
|
||||
inputProperty->resultName = it->first;
|
||||
inputProperty->eclipseKeyword = it->second;
|
||||
inputProperty->fileName = fileName;
|
||||
inputProperty->resolvedState = RimEclipseInputProperty::RESOLVED;
|
||||
rimInputCase->m_inputPropertyCollection->inputProperties.push_back(inputProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
errorMessage = e.what();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
errorMessage = "Unknown exception throwm from Opm::Parser";
|
||||
}
|
||||
|
||||
if (eclipseGrid)
|
||||
{
|
||||
const Opm::MessageContainer& messages = eclipseGrid->getMessageContainer();
|
||||
for (auto m : messages)
|
||||
{
|
||||
RiuMainWindow::instance()->processMonitor()->addStringToLog(" " + QString::fromStdString(m.message) + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (errorMessage.size() > 0)
|
||||
{
|
||||
RiuMainWindow::instance()->processMonitor()->addStringToLog(" " + QString::fromStdString(errorMessage) + "\n");
|
||||
RiuMainWindow::instance()->processMonitor()->addStringToLog(QString("Failed grid reading from file : " + fileName + "\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
RiuMainWindow::instance()->processMonitor()->addStringToLog(QString("Completed grid reading from file : " + fileName + "\n"));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@ -501,70 +442,6 @@ size_t RifReaderOpmParserPropertyReader::findOrCreateResult(const QString& newRe
|
||||
return resultIndex;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<QString, QString> RifReaderOpmParserInput::copyPropertiesToCaseData(const QString& fileName, RigCaseData* caseData)
|
||||
{
|
||||
RiuMainWindow::instance()->processMonitor()->addStringToLog(QString("Started reading of properties from file : " + fileName + "\n"));
|
||||
|
||||
std::map<QString, QString> newResults;
|
||||
|
||||
{
|
||||
std::shared_ptr<const Opm::EclipseGrid> eclipseGrid;
|
||||
std::string errorMessage;
|
||||
|
||||
try
|
||||
{
|
||||
Opm::Parser parser;
|
||||
|
||||
// A default ParseContext will set up all parsing errors to throw exceptions
|
||||
Opm::ParseContext parseContext;
|
||||
|
||||
// Treat all parsing errors as warnings
|
||||
parseContext.update(Opm::InputError::WARN);
|
||||
|
||||
auto deck = parser.parseFile(fileName.toStdString(), parseContext);
|
||||
|
||||
RifReaderOpmParserPropertyReader::readAllProperties(deck, caseData, &newResults);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
errorMessage = e.what();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
errorMessage = "Unknown exception throwm from Opm::Parser";
|
||||
}
|
||||
|
||||
if (eclipseGrid)
|
||||
{
|
||||
const Opm::MessageContainer& messages = eclipseGrid->getMessageContainer();
|
||||
for (auto m : messages)
|
||||
{
|
||||
RiuMainWindow::instance()->processMonitor()->addStringToLog(" " + QString::fromStdString(m.message) + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (errorMessage.size() > 0)
|
||||
{
|
||||
RiuMainWindow::instance()->processMonitor()->addStringToLog(" " + QString::fromStdString(errorMessage) + "\n");
|
||||
RiuMainWindow::instance()->processMonitor()->addStringToLog(QString("Failed reading of properties from file : " + fileName + "\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
RiuMainWindow::instance()->processMonitor()->addStringToLog(QString("Completed reading of properties from file : " + fileName + "\n"));
|
||||
}
|
||||
}
|
||||
|
||||
return newResults;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -603,7 +480,8 @@ void RifReaderOpmParserPropertyReader::readAllProperties(std::shared_ptr< Opm::D
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifReaderOpmParserPropertyReader::RifReaderOpmParserPropertyReader()
|
||||
RifReaderOpmParserPropertyReader::RifReaderOpmParserPropertyReader(std::shared_ptr< Opm::Deck > deck)
|
||||
: m_deck(deck)
|
||||
{
|
||||
|
||||
}
|
||||
@ -611,9 +489,9 @@ RifReaderOpmParserPropertyReader::RifReaderOpmParserPropertyReader()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RifReaderOpmParserPropertyReader::~RifReaderOpmParserPropertyReader()
|
||||
RifReaderOpmParserPropertyReader::RifReaderOpmParserPropertyReader(const QString& fileName)
|
||||
{
|
||||
|
||||
open(fileName);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -652,15 +530,15 @@ bool RifReaderOpmParserPropertyReader::open(const QString& fileName)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::set<QString> RifReaderOpmParserPropertyReader::keywords() const
|
||||
std::set<std::string> RifReaderOpmParserPropertyReader::keywords() const
|
||||
{
|
||||
std::set<QString> ids;
|
||||
std::set<std::string> ids;
|
||||
|
||||
if (m_deck)
|
||||
{
|
||||
for (auto it = m_deck->begin(); it != m_deck->end(); it++)
|
||||
{
|
||||
ids.insert(QString::fromStdString(it->name()));
|
||||
ids.insert(it->name());
|
||||
}
|
||||
}
|
||||
|
||||
@ -670,23 +548,21 @@ std::set<QString> RifReaderOpmParserPropertyReader::keywords() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifReaderOpmParserPropertyReader::copyPropertyToCaseData(const QString& keywordName, RigCaseData* caseData, const QString& resultName)
|
||||
bool RifReaderOpmParserPropertyReader::copyPropertyToCaseData(const std::string& keywordName, RigCaseData* caseData, const QString& resultName)
|
||||
{
|
||||
{
|
||||
std::string errorMessage;
|
||||
|
||||
try
|
||||
{
|
||||
std::string stdKeywordName = keywordName.toStdString();
|
||||
|
||||
if (m_deck->hasKeyword(stdKeywordName))
|
||||
if (m_deck->hasKeyword(keywordName))
|
||||
{
|
||||
bool isItemCountEqual = isDataItemCountIdenticalToMainGridCellCount(m_deck, stdKeywordName, caseData);
|
||||
bool isItemCountEqual = isDataItemCountIdenticalToMainGridCellCount(m_deck, keywordName, caseData);
|
||||
if (isItemCountEqual)
|
||||
{
|
||||
std::vector<double> allValues;
|
||||
|
||||
getAllValuesForKeyword(m_deck, stdKeywordName, allValues);
|
||||
getAllValuesForKeyword(m_deck, keywordName, allValues);
|
||||
|
||||
size_t resultIndex = RifReaderOpmParserPropertyReader::findOrCreateResult(resultName, caseData);
|
||||
if (resultIndex != cvf::UNDEFINED_SIZE_T)
|
||||
@ -711,11 +587,11 @@ bool RifReaderOpmParserPropertyReader::copyPropertyToCaseData(const QString& key
|
||||
if (errorMessage.size() > 0)
|
||||
{
|
||||
RiuMainWindow::instance()->processMonitor()->addStringToLog(" " + QString::fromStdString(errorMessage) + "\n");
|
||||
RiuMainWindow::instance()->processMonitor()->addStringToLog(QString("Error detected while reading property %1 from file : %2\n").arg(keywordName).arg(fileName));
|
||||
RiuMainWindow::instance()->processMonitor()->addStringToLog(QString("Error detected while reading property %1 from file : %2\n").arg(QString::fromStdString(keywordName)).arg(fileName));
|
||||
}
|
||||
else
|
||||
{
|
||||
RiuMainWindow::instance()->processMonitor()->addStringToLog(QString("Completed reading of property %1 from file : %2\n").arg(keywordName).arg(fileName));
|
||||
RiuMainWindow::instance()->processMonitor()->addStringToLog(QString("Completed reading of property %1 from file : %2\n").arg(QString::fromStdString(keywordName)).arg(fileName));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,9 +24,9 @@
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
#include <QString>
|
||||
|
||||
@ -49,15 +49,11 @@ public:
|
||||
static void importGridPropertiesFaults(const QString& fileName, RigCaseData* eclipseCase);
|
||||
|
||||
static void readFaults(const QString& fileName, cvf::Collection<RigFault>& faults);
|
||||
|
||||
/*
|
||||
static bool openGridFile(const QString& fileName, bool importProperties, RigCaseData* eclipseCase, RimEclipseInputCaseOpm* RimInputCase);
|
||||
static std::map<QString, QString> copyPropertiesToCaseData(const QString& fileName, RigCaseData* eclipseCase);
|
||||
*/
|
||||
|
||||
static std::vector<std::string> knownPropertyKeywords();
|
||||
|
||||
private:
|
||||
static void importFaults(const Opm::Deck& deck, cvf::Collection<RigFault>& faults);
|
||||
static std::vector<std::string> knownPropertyKeywords();
|
||||
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);
|
||||
@ -66,23 +62,29 @@ private:
|
||||
|
||||
|
||||
|
||||
// This class is intended to be used for reading additional properties from standalone files
|
||||
// Not yet in use
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RifReaderOpmParserPropertyReader
|
||||
{
|
||||
public:
|
||||
RifReaderOpmParserPropertyReader();
|
||||
virtual ~RifReaderOpmParserPropertyReader();
|
||||
RifReaderOpmParserPropertyReader(std::shared_ptr< Opm::Deck > deck);
|
||||
RifReaderOpmParserPropertyReader(const QString& fileName);
|
||||
|
||||
bool open(const QString& fileName);
|
||||
std::set<QString> keywords() const;
|
||||
std::set<std::string> keywords() const;
|
||||
|
||||
bool copyPropertyToCaseData(const QString& keywordName, RigCaseData* eclipseCase, const QString& resultName);
|
||||
bool copyPropertyToCaseData(const std::string& keywordName, RigCaseData* eclipseCase, const QString& resultName);
|
||||
|
||||
static size_t findOrCreateResult(const QString& newResultName, RigCaseData* reservoir);
|
||||
static size_t findOrCreateResult(const QString& newResultName, RigCaseData* reservoir);
|
||||
|
||||
private:
|
||||
static void readAllProperties(std::shared_ptr< Opm::Deck > deck, RigCaseData* caseData, std::map<QString, QString>* newResults);
|
||||
static void getAllValuesForKeyword(std::shared_ptr< Opm::Deck > deck, const std::string& keyword, std::vector<double>& allValues);
|
||||
static bool isDataItemCountIdenticalToMainGridCellCount(std::shared_ptr< Opm::Deck > deck, const std::string& keyword, RigCaseData* caseData);
|
||||
bool open(const QString& fileName);
|
||||
|
||||
private:
|
||||
std::shared_ptr< Opm::Deck > m_deck;
|
||||
};
|
||||
|
@ -164,6 +164,7 @@ QStringList RimContextCommandBuilder::commandsFromSelection()
|
||||
else if (dynamic_cast<RimEclipseInputPropertyCollection*>(uiItem))
|
||||
{
|
||||
commandIds << "RicAddEclipseInputPropertyFeature";
|
||||
commandIds << "RicAddOpmInputPropertyFeature";
|
||||
}
|
||||
else if (dynamic_cast<RimEclipseInputProperty*>(uiItem))
|
||||
{
|
||||
|
@ -49,6 +49,12 @@ RimEclipseInputCaseOpm::RimEclipseInputCaseOpm()
|
||||
|
||||
CAF_PDM_InitField(&m_gridFileName, "GridFileName", QString(), "Case grid filename", "", "" ,"");
|
||||
m_gridFileName.uiCapability()->setUiReadOnly(true);
|
||||
CAF_PDM_InitFieldNoDefault(&m_additionalFileNames, "AdditionalFileNames", "Additional files", "", "", "");
|
||||
m_additionalFileNames.uiCapability()->setUiReadOnly(true);
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_inputPropertyCollection, "InputPropertyCollection", "", "", "", "");
|
||||
m_inputPropertyCollection = new RimEclipseInputPropertyCollection;
|
||||
m_inputPropertyCollection->parentField()->uiCapability()->setUiHidden(true);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -56,6 +62,7 @@ RimEclipseInputCaseOpm::RimEclipseInputCaseOpm()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimEclipseInputCaseOpm::~RimEclipseInputCaseOpm()
|
||||
{
|
||||
delete m_inputPropertyCollection;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -72,6 +79,42 @@ void RimEclipseInputCaseOpm::importNewEclipseGridAndProperties(const QString& fi
|
||||
importEclipseGridAndProperties(m_gridFileName);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimEclipseInputCaseOpm::appendPropertiesFromStandaloneFiles(const QStringList& fileNames)
|
||||
{
|
||||
for (auto filename : fileNames)
|
||||
{
|
||||
QFileInfo fi(filename);
|
||||
if (!fi.exists()) continue;
|
||||
|
||||
RifReaderOpmParserPropertyReader propertyReader(filename);
|
||||
std::set<std::string> fileKeywordSet = propertyReader.keywords();
|
||||
|
||||
std::vector<std::string> knownKeywords = RifReaderOpmParserInput::knownPropertyKeywords();
|
||||
for (auto knownKeyword : knownKeywords)
|
||||
{
|
||||
if (fileKeywordSet.count(knownKeyword) > 0)
|
||||
{
|
||||
QString qtKnownKeyword = QString::fromStdString(knownKeyword);
|
||||
QString resultName = this->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->makeResultNameUnique(qtKnownKeyword);
|
||||
if (propertyReader.copyPropertyToCaseData(knownKeyword, this->reservoirData(), resultName))
|
||||
{
|
||||
RimEclipseInputProperty* inputProperty = new RimEclipseInputProperty;
|
||||
inputProperty->resultName = resultName;
|
||||
inputProperty->eclipseKeyword = qtKnownKeyword;
|
||||
inputProperty->fileName = filename;
|
||||
inputProperty->resolvedState = RimEclipseInputProperty::RESOLVED;
|
||||
m_inputPropertyCollection->inputProperties.push_back(inputProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_additionalFileNames.v().push_back(filename);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -79,6 +122,8 @@ bool RimEclipseInputCaseOpm::openEclipseGridFile()
|
||||
{
|
||||
importEclipseGridAndProperties(m_gridFileName);
|
||||
|
||||
loadAndSyncronizeInputProperties();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -102,6 +147,11 @@ void RimEclipseInputCaseOpm::updateFilePathsFromProjectPath(const QString& newPr
|
||||
std::vector<QString> searchedPaths;
|
||||
|
||||
m_gridFileName = RimTools::relocateFile(m_gridFileName(), newProjectPath, oldProjectPath, &foundFile, &searchedPaths);
|
||||
|
||||
for (size_t i = 0; i < m_additionalFileNames().size(); i++)
|
||||
{
|
||||
m_additionalFileNames.v()[i] = RimTools::relocateFile(m_additionalFileNames()[i], newProjectPath, oldProjectPath, &foundFile, &searchedPaths);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -136,3 +186,83 @@ void RimEclipseInputCaseOpm::importEclipseGridAndProperties(const QString& fileN
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimEclipseInputCaseOpm::loadAndSyncronizeInputProperties()
|
||||
{
|
||||
// Make sure we actually have reservoir data
|
||||
|
||||
CVF_ASSERT(this->reservoirData());
|
||||
CVF_ASSERT(this->reservoirData()->mainGrid()->gridPointDimensions() != cvf::Vec3st(0, 0, 0));
|
||||
|
||||
// Then read the properties from all the files referenced by the InputReservoir
|
||||
|
||||
for (QString filename : m_additionalFileNames())
|
||||
{
|
||||
QFileInfo fileNameInfo(filename);
|
||||
bool isExistingFile = fileNameInfo.exists();
|
||||
|
||||
// Find the input property objects referring to the file
|
||||
|
||||
std::vector<RimEclipseInputProperty*> ipsUsingThisFile = this->m_inputPropertyCollection()->findInputProperties(filename);
|
||||
|
||||
if (!isExistingFile)
|
||||
{
|
||||
for (auto inputProperty : ipsUsingThisFile)
|
||||
{
|
||||
inputProperty->resolvedState = RimEclipseInputProperty::FILE_MISSING;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RifReaderOpmParserPropertyReader propertyReader(filename);
|
||||
std::set<std::string> fileKeywordSet = propertyReader.keywords();
|
||||
|
||||
for (auto inputProperty : ipsUsingThisFile)
|
||||
{
|
||||
QString kw = inputProperty->eclipseKeyword();
|
||||
inputProperty->resolvedState = RimEclipseInputProperty::KEYWORD_NOT_IN_FILE;
|
||||
if (fileKeywordSet.count(kw.toStdString()))
|
||||
{
|
||||
if (propertyReader.copyPropertyToCaseData(kw.toStdString(), this->reservoirData(), inputProperty->resultName))
|
||||
{
|
||||
inputProperty->resolvedState = RimEclipseInputProperty::RESOLVED;
|
||||
}
|
||||
}
|
||||
fileKeywordSet.erase(kw.toStdString());
|
||||
}
|
||||
|
||||
if (!fileKeywordSet.empty())
|
||||
{
|
||||
std::vector<std::string> knownKeywords = RifReaderOpmParserInput::knownPropertyKeywords();
|
||||
for (auto knownKeyword : knownKeywords)
|
||||
{
|
||||
if (fileKeywordSet.count(knownKeyword) > 0)
|
||||
{
|
||||
QString qtKnownKeyword = QString::fromStdString(knownKeyword);
|
||||
QString resultName = this->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->makeResultNameUnique(qtKnownKeyword);
|
||||
if (propertyReader.copyPropertyToCaseData(knownKeyword, this->reservoirData(), resultName))
|
||||
{
|
||||
RimEclipseInputProperty* inputProperty = new RimEclipseInputProperty;
|
||||
inputProperty->resultName = resultName;
|
||||
inputProperty->eclipseKeyword = qtKnownKeyword;
|
||||
inputProperty->fileName = filename;
|
||||
inputProperty->resolvedState = RimEclipseInputProperty::RESOLVED;
|
||||
m_inputPropertyCollection->inputProperties.push_back(inputProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(auto inputProperty : m_inputPropertyCollection->inputProperties())
|
||||
{
|
||||
if (inputProperty->resolvedState() == RimEclipseInputProperty::UNKNOWN)
|
||||
{
|
||||
inputProperty->resolvedState = RimEclipseInputProperty::FILE_MISSING;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,8 @@ public:
|
||||
|
||||
void importNewEclipseGridAndProperties(const QString& fileName);
|
||||
|
||||
void appendPropertiesFromStandaloneFiles(const QStringList& fileNames);
|
||||
|
||||
// RimCase overrides
|
||||
virtual bool openEclipseGridFile(); // Find grid file among file set. Read, Find read and validate property date. Syncronize child property sets.
|
||||
|
||||
@ -56,7 +58,12 @@ public:
|
||||
|
||||
private:
|
||||
void importEclipseGridAndProperties(const QString& fileName);
|
||||
void loadAndSyncronizeInputProperties();
|
||||
|
||||
|
||||
private:
|
||||
caf::PdmChildField<RimEclipseInputPropertyCollection*> m_inputPropertyCollection;
|
||||
caf::PdmField<std::vector<QString> > m_additionalFileNames;
|
||||
|
||||
caf::PdmField<QString> m_gridFileName;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user