12#ifndef DUMUX_FACETCOUPLING_MAPPER_BASE_HH
13#define DUMUX_FACETCOUPLING_MAPPER_BASE_HH
16#include <unordered_map>
20#include <dune/common/indices.hh>
21#include <dune/common/exceptions.hh>
36template<
class BulkFVG,
42 using BulkGridView =
typename BulkFVG::GridView;
45 using LowDimGridView =
typename LowDimFVG::GridView;
46 using LowDimElement =
typename LowDimGridView::template Codim<0>::Entity;
50 static constexpr int bulkDim = BulkGridView::dimension;
51 static constexpr int lowDimDim = LowDimGridView::dimension;
52 static_assert(bulkDim == lowDimDim+1,
"Lower-dimensional geometry is not of codim 1 w.r.t. bulk geometry!");
55 static constexpr auto bulkDiscMethod = BulkFVG::discMethod;
58 template<
class Embeddings >
61 using GCBulkGridView =
typename Embeddings::template GridView<bulkId>;
62 using GCLowDimGridView =
typename Embeddings::template GridView<lowDimId>;
63 static constexpr bool bulkMatch = std::is_same<GCBulkGridView, BulkGridView>::value;
64 static constexpr bool lowDimMatch = std::is_same<GCLowDimGridView, LowDimGridView>::value;
65 static_assert(bulkMatch,
"The bulk domain id does not match the provided bulk grid geometry");
66 static_assert(lowDimMatch,
"The lowDim domain id does not match the provided lowDim grid geometry");
69 static constexpr bool value = bulkMatch && lowDimMatch;
76 struct BulkCouplingData
79 std::vector< LowDimIndexType > couplingStencil;
82 std::vector< LowDimIndexType > couplingElementStencil;
85 std::unordered_map< LowDimIndexType, std::vector<BulkIndexType> > dofToCouplingScvfMap;
88 std::unordered_map< LowDimIndexType, std::vector<BulkIndexType> > elementToScvfMap;
95 struct LowDimCouplingData
98 std::vector< BulkIndexType > couplingStencil;
101 using Embedment = std::pair< BulkIndexType, std::vector<BulkIndexType> >;
102 std::vector< Embedment > embedments;
106 using BulkCouplingMap = std::unordered_map<BulkIndexType, BulkCouplingData>;
107 using LowDimCouplingMap = std::unordered_map<LowDimIndexType, LowDimCouplingData>;
110 using LowDimStencil = std::vector<LowDimIndexType>;
111 using BulkStencil = std::vector<BulkIndexType>;
114 template<std::
size_t id>
115 using GridIdType = Dune::index_constant<id>;
123 template<std::
size_t id>
124 using Stencil =
typename std::conditional<id == bulkId, BulkStencil, LowDimStencil>::type;
127 template<std::
size_t i, std::
size_t j>
128 using CouplingMap =
typename std::conditional<i == bulkId, BulkCouplingMap, LowDimCouplingMap>::type;
132 static constexpr GridIdType< (dim == bulkDim ? bulkId : lowDimId) >
gridId()
133 {
return GridIdType< (dim == bulkDim ? bulkId : lowDimId) >(); }
139 template<
class Embeddings >
140 void update(
const BulkFVG& bulkFvGridGeometry,
141 const LowDimFVG& lowDimFvGridGeometry,
142 std::shared_ptr<const Embeddings> embeddings)
143 { DUNE_THROW(Dune::NotImplemented,
"Implementation does not provide an update() function."); }
146 const BulkCouplingMap&
couplingMap(GridIdType<bulkId>, GridIdType<lowDimId>)
const
147 {
return bulkCouplingData_; }
150 const LowDimCouplingMap&
couplingMap(GridIdType<lowDimId>, GridIdType<bulkId>)
const
151 {
return lowDimCouplingData_; }
164 template<
class Embeddings,
typename AddCouplingEntryPolicy >
165 void update_(
const BulkFVG& bulkFvGridGeometry,
166 const LowDimFVG& lowDimFvGridGeometry,
167 std::shared_ptr<const Embeddings> embeddings,
168 AddCouplingEntryPolicy&& addCouplingEntryPolicy)
171 static_assert(IsValidDomainId<Embeddings>::value,
"Grid type mismatch. Please review the provided domain id offset.");
174 bulkCouplingData_.clear();
175 lowDimCouplingData_.clear();
178 const auto bulkInsertionToElemIdxMap = makeInsertionToGridIndexMap_(embeddings, bulkFvGridGeometry);
181 for (
const auto& element : elements(lowDimFvGridGeometry.gridView()))
183 auto adjoinedEntities = embeddings->template adjoinedEntityIndices<lowDimId>(element);
186 if (adjoinedEntities.size() == 0)
190 std::for_each(adjoinedEntities.begin(), adjoinedEntities.end(), [&] (
auto& idx) { idx = bulkInsertionToElemIdxMap.at(idx); });
193 addCouplingEntryPolicy(std::move(adjoinedEntities), element, lowDimFvGridGeometry, bulkFvGridGeometry);
198 template<
class Gr
idGeometry>
199 std::vector< typename IndexTraits<typename GridGeometry::GridView>::GridIndex >
201 const GridGeometry& gridGeometry)
203 static constexpr int dim = GridGeometry::GridView::dimension;
206 const auto numCorners = element.subEntities(dim);
207 std::vector< GridIndexType > nodalDofs(
numCorners);
209 nodalDofs[i] = gridGeometry.vertexMapper().subIndex(element, i, dim);
215 BulkCouplingMap&
couplingMap_(GridIdType<bulkId>, GridIdType<lowDimId>)
216 {
return bulkCouplingData_; }
219 LowDimCouplingMap&
couplingMap_(GridIdType<lowDimId>, GridIdType<bulkId>)
220 {
return lowDimCouplingData_; }
225 template<
class Embeddings,
class Gr
idGeometry>
227 makeInsertionToGridIndexMap_(std::shared_ptr<const Embeddings> embeddings,
const GridGeometry& gridGeometry)
const
231 std::unordered_map< GridIndexType, GridIndexType > map;
232 for (
const auto& e : elements(gridGeometry.gridView()))
233 map.insert( std::make_pair( embeddings->template insertionIndex<bulkId>(e), gridGeometry.elementMapper().index(e) ) );
238 BulkCouplingMap bulkCouplingData_;
239 LowDimCouplingMap lowDimCouplingData_;
Base class for the coupling mapper that sets up and stores the coupling maps between two domains of d...
Definition: couplingmapperbase.hh:41
const BulkCouplingMap & couplingMap(GridIdType< bulkId >, GridIdType< lowDimId >) const
returns coupling data for bulk -> lowDim
Definition: couplingmapperbase.hh:146
static constexpr GridIdType<(dim==bulkDim ? bulkId :lowDimId) > gridId()
Allow retrievment of grid id for a given grid dimension.
Definition: couplingmapperbase.hh:132
static constexpr auto facetGridId
Definition: couplingmapperbase.hh:120
typename std::conditional< id==bulkId, BulkStencil, LowDimStencil >::type Stencil
Export the stencil type for the provided grid index.
Definition: couplingmapperbase.hh:124
std::vector< typename IndexTraits< typename GridGeometry::GridView >::GridIndex > extractNodalDofs_(const typename GridGeometry::GridView::template Codim< 0 >::Entity &element, const GridGeometry &gridGeometry)
Creates a container with the nodal dofs within an element.
Definition: couplingmapperbase.hh:200
void update(const BulkFVG &bulkFvGridGeometry, const LowDimFVG &lowDimFvGridGeometry, std::shared_ptr< const Embeddings > embeddings)
Update coupling maps. This is the standard interface and has to be overloaded by the implementation.
Definition: couplingmapperbase.hh:140
LowDimCouplingMap & couplingMap_(GridIdType< lowDimId >, GridIdType< bulkId >)
returns non-const coupling data for lowDim -> bulk
Definition: couplingmapperbase.hh:219
const LowDimCouplingMap & couplingMap(GridIdType< lowDimId >, GridIdType< bulkId >) const
returns coupling data for lowDim -> bulk
Definition: couplingmapperbase.hh:150
void update_(const BulkFVG &bulkFvGridGeometry, const LowDimFVG &lowDimFvGridGeometry, std::shared_ptr< const Embeddings > embeddings, AddCouplingEntryPolicy &&addCouplingEntryPolicy)
Update coupling maps.
Definition: couplingmapperbase.hh:165
static constexpr auto bulkGridId
Export grid ids.
Definition: couplingmapperbase.hh:119
typename std::conditional< i==bulkId, BulkCouplingMap, LowDimCouplingMap >::type CouplingMap
Export the coupling map type.
Definition: couplingmapperbase.hh:128
BulkCouplingMap & couplingMap_(GridIdType< bulkId >, GridIdType< lowDimId >)
returns non-const coupling data for bulk -> lowDim
Definition: couplingmapperbase.hh:215
std::size_t numCorners(Shape shape)
Returns the number of corners of a given geometry.
Definition: throatproperties.hh:220
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:27