From 5b5dddd64c418affbc1eea356cd1467bf27e4e19 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Tue, 3 Dec 2019 12:31:24 +0100 Subject: [PATCH] add mpi serialization for TableManager --- opm/simulators/utils/ParallelRestart.cpp | 120 +++++++++++++++++++++++ opm/simulators/utils/ParallelRestart.hpp | 2 + tests/test_ParallelRestart.cpp | 47 +++++++++ 3 files changed, 169 insertions(+) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index f335997a7..137854aef 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include #include @@ -517,6 +518,34 @@ std::size_t packSize(const RockTable& data, Dune::MPIHelper::MPICommunicator com return packSize(static_cast&>(data), comm); } +std::size_t packSize(const TableManager& data, Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.getSimpleTables(), comm) + + packSize(data.getPvtgTables(), comm) + + packSize(data.getPvtoTables(), comm) + + packSize(data.getRock2dTables(), comm) + + packSize(data.getRock2dtrTables(), comm) + + packSize(data.getPvtwTable(), comm) + + packSize(data.getPvcdoTable(), comm) + + packSize(data.getDensityTable(), comm) + + packSize(data.getRockTable(), comm) + + packSize(data.getViscrefTable(), comm) + + packSize(data.getWatdentTable(), comm) + + packSize(data.getPlymwinjTables(), comm) + + packSize(data.getSkprwatTables(), comm) + + packSize(data.getSkprpolyTables(), comm) + + packSize(data.getTabdims(), comm) + + packSize(data.getRegdims(), comm) + + packSize(data.getEqldims(), comm) + + packSize(data.getAqudims(), comm) + + packSize(data.useImptvd(), comm) + + packSize(data.useEnptvd(), comm) + + packSize(data.useEqlnum(), comm) + + packSize(data.useJFunc(), comm) + + (data.useJFunc() ? packSize(data.getJFunc(), comm) : 0) + + packSize(data.rtemp(), comm); +} + ////// pack routines template @@ -1014,6 +1043,36 @@ void pack(const RockTable& data, std::vector& buffer, int& position, pack(static_cast&>(data), buffer, position, comm); } +void pack(const TableManager& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.getSimpleTables(), buffer, position, comm); + pack(data.getPvtgTables(), buffer, position, comm); + pack(data.getPvtoTables(), buffer, position, comm); + pack(data.getRock2dTables(), buffer, position, comm); + pack(data.getRock2dtrTables(), buffer, position, comm); + pack(data.getPvtwTable(), buffer, position, comm); + pack(data.getPvcdoTable(), buffer, position, comm); + pack(data.getDensityTable(), buffer, position, comm); + pack(data.getRockTable(), buffer, position, comm); + pack(data.getViscrefTable(), buffer, position, comm); + pack(data.getWatdentTable(), buffer, position, comm); + pack(data.getPlymwinjTables(), buffer, position, comm); + pack(data.getSkprwatTables(), buffer, position, comm); + pack(data.getSkprpolyTables(), buffer, position, comm); + pack(data.getTabdims(), buffer, position, comm); + pack(data.getRegdims(), buffer, position, comm); + pack(data.getEqldims(), buffer, position, comm); + pack(data.getAqudims(), buffer, position, comm); + pack(data.useImptvd(), buffer, position, comm); + pack(data.useEnptvd(), buffer, position, comm); + pack(data.useEqlnum(), buffer, position, comm); + pack(data.useJFunc(), buffer, position, comm); + if (data.useJFunc()) + pack(data.getJFunc(), buffer, position, comm); + pack(data.rtemp(), buffer, position, comm); +} + /// unpack routines template @@ -1640,6 +1699,67 @@ void unpack(RockTable& data, std::vector& buffer, int& position, data = RockTable(pdata); } +void unpack(TableManager& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + std::map simpleTables; + std::vector pvtgTables; + std::vector pvtoTables; + std::vector rock2dTables; + std::vector rock2dtrTables; + PvtwTable pvtwTable; + PvcdoTable pvcdoTable; + DensityTable densityTable; + RockTable rockTable; + ViscrefTable viscrefTable; + WatdentTable watdentTable; + std::map plymwinjTables; + std::map skprwatTables; + std::map skprpolyTables; + Tabdims tabdims; + Regdims regdims; + Eqldims eqldims; + Aqudims aqudims; + bool hasImptvd; + bool hasEntpvd; + bool hasEqlnum; + std::shared_ptr jfunc; + double rtemp; + unpack(simpleTables, buffer, position, comm); + unpack(pvtgTables, buffer, position, comm); + unpack(pvtoTables, buffer, position, comm); + unpack(rock2dTables, buffer, position, comm); + unpack(rock2dtrTables, buffer, position, comm); + unpack(pvtwTable, buffer, position, comm); + unpack(pvcdoTable, buffer, position, comm); + unpack(densityTable, buffer, position, comm); + unpack(rockTable, buffer, position, comm); + unpack(viscrefTable, buffer, position, comm); + unpack(watdentTable, buffer, position, comm); + unpack(plymwinjTables, buffer, position, comm); + unpack(skprwatTables, buffer, position, comm); + unpack(skprpolyTables, buffer, position, comm); + unpack(tabdims, buffer, position, comm); + unpack(regdims, buffer, position, comm); + unpack(eqldims, buffer, position, comm); + unpack(aqudims, buffer, position, comm); + unpack(hasImptvd, buffer, position, comm); + unpack(hasEntpvd, buffer, position, comm); + unpack(hasEqlnum, buffer, position, comm); + bool hasJf; + unpack(hasJf, buffer, position, comm); + if (hasJf) { + jfunc = std::make_shared(); + unpack(*jfunc, buffer, position, comm); + } + unpack(rtemp, buffer, position, comm); + data = TableManager(simpleTables, pvtgTables, pvtoTables, rock2dTables, + rock2dtrTables, pvtwTable, pvcdoTable, densityTable, + rockTable, viscrefTable, watdentTable, plymwinjTables, + skprwatTables, skprpolyTables, tabdims, regdims, eqldims, + aqudims, hasImptvd, hasEntpvd, hasEqlnum, jfunc, rtemp); +} + } // 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 d37a1e935..f79786368 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -81,6 +81,7 @@ class SkprwatTable; class Tabdims; class TableColumn; class TableContainer; +class TableManager; class TableSchema; class ThresholdPressure; class UDQParams; @@ -317,6 +318,7 @@ ADD_PACK_PROTOTYPES(SkprwatTable) ADD_PACK_PROTOTYPES(Tabdims) ADD_PACK_PROTOTYPES(TableColumn) ADD_PACK_PROTOTYPES(TableContainer) +ADD_PACK_PROTOTYPES(TableManager) ADD_PACK_PROTOTYPES(TableSchema) ADD_PACK_PROTOTYPES(ThresholdPressure) ADD_PACK_PROTOTYPES(TimeMap) diff --git a/tests/test_ParallelRestart.cpp b/tests/test_ParallelRestart.cpp index c35061cef..764e6f3cc 100644 --- a/tests/test_ParallelRestart.cpp +++ b/tests/test_ParallelRestart.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include #include @@ -209,6 +210,16 @@ Opm::PvtoTable getPvtoTable() } +Opm::TableContainer getTableContainer() +{ + Opm::OrderedMap data; + data.insert({"test3", getTableColumn()}); + Opm::SimpleTable tab1(getTableSchema(), data, true); + Opm::TableContainer result(2); + result.addTable(0, std::make_shared(tab1)); + result.addTable(1, std::make_shared(tab1)); + return result; +} #endif @@ -921,6 +932,42 @@ BOOST_AUTO_TEST_CASE(RockTable) } +BOOST_AUTO_TEST_CASE(TableManager) +{ +#if HAVE_MPI + auto jfunc = std::make_shared(Opm::JFunc::Flag::BOTH, + 1.0, 2.0, 3.0, 4.0, + Opm::JFunc::Direction::XY); + Opm::TableManager val1({{"test", getTableContainer()}}, + {getPvtgTable()}, + {getPvtoTable()}, + {Opm::Rock2dTable({{1.0,2.0},{3.0,4.0}}, {1.0, 2.0, 3.0})}, + {Opm::Rock2dtrTable({{1.0,2.0},{3.0,4.0}}, {1.0, 2.0, 3.0})}, + Opm::PvtwTable({Opm::PVTWRecord{1.0, 2.0, 3.0, 4.0, 5.0}}), + Opm::PvcdoTable({Opm::PVCDORecord{1.0, 2.0, 3.0, 4.0, 5.0}}), + Opm::DensityTable({Opm::DENSITYRecord{1.0, 2.0, 3.0}}), + Opm::RockTable({Opm::ROCKRecord{1.0,2.0}}), + Opm::ViscrefTable({Opm::VISCREFRecord{1.0, 2.0}}), + Opm::WatdentTable({Opm::WATDENTRecord{1.0, 2.0, 3.0}}), + {{1, Opm::PlymwinjTable({1.0}, {2.0}, 1, {{1.0}, {2.0}})}}, + {{2, Opm::SkprwatTable({1.0}, {2.0}, 1, {{1.0}, {2.0}})}}, + {{3, Opm::SkprpolyTable({1.0}, {2.0}, 1, {{1.0}, {2.0}}, 3.0)}}, + Opm::Tabdims(1,2,3,4,5,6), + Opm::Regdims(1,2,3,4,5), + Opm::Eqldims(1,2,3,4,5), + Opm::Aqudims(1,2,3,4,5,6,7,8), + true, + true, + true, + jfunc, + 1.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;