From e53072faf586c71cd09bbefc538dbec69830929a Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Wed, 11 Dec 2019 11:42:45 +0100 Subject: [PATCH] add mpi serialization for Dimension --- opm/simulators/utils/ParallelRestart.cpp | 30 ++++++++++++++++++++++++ opm/simulators/utils/ParallelRestart.hpp | 2 ++ tests/test_ParallelRestart.cpp | 11 +++++++++ 3 files changed, 43 insertions(+) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index 5daf858b9..9bf202152 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -1126,6 +1126,14 @@ std::size_t packSize(const std::shared_ptr& data, template std::size_t packSize(const std::shared_ptr& data, Dune::MPIHelper::MPICommunicator comm); +std::size_t packSize(const Dimension& data, + Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.getName(), comm) + + packSize(data.getSIScalingRaw(), comm) + + packSize(data.getSIOffset(), comm); +} + ////// pack routines template @@ -2264,6 +2272,15 @@ void pack(const std::shared_ptr& data, std::vector& buffer, int& positi template void pack(const std::shared_ptr& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +void pack(const Dimension& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.getName(), buffer, position, comm); + pack(data.getSIScalingRaw(), buffer, position, comm); + pack(data.getSIOffset(), buffer, position, comm); +} + /// unpack routines template @@ -3851,6 +3868,19 @@ template void unpack(std::shared_ptr& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +void unpack(Dimension& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + std::string name; + double siScaling, siOffset; + + unpack(name, buffer, position, comm); + unpack(siScaling, buffer, position, comm); + unpack(siOffset, buffer, position, comm); + data = Dimension(name, siScaling, siOffset); +} + #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 a465e59eb..f22c524ed 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -62,6 +62,7 @@ class ColumnSchema; class Connection; class DENSITYRecord; class DensityTable; +class Dimension; class EclHysterConfig; class Eqldims; class EDITNNC; @@ -539,6 +540,7 @@ ADD_PACK_PROTOTYPES(data::Well) ADD_PACK_PROTOTYPES(data::WellRates) ADD_PACK_PROTOTYPES(DENSITYRecord) ADD_PACK_PROTOTYPES(DensityTable) +ADD_PACK_PROTOTYPES(Dimension) ADD_PACK_PROTOTYPES(EDITNNC) ADD_PACK_PROTOTYPES(EndpointScaling) ADD_PACK_PROTOTYPES(Equil) diff --git a/tests/test_ParallelRestart.cpp b/tests/test_ParallelRestart.cpp index 1bd9645fc..568e5b766 100644 --- a/tests/test_ParallelRestart.cpp +++ b/tests/test_ParallelRestart.cpp @@ -1507,6 +1507,17 @@ BOOST_AUTO_TEST_CASE(Segment) } +BOOST_AUTO_TEST_CASE(Dimension) +{ +#ifdef HAVE_MPI + Opm::Dimension val1("test", 1.0, 2.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;