Merge pull request #2793 from atgeirr/backport-of-pr-2761

Backport of pr 2761
This commit is contained in:
Atgeirr Flø Rasmussen 2021-10-28 10:06:14 +02:00 committed by GitHub
commit d27d01a8a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 193 additions and 9 deletions

View File

@ -19,29 +19,37 @@
#ifndef SCHEDULE_HPP
#define SCHEDULE_HPP
#include <cstddef>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <opm/parser/eclipse/Python/Python.hpp>
#include <time.h>
#include <opm/parser/eclipse/EclipseState/Runspec.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/GasLiftOpt.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Group/Group.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Group/GTNode.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Group/GuideRateConfig.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/MessageLimits.hpp>
#include <opm/parser/eclipse/EclipseState/Runspec.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Network/ExtNetwork.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/RPTConfig.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleDeck.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Well/PAvg.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Well/Well.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Well/WellTestConfig.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Well/WellMatcher.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/WriteRestartFileEvents.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleDeck.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/RPTConfig.hpp>
#include <opm/parser/eclipse/Python/Python.hpp>
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
namespace Opm
{
@ -57,6 +65,7 @@ namespace Opm
class SummaryState;
class ErrorGuard;
class UDQConfig;
namespace RestartIO { struct RstState; }
@ -69,6 +78,8 @@ namespace Opm
Runspec m_runspec;
RSTConfig rst_config;
std::optional<int> output_interval;
double sumthin{-1.0};
bool rptonly{false};
ScheduleStatic() = default;

View File

@ -48,6 +48,7 @@
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
#include <opm/parser/eclipse/Parser/ParserKeywords/E.hpp>
#include <opm/parser/eclipse/Parser/ParserKeywords/P.hpp>
#include <opm/parser/eclipse/Parser/ParserKeywords/R.hpp>
#include <opm/parser/eclipse/Parser/ParserKeywords/S.hpp>
#include <opm/parser/eclipse/Parser/ParserKeywords/W.hpp>
@ -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<Opm::ParserKeywords::SUMTHIN>();
// 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<const Python> 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::optional<ti
sched_state.rft_config.update( RFTConfig() );
sched_state.rst_config.update( RSTConfig::first( this->m_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);
}

View File

@ -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<const Python>() };
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<const Python>() };
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)");
}