add mpi serialization for Well

This commit is contained in:
Arne Morten Kvarving 2019-12-11 11:45:13 +01:00
parent c31d209295
commit d01a389396
3 changed files with 172 additions and 1 deletions

View File

@ -1158,6 +1158,42 @@ std::size_t packSize(const WellSegments& data,
} }
std::size_t packSize(const Well& data,
Dune::MPIHelper::MPICommunicator comm)
{
std::size_t size = packSize(data.name(), comm) +
packSize(data.groupName(), comm) +
packSize(data.firstTimeStep(), comm) +
packSize(data.seqIndex(), comm) +
packSize(data.getHeadI(), comm) +
packSize(data.getHeadJ(), comm) +
packSize(data.getRefDepth(), comm) +
packSize(data.getPreferredPhase(), comm) +
packSize(data.getWellConnectionOrdering(), comm) +
packSize(data.units(), comm) +
packSize(data.udqUndefined(), comm) +
packSize(data.getStatus(), comm) +
packSize(data.getDrainageRadius(), comm) +
packSize(data.getAllowCrossFlow(), comm) +
packSize(data.getAutomaticShutIn(), comm) +
packSize(data.isProducer(), comm) +
packSize(data.wellGuideRate(), comm) +
packSize(data.getEfficiencyFactor(), comm) +
packSize(data.getSolventFraction(), comm) +
packSize(data.predictionMode(), comm) +
packSize(data.getEconLimits(), comm) +
packSize(data.getFoamProperties(), comm) +
packSize(data.getPolymerProperties(), comm) +
packSize(data.getTracerProperties(), comm) +
packSize(data.getProductionProperties(), comm) +
packSize(data.getInjectionProperties(), comm) +
packSize(data.hasSegments(), comm);
if (data.hasSegments())
size += packSize(data.getSegments(), comm);
return size;
}
////// pack routines ////// pack routines
template<class T> template<class T>
@ -2330,6 +2366,41 @@ void pack(const WellSegments& data,
pack(data.segmentNumberIndex(), buffer, position, comm); pack(data.segmentNumberIndex(), buffer, position, comm);
} }
void pack(const Well& data,
std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
pack(data.name(), buffer, position, comm);
pack(data.groupName(), buffer, position, comm);
pack(data.firstTimeStep(), buffer, position, comm);
pack(data.seqIndex(), buffer, position, comm);
pack(data.getHeadI(), buffer, position, comm);
pack(data.getHeadJ(), buffer, position, comm);
pack(data.getRefDepth(), buffer, position, comm);
pack(data.getPreferredPhase(), buffer, position, comm);
pack(data.getWellConnectionOrdering(), buffer, position, comm);
pack(data.units(), buffer, position, comm);
pack(data.udqUndefined(), buffer, position, comm);
pack(data.getStatus(), buffer, position, comm);
pack(data.getDrainageRadius(), buffer, position, comm);
pack(data.getAllowCrossFlow(), buffer, position, comm);
pack(data.getAutomaticShutIn(), buffer, position, comm);
pack(data.isProducer(), buffer, position, comm);
pack(data.wellGuideRate(), buffer, position, comm);
pack(data.getEfficiencyFactor(), buffer, position, comm);
pack(data.getSolventFraction(), buffer, position, comm);
pack(data.predictionMode(), buffer, position, comm);
pack(data.getEconLimits(), buffer, position, comm);
pack(data.getFoamProperties(), buffer, position, comm);
pack(data.getPolymerProperties(), buffer, position, comm);
pack(data.getTracerProperties(), buffer, position, comm);
pack(data.getProductionProperties(), buffer, position, comm);
pack(data.getInjectionProperties(), buffer, position, comm);
pack(data.hasSegments(), buffer, position, comm);
if (data.hasSegments())
pack(data.getSegments(), buffer, position, comm);
}
/// unpack routines /// unpack routines
template<class T> template<class T>
@ -3972,6 +4043,74 @@ void unpack(WellSegments& data,
multiPhaseModel, segments, segmentNumberIndex); multiPhaseModel, segments, segmentNumberIndex);
} }
void unpack(Well& data,
std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
std::string name, groupName;
std::size_t firstTimeStep, seqIndex;
int headI, headJ;
double ref_depth;
Phase phase;
Connection::Order ordering;
UnitSystem units;
double udq_undefined;
Well::Status status;
double drainageRadius;
bool allowCrossFlow, automaticShutIn, isProducer;
Well::WellGuideRate guideRate;
double efficiencyFactor;
double solventFraction;
bool prediction_mode;
auto econLimits = std::make_shared<WellEconProductionLimits>();
auto foamProperties = std::make_shared<WellFoamProperties>();
auto polymerProperties = std::make_shared<WellPolymerProperties>();
auto tracerProperties = std::make_shared<WellTracerProperties>();
auto connection = std::make_shared<WellConnections>();
auto production = std::make_shared<Well::WellProductionProperties>();
auto injection = std::make_shared<Well::WellInjectionProperties>();
std::shared_ptr<WellSegments> segments;
unpack(name, buffer, position, comm);
unpack(groupName, buffer, position, comm);
unpack(firstTimeStep, buffer, position, comm);
unpack(seqIndex, buffer, position, comm);
unpack(headI, buffer, position, comm);
unpack(headJ, buffer, position, comm);
unpack(ref_depth, buffer, position, comm);
unpack(phase, buffer, position, comm);
unpack(ordering, buffer, position, comm);
unpack(units, buffer, position, comm);
unpack(udq_undefined, buffer, position, comm);
unpack(status, buffer, position, comm);
unpack(drainageRadius, buffer, position, comm);
unpack(allowCrossFlow, buffer, position, comm);
unpack(automaticShutIn, buffer, position, comm);
unpack(isProducer, buffer, position, comm);
unpack(guideRate, buffer, position, comm);
unpack(efficiencyFactor, buffer, position, comm);
unpack(solventFraction, buffer, position, comm);
unpack(prediction_mode, buffer, position, comm);
unpack(*econLimits, buffer, position, comm);
unpack(*foamProperties, buffer, position, comm);
unpack(*polymerProperties, buffer, position, comm);
unpack(*tracerProperties, buffer, position, comm);
unpack(*production, buffer, position, comm);
unpack(*injection, buffer, position, comm);
bool hasSegments;
unpack(hasSegments, buffer, position, comm);
if (hasSegments) {
segments = std::make_shared<WellSegments>();
unpack(*segments, buffer, position, comm);
}
data = Well(name, groupName, firstTimeStep, seqIndex, headI, headJ,
ref_depth, phase, ordering, units, udq_undefined, status,
drainageRadius, allowCrossFlow, automaticShutIn, isProducer,
guideRate, efficiencyFactor, solventFraction, prediction_mode,
econLimits, foamProperties, polymerProperties, tracerProperties,
connection, production, injection, segments);
}
#define INSTANTIATE_PACK_VECTOR(T) \ #define INSTANTIATE_PACK_VECTOR(T) \
template std::size_t packSize(const std::vector<T>& data, \ template std::size_t packSize(const std::vector<T>& data, \
Dune::MPIHelper::MPICommunicator comm); \ Dune::MPIHelper::MPICommunicator comm); \

View File

@ -604,6 +604,7 @@ ADD_PACK_PROTOTYPES(VISCREFRecord)
ADD_PACK_PROTOTYPES(ViscrefTable) ADD_PACK_PROTOTYPES(ViscrefTable)
ADD_PACK_PROTOTYPES(WATDENTRecord) ADD_PACK_PROTOTYPES(WATDENTRecord)
ADD_PACK_PROTOTYPES(WatdentTable) ADD_PACK_PROTOTYPES(WatdentTable)
ADD_PACK_PROTOTYPES(Well)
ADD_PACK_PROTOTYPES(Well::WellGuideRate) ADD_PACK_PROTOTYPES(Well::WellGuideRate)
ADD_PACK_PROTOTYPES(Well::WellInjectionProperties) ADD_PACK_PROTOTYPES(Well::WellInjectionProperties)
ADD_PACK_PROTOTYPES(Well::WellProductionProperties) ADD_PACK_PROTOTYPES(Well::WellProductionProperties)

View File

@ -238,6 +238,26 @@ Opm::TableContainer getTableContainer()
} }
Opm::Well getFullWell()
{
Opm::UnitSystem unitSystem;
return Opm::Well("test1", "test2", 1, 2, 3, 4, 5.0,
Opm::Phase::WATER, Opm::Connection::Order::DEPTH,
unitSystem, 6.0, Opm::Well::Status::SHUT,
7.0, true, true, false,
Opm::Well::WellGuideRate{true, 1.0, Opm::Well::GuideRateTarget::COMB, 2.0},
8.0, 9.0, false,
std::make_shared<Opm::WellEconProductionLimits>(),
std::make_shared<Opm::WellFoamProperties>(),
std::make_shared<Opm::WellPolymerProperties>(),
std::make_shared<Opm::WellTracerProperties>(),
std::make_shared<Opm::WellConnections>(),
std::make_shared<Opm::Well::WellProductionProperties>(),
std::make_shared<Opm::Well::WellInjectionProperties>(),
std::make_shared<Opm::WellSegments>());
}
Opm::VFPInjTable getVFPInjTable() Opm::VFPInjTable getVFPInjTable()
{ {
Opm::VFPInjTable::array_type table; Opm::VFPInjTable::array_type table;
@ -342,7 +362,7 @@ BOOST_AUTO_TEST_CASE(dataSegment)
} }
BOOST_AUTO_TEST_CASE(Well) BOOST_AUTO_TEST_CASE(dataWell)
{ {
#if HAVE_MPI #if HAVE_MPI
Opm::data::Well well1 = getWell(); Opm::data::Well well1 = getWell();
@ -1550,6 +1570,17 @@ BOOST_AUTO_TEST_CASE(WellSegments)
} }
BOOST_AUTO_TEST_CASE(Well)
{
#ifdef HAVE_MPI
Opm::Well val1 = getFullWell();
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() bool init_unit_test_func()
{ {
return true; return true;