From e7f0a00b0077d53640c970eb324f003739c0e2fe Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 14:00:07 +0100 Subject: [PATCH] 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;