Added EclipseSummaryAddress

This commit is contained in:
Magne Sjaastad
2016-05-04 14:11:04 +02:00
parent ec202310b7
commit 5640621049
8 changed files with 469 additions and 74 deletions

View File

@@ -18,6 +18,7 @@ ${CEE_CURRENT_LIST_DIR}RifJsonEncodeDecode.h
${CEE_CURRENT_LIST_DIR}RifReaderInterface.h
${CEE_CURRENT_LIST_DIR}RifReaderMockModel.h
${CEE_CURRENT_LIST_DIR}RifReaderSettings.h
${CEE_CURRENT_LIST_DIR}RifEclipseSummaryAddress.h
)
set (SOURCE_GROUP_SOURCE_FILES
@@ -34,6 +35,7 @@ ${CEE_CURRENT_LIST_DIR}RifJsonEncodeDecode.cpp
${CEE_CURRENT_LIST_DIR}RifReaderInterface.cpp
${CEE_CURRENT_LIST_DIR}RifReaderMockModel.cpp
${CEE_CURRENT_LIST_DIR}RifReaderSettings.cpp
${CEE_CURRENT_LIST_DIR}RifEclipseSummaryAddress.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@@ -0,0 +1,286 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 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 "RifEclipseSummaryAddress.h"
#include <vector>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RifEclipseSummaryAddress::RifEclipseSummaryAddress(const std::string& ertSummaryVarId)
: m_ertSummaryVarId(ertSummaryVarId)
{
fromErtSummaryVarId(m_ertSummaryVarId, &m_variableCategory, &m_simulationItemName, &m_quantityName);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RifEclipseSummaryAddress::RifEclipseSummaryAddress(SummaryVarCategory category, const std::string& simulationItemName, const std::string& quantityName)
: m_variableCategory(category),
m_simulationItemName(simulationItemName),
m_quantityName(quantityName)
{
m_ertSummaryVarId = toErtSummaryVarId(m_variableCategory, m_simulationItemName, m_quantityName);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RifEclipseSummaryAddress::SummaryVarCategory RifEclipseSummaryAddress::category() const
{
return m_variableCategory;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::string RifEclipseSummaryAddress::simulationItemName() const
{
return m_simulationItemName;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::string RifEclipseSummaryAddress::quantityName() const
{
return m_quantityName;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::string RifEclipseSummaryAddress::ertSummaryVarId() const
{
return m_ertSummaryVarId;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::string RifEclipseSummaryAddress::categoryName(SummaryVarCategory category)
{
std::string name;
switch (category)
{
case RifEclipseSummaryAddress::SUMMARY_WELL:
name = "Well";
break;
case RifEclipseSummaryAddress::SUMMARY_WELL_COMPLETION:
name = "Completion";
break;
case RifEclipseSummaryAddress::SUMMARY_GROUP:
name = "Group";
break;
case RifEclipseSummaryAddress::SUMMARY_FIELD:
name = "Field";
break;
case RifEclipseSummaryAddress::SUMMARY_REGION:
name = "Region";
break;
case RifEclipseSummaryAddress::SUMMARY_MISC:
name = "Misc";
break;
case RifEclipseSummaryAddress::SUMMARY_BLOCK:
name = "Block";
break;
case RifEclipseSummaryAddress::SUMMARY_BLOCK_LGR:
name = "LGR Block";
break;
case RifEclipseSummaryAddress::SUMMARY_AQUIFIER:
name = "Aquifier";
break;
case RifEclipseSummaryAddress::SUMMARY_SEGMENT:
name = "Segment";
break;
case RifEclipseSummaryAddress::SUMMARY_SEGMENT_RIVER:
name = "Segment River";
break;
default:
break;
}
return name;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::string RifEclipseSummaryAddress::toErtSummaryVarId(SummaryVarCategory category, const std::string& simulationItemName, const std::string& quantityName)
{
std::string ertSummaryVarId;
ertSummaryVarId += prefixForCategory(category);
ertSummaryVarId += quantityName;
if (simulationItemName.size() != 0)
{
ertSummaryVarId += ":";
ertSummaryVarId += simulationItemName;
}
return ertSummaryVarId;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<std::string> split(const std::string &text, char sep) {
std::vector<std::string> tokens;
std::size_t start = 0, end = 0;
while ((end = text.find(sep, start)) != std::string::npos) {
tokens.push_back(text.substr(start, end - start));
start = end + 1;
}
tokens.push_back(text.substr(start));
return tokens;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifEclipseSummaryAddress::fromErtSummaryVarId(const std::string& ertSummaryVarId, SummaryVarCategory* type, std::string* simulationItemName, std::string* quantityName)
{
*type = categoryFromErtSummaryVarId(ertSummaryVarId);
std::string prefix = prefixForCategory(*type);
std::string addressNoPrefix = ertSummaryVarId.substr(prefix.size());
std::vector<std::string> tokens = split(addressNoPrefix, ':');
if (tokens.size() > 0)
{
*quantityName = tokens[0];
}
if (tokens.size() > 1)
{
*simulationItemName = tokens[1];
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::string RifEclipseSummaryAddress::prefixForCategory(SummaryVarCategory category)
{
std::string prefix;
switch (category)
{
case RifEclipseSummaryAddress::SUMMARY_WELL:
prefix = "W";
break;
case RifEclipseSummaryAddress::SUMMARY_WELL_COMPLETION:
prefix = "C";
break;
case RifEclipseSummaryAddress::SUMMARY_GROUP:
prefix = "G";
break;
case RifEclipseSummaryAddress::SUMMARY_FIELD:
prefix = "F";
break;
case RifEclipseSummaryAddress::SUMMARY_REGION:
prefix = "R";
break;
case RifEclipseSummaryAddress::SUMMARY_MISC:
break;
case RifEclipseSummaryAddress::SUMMARY_BLOCK:
prefix = "B";
break;
case RifEclipseSummaryAddress::SUMMARY_BLOCK_LGR:
prefix = "LB";
break;
case RifEclipseSummaryAddress::SUMMARY_AQUIFIER:
prefix = "A";
break;
case RifEclipseSummaryAddress::SUMMARY_SEGMENT:
prefix = "S";
break;
case RifEclipseSummaryAddress::SUMMARY_SEGMENT_RIVER:
prefix = "SR";
break;
default:
break;
}
return prefix;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RifEclipseSummaryAddress::SummaryVarCategory RifEclipseSummaryAddress::categoryFromErtSummaryVarId(const std::string& resultAddress)
{
SummaryVarCategory category = RifEclipseSummaryAddress::SUMMARY_MISC;
if (resultAddress.size() > 1)
{
std::string twoFirstChars = resultAddress.substr(0, 2);
if (twoFirstChars == "SR")
{
category = RifEclipseSummaryAddress::SUMMARY_SEGMENT_RIVER;
}
else if (twoFirstChars == "LB")
{
category = RifEclipseSummaryAddress::SUMMARY_BLOCK_LGR;
}
else
{
char firstChar = resultAddress[0];
switch (firstChar)
{
case 'W':
category = RifEclipseSummaryAddress::SUMMARY_WELL;
break;
case 'C':
category = RifEclipseSummaryAddress::SUMMARY_WELL_COMPLETION;
break;
case 'G':
category = RifEclipseSummaryAddress::SUMMARY_GROUP;
break;
case 'F':
category = RifEclipseSummaryAddress::SUMMARY_FIELD;
break;
case 'R':
category = RifEclipseSummaryAddress::SUMMARY_REGION;
break;
case 'B':
category = RifEclipseSummaryAddress::SUMMARY_BLOCK;
break;
case 'A':
category = RifEclipseSummaryAddress::SUMMARY_AQUIFIER;
break;
case 'S':
category = RifEclipseSummaryAddress::SUMMARY_SEGMENT;
break;
default:
break;
}
}
}
return category;
}

View File

@@ -0,0 +1,73 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <string>
//==================================================================================================
//
//
//==================================================================================================
class RifEclipseSummaryAddress
{
public:
// Based on list in ecl_smspec.c and list of types taken from Eclipse Reference Manual ecl_rm_2011.1.pdf
enum SummaryVarCategory
{
SUMMARY_WELL, // W
SUMMARY_WELL_COMPLETION, // C
SUMMARY_GROUP, // G
SUMMARY_FIELD, // F
SUMMARY_REGION, // R
SUMMARY_MISC, //
SUMMARY_BLOCK, // B
SUMMARY_BLOCK_LGR, // LB
SUMMARY_AQUIFIER, // A
SUMMARY_SEGMENT, // S
SUMMARY_SEGMENT_RIVER // SR
};
public:
RifEclipseSummaryAddress(const std::string& ertSummaryVarId);
RifEclipseSummaryAddress(SummaryVarCategory category, const std::string& simulationItemName, const std::string& quantityName);
SummaryVarCategory category() const;
std::string simulationItemName() const;
std::string quantityName() const;
std::string ertSummaryVarId() const;
static std::string categoryName(SummaryVarCategory category);
private:
static std::string toErtSummaryVarId(SummaryVarCategory category, const std::string& simulationItemName, const std::string& quantityName);
static void fromErtSummaryVarId(const std::string& ertSummaryVarId, SummaryVarCategory* category, std::string* simulationItemName, std::string* quantityName);
static std::string prefixForCategory(SummaryVarCategory category);
static SummaryVarCategory categoryFromErtSummaryVarId(const std::string& ertSummaryVarId);
private:
std::string m_ertSummaryVarId;
SummaryVarCategory m_variableCategory;
std::string m_simulationItemName;
std::string m_quantityName;
};

View File

@@ -70,33 +70,24 @@ std::vector<std::string> RifEclipseSummaryTools::findSummaryDataFiles(const std:
//--------------------------------------------------------------------------------------------------
void RifEclipseSummaryTools::dumpMetaData(RifReaderEclipseSummary* readerEclipseSummary)
{
std::cout << " -- Well names --" << std::endl;
std::vector<RifEclipseSummaryAddress> addresses = readerEclipseSummary->allResultAddresses();
for (int category = 0; category < RifEclipseSummaryAddress::SUMMARY_SEGMENT_RIVER; category++)
{
std::vector<std::string> names = readerEclipseSummary->wellNames();
RifEclipseSummaryAddress::SummaryVarCategory categoryEnum = RifEclipseSummaryAddress::SummaryVarCategory(category);
for (size_t i = 0; i < names.size(); i++)
std::vector<RifEclipseSummaryAddress> catAddresses = addressesForCategory(addresses, categoryEnum);
if (catAddresses.size() > 0)
{
std::cout << names[i] << std::endl;
}
}
std::cout << RifEclipseSummaryAddress::categoryName(categoryEnum) << " count : " << catAddresses.size() << std::endl;
std::cout << " -- Well variable names --" << std::endl;
{
std::vector<std::string> names = readerEclipseSummary->wellVariableNames();
for (size_t i = 0; i < catAddresses.size(); i++)
{
std::cout << catAddresses[i].ertSummaryVarId() << " " << catAddresses[i].simulationItemName() << " " << catAddresses[i].quantityName() << std::endl;
}
for (size_t i = 0; i < names.size(); i++)
{
std::cout << names[i] << std::endl;
}
}
std::cout << " -- Group names --" << std::endl;
{
std::vector<std::string> names = readerEclipseSummary->wellGroupNames();
for (size_t i = 0; i < names.size(); i++)
{
std::cout << names[i] << std::endl;
std::cout << std::endl;
}
}
}
@@ -131,3 +122,21 @@ void RifEclipseSummaryTools::findSummaryHeaderFileInfo(const std::string& inputF
util_safe_free(myBase);
util_safe_free(myPath);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RifEclipseSummaryAddress> RifEclipseSummaryTools::addressesForCategory(const std::vector<RifEclipseSummaryAddress>& addresses, RifEclipseSummaryAddress::SummaryVarCategory category)
{
std::vector<RifEclipseSummaryAddress> filteredAddresses;
for (size_t i = 0; i < addresses.size(); i++)
{
if (addresses[i].category() == category)
{
filteredAddresses.push_back(addresses[i]);
}
}
return filteredAddresses;
}

View File

@@ -18,6 +18,8 @@
#pragma once
#include "RifEclipseSummaryAddress.h"
#include <string>
#include <vector>
@@ -38,4 +40,5 @@ public:
private:
static void findSummaryHeaderFileInfo(const std::string& inputFile, std::string* headerFile, std::string* path, std::string* base, bool* isFormatted);
static std::vector<RifEclipseSummaryAddress> addressesForCategory(const std::vector<RifEclipseSummaryAddress>& addresses, RifEclipseSummaryAddress::SummaryVarCategory category);
};

View File

@@ -103,6 +103,22 @@ std::vector<std::string> RifReaderEclipseSummary::variableNames() const
return names;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RifEclipseSummaryAddress> RifReaderEclipseSummary::allResultAddresses() const
{
std::vector<RifEclipseSummaryAddress> addresses;
std::vector<std::string> fileVariableNames = variableNames();
for (size_t i = 0; i < fileVariableNames.size(); i++)
{
addresses.push_back(RifEclipseSummaryAddress(fileVariableNames[i]));
}
return addresses;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -123,6 +139,15 @@ bool RifReaderEclipseSummary::values(const std::string& variableName, std::vecto
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifReaderEclipseSummary::values(const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values)
{
std::string var = resultAddress.ertSummaryVarId();
return this->values(var, values);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -143,53 +168,6 @@ int RifReaderEclipseSummary::timeStepCount() const
return ecl_sum_get_data_length(ecl_sum);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<std::string> RifReaderEclipseSummary::wellGroupNames() const
{
assert(ecl_sum != NULL);
std::vector<std::string> names;
stringlist_type* stringList = ecl_sum_alloc_group_list(ecl_sum, NULL);
RifReaderEclipseSummary::populateVectorFromStringList(stringList, &names);
stringlist_free(stringList);
return names;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<std::string> RifReaderEclipseSummary::wellNames() const
{
assert(ecl_sum != NULL);
std::vector<std::string> names;
stringlist_type* stringList = ecl_sum_alloc_well_list(ecl_sum, NULL);
RifReaderEclipseSummary::populateVectorFromStringList(stringList, &names);
stringlist_free(stringList);
return names;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<std::string> RifReaderEclipseSummary::wellVariableNames() const
{
assert(ecl_sum != NULL);
std::vector<std::string> names;
stringlist_type* stringList = ecl_sum_alloc_well_var_list(ecl_sum);
RifReaderEclipseSummary::populateVectorFromStringList(stringList, &names);
stringlist_free(stringList);
return names;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -18,9 +18,12 @@
#pragma once
#include "RifEclipseSummaryAddress.h"
#include <string>
#include <vector>
class QDateTime;
// Taken from ecl_sum.h
@@ -42,16 +45,13 @@ public:
bool open(const std::string& headerFileName, const std::vector<std::string>& dataFileNames);
void close();
std::vector<std::string> wellNames() const;
std::vector<std::string> wellGroupNames() const;
std::vector<std::string> wellVariableNames() const;
std::vector<std::string> variableNames() const;
std::vector<RifEclipseSummaryAddress> allResultAddresses() const;
std::vector<time_t> timeSteps() const;
bool values(const std::string& variableName, std::vector<double>* values);
bool values(const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values);
// TODO: Move this to a tools class with static members
static std::vector<QDateTime> fromTimeT(const std::vector<time_t>& timeSteps);