From 13de64985ac95f66373a045ead9190ef50651628 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 12 Dec 2019 15:34:24 +0100 Subject: [PATCH] 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;