Gather WBP pressure data before summary eval

This commit is contained in:
Joakim Hove 2020-12-01 09:09:06 +01:00
parent 1d86e2dc97
commit 72905f3e3b
3 changed files with 101 additions and 12 deletions

View File

@ -655,14 +655,70 @@ public:
};
class PackUnPackWBPData : public P2PCommunicatorType::DataHandleInterface
{
const std::map<std::size_t, double>& localWBPData_;
std::map<std::size_t, double>& globalWBPValues_;
public:
PackUnPackWBPData(const std::map<std::size_t, double>& localWBPData,
std::map<std::size_t, double>& globalWBPValues,
bool isIORank)
: localWBPData_(localWBPData)
, globalWBPValues_(globalWBPValues)
{
if (isIORank) {
MessageBufferType buffer;
pack(0, buffer);
// pass a dummyLink to satisfy virtual class
int dummyLink = -1;
unpack(dummyLink, buffer);
}
}
// pack all data associated with link
void pack(int link, MessageBufferType& buffer)
{
// we should only get one link
if (link != 0)
throw std::logic_error("link in method pack is not 0 as expected");
// write all block data
unsigned int size = localWBPData_.size();
buffer.write(size);
for (const auto& [global_index, wbp_value] : localWBPData_) {
buffer.write(global_index);
buffer.write(wbp_value);
}
}
// unpack all data associated with link
void unpack(int /*link*/, MessageBufferType& buffer)
{
// read all block data
unsigned int size = 0;
buffer.read(size);
for (size_t i = 0; i < size; ++i) {
std::size_t idx;
double data;
buffer.read(idx);
buffer.read(data);
globalWBPValues_[idx] = data;
}
}
};
// gather solution to rank 0 for EclipseWriter
void collect(const Opm::data::Solution& localCellData,
const std::map<std::pair<std::string, int>, double>& localBlockData,
const std::map<std::size_t, double>& localWBPData,
const Opm::data::Wells& localWellData,
const Opm::data::GroupAndNetworkValues& localGroupAndNetworkData)
{
globalCellData_ = {};
globalBlockData_.clear();
globalWBPData_.clear();
globalWellData_.clear();
globalGroupAndNetworkData_.clear();
@ -703,12 +759,17 @@ public:
this->isIORank()
};
PackUnPackWBPData packUnpackWBPData {
localWBPData,
this->globalWBPData_,
this->isIORank()
};
toIORankComm_.exchange(packUnpackCellData);
toIORankComm_.exchange(packUnpackWellData);
toIORankComm_.exchange(packUnpackGroupAndNetworkData);
toIORankComm_.exchange(packUnpackBlockData);
toIORankComm_.exchange(packUnpackWBPData);
#ifndef NDEBUG
// mkae sure every process is on the same page
@ -716,6 +777,9 @@ public:
#endif
}
const std::map<std::size_t, double>& globalWBPData() const
{ return this->globalWBPData_; }
const std::map<std::pair<std::string, int>, double>& globalBlockData() const
{ return globalBlockData_; }
@ -772,6 +836,7 @@ protected:
std::vector<int> globalRanks_;
Opm::data::Solution globalCellData_;
std::map<std::pair<std::string, int>, double> globalBlockData_;
std::map<std::size_t, double> globalWBPData_;
Opm::data::Wells globalWellData_;
Opm::data::GroupAndNetworkValues globalGroupAndNetworkData_;
std::vector<int> localIdxToGlobalIdx_;

View File

@ -225,6 +225,11 @@ public:
}
}
for (const auto& global_index : wbp_index_list) {
if (collectToIORank.isCartIdxOnThisRank(global_index - 1))
this->wbpData_[global_index] = 0.0;
}
forceDisableFipOutput_ = EWOMS_GET_PARAM(TypeTag, bool, ForceDisableFluidInPlaceOutput);
}
@ -837,6 +842,8 @@ public:
if (gasConnectionSaturations_.count(cartesianIdx) > 0) {
gasConnectionSaturations_[cartesianIdx] = Opm::getValue(fs.saturation(gasPhaseIdx));
}
if (this->wbpData_.count(cartesianIdx) > 0)
this->wbpData_[cartesianIdx] = Opm::getValue(fs.pressure(oilPhaseIdx));
// tracers
const auto& tracerModel = simulator_.problem().tracerModel();
@ -1852,6 +1859,10 @@ public:
return 0;
}
const std::map<std::size_t, double>& getWBPData() const {
return this->wbpData_;
}
const std::map<std::pair<std::string, int>, double>& getBlockData()
{ return blockData_; }
@ -2365,6 +2376,7 @@ private:
ScalarBuffer hydrocarbonPoreVolume_;
ScalarBuffer pressureTimesPoreVolume_;
ScalarBuffer pressureTimesHydrocarbonVolume_;
std::map<std::size_t , double> wbpData_;
std::map<std::pair<std::string, int>, double> blockData_;
std::map<size_t, Scalar> oilConnectionPressures_;
std::map<size_t, Scalar> waterConnectionSaturations_;

View File

@ -204,14 +204,12 @@ public:
wbp_index_list = wbp_calculators.index_list();
}
if (collectToIORank_.isParallel()) {
#ifdef HAVE_MPI
const auto& comm = simulator_.vanguard().grid().comm();
unsigned long size = wbp_index_list.size();
MPI_Bcast(&size, 1, MPI_UNSIGNED_LONG, collectToIORank_.ioRank, MPI_COMM_WORLD);
comm.broadcast(&size, 1, collectToIORank_.ioRank);
if (!collectToIORank_.isIORank())
wbp_index_list.resize( size );
MPI_Bcast(wbp_index_list.data(), size * sizeof(std::size_t), MPI_CHAR, collectToIORank_.ioRank, MPI_COMM_WORLD);
#endif
comm.broadcast(wbp_index_list.data(), size, collectToIORank_.ioRank);
}
// create output thread if enabled and rank is I/O rank
// async output is enabled by default if pthread are enabled
@ -256,7 +254,6 @@ public:
void evalSummaryState(bool isSubStep)
{
PAvgCalculatorCollection wbp_calculators;
const int reportStepNum = simulator_.episodeIndex() + 1;
/*
The summary data is not evaluated for timestep 0, that is
@ -294,8 +291,11 @@ public:
this->prepareLocalCellData(isSubStep, reportStepNum);
if (collectToIORank_.isParallel())
collectToIORank_.collect({}, eclOutputModule_->getBlockData(),
localWellData, localGroupAndNetworkData);
collectToIORank_.collect({},
eclOutputModule_->getBlockData(),
eclOutputModule_->getWBPData(),
localWellData,
localGroupAndNetworkData);
std::map<std::string, double> miscSummaryData;
std::map<std::string, std::vector<double>> regionData;
@ -308,9 +308,18 @@ public:
eclOutputModule_->outputInjLog(reportStepNum, isSubStep, forceDisableInjOutput);
eclOutputModule_->outputCumLog(reportStepNum, isSubStep, forceDisableCumOutput);
std::vector<char> buffer;
if (this->collectToIORank_.isIORank()) {
const auto& summary = eclIO_->summary();
auto wbp_calculators = summary.wbp_calculators(reportStepNum);
const auto& wbpData
= this->collectToIORank_.isParallel()
? this->collectToIORank_.globalWBPData()
: this->eclOutputModule_->getWBPData();
for (const auto& [global_index, pressure] : wbpData)
wbp_calculators.add_pressure( global_index, pressure );
// Add TCPU
if (totalCpuTime != 0.0) {
@ -390,8 +399,11 @@ public:
}
if (this->collectToIORank_.isParallel()) {
collectToIORank_.collect(localCellData, eclOutputModule_->getBlockData(),
localWellData, localGroupAndNetworkData);
collectToIORank_.collect(localCellData,
eclOutputModule_->getBlockData(),
eclOutputModule_->getWBPData(),
localWellData,
localGroupAndNetworkData);
}
if (this->collectToIORank_.isIORank()) {