Special case wells with no open connections in ParallelWellInfo

This commit is contained in:
Joakim Hove 2021-08-31 17:31:45 +02:00
parent aba95a8263
commit 7bb3dba310
3 changed files with 26 additions and 8 deletions

View File

@ -381,7 +381,8 @@ void ParallelWellInfo::communicateFirstPerforation(bool hasFirst)
comm_->allgather(&first, 1, firstVec.data());
auto found = std::find_if(firstVec.begin(), firstVec.end(),
[](int i) -> bool{ return i;});
rankWithFirstPerf_ = found - firstVec.begin();
if (found != firstVec.end())
rankWithFirstPerf_ = found - firstVec.begin();
}
void ParallelWellInfo::pushBackEclIndex(int above, int current)

View File

@ -279,20 +279,26 @@ public:
/// \brief Collectively decide which rank has first perforation.
void communicateFirstPerforation(bool hasFirst);
/// If the well does not have any open connections the member rankWithFirstPerf
/// is not initialized, and no broadcast is performed. In this case the argument
/// is returned unmodified.
template<class T>
T broadcastFirstPerforationValue(const T& t) const
{
T res = t;
if (rankWithFirstPerf_ >= 0) {
#ifndef NDEBUG
assert(rankWithFirstPerf_ >= 0 && rankWithFirstPerf_ < comm_->size());
// At least on some OpenMPI version this might broadcast might interfere
// with other communication if there are bugs
comm_->barrier();
assert(rankWithFirstPerf_ < comm_->size());
// At least on some OpenMPI version this might broadcast might interfere
// with other communication if there are bugs
comm_->barrier();
#endif
comm_->broadcast(&res, 1, rankWithFirstPerf_);
comm_->broadcast(&res, 1, rankWithFirstPerf_);
#ifndef NDEBUG
comm_->barrier();
comm_->barrier();
#endif
}
return res;
}
@ -406,7 +412,7 @@ private:
bool hasLocalCells_;
/// \brief Whether we own the well and should do reports etc.
bool isOwner_;
/// \brief Rank with the first perforation on it.
/// \brief Rank with the first perforation on it, -1 for wells with no open connections.
int rankWithFirstPerf_;
/// \brief Communication object for the well
///

View File

@ -468,3 +468,14 @@ BOOST_AUTO_TEST_CASE(GlobalPerfFactoryParallel1)
testGlobalPerfFactoryParallel(1);
testGlobalPerfFactoryParallel(3);
}
BOOST_AUTO_TEST_CASE(EmptyWell) {
auto comm = Communication(Dune::MPIHelper::getCommunicator());
Opm::ParallelWellInfo pw({"WELL1", true}, comm);
pw.communicateFirstPerforation(false);
double local_p = 1;
auto global_p = pw.broadcastFirstPerforationValue(local_p);
BOOST_CHECK_EQUAL(local_p, global_p);
}