From 34a55ed381422f58305057c9952f7e5a24f271dc Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Wed, 4 Dec 2019 20:27:18 +0100 Subject: [PATCH 1/8] add mpi serialization for std::array --- opm/simulators/utils/ParallelRestart.cpp | 22 ++++++++++++++++++++++ opm/simulators/utils/ParallelRestart.hpp | 11 +++++++++++ 2 files changed, 33 insertions(+) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index e17a29d1a..8317521c7 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -271,6 +271,12 @@ std::size_t packSize(const std::unordered_map& data, Dune::MPIHelpe return totalSize; } +template +std::size_t packSize(const std::array& data, Dune::MPIHelper::MPICommunicator comm) +{ + return N*packSize(data[0], comm); +} + HANDLE_AS_POD(Actdims) HANDLE_AS_POD(Aqudims) HANDLE_AS_POD(data::Connection) @@ -1486,6 +1492,14 @@ void pack(const std::unordered_set& data, } } +template +void pack(const std::array& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + for (const T& entry : data) + pack(entry, buffer, position, comm); +} + template void pack(const std::vector& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm) @@ -2931,6 +2945,14 @@ void unpack(std::unordered_set& data, } } +template +void unpack(std::array& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + for (T& entry : data) + unpack(entry, buffer, position, comm); +} + template void unpack(OrderedMap& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm) diff --git a/opm/simulators/utils/ParallelRestart.hpp b/opm/simulators/utils/ParallelRestart.hpp index 78685ac32..7accf8d36 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -184,6 +184,9 @@ template std::size_t packSize(const std::shared_ptr& data, Dune::MPIHelper::MPICommunicator comm); +template +std::size_t packSize(const std::array& data, Dune::MPIHelper::MPICommunicator comm); + std::size_t packSize(const char* str, Dune::MPIHelper::MPICommunicator comm); std::size_t packSize(const std::string& str, Dune::MPIHelper::MPICommunicator comm); @@ -313,6 +316,10 @@ template void pack(const std::shared_ptr& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void pack(const std::array& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + template void pack(const std::map& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); @@ -463,6 +470,10 @@ template void unpack(std::shared_ptr& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void unpack(std::array& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + template void unpack(std::map& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); From 805f68fdee43b968541f7979232431b1598481fc Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 13:00:47 +0100 Subject: [PATCH 2/8] add mpi serialization for GuideRateModel --- opm/simulators/utils/ParallelRestart.cpp | 51 ++++++++++++++++++++++++ opm/simulators/utils/ParallelRestart.hpp | 2 + tests/test_ParallelRestart.cpp | 23 +++++++++++ 3 files changed, 76 insertions(+) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index 8317521c7..80ce734cf 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -1390,6 +1391,19 @@ std::size_t packSize(const UDQActive& data, packSize(data.getWgKeys(), comm); } +std::size_t packSize(const GuideRateModel& data, + Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.timeInterval(), comm) + + packSize(data.target(), comm) + + packSize(data.coefs(), comm) + + packSize(data.allow_increase(), comm) + + packSize(data.damping_factor(), comm) + + packSize(data.free_gas(), comm) + + packSize(data.defaultModel(), comm) + + packSize(data.udaCoefs(), comm); +} + ////// pack routines template @@ -2803,6 +2817,20 @@ void pack(const UDQActive& data, pack(data.getWgKeys(), buffer, position, comm); } +void pack(const GuideRateModel& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.timeInterval(), buffer, position, comm); + pack(data.target(), buffer, position, comm); + pack(data.coefs(), buffer, position, comm); + pack(data.allow_increase(), buffer, position, comm); + pack(data.damping_factor(), buffer, position, comm); + pack(data.free_gas(), buffer, position, comm); + pack(data.defaultModel(), buffer, position, comm); + pack(data.udaCoefs(), buffer, position, comm); +} + /// unpack routines template @@ -4787,6 +4815,29 @@ void unpack(UDQActive& data, data = UDQActive(inputRecords, outputRecords, udqKeys, wgKeys); } +void unpack(GuideRateModel& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + double timeInterval; + GuideRateModel::Target target; + std::array coefs; + bool allow_increase, free_gas, defaultModel; + double damping_factor; + std::array udaCoefs; + + unpack(timeInterval, buffer, position, comm); + unpack(target, buffer, position, comm); + unpack(coefs, buffer, position, comm); + unpack(allow_increase, buffer, position, comm); + unpack(damping_factor, buffer, position, comm); + unpack(free_gas, buffer, position, comm); + unpack(defaultModel, buffer, position, comm); + unpack(udaCoefs, buffer, position, comm); + data = GuideRateModel(timeInterval, target, coefs, allow_increase, + damping_factor, free_gas, defaultModel, udaCoefs); +} + #define INSTANTIATE_PACK_VECTOR(T) \ template std::size_t packSize(const std::vector& data, \ Dune::MPIHelper::MPICommunicator comm); \ diff --git a/opm/simulators/utils/ParallelRestart.hpp b/opm/simulators/utils/ParallelRestart.hpp index 7accf8d36..6f417ab2e 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -75,6 +75,7 @@ class EquilRecord; class Events; class FoamConfig; class FoamData; +class GuideRateModel; class InitConfig; class IOConfig; template class IOrderSet; @@ -600,6 +601,7 @@ ADD_PACK_PROTOTYPES(EquilRecord) ADD_PACK_PROTOTYPES(Events) ADD_PACK_PROTOTYPES(FoamConfig) ADD_PACK_PROTOTYPES(FoamData) +ADD_PACK_PROTOTYPES(GuideRateModel) ADD_PACK_PROTOTYPES(Group) ADD_PACK_PROTOTYPES(Group::GroupInjectionProperties) ADD_PACK_PROTOTYPES(Group::GroupProductionProperties) diff --git a/tests/test_ParallelRestart.cpp b/tests/test_ParallelRestart.cpp index 30476926d..87761c04b 100644 --- a/tests/test_ParallelRestart.cpp +++ b/tests/test_ParallelRestart.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -335,6 +336,17 @@ Opm::UDQConfig getUDQConfig() omap, {{Opm::UDQVarType::SCALAR, 5}, {Opm::UDQVarType::WELL_VAR, 6}}); } + + +Opm::GuideRateModel getGuideRateModel() +{ + return Opm::GuideRateModel(1.0, Opm::GuideRateModel::Target::WAT, + {2.0, 3.0, 4.0, 5.0, 6.0, 7.0}, + true, 8.0, false, false, + {Opm::UDAValue(9.0), + Opm::UDAValue(10.0), + Opm::UDAValue(11.0)}); +} #endif @@ -1831,6 +1843,17 @@ BOOST_AUTO_TEST_CASE(UDQActive) } +BOOST_AUTO_TEST_CASE(GuideRateModel) +{ +#ifdef HAVE_MPI + Opm::GuideRateModel val1 = getGuideRateModel(); + auto val2 = PackUnpack(val1); + BOOST_CHECK(std::get<1>(val2) == std::get<2>(val2)); + BOOST_CHECK(val1 == std::get<0>(val2)); +#endif +} + + bool init_unit_test_func() { return true; From 5de7605863de4f880e95cfeb40589ebdc33de2e2 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 13:40:13 +0100 Subject: [PATCH 3/8] add mpi serialization for GuideRateConfig --- opm/simulators/utils/ParallelRestart.cpp | 33 ++++++++++++++++ opm/simulators/utils/ParallelRestart.hpp | 5 ++- tests/test_ParallelRestart.cpp | 48 ++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index 80ce734cf..e8afec1b1 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -288,6 +288,8 @@ HANDLE_AS_POD(EclHysterConfig) HANDLE_AS_POD(Eqldims) HANDLE_AS_POD(EquilRecord) HANDLE_AS_POD(FoamData) +HANDLE_AS_POD(GuideRateConfig::GroupTarget); +HANDLE_AS_POD(GuideRateConfig::WellTarget); HANDLE_AS_POD(JFunc) HANDLE_AS_POD(MLimits) HANDLE_AS_POD(PVTWRecord) @@ -1404,6 +1406,14 @@ std::size_t packSize(const GuideRateModel& data, packSize(data.udaCoefs(), comm); } +std::size_t packSize(const GuideRateConfig& data, + Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.getModel(), comm) + + packSize(data.getWells(), comm) + + packSize(data.getGroups(), comm); +} + ////// pack routines template @@ -2831,6 +2841,15 @@ void pack(const GuideRateModel& data, pack(data.udaCoefs(), buffer, position, comm); } +void pack(const GuideRateConfig& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.getModel(), buffer, position, comm); + pack(data.getWells(), buffer, position, comm); + pack(data.getGroups(), buffer, position, comm); +} + /// unpack routines template @@ -4838,6 +4857,20 @@ void unpack(GuideRateModel& data, damping_factor, free_gas, defaultModel, udaCoefs); } +void unpack(GuideRateConfig& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + std::shared_ptr model; + std::unordered_map wells; + std::unordered_map groups; + + unpack(model, buffer, position, comm); + unpack(wells, buffer, position, comm); + unpack(groups, buffer, position, comm); + data = GuideRateConfig(model, wells, groups); +} + #define INSTANTIATE_PACK_VECTOR(T) \ template std::size_t packSize(const std::vector& data, \ Dune::MPIHelper::MPICommunicator comm); \ diff --git a/opm/simulators/utils/ParallelRestart.hpp b/opm/simulators/utils/ParallelRestart.hpp index 6f417ab2e..9709d3858 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -75,7 +76,6 @@ class EquilRecord; class Events; class FoamConfig; class FoamData; -class GuideRateModel; class InitConfig; class IOConfig; template class IOrderSet; @@ -601,6 +601,9 @@ ADD_PACK_PROTOTYPES(EquilRecord) ADD_PACK_PROTOTYPES(Events) ADD_PACK_PROTOTYPES(FoamConfig) ADD_PACK_PROTOTYPES(FoamData) +ADD_PACK_PROTOTYPES(GuideRateConfig) +ADD_PACK_PROTOTYPES(GuideRateConfig::GroupTarget) +ADD_PACK_PROTOTYPES(GuideRateConfig::WellTarget) ADD_PACK_PROTOTYPES(GuideRateModel) ADD_PACK_PROTOTYPES(Group) ADD_PACK_PROTOTYPES(Group::GroupInjectionProperties) diff --git a/tests/test_ParallelRestart.cpp b/tests/test_ParallelRestart.cpp index 87761c04b..fc53483d8 100644 --- a/tests/test_ParallelRestart.cpp +++ b/tests/test_ParallelRestart.cpp @@ -350,6 +350,18 @@ Opm::GuideRateModel getGuideRateModel() #endif +Opm::GuideRateConfig::GroupTarget getGuideRateConfigGroup() +{ + return Opm::GuideRateConfig::GroupTarget{1.0, Opm::Group::GuideRateTarget::COMB}; +} + + +Opm::GuideRateConfig::WellTarget getGuideRateConfigWell() +{ + return Opm::GuideRateConfig::WellTarget{1.0, Opm::Well::GuideRateTarget::COMB, 2.0}; +} + + } @@ -1854,6 +1866,42 @@ BOOST_AUTO_TEST_CASE(GuideRateModel) } +BOOST_AUTO_TEST_CASE(GuideRateConfigGroup) +{ +#ifdef HAVE_MPI + Opm::GuideRateConfig::GroupTarget val1 = getGuideRateConfigGroup(); + auto val2 = PackUnpack(val1); + BOOST_CHECK(std::get<1>(val2) == std::get<2>(val2)); + BOOST_CHECK(val1 == std::get<0>(val2)); +#endif +} + + +BOOST_AUTO_TEST_CASE(GuideRateConfigWell) +{ +#ifdef HAVE_MPI + Opm::GuideRateConfig::WellTarget val1 = getGuideRateConfigWell(); + auto val2 = PackUnpack(val1); + BOOST_CHECK(std::get<1>(val2) == std::get<2>(val2)); + BOOST_CHECK(val1 == std::get<0>(val2)); +#endif +} + + +BOOST_AUTO_TEST_CASE(GuideRateConfig) +{ +#ifdef HAVE_MPI + auto model = std::make_shared(getGuideRateModel()); + Opm::GuideRateConfig val1(model, + {{"test1", getGuideRateConfigWell()}}, + {{"test2", getGuideRateConfigGroup()}}); + auto val2 = PackUnpack(val1); + BOOST_CHECK(std::get<1>(val2) == std::get<2>(val2)); + BOOST_CHECK(val1 == std::get<0>(val2)); +#endif +} + + bool init_unit_test_func() { return true; From e7f0a00b0077d53640c970eb324f003739c0e2fe Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 14:00:07 +0100 Subject: [PATCH 4/8] add mpi serialization for GConSale --- opm/simulators/utils/ParallelRestart.cpp | 57 ++++++++++++++++++++++++ opm/simulators/utils/ParallelRestart.hpp | 3 ++ tests/test_ParallelRestart.cpp | 32 +++++++++++++ 3 files changed, 92 insertions(+) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index e8afec1b1..73e77cc7b 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -1414,6 +1414,23 @@ std::size_t packSize(const GuideRateConfig& data, packSize(data.getGroups(), comm); } +std::size_t packSize(const GConSale::GCONSALEGroup& data, + Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.sales_target, comm) + + packSize(data.max_sales_rate, comm) + + packSize(data.min_sales_rate, comm) + + packSize(data.max_proc, comm) + + packSize(data.udq_undefined, comm) + + packSize(data.unit_system, comm); +} + +std::size_t packSize(const GConSale& data, + Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.getGroups(), comm); +} + ////// pack routines template @@ -2850,6 +2867,25 @@ void pack(const GuideRateConfig& data, pack(data.getGroups(), buffer, position, comm); } +void pack(const GConSale::GCONSALEGroup& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.sales_target, buffer, position, comm); + pack(data.max_sales_rate, buffer, position, comm); + pack(data.min_sales_rate, buffer, position, comm); + pack(data.max_proc, buffer, position, comm); + pack(data.udq_undefined, buffer, position, comm); + pack(data.unit_system, buffer, position, comm); +} + +void pack(const GConSale& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.getGroups(), buffer, position, comm); +} + /// unpack routines template @@ -4871,6 +4907,27 @@ void unpack(GuideRateConfig& data, data = GuideRateConfig(model, wells, groups); } +void unpack(GConSale::GCONSALEGroup& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + unpack(data.sales_target, buffer, position, comm); + unpack(data.max_sales_rate, buffer, position, comm); + unpack(data.min_sales_rate, buffer, position, comm); + unpack(data.max_proc, buffer, position, comm); + unpack(data.udq_undefined, buffer, position, comm); + unpack(data.unit_system, buffer, position, comm); +} + +void unpack(GConSale& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + std::map groups; + unpack(groups, buffer, position, comm); + data = GConSale(groups); +} + #define INSTANTIATE_PACK_VECTOR(T) \ template std::size_t packSize(const std::vector& data, \ Dune::MPIHelper::MPICommunicator comm); \ diff --git a/opm/simulators/utils/ParallelRestart.hpp b/opm/simulators/utils/ParallelRestart.hpp index 9709d3858..69731d427 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -601,6 +602,8 @@ ADD_PACK_PROTOTYPES(EquilRecord) ADD_PACK_PROTOTYPES(Events) ADD_PACK_PROTOTYPES(FoamConfig) ADD_PACK_PROTOTYPES(FoamData) +ADD_PACK_PROTOTYPES(GConSale) +ADD_PACK_PROTOTYPES(GConSale::GCONSALEGroup) ADD_PACK_PROTOTYPES(GuideRateConfig) ADD_PACK_PROTOTYPES(GuideRateConfig::GroupTarget) ADD_PACK_PROTOTYPES(GuideRateConfig::WellTarget) diff --git a/tests/test_ParallelRestart.cpp b/tests/test_ParallelRestart.cpp index fc53483d8..2647ec930 100644 --- a/tests/test_ParallelRestart.cpp +++ b/tests/test_ParallelRestart.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1902,6 +1903,37 @@ BOOST_AUTO_TEST_CASE(GuideRateConfig) } +BOOST_AUTO_TEST_CASE(GConSaleGroup) +{ +#ifdef HAVE_MPI + Opm::GConSale::GCONSALEGroup val1{Opm::UDAValue(1.0), + Opm::UDAValue(2.0), + Opm::UDAValue(3.0), + Opm::GConSale::MaxProcedure::PLUG, + 4.0, Opm::UnitSystem()}; + auto val2 = PackUnpack(val1); + BOOST_CHECK(std::get<1>(val2) == std::get<2>(val2)); + BOOST_CHECK(val1 == std::get<0>(val2)); +#endif +} + + +BOOST_AUTO_TEST_CASE(GConSale) +{ +#ifdef HAVE_MPI + Opm::GConSale::GCONSALEGroup group{Opm::UDAValue(1.0), + Opm::UDAValue(2.0), + Opm::UDAValue(3.0), + Opm::GConSale::MaxProcedure::PLUG, + 4.0, Opm::UnitSystem()}; + Opm::GConSale val1({{"test1", group}, {"test2", group}}); + auto val2 = PackUnpack(val1); + BOOST_CHECK(std::get<1>(val2) == std::get<2>(val2)); + BOOST_CHECK(val1 == std::get<0>(val2)); +#endif +} + + bool init_unit_test_func() { return true; From b925d75deff6733bf64480687355882e76a6de94 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 14:12:29 +0100 Subject: [PATCH 5/8] add mpi serialization for GConSump --- opm/simulators/utils/ParallelRestart.cpp | 54 ++++++++++++++++++++++++ opm/simulators/utils/ParallelRestart.hpp | 3 ++ tests/test_ParallelRestart.cpp | 29 +++++++++++++ 3 files changed, 86 insertions(+) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index 73e77cc7b..9ebac7680 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -1431,6 +1431,22 @@ std::size_t packSize(const GConSale& data, return packSize(data.getGroups(), comm); } +std::size_t packSize(const GConSump::GCONSUMPGroup& data, + Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.consumption_rate, comm) + + packSize(data.import_rate, comm) + + packSize(data.network_node, comm) + + packSize(data.udq_undefined, comm) + + packSize(data.unit_system, comm); +} + +std::size_t packSize(const GConSump& data, + Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.getGroups(), comm); +} + ////// pack routines template @@ -2886,6 +2902,24 @@ void pack(const GConSale& data, pack(data.getGroups(), buffer, position, comm); } +void pack(const GConSump::GCONSUMPGroup& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.consumption_rate, buffer, position, comm); + pack(data.import_rate, buffer, position, comm); + pack(data.network_node, buffer, position, comm); + pack(data.udq_undefined, buffer, position, comm); + pack(data.unit_system, buffer, position, comm); +} + +void pack(const GConSump& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.getGroups(), buffer, position, comm); +} + /// unpack routines template @@ -4928,6 +4962,26 @@ void unpack(GConSale& data, data = GConSale(groups); } +void unpack(GConSump::GCONSUMPGroup& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + unpack(data.consumption_rate, buffer, position, comm); + unpack(data.import_rate, buffer, position, comm); + unpack(data.network_node, buffer, position, comm); + unpack(data.udq_undefined, buffer, position, comm); + unpack(data.unit_system, buffer, position, comm); +} + +void unpack(GConSump& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + std::map groups; + unpack(groups, buffer, position, comm); + data = GConSump(groups); +} + #define INSTANTIATE_PACK_VECTOR(T) \ template std::size_t packSize(const std::vector& data, \ Dune::MPIHelper::MPICommunicator comm); \ diff --git a/opm/simulators/utils/ParallelRestart.hpp b/opm/simulators/utils/ParallelRestart.hpp index 69731d427..1fd2c86f4 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -604,6 +605,8 @@ ADD_PACK_PROTOTYPES(FoamConfig) ADD_PACK_PROTOTYPES(FoamData) ADD_PACK_PROTOTYPES(GConSale) ADD_PACK_PROTOTYPES(GConSale::GCONSALEGroup) +ADD_PACK_PROTOTYPES(GConSump) +ADD_PACK_PROTOTYPES(GConSump::GCONSUMPGroup) ADD_PACK_PROTOTYPES(GuideRateConfig) ADD_PACK_PROTOTYPES(GuideRateConfig::GroupTarget) ADD_PACK_PROTOTYPES(GuideRateConfig::WellTarget) diff --git a/tests/test_ParallelRestart.cpp b/tests/test_ParallelRestart.cpp index 2647ec930..18f0d8a57 100644 --- a/tests/test_ParallelRestart.cpp +++ b/tests/test_ParallelRestart.cpp @@ -1934,6 +1934,35 @@ BOOST_AUTO_TEST_CASE(GConSale) } +BOOST_AUTO_TEST_CASE(GConSumpGroup) +{ +#ifdef HAVE_MPI + Opm::GConSump::GCONSUMPGroup val1{Opm::UDAValue(1.0), + Opm::UDAValue(2.0), + "test", + 3.0, Opm::UnitSystem()}; + auto val2 = PackUnpack(val1); + BOOST_CHECK(std::get<1>(val2) == std::get<2>(val2)); + BOOST_CHECK(val1 == std::get<0>(val2)); +#endif +} + + +BOOST_AUTO_TEST_CASE(GConSump) +{ +#ifdef HAVE_MPI + Opm::GConSump::GCONSUMPGroup group{Opm::UDAValue(1.0), + Opm::UDAValue(2.0), + "test", + 3.0, Opm::UnitSystem()}; + Opm::GConSump val1({{"test1", group}, {"test2", group}}); + auto val2 = PackUnpack(val1); + BOOST_CHECK(std::get<1>(val2) == std::get<2>(val2)); + BOOST_CHECK(val1 == std::get<0>(val2)); +#endif +} + + bool init_unit_test_func() { return true; From 55630acded39fe66eefd5140c992aeb4928d78b0 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 15:00:34 +0100 Subject: [PATCH 6/8] add mpi serialization for RFTConfig --- opm/simulators/utils/ParallelRestart.cpp | 45 ++++++++++++++++++++++++ opm/simulators/utils/ParallelRestart.hpp | 2 ++ tests/test_ParallelRestart.cpp | 17 +++++++++ 3 files changed, 64 insertions(+) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index 9ebac7680..1039de078 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -1447,6 +1448,17 @@ std::size_t packSize(const GConSump& data, return packSize(data.getGroups(), comm); } +std::size_t packSize(const RFTConfig& data, + Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.timeMap(), comm) + + packSize(data.wellOpenRftTime(), comm) + + packSize(data.wellOpenRftName(), comm) + + packSize(data.wellOpen(), comm) + + packSize(data.rftConfig(), comm) + + packSize(data.pltConfig(), comm); +} + ////// pack routines template @@ -2920,6 +2932,18 @@ void pack(const GConSump& data, pack(data.getGroups(), buffer, position, comm); } +void pack(const RFTConfig& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.timeMap(), buffer, position, comm); + pack(data.wellOpenRftTime(), buffer, position, comm); + pack(data.wellOpenRftName(), buffer, position, comm); + pack(data.wellOpen(), buffer, position, comm); + pack(data.rftConfig(), buffer, position, comm); + pack(data.pltConfig(), buffer, position, comm); +} + /// unpack routines template @@ -4982,6 +5006,27 @@ void unpack(GConSump& data, data = GConSump(groups); } +void unpack(RFTConfig& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + TimeMap timeMap; + std::pair wellOpenRftTime; + std::unordered_set wellOpenRftName; + std::unordered_map wellOpen; + RFTConfig::RFTMap rftConfig; + RFTConfig::PLTMap pltConfig; + + unpack(timeMap, buffer, position, comm); + unpack(wellOpenRftTime, buffer, position, comm); + unpack(wellOpenRftName, buffer, position, comm); + unpack(wellOpen, buffer, position, comm); + unpack(rftConfig, buffer, position, comm); + unpack(pltConfig, buffer, position, comm); + data = RFTConfig(timeMap, wellOpenRftTime, wellOpenRftName, + wellOpen, rftConfig, pltConfig); +} + #define INSTANTIATE_PACK_VECTOR(T) \ template std::size_t packSize(const std::vector& data, \ Dune::MPIHelper::MPICommunicator comm); \ diff --git a/opm/simulators/utils/ParallelRestart.hpp b/opm/simulators/utils/ParallelRestart.hpp index 1fd2c86f4..18fb129fd 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -99,6 +99,7 @@ class PvtwTable; class Regdims; class RestartConfig; class RestartSchedule; +class RFTConfig; class ROCKRecord; class RockTable; class Rock2dTable; @@ -636,6 +637,7 @@ ADD_PACK_PROTOTYPES(RestartConfig) ADD_PACK_PROTOTYPES(RestartKey) ADD_PACK_PROTOTYPES(RestartSchedule) ADD_PACK_PROTOTYPES(RestartValue) +ADD_PACK_PROTOTYPES(RFTConfig) ADD_PACK_PROTOTYPES(ROCKRecord) ADD_PACK_PROTOTYPES(RockTable) ADD_PACK_PROTOTYPES(Rock2dTable) diff --git a/tests/test_ParallelRestart.cpp b/tests/test_ParallelRestart.cpp index 18f0d8a57..dd6684193 100644 --- a/tests/test_ParallelRestart.cpp +++ b/tests/test_ParallelRestart.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -1963,6 +1964,22 @@ BOOST_AUTO_TEST_CASE(GConSump) } +BOOST_AUTO_TEST_CASE(RFTConfig) +{ +#ifdef HAVE_MPI + Opm::RFTConfig val1(getTimeMap(), + {true, 1}, + {"test1", "test2"}, + {{"test3", 2}}, + {{"test1", {{{Opm::RFTConfig::RFT::TIMESTEP, 3}}, 4}}}, + {{"test2", {{{Opm::RFTConfig::PLT::REPT, 5}}, 6}}}); + auto val2 = PackUnpack(val1); + BOOST_CHECK(std::get<1>(val2) == std::get<2>(val2)); + BOOST_CHECK(val1 == std::get<0>(val2)); +#endif +} + + bool init_unit_test_func() { return true; From 13de64985ac95f66373a045ead9190ef50651628 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 15:34:24 +0100 Subject: [PATCH 7/8] add mpi serialization for DeckItem --- opm/simulators/utils/ParallelRestart.cpp | 60 ++++++++++++++++++++++++ opm/simulators/utils/ParallelRestart.hpp | 2 + tests/test_ParallelRestart.cpp | 18 +++++++ 3 files changed, 80 insertions(+) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index 1039de078..f23500d41 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -1459,6 +1459,21 @@ std::size_t packSize(const RFTConfig& data, packSize(data.pltConfig(), comm); } +std::size_t packSize(const DeckItem& data, + Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.dVal(), comm) + + packSize(data.iVal(), comm) + + packSize(data.sVal(), comm) + + packSize(data.uVal(), comm) + + packSize(data.getType(), comm) + + packSize(data.name(), comm) + + packSize(data.valueStatus(), comm) + + packSize(data.rawData(), comm) + + packSize(data.activeDimensions(), comm) + + packSize(data.defaultDimensions(), comm); +} + ////// pack routines template @@ -2944,6 +2959,22 @@ void pack(const RFTConfig& data, pack(data.pltConfig(), buffer, position, comm); } +void pack(const DeckItem& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.dVal(), buffer, position, comm); + pack(data.iVal(), buffer, position, comm); + pack(data.sVal(), buffer, position, comm); + pack(data.uVal(), buffer, position, comm); + pack(data.getType(), buffer, position, comm); + pack(data.name(), buffer, position, comm); + pack(data.valueStatus(), buffer, position, comm); + pack(data.rawData(), buffer, position, comm); + pack(data.activeDimensions(), buffer, position, comm); + pack(data.defaultDimensions(), buffer, position, comm); +} + /// unpack routines template @@ -5027,6 +5058,35 @@ void unpack(RFTConfig& data, wellOpen, rftConfig, pltConfig); } + +void unpack(DeckItem& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + std::vector dVal; + std::vector iVal; + std::vector sVal; + std::vector uVal; + type_tag type; + std::string name; + std::vector valueStatus; + bool rawData; + std::vector activeDimensions, defaultDimensions; + + unpack(dVal, buffer, position, comm); + unpack(iVal, buffer, position, comm); + unpack(sVal, buffer, position, comm); + unpack(uVal, buffer, position, comm); + unpack(type, buffer, position, comm); + unpack(name, buffer, position, comm); + unpack(valueStatus, buffer, position, comm); + unpack(rawData, buffer, position, comm); + unpack(activeDimensions, buffer, position, comm); + unpack(defaultDimensions, buffer, position, comm); + data = DeckItem(dVal, iVal, sVal, uVal, type, name, + valueStatus, rawData, activeDimensions, defaultDimensions); +} + #define INSTANTIATE_PACK_VECTOR(T) \ template std::size_t packSize(const std::vector& data, \ Dune::MPIHelper::MPICommunicator comm); \ diff --git a/opm/simulators/utils/ParallelRestart.hpp b/opm/simulators/utils/ParallelRestart.hpp index 18fb129fd..3c1fd7c91 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -66,6 +66,7 @@ class Actdims; class Aqudims; class ColumnSchema; class Connection; +class DeckItem; class DENSITYRecord; class DensityTable; class Dimension; @@ -592,6 +593,7 @@ ADD_PACK_PROTOTYPES(data::Segment) ADD_PACK_PROTOTYPES(data::Solution) ADD_PACK_PROTOTYPES(data::Well) ADD_PACK_PROTOTYPES(data::WellRates) +ADD_PACK_PROTOTYPES(DeckItem) ADD_PACK_PROTOTYPES(DENSITYRecord) ADD_PACK_PROTOTYPES(DensityTable) ADD_PACK_PROTOTYPES(Dimension) diff --git a/tests/test_ParallelRestart.cpp b/tests/test_ParallelRestart.cpp index dd6684193..bc4ccaceb 100644 --- a/tests/test_ParallelRestart.cpp +++ b/tests/test_ParallelRestart.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -1980,6 +1981,23 @@ BOOST_AUTO_TEST_CASE(RFTConfig) } +BOOST_AUTO_TEST_CASE(DeckItem) +{ +#ifdef HAVE_MPI + Opm::DeckItem val1({1.0}, {2}, {"test3"}, {Opm::UDAValue(4)}, + Opm::type_tag::string, "test5", + {Opm::value::status::deck_value}, + true, + {Opm::Dimension("DimensionLess", 7.0, 8.0)}, + {Opm::Dimension("Metric", 10.0, 11.0)}); + + auto val2 = PackUnpack(val1); + BOOST_CHECK(std::get<1>(val2) == std::get<2>(val2)); + BOOST_CHECK(val1 == std::get<0>(val2)); +#endif +} + + bool init_unit_test_func() { return true; From 4899056717a8d70d99b63cd853016538edc8afa2 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 15:42:05 +0100 Subject: [PATCH 8/8] add mpi serialization for DeckRecord --- opm/simulators/utils/ParallelRestart.cpp | 22 +++++++++++++++++ opm/simulators/utils/ParallelRestart.hpp | 2 ++ tests/test_ParallelRestart.cpp | 31 ++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index f23500d41..78c8c2706 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -1474,6 +1474,12 @@ std::size_t packSize(const DeckItem& data, packSize(data.defaultDimensions(), comm); } +std::size_t packSize(const DeckRecord& data, + Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.getItems(), comm); +} + ////// pack routines template @@ -2975,6 +2981,13 @@ void pack(const DeckItem& data, pack(data.defaultDimensions(), buffer, position, comm); } +void pack(const DeckRecord& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.getItems(), buffer, position, comm); +} + /// unpack routines template @@ -5087,6 +5100,15 @@ void unpack(DeckItem& data, valueStatus, rawData, activeDimensions, defaultDimensions); } +void unpack(DeckRecord& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + std::vector items; + unpack(items, buffer, position, comm); + data = DeckRecord(std::move(items)); +} + #define INSTANTIATE_PACK_VECTOR(T) \ template std::size_t packSize(const std::vector& data, \ Dune::MPIHelper::MPICommunicator comm); \ diff --git a/opm/simulators/utils/ParallelRestart.hpp b/opm/simulators/utils/ParallelRestart.hpp index 3c1fd7c91..0a7c48d24 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -67,6 +67,7 @@ class Aqudims; class ColumnSchema; class Connection; class DeckItem; +class DeckRecord; class DENSITYRecord; class DensityTable; class Dimension; @@ -594,6 +595,7 @@ ADD_PACK_PROTOTYPES(data::Solution) ADD_PACK_PROTOTYPES(data::Well) ADD_PACK_PROTOTYPES(data::WellRates) ADD_PACK_PROTOTYPES(DeckItem) +ADD_PACK_PROTOTYPES(DeckRecord) ADD_PACK_PROTOTYPES(DENSITYRecord) ADD_PACK_PROTOTYPES(DensityTable) ADD_PACK_PROTOTYPES(Dimension) diff --git a/tests/test_ParallelRestart.cpp b/tests/test_ParallelRestart.cpp index bc4ccaceb..b2bd7336f 100644 --- a/tests/test_ParallelRestart.cpp +++ b/tests/test_ParallelRestart.cpp @@ -365,6 +365,26 @@ Opm::GuideRateConfig::WellTarget getGuideRateConfigWell() } +Opm::DeckRecord getDeckRecord() +{ + Opm::DeckItem item1({1.0}, {2}, {"test3"}, {Opm::UDAValue(4)}, + Opm::type_tag::string, "test5", + {Opm::value::status::deck_value}, + true, + {Opm::Dimension("DimensionLess", 7.0, 8.0)}, + {Opm::Dimension("Metric", 10.0, 11.0)}); + + Opm::DeckItem item2({1.0}, {2}, {"test3"}, {Opm::UDAValue(4)}, + Opm::type_tag::string, "test6", + {Opm::value::status::deck_value}, + true, + {Opm::Dimension("DimensionLess", 7.0, 8.0)}, + {Opm::Dimension("Metric", 10.0, 11.0)}); + + return Opm::DeckRecord({item1, item2}); +} + + } @@ -1998,6 +2018,17 @@ BOOST_AUTO_TEST_CASE(DeckItem) } +BOOST_AUTO_TEST_CASE(DeckRecord) +{ +#ifdef HAVE_MPI + Opm::DeckRecord val1 = getDeckRecord(); + auto val2 = PackUnpack(val1); + BOOST_CHECK(std::get<1>(val2) == std::get<2>(val2)); + BOOST_CHECK(val1 == std::get<0>(val2)); +#endif +} + + bool init_unit_test_func() { return true;