From cdfac8c02b6b66d2e1b5a1db68de948fa6569dcf Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Mon, 2 Dec 2019 10:46:58 +0100 Subject: [PATCH] add mpi serialization for Phases --- opm/simulators/utils/ParallelRestart.cpp | 20 ++++++++++++++++++++ opm/simulators/utils/ParallelRestart.hpp | 2 ++ tests/test_ParallelRestart.cpp | 12 ++++++++++++ 3 files changed, 34 insertions(+) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index 18de66ba8..ad25a81f5 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -22,6 +22,7 @@ #endif #include "ParallelRestart.hpp" +#include #include #include #include @@ -385,6 +386,11 @@ std::size_t packSize(const IOConfig& data, Dune::MPIHelper::MPICommunicator comm packSize(data.getEclCompatibleRST(), comm); } +std::size_t packSize(const Phases& data, Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.getBits(), comm); +} + ////// pack routines template @@ -760,6 +766,12 @@ void pack(const IOConfig& data, std::vector& buffer, int& position, pack(data.getEclCompatibleRST(), buffer, position, comm); } +void pack(const Phases& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.getBits(), buffer, position, comm); +} + /// unpack routines template @@ -1219,6 +1231,14 @@ void unpack(IOConfig& data, std::vector& buffer, int& position, no_sim, base_name, ecl_compatible_rst); } +void unpack(Phases& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + unsigned long bits; + unpack(bits, buffer, position, comm); + data = Phases(std::bitset(bits)); +} + } // end namespace Mpi RestartValue loadParallelRestart(const EclipseIO* eclIO, SummaryState& summaryState, const std::vector& solutionKeys, diff --git a/opm/simulators/utils/ParallelRestart.hpp b/opm/simulators/utils/ParallelRestart.hpp index a25303c4e..8add981ce 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -49,6 +49,7 @@ class InitConfig; class IOConfig; class NNC; struct NNCdata; +class Phases; class RestartConfig; class RestartSchedule; class Rock2dTable; @@ -251,6 +252,7 @@ ADD_PACK_PROTOTYPES(InitConfig) ADD_PACK_PROTOTYPES(IOConfig) ADD_PACK_PROTOTYPES(NNC) ADD_PACK_PROTOTYPES(NNCdata) +ADD_PACK_PROTOTYPES(Phases) ADD_PACK_PROTOTYPES(RestartConfig) ADD_PACK_PROTOTYPES(RestartKey) ADD_PACK_PROTOTYPES(RestartSchedule) diff --git a/tests/test_ParallelRestart.cpp b/tests/test_ParallelRestart.cpp index cbc5055ad..0cc716832 100644 --- a/tests/test_ParallelRestart.cpp +++ b/tests/test_ParallelRestart.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -547,6 +548,17 @@ BOOST_AUTO_TEST_CASE(IOConfig) } +BOOST_AUTO_TEST_CASE(Phases) +{ +#if HAVE_MPI + Opm::Phases val1(true, true, true, false, true, false, true, false); + 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;