From 5306fb1db8d14192ec3d714481ecc1ec416548e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B8rn=20Skille?= Date: Wed, 10 Nov 2021 13:23:25 +0100 Subject: [PATCH] updates of ESmry and ExtESmry * add function for returning root name * add function for returning io (opening and loading) * rename member function LoadData() to loadData() --- opm/io/eclipse/ESmry.hpp | 9 +++++++-- opm/io/eclipse/ExtESmry.hpp | 5 +++++ src/opm/io/eclipse/ESmry.cpp | 28 ++++++++++++++++++++++---- src/opm/io/eclipse/ESmry_write_rsm.cpp | 2 +- src/opm/io/eclipse/ExtESmry.cpp | 19 +++++++++++++++++ test_util/EclRegressionTest.cpp | 4 ++-- tests/test_ESmry.cpp | 14 ++++++------- 7 files changed, 65 insertions(+), 16 deletions(-) diff --git a/opm/io/eclipse/ESmry.hpp b/opm/io/eclipse/ESmry.hpp index 8f8e3918e..c97826098 100644 --- a/opm/io/eclipse/ESmry.hpp +++ b/opm/io/eclipse/ESmry.hpp @@ -56,8 +56,8 @@ public: std::vector get_at_rstep(const SummaryNode& node) const; std::vector dates_at_rstep() const; - void LoadData(const std::vector& vectList) const; - void LoadData() const; + void loadData(const std::vector& vectList) const; + void loadData() const; bool make_esmry_file(); @@ -78,6 +78,8 @@ public: void write_rsm_file(std::optional = std::nullopt) const; bool all_steps_available(); + std::string rootname() { return inputFileName.stem(); } + std::tuple get_io_elapsed() const; private: std::filesystem::path inputFileName; @@ -110,6 +112,9 @@ private: time_point startdat; + mutable double m_io_opening; + mutable double m_io_loading; + std::vector checkForMultipleResultFiles(const std::filesystem::path& rootN, bool formatted) const; void getRstString(const std::vector& restartArray, diff --git a/opm/io/eclipse/ExtESmry.hpp b/opm/io/eclipse/ExtESmry.hpp index 13f9c972b..4869eaa58 100644 --- a/opm/io/eclipse/ExtESmry.hpp +++ b/opm/io/eclipse/ExtESmry.hpp @@ -67,6 +67,8 @@ public: std::vector dates(); bool all_steps_available(); + std::string rootname() { return m_inputFileName.stem(); } + std::tuple get_io_elapsed() const; private: std::filesystem::path m_inputFileName; @@ -94,6 +96,9 @@ private: time_point m_startdat; + double m_io_opening; + double m_io_loading; + uint64_t open_esmry(std::filesystem::path& inputFileName, LodsmryHeadType& lodsmry_head); void updatePathAndRootName(std::filesystem::path& dir, std::filesystem::path& rootN); diff --git a/src/opm/io/eclipse/ESmry.cpp b/src/opm/io/eclipse/ESmry.cpp index 4621f2a57..9418817eb 100644 --- a/src/opm/io/eclipse/ESmry.cpp +++ b/src/opm/io/eclipse/ESmry.cpp @@ -96,6 +96,11 @@ ESmry::ESmry(const std::string &filename, bool loadBaseRunData) : inputFileName { filename }, summaryNodes { } { + m_io_opening = 0.0; + m_io_loading = 0.0; + + auto start = std::chrono::system_clock::now(); + fromSingleRun = !loadBaseRunData; std::filesystem::path rootName = inputFileName.parent_path() / inputFileName.stem(); @@ -577,6 +582,9 @@ ESmry::ESmry(const std::string &filename, bool loadBaseRunData) : nTstep = timeStepList.size(); } + + std::chrono::duration elapsed_seconds = std::chrono::system_clock::now() - start; + m_io_opening += elapsed_seconds.count(); } void ESmry::read_ministeps_from_disk() @@ -660,8 +668,9 @@ std::string ESmry::read_string_from_disk(std::fstream& fileH, uint64_t size) con } -void ESmry::LoadData(const std::vector& vectList) const +void ESmry::loadData(const std::vector& vectList) const { + auto start = std::chrono::system_clock::now(); size_t nvect = vectList.size(); std::vector keywIndVect; @@ -758,6 +767,9 @@ void ESmry::LoadData(const std::vector& vectList) const for (const auto& ind : keywIndVect) vectorLoaded[ind] = true; + + std::chrono::duration elapsed_seconds = std::chrono::system_clock::now() - start; + m_io_loading += elapsed_seconds.count(); } std::vector ESmry::makeKeywPosVector(int specInd) const @@ -782,7 +794,7 @@ std::vector ESmry::makeKeywPosVector(int specInd) const return keywpos; } -void ESmry::LoadData() const +void ESmry::loadData() const { std::fstream fileH; @@ -1021,7 +1033,7 @@ bool ESmry::make_esmry_file() else is_rstep.push_back(0); - this->LoadData(); + this->loadData(); { Opm::TimeStampUTC ts( std::chrono::system_clock::to_time_t( startdat )); @@ -1286,7 +1298,7 @@ const std::vector& ESmry::get(const std::string& name) const int ind = std::distance(keyword.begin(), it); if (!vectorLoaded[ind]){ - LoadData({name}); + loadData({name}); vectorLoaded[ind]=true; } @@ -1353,4 +1365,12 @@ std::vector ESmry::dates_at_rstep() const { const auto& full_vector = this->dates(); return this->rstep_vector(full_vector); } + +std::tuple ESmry::get_io_elapsed() const +{ + std::tuple duration = std::make_tuple(m_io_opening, m_io_loading); + return duration; +} + + }} // namespace Opm::EclIO diff --git a/src/opm/io/eclipse/ESmry_write_rsm.cpp b/src/opm/io/eclipse/ESmry_write_rsm.cpp index e1338913a..e46eb4480 100644 --- a/src/opm/io/eclipse/ESmry_write_rsm.cpp +++ b/src/opm/io/eclipse/ESmry_write_rsm.cpp @@ -245,7 +245,7 @@ void ESmry::write_rsm(std::ostream& os) const { data_vector_blocks.emplace_back(data_vectors.begin() + i, data_vectors.begin() + last); } - this->LoadData(); + this->loadData(); std::vector time_column; if (this->hasKey("DAY") && this->hasKey("MONTH") && this->hasKey("YEAR")) { write_dates = true; diff --git a/src/opm/io/eclipse/ExtESmry.cpp b/src/opm/io/eclipse/ExtESmry.cpp index 748117c31..682733539 100644 --- a/src/opm/io/eclipse/ExtESmry.cpp +++ b/src/opm/io/eclipse/ExtESmry.cpp @@ -93,6 +93,11 @@ ExtESmry::ExtESmry(const std::string &filename, bool loadBaseRunData) : m_inputFileName { filename }, m_loadBaseRun(loadBaseRunData) { + m_io_opening = 0.0; + m_io_loading = 0.0; + + auto start = std::chrono::system_clock::now(); + if (m_inputFileName.extension()=="") m_inputFileName+=".ESMRY"; @@ -222,6 +227,9 @@ ExtESmry::ExtESmry(const std::string &filename, bool loadBaseRunData) : for (size_t m = 0; m < m_rstep.size(); m++) if (m_rstep[m] == 1) m_seqIndex.push_back(m); + + std::chrono::duration elapsed_seconds = std::chrono::system_clock::now() - start; + m_io_opening += elapsed_seconds.count(); } @@ -357,6 +365,8 @@ void ExtESmry::updatePathAndRootName(std::filesystem::path& dir, std::filesystem void ExtESmry::loadData(const std::vector& stringVect) { + auto start = std::chrono::system_clock::now(); + std::vector keyIndexVect; for (const auto& key: stringVect) @@ -419,6 +429,9 @@ void ExtESmry::loadData(const std::vector& stringVect) for (auto kind : keyIndexVect) m_vectorLoaded[kind] = true; + + std::chrono::duration elapsed_seconds = std::chrono::system_clock::now() - start; + m_io_loading += elapsed_seconds.count(); } void ExtESmry::loadData() @@ -466,6 +479,12 @@ bool ExtESmry::hasKey(const std::string &key) const return std::find(m_keyword.begin(), m_keyword.end(), key) != m_keyword.end(); } +std::tuple ExtESmry::get_io_elapsed() const +{ + std::tuple duration = std::make_tuple(m_io_opening, m_io_loading); + return duration; +} + }} // namespace Opm::ecl diff --git a/test_util/EclRegressionTest.cpp b/test_util/EclRegressionTest.cpp index a160fbea1..3b4fdb1f6 100644 --- a/test_util/EclRegressionTest.cpp +++ b/test_util/EclRegressionTest.cpp @@ -883,11 +883,11 @@ void ECLRegressionTest::results_smry() if (foundSmspec1 && foundSmspec2) { ESmry smry1(fileName1, loadBaseRunData); - smry1.LoadData(); + smry1.loadData(); std::cout << "\nLoading summary file " << fileName1 << " .... done" << std::endl; ESmry smry2(fileName2, loadBaseRunData); - smry2.LoadData(); + smry2.loadData(); std::cout << "\nLoading summary file " << fileName2 << " .... done" << std::endl; deviations.clear(); diff --git a/tests/test_ESmry.cpp b/tests/test_ESmry.cpp index 39a5b9ce8..8a0da9cb1 100644 --- a/tests/test_ESmry.cpp +++ b/tests/test_ESmry.cpp @@ -155,7 +155,7 @@ BOOST_AUTO_TEST_CASE(TestESmry_1) { getRefSmryVect(time_ref, wgpr_prod_ref, wbhp_prod_ref, wbhp_inj_ref,fgor_ref, bpr_111_ref, bpr_10103_ref); ESmry smry1("SPE1CASE1.SMSPEC"); - smry1.LoadData(); + smry1.loadData(); std::vector smryVect = smry1.get("TIME"); BOOST_CHECK_EQUAL(smryVect==time_ref, true); @@ -232,7 +232,7 @@ BOOST_AUTO_TEST_CASE(TestESmry_2) { // will be loaded. No data from base run (SPE1CASE1 in this case) ESmry smry1("SPE1CASE1_RST60.SMSPEC"); // equivalent to smry1("SPE1CASE1_RST60.SMSPEC",false) - smry1.LoadData(); + smry1.loadData(); std::vector smryVect = smry1.get("TIME"); std::vector time_ref_rst60 = getFrom(time_ref,63); @@ -310,7 +310,7 @@ BOOST_AUTO_TEST_CASE(TestESmry_3) { // vectors should be equal to reference vectors (from SPE1CASE1) ESmry smry1("SPE1CASE1_RST60.SMSPEC",true); - smry1.LoadData(); + smry1.loadData(); std::vector smryVect = smry1.get("TIME"); BOOST_CHECK_EQUAL(smryVect==time_ref, true); @@ -357,7 +357,7 @@ BOOST_AUTO_TEST_CASE(TestESmry_4) { std::vector time_ref = {31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365, 396, 424, 455, 485, 516, 546, 577, 608, 638, 669, 699, 730, 761, 789, 820, 850, 881, 911, 942, 973, 1003, 1034, 1064, 1095, 1126, 1154, 1185, 1215, 1246, 1276, 1307, 1338, 1368, 1399, 1429, 1460, 1491, 1519, 1550, 1580, 1611, 1641, 1672, 1703, 1733, 1764, 1794, 1825, 1856, 1884, 1915, 1945, 1976, 2006, 2037, 2068, 2098, 2129, 2159, 2190, 2221, 2249, 2280, 2310, 2341, 2371, 2402, 2433, 2463, 2494, 2524, 2555, 2586, 2614, 2645, 2675, 2706, 2736, 2767, 2798, 2828, 2859, 2889, 2920, 2951, 2979, 3010, 3040, 3071, 3101, 3132, 3163, 3193, 3224, 3254, 3285, 3316, 3344, 3375, 3405, 3436, 3466, 3497, 3528, 3558, 3589, 3619, 3650}; ESmry smry1("SPE1CASE1.SMSPEC"); - smry1.LoadData(); + smry1.loadData(); std::vector smryVect = smry1.get("TIME"); std::vector smryVect_rstep = smry1.get_at_rstep("TIME"); @@ -377,7 +377,7 @@ BOOST_AUTO_TEST_CASE(TestESmry_5) { // array NAMES (of type C0NN) in IX smspec files ESmry smry1("MODEL1_IX.SMSPEC"); - smry1.LoadData(); + smry1.loadData(); std::vector report_timesteps = {31.0, 60.0, 91.0, 121.0, 152.0, 182.0, 213.0, 244.0, 274.0, 305.0, 335.0, 364.0}; @@ -400,7 +400,7 @@ BOOST_AUTO_TEST_CASE(TestESmry_5) { namespace fs = std::filesystem; BOOST_AUTO_TEST_CASE(TestCreateRSM) { ESmry smry1("SPE1CASE1.SMSPEC"); - smry1.LoadData(); + smry1.loadData(); { WorkArea work; @@ -414,7 +414,7 @@ BOOST_AUTO_TEST_CASE(TestCreateRSM) { BOOST_AUTO_TEST_CASE(TestUnits) { ESmry smry("SPE1CASE1.SMSPEC"); - smry.LoadData(); + smry.loadData(); BOOST_CHECK_THROW( smry.get_unit("NO_SUCH_KEY"), std::out_of_range); BOOST_CHECK_EQUAL( smry.get_unit("TIME"), "DAYS");