From 186014177176623fe8e64fdbae69c334c22e6262 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Fri, 13 Dec 2019 11:40:55 +0100 Subject: [PATCH] add mpi serialization for DeckKeyword --- opm/simulators/utils/ParallelRestart.cpp | 39 ++++++++++++++++++++++++ opm/simulators/utils/ParallelRestart.hpp | 1 + tests/test_ParallelRestart.cpp | 12 ++++++++ 3 files changed, 52 insertions(+) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index f60095c88..73d651187 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -1488,6 +1488,16 @@ std::size_t packSize(const Location& data, packSize(data.lineno, comm); } +std::size_t packSize(const DeckKeyword& data, + Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.name(), comm) + + packSize(data.location(), comm) + + packSize(data.records(), comm) + + packSize(data.isDataKeyword(), comm) + + packSize(data.isSlashTerminated(), comm); +} + ////// pack routines template @@ -3004,6 +3014,17 @@ void pack(const Location& data, pack(data.lineno, buffer, position, comm); } +void pack(const DeckKeyword& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.name(), buffer, position, comm); + pack(data.location(), buffer, position, comm); + pack(data.records(), buffer, position, comm); + pack(data.isDataKeyword(), buffer, position, comm); + pack(data.isSlashTerminated(), buffer, position, comm); +} + /// unpack routines template @@ -5134,6 +5155,24 @@ void unpack(Location& data, unpack(data.lineno, buffer, position, comm); } +void unpack(DeckKeyword& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + std::string name; + Location location; + std::vector records; + bool isDataKeyword, isSlashTerminated; + + unpack(name, buffer, position, comm); + unpack(location, buffer, position, comm); + unpack(records, buffer, position, comm); + unpack(isDataKeyword, buffer, position, comm); + unpack(isSlashTerminated, buffer, position, comm); + data = DeckKeyword(name, location, records, + isDataKeyword, isSlashTerminated); +} + #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 a45355dbd..1e2ba59ac 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -596,6 +596,7 @@ ADD_PACK_PROTOTYPES(data::Solution) ADD_PACK_PROTOTYPES(data::Well) ADD_PACK_PROTOTYPES(data::WellRates) ADD_PACK_PROTOTYPES(DeckItem) +ADD_PACK_PROTOTYPES(DeckKeyword) ADD_PACK_PROTOTYPES(DeckRecord) ADD_PACK_PROTOTYPES(DENSITYRecord) ADD_PACK_PROTOTYPES(DensityTable) diff --git a/tests/test_ParallelRestart.cpp b/tests/test_ParallelRestart.cpp index d01ad8543..3f1a7e162 100644 --- a/tests/test_ParallelRestart.cpp +++ b/tests/test_ParallelRestart.cpp @@ -2041,6 +2041,18 @@ BOOST_AUTO_TEST_CASE(Location) } +BOOST_AUTO_TEST_CASE(DeckKeyword) +{ +#ifdef HAVE_MPI + Opm::DeckKeyword val1("test", {"test",1}, + {getDeckRecord(), getDeckRecord()}, 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;