mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2781 Ensemble curve set. Support for Tempest workflow (lookup and parse runspecifiction.xml file)
This commit is contained in:
parent
3b94c06e11
commit
7347e0ecc3
@ -32,27 +32,88 @@
|
|||||||
/// Constants
|
/// Constants
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
#define PARAMETERS_FILE_NAME "parameters.txt"
|
#define PARAMETERS_FILE_NAME "parameters.txt"
|
||||||
|
#define RUNSPEC_FILE_NAME "runspecification.xml"
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
RifCaseRealizationParametersReader::RifCaseRealizationParametersReader(const QString& fileName)
|
RifCaseRealizationReader::RifCaseRealizationReader(const QString& fileName)
|
||||||
{
|
{
|
||||||
m_parameters = std::shared_ptr<RigCaseRealizationParameters>(new RigCaseRealizationParameters());
|
m_parameters = std::shared_ptr<RigCaseRealizationParameters>(new RigCaseRealizationParameters());
|
||||||
m_fileName = fileName;
|
m_fileName = fileName;
|
||||||
m_file = nullptr;
|
m_file = nullptr;
|
||||||
m_textStream = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
RifCaseRealizationParametersReader::RifCaseRealizationParametersReader()
|
RifCaseRealizationReader::~RifCaseRealizationReader()
|
||||||
|
{
|
||||||
|
closeFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
const std::shared_ptr<RigCaseRealizationParameters> RifCaseRealizationReader::parameters() const
|
||||||
|
{
|
||||||
|
return m_parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
std::shared_ptr<RifCaseRealizationReader> RifCaseRealizationReader::createReaderFromFileName(const QString& fileName)
|
||||||
|
{
|
||||||
|
std::shared_ptr<RifCaseRealizationReader> reader;
|
||||||
|
|
||||||
|
if (fileName.endsWith(PARAMETERS_FILE_NAME))
|
||||||
|
{
|
||||||
|
reader.reset(new RifCaseRealizationParametersReader(fileName));
|
||||||
|
}
|
||||||
|
else if (fileName.endsWith(RUNSPEC_FILE_NAME))
|
||||||
|
{
|
||||||
|
reader.reset(new RifCaseRealizationRunspecificationReader(fileName));
|
||||||
|
}
|
||||||
|
return reader;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
QFile* RifCaseRealizationReader::openFile()
|
||||||
|
{
|
||||||
|
if (!m_file)
|
||||||
|
{
|
||||||
|
m_file = new QFile(m_fileName);
|
||||||
|
if (!m_file->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
|
{
|
||||||
|
closeFile();
|
||||||
|
throw FileParseException(QString("Failed to open %1").arg(m_fileName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m_file;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RifCaseRealizationReader::closeFile()
|
||||||
|
{
|
||||||
|
if (m_file)
|
||||||
|
{
|
||||||
|
m_file->close();
|
||||||
|
delete m_file;
|
||||||
|
m_file = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
RifCaseRealizationParametersReader::RifCaseRealizationParametersReader(const QString& fileName) :
|
||||||
|
RifCaseRealizationReader(fileName)
|
||||||
{
|
{
|
||||||
m_parameters = std::shared_ptr<RigCaseRealizationParameters>(new RigCaseRealizationParameters());
|
|
||||||
m_fileName = "";
|
|
||||||
m_file = nullptr;
|
|
||||||
m_textStream = nullptr;
|
m_textStream = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,15 +126,6 @@ RifCaseRealizationParametersReader::~RifCaseRealizationParametersReader()
|
|||||||
{
|
{
|
||||||
delete m_textStream;
|
delete m_textStream;
|
||||||
}
|
}
|
||||||
closeFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void RifCaseRealizationParametersReader::setFileName(const QString& fileName)
|
|
||||||
{
|
|
||||||
m_fileName = fileName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -137,9 +189,9 @@ void RifCaseRealizationParametersReader::parse()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
QTextStream* RifCaseRealizationParametersReader::openDataStream()
|
QTextStream* RifCaseRealizationParametersReader::openDataStream()
|
||||||
{
|
{
|
||||||
openFile();
|
auto file = openFile();
|
||||||
|
|
||||||
m_textStream = new QTextStream(m_file);
|
m_textStream = new QTextStream(file);
|
||||||
return m_textStream;
|
return m_textStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,15 +211,81 @@ void RifCaseRealizationParametersReader::closeDataStream()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RifCaseRealizationParametersReader::openFile()
|
RifCaseRealizationRunspecificationReader::RifCaseRealizationRunspecificationReader(const QString& fileName) :
|
||||||
|
RifCaseRealizationReader(fileName)
|
||||||
{
|
{
|
||||||
if (!m_file)
|
m_xmlStream = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
RifCaseRealizationRunspecificationReader::~RifCaseRealizationRunspecificationReader()
|
||||||
|
{
|
||||||
|
if (m_xmlStream)
|
||||||
{
|
{
|
||||||
m_file = new QFile(m_fileName);
|
delete m_xmlStream;
|
||||||
if (!m_file->open(QIODevice::ReadOnly | QIODevice::Text))
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RifCaseRealizationRunspecificationReader::parse()
|
||||||
|
{
|
||||||
|
auto xml = openDataStream();
|
||||||
|
QString paramName;
|
||||||
|
|
||||||
|
while (!xml->atEnd())
|
||||||
|
{
|
||||||
|
xml->readNext();
|
||||||
|
|
||||||
|
if (xml->isStartElement())
|
||||||
{
|
{
|
||||||
closeFile();
|
if (xml->name() == "modifier")
|
||||||
throw FileParseException(QString("Failed to open %1").arg(m_fileName));
|
{
|
||||||
|
paramName = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xml->name() == "id")
|
||||||
|
{
|
||||||
|
paramName = xml->readElementText();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(xml->name() == "value")
|
||||||
|
{
|
||||||
|
QString paramStrValue = xml->readElementText();
|
||||||
|
|
||||||
|
if (paramName.isEmpty()) continue;
|
||||||
|
|
||||||
|
if (RiaStdStringTools::startsWithAlphabetic(paramStrValue.toStdString()))
|
||||||
|
{
|
||||||
|
m_parameters->addParameter(paramName, paramStrValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!RiaStdStringTools::isNumber(paramStrValue.toStdString(), QLocale::c().decimalPoint().toAscii()))
|
||||||
|
{
|
||||||
|
throw FileParseException(QString("RifEnsembleParametersReader: Invalid number format in line %1").arg(xml->lineNumber()));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool parseOk = true;
|
||||||
|
double value = QLocale::c().toDouble(paramStrValue, &parseOk);
|
||||||
|
if (!parseOk)
|
||||||
|
{
|
||||||
|
throw FileParseException(QString("RifEnsembleParametersReader: Invalid number format in line %1").arg(xml->lineNumber()));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_parameters->addParameter(paramName, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (xml->isEndElement())
|
||||||
|
{
|
||||||
|
if (xml->name() == "modifier")
|
||||||
|
{
|
||||||
|
paramName = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -175,22 +293,25 @@ void RifCaseRealizationParametersReader::openFile()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RifCaseRealizationParametersReader::closeFile()
|
QXmlStreamReader * RifCaseRealizationRunspecificationReader::openDataStream()
|
||||||
{
|
{
|
||||||
if (m_file)
|
auto file = openFile();
|
||||||
{
|
|
||||||
m_file->close();
|
m_xmlStream = new QXmlStreamReader(file);
|
||||||
delete m_file;
|
return m_xmlStream;
|
||||||
m_file = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
const std::shared_ptr<RigCaseRealizationParameters> RifCaseRealizationParametersReader::parameters() const
|
void RifCaseRealizationRunspecificationReader::closeDataStream()
|
||||||
{
|
{
|
||||||
return m_parameters;
|
if (m_xmlStream)
|
||||||
|
{
|
||||||
|
delete m_xmlStream;
|
||||||
|
m_xmlStream = nullptr;
|
||||||
|
}
|
||||||
|
closeFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -212,7 +333,8 @@ QString RifCaseRealizationParametersFileLocator::locate(const QString& modelPath
|
|||||||
QStringList files = qdir.entryList(QDir::Files | QDir::NoDotAndDotDot);
|
QStringList files = qdir.entryList(QDir::Files | QDir::NoDotAndDotDot);
|
||||||
for (const QString& file : files)
|
for (const QString& file : files)
|
||||||
{
|
{
|
||||||
if (QString::compare(file, PARAMETERS_FILE_NAME, Qt::CaseInsensitive) == 0)
|
if (QString::compare(file, PARAMETERS_FILE_NAME, Qt::CaseInsensitive) == 0 ||
|
||||||
|
QString::compare(file, RUNSPEC_FILE_NAME, Qt::CaseInsensitive) == 0)
|
||||||
{
|
{
|
||||||
return qdir.absoluteFilePath(file);
|
return qdir.absoluteFilePath(file);
|
||||||
}
|
}
|
||||||
|
@ -34,38 +34,76 @@
|
|||||||
|
|
||||||
class QStringList;
|
class QStringList;
|
||||||
class QTextStream;
|
class QTextStream;
|
||||||
|
class QXmlStreamReader;
|
||||||
class QFile;
|
class QFile;
|
||||||
|
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
class RifCaseRealizationParametersReader
|
class RifCaseRealizationReader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RifCaseRealizationParametersReader();
|
RifCaseRealizationReader(const QString& fileName);
|
||||||
RifCaseRealizationParametersReader(const QString& fileName);
|
virtual ~RifCaseRealizationReader();
|
||||||
~RifCaseRealizationParametersReader();
|
|
||||||
|
|
||||||
void setFileName(const QString& fileName);
|
virtual void parse() = 0;
|
||||||
void parse();
|
|
||||||
const std::shared_ptr<RigCaseRealizationParameters> parameters() const;
|
const std::shared_ptr<RigCaseRealizationParameters> parameters() const;
|
||||||
|
|
||||||
|
static std::shared_ptr<RifCaseRealizationReader> createReaderFromFileName(const QString& fileName);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QFile* openFile();
|
||||||
|
void closeFile();
|
||||||
|
|
||||||
|
std::shared_ptr<RigCaseRealizationParameters> m_parameters;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_fileName;
|
||||||
|
QFile* m_file;
|
||||||
|
};
|
||||||
|
|
||||||
|
//==================================================================================================
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//==================================================================================================
|
||||||
|
class RifCaseRealizationParametersReader : public RifCaseRealizationReader
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RifCaseRealizationParametersReader(const QString& fileName);
|
||||||
|
virtual ~RifCaseRealizationParametersReader();
|
||||||
|
|
||||||
|
virtual void parse() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTextStream* openDataStream();
|
QTextStream* openDataStream();
|
||||||
void closeDataStream();
|
void closeDataStream();
|
||||||
void openFile();
|
|
||||||
void closeFile();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<RigCaseRealizationParameters> m_parameters;
|
QTextStream* m_textStream;
|
||||||
|
|
||||||
QString m_fileName;
|
|
||||||
QFile* m_file;
|
|
||||||
QTextStream* m_textStream;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//==================================================================================================
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//==================================================================================================
|
||||||
|
class RifCaseRealizationRunspecificationReader : public RifCaseRealizationReader
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RifCaseRealizationRunspecificationReader(const QString& fileName);
|
||||||
|
virtual ~RifCaseRealizationRunspecificationReader();
|
||||||
|
|
||||||
|
virtual void parse() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QXmlStreamReader * openDataStream();
|
||||||
|
void closeDataStream();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QXmlStreamReader* m_xmlStream;
|
||||||
|
};
|
||||||
|
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
@ -44,15 +44,17 @@ void addCaseRealizationParametersIfFound(RimSummaryCase& sumCase, const QString
|
|||||||
QString parametersFile = RifCaseRealizationParametersFileLocator::locate(modelFolderOrFile);
|
QString parametersFile = RifCaseRealizationParametersFileLocator::locate(modelFolderOrFile);
|
||||||
if (!parametersFile.isEmpty())
|
if (!parametersFile.isEmpty())
|
||||||
{
|
{
|
||||||
RifCaseRealizationParametersReader reader(parametersFile);
|
auto reader = RifCaseRealizationReader::createReaderFromFileName(parametersFile);
|
||||||
|
if (reader)
|
||||||
// Try parse case realization parameters
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
reader.parse();
|
// Try parse case realization parameters
|
||||||
sumCase.setCaseRealizationParameters(reader.parameters());
|
try
|
||||||
|
{
|
||||||
|
reader->parse();
|
||||||
|
sumCase.setCaseRealizationParameters(reader->parameters());
|
||||||
|
}
|
||||||
|
catch (...) {}
|
||||||
}
|
}
|
||||||
catch (...) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user