(#736) Added support for basic metadata and basic value queries

This commit is contained in:
Magne Sjaastad
2016-04-12 11:32:28 +02:00
parent 1d9405b266
commit 4b33c31a0f
7 changed files with 1108 additions and 0 deletions

View File

@@ -9,9 +9,11 @@ ${CEE_CURRENT_LIST_DIR}RifEclipseInputFileTools.h
${CEE_CURRENT_LIST_DIR}RifEclipseOutputFileTools.h
${CEE_CURRENT_LIST_DIR}RifEclipseRestartDataAccess.h
${CEE_CURRENT_LIST_DIR}RifEclipseRestartFilesetAccess.h
${CEE_CURRENT_LIST_DIR}RifEclipseSummaryTools.h
${CEE_CURRENT_LIST_DIR}RifEclipseUnifiedRestartFileAccess.h
${CEE_CURRENT_LIST_DIR}RifReaderEclipseInput.h
${CEE_CURRENT_LIST_DIR}RifReaderEclipseOutput.h
${CEE_CURRENT_LIST_DIR}RifReaderEclipseSummary.h
${CEE_CURRENT_LIST_DIR}RifJsonEncodeDecode.h
${CEE_CURRENT_LIST_DIR}RifReaderInterface.h
${CEE_CURRENT_LIST_DIR}RifReaderMockModel.h
@@ -24,8 +26,10 @@ ${CEE_CURRENT_LIST_DIR}RifEclipseOutputFileTools.cpp
${CEE_CURRENT_LIST_DIR}RifEclipseRestartDataAccess.cpp
${CEE_CURRENT_LIST_DIR}RifEclipseRestartFilesetAccess.cpp
${CEE_CURRENT_LIST_DIR}RifEclipseUnifiedRestartFileAccess.cpp
${CEE_CURRENT_LIST_DIR}RifEclipseSummaryTools.cpp
${CEE_CURRENT_LIST_DIR}RifReaderEclipseInput.cpp
${CEE_CURRENT_LIST_DIR}RifReaderEclipseOutput.cpp
${CEE_CURRENT_LIST_DIR}RifReaderEclipseSummary.cpp
${CEE_CURRENT_LIST_DIR}RifJsonEncodeDecode.cpp
${CEE_CURRENT_LIST_DIR}RifReaderInterface.cpp
${CEE_CURRENT_LIST_DIR}RifReaderMockModel.cpp

View File

@@ -0,0 +1,133 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RifEclipseSummaryTools.h"
#include "RifReaderEclipseSummary.h"
#include "ecl_util.h"
#include <iostream>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifEclipseSummaryTools::findSummaryHeaderFile(const std::string& inputFile, std::string* headerFile, bool* isFormatted)
{
findSummaryHeaderFileInfo(inputFile, headerFile, NULL, NULL, isFormatted);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<std::string> RifEclipseSummaryTools::findSummaryDataFiles(const std::string& caseFile)
{
std::vector<std::string> fileNames;
std::string path;
std::string base;
findSummaryHeaderFileInfo(caseFile, NULL, &path, &base, NULL);
if (path.empty() || base.empty()) return fileNames;
char* header_file = NULL;
stringlist_type* summary_file_list = stringlist_alloc_new();
ecl_util_alloc_summary_files(path.data(), base.data(), NULL, &header_file, summary_file_list);
if (stringlist_get_size( summary_file_list ) > 0)
{
for (int i = 0; i < stringlist_get_size(summary_file_list); i++)
{
fileNames.push_back(stringlist_iget(summary_file_list, i));
}
}
util_safe_free(header_file);
stringlist_free(summary_file_list);
return fileNames;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifEclipseSummaryTools::dumpMetaData(RifReaderEclipseSummary* readerEclipseSummary)
{
std::cout << " -- Well names --" << std::endl;
{
std::vector<std::string> names = readerEclipseSummary->wellNames();
for (size_t i = 0; i < names.size(); i++)
{
std::cout << names[i] << std::endl;
}
}
std::cout << " -- Well variable names --" << std::endl;
{
std::vector<std::string> names = readerEclipseSummary->wellVariableNames();
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;
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifEclipseSummaryTools::findSummaryHeaderFileInfo(const std::string& inputFile, std::string* headerFile, std::string* path, std::string* base, bool* isFormatted)
{
char* myPath = NULL;
char* myBase = NULL;
bool formattedFile = true;
util_alloc_file_components(inputFile.data(), &myPath, &myBase, NULL);
char* myHeaderFile = ecl_util_alloc_exfilename(myPath, myBase, ECL_SUMMARY_HEADER_FILE, true, -1);
if (!myHeaderFile)
{
myHeaderFile = ecl_util_alloc_exfilename(myPath, myBase, ECL_SUMMARY_HEADER_FILE, false, -1);
if (myHeaderFile)
{
formattedFile = false;
}
}
if (myHeaderFile && headerFile) *headerFile = myHeaderFile;
if (myPath && path) *path = myPath;
if (myBase && base) *base = myBase;
if (isFormatted) *isFormatted = formattedFile;
util_safe_free(myHeaderFile);
util_safe_free(myBase);
util_safe_free(myPath);
}

View File

@@ -0,0 +1,41 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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>
#include <vector>
class RifReaderEclipseSummary;
//==================================================================================================
//
//
//
//==================================================================================================
class RifEclipseSummaryTools
{
public:
static void findSummaryHeaderFile(const std::string& inputFile, std::string* headerFile, bool* isFormatted);
static std::vector<std::string> findSummaryDataFiles(const std::string& caseFile);
static void dumpMetaData(RifReaderEclipseSummary* readerEclipseSummary);
private:
static void findSummaryHeaderFileInfo(const std::string& inputFile, std::string* headerFile, std::string* path, std::string* base, bool* isFormatted);
};

View File

@@ -0,0 +1,238 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RifReaderEclipseSummary.h"
#include "ecl_sum.h"
#include <string>
#include <assert.h>
#include <QDateTime>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RifReaderEclipseSummary::RifReaderEclipseSummary()
: ecl_sum(NULL)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RifReaderEclipseSummary::~RifReaderEclipseSummary()
{
close();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifReaderEclipseSummary::open(const std::string& headerFileName, const std::vector<std::string>& dataFileNames)
{
assert(ecl_sum == NULL);
assert(!headerFileName.empty());
assert(dataFileNames.size() > 0);
stringlist_type* dataFiles = stringlist_alloc_new();
for (size_t i = 0; i < dataFileNames.size(); i++)
{
stringlist_append_copy(dataFiles, dataFileNames[i].data());
}
std::string itemSeparatorInVariableNames = ":";
ecl_sum = ecl_sum_fread_alloc(headerFileName.data(), dataFiles, itemSeparatorInVariableNames.data());
stringlist_free(dataFiles);
if (ecl_sum)
{
assert(ecl_sum_get_smspec(ecl_sum) != NULL);
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifReaderEclipseSummary::close()
{
if (ecl_sum)
{
ecl_sum_free(ecl_sum);
ecl_sum = NULL;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<std::string> RifReaderEclipseSummary::variableNames() const
{
assert(ecl_sum != NULL);
// Get all possible variable names from file
stringlist_type* keys = ecl_sum_alloc_matching_general_var_list(ecl_sum, NULL);
stringlist_sort(keys, NULL);
std::vector<std::string> names;
RifReaderEclipseSummary::populateVectorFromStringList(keys, &names);
stringlist_free(keys);
return names;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifReaderEclipseSummary::values(const std::string& variableName, std::vector<double>* values)
{
assert(ecl_sum != NULL);
int variableIndex = variableIndexFromVariableName(variableName);
if (variableIndex < 0) return false;
for (int time_index = 0; time_index < timeStepCount(); time_index++)
{
double value = ecl_sum_iget(ecl_sum, time_index, variableIndex);
values->push_back(value);
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RifReaderEclipseSummary::variableIndexFromVariableName(const std::string& keyword) const
{
assert(ecl_sum != NULL);
return ecl_sum_get_general_var_params_index(ecl_sum, keyword.data());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RifReaderEclipseSummary::timeStepCount() const
{
assert(ecl_sum != NULL);
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;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<time_t> RifReaderEclipseSummary::timeSteps() const
{
assert(ecl_sum != NULL);
std::vector<time_t> steps;
for (int time_index = 0; time_index < timeStepCount(); time_index++)
{
time_t sim_time = ecl_sum_iget_sim_time(ecl_sum , time_index);
steps.push_back(sim_time);
}
return steps;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<QDateTime> RifReaderEclipseSummary::fromTimeT(const std::vector<time_t>& timeSteps)
{
std::vector<QDateTime> a;
for (size_t i = 0; i < timeSteps.size(); i++)
{
QDateTime dt = QDateTime::fromTime_t(timeSteps[i]);
a.push_back(dt);
}
return a;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RifReaderEclipseSummary::populateVectorFromStringList(stringlist_type* stringList, std::vector<std::string>* strings)
{
assert(stringList && strings);
for (int i = 0; i < stringlist_get_size(stringList); i++)
{
strings->push_back(stringlist_iget(stringList, i));
}
}

View File

@@ -0,0 +1,68 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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>
#include <vector>
class QDateTime;
// Taken from ecl_sum.h
typedef struct ecl_sum_struct ecl_sum_type;
// Taken from stringlist.h
typedef struct stringlist_struct stringlist_type;
//==================================================================================================
//
//
//==================================================================================================
class RifReaderEclipseSummary
{
public:
RifReaderEclipseSummary();
~RifReaderEclipseSummary();
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<time_t> timeSteps() const;
bool values(const std::string& variableName, 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);
private:
int variableIndexFromVariableName(const std::string& variableName) const;
int timeStepCount() const;
static void populateVectorFromStringList(stringlist_type* stringList, std::vector<std::string>* strings);
private:
ecl_sum_type* ecl_sum;
};