From 981ba74211852293faf0f8be4e7c6fcc9c106d0c Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 5 Dec 2019 10:42:45 +0100 Subject: [PATCH] add mpi serialization for GasPvtMultiplexer and GasPvtThermal these are interlinked so kept in one commit --- opm/simulators/utils/ParallelRestart.cpp | 165 +++++++++++++++++++++++ opm/simulators/utils/ParallelRestart.hpp | 26 ++++ tests/test_ParallelRestart.cpp | 15 +++ 3 files changed, 206 insertions(+) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index 03c7099e9..0781c58cc 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -630,6 +630,54 @@ std::size_t packSize(const DryGasPvt& data, template std::size_t packSize(const DryGasPvt& data, Dune::MPIHelper::MPICommunicator comm); +template +std::size_t packSize(const GasPvtThermal& data, + Dune::MPIHelper::MPICommunicator comm) +{ + std::size_t size = packSize(data.gasvisctCurves(), comm) + + packSize(data.gasdentRefTemp(), comm) + + packSize(data.gasdentCT1(), comm) + + packSize(data.gasdentCT2(), 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 GasPvtThermal& data, + Dune::MPIHelper::MPICommunicator comm); + +template +std::size_t packSize(const GasPvtMultiplexer& data, + Dune::MPIHelper::MPICommunicator comm) +{ + std::size_t size = packSize(data.gasPvtApproach(), comm); + const void* realGasPvt = data.realGasPvt(); + using PvtApproach = GasPvtMultiplexer; + if (data.gasPvtApproach() == PvtApproach::DryGasPvt) { + const auto& pvt = *static_cast*>(realGasPvt); + size += packSize(pvt, comm); + } else if (data.gasPvtApproach() == PvtApproach::WetGasPvt) { + const auto& pvt = *static_cast*>(realGasPvt); + size += packSize(pvt, comm); + } else if (data.gasPvtApproach() == PvtApproach::ThermalGasPvt) { + const auto& pvt = *static_cast*>(realGasPvt); + size += packSize(pvt, comm); + } + + return size; +} + +template std::size_t packSize(const GasPvtMultiplexer& data, + Dune::MPIHelper::MPICommunicator comm); +template std::size_t packSize(const GasPvtMultiplexer& data, + Dune::MPIHelper::MPICommunicator comm); + template std::size_t packSize(const WetGasPvt& data, Dune::MPIHelper::MPICommunicator comm) @@ -1263,6 +1311,33 @@ template void pack(const SolventPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void pack(const GasPvtMultiplexer& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.gasPvtApproach(), buffer, position, comm); + const void* realGasPvt = data.realGasPvt(); + using PvtApproach = GasPvtMultiplexer; + if (data.gasPvtApproach() == PvtApproach::DryGasPvt) { + const auto& pvt = *static_cast*>(realGasPvt); + pack(pvt, buffer, position, comm); + } else if (data.gasPvtApproach() == PvtApproach::WetGasPvt) { + const auto& pvt = *static_cast*>(realGasPvt); + pack(pvt, buffer, position, comm); + } else if (data.gasPvtApproach() == PvtApproach::ThermalGasPvt) { + const auto& pvt = *static_cast*>(realGasPvt); + pack(pvt, buffer, position, comm); + } +} + +template void pack(const GasPvtMultiplexer& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); +template void pack(const GasPvtMultiplexer& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + template void pack(const DryGasPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm) @@ -1277,6 +1352,28 @@ template void pack(const DryGasPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void pack(const GasPvtThermal& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.gasvisctCurves(), buffer, position, comm); + pack(data.gasdentRefTemp(), buffer, position, comm); + pack(data.gasdentCT1(), buffer, position, comm); + pack(data.gasdentCT2(), 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 GasPvtThermal& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + template void pack(const WetGasPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm) @@ -2079,6 +2176,38 @@ template void unpack(SolventPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void unpack(GasPvtMultiplexer& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + typename GasPvtMultiplexer::GasPvtApproach approach; + unpack(approach, buffer, position, comm); + using PvtApproach = GasPvtMultiplexer; + void* pvt = nullptr; + if (approach == PvtApproach::DryGasPvt) { + DryGasPvt* realPvt = new DryGasPvt; + unpack(*realPvt, buffer, position, comm); + pvt = realPvt; + } else if (data.gasPvtApproach() == PvtApproach::WetGasPvt) { + WetGasPvt* realPvt = new WetGasPvt; + unpack(*realPvt, buffer, position, comm); + pvt = realPvt; + } else if (data.gasPvtApproach() == PvtApproach::ThermalGasPvt) { + GasPvtThermal* realPvt = new GasPvtThermal; + unpack(*realPvt, buffer, position, comm); + pvt = realPvt; + } + data = GasPvtMultiplexer(approach, pvt); +} + +template void unpack(GasPvtMultiplexer& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); +template void unpack(GasPvtMultiplexer& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + template void unpack(DryGasPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm) @@ -2099,6 +2228,42 @@ template void unpack(DryGasPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void unpack(GasPvtThermal& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + std::vector::TabulatedOneDFunction> gasvisctCurves; + std::vector gasdentRefTemp, gasdentCT1, gasdentCT2; + std::vector::TabulatedOneDFunction> internalEnergyCurves; + bool enableThermalDensity, enableThermalViscosity, enableInternalEnergy; + unpack(gasvisctCurves, buffer, position, comm); + unpack(gasdentRefTemp, buffer, position, comm); + unpack(gasdentCT1, buffer, position, comm); + unpack(gasdentCT2, 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 GasPvtThermal::IsothermalPvt* pvt = nullptr; + if (isothermal) { + pvt = new typename GasPvtThermal::IsothermalPvt; + unpack(*pvt, buffer, position, comm); + } + data = GasPvtThermal(pvt, gasvisctCurves, gasdentRefTemp, + gasdentCT1, gasdentCT2, + internalEnergyCurves, + enableThermalDensity, + enableThermalViscosity, + enableInternalEnergy); +} + +template void unpack(GasPvtThermal& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + template void unpack(WetGasPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm) diff --git a/opm/simulators/utils/ParallelRestart.hpp b/opm/simulators/utils/ParallelRestart.hpp index d1629a163..1be5fe1d8 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -163,9 +164,16 @@ std::size_t packSize(const UniformXTabulated2DFunction& data, Dune::MPIH template std::size_t packSize(const SolventPvt& data, Dune::MPIHelper::MPICommunicator comm); +template +std::size_t packSize(const GasPvtMultiplexer& data, + Dune::MPIHelper::MPICommunicator comm); + template std::size_t packSize(const DryGasPvt& data, Dune::MPIHelper::MPICommunicator comm); +template +std::size_t packSize(const GasPvtThermal& data, Dune::MPIHelper::MPICommunicator comm); + template std::size_t packSize(const WetGasPvt& data, Dune::MPIHelper::MPICommunicator comm); @@ -244,10 +252,19 @@ template void pack(const SolventPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void pack(const GasPvtMultiplexer& data, + const std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + template void pack(const DryGasPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void pack(const GasPvtThermal& data, std::vector& buffer, + int& position, Dune::MPIHelper::MPICommunicator comm); + template void pack(const WetGasPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); @@ -330,10 +347,19 @@ template void unpack(SolventPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void unpack(GasPvtMultiplexer& data, + const std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + template void unpack(DryGasPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void unpack(GasPvtThermal& data, std::vector& buffer, + int& position, Dune::MPIHelper::MPICommunicator comm); + template void unpack(WetGasPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); diff --git a/tests/test_ParallelRestart.cpp b/tests/test_ParallelRestart.cpp index d00f19fec..0009619cf 100644 --- a/tests/test_ParallelRestart.cpp +++ b/tests/test_ParallelRestart.cpp @@ -1038,6 +1038,21 @@ BOOST_AUTO_TEST_CASE(DryGasPvt) } +BOOST_AUTO_TEST_CASE(GasPvtThermal) +{ +#ifdef HAVE_MPI + Opm::Tabulated1DFunction func(2, std::vector{1.0, 2.0}, + std::vector{3.0, 4.0}); + Opm::GasPvtThermal::IsothermalPvt* pvt = new Opm::GasPvtThermal::IsothermalPvt; + Opm::GasPvtThermal val1(pvt, {func}, {1.0, 2.0}, {3.0, 4.0}, {5.0, 6.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 +} + + BOOST_AUTO_TEST_CASE(WetGasPvt) { #ifdef HAVE_MPI