add mpi serialization for RestartConfig

This commit is contained in:
Arne Morten Kvarving
2019-12-02 09:38:52 +01:00
parent a869641ee4
commit 3470760307
3 changed files with 55 additions and 0 deletions

View File

@@ -357,6 +357,16 @@ std::size_t packSize(const TimeMap& data, Dune::MPIHelper::MPICommunicator 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);
}
////// pack routines
template<class T>
@@ -703,6 +713,17 @@ void pack(const TimeMap& data, std::vector<char>& buffer, int& position,
pack(data.firstTimeStepYears(), buffer, position, comm);
}
void pack(const RestartConfig& data, std::vector<char>& 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);
}
/// unpack routines
template<class T>
@@ -1117,6 +1138,25 @@ void unpack(TimeMap& data, std::vector<char>& buffer, int& position,
data = TimeMap(timeList, firstStepMonths, firstStepYears);
}
void unpack(RestartConfig& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
TimeMap timemap;
int firstRstStep;
bool writeInitialRst;
DynamicState<RestartSchedule> restart_sched;
DynamicState<std::map<std::string,int>> restart_keyw;
std::vector<bool> 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);
}
} // end namespace Mpi
RestartValue loadParallelRestart(const EclipseIO* eclIO, SummaryState& summaryState,
const std::vector<Opm::RestartKey>& solutionKeys,

View File

@@ -48,6 +48,7 @@ class FoamData;
class InitConfig;
class NNC;
struct NNCdata;
class RestartConfig;
class RestartSchedule;
class Rock2dTable;
class Rock2dtrTable;
@@ -248,6 +249,7 @@ ADD_PACK_PROTOTYPES(FoamData)
ADD_PACK_PROTOTYPES(InitConfig)
ADD_PACK_PROTOTYPES(NNC)
ADD_PACK_PROTOTYPES(NNCdata)
ADD_PACK_PROTOTYPES(RestartConfig)
ADD_PACK_PROTOTYPES(RestartKey)
ADD_PACK_PROTOTYPES(RestartSchedule)
ADD_PACK_PROTOTYPES(RestartValue)

View File

@@ -521,6 +521,19 @@ BOOST_AUTO_TEST_CASE(TimeMap)
}
BOOST_AUTO_TEST_CASE(RestartConfig)
{
#if HAVE_MPI
Opm::DynamicState<Opm::RestartSchedule> rsched({Opm::RestartSchedule(1, 2, 3)}, 2);
Opm::DynamicState<std::map<std::string,int>> 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
}
bool init_unit_test_func()
{
return true;