From 173a404725f7d2fe45756a28f6f57d9225a09829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Thu, 9 Sep 2021 11:45:45 +0200 Subject: [PATCH 1/2] Sort Includes in Schedule.hpp --- .../EclipseState/Schedule/Schedule.hpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp index 5d0dfe712..6a03a5a7d 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp @@ -19,29 +19,37 @@ #ifndef SCHEDULE_HPP #define SCHEDULE_HPP +#include #include #include #include +#include +#include #include +#include +#include -#include +#include + +#include #include #include #include #include #include -#include #include +#include +#include +#include #include #include #include #include #include -#include -#include -#include +#include +#include namespace Opm { @@ -57,6 +65,7 @@ namespace Opm class SummaryState; class ErrorGuard; class UDQConfig; + namespace RestartIO { struct RstState; } From 98388a7a7e7dbc9745e89f2908e90b242d5c3293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Thu, 9 Sep 2021 11:48:21 +0200 Subject: [PATCH 2/2] Initialize RPTONLY/SUMTHIN Settings From SUMMARY Section --- .../EclipseState/Schedule/Schedule.hpp | 2 + .../EclipseState/Schedule/Schedule.cpp | 38 ++++- tests/parser/ScheduleTests.cpp | 143 ++++++++++++++++++ 3 files changed, 179 insertions(+), 4 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp index 6a03a5a7d..a381065eb 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp @@ -78,6 +78,8 @@ namespace Opm Runspec m_runspec; RSTConfig rst_config; std::optional output_interval; + double sumthin{-1.0}; + bool rptonly{false}; ScheduleStatic() = default; diff --git a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp index f1b3dabda..83b866776 100644 --- a/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp +++ b/src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -84,9 +85,6 @@ #include "Well/injection.hpp" #include "MSW/Compsegs.hpp" -namespace Opm { - - namespace { bool name_match(const std::string& pattern, const std::string& name) { @@ -94,8 +92,36 @@ namespace { return (fnmatch(pattern.c_str(), name.c_str(), flags) == 0); } + double sumthin_summary_section(const Opm::SUMMARYSection& section) { + const auto entries = section.getKeywordList(); + + // Care only about the last SUMTHIN entry in the SUMMARY + // section if keyword is present here at all. + return entries.empty() + ? -1.0 // (<= 0.0) + : entries.back()->getRecord(0).getItem(0).getSIDouble(0); + } + + bool rptonly_summary_section(const Opm::SUMMARYSection& section) { + auto rptonly = false; + + using On = Opm::ParserKeywords::RPTONLY; + using Off = Opm::ParserKeywords::RPTONLYO; + + // Last on/off keyword entry "wins". + for (const auto& keyword : section) { + if (keyword.name() == On::keywordName) + rptonly = true; + else if (keyword.name() == Off::keywordName) + rptonly = false; + } + + return rptonly; + } } +namespace Opm { + ScheduleStatic::ScheduleStatic(std::shared_ptr python_handle, const ScheduleRestartInfo& restart_info, const Deck& deck, @@ -110,7 +136,9 @@ namespace { m_unit_system( deck.getActiveUnitSystem() ), m_runspec( runspec ), rst_config( SOLUTIONSection(deck), parseContext, errors ), - output_interval(output_interval_) + output_interval(output_interval_), + sumthin(sumthin_summary_section(SUMMARYSection{ deck })), + rptonly(rptonly_summary_section(SUMMARYSection{ deck })) { } @@ -1786,6 +1814,8 @@ void Schedule::create_first(const time_point& start_time, const std::optionalm_static.rst_config ) ); sched_state.network_balance.update( Network::Balance() ); + sched_state.update_sumthin(this->m_static.sumthin); + sched_state.rptonly(this->m_static.rptonly); //sched_state.update_date( start_time ); this->addGroup("FIELD", 0); } diff --git a/tests/parser/ScheduleTests.cpp b/tests/parser/ScheduleTests.cpp index 677c649cd..6615993d4 100644 --- a/tests/parser/ScheduleTests.cpp +++ b/tests/parser/ScheduleTests.cpp @@ -4618,3 +4618,146 @@ WCONPROD } +BOOST_AUTO_TEST_CASE(SUMTHIN_IN_SUMMARY) { + const auto deck = Parser{}.parseString(R"(RUNSPEC +DIMENS + 10 10 10 / + +START -- 0 +10 MAI 2007 / + +GRID +DXV +10*100.0 / +DYV +10*100.0 / +DZV +10*10.0 / +DEPTHZ +121*2000.0 / + +SUMMARY +SUMTHIN +10.0 / + +SCHEDULE +WELSPECS + 'W_1' 'OP' 30 37 3.33 'OIL' 7* / +/ +DATES -- 1, 2, 3 + 10 'JUN' 2007 / + 10 JLY 2007 / + 10 AUG 2007 / +/ +SUMTHIN +100.0 / +WELSPECS + 'WX2' 'OP' 30 37 3.33 'OIL' 7* / + 'W_3' 'OP' 20 51 3.92 'OIL' 7* / +/ +DATES -- 4,5 + 10 SEP 2007 / + 10 OCT 2007 / +/ +SUMTHIN +0.0 / +DATES -- 6,7 + 10 SEP 2007 / + 10 OCT 2007 / +/ +END +)"); + + const auto es = EclipseState { deck }; + const auto sched = Schedule { deck, es, std::make_shared() }; + + BOOST_REQUIRE_MESSAGE(sched[0].sumthin().has_value(), + R"("SUMTHIN" must be configured on report step 1)"); + + BOOST_CHECK_CLOSE(sched[0].sumthin().value(), 10.0 * 86'400.0, 1.0e-10); + + BOOST_REQUIRE_MESSAGE(sched[1].sumthin().has_value(), + R"("SUMTHIN" must be configured on report step 2)"); + + BOOST_CHECK_CLOSE(sched[1].sumthin().value(), 10.0 * 86'400.0, 1.0e-10); + + BOOST_REQUIRE_MESSAGE(sched[2].sumthin().has_value(), + R"("SUMTHIN" must be configured on report step 3)"); + + BOOST_CHECK_CLOSE(sched[2].sumthin().value(), 10.0 * 86'400.0, 1.0e-10); + + BOOST_REQUIRE_MESSAGE(sched[3].sumthin().has_value(), + R"("SUMTHIN" must be configured on report step 4)"); + + BOOST_CHECK_CLOSE(sched[3].sumthin().value(), 100.0 * 86'400.0, 1.0e-10); + + BOOST_REQUIRE_MESSAGE(sched[4].sumthin().has_value(), + R"("SUMTHIN" must be configured on report step 5)"); + + BOOST_CHECK_CLOSE(sched[4].sumthin().value(), 100.0 * 86'400.0, 1.0e-10); + + BOOST_REQUIRE_MESSAGE(!sched[5].sumthin().has_value(), + R"("SUMTHIN" must NOT be configured on report step 6)"); + + BOOST_CHECK_THROW(sched[5].sumthin().value(), std::bad_optional_access); + + BOOST_REQUIRE_MESSAGE(!sched[6].sumthin().has_value(), + R"("SUMTHIN" must NOT be configured on report step 7)"); +} + +BOOST_AUTO_TEST_CASE(RPTONLY_IN_SUMMARY) { + const auto deck = Parser{}.parseString(R"(RUNSPEC +DIMENS + 10 10 10 / + +START -- 0 +10 MAI 2007 / + +GRID +DXV +10*100.0 / +DYV +10*100.0 / +DZV +10*10.0 / +DEPTHZ +121*2000.0 / + +SUMMARY +RPTONLY + +SCHEDULE +WELSPECS + 'W_1' 'OP' 30 37 3.33 'OIL' 7* / +/ +DATES -- 1, 2 + 10 'JUN' 2007 / + 10 JLY 2007 / +/ +WELSPECS + 'WX2' 'OP' 30 37 3.33 'OIL' 7* / + 'W_3' 'OP' 20 51 3.92 'OIL' 7* / +/ +RPTONLYO +DATES -- 3, 4 + 10 AUG 2007 / + 10 SEP 2007 / +/ +END +)"); + + const auto es = EclipseState { deck }; + const auto sched = Schedule { deck, es, std::make_shared() }; + + BOOST_CHECK_MESSAGE(sched[0].rptonly(), + R"("RPTONLY" must be configured on report step 1)"); + + BOOST_CHECK_MESSAGE(sched[1].rptonly(), + R"("RPTONLY" must be configured on report step 2)"); + + BOOST_CHECK_MESSAGE(! sched[2].rptonly(), + R"("RPTONLY" must NOT be configured on report step 3)"); + + BOOST_CHECK_MESSAGE(! sched[3].rptonly(), + R"("RPTONLY" must NOT be configured on report step 4)"); +}