From a8b76b5ffc2843ae3af65001a66c1d78fc6c3837 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Mon, 9 Dec 2019 10:42:45 +0100 Subject: [PATCH] add mpi serialization for VFPInjTable --- opm/simulators/utils/ParallelRestart.cpp | 52 ++++++++++++++++++++++++ opm/simulators/utils/ParallelRestart.hpp | 2 + tests/test_ParallelRestart.cpp | 28 +++++++++++++ 3 files changed, 82 insertions(+) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index 1f90c555c..376f260e5 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -898,6 +899,18 @@ std::size_t packSize(const MessageLimits& data, return packSize(data.getLimits(), comm); } +std::size_t packSize(const VFPInjTable& data, + Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.getTableNum(), comm) + + packSize(data.getDatumDepth(), comm) + + packSize(data.getFloType(), comm) + + packSize(data.getFloAxis(), comm) + + packSize(data.getTHPAxis(), comm) + + data.getTable().num_elements() * + packSize(double(), comm); +} + ////// pack routines template @@ -1806,6 +1819,18 @@ void pack(const MessageLimits& data, { pack(data.getLimits(), buffer, position, comm); } +void pack(const VFPInjTable& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.getTableNum(), buffer, position, comm); + pack(data.getDatumDepth(), buffer, position, comm); + pack(data.getFloType(), buffer, position, comm); + pack(data.getFloAxis(), buffer, position, comm); + pack(data.getTHPAxis(), buffer, position, comm); + for (size_t i = 0; i < data.getTable().num_elements(); ++i) + pack(*(data.getTable().data() + i), buffer, position, comm); +} /// unpack routines template @@ -3023,6 +3048,33 @@ void unpack(MessageLimits& data, unpack(limits, buffer, position, comm); data = MessageLimits(limits); } + +void unpack(VFPInjTable& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + int tableNum; + double datumDepth; + VFPInjTable::FLO_TYPE floType; + std::vector floAxis, thpAxis; + VFPInjTable::array_type table; + + unpack(tableNum, buffer, position, comm); + unpack(datumDepth, buffer, position, comm); + unpack(floType, buffer, position, comm); + unpack(floAxis, buffer, position, comm); + unpack(thpAxis, buffer, position, comm); + VFPInjTable::extents extents; + extents[0] = thpAxis.size(); + extents[1] = floAxis.size(); + table.resize(extents); + for (size_t i = 0; i < table.num_elements(); ++i) + unpack(*(table.data() + i), buffer, position, comm); + + data = VFPInjTable(tableNum, datumDepth, floType, + floAxis, thpAxis, table); +} + } // 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 7efb0fe89..fcf0fe634 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -104,6 +104,7 @@ class TableManager; class TableSchema; class ThresholdPressure; class UDQParams; +class VFPInjTable; class VISCREFRecord; class ViscrefTable; class WATDENTRecord; @@ -562,6 +563,7 @@ ADD_PACK_PROTOTYPES(ThresholdPressure) ADD_PACK_PROTOTYPES(TimeMap) ADD_PACK_PROTOTYPES(TimeMap::StepData) ADD_PACK_PROTOTYPES(UDQParams) +ADD_PACK_PROTOTYPES(VFPInjTable) ADD_PACK_PROTOTYPES(VISCREFRecord) ADD_PACK_PROTOTYPES(ViscrefTable) ADD_PACK_PROTOTYPES(WATDENTRecord) diff --git a/tests/test_ParallelRestart.cpp b/tests/test_ParallelRestart.cpp index 295fd244d..11bd27ce2 100644 --- a/tests/test_ParallelRestart.cpp +++ b/tests/test_ParallelRestart.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -185,6 +186,7 @@ Opm::FoamData getFoamData() return Opm::FoamData(1.0, 2.0, 3.0, true, 4.0); } + Opm::TimeMap getTimeMap() { return Opm::TimeMap({123}, @@ -226,6 +228,21 @@ Opm::TableContainer getTableContainer() result.addTable(1, std::make_shared(tab1)); return result; } + + +Opm::VFPInjTable getVFPInjTable() +{ + Opm::VFPInjTable::array_type table; + Opm::VFPInjTable::extents shape; + shape[0] = 3; + shape[1] = 2; + table.resize(shape); + double foo = 1.0; + for (size_t i = 0; i < table.num_elements(); ++i) + *(table.data() + i) = foo++; + return Opm::VFPInjTable(1, 2.0, Opm::VFPInjTable::FLO_WAT, {1.0, 2.0}, + {3.0, 4.0, 5.0}, table); +} #endif @@ -1222,6 +1239,17 @@ BOOST_AUTO_TEST_CASE(MessageLimits) } +BOOST_AUTO_TEST_CASE(VFPInjTable) +{ +#ifdef HAVE_MPI + Opm::VFPInjTable val1 = getVFPInjTable(); + 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;