Skip to content

Commit

Permalink
Finish v0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
einar90 committed Apr 5, 2016
2 parents 0541cbf + fc337d6 commit 67915a1
Show file tree
Hide file tree
Showing 84 changed files with 17,211 additions and 60 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "FieldOpt/WellIndexCalculator"]
path = FieldOpt/WellIndexCalculator
url = [email protected]:PetroleumCyberneticsGroup/WellIndexCalculator.git
[submodule "FieldOpt/AdgprsSummaryConverter"]
path = FieldOpt/AdgprsSummaryConverter
url = [email protected]:PetroleumCyberneticsGroup/AdgprsSummaryConverter.git
17 changes: 17 additions & 0 deletions FieldOpt/AdgprsResultsReader/AdgprsResultsReader.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
include(../defaults.pri)

CONFIG -= app_bundle
CONFIG += c++11
TEMPLATE = lib

LIBS += -lhdf5_cpp

TARGET = adgprsresultsreader

SOURCES += \
json_summary_reader.cpp \
adgprs_results_reader.cpp

HEADERS += \
json_summary_reader.h \
adgprs_results_reader.h
23 changes: 23 additions & 0 deletions FieldOpt/AdgprsResultsReader/adgprs_results_reader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "adgprs_results_reader.h"
#include <QStringList>
#include "Utilities/unix/execution.h"
#include "Utilities/file_handling/filehandling.h"

namespace AdgprsResultsReader {

AdgprsResultsReader::AdgprsResultsReader(QString summary_path)
{
hdf5_path_ = summary_path;
json_path_ = summary_path.split(".SIM.H5").first() + ".json";
convertHdfSummaryToJson();
json_reader_ = new JsonSummaryReader(json_path_);
}

void AdgprsResultsReader::convertHdfSummaryToJson()
{
QString conversion_script_path = Utilities::FileHandling::GetBuildDirectoryPath() + "/AdgprsSummaryConverter/AdgprsSummaryConverter.py";
QStringList params = {hdf5_path_, json_path_};
Utilities::Unix::ExecShellScript(conversion_script_path, params);
}

}
34 changes: 34 additions & 0 deletions FieldOpt/AdgprsResultsReader/adgprs_results_reader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef ADGPRSRESULTSREADER_H
#define ADGPRSRESULTSREADER_H

#include <QString>
#include "json_summary_reader.h"

namespace AdgprsResultsReader {

class AdgprsResultsReader
{
public:
/*!
* \brief AdgprsResultsReader
* \param summary_path Path to a ADGPRS summary file in the HDF5 format, including the .SIM.H5 suffix.
*/
AdgprsResultsReader(QString summary_path);

/*!
* \brief results Get the object allowing access to the results.
* \return
*/
JsonSummaryReader *results() const { return json_reader_; }

private:
QString hdf5_path_;
QString json_path_;
JsonSummaryReader *json_reader_;

void convertHdfSummaryToJson();

};

}
#endif // ADGPRSRESULTSREADER_H
125 changes: 125 additions & 0 deletions FieldOpt/AdgprsResultsReader/json_summary_reader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#include "json_summary_reader.h"
#include <stdexcept>
#include <iostream>
#include <QJsonDocument>
#include <QJsonArray>
#include <QFile>
#include <QList>
#include <stdexcept>
#include <cmath>

namespace AdgprsResultsReader {

JsonSummaryReader::JsonSummaryReader(QString file_path)
{
QFile *file = new QFile(file_path);
if (!file->open(QIODevice::ReadOnly))
throw std::runtime_error("Unable to open JSON summary file " + file_path.toStdString());
QByteArray data = file->readAll();
QJsonDocument json = QJsonDocument::fromJson(data);
if (json.isNull())
throw std::runtime_error("Unable to parse the JSON summary file " + file_path.toStdString());
if (!json.isObject())
throw std::runtime_error("The json summary must be a valid json object " + file_path.toStdString());

QJsonObject json_summary = QJsonObject(json.object());
readGlobal(json_summary["Field"].toObject());
readFieldProps(json_summary["Field"].toObject()["Properties"].toObject());
readWellProps(json_summary["Wells"].toArray());
file->close();

}

QList<QString> JsonSummaryReader::GetAvalableFieldPropertyNames() const
{
return field_properties_.keys();
}

QVector<double> *JsonSummaryReader::GetFieldProperty(QString prop_name) const
{
if (QString::compare(prop_name, "TIME") == 0)
return time_;
if (!field_properties_.contains(prop_name))
throw std::runtime_error("Field property " + prop_name.toStdString() + " not recognized.");
return field_properties_[prop_name];
}

QList<QString> JsonSummaryReader::GetAvailableWellPropertyNames() const
{
return getWell(0)->properties_.keys();
}

QVector<double> *JsonSummaryReader::GetWellProperty(int well, QString prop_name) const
{
if (!getWell(well)->properties_.contains(prop_name))
throw std::runtime_error("Well property " + prop_name.toStdString() + " not recognized.");
return getWell(well)->properties_[prop_name];
}

bool JsonSummaryReader::IsInjector(int well) const
{
return getWell(well)->is_injector;
}

int JsonSummaryReader::GetNumberOfPerforations(int well) const
{
return getWell(well)->num_perforations;
}

JsonSummaryReader::WellData *JsonSummaryReader::getWell(int well) const
{
if (well < 0 || well >= wells_.size())
throw std::runtime_error(QString::number(well).toStdString() + " not a valid well number.");
return wells_[well];
}

void JsonSummaryReader::readGlobal(QJsonObject field)
{
num_wells_ = field["NumWells"].toInt();

time_ = new QVector<double>();
QJsonArray json_time = field["TIME"].toArray();
foreach (QJsonValue t, json_time) {
time_->append(t.toDouble());
}
}

void JsonSummaryReader::readFieldProps(QJsonObject field_props)
{
field_properties_ = QHash<QString, QVector<double> *>();
QList<QString> keys = {"FGPT", "FOPT", "FWPT", "FOPR", "FGPR", "FWPR",
"FGIT", "FGIR", "FOIT", "FOIR", "FWIT", "FWIR"};

foreach (QString key, keys) {
field_properties_[key] = new QVector<double>();
foreach (QJsonValue v, field_props[key].toArray()) {
field_properties_[key]->append(std::abs(v.toDouble()));
}
}
}

void JsonSummaryReader::readWellProps(QJsonArray well_props)
{
foreach (QJsonValue w, well_props) {
WellData *data = new WellData();
if (w.toObject()["IsInjector"].toInt() == 1)
data->is_injector = true;
else
data->is_injector = false;

data->num_perforations = w.toObject()["NumPerforations"].toInt();

data->properties_ = QHash<QString, QVector<double> *>();
QList<QString> keys = {"WBHP","WGR","WOR","WWR","WGT","WOT","WWT"};
foreach (QString key, keys) {
data->properties_[key] = new QVector<double>();
foreach (QJsonValue v, w.toObject()["Properties"].toObject()[key].toArray()) {
data->properties_[key]->append(v.toDouble());
}
}
wells_.append(data);
}
}


}
94 changes: 94 additions & 0 deletions FieldOpt/AdgprsResultsReader/json_summary_reader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#ifndef JSON_SUMMARY_READER_H
#define JSON_SUMMARY_READER_H

#include <QString>
#include <QVector>
#include <QHash>
#include <QJsonObject>

namespace AdgprsResultsReader {

/*!
* \brief The JsonSummaryReader class reads the JSON summary files created
* by the AdgprsSummaryConverter pythnon script. This class should not be instantiated directly.
*
* \note All field values are absolute values. I.e. borth production and injection numbers will
* be positive.
*/
class JsonSummaryReader
{
public:
/*!
* \brief JsonSummaryReader reads the summary file and stores the data in arrays.
* \param file_path Path to a valid .json file.
*/
JsonSummaryReader(QString file_path);

/*!
* \brief GetNumberOfWells Returns the number of wells found in the summary.
*/
int GetNumberOfWells() const { return num_wells_; }

/*!
* \brief GetTimeVector Get the time vector for the summary data.
*/
QVector<double> *GetTimeVector() const { return time_; }

/*!
* \brief GetAvalableFieldPropertyNames Get a list of all the valid field property names.
*/
QList<QString> GetAvalableFieldPropertyNames() const;

/*!
* \brief GetFieldProperty Returns a data vector for a specific property.
* \param prop_name name of the property, using the ECLIPSE summary naming scheme (e.g. FOPT, FWPR).
*/
QVector<double> *GetFieldProperty(QString prop_name) const;

/*!
* \brief GetAvailableWellPropertyNames Get a list of all the valid well property names.
*/
QList<QString> GetAvailableWellPropertyNames() const;

/*!
* \brief GetWellProperty Returns a data vector for a specific property for a specific well.
* \param well The number of the well to get data from.
* \param prop_name The name of the property to get.
*/
QVector<double> *GetWellProperty(int well, QString prop_name) const;

/*!
* \brief IsInjector Check if a well is an injector.
* \param well The number of the well to check.
*/
bool IsInjector(int well) const;

/*!
* \brief GetNumberOfPerforations Get the number of perforations in a specific well.
* \param well The number of the well to check.
*/
int GetNumberOfPerforations(int well) const;


private:
struct WellData {
bool is_injector;
int num_perforations;
QHash<QString, QVector<double> *> properties_;
};

QVector<double> *time_;
int num_wells_;

QHash<QString, QVector<double> *> field_properties_;
QList<WellData *> wells_;
WellData *getWell(int well) const;

void readGlobal(QJsonObject field);
void readFieldProps(QJsonObject field_props);
void readWellProps(QJsonArray well_props);
};

}

#endif // JSON_SUMMARY_READER_H
1 change: 1 addition & 0 deletions FieldOpt/AdgprsSummaryConverter
Submodule AdgprsSummaryConverter added at 577fc4
27 changes: 18 additions & 9 deletions FieldOpt/FieldOpt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,31 @@ SUBDIRS = \
Utilities \
Optimization \
Simulation \
Runner
Runner \
WellIndexCalculator \
GTest \
AdgprsResultsReader

GTest.depends = ERTWrapper Utilities Model Optimization Simulation Runner
GTest.depends = ERTWrapper Utilities Model Optimization Simulation Runner AdgprsResultsReader
Model.depends = ERTWrapper Utilities
Optimization.depends = Model Utilities Simulation
Simulation.depends = Model Utilities
Simulation.depends = Model Utilities AdgprsResultsReader
Runner.depends = Optimization Model Utilities Simulation
WellIndexCalculator.depends = Model

OTHER_FILES += \
defaults.pri \
../examples/MRST/compass/driver.dat \
../examples/MRST/compass/driver_kongull.dat
../examples/MRST/compass/driver_kongull.dat \
AdgprsSummaryConverter/*

# Copy simulator execution scripts to build dir
copy_sim_exec_scripts.commands = $(COPY_DIR) $$PWD/execution_scripts $$OUT_PWD
first.depends = $(first) copy_sim_exec_scripts
# Copy ADPGRS summary converter python script to build dir
copy_scripts.commands = \
$(MKDIR) -p $$OUT_PWD/AdgprsSummaryConverter ; \
$(MKDIR) -p $$OUT_PWD/execution_scripts ; \
$(COPY_FILE) $$PWD/execution_scripts/*.sh $$OUT_PWD/execution_scripts ; \
$(COPY_FILE) $$PWD/AdgprsSummaryConverter/*.py $$OUT_PWD/AdgprsSummaryConverter/
first.depends = $(first) copy_scripts
export(first.depends)
export(copy_sim_exec_scripts.commands)
QMAKE_EXTRA_TARGETS += first copy_sim_exec_scripts
export(copy_scripts.commands)
QMAKE_EXTRA_TARGETS += first copy_scripts
22 changes: 22 additions & 0 deletions FieldOpt/GTest/AdgprsResultsReader/test_adgprs_results_reader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "GTest/Simulation/results/test_fixture_adgprs.h"
#include "AdgprsResultsReader/adgprs_results_reader.h"

namespace {

class AdgprsResultsReaderTest : public AdgprsTestFixture {
protected:
AdgprsResultsReaderTest() {
reader_ = new AdgprsResultsReader::AdgprsResultsReader(hdf5_summary_path_);
}
virtual ~AdgprsResultsReaderTest() {}
virtual void SetUp() {}
AdgprsResultsReader::AdgprsResultsReader *reader_;
};

TEST_F(AdgprsResultsReaderTest, Global) {
EXPECT_EQ(5, reader_->results()->GetNumberOfWells());
}

}


Loading

0 comments on commit 67915a1

Please sign in to comment.