diff --git a/opm/simulators/utils/ParallelRestart.cpp b/opm/simulators/utils/ParallelRestart.cpp index 435f66758..c7c352bf7 100644 --- a/opm/simulators/utils/ParallelRestart.cpp +++ b/opm/simulators/utils/ParallelRestart.cpp @@ -22,11 +22,15 @@ #endif #include "ParallelRestart.hpp" +#include #include #include #include #include +#include +#include #include +#include #include #include #include @@ -148,6 +152,11 @@ std::size_t packSize(const OrderedMap& data, Dune::MPIHelper::MPIComm return packSize(data.getIndex(), comm) + packSize(data.getStorage(), comm); } +template +std::size_t packSize(const DynamicState& data, Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.data(), comm) + packSize(data.initialRange(), comm); +} std::size_t packSize(const char* str, Dune::MPIHelper::MPICommunicator comm) { @@ -196,6 +205,9 @@ HANDLE_AS_POD(data::Rates) HANDLE_AS_POD(data::Segment) HANDLE_AS_POD(EquilRecord) HANDLE_AS_POD(FoamData) +HANDLE_AS_POD(RestartSchedule) +HANDLE_AS_POD(Tabdims) +HANDLE_AS_POD(TimeMap::StepData) std::size_t packSize(const data::Well& data, Dune::MPIHelper::MPICommunicator comm) { @@ -341,6 +353,45 @@ std::size_t packSize(const SimulationConfig& data, Dune::MPIHelper::MPICommunica packSize(data.isThermal(), comm); } +std::size_t packSize(const TimeMap& data, Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.timeList(), comm) + + packSize(data.firstTimeStepMonths(), comm) + + packSize(data.firstTimeStepYears(), comm); +} + +std::size_t packSize(const RestartConfig& data, Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.timeMap(), comm) + + packSize(data.getFirstRestartStep(), comm) + + packSize(data.writeInitialRst(), comm) + + packSize(data.restartSchedule(), comm) + + packSize(data.restartKeywords(), comm) + + packSize(data.saveKeywords(), comm); +} + +std::size_t packSize(const IOConfig& data, Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.getWriteINITFile(), comm) + + packSize(data.getWriteEGRIDFile(), comm) + + packSize(data.getUNIFIN(), comm) + + packSize(data.getUNIFOUT(), comm) + + packSize(data.getFMTIN(), comm) + + packSize(data.getFMTOUT(), comm) + + packSize(data.getFirstRestartStep(), comm) + + packSize(data.getDeckFileName(), comm) + + packSize(data.getOutputEnabled(), comm) + + packSize(data.getOutputDir(), comm) + + packSize(data.getNoSim(), comm) + + packSize(data.getBaseName(), comm) + + packSize(data.getEclCompatibleRST(), comm); +} + +std::size_t packSize(const Phases& data, Dune::MPIHelper::MPICommunicator comm) +{ + return packSize(data.getBits(), comm); +} + ////// pack routines template @@ -449,6 +500,14 @@ void pack(const OrderedMap& data, std::vector& buffer, int& po pack(data.getStorage(), buffer, position, comm); } +template +void pack(const DynamicState& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.data(), buffer, position, comm); + pack(data.initialRange(), buffer, position, comm); +} + void pack(const char* str, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm) { @@ -671,6 +730,49 @@ void pack(const SimulationConfig& data, std::vector& buffer, int& position pack(data.isThermal(), buffer, position, comm); } +void pack(const TimeMap& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.timeList(), buffer, position, comm); + pack(data.firstTimeStepMonths(), buffer, position, comm); + pack(data.firstTimeStepYears(), buffer, position, comm); +} + +void pack(const RestartConfig& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.timeMap(), buffer, position, comm); + pack(data.getFirstRestartStep(), buffer, position, comm); + pack(data.writeInitialRst(), buffer, position, comm); + pack(data.restartSchedule(), buffer, position, comm); + pack(data.restartKeywords(), buffer, position, comm); + pack(data.saveKeywords(), buffer, position, comm); +} + +void pack(const IOConfig& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.getWriteINITFile(), buffer, position, comm); + pack(data.getWriteEGRIDFile(), buffer, position, comm); + pack(data.getUNIFIN(), buffer, position, comm); + pack(data.getUNIFOUT(), buffer, position, comm); + pack(data.getFMTIN(), buffer, position, comm); + pack(data.getFMTOUT(), buffer, position, comm); + pack(data.getFirstRestartStep(), buffer, position, comm); + pack(data.getDeckFileName(), buffer, position, comm); + pack(data.getOutputEnabled(), buffer, position, comm); + pack(data.getOutputDir(), buffer, position, comm); + pack(data.getNoSim(), buffer, position, comm); + pack(data.getBaseName(), buffer, position, comm); + pack(data.getEclCompatibleRST(), buffer, position, comm); +} + +void pack(const Phases& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + pack(data.getBits(), buffer, position, comm); +} + /// unpack routines template @@ -785,6 +887,17 @@ void unpack(OrderedMap& data, std::vector& buffer, int& positio data = OrderedMap(index, storage); } +template +void unpack(DynamicState& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + std::vector ddata; + size_t initial_range; + unpack(ddata, buffer, position, comm); + unpack(initial_range, buffer, position, comm); + data = DynamicState(ddata, initial_range); +} + void unpack(char* str, std::size_t length, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm) { @@ -1061,6 +1174,72 @@ void unpack(SimulationConfig& data, std::vector& buffer, int& position, data = SimulationConfig(thresholdPressure, useCPR, DISGAS, VAPOIL, isThermal); } +void unpack(TimeMap& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + std::vector timeList; + std::vector firstStepMonths; + std::vector firstStepYears; + unpack(timeList, buffer, position, comm); + unpack(firstStepMonths, buffer, position, comm); + unpack(firstStepYears, buffer, position, comm); + + data = TimeMap(timeList, firstStepMonths, firstStepYears); +} + +void unpack(RestartConfig& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + TimeMap timemap; + int firstRstStep; + bool writeInitialRst; + DynamicState restart_sched; + DynamicState> restart_keyw; + std::vector save_keyw; + unpack(timemap, buffer, position, comm); + unpack(firstRstStep, buffer, position, comm); + unpack(writeInitialRst, buffer, position, comm); + unpack(restart_sched, buffer, position, comm); + unpack(restart_keyw, buffer, position, comm); + unpack(save_keyw, buffer, position, comm); + data = RestartConfig(timemap, firstRstStep, writeInitialRst, restart_sched, + restart_keyw, save_keyw); +} + +void unpack(IOConfig& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + bool write_init, write_egrid, unifin, unifout, fmtin, fmtout; + int firstRestartStep; + std::string deck_name, output_dir, base_name; + bool output_enabled, no_sim, ecl_compatible_rst; + + unpack(write_init, buffer, position, comm); + unpack(write_egrid, buffer, position, comm); + unpack(unifin, buffer, position, comm); + unpack(unifout, buffer, position, comm); + unpack(fmtin, buffer, position, comm); + unpack(fmtout, buffer, position, comm); + unpack(firstRestartStep, buffer, position, comm); + unpack(deck_name, buffer, position, comm); + unpack(output_enabled, buffer, position, comm); + unpack(output_dir, buffer, position, comm); + unpack(no_sim, buffer, position, comm); + unpack(base_name, buffer, position, comm); + unpack(ecl_compatible_rst, buffer, position, comm); + data = IOConfig(write_init, write_egrid, unifin, unifout, fmtin, fmtout, + firstRestartStep, deck_name, output_enabled, output_dir, + no_sim, base_name, ecl_compatible_rst); +} + +void unpack(Phases& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm) +{ + unsigned long bits; + unpack(bits, buffer, position, comm); + data = Phases(std::bitset(bits)); +} + } // 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 3516910a4..997cd3ad3 100644 --- a/opm/simulators/utils/ParallelRestart.hpp +++ b/opm/simulators/utils/ParallelRestart.hpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include @@ -44,12 +46,17 @@ class EquilRecord; class FoamConfig; class FoamData; class InitConfig; +class IOConfig; class NNC; struct NNCdata; +class Phases; +class RestartConfig; +class RestartSchedule; class Rock2dTable; class Rock2dtrTable; class SimulationConfig; class SimpleTable; +class Tabdims; class TableColumn; class TableContainer; class TableSchema; @@ -101,6 +108,9 @@ std::size_t packSize(const std::unordered_map& data, Dune::MPIHelpe template std::size_t packSize(const OrderedMap& data, Dune::MPIHelper::MPICommunicator comm); +template +std::size_t packSize(const DynamicState& data, Dune::MPIHelper::MPICommunicator comm); + ////// pack routines template @@ -152,6 +162,10 @@ template void pack(const OrderedMap& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void pack(const DynamicState& data, std::vector& buffer, + int& position, Dune::MPIHelper::MPICommunicator comm); + void pack(const char* str, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); @@ -206,6 +220,10 @@ template void unpack(OrderedMap& data, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); +template +void unpack(DynamicState& data, std::vector& buffer, int& position, + Dune::MPIHelper::MPICommunicator comm); + void unpack(char* str, std::size_t length, std::vector& buffer, int& position, Dune::MPIHelper::MPICommunicator comm); @@ -232,19 +250,26 @@ ADD_PACK_PROTOTYPES(EquilRecord) ADD_PACK_PROTOTYPES(FoamConfig) ADD_PACK_PROTOTYPES(FoamData) ADD_PACK_PROTOTYPES(InitConfig) +ADD_PACK_PROTOTYPES(IOConfig) ADD_PACK_PROTOTYPES(NNC) ADD_PACK_PROTOTYPES(NNCdata) +ADD_PACK_PROTOTYPES(Phases) +ADD_PACK_PROTOTYPES(RestartConfig) ADD_PACK_PROTOTYPES(RestartKey) +ADD_PACK_PROTOTYPES(RestartSchedule) ADD_PACK_PROTOTYPES(RestartValue) ADD_PACK_PROTOTYPES(Rock2dTable) ADD_PACK_PROTOTYPES(Rock2dtrTable) ADD_PACK_PROTOTYPES(std::string) ADD_PACK_PROTOTYPES(SimulationConfig) ADD_PACK_PROTOTYPES(SimpleTable) +ADD_PACK_PROTOTYPES(Tabdims) ADD_PACK_PROTOTYPES(TableColumn) ADD_PACK_PROTOTYPES(TableContainer) ADD_PACK_PROTOTYPES(TableSchema) ADD_PACK_PROTOTYPES(ThresholdPressure) +ADD_PACK_PROTOTYPES(TimeMap) +ADD_PACK_PROTOTYPES(TimeMap::StepData) } // end namespace Mpi RestartValue loadParallelRestart(const EclipseIO* eclIO, SummaryState& summaryState, diff --git a/tests/test_ParallelRestart.cpp b/tests/test_ParallelRestart.cpp index c76682e17..7d599d841 100644 --- a/tests/test_ParallelRestart.cpp +++ b/tests/test_ParallelRestart.cpp @@ -25,17 +25,22 @@ #include #include +#include #include #include #include #include #include +#include +#include +#include #include #include #include #include #include #include +#include #include #include #include @@ -166,6 +171,14 @@ Opm::FoamData getFoamData() #endif +Opm::TimeMap getTimeMap() +{ + return Opm::TimeMap({123}, + {{1, Opm::TimeStampUTC(123)}}, + {{2, Opm::TimeStampUTC(456)}}); +} + + } @@ -478,6 +491,86 @@ BOOST_AUTO_TEST_CASE(SimulationConfig) } +BOOST_AUTO_TEST_CASE(RestartSchedule) +{ +#if HAVE_MPI + Opm::RestartSchedule val1(1, 2, 3); + 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(StepData) +{ +#if HAVE_MPI + Opm::TimeMap::StepData val1{1, Opm::TimeStampUTC(123456)}; + 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(TimeMap) +{ +#if HAVE_MPI + Opm::TimeMap val1 = getTimeMap(); + 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(RestartConfig) +{ +#if HAVE_MPI + Opm::DynamicState rsched({Opm::RestartSchedule(1, 2, 3)}, 2); + Opm::DynamicState> rkw({{{"test",3}}}, 3); + Opm::RestartConfig val1(getTimeMap(), 1, true, rsched, rkw, {false, true}); + 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(IOConfig) +{ +#if HAVE_MPI + Opm::IOConfig val1(true, false, true, false, false, true, 1, "test1", true, + "test2", true, "test3", 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(Phases) +{ +#if HAVE_MPI + Opm::Phases val1(true, true, true, false, true, false, 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(Tabdims) +{ +#if HAVE_MPI + Opm::Tabdims val1(1,2,3,4,5,6); + 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;