From fe4ed0466a6076347bd04396066123d7ebc61e0b Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 5 Dec 2019 14:29:42 +0100 Subject: [PATCH] add mpi serialization for OilPvtMultiplexer and OilPvtThermal these are intermixed so kept in one commit --- opm/simulators/utils/ParallelRestart.cpp | 186 +++++++++++++++++++++++ opm/simulators/utils/ParallelRestart.hpp | 26 ++++ tests/test_ParallelRestart.cpp | 16 ++ 3 files changed, 228 insertions(+) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index d0bc260ff..64f29f1ec 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -697,6 +697,35 @@ std::size_t packSize(const WetGasPvt& data, template std::size_t packSize(const WetGasPvt& data, Dune::MPIHelper::MPICommunicator comm); +template +std::size_t packSize(const OilPvtMultiplexer& data, + Dune::MPIHelper::MPICommunicator comm) +{ + std::size_t size = packSize(data.approach(), comm); + const void* realOilPvt = data.realOilPvt(); + using PvtApproach = OilPvtMultiplexer; + if (data.approach() == PvtApproach::ConstantCompressibilityOilPvt) { + const auto& pvt = *static_cast*>(realOilPvt); + size += packSize(pvt, comm); + } else if (data.approach() == PvtApproach::DeadOilPvt) { + const auto& pvt = *static_cast*>(realOilPvt); + size += packSize(pvt, comm); + } else if (data.approach() == PvtApproach::LiveOilPvt) { + const auto& pvt = *static_cast*>(realOilPvt); + size += packSize(pvt, comm); + } else if (data.approach() == PvtApproach::ThermalOilPvt) { + const auto& pvt = *static_cast*>(realOilPvt); + size += packSize(pvt, comm); + } + + return size; +} + +template std::size_t packSize(const OilPvtMultiplexer& data, + Dune::MPIHelper::MPICommunicator comm); +template std::size_t packSize(const OilPvtMultiplexer& data, + Dune::MPIHelper::MPICommunicator comm); + template std::size_t packSize(const ConstantCompressibilityOilPvt& data, Dune::MPIHelper::MPICommunicator comm) @@ -745,6 +774,31 @@ std::size_t packSize(const LiveOilPvt& data, template std::size_t packSize(const LiveOilPvt& data, Dune::MPIHelper::MPICommunicator comm); +template +std::size_t packSize(const OilPvtThermal& data, + Dune::MPIHelper::MPICommunicator comm) +{ + std::size_t size = packSize(data.oilvisctCurves(), comm) + + packSize(data.viscrefPress(), comm) + + packSize(data.viscrefRs(), comm) + + packSize(data.viscRef(), comm) + + packSize(data.oildentRefTemp(), comm) + + packSize(data.oildentCT1(), comm) + + packSize(data.oildentCT2(), comm) + + packSize(data.internalEnergyCurves(), comm) + + packSize(data.enableThermalDensity(), comm) + + packSize(data.enableThermalViscosity(), comm) + + packSize(data.enableInternalEnergy(), comm); + size += packSize(bool(), comm); + if (data.isoThermalPvt()) + size += packSize(*data.isoThermalPvt(), comm); + + return size; +} + +template std::size_t packSize(const OilPvtThermal& data, + Dune::MPIHelper::MPICommunicator comm); + ////// pack routines template @@ -1442,6 +1496,36 @@ template void pack(const WetGasPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void pack(const OilPvtMultiplexer& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.approach(), buffer, position, comm); + const void* realOilPvt = data.realOilPvt(); + using PvtApproach = OilPvtMultiplexer; + if (data.approach() == PvtApproach::ConstantCompressibilityOilPvt) { + const auto& pvt = *static_cast*>(realOilPvt); + pack(pvt, buffer, position, comm); + } else if (data.approach() == PvtApproach::DeadOilPvt) { + const auto& pvt = *static_cast*>(realOilPvt); + pack(pvt, buffer, position, comm); + } else if (data.approach() == PvtApproach::LiveOilPvt) { + const auto& pvt = *static_cast*>(realOilPvt); + pack(pvt, buffer, position, comm); + } else if (data.approach() == PvtApproach::ThermalOilPvt) { + const auto& pvt = *static_cast*>(realOilPvt); + pack(pvt, buffer, position, comm); + } +} + +template void pack(const OilPvtMultiplexer& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); +template void pack(const OilPvtMultiplexer& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + template void pack(const ConstantCompressibilityOilPvt& data, std::vector& buffer, int& position, @@ -1496,6 +1580,31 @@ template void pack(const LiveOilPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void pack(const OilPvtThermal& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.oilvisctCurves(), buffer, position, comm); + pack(data.viscrefPress(), buffer, position, comm); + pack(data.viscrefRs(), buffer, position, comm); + pack(data.viscRef(), buffer, position, comm); + pack(data.oildentRefTemp(), buffer, position, comm); + pack(data.oildentCT1(), buffer, position, comm); + pack(data.oildentCT2(), buffer, position, comm); + pack(data.internalEnergyCurves(), buffer, position, comm); + pack(data.enableThermalDensity(), buffer, position, comm); + pack(data.enableThermalViscosity(), buffer, position, comm); + pack(data.enableInternalEnergy(), buffer, position, comm); + pack(data.isoThermalPvt() != nullptr, buffer, position, comm); + if (data.isoThermalPvt()) + pack(*data.isoThermalPvt(), buffer, position, comm); +} + +template void pack(const OilPvtThermal& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + /// unpack routines template @@ -2399,6 +2508,42 @@ template void unpack(WetGasPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void unpack(OilPvtMultiplexer& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + typename OilPvtMultiplexer::OilPvtApproach approach; + unpack(approach, buffer, position, comm); + using PvtApproach = OilPvtMultiplexer; + void* pvt = nullptr; + if (approach == PvtApproach::ConstantCompressibilityOilPvt) { + auto* realPvt = new ConstantCompressibilityOilPvt; + unpack(*realPvt, buffer, position, comm); + pvt = realPvt; + } else if (approach == PvtApproach::DeadOilPvt) { + auto* realPvt = new DeadOilPvt; + unpack(*realPvt, buffer, position, comm); + pvt = realPvt; + } else if (approach == PvtApproach::LiveOilPvt) { + auto* realPvt = new LiveOilPvt; + unpack(*realPvt, buffer, position, comm); + pvt = realPvt; + } else if (approach == PvtApproach::ThermalOilPvt) { + auto* realPvt = new OilPvtThermal; + unpack(*realPvt, buffer, position, comm); + pvt = realPvt; + } + data = OilPvtMultiplexer(approach, pvt); +} + +template void unpack(OilPvtMultiplexer& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); +template void unpack(OilPvtMultiplexer& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + template void unpack(ConstantCompressibilityOilPvt& data, std::vector& buffer, int& position, @@ -2489,6 +2634,47 @@ template void unpack(LiveOilPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void unpack(OilPvtThermal& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + std::vector::TabulatedOneDFunction> oilvisctCurves; + std::vector oildentRefTemp, oildentCT1, oildentCT2, viscrefPress, viscrefRs, viscRef; + std::vector::TabulatedOneDFunction> internalEnergyCurves; + bool enableThermalDensity, enableThermalViscosity, enableInternalEnergy; + unpack(oilvisctCurves, buffer, position, comm); + unpack(viscrefPress, buffer, position, comm); + unpack(viscrefRs, buffer, position, comm); + unpack(viscRef, buffer, position, comm); + unpack(oildentRefTemp, buffer, position, comm); + unpack(oildentCT1, buffer, position, comm); + unpack(oildentCT2, buffer, position, comm); + unpack(internalEnergyCurves, buffer, position, comm); + unpack(enableThermalDensity, buffer, position, comm); + unpack(enableThermalViscosity, buffer, position, comm); + unpack(enableInternalEnergy, buffer, position, comm); + bool isothermal; + unpack(isothermal, buffer, position, comm); + typename OilPvtThermal::IsothermalPvt* pvt = nullptr; + if (isothermal) { + pvt = new typename OilPvtThermal::IsothermalPvt; + unpack(*pvt, buffer, position, comm); + } + data = OilPvtThermal(pvt, oilvisctCurves, + viscrefPress, viscrefRs, viscRef, + oildentRefTemp, + oildentCT1, oildentCT2, + internalEnergyCurves, + enableThermalDensity, + enableThermalViscosity, + enableInternalEnergy); +} + +template void unpack(OilPvtThermal& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + } // 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 3a7ca37be..e66d4ede7 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -180,6 +181,10 @@ std::size_t packSize(const GasPvtThermal& data, Dune::MPIHelper::MPIComm template std::size_t packSize(const WetGasPvt& data, Dune::MPIHelper::MPICommunicator comm); +template +std::size_t packSize(const OilPvtMultiplexer& data, + Dune::MPIHelper::MPICommunicator comm); + template std::size_t packSize(const ConstantCompressibilityOilPvt& data, Dune::MPIHelper::MPICommunicator comm); @@ -192,6 +197,9 @@ template std::size_t packSize(const LiveOilPvt& data, Dune::MPIHelper::MPICommunicator comm); +template +std::size_t packSize(const OilPvtThermal& data, Dune::MPIHelper::MPICommunicator comm); + ////// pack routines template @@ -284,6 +292,11 @@ template void pack(const WetGasPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void pack(const OilPvtMultiplexer& data, + const std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + template void pack(const ConstantCompressibilityOilPvt& data, std::vector& buffer, int& position, @@ -299,6 +312,10 @@ void pack(const LiveOilPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void pack(const OilPvtThermal& data, std::vector& buffer, + int& position, Dune::MPIHelper::MPICommunicator comm); + void pack(const char* str, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); @@ -394,6 +411,11 @@ template void unpack(WetGasPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void unpack(OilPvtMultiplexer& data, + const std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + template void unpack(ConstantCompressibilityOilPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); @@ -406,6 +428,10 @@ template void unpack(LiveOilPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void unpack(OilPvtThermal& data, std::vector& buffer, + int& position, Dune::MPIHelper::MPICommunicator comm); + void unpack(char* str, std::size_t length, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); diff --git a/tests/test_ParallelRestart.cpp b/tests/test_ParallelRestart.cpp index b1abfa09a..475261e85 100644 --- a/tests/test_ParallelRestart.cpp +++ b/tests/test_ParallelRestart.cpp @@ -1120,6 +1120,22 @@ BOOST_AUTO_TEST_CASE(LiveOilPvt) } +BOOST_AUTO_TEST_CASE(OilPvtThermal) +{ +#ifdef HAVE_MPI + Opm::Tabulated1DFunction func(2, std::vector{1.0, 2.0}, + std::vector{3.0, 4.0}); + Opm::OilPvtThermal::IsothermalPvt* pvt = new Opm::OilPvtThermal::IsothermalPvt; + Opm::OilPvtThermal val1(pvt, {func}, {1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}, + {7.0, 8.0}, {9.0, 10.0}, {11.0, 12.0}, + {func}, true, 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;