From 7f36bac5798088a479166a8dd4da66d33bc2dbc5 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 2 Feb 2023 11:52:08 +0100 Subject: [PATCH 1/3] WellContainer: add serialization support --- opm/simulators/wells/WellContainer.hpp | 24 ++++++++++++++++++++++-- tests/test_RestartSerialization.cpp | 14 ++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/opm/simulators/wells/WellContainer.hpp b/opm/simulators/wells/WellContainer.hpp index a27ffa554..bb7f46be9 100644 --- a/opm/simulators/wells/WellContainer.hpp +++ b/opm/simulators/wells/WellContainer.hpp @@ -45,15 +45,23 @@ namespace Opm { template class WellContainer { public: - WellContainer() = default; - WellContainer(std::initializer_list> init_list) { for (const auto& [name, value] : init_list) this->add(name, value); } + static WellContainer serializationTestObject(const T& data) + { + WellContainer result; + + result.m_data = {data}; + result.index_map = {{"test1", 1}, {"test2", 4}}; + + return result; + } + bool empty() const { return this->index_map.empty(); } @@ -167,6 +175,18 @@ public: return wlist; } + template + void serializeOp(Serializer& serializer) + { + serializer(m_data); + serializer(index_map); + } + + bool operator==(const WellContainer& rhs) const + { + return this->m_data == rhs.m_data && + this->index_map == rhs.index_map; + } private: void update_if(std::size_t index, const std::string& name, const WellContainer& other) { diff --git a/tests/test_RestartSerialization.cpp b/tests/test_RestartSerialization.cpp index 16403bd30..7718d76b5 100644 --- a/tests/test_RestartSerialization.cpp +++ b/tests/test_RestartSerialization.cpp @@ -113,6 +113,20 @@ BOOST_AUTO_TEST_CASE(SingleWellState) BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized SingleWellState differ"); } +BOOST_AUTO_TEST_CASE(WellContainer) +{ + auto data_out = Opm::WellContainer::serializationTestObject(1.0); + Opm::Serialization::MemPacker packer; + Opm::Serializer ser(packer); + ser.pack(data_out); + const size_t pos1 = ser.position(); + decltype(data_out) data_in; + ser.unpack(data_in); + const size_t pos2 = ser.position(); + BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for WellContainer"); + BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized WellContainer differ"); +} + BOOST_AUTO_TEST_CASE(EclGenericVanguard) { auto in_params = Opm::EclGenericVanguard::serializationTestParams(); From 1a5ae624b11639fbda526b790ca5e1d298bcba44 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Wed, 15 Feb 2023 20:03:06 +0100 Subject: [PATCH 2/3] GroupState: add gpmaint_state to comparison operator --- opm/simulators/wells/GroupState.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/opm/simulators/wells/GroupState.cpp b/opm/simulators/wells/GroupState.cpp index 08303e6c7..32e7ba7c4 100644 --- a/opm/simulators/wells/GroupState.cpp +++ b/opm/simulators/wells/GroupState.cpp @@ -43,7 +43,8 @@ bool GroupState::operator==(const GroupState& other) const { this->inj_vrep_rate == other.inj_vrep_rate && this->inj_surface_rates == other.inj_surface_rates && this->m_grat_sales_target == other.m_grat_sales_target && - this->injection_controls == other.injection_controls; + this->injection_controls == other.injection_controls && + this->gpmaint_state == other.gpmaint_state; } //------------------------------------------------------------------------- From b87bf2b3ae68e44c9c2193b51d507edd485233e9 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 2 Feb 2023 11:52:08 +0100 Subject: [PATCH 3/3] GroupState: add serialization support --- opm/simulators/wells/GroupState.cpp | 19 +++++++++++++++++++ opm/simulators/wells/GroupState.hpp | 23 ++++++++++++++++++++++- tests/test_RestartSerialization.cpp | 2 ++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/opm/simulators/wells/GroupState.cpp b/opm/simulators/wells/GroupState.cpp index 32e7ba7c4..e8f4048f7 100644 --- a/opm/simulators/wells/GroupState.cpp +++ b/opm/simulators/wells/GroupState.cpp @@ -33,6 +33,25 @@ GroupState::GroupState(std::size_t np) : num_phases(np) {} +GroupState GroupState::serializationTestObject() +{ + GroupState result(3); + result.m_production_rates = {{"test1", {1.0, 2.0}}}; + result.production_controls = {{"test2", Group::ProductionCMode::LRAT}}; + result.prod_red_rates = {{"test3", {3.0, 4.0, 5.0}}}; + result.inj_red_rates = {{"test4", {6.0, 7.0}}}; + result.inj_surface_rates = {{"test5", {8.0}}}; + result.inj_resv_rates = {{"test6", {9.0, 10.0}}}; + result.inj_rein_rates = {{"test7", {11.0}}}; + result.inj_vrep_rate = {{"test8", 12.0}, {"test9", 13.0}}; + result.m_grat_sales_target = {{"test10", 14.0}}; + result.m_gpmaint_target = {{"test11", 15.0}}; + result.injection_controls = {{{Phase::FOAM, "test12"}, Group::InjectionCMode::REIN}}; + result.gpmaint_state.add("foo", GPMaint::State::serializationTestObject()); + + return result; +} + bool GroupState::operator==(const GroupState& other) const { return this->m_production_rates == other.m_production_rates && this->production_controls == other.production_controls && diff --git a/opm/simulators/wells/GroupState.hpp b/opm/simulators/wells/GroupState.hpp index ec32445b7..faa60df85 100644 --- a/opm/simulators/wells/GroupState.hpp +++ b/opm/simulators/wells/GroupState.hpp @@ -33,7 +33,11 @@ namespace Opm { class GroupState { public: + GroupState() = default; explicit GroupState(std::size_t num_phases); + + static GroupState serializationTestObject(); + bool operator==(const GroupState& other) const; bool has_production_rates(const std::string& gname) const; @@ -159,9 +163,26 @@ public: throw std::logic_error("Internal size mismatch when distributing groupData"); } + template + void serializeOp(Serializer& serializer) + { + serializer(num_phases); + serializer(m_production_rates); + serializer(production_controls); + serializer(prod_red_rates); + serializer(inj_red_rates); + serializer(inj_surface_rates); + serializer(inj_resv_rates); + serializer(inj_rein_rates); + serializer(inj_vrep_rate); + serializer(m_grat_sales_target); + serializer(m_gpmaint_target); + serializer(injection_controls); + serializer(gpmaint_state); + } private: - std::size_t num_phases; + std::size_t num_phases{}; std::map> m_production_rates; std::map production_controls; std::map> prod_red_rates; diff --git a/tests/test_RestartSerialization.cpp b/tests/test_RestartSerialization.cpp index 7718d76b5..a0302311a 100644 --- a/tests/test_RestartSerialization.cpp +++ b/tests/test_RestartSerialization.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -76,6 +77,7 @@ BOOST_AUTO_TEST_CASE(NAME) \ #define TEST_FOR_TYPE(TYPE) \ TEST_FOR_TYPE_NAMED(TYPE, TYPE) +TEST_FOR_TYPE(GroupState) TEST_FOR_TYPE(HardcodedTimeStepControl) TEST_FOR_TYPE(PIDAndIterationCountTimeStepControl) TEST_FOR_TYPE(PIDTimeStepControl)