add mpi serialization for Segment

This commit is contained in:
Arne Morten Kvarving 2019-12-10 13:47:01 +01:00
parent badc59ca6f
commit 781625ec63
3 changed files with 98 additions and 1 deletions

View File

@ -1093,6 +1093,25 @@ std::size_t packSize(const Valve& data,
packSize(data.status(), comm);
}
std::size_t packSize(const Segment& data,
Dune::MPIHelper::MPICommunicator comm)
{
return packSize(data.segmentNumber(), comm) +
packSize(data.branchNumber(), comm) +
packSize(data.outletSegment(), comm) +
packSize(data.inletSegments(), comm) +
packSize(data.totalLength(), comm) +
packSize(data.depth(), comm) +
packSize(data.internalDiameter(), comm) +
packSize(data.roughness(), comm) +
packSize(data.crossArea(), comm) +
packSize(data.volume(), comm) +
packSize(data.dataReady(), comm) +
packSize(data.segmentType(), comm) +
packSize(data.spiralICD(), comm) +
packSize(data.getValve(), comm);
}
template<class T>
std::size_t packSize(const std::shared_ptr<T>& data,
Dune::MPIHelper::MPICommunicator comm)
@ -1104,6 +1123,9 @@ std::size_t packSize(const std::shared_ptr<T>& data,
return size;
}
template std::size_t packSize(const std::shared_ptr<SpiralICD>& data,
Dune::MPIHelper::MPICommunicator comm);
////// pack routines
template<class T>
@ -2210,6 +2232,26 @@ void pack(const Valve& data,
pack(data.status(), buffer, position, comm);
}
void pack(const Segment& data,
std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
pack(data.segmentNumber(), buffer, position, comm);
pack(data.branchNumber(), buffer, position, comm);
pack(data.outletSegment(), buffer, position, comm);
pack(data.inletSegments(), buffer, position, comm);
pack(data.totalLength(), buffer, position, comm);
pack(data.depth(), buffer, position, comm);
pack(data.internalDiameter(), buffer, position, comm);
pack(data.roughness(), buffer, position, comm);
pack(data.crossArea(), buffer, position, comm);
pack(data.volume(), buffer, position, comm);
pack(data.dataReady(), buffer, position, comm);
pack(data.segmentType(), buffer, position, comm);
pack(data.spiralICD(), buffer, position, comm);
pack(data.getValve(), buffer, position, comm);
}
template<class T>
void pack(const std::shared_ptr<T>& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
@ -2219,6 +2261,9 @@ void pack(const std::shared_ptr<T>& data, std::vector<char>& buffer, int& positi
pack(*data, buffer, position, comm);
}
template void pack(const std::shared_ptr<SpiralICD>& data, std::vector<char>& buffer,
int& position, Dune::MPIHelper::MPICommunicator comm);
/// unpack routines
template<class T>
@ -3758,6 +3803,38 @@ void unpack(Valve& data,
pipeCrossArea, status);
}
void unpack(Segment& data,
std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
int segmentNumber, branchNumber, outletSegment;
std::vector<int> inletSegments;
double totalLength, depth, internalDiameter, roughness, crossArea, volume;
bool dataReady;
Segment::SegmentType segmentType;
std::shared_ptr<SpiralICD> spiralICD;
std::shared_ptr<Valve> valve;
unpack(segmentNumber, buffer, position, comm);
unpack(branchNumber, buffer, position, comm);
unpack(outletSegment, buffer, position, comm);
unpack(inletSegments, buffer, position, comm);
unpack(totalLength, buffer, position, comm);
unpack(depth, buffer, position, comm);
unpack(internalDiameter, buffer, position, comm);
unpack(roughness, buffer, position, comm);
unpack(crossArea, buffer, position, comm);
unpack(volume, buffer, position, comm);
unpack(dataReady, buffer, position, comm);
unpack(segmentType, buffer, position, comm);
unpack(spiralICD, buffer, position, comm);
unpack(valve, buffer, position, comm);
data = Segment(segmentNumber, branchNumber, outletSegment,
inletSegments, totalLength, depth,
internalDiameter, roughness, crossArea,
volume, dataReady, segmentType, spiralICD, valve);
}
template<class T>
void unpack(std::shared_ptr<T>& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
@ -3770,6 +3847,10 @@ void unpack(std::shared_ptr<T>& data, std::vector<char>& buffer, int& position,
}
}
template void unpack(std::shared_ptr<SpiralICD>& data,
std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm);
#define INSTANTIATE_PACK_VECTOR(T) \
template std::size_t packSize(const std::vector<T>& data, \
Dune::MPIHelper::MPICommunicator comm); \

View File

@ -96,6 +96,7 @@ class RockTable;
class Rock2dTable;
class Rock2dtrTable;
class Runspec;
class Segment;
class SimulationConfig;
class SimpleTable;
class SkprpolyTable;
@ -575,6 +576,7 @@ ADD_PACK_PROTOTYPES(Rock2dTable)
ADD_PACK_PROTOTYPES(Rock2dtrTable)
ADD_PACK_PROTOTYPES(Runspec)
ADD_PACK_PROTOTYPES(std::string)
ADD_PACK_PROTOTYPES(Segment)
ADD_PACK_PROTOTYPES(SimulationConfig)
ADD_PACK_PROTOTYPES(SimpleTable)
ADD_PACK_PROTOTYPES(SkprpolyTable)

View File

@ -330,7 +330,7 @@ BOOST_AUTO_TEST_CASE(dataConnection)
}
BOOST_AUTO_TEST_CASE(Segment)
BOOST_AUTO_TEST_CASE(dataSegment)
{
#if HAVE_MPI
Opm::data::Segment seg1 = getSegment();
@ -1493,6 +1493,20 @@ BOOST_AUTO_TEST_CASE(Valve)
}
BOOST_AUTO_TEST_CASE(Segment)
{
#ifdef HAVE_MPI
Opm::Segment val1(1, 2, 3, {1, 2}, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, false,
Opm::Segment::SegmentType::SICD,
std::make_shared<Opm::SpiralICD>(),
std::make_shared<Opm::Valve>());
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;