add mpi serialization for UnitSystem

This commit is contained in:
Arne Morten Kvarving 2019-12-11 11:43:46 +01:00
parent e53072faf5
commit 5bc506cd3b
3 changed files with 48 additions and 0 deletions

View File

@ -1134,6 +1134,15 @@ std::size_t packSize(const Dimension& data,
packSize(data.getSIOffset(), comm);
}
std::size_t packSize(const UnitSystem& data,
Dune::MPIHelper::MPICommunicator comm)
{
return packSize(data.getName(), comm) +
packSize(data.getType(), comm) +
packSize(data.getDimensions(), comm) +
packSize(data.use_count(), comm);
}
////// pack routines
template<class T>
@ -2281,6 +2290,16 @@ void pack(const Dimension& data,
pack(data.getSIOffset(), buffer, position, comm);
}
void pack(const UnitSystem& data,
std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
pack(data.getName(), buffer, position, comm);
pack(data.getType(), buffer, position, comm);
pack(data.getDimensions(), buffer, position, comm);
pack(data.use_count(), buffer, position, comm);
}
/// unpack routines
template<class T>
@ -3881,6 +3900,22 @@ void unpack(Dimension& data,
data = Dimension(name, siScaling, siOffset);
}
void unpack(UnitSystem& data,
std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
std::string name;
UnitSystem::UnitType type;
std::map<std::string, Dimension> dimensions;
size_t use_count;
unpack(name, buffer, position, comm);
unpack(type, buffer, position, comm);
unpack(dimensions, buffer, position, comm);
unpack(use_count, buffer, position, comm);
data = UnitSystem(name, type, dimensions, use_count);
}
#define INSTANTIATE_PACK_VECTOR(T) \
template std::size_t packSize(const std::vector<T>& data, \
Dune::MPIHelper::MPICommunicator comm); \

View File

@ -111,6 +111,7 @@ class TableSchema;
class ThresholdPressure;
class UDAValue;
class UDQParams;
class UnitSystem;
class Valve;
class VFPInjTable;
class VFPProdTable;
@ -594,6 +595,7 @@ ADD_PACK_PROTOTYPES(TimeMap)
ADD_PACK_PROTOTYPES(TimeMap::StepData)
ADD_PACK_PROTOTYPES(UDAValue)
ADD_PACK_PROTOTYPES(UDQParams)
ADD_PACK_PROTOTYPES(UnitSystem)
ADD_PACK_PROTOTYPES(Valve)
ADD_PACK_PROTOTYPES(VFPInjTable)
ADD_PACK_PROTOTYPES(VFPProdTable)

View File

@ -1518,6 +1518,17 @@ BOOST_AUTO_TEST_CASE(Dimension)
}
BOOST_AUTO_TEST_CASE(UnitSystem)
{
#ifdef HAVE_MPI
Opm::UnitSystem val1(Opm::UnitSystem::UnitType::UNIT_TYPE_METRIC);
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;