23#ifndef OPM_LGR_OUTPUT_TRANS_GATHER_HPP
24#define OPM_LGR_OUTPUT_TRANS_GATHER_HPP
26#include <dune/grid/common/mcmgmapper.hh>
27#include <dune/grid/common/partitionset.hh>
29#include <opm/grid/common/CommunicationUtils.hpp>
30#include <opm/grid/cpgrid/LevelCartesianIndexMapper.hpp>
47template <std::
size_t N>
51 using Key = std::array<int, N>;
58 : records_(std::move(records))
60 std::sort(records_.begin(), records_.end(),
61 [](
const auto& a,
const auto& b) { return a.first < b.first; });
62 assert(std::adjacent_find(records_.begin(), records_.end(),
63 [](
const auto& a,
const auto& b) { return a.first == b.first; })
64 == records_.end() &&
"duplicate LGR transmissibility key");
70 const auto it = std::lower_bound(records_.begin(), records_.end(), key,
71 [](
const auto& record,
const Key& k) { return record.first < k; });
72 return (it != records_.end() && it->first == key) ? &it->second :
nullptr;
76 std::vector<std::pair<Key, double>> records_;
116template <
class Gr
idView,
class TransFn>
119 const GridView& gridView,
124 std::vector<std::pair<std::array<int,3>,
double>> same;
125 std::vector<std::pair<std::array<int,4>,
double>> cross;
128 const Dune::MultipleCodimMultipleGeomTypeMapper<GridView>
129 elemMapper(gridView, Dune::mcmgElementLayout());
131 for (
const auto& elem : elements(gridView, Dune::Partitions::interior)) {
133 const int levelIn = elem.level();
134 const int cartIn = levelCartMapp.cartesianIndex(elem.getLevelElem().index(), levelIn);
135 const auto idxIn = elemMapper.index(elem);
137 for (
const auto& is : intersections(gridView, elem)) {
138 if (!is.neighbor()) {
142 const auto outside = is.outside();
143 const int levelOut = outside.level();
145 if (levelIn != levelOut) {
146 if (levelIn > levelOut) {
151 std::array<int,4>{levelIn, cartIn, levelOut,
152 levelCartMapp.cartesianIndex(outside.getLevelElem().index(), levelOut)},
153 transFn(idxIn, elemMapper.index(outside)));
157 const int cartOut = levelCartMapp.cartesianIndex(
158 outside.getLevelElem().index(), levelIn);
160 if (cartIn > cartOut) {
167 same.emplace_back(std::array<int,3>{levelIn, cartIn, cartOut},
168 transFn(idxIn, elemMapper.index(outside)));
179 const auto& comm = grid.comm();
180 auto allSame = gatherv(same, comm, 0).first;
181 auto allCross = gatherv(cross, comm, 0).first;
Definition: EclGenericWriter.hpp:54
Definition: LgrOutputTransGather.hpp:49
LgrTransIndex(std::vector< std::pair< Key, double > > records)
Definition: LgrOutputTransGather.hpp:57
std::array< int, N > Key
Definition: LgrOutputTransGather.hpp:51
const double * find(const Key &key) const
Definition: LgrOutputTransGather.hpp:68
Definition: blackoilbioeffectsmodules.hh:45
GatheredLgrOutputTrans gatherLgrOutputTrans(const Dune::CpGrid &grid, const GridView &gridView, TransFn &&transFn)
Definition: LgrOutputTransGather.hpp:118
Definition: LgrOutputTransGather.hpp:92
LgrTransIndex< 3 > sameLevel
Definition: LgrOutputTransGather.hpp:93
LgrTransIndex< 4 > crossLevel
Definition: LgrOutputTransGather.hpp:94