@@ -52,6 +52,7 @@ public:
|
||||
std::chrono::system_clock::time_point startdate() const { return startdat; }
|
||||
|
||||
const std::vector<std::string>& keywordList() const;
|
||||
std::vector<std::string> keywordList(const std::string& pattern) const;
|
||||
const std::vector<SummaryNode>& summaryNodeList() const;
|
||||
|
||||
int timestepIdxAtReportstepStart(const int reportStep) const;
|
||||
|
||||
@@ -298,9 +298,6 @@ std::chrono::system_clock::time_point esmry_start_date(const Opm::EclIO::ESmry *
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void python::common::export_IO(py::module& m) {
|
||||
|
||||
py::enum_<Opm::EclIO::eclArrType>(m, "eclArrType", py::arithmetic())
|
||||
@@ -341,7 +338,11 @@ void python::common::export_IO(py::module& m) {
|
||||
.def("__get_all", &get_smry_vector)
|
||||
.def("__get_at_rstep", &get_smry_vector_at_rsteps)
|
||||
.def_property_readonly("start_date", &esmry_start_date)
|
||||
.def_property_readonly("list_of_keys", &Opm::EclIO::ESmry::keywordList);
|
||||
|
||||
.def("keys", (const std::vector<std::string>& (Opm::EclIO::ESmry::*) (void) const)
|
||||
&Opm::EclIO::ESmry::keywordList)
|
||||
.def("keys", (std::vector<std::string> (Opm::EclIO::ESmry::*) (const std::string&) const)
|
||||
&Opm::EclIO::ESmry::keywordList);
|
||||
|
||||
py::class_<Opm::EclIO::EGrid>(m, "EGrid")
|
||||
.def(py::init<const std::string &>())
|
||||
|
||||
@@ -79,17 +79,26 @@ class TestEclFile(unittest.TestCase):
|
||||
"WWIR:PROD", "WWIT:INJ", "WWIT:PROD", "WWPR:INJ", "WWPR:PROD", "WWPT:INJ",
|
||||
"WWPT:PROD"]
|
||||
|
||||
ref_keys_pattern = ["WGPR:INJ", "WGPR:PROD", "WOPR:INJ", "WOPR:PROD", "WWPR:INJ", "WWPR:PROD"]
|
||||
|
||||
smry1 = ESmry(test_path("data/SPE1CASE1.SMSPEC"))
|
||||
|
||||
self.assertEqual(len(smry1.list_of_keys), len(ref_key_list))
|
||||
list_of_keys = smry1.keys()
|
||||
self.assertEqual(len(list_of_keys), len(ref_key_list))
|
||||
|
||||
for key, ref_key in zip(smry1.list_of_keys, ref_key_list):
|
||||
for key, ref_key in zip(list_of_keys, ref_key_list):
|
||||
self.assertEqual(key, ref_key)
|
||||
|
||||
for key in smry1.list_of_keys:
|
||||
for key in list_of_keys:
|
||||
data = smry1[key]
|
||||
self.assertEqual(len(smry1), len(data))
|
||||
|
||||
list_of_keys2 = smry1.keys("W?PR:*")
|
||||
|
||||
self.assertEqual(len(list_of_keys2), len(ref_keys_pattern))
|
||||
|
||||
for key, ref in zip(list_of_keys2, ref_keys_pattern):
|
||||
self.assertEqual(key, ref)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <set>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <fnmatch.h>
|
||||
|
||||
#include <opm/common/utility/FileSystem.hpp>
|
||||
#include <opm/common/utility/TimeService.hpp>
|
||||
@@ -615,10 +616,24 @@ const std::string& ESmry::get_unit(const std::string& name) const {
|
||||
return kwunits.at(name);
|
||||
}
|
||||
|
||||
const std::vector<std::string>& ESmry::keywordList() const {
|
||||
const std::vector<std::string>& ESmry::keywordList() const
|
||||
{
|
||||
return keyword;
|
||||
}
|
||||
|
||||
std::vector<std::string> ESmry::keywordList(const std::string& pattern) const
|
||||
{
|
||||
std::vector<std::string> list;
|
||||
|
||||
for (auto key : keyword)
|
||||
if (fnmatch( pattern.c_str(), key.c_str(), 0 ) == 0 )
|
||||
list.push_back(key);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const std::vector<SummaryNode>& ESmry::summaryNodeList() const {
|
||||
return summaryNodes;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ void printHeader(const std::vector<std::string>& keyList){
|
||||
std::cout << "--" << std::setw(14) << keyList[0];
|
||||
|
||||
for (size_t n= 1; n < keyList.size(); n++){
|
||||
std::cout << std::setw(16) << keyList[n];
|
||||
std::cout << std::setw(16) << keyList[n];
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
@@ -50,14 +50,14 @@ void printHeader(const std::vector<std::string>& keyList){
|
||||
std::string formatString(float data){
|
||||
|
||||
std::stringstream stream;
|
||||
|
||||
|
||||
if (std::fabs(data) < 1e6){
|
||||
stream << std::fixed << std::setw(16) << std::setprecision(6) << data;
|
||||
} else {
|
||||
stream << std::scientific << std::setw(16) << std::setprecision(6) << data;
|
||||
}
|
||||
|
||||
return stream.str();
|
||||
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
@@ -81,62 +81,67 @@ int main(int argc, char **argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int argOffset = optind;
|
||||
|
||||
std::string filename = argv[argOffset];
|
||||
Opm::EclIO::ESmry smryFile(filename);
|
||||
|
||||
|
||||
if (listKeys){
|
||||
auto list = smryFile.keywordList();
|
||||
|
||||
|
||||
for (size_t n = 0; n < list.size(); n++){
|
||||
std::cout << std::setw(20) << list[n];
|
||||
|
||||
|
||||
if (((n+1) % 5)==0){
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<std::string> smryList;
|
||||
for (int i=0; i<argc - argOffset-1;i++){
|
||||
smryList.push_back(argv[i+argOffset+1]);
|
||||
for (int i=0; i<argc - argOffset-1; i++) {
|
||||
if (smryFile.hasKey(argv[i+argOffset+1])) {
|
||||
smryList.push_back(argv[i+argOffset+1]);
|
||||
} else {
|
||||
auto list = smryFile.keywordList(argv[i+argOffset+1]);
|
||||
|
||||
if (list.size()==0) {
|
||||
std::string message = "Key " + std::string(argv[i+argOffset+1]) + " not found in summary file " + filename;
|
||||
std::cout << "\n!Runtime Error \n >> " << message << "\n\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for (auto vect : list)
|
||||
smryList.push_back(vect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (smryList.size()==0){
|
||||
std::string message = "No summary keys specified on command line";
|
||||
std::cout << "\n!Runtime Error \n >> " << message << "\n\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::vector<float>> smryData;
|
||||
|
||||
for (auto key : smryList){
|
||||
|
||||
if (!smryFile.hasKey(key)){
|
||||
std::string message = "Key " + key + " not found in summary file " + filename;
|
||||
std::cout << "\n!Runtime Error \n >> " << message << "\n\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for (auto key : smryList) {
|
||||
std::vector<float> vect = reportStepsOnly ? smryFile.get_at_rstep(key) : smryFile.get(key);
|
||||
|
||||
smryData.push_back(vect);
|
||||
}
|
||||
|
||||
|
||||
printHeader(smryList);
|
||||
|
||||
|
||||
for (size_t s=0; s<smryData[0].size(); s++){
|
||||
for (size_t n=0; n < smryData.size(); n++){
|
||||
std::cout << formatString(smryData[n][s]);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user