Refactor serialization of std::shared_ptr<> members in ScheduleState
This commit is contained in:
@@ -369,6 +369,7 @@ if(ENABLE_ECL_INPUT)
|
||||
tests/parser/RockTableTests.cpp
|
||||
tests/parser/RunspecTests.cpp
|
||||
tests/parser/SaltTableTests.cpp
|
||||
tests/parser/ScheduleSerializeTest.cpp
|
||||
tests/parser/ScheduleRestartTests.cpp
|
||||
tests/parser/ScheduleTests.cpp
|
||||
tests/parser/SectionTests.cpp
|
||||
|
||||
@@ -349,8 +349,94 @@ namespace Opm
|
||||
}
|
||||
serializer.vector(snapshots);
|
||||
m_static.serializeOp(serializer);
|
||||
|
||||
pack_unpack<WellTestConfig, Serializer>(serializer,
|
||||
std::mem_fn(&ScheduleState::wtest_config),
|
||||
std::mem_fn(&ScheduleState::update_wtest_config));
|
||||
|
||||
pack_unpack<GConSale, Serializer>(serializer,
|
||||
std::mem_fn(&ScheduleState::gconsale),
|
||||
std::mem_fn(&ScheduleState::update_gconsale));
|
||||
|
||||
pack_unpack<GConSump, Serializer>(serializer,
|
||||
std::mem_fn(&ScheduleState::gconsump),
|
||||
std::mem_fn(&ScheduleState::update_gconsump));
|
||||
|
||||
pack_unpack<WListManager, Serializer>(serializer,
|
||||
std::mem_fn(&ScheduleState::wlist_manager),
|
||||
std::mem_fn(&ScheduleState::update_wlist_manager));
|
||||
|
||||
pack_unpack<Network::ExtNetwork, Serializer>(serializer,
|
||||
std::mem_fn(&ScheduleState::network),
|
||||
std::mem_fn(&ScheduleState::update_network));
|
||||
|
||||
pack_unpack<RPTConfig, Serializer>(serializer,
|
||||
std::mem_fn(&ScheduleState::rpt_config),
|
||||
std::mem_fn(&ScheduleState::update_rpt_config));
|
||||
|
||||
pack_unpack<Action::Actions, Serializer>(serializer,
|
||||
std::mem_fn(&ScheduleState::actions),
|
||||
std::mem_fn(&ScheduleState::update_actions));
|
||||
|
||||
pack_unpack<UDQActive, Serializer>(serializer,
|
||||
std::mem_fn(&ScheduleState::udq_active),
|
||||
std::mem_fn(&ScheduleState::update_udq_active));
|
||||
}
|
||||
|
||||
template <typename T, class Serializer>
|
||||
void pack_unpack(Serializer& serializer,
|
||||
const std::function<T(const ScheduleState &)>& get,
|
||||
const std::function<void(ScheduleState &, const T& )>& set) {
|
||||
|
||||
std::vector<T> value_list;
|
||||
std::vector<std::size_t> index_list;
|
||||
|
||||
if (serializer.isSerializing())
|
||||
pack_state<T>(value_list, index_list, get);
|
||||
|
||||
serializer.vector(value_list);
|
||||
serializer.template vector<std::size_t, false>(index_list);
|
||||
|
||||
if (!serializer.isSerializing())
|
||||
unpack_state<T>(value_list, index_list, set);
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void pack_state(std::vector<T>& value_list, std::vector<std::size_t>& index_list, const std::function<T(const ScheduleState &)>& get) {
|
||||
if (this->snapshots.empty())
|
||||
return;
|
||||
|
||||
value_list.push_back( get( this->snapshots[0] ));
|
||||
index_list.push_back( 0 );
|
||||
for (std::size_t index = 1; index < this->snapshots.size(); index++) {
|
||||
const auto& value = get( this->snapshots[index] );
|
||||
if (!(value == value_list.back())) {
|
||||
value_list.push_back( value );
|
||||
index_list.push_back( index );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void unpack_state(const std::vector<T>& value_list, const std::vector<std::size_t>& index_list, const std::function<void(ScheduleState &, const T& )>& set) {
|
||||
std::size_t unique_index = 0;
|
||||
while (unique_index < value_list.size()) {
|
||||
const auto& value = value_list[unique_index];
|
||||
const auto& first_index = index_list[unique_index];
|
||||
auto last_index = this->snapshots.size();
|
||||
if (unique_index < (value_list.size() - 1))
|
||||
last_index = index_list[unique_index + 1];
|
||||
|
||||
for (std::size_t index=first_index; index < last_index; index++)
|
||||
set( this->snapshots[index], value );
|
||||
|
||||
unique_index++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
template<class Key, class Value> using Map2 = std::map<Key,Value>;
|
||||
ScheduleStatic m_static;
|
||||
@@ -440,6 +526,7 @@ namespace Opm
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static std::string formatDate(std::time_t t);
|
||||
std::string simulationDays(std::size_t currentStep) const;
|
||||
|
||||
|
||||
@@ -153,16 +153,8 @@ namespace Opm {
|
||||
m_message_limits.serializeOp(serializer);
|
||||
serializer(m_well_order);
|
||||
serializer(m_whistctl_mode);
|
||||
serializer(m_wtest_config);
|
||||
serializer(m_gconsale);
|
||||
serializer(m_gconsump);
|
||||
serializer(m_wlist_manager);
|
||||
serializer(m_network);
|
||||
serializer(m_rptconfig);
|
||||
serializer.map(m_vfpprod);
|
||||
serializer.map(m_vfpinj);
|
||||
serializer(m_actions);
|
||||
serializer(m_udq_active);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,367 @@
|
||||
/*
|
||||
Copyright 2021 Equinor ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MODULE ScheduleTests
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
||||
#include <opm/common/utility/TimeService.hpp>
|
||||
#include <opm/common/utility/OpmInputError.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Python/Python.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Runspec.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleState.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/RFTConfig.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/OilVaporizationProperties.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Well/WellConnections.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Well/Well.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/GasLiftOpt.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Well/WellMatcher.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Well/PAvg.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
|
||||
#include <opm/parser/eclipse/Units/Dimension.hpp>
|
||||
#include <opm/parser/eclipse/Units/UnitSystem.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Well/WellProductionProperties.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Well/WellInjectionProperties.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Group/GuideRateConfig.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Group/GuideRate.hpp>
|
||||
|
||||
using namespace Opm;
|
||||
|
||||
std::string deck0 = R"(
|
||||
START -- 0
|
||||
10 MAI 2007 /
|
||||
SCHEDULE
|
||||
|
||||
DATES -- 1
|
||||
10 JUN 2007 /
|
||||
/
|
||||
|
||||
DATES -- 2
|
||||
15 JUN 2007 /
|
||||
/
|
||||
|
||||
DATES -- 3
|
||||
20 JUN 2007 /
|
||||
/
|
||||
|
||||
DATES -- 4
|
||||
10 JUL 2007 /
|
||||
/
|
||||
|
||||
|
||||
DATES -- 5
|
||||
10 AUG 2007 /
|
||||
/
|
||||
|
||||
|
||||
DATES -- 6
|
||||
10 SEP 2007 /
|
||||
/
|
||||
|
||||
DATES -- 7
|
||||
10 NOV 2007 /
|
||||
/
|
||||
|
||||
)";
|
||||
|
||||
|
||||
|
||||
std::string WTEST_deck = R"(
|
||||
START -- 0
|
||||
10 MAI 2007 /
|
||||
SCHEDULE
|
||||
WELSPECS
|
||||
'DEFAULT' 'OP' 30 37 3.33 'OIL' 7*/
|
||||
'ALLOW' 'OP' 30 37 3.33 'OIL' 3* YES /
|
||||
'BAN' 'OP' 20 51 3.92 'OIL' 3* NO /
|
||||
'W1' 'OP' 20 51 3.92 'OIL' 3* NO /
|
||||
'W2' 'OP' 20 51 3.92 'OIL' 3* NO /
|
||||
'W3' 'OP' 20 51 3.92 'OIL' 3* NO /
|
||||
/
|
||||
|
||||
COMPDAT
|
||||
'BAN' 1 1 1 1 'OPEN' 1* 1.168 0.311 107.872 1* 1* 'Z' 21.925 /
|
||||
/
|
||||
|
||||
WCONHIST
|
||||
'BAN' 'OPEN' 'RESV' 0.000 0.000 0.000 5* /
|
||||
/
|
||||
|
||||
WTEST
|
||||
'ALLOW' 1 'PE' /
|
||||
/
|
||||
|
||||
WLIST
|
||||
'*ILIST' 'NEW' W1 /
|
||||
'*ILIST' 'ADD' W2 /
|
||||
/
|
||||
|
||||
DATES -- 1
|
||||
10 JUN 2007 /
|
||||
/
|
||||
|
||||
DATES -- 2
|
||||
15 JUN 2007 /
|
||||
/
|
||||
|
||||
DATES -- 3
|
||||
20 JUN 2007 /
|
||||
/
|
||||
|
||||
|
||||
WTEST
|
||||
'ALLOW' 1 '' /
|
||||
'BAN' 1 'DGC' /
|
||||
/
|
||||
|
||||
WLIST
|
||||
'*ILIST' 'ADD' W3 /
|
||||
/
|
||||
|
||||
|
||||
WCONHIST
|
||||
'BAN' 'OPEN' 'RESV' 1.000 0.000 0.000 5* /
|
||||
/
|
||||
|
||||
DATES -- 4
|
||||
10 JUL 2007 /
|
||||
/
|
||||
|
||||
WELSPECS
|
||||
'I1' 'OP' 20 51 3.92 'OIL' 3* NO /
|
||||
'I2' 'OP' 20 51 3.92 'OIL' 3* NO /
|
||||
'I3' 'OP' 20 51 3.92 'OIL' 3* NO /
|
||||
/
|
||||
|
||||
|
||||
WCONPROD
|
||||
'BAN' 'OPEN' 'ORAT' 0.000 0.000 0.000 5* /
|
||||
/
|
||||
|
||||
|
||||
DATES -- 5
|
||||
10 AUG 2007 /
|
||||
/
|
||||
|
||||
WCONINJH
|
||||
'BAN' 'WATER' 1* 0 /
|
||||
/
|
||||
|
||||
DATES -- 6
|
||||
10 SEP 2007 /
|
||||
/
|
||||
|
||||
WELOPEN
|
||||
'BAN' OPEN /
|
||||
/
|
||||
|
||||
DATES -- 7
|
||||
10 NOV 2007 /
|
||||
/
|
||||
|
||||
WCONINJH
|
||||
'BAN' 'WATER' 1* 1.0 /
|
||||
/
|
||||
)";
|
||||
|
||||
std::string GCONSALE_deck = R"(
|
||||
START -- 0
|
||||
10 MAI 2007 /
|
||||
SCHEDULE
|
||||
|
||||
GRUPTREE
|
||||
'G1' 'FIELD' /
|
||||
'G2' 'FIELD' /
|
||||
/
|
||||
|
||||
GCONSALE
|
||||
'G1' 50000 55000 45000 WELL /
|
||||
/
|
||||
|
||||
GCONSUMP
|
||||
'G1' 20 50 'a_node' /
|
||||
'G2' 30 60 /
|
||||
/
|
||||
|
||||
DATES -- 1
|
||||
10 JUN 2007 /
|
||||
/
|
||||
|
||||
DATES -- 2
|
||||
15 JUN 2007 /
|
||||
/
|
||||
|
||||
DATES -- 3
|
||||
20 JUN 2007 /
|
||||
/
|
||||
|
||||
GCONSALE
|
||||
'G1' 12345 12345 12345 WELL /
|
||||
/
|
||||
|
||||
GCONSUMP
|
||||
'G1' 10 77 'b_node' /
|
||||
'G2' 10 77 /
|
||||
/
|
||||
|
||||
DATES -- 4
|
||||
10 JUL 2007 /
|
||||
/
|
||||
|
||||
DATES -- 5
|
||||
10 AUG 2007 /
|
||||
/
|
||||
|
||||
DATES -- 6
|
||||
10 SEP 2007 /
|
||||
/
|
||||
|
||||
DATES -- 7
|
||||
10 NOV 2007 /
|
||||
/
|
||||
|
||||
|
||||
|
||||
)";
|
||||
|
||||
static Schedule make_schedule(const std::string& deck_string) {
|
||||
const auto& deck = Parser{}.parseString(deck_string);
|
||||
auto python = std::make_shared<Python>();
|
||||
EclipseGrid grid(10,10,10);
|
||||
TableManager table ( deck );
|
||||
FieldPropsManager fp( deck, Phases{true, true, true}, grid, table);
|
||||
Runspec runspec (deck);
|
||||
return Schedule(deck, grid , fp, runspec, python);
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SerializeWTest) {
|
||||
auto sched = make_schedule(WTEST_deck);
|
||||
auto sched0 = make_schedule(deck0);
|
||||
auto wtest1 = sched[0].wtest_config();
|
||||
auto wtest2 = sched[3].wtest_config();
|
||||
|
||||
{
|
||||
std::vector<Opm::WellTestConfig> value_list;
|
||||
std::vector<std::size_t> index_list;
|
||||
sched.pack_state<Opm::WellTestConfig>( value_list, index_list, std::mem_fn( &ScheduleState::wtest_config ));
|
||||
BOOST_CHECK_EQUAL( value_list.size(), 2 );
|
||||
|
||||
sched0.unpack_state<Opm::WellTestConfig>( value_list, index_list, std::mem_fn( &ScheduleState::update_wtest_config ));
|
||||
}
|
||||
BOOST_CHECK( wtest1 == sched0[0].wtest_config());
|
||||
BOOST_CHECK( wtest1 == sched0[1].wtest_config());
|
||||
BOOST_CHECK( wtest1 == sched0[2].wtest_config());
|
||||
|
||||
BOOST_CHECK( wtest2 == sched0[3].wtest_config());
|
||||
BOOST_CHECK( wtest2 == sched0[4].wtest_config());
|
||||
BOOST_CHECK( wtest2 == sched0[5].wtest_config());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SerializeWList) {
|
||||
auto sched = make_schedule(WTEST_deck);
|
||||
auto sched0 = make_schedule(deck0);
|
||||
auto wlm1 = sched[0].wlist_manager();
|
||||
auto wlm2 = sched[3].wlist_manager();
|
||||
|
||||
{
|
||||
std::vector<Opm::WListManager> value_list;
|
||||
std::vector<std::size_t> index_list;
|
||||
sched.pack_state<Opm::WListManager>( value_list, index_list, std::mem_fn( &ScheduleState::wlist_manager ));
|
||||
BOOST_CHECK_EQUAL( value_list.size(), 2 );
|
||||
sched0.unpack_state<Opm::WListManager>( value_list, index_list, std::mem_fn(&ScheduleState::update_wlist_manager) );
|
||||
}
|
||||
BOOST_CHECK( wlm1 == sched0[0].wlist_manager());
|
||||
BOOST_CHECK( wlm1 == sched0[1].wlist_manager());
|
||||
BOOST_CHECK( wlm1 == sched0[2].wlist_manager());
|
||||
|
||||
BOOST_CHECK( wlm2 == sched0[3].wlist_manager());
|
||||
BOOST_CHECK( wlm2 == sched0[4].wlist_manager());
|
||||
BOOST_CHECK( wlm2 == sched0[5].wlist_manager());
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SerializeGCONSALE) {
|
||||
auto sched = make_schedule(GCONSALE_deck);
|
||||
auto sched0 = make_schedule(deck0);
|
||||
auto gconsale1 = sched[0].gconsale();
|
||||
auto gconsale2 = sched[3].gconsale();
|
||||
|
||||
{
|
||||
std::vector<Opm::GConSale> value_list;
|
||||
std::vector<std::size_t> index_list;
|
||||
sched.pack_state<Opm::GConSale>( value_list, index_list, std::mem_fn( &ScheduleState::gconsale ));
|
||||
BOOST_CHECK_EQUAL( value_list.size(), 2 );
|
||||
sched0.unpack_state<Opm::GConSale>( value_list, index_list, std::mem_fn( &ScheduleState::update_gconsale ));
|
||||
}
|
||||
|
||||
BOOST_CHECK( gconsale1 == sched0[0].gconsale());
|
||||
BOOST_CHECK( gconsale1 == sched0[1].gconsale());
|
||||
BOOST_CHECK( gconsale1 == sched0[2].gconsale());
|
||||
|
||||
BOOST_CHECK( gconsale2 == sched0[3].gconsale());
|
||||
BOOST_CHECK( gconsale2 == sched0[4].gconsale());
|
||||
BOOST_CHECK( gconsale2 == sched0[5].gconsale());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SerializeGCONSUMP) {
|
||||
auto sched = make_schedule(GCONSALE_deck);
|
||||
auto sched0 = make_schedule(deck0);
|
||||
auto gconsump1 = sched[0].gconsump();
|
||||
auto gconsump2 = sched[3].gconsump();
|
||||
|
||||
{
|
||||
std::vector<Opm::GConSump> value_list;
|
||||
std::vector<std::size_t> index_list;
|
||||
sched.pack_state<Opm::GConSump>( value_list, index_list, std::mem_fn( &ScheduleState::gconsump ));
|
||||
BOOST_CHECK_EQUAL( value_list.size(), 2 );
|
||||
sched0.unpack_state<Opm::GConSump>( value_list, index_list, std::mem_fn( &ScheduleState::update_gconsump ));
|
||||
}
|
||||
|
||||
BOOST_CHECK( gconsump1 == sched0[0].gconsump());
|
||||
BOOST_CHECK( gconsump1 == sched0[1].gconsump());
|
||||
BOOST_CHECK( gconsump1 == sched0[2].gconsump());
|
||||
|
||||
BOOST_CHECK( gconsump2 == sched0[3].gconsump());
|
||||
BOOST_CHECK( gconsump2 == sched0[4].gconsump());
|
||||
BOOST_CHECK( gconsump2 == sched0[5].gconsump());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user