From ee6044b2e00d5a1ceae488e9f6c31cd4dcc07eb8 Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Tue, 8 Sep 2020 20:28:42 +0200 Subject: [PATCH] Fixes determining whether index of summary keyword is on process. We used a method isGlobalIdxOnThisRank to determine whether to write an entry for a summary keyword (like BPR). Unfortunately, this did exactly what the name suggested, but we actually passed a cartesian index to it. That meant that a lower cartesian index might have found on many processes (with different cartesian index and hence resulting in wrong values), while higher for ones no process would have been found with it (resulting in writing zeros). With this commit we store a sorted list of cartesian indices and query that in the renamed and restructured function isCartesianidxOnThisRank. Most probably this broke during refactoring. Closes #2665 --- ebos/collecttoiorank.hh | 22 +++++++++++++++++----- ebos/ecloutputblackoilmodule.hh | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ebos/collecttoiorank.hh b/ebos/collecttoiorank.hh index 7f7f211fe..9010a4e58 100644 --- a/ebos/collecttoiorank.hh +++ b/ebos/collecttoiorank.hh @@ -309,7 +309,16 @@ public: typedef Dune::MultipleCodimMultipleGeomTypeMapper ElementMapper; ElementMapper elemMapper(localGridView, Dune::mcmgElementLayout()); + const auto& cartMapper = vanguard.cartesianIndexMapper(); + sortedCartesianIdx_.reserve(vanguard.gridView().size(0)); + for(const auto& elem: elements(localGridView)) + { + auto idx = elemMapper.index(elem); + sortedCartesianIdx_.push_back(cartMapper.cartesianIndex(idx)); + } + + std::sort(sortedCartesianIdx_.begin(), sortedCartesianIdx_.end()); localIdxToGlobalIdx_.resize(localGridView.size(0), -1); // the I/O rank receives from all other ranks @@ -747,15 +756,14 @@ public: const std::vector& globalRanks() const { return globalRanks_; } - bool isGlobalIdxOnThisRank(unsigned globalIdx) const + bool isCartIdxOnThisRank(int cartIdx) const { if (!isParallel()) return true; - if (localIdxToGlobalIdx_.empty()) - throw std::logic_error("index map is not created on this rank"); - - return std::find(localIdxToGlobalIdx_.begin(), localIdxToGlobalIdx_.end(), globalIdx) != localIdxToGlobalIdx_.end(); + assert(!needsReordering); + auto candidate = std::lower_bound(sortedCartesianIdx_.begin(), sortedCartesianIdx_.end(), cartIdx); + return (candidate != sortedCartesianIdx_.end() && *candidate == cartIdx); } protected: @@ -769,6 +777,10 @@ protected: Opm::data::Wells globalWellData_; Opm::data::GroupValues globalGroupData_; std::vector localIdxToGlobalIdx_; + /// \brief sorted list of cartesian indices present- + /// + /// non-empty only when running in parallel + std::vector sortedCartesianIdx_; }; } // end namespace Opm diff --git a/ebos/ecloutputblackoilmodule.hh b/ebos/ecloutputblackoilmodule.hh index 8215b9bfc..530ef1b7f 100644 --- a/ebos/ecloutputblackoilmodule.hh +++ b/ebos/ecloutputblackoilmodule.hh @@ -194,7 +194,7 @@ public: // Initialize block output for (const auto& node: summaryConfig) { if (node.category() == SummaryConfigNode::Category::Block) { - if (collectToIORank.isGlobalIdxOnThisRank(node.number() - 1)) { + if (collectToIORank.isCartIdxOnThisRank(node.number() - 1)) { std::pair key = std::make_pair(node.keyword(), node.number()); blockData_[key] = 0.0; }