From 66949e0a593e7233861630a194de139d02b311fc Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Wed, 18 Dec 2019 12:25:59 +0100 Subject: [PATCH] add mpi serialization for Schedule --- opm/simulators/utils/ParallelRestart.cpp | 116 +++++++++++++++++++++++ opm/simulators/utils/ParallelRestart.hpp | 4 +- tests/test_ParallelRestart.cpp | 112 +++++++++++++++++++++- 3 files changed, 229 insertions(+), 3 deletions(-) diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index 2ec6df72d..2339a8a21 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -1623,6 +1624,34 @@ std::size_t packSize(const Action::Actions& data, return packSize(data.getActions(), comm); } +std::size_t packSize(const Schedule& data, + Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.getTimeMap(), comm) + + packSize(data.getStaticWells(), comm) + + packSize(data.getGroups(), comm) + + packSize(data.getOilVapProps(), comm) + + packSize(data.getEvents(), comm) + + packSize(data.getModifierDeck(), comm) + + packSize(data.getTuning(), comm) + + packSize(data.getMessageLimits(), comm) + + packSize(data.getRunspec(), comm) + + packSize(data.getVFPProdTables(), comm) + + packSize(data.getVFPInjTables(), comm) + + packSize(data.getWellTestConfig(), comm) + + packSize(data.getWListManager(), comm) + + packSize(data.getUDQConfig(), comm) + + packSize(data.getUDQActive(), comm) + + packSize(data.getGuideRateConfig(), comm) + + packSize(data.getGConSale(), comm) + + packSize(data.getGConSump(), comm) + + packSize(data.getGlobalWhistCtlMode(), comm) + + packSize(data.getActions(), comm) + + packSize(data.rftConfig(), comm) + + packSize(data.getNupCol(), comm) + + packSize(data.getWellGroupEvents(), comm); +} + ////// pack routines template @@ -3274,6 +3303,35 @@ void pack(const Action::Actions& data, pack(data.getActions(), buffer, position, comm); } +void pack(const Schedule& data, + std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.getTimeMap(), buffer, position, comm); + pack(data.getStaticWells(), buffer, position, comm); + pack(data.getGroups(), buffer, position, comm); + pack(data.getOilVapProps(), buffer, position, comm); + pack(data.getEvents(), buffer, position, comm); + pack(data.getModifierDeck(), buffer, position, comm); + pack(data.getTuning(), buffer, position, comm); + pack(data.getMessageLimits(), buffer, position, comm); + pack(data.getRunspec(), buffer, position, comm); + pack(data.getVFPProdTables(), buffer, position, comm); + pack(data.getVFPInjTables(), buffer, position, comm); + pack(data.getWellTestConfig(), buffer, position, comm); + pack(data.getWListManager(), buffer, position, comm); + pack(data.getUDQConfig(), buffer, position, comm); + pack(data.getUDQActive(), buffer, position, comm); + pack(data.getGuideRateConfig(), buffer, position, comm); + pack(data.getGConSale(), buffer, position, comm); + pack(data.getGConSump(), buffer, position, comm); + pack(data.getGlobalWhistCtlMode(), buffer, position, comm); + pack(data.getActions(), buffer, position, comm); + pack(data.rftConfig(), buffer, position, comm); + pack(data.getNupCol(), buffer, position, comm); + pack(data.getWellGroupEvents(), buffer, position, comm); +} + /// unpack routines template @@ -5618,6 +5676,64 @@ void unpack(Action::Actions& data, std::vector& buffer, int& position, data = Action::Actions(actions); } +void unpack(Schedule& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + TimeMap timeMap; + Schedule::WellMap staticWells; + Schedule::GroupMap groups; + DynamicState oilVapProps; + Events events; + DynamicVector modifierDeck; + Tuning tuning; + MessageLimits messageLimits; + Runspec runspec; + Schedule::VFPProdMap vfpProdTables; + Schedule::VFPInjMap vfpInjTables; + DynamicState> wellTestConfig; + DynamicState> wListManager; + DynamicState> udqConfig; + DynamicState> udqActive; + DynamicState> guideRateConfig; + DynamicState> gconSale; + DynamicState> gconSump; + DynamicState globalWhistCtlMode; + DynamicState> actions; + RFTConfig rftConfig; + DynamicState nupCol; + std::map wellGroupEvents; + + unpack(timeMap, buffer, position, comm); + unpack(staticWells, buffer, position, comm); + unpack(groups, buffer, position, comm); + unpack(oilVapProps, buffer, position, comm); + unpack(events, buffer, position, comm); + unpack(modifierDeck, buffer, position, comm); + unpack(tuning, buffer, position, comm); + unpack(messageLimits, buffer, position, comm); + unpack(runspec, buffer, position, comm); + unpack(vfpProdTables, buffer, position, comm); + unpack(vfpInjTables, buffer, position, comm); + unpack(wellTestConfig, buffer, position, comm); + unpack(wListManager, buffer, position, comm); + unpack(udqConfig, buffer, position, comm); + unpack(udqActive, buffer, position, comm); + unpack(guideRateConfig, buffer, position, comm); + unpack(gconSale, buffer, position, comm); + unpack(gconSump, buffer, position, comm); + unpack(globalWhistCtlMode, buffer, position, comm); + unpack(actions, buffer, position, comm); + unpack(rftConfig, buffer, position, comm); + unpack(nupCol, buffer, position, comm); + unpack(wellGroupEvents, buffer, position, comm); + data = Schedule(timeMap, staticWells, groups, oilVapProps, events, + modifierDeck, tuning, messageLimits, runspec, + vfpProdTables, vfpInjTables, wellTestConfig, + wListManager, udqConfig, udqActive, guideRateConfig, + gconSale, gconSump, globalWhistCtlMode, actions, + rftConfig, nupCol, wellGroupEvents); +} + #define INSTANTIATE_PACK_VECTOR(T) \ template std::size_t packSize(const std::vector& data, \ Dune::MPIHelper::MPICommunicator comm); \ diff --git a/opm/simulators/utils/ParallelRestart.hpp b/opm/simulators/utils/ParallelRestart.hpp index 5338d01c6..a7f67269d 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -118,6 +118,7 @@ class RockTable; class Rock2dTable; class Rock2dtrTable; class Runspec; +class Schedule; class Segment; class SimulationConfig; class SimpleTable; @@ -680,13 +681,14 @@ ADD_PACK_PROTOTYPES(RockTable) ADD_PACK_PROTOTYPES(Rock2dTable) ADD_PACK_PROTOTYPES(Rock2dtrTable) ADD_PACK_PROTOTYPES(Runspec) -ADD_PACK_PROTOTYPES(std::string) +ADD_PACK_PROTOTYPES(Schedule) ADD_PACK_PROTOTYPES(Segment) ADD_PACK_PROTOTYPES(SimulationConfig) ADD_PACK_PROTOTYPES(SimpleTable) ADD_PACK_PROTOTYPES(SkprpolyTable) ADD_PACK_PROTOTYPES(SkprwatTable) ADD_PACK_PROTOTYPES(SpiralICD) +ADD_PACK_PROTOTYPES(std::string) ADD_PACK_PROTOTYPES(Tabdims) ADD_PACK_PROTOTYPES(TableColumn) ADD_PACK_PROTOTYPES(TableContainer) diff --git a/tests/test_ParallelRestart.cpp b/tests/test_ParallelRestart.cpp index 59e3afcbb..cc2dd94ef 100644 --- a/tests/test_ParallelRestart.cpp +++ b/tests/test_ParallelRestart.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -460,8 +461,6 @@ Opm::Action::ActionX getActionX() true, false)}, ast, {getCondition()}, 4, 5); } - - #endif @@ -2230,6 +2229,115 @@ BOOST_AUTO_TEST_CASE(Actions) } +BOOST_AUTO_TEST_CASE(Schedule) +{ +#ifdef HAVE_MPI + Opm::UnitSystem unitSystem; + Opm::Schedule::WellMap wells; + wells.insert({"test", {{std::make_shared(getFullWell())},1}}); + Opm::Schedule::GroupMap groups; + groups.insert({"test", {{std::make_shared("test1", 1, 2, 3.0, unitSystem, + Opm::Group::GroupType::PRODUCTION, + 4.0, true, 5, "test2", + Opm::IOrderSet({"test3", "test4"}, {"test3","test4"}), + Opm::IOrderSet({"test5", "test6"}, {"test5","test6"}), + Opm::Group::GroupInjectionProperties(), + Opm::Group::GroupProductionProperties())},1}}); + using VapType = Opm::OilVaporizationProperties::OilVaporization; + Opm::DynamicState oilvap{{Opm::OilVaporizationProperties(VapType::VAPPARS, + {1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}, + {false, true}, {7.0, 8.0})},1}; + Opm::Events events(Opm::DynamicVector({1,2,3,4,5})); + std::unique_ptr unitSys(new Opm::UnitSystem); + Opm::Deck sdeck({Opm::DeckKeyword("test", {"test",1}, + {getDeckRecord(), getDeckRecord()}, true, false)}, + Opm::UnitSystem(), unitSys.get(), + "test2", "test3", 2); + Opm::DynamicVector modifierDeck({sdeck}); + std::vector limits{Opm::MLimits{1,2,3,4,5,6,7,8,9,10,11,12}}; + Opm::MessageLimits messageLimits(Opm::DynamicState(limits,2)); + Opm::Runspec runspec(Opm::Phases(true, true, true, false, true, false, true, false), + Opm::Tabdims(1,2,3,4,5,6), + Opm::EndpointScaling(std::bitset<4>(13)), + Opm::Welldims(1,2,3,4), + Opm::WellSegmentDims(1,2,3), + Opm::UDQParams(true, 1, 2.0, 3.0, 4.0), + Opm::EclHysterConfig(true, 1, 2), + Opm::Actdims(1,2,3,4)); + Opm::Schedule::VFPProdMap vfpProd {{1, {{std::make_shared(getVFPProdTable())},1}}}; + Opm::Schedule::VFPInjMap vfpIn{{1, {{std::make_shared(getVFPInjTable())},1}}}; + Opm::WellTestConfig::WTESTWell tw{"test", Opm::WellTestConfig::ECONOMIC, + 1.0, 2, 3.0, 4}; + Opm::WellTestConfig wtc({tw, tw, tw}); + + Opm::WList wl({"test1", "test2", "test3"}); + std::map data{{"test", wl}, {"test2", wl}}; + Opm::WListManager wlm(data); + + Opm::UDQActive udqa({Opm::UDQActive::InputRecord(1, "test1", "test2", + Opm::UDAControl::WCONPROD_ORAT)}, + {Opm::UDQActive::Record("test1", 1, 2, "test2", + Opm::UDAControl::WCONPROD_ORAT)}, + {{"test1", 1}}, {{"test2", 2}}); + + auto model = std::make_shared(getGuideRateModel()); + Opm::GuideRateConfig grc(model, + {{"test1", getGuideRateConfigWell()}}, + {{"test2", getGuideRateConfigGroup()}}); + + Opm::GConSale::GCONSALEGroup group{Opm::UDAValue(1.0), + Opm::UDAValue(2.0), + Opm::UDAValue(3.0), + Opm::GConSale::MaxProcedure::PLUG, + 4.0, Opm::UnitSystem()}; + Opm::GConSale gcs({{"test1", group}, {"test2", group}}); + + Opm::GConSump::GCONSUMPGroup grp{Opm::UDAValue(1.0), + Opm::UDAValue(2.0), + "test", + 3.0, Opm::UnitSystem()}; + Opm::GConSump gcm({{"test1", grp}, {"test2", grp}}); + + Opm::Action::Actions acnts({getActionX()}); + + Opm::RFTConfig rftc(getTimeMap(), + {true, 1}, + {"test1", "test2"}, + {{"test3", 2}}, + {{"test1", {{{Opm::RFTConfig::RFT::TIMESTEP, 3}}, 4}}}, + {{"test2", {{{Opm::RFTConfig::PLT::REPT, 5}}, 6}}}); + + Opm::Schedule val1(getTimeMap(), + wells, + groups, + oilvap, + events, + modifierDeck, + getTuning(), + messageLimits, + runspec, + vfpProd, + vfpIn, + {{std::make_shared(wtc)}, 1}, + {{std::make_shared(wlm)}, 1}, + {{std::make_shared(getUDQConfig())}, 1}, + {{std::make_shared(udqa)}, 1}, + {{std::make_shared(grc)}, 1}, + {{std::make_shared(gcs)}, 1}, + {{std::make_shared(gcm)}, 1}, + {{Opm::Well::ProducerCMode::CRAT}, 1}, + {{std::make_shared(acnts)}, 1}, + rftc, + {std::vector{1}, 1}, + {{"test", events}}); + + 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;