Updates of C++ class ERft to be used with python bindings
-> Support for extracting data based on report index -> adding extra float (time) to RftReportList
This commit is contained in:
parent
b992ff0e1c
commit
d258ce5a57
@ -44,16 +44,20 @@ public:
|
||||
template <typename T>
|
||||
const std::vector<T>& getRft(const std::string& name, const std::string& wellName,
|
||||
int year, int month, int day) const;
|
||||
template <typename T>
|
||||
const std::vector<T>& getRft(const std::string& name, int reportIndex) const;
|
||||
|
||||
std::vector<std::string> listOfWells() const;
|
||||
std::vector<RftDate> listOfdates() const;
|
||||
|
||||
using RftReportList = std::vector<std::pair<std::string, RftDate>>;
|
||||
using RftReportList = std::vector<std::tuple<std::string, RftDate, float>>;
|
||||
const RftReportList& listOfRftReports() const { return rftReportList; }
|
||||
|
||||
bool hasRft(const std::string& wellName, const RftDate& date) const;
|
||||
bool hasRft(const std::string& wellName, int year, int month, int day) const;
|
||||
|
||||
std::vector<EclEntry> listOfRftArrays(int reportIndex ) const;
|
||||
|
||||
std::vector<EclEntry> listOfRftArrays(const std::string& wellName,
|
||||
const RftDate& date) const;
|
||||
|
||||
@ -63,8 +67,10 @@ public:
|
||||
bool hasArray(const std::string& arrayName, const std::string& wellName,
|
||||
const RftDate& date) const;
|
||||
|
||||
int numberOfReports() { return numReports; }
|
||||
|
||||
private:
|
||||
std::map<int, std::pair<int,int>> arrIndexRange;
|
||||
std::map<int, std::tuple<int,int>> arrIndexRange;
|
||||
int numReports;
|
||||
std::vector<float> timeList;
|
||||
|
||||
@ -72,9 +78,11 @@ private:
|
||||
std::set<RftDate> dateList;
|
||||
RftReportList rftReportList;
|
||||
|
||||
std::map<std::pair<std::string,RftDate>,int> reportIndex; // mapping report index to wellName and date (tupe)
|
||||
std::map<std::tuple<std::string,RftDate>,int> reportIndices; // mapping report index to wellName and date (tupe)
|
||||
|
||||
int getReportIndex(const std::string& wellName, const RftDate& date) const;
|
||||
|
||||
int getArrayIndex(const std::string& name, int reportIndex) const;
|
||||
int getArrayIndex(const std::string& name, const std::string& wellName,
|
||||
const RftDate& date) const;
|
||||
};
|
||||
|
@ -63,13 +63,11 @@ ERft::ERft(const std::string &filename) : EclFile(filename)
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < first.size(); i++) {
|
||||
std::pair<int,int> range;
|
||||
range.first = first[i];
|
||||
|
||||
std::tuple<int,int> range;
|
||||
if (i == first.size() - 1) {
|
||||
range.second = listOfArrays.size();
|
||||
range = std::make_tuple(first[i], listOfArrays.size());
|
||||
} else {
|
||||
range.second = first[i+1];
|
||||
range = std::make_tuple(first[i], first[i+1]);
|
||||
}
|
||||
|
||||
arrIndexRange[i] = range;
|
||||
@ -78,32 +76,33 @@ ERft::ERft(const std::string &filename) : EclFile(filename)
|
||||
numReports = first.size();
|
||||
|
||||
for (size_t i = 0; i < wellName.size(); i++) {
|
||||
std::pair<std::string,RftDate> wellDatePair(wellName[i],dates[i]);
|
||||
reportIndex[wellDatePair] = i;
|
||||
rftReportList.push_back(wellDatePair);
|
||||
std::tuple<std::string, RftDate> wellDateTuple = std::make_tuple(wellName[i], dates[i]);
|
||||
std::tuple<std::string, RftDate, float> wellDateTimeTuple = std::make_tuple(wellName[i], dates[i], timeList[i]);
|
||||
reportIndices[wellDateTuple] = i;
|
||||
rftReportList.push_back(wellDateTimeTuple);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ERft::hasRft(const std::string& wellName, const RftDate& date) const
|
||||
{
|
||||
return reportIndex.find({wellName, date}) != reportIndex.end();
|
||||
return reportIndices.find({wellName, date}) != reportIndices.end();
|
||||
}
|
||||
|
||||
|
||||
bool ERft::hasRft(const std::string& wellName, int year, int month, int day) const
|
||||
{
|
||||
RftDate date(year, month, day);
|
||||
return reportIndex.find({wellName,date}) != reportIndex.end();
|
||||
return reportIndices.find({wellName,date}) != reportIndices.end();
|
||||
}
|
||||
|
||||
|
||||
int ERft::getReportIndex(const std::string& wellName, const RftDate& date) const
|
||||
{
|
||||
std::pair<std::string,std::tuple<int,int,int>> wellDatePair(wellName,date);
|
||||
auto rIndIt = reportIndex.find(wellDatePair);
|
||||
std::tuple<std::string,std::tuple<int,int,int>> wellDatePair(wellName, date);
|
||||
auto rIndIt = reportIndices.find(wellDatePair);
|
||||
|
||||
if (rIndIt == reportIndex.end()) {
|
||||
if (rIndIt == reportIndices.end()) {
|
||||
int y = std::get<0>(date);
|
||||
int m = std::get<1>(date);
|
||||
int d = std::get<2>(date);
|
||||
@ -124,8 +123,8 @@ bool ERft::hasArray(const std::string& arrayName, const std::string& wellName,
|
||||
|
||||
auto searchInd = arrIndexRange.find(reportInd);
|
||||
|
||||
int fromInd = searchInd->second.first;
|
||||
int toInd = searchInd->second.second;
|
||||
int fromInd = std::get<0>(searchInd->second);
|
||||
int toInd = std::get<1>(searchInd->second);
|
||||
|
||||
auto it = std::find(array_name.begin()+fromInd,array_name.begin()+toInd,arrayName);
|
||||
return it != array_name.begin() + toInd;
|
||||
@ -139,8 +138,8 @@ int ERft::getArrayIndex(const std::string& name, const std::string& wellName,
|
||||
|
||||
auto searchInd = arrIndexRange.find(rInd);
|
||||
|
||||
int fromInd =searchInd->second.first;
|
||||
int toInd = searchInd->second.second;
|
||||
int fromInd =std::get<0>(searchInd->second);
|
||||
int toInd = std::get<1>(searchInd->second);
|
||||
auto it=std::find(array_name.begin()+fromInd,array_name.begin()+toInd,name);
|
||||
|
||||
if (std::distance(array_name.begin(),it) == toInd) {
|
||||
@ -157,6 +156,28 @@ int ERft::getArrayIndex(const std::string& name, const std::string& wellName,
|
||||
}
|
||||
|
||||
|
||||
int ERft::getArrayIndex(const std::string& name, int reportIndex) const
|
||||
{
|
||||
if ((reportIndex < 0) || (reportIndex >= numReports)) {
|
||||
std::string message = "Report index " + std::to_string(reportIndex) + " not found in RFT file.";
|
||||
OPM_THROW(std::invalid_argument, message);
|
||||
}
|
||||
|
||||
auto searchInd = arrIndexRange.find(reportIndex);
|
||||
int fromInd =std::get<0>(searchInd->second);
|
||||
int toInd = std::get<1>(searchInd->second);
|
||||
|
||||
auto it=std::find(array_name.begin() + fromInd,array_name.begin() + toInd,name);
|
||||
|
||||
if (std::distance(array_name.begin(),it) == toInd) {
|
||||
std::string message = "Array " + name + " not found for RFT, rft report index: " + std::to_string(reportIndex);
|
||||
OPM_THROW(std::invalid_argument, message);
|
||||
}
|
||||
|
||||
return std::distance(array_name.begin(),it);
|
||||
}
|
||||
|
||||
|
||||
template<> const std::vector<float>&
|
||||
ERft::getRft<float>(const std::string& name, const std::string &wellName,
|
||||
const RftDate& date) const
|
||||
@ -277,6 +298,98 @@ ERft::getRft<bool>(const std::string& name, const std::string& wellName,
|
||||
}
|
||||
|
||||
|
||||
template<> const std::vector<float>&
|
||||
ERft::getRft<float>(const std::string& name, int reportIndex) const
|
||||
{
|
||||
int arrInd = getArrayIndex(name, reportIndex);
|
||||
|
||||
if (array_type[arrInd] != REAL) {
|
||||
std::string message = "Array " + name + " found in RFT file for selected report, but called with wrong type";
|
||||
OPM_THROW(std::runtime_error, message);
|
||||
}
|
||||
|
||||
auto search_array = real_array.find(arrInd);
|
||||
return search_array->second;
|
||||
}
|
||||
|
||||
|
||||
template<> const std::vector<double>&
|
||||
ERft::getRft<double>(const std::string& name, int reportIndex) const
|
||||
{
|
||||
int arrInd = getArrayIndex(name, reportIndex);
|
||||
|
||||
if (array_type[arrInd] != DOUB) {
|
||||
std::string message = "Array " + name + " !!found in RFT file for selected report, but called with wrong type";
|
||||
OPM_THROW(std::runtime_error, message);
|
||||
}
|
||||
|
||||
auto search_array = doub_array.find(arrInd);
|
||||
return search_array->second;
|
||||
}
|
||||
|
||||
|
||||
template<> const std::vector<int>&
|
||||
ERft::getRft<int>(const std::string& name, int reportIndex) const
|
||||
{
|
||||
int arrInd = getArrayIndex(name, reportIndex);
|
||||
|
||||
if (array_type[arrInd] != INTE) {
|
||||
std::string message = "Array " + name + " !!found in RFT file for selected report, but called with wrong type";
|
||||
OPM_THROW(std::runtime_error, message);
|
||||
}
|
||||
|
||||
auto search_array = inte_array.find(arrInd);
|
||||
return search_array->second;
|
||||
}
|
||||
|
||||
|
||||
template<> const std::vector<bool>&
|
||||
ERft::getRft<bool>(const std::string& name, int reportIndex) const
|
||||
{
|
||||
int arrInd = getArrayIndex(name, reportIndex);
|
||||
|
||||
if (array_type[arrInd] != LOGI) {
|
||||
std::string message = "Array " + name + " !!found in RFT file for selected report, but called with wrong type";
|
||||
OPM_THROW(std::runtime_error, message);
|
||||
}
|
||||
|
||||
auto search_array = logi_array.find(arrInd);
|
||||
return search_array->second;
|
||||
}
|
||||
|
||||
|
||||
template<> const std::vector<std::string>&
|
||||
ERft::getRft<std::string>(const std::string& name, int reportIndex) const
|
||||
{
|
||||
int arrInd = getArrayIndex(name, reportIndex);
|
||||
|
||||
if (array_type[arrInd] != CHAR) {
|
||||
std::string message = "Array " + name + " !!found in RFT file for selected report, but called with wrong type";
|
||||
OPM_THROW(std::runtime_error, message);
|
||||
}
|
||||
|
||||
auto search_array = char_array.find(arrInd);
|
||||
return search_array->second;
|
||||
}
|
||||
|
||||
|
||||
std::vector<EclFile::EclEntry> ERft::listOfRftArrays(int reportIndex) const
|
||||
{
|
||||
if ((reportIndex < 0) || (reportIndex >= numReports)) {
|
||||
std::string message = "Report index " + std::to_string(reportIndex) + " not found in RFT file.";
|
||||
OPM_THROW(std::invalid_argument, message);
|
||||
}
|
||||
|
||||
std::vector<EclEntry> list;
|
||||
auto searchInd = arrIndexRange.find(reportIndex);
|
||||
|
||||
for (int i = std::get<0>(searchInd->second); i < std::get<1>(searchInd->second); i++) {
|
||||
list.emplace_back(array_name[i], array_type[i], array_size[i]);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
std::vector<EclFile::EclEntry> ERft::listOfRftArrays(const std::string& wellName,
|
||||
const RftDate& date) const
|
||||
{
|
||||
@ -284,7 +397,7 @@ std::vector<EclFile::EclEntry> ERft::listOfRftArrays(const std::string& wellName
|
||||
int rInd = getReportIndex(wellName, date);
|
||||
|
||||
auto searchInd = arrIndexRange.find(rInd);
|
||||
for (int i = searchInd->second.first; i < searchInd->second.second; i++) {
|
||||
for (int i = std::get<0>(searchInd->second); i < std::get<1>(searchInd->second); i++) {
|
||||
list.emplace_back(array_name[i], array_type[i], array_size[i]);
|
||||
}
|
||||
|
||||
|
@ -1006,16 +1006,16 @@ void ECLRegressionTest::results_rft()
|
||||
if (rftReportList1 != rftReportList2) {
|
||||
std::vector<std::string> rftList1;
|
||||
for (auto& report : rftReportList1) {
|
||||
std::string well = report.first;
|
||||
std::tuple<int, int, int> date = report.second;
|
||||
std::string well = std::get<0>(report);
|
||||
std::tuple<int, int, int> date = std::get<1>(report);
|
||||
std::string str1 = well +" (" + std::to_string(std::get<0>(date)) + "/" + std::to_string(std::get<1>(date)) + "/" + std::to_string(std::get<2>(date)) + ")";
|
||||
rftList1.push_back(str1);
|
||||
}
|
||||
|
||||
std::vector<std::string> rftList2;
|
||||
for (auto& report : rftReportList2) {
|
||||
std::string well = report.first;
|
||||
std::tuple<int, int, int> date = report.second;
|
||||
std::string well = std::get<0>(report);
|
||||
std::tuple<int, int, int> date = std::get<1>(report);
|
||||
std::string str2 = well +" (" + std::to_string(std::get<0>(date)) + "/" + std::to_string(std::get<1>(date)) + "/" + std::to_string(std::get<2>(date)) + ")";
|
||||
rftList2.push_back(str2);
|
||||
}
|
||||
@ -1026,8 +1026,8 @@ void ECLRegressionTest::results_rft()
|
||||
}
|
||||
|
||||
for (auto& report : rftReportList2) {
|
||||
std::string well = report.first;
|
||||
std::tuple<int, int, int> date = report.second;
|
||||
std::string well = std::get<0>(report);
|
||||
std::tuple<int, int, int> date = std::get<1>(report);
|
||||
|
||||
std::string dateStr = std::to_string(std::get<0>(date)) + "/" + std::to_string(std::get<1>(date)) + "/" + std::to_string(std::get<2>(date));
|
||||
|
||||
|
@ -90,12 +90,12 @@ BOOST_AUTO_TEST_CASE(TestERft_1) {
|
||||
Date{2017,7,31},
|
||||
};
|
||||
|
||||
const std::vector<std::pair<std::string,Date>> ref_rftList = {
|
||||
{"PROD", Date{2015,1, 1}},
|
||||
{"INJ" , Date{2015,1, 1}},
|
||||
{"A-1H", Date{2015,9, 1}},
|
||||
{"B-2H", Date{2016,5,31}},
|
||||
{"PROD", Date{2017,7,31}}
|
||||
const std::vector<std::tuple<std::string, Date, float>> ref_rftList = {
|
||||
{"PROD", Date{2015,1, 1}, 0.00000000e+00},
|
||||
{"INJ" , Date{2015,1, 1}, 0.00000000e+00},
|
||||
{"A-1H", Date{2015,9, 1}, 0.24300000E+03},
|
||||
{"B-2H", Date{2016,5,31}, 0.51600000E+03},
|
||||
{"PROD", Date{2017,7,31}, 0.94200000E+03}
|
||||
};
|
||||
|
||||
std::string testFile="SPE1CASE1.RFT";
|
||||
@ -104,7 +104,7 @@ BOOST_AUTO_TEST_CASE(TestERft_1) {
|
||||
|
||||
std::vector<std::string> wellList = rft1.listOfWells();
|
||||
std::vector<Date> rftDates = rft1.listOfdates();
|
||||
std::vector<std::pair<std::string,Date>> rftList = rft1.listOfRftReports();
|
||||
std::vector<std::tuple<std::string, Date, float>> rftList = rft1.listOfRftReports();
|
||||
|
||||
BOOST_CHECK_EQUAL(wellList==ref_wellList, true);
|
||||
BOOST_CHECK_EQUAL(rftDates==ref_dates, true);
|
||||
@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(TestERft_1) {
|
||||
BOOST_CHECK_THROW(rft1.hasArray("SGAS","C-2H", Date{2016,5,30}),std::invalid_argument);
|
||||
BOOST_CHECK_THROW(rft1.hasArray("XXXX","C-2H", Date{2016,5,30}),std::invalid_argument);
|
||||
|
||||
// test member function getRft
|
||||
// // test member function getRft(name, wellName, date)
|
||||
|
||||
std::vector<int> vect1=rft1.getRft<int>("CONIPOS","B-2H", Date{2016,5,31});
|
||||
std::vector<float> vect2=rft1.getRft<float>("PRESSURE","B-2H", Date{2016,5,31});
|
||||
@ -139,6 +139,25 @@ BOOST_AUTO_TEST_CASE(TestERft_1) {
|
||||
BOOST_CHECK_EQUAL(vect2.size(), 3);
|
||||
BOOST_CHECK_EQUAL(vect3.size(), 16);
|
||||
|
||||
// test member function getRft(name, reportIndex)
|
||||
|
||||
std::vector<int> vect1a=rft1.getRft<int>("CONIPOS", 3);
|
||||
BOOST_CHECK_EQUAL(vect1.size(), vect1a.size());
|
||||
|
||||
std::vector<float> vect2a = rft1.getRft<float>("PRESSURE", 3);
|
||||
BOOST_CHECK_EQUAL(vect2.size(), vect2a.size());
|
||||
|
||||
for (size_t t = 0; t < vect2.size(); t++){
|
||||
BOOST_CHECK_EQUAL(vect2[t], vect2a[t]);
|
||||
}
|
||||
|
||||
std::vector<std::string> vect3a = rft1.getRft<std::string>("WELLETC", 3);
|
||||
BOOST_CHECK_EQUAL(vect2.size(), vect2a.size());
|
||||
|
||||
for (size_t t = 0; t < vect3.size(); t++){
|
||||
BOOST_CHECK_EQUAL(vect3[t], vect3a[t]);
|
||||
}
|
||||
|
||||
// called with invalid argument, array not existing, wrong well name or wrong date
|
||||
BOOST_CHECK_THROW(std::vector<int> vect11=rft1.getRft<int>("CONIPOS","C-2H", Date{2016,5,31}),std::invalid_argument);
|
||||
BOOST_CHECK_THROW(std::vector<int> vect11=rft1.getRft<int>("CONIPOS","B-2H", Date{2016,5,30}),std::invalid_argument);
|
||||
|
@ -325,7 +325,7 @@ namespace {
|
||||
>{};
|
||||
|
||||
for (const auto& wellDate : rft.listOfRftReports()) {
|
||||
dates[wellDate.first].push_back(wellDate.second);
|
||||
dates[std::get<0>(wellDate)].push_back(std::get<1>(wellDate));
|
||||
}
|
||||
|
||||
// Well OP_1
|
||||
|
Loading…
Reference in New Issue
Block a user