From 06fd01c6bacf4ac90e0705d8cf03302c9ae5667d Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 11 Oct 2021 11:24:29 +0200 Subject: [PATCH] Create WellTestState object from restart file --- .../Schedule/Well/WellTestState.hpp | 7 +++++ .../Schedule/Well/WellTestState.cpp | 30 +++++++++++++++++-- tests/test_AggregateWellData.cpp | 4 ++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.hpp b/opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.hpp index fad6a5265..ac4820080 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.hpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -102,6 +103,7 @@ public: WTestWell(const std::string& wname, WellTestConfig::Reason reason_, double last_test); int int_reason() const; + static WellTestConfig::Reason inverse_ecl_reason(int ecl_reason); bool operator==(const WTestWell& other) const { return this->name == other.name && @@ -187,6 +189,11 @@ public: buffer.read(this->num_attempt); } }; + + WellTestState() = default; + WellTestState(std::time_t start_time, const RestartIO::RstState& rst_state); + + std::vector test_wells(const WellTestConfig& config, double sim_time); /* diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.cpp index d67c5b96e..c3307f6ed 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.cpp @@ -16,10 +16,11 @@ You should have received a copy of the GNU General Public License along with OPM. If not, see . */ -#include #include - #include +#include +#include + #include #include #include @@ -47,6 +48,31 @@ namespace Opm { } } + WellTestConfig::Reason WellTestState::WTestWell::inverse_ecl_reason(int ecl_reason) { + switch (ecl_reason) { + case WTest::EclCloseReason::PHYSICAL: return WellTestConfig::Reason::PHYSICAL; + case WTest::EclCloseReason::ECONOMIC: return WellTestConfig::Reason::ECONOMIC; + case WTest::EclCloseReason::GCON: return WellTestConfig::Reason::GROUP; + case WTest::EclCloseReason::THPLimit: return WellTestConfig::Reason::THP_DESIGN; + default: + throw std::logic_error("Not yet handled WTEST config alternative"); + } + } + + + WellTestState::WellTestState(std::time_t start_time, const RestartIO::RstState& rst_state) { + // Dont know whether the closing time of the closed well is stored in + // the restart file, here we just initialize the well close time to the + // time of the restart. + auto elapsed = std::difftime(start_time, rst_state.header.sim_time()); + for (const auto& well : rst_state.wells) { + if (well.wtest_close_reason != 0) + this->close_well(well.name, + WellTestState::WTestWell::inverse_ecl_reason(well.wtest_close_reason), + elapsed); + } + } + WellTestState::WTestWell WellTestState::WTestWell::serializeObject() { return WTestWell("Name", WellTestConfig::Reason::GROUP, 123.45); diff --git a/tests/test_AggregateWellData.cpp b/tests/test_AggregateWellData.cpp index 6aee9ab12..40277eba4 100644 --- a/tests/test_AggregateWellData.cpp +++ b/tests/test_AggregateWellData.cpp @@ -817,10 +817,12 @@ BOOST_AUTO_TEST_CASE (Declared_Well_Data) { Opm::WellTestConfig wtest_config{rst_state, rptStep}; - Opm::WellTestState wtest_state; + Opm::WellTestState ws{simCase.sched.runspec().start_time(), rst_state}; BOOST_CHECK(wtest_config.has("OP_1", Opm::WellTestConfig::Reason::PHYSICAL)); BOOST_CHECK(wtest_config.has("OP_1", Opm::WellTestConfig::Reason::GROUP)); BOOST_CHECK(wtest_config.has("OP_1", Opm::WellTestConfig::Reason::THP_DESIGN)); + + BOOST_CHECK(ws.well_is_closed("OP_1")); } }