Distribute Group Values at Parallel Restart

Mostly to prepare for restoring the groups' active controls from
restart information.
This commit is contained in:
Bård Skaflestad 2020-08-28 08:39:09 +02:00
parent a0373ed428
commit bdc34a7580
3 changed files with 145 additions and 6 deletions

View File

@ -206,6 +206,7 @@ std::size_t packSize(const std::array<T,N>& data, Dune::MPIHelper::MPICommunicat
HANDLE_AS_POD(data::Connection)
HANDLE_AS_POD(data::CurrentControl)
HANDLE_AS_POD(data::GroupConstraints)
HANDLE_AS_POD(data::Rates)
HANDLE_AS_POD(data::Segment)
@ -217,6 +218,18 @@ std::size_t packSize(const data::GuideRateValue&, Dune::MPIHelper::MPICommunicat
+ packSize(std::array<double, nItem>{}, comm);
}
std::size_t packSize(const data::GroupGuideRates& data, Dune::MPIHelper::MPICommunicator comm)
{
return packSize(data.production, comm)
+ packSize(data.injection, comm);
}
std::size_t packSize(const data::GroupData& data, Dune::MPIHelper::MPICommunicator comm)
{
return packSize(data.currentControl, comm)
+ packSize(data.guideRates, comm);
}
std::size_t packSize(const data::Well& data, Dune::MPIHelper::MPICommunicator comm)
{
std::size_t size = packSize(data.rates, comm);
@ -247,6 +260,13 @@ std::size_t packSize(const data::Solution& data, Dune::MPIHelper::MPICommunicato
return packSize(static_cast<const std::map< std::string, data::CellData>&>(data), comm);
}
std::size_t packSize(const data::GroupValues& data, Dune::MPIHelper::MPICommunicator comm)
{
// Needs explicit conversion to a supported base type holding the data
// to prevent throwing.
return packSize(static_cast<const std::map<std::string, data::GroupData>&>(data), comm);
}
std::size_t packSize(const data::WellRates& data, Dune::MPIHelper::MPICommunicator comm)
{
// Needs explicit conversion to a supported base type holding the data
@ -256,7 +276,10 @@ std::size_t packSize(const data::WellRates& data, Dune::MPIHelper::MPICommunicat
std::size_t packSize(const RestartValue& data, Dune::MPIHelper::MPICommunicator comm)
{
return packSize(data.solution, comm) + packSize(data.wells, comm) + packSize(data.extra, comm);
return packSize(data.solution, comm)
+ packSize(data.wells, comm)
+ packSize(data.groups, comm)
+ packSize(data.extra, comm);
}
////// pack routines
@ -467,6 +490,20 @@ void pack(const data::GuideRateValue& data, std::vector<char>& buffer, int& posi
pack(val, buffer, position, comm);
}
void pack(const data::GroupGuideRates& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
pack(data.production, buffer, position, comm);
pack(data.injection, buffer, position, comm);
}
void pack(const data::GroupData& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
pack(data.currentControl, buffer, position, comm);
pack(data.guideRates, buffer, position, comm);
}
void pack(const data::Well& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
@ -515,11 +552,21 @@ void pack(const data::WellRates& data, std::vector<char>& buffer, int& position,
buffer, position, comm);
}
void pack(const data::GroupValues& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
// Needs explicit conversion to a supported base type holding the data
// to prevent throwing.
pack(static_cast<const std::map< std::string, data::GroupData>&>(data),
buffer, position, comm);
}
void pack(const RestartValue& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
pack(data.solution, buffer, position, comm);
pack(data.wells, buffer, position, comm);
pack(data.groups, buffer, position, comm);
pack(data.extra, buffer, position, comm);
}
@ -761,6 +808,20 @@ void unpack(data::GuideRateValue& data, std::vector<char>& buffer, int& position
}
}
void unpack(data::GroupGuideRates& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
unpack(data.production, buffer, position, comm);
unpack(data.injection, buffer, position, comm);
}
void unpack(data::GroupData& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
unpack(data.currentControl, buffer, position, comm);
unpack(data.guideRates, buffer, position, comm);
}
void unpack(RestartKey& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
@ -795,11 +856,21 @@ void unpack(data::WellRates& data, std::vector<char>& buffer, int& position,
buffer, position, comm);
}
void unpack(data::GroupValues& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
// Needs explicit conversion to a supported base type holding the data
// to prevent throwing.
unpack(static_cast<std::map< std::string, data::GroupData>&>(data),
buffer, position, comm);
}
void unpack(RestartValue& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
unpack(data.solution, buffer, position, comm);
unpack(data.wells, buffer, position, comm);
unpack(data.groups, buffer, position, comm);
unpack(data.extra, buffer, position, comm);
}

View File

@ -307,6 +307,10 @@ ADD_PACK_PROTOTYPES(data::Rates)
ADD_PACK_PROTOTYPES(data::Segment)
ADD_PACK_PROTOTYPES(data::Solution)
ADD_PACK_PROTOTYPES(data::GuideRateValue)
ADD_PACK_PROTOTYPES(data::GroupConstraints)
ADD_PACK_PROTOTYPES(data::GroupGuideRates)
ADD_PACK_PROTOTYPES(data::GroupData)
ADD_PACK_PROTOTYPES(data::GroupValues)
ADD_PACK_PROTOTYPES(data::Well)
ADD_PACK_PROTOTYPES(data::WellRates)
ADD_PACK_PROTOTYPES(RestartKey)

View File

@ -25,6 +25,7 @@
#include <boost/test/unit_test.hpp>
#include <tuple>
#include <utility>
#include <opm/common/OpmLog/Location.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
@ -214,7 +215,40 @@ Opm::data::Well getWell()
return well1;
}
Opm::data::GroupGuideRates getGroupGuideRates()
{
using Item = Opm::data::GuideRateValue::Item;
auto gr = Opm::data::GroupGuideRates{};
gr.production.set(Item::Oil , 999.888)
.set(Item::Gas , 8888.777)
.set(Item::ResV, 12345.678);
gr.injection.set(Item::Gas , 9876.543)
.set(Item::Water, 2345.987);
return gr;
}
Opm::data::GroupConstraints getGroupConstraints()
{
using PMode = ::Opm::Group::ProductionCMode;
using IMode = ::Opm::Group::InjectionCMode;
return Opm::data::GroupConstraints{}
.set(PMode::ORAT, // Production
IMode::VREP, // Gas Injection
IMode::NONE); // Water Injection
}
Opm::data::GroupData getGroupData()
{
return Opm::data::GroupData {
getGroupConstraints(),
getGroupGuideRates()
};
}
}
@ -326,6 +360,29 @@ BOOST_AUTO_TEST_CASE(WellRates)
DO_CHECKS(data::WellRates)
}
BOOST_AUTO_TEST_CASE(dataGroupConstraints)
{
const auto val1 = getGroupConstraints();
const auto val2 = PackUnpack(val1);
DO_CHECKS(data::GroupConstraints)
}
BOOST_AUTO_TEST_CASE(dataGroupGuideRates)
{
const auto val1 = getGroupData().guideRates;
const auto val2 = PackUnpack(val1);
DO_CHECKS(data::GroupGuideRates)
}
BOOST_AUTO_TEST_CASE(dataGroupData)
{
const auto val1 = getGroupData();
const auto val2 = PackUnpack(val1);
DO_CHECKS(data::GroupData)
}
BOOST_AUTO_TEST_CASE(CellData)
{
@ -348,11 +405,18 @@ BOOST_AUTO_TEST_CASE(RestartKey)
BOOST_AUTO_TEST_CASE(RestartValue)
{
Opm::data::WellRates wells1;
Opm::data::GroupValues groups1;
wells1.insert({"test_well", getWell()});
Opm::RestartValue val1(getSolution(), wells1, groups1);
auto val2 = PackUnpack(val1);
auto wells1 = Opm::data::WellRates {{
{ "test_well", getWell() },
}};
auto groups1 = Opm::data::GroupValues {{
{ "test_group1", getGroupData() },
}};
const auto val1 = Opm::RestartValue {
getSolution(), std::move(wells1), std::move(groups1)
};
const auto val2 = PackUnpack(val1);
DO_CHECKS(RestartValue)
}