diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index ff0505f3f..d4301395a 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -799,6 +799,29 @@ std::size_t packSize(const OilPvtThermal& data, template std::size_t packSize(const OilPvtThermal& data, Dune::MPIHelper::MPICommunicator comm); +template +std::size_t packSize(const WaterPvtMultiplexer& data, + Dune::MPIHelper::MPICommunicator comm) +{ + std::size_t size = packSize(data.approach(), comm); + const void* realWaterPvt = data.realWaterPvt(); + using PvtApproach = WaterPvtMultiplexer; + if (data.approach() == PvtApproach::ConstantCompressibilityWaterPvt) { + const auto& pvt = *static_cast*>(realWaterPvt); + size += packSize(pvt, comm); + } else if (data.approach() == PvtApproach::ThermalWaterPvt) { + const auto& pvt = *static_cast*>(realWaterPvt); + size += packSize(pvt, comm); + } + + return size; +} + +template std::size_t packSize(const WaterPvtMultiplexer& data, + Dune::MPIHelper::MPICommunicator comm); +template std::size_t packSize(const WaterPvtMultiplexer& data, + Dune::MPIHelper::MPICommunicator comm); + template std::size_t packSize(const ConstantCompressibilityWaterPvt& data, Dune::MPIHelper::MPICommunicator comm) @@ -814,6 +837,34 @@ std::size_t packSize(const ConstantCompressibilityWaterPvt& data, template std::size_t packSize(const ConstantCompressibilityWaterPvt& data, Dune::MPIHelper::MPICommunicator comm); +template +std::size_t packSize(const WaterPvtThermal& data, + Dune::MPIHelper::MPICommunicator comm) +{ + std::size_t size = packSize(data.viscrefPress(), comm) + + packSize(data.watdentRefTemp(), comm) + + packSize(data.watdentCT1(), comm) + + packSize(data.watdentCT2(), comm) + + packSize(data.pvtwRefPress(), comm) + + packSize(data.pvtwRefB(), comm) + + packSize(data.pvtwCompressibility(), comm) + + packSize(data.pvtwViscosity(), comm) + + packSize(data.pvtwViscosibility(), comm) + + packSize(data.watvisctCurves(), 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 WaterPvtThermal& data, + Dune::MPIHelper::MPICommunicator comm); + ////// pack routines template @@ -1620,6 +1671,30 @@ template void pack(const OilPvtThermal& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void pack(const WaterPvtMultiplexer& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.approach(), buffer, position, comm); + const void* realWaterPvt = data.realWaterPvt(); + using PvtApproach = WaterPvtMultiplexer; + if (data.approach() == PvtApproach::ConstantCompressibilityWaterPvt) { + const auto& pvt = *static_cast*>(realWaterPvt); + pack(pvt, buffer, position, comm); + } else if (data.approach() == PvtApproach::ThermalWaterPvt) { + const auto& pvt = *static_cast*>(realWaterPvt); + pack(pvt, buffer, position, comm); + } +} + +template void pack(const WaterPvtMultiplexer& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); +template void pack(const WaterPvtMultiplexer& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + template void pack(const ConstantCompressibilityWaterPvt& data, std::vector& buffer, int& position, @@ -1637,6 +1712,34 @@ template void pack(const ConstantCompressibilityWaterPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void pack(const WaterPvtThermal& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.viscrefPress(), buffer, position, comm); + pack(data.watdentRefTemp(), buffer, position, comm); + pack(data.watdentCT1(), buffer, position, comm); + pack(data.watdentCT2(), buffer, position, comm); + pack(data.pvtwRefPress(), buffer, position, comm); + pack(data.pvtwRefB(), buffer, position, comm); + pack(data.pvtwCompressibility(), buffer, position, comm); + pack(data.pvtwViscosity(), buffer, position, comm); + pack(data.pvtwViscosibility(), buffer, position, comm); + pack(data.watvisctCurves(), 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 WaterPvtThermal& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + /// unpack routines template @@ -2707,6 +2810,34 @@ template void unpack(OilPvtThermal& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void unpack(WaterPvtMultiplexer& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + typename WaterPvtMultiplexer::WaterPvtApproach approach; + unpack(approach, buffer, position, comm); + using PvtApproach = WaterPvtMultiplexer; + void* pvt = nullptr; + if (approach == PvtApproach::ConstantCompressibilityWaterPvt) { + auto* realPvt = new ConstantCompressibilityWaterPvt; + unpack(*realPvt, buffer, position, comm); + pvt = realPvt; + } else if (data.approach() == PvtApproach::ThermalWaterPvt) { + auto* realPvt = new WaterPvtThermal; + unpack(*realPvt, buffer, position, comm); + pvt = realPvt; + } + data = WaterPvtMultiplexer(approach, pvt); +} + +template void unpack(WaterPvtMultiplexer& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); +template void unpack(WaterPvtMultiplexer& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + template void unpack(ConstantCompressibilityWaterPvt& data, std::vector& buffer, int& position, @@ -2734,6 +2865,55 @@ template void unpack(ConstantCompressibilityWaterPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void unpack(WaterPvtThermal& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + std::vector viscrefPress, watdentRefTemp, watdentCT1, watdentCT2, + pvtwRefPress, pvtwRefB, pvtwCompressibility, + pvtwViscosity, pvtwViscosibility; + std::vector::TabulatedOneDFunction> watvisctCurves; + std::vector::TabulatedOneDFunction> internalEnergyCurves; + bool enableThermalDensity, enableThermalViscosity, enableInternalEnergy; + unpack(viscrefPress, buffer, position, comm); + unpack(watdentRefTemp, buffer, position, comm); + unpack(watdentCT1, buffer, position, comm); + unpack(watdentCT2, buffer, position, comm); + unpack(pvtwRefPress, buffer, position, comm); + unpack(pvtwRefB, buffer, position, comm); + unpack(pvtwCompressibility, buffer, position, comm); + unpack(pvtwViscosity, buffer, position, comm); + unpack(pvtwViscosibility, buffer, position, comm); + unpack(watvisctCurves, 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 WaterPvtThermal::IsothermalPvt* pvt = nullptr; + if (isothermal) { + pvt = new typename WaterPvtThermal::IsothermalPvt; + unpack(*pvt, buffer, position, comm); + } + data = WaterPvtThermal(pvt, viscrefPress, watdentRefTemp, + watdentCT1, watdentCT2, + pvtwRefPress, pvtwRefB, + pvtwCompressibility, + pvtwViscosity, + pvtwViscosibility, + watvisctCurves, + internalEnergyCurves, + enableThermalDensity, + enableThermalViscosity, + enableInternalEnergy); +} + +template void unpack(WaterPvtThermal& 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 9b73ecb5f..47e7f77d2 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -201,10 +202,17 @@ std::size_t packSize(const LiveOilPvt& data, template std::size_t packSize(const OilPvtThermal& data, Dune::MPIHelper::MPICommunicator comm); +template +std::size_t packSize(const WaterPvtMultiplexer& data, + Dune::MPIHelper::MPICommunicator comm); + template std::size_t packSize(const ConstantCompressibilityWaterPvt& data, Dune::MPIHelper::MPICommunicator comm); +template +std::size_t packSize(const WaterPvtThermal& data, Dune::MPIHelper::MPICommunicator comm); + ////// pack routines template @@ -321,11 +329,20 @@ template void pack(const OilPvtThermal& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void pack(const WaterPvtMultiplexer& data, + const std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + template void pack(const ConstantCompressibilityWaterPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void pack(const WaterPvtThermal& data, std::vector& buffer, + int& position, Dune::MPIHelper::MPICommunicator comm); + void pack(const char* str, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); @@ -442,6 +459,15 @@ template void unpack(OilPvtThermal& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void unpack(WaterPvtMultiplexer& data, + const std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + +template +void unpack(WaterPvtThermal& data, std::vector& buffer, + int& position, Dune::MPIHelper::MPICommunicator comm); + template void unpack(ConstantCompressibilityWaterPvt& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); diff --git a/tests/test_ParallelRestart.cpp b/tests/test_ParallelRestart.cpp index 01dd855bd..5275822d9 100644 --- a/tests/test_ParallelRestart.cpp +++ b/tests/test_ParallelRestart.cpp @@ -1148,6 +1148,23 @@ BOOST_AUTO_TEST_CASE(ConstantCompressibilityWaterPvt) } +BOOST_AUTO_TEST_CASE(WaterPvtThermal) +{ +#ifdef HAVE_MPI + Opm::Tabulated1DFunction func(2, std::vector{1.0, 2.0}, + std::vector{3.0, 4.0}); + Opm::WaterPvtThermal::IsothermalPvt* pvt = new Opm::WaterPvtThermal::IsothermalPvt; + Opm::WaterPvtThermal val1(pvt, {1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}, + {7.0, 8.0}, {9.0, 10.0}, {11.0, 12.0}, + {13.0, 14.0}, {15.0, 16.0}, {17.0, 18.0}, + {func}, {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;