22#ifndef DUMUX_FACETCOUPLING_MAPPER_BASE_HH
23#define DUMUX_FACETCOUPLING_MAPPER_BASE_HH
26#include <unordered_map>
30#include <dune/common/indices.hh>
31#include <dune/common/exceptions.hh>
46template<
class BulkFVG,
52 using BulkGridView =
typename BulkFVG::GridView;
55 using LowDimGridView =
typename LowDimFVG::GridView;
56 using LowDimElement =
typename LowDimGridView::template Codim<0>::Entity;
60 static constexpr int bulkDim = BulkGridView::dimension;
61 static constexpr int lowDimDim = LowDimGridView::dimension;
62 static_assert(bulkDim == lowDimDim+1,
"Lower-dimensional geometry is not of codim 1 w.r.t. bulk geometry!");
65 static constexpr auto bulkDiscMethod = BulkFVG::discMethod;
68 template<
class Embeddings >
71 using GCBulkGridView =
typename Embeddings::template GridView<bulkId>;
72 using GCLowDimGridView =
typename Embeddings::template GridView<lowDimId>;
73 static constexpr bool bulkMatch = std::is_same<GCBulkGridView, BulkGridView>::value;
74 static constexpr bool lowDimMatch = std::is_same<GCLowDimGridView, LowDimGridView>::value;
75 static_assert(bulkMatch,
"The bulk domain id does not match the provided bulk grid geometry");
76 static_assert(lowDimMatch,
"The lowDim domain id does not match the provided lowDim grid geometry");
79 static constexpr bool value = bulkMatch && lowDimMatch;
86 struct BulkCouplingData
89 std::vector< LowDimIndexType > couplingStencil;
92 std::vector< LowDimIndexType > couplingElementStencil;
95 std::unordered_map< LowDimIndexType, std::vector<BulkIndexType> > dofToCouplingScvfMap;
98 std::unordered_map< LowDimIndexType, std::vector<BulkIndexType> > elementToScvfMap;
105 struct LowDimCouplingData
108 std::vector< BulkIndexType > couplingStencil;
111 using Embedment = std::pair< BulkIndexType, std::vector<BulkIndexType> >;
112 std::vector< Embedment > embedments;
116 using BulkCouplingMap = std::unordered_map<BulkIndexType, BulkCouplingData>;
117 using LowDimCouplingMap = std::unordered_map<LowDimIndexType, LowDimCouplingData>;
120 using LowDimStencil = std::vector<LowDimIndexType>;
121 using BulkStencil = std::vector<BulkIndexType>;
124 template<std::
size_t id>
125 using GridIdType = Dune::index_constant<id>;
133 template<std::
size_t id>
134 using Stencil =
typename std::conditional<id == bulkId, BulkStencil, LowDimStencil>::type;
137 template<std::
size_t i, std::
size_t j>
138 using CouplingMap =
typename std::conditional<i == bulkId, BulkCouplingMap, LowDimCouplingMap>::type;
142 static constexpr GridIdType< (dim == bulkDim ? bulkId : lowDimId) >
gridId()
143 {
return GridIdType< (dim == bulkDim ? bulkId : lowDimId) >(); }
149 template<
class Embeddings >
150 void update(
const BulkFVG& bulkFvGridGeometry,
151 const LowDimFVG& lowDimFvGridGeometry,
152 std::shared_ptr<const Embeddings> embeddings)
153 { DUNE_THROW(Dune::NotImplemented,
"Implementation does not provide an update() function."); }
156 const BulkCouplingMap&
couplingMap(GridIdType<bulkId>, GridIdType<lowDimId>)
const
157 {
return bulkCouplingData_; }
160 const LowDimCouplingMap&
couplingMap(GridIdType<lowDimId>, GridIdType<bulkId>)
const
161 {
return lowDimCouplingData_; }
174 template<
class Embeddings,
typename AddCouplingEntryPolicy >
175 void update_(
const BulkFVG& bulkFvGridGeometry,
176 const LowDimFVG& lowDimFvGridGeometry,
177 std::shared_ptr<const Embeddings> embeddings,
178 AddCouplingEntryPolicy&& addCouplingEntryPolicy)
181 static_assert(IsValidDomainId<Embeddings>::value,
"Grid type mismatch. Please review the provided domain id offset.");
184 bulkCouplingData_.clear();
185 lowDimCouplingData_.clear();
188 const auto bulkInsertionToElemIdxMap = makeInsertionToGridIndexMap_(embeddings, bulkFvGridGeometry);
191 for (
const auto& element : elements(lowDimFvGridGeometry.gridView()))
193 auto adjoinedEntities = embeddings->template adjoinedEntityIndices<lowDimId>(element);
196 if (adjoinedEntities.size() == 0)
200 std::for_each(adjoinedEntities.begin(), adjoinedEntities.end(), [&] (
auto& idx) { idx = bulkInsertionToElemIdxMap.at(idx); });
203 addCouplingEntryPolicy(std::move(adjoinedEntities), element, lowDimFvGridGeometry, bulkFvGridGeometry);
208 template<
class Gr
idGeometry>
209 std::vector< typename IndexTraits<typename GridGeometry::GridView>::GridIndex >
211 const GridGeometry& gridGeometry)
213 static constexpr int dim = GridGeometry::GridView::dimension;
216 const auto numCorners = element.subEntities(dim);
217 std::vector< GridIndexType > nodalDofs(
numCorners);
219 nodalDofs[i] = gridGeometry.vertexMapper().subIndex(element, i, dim);
225 BulkCouplingMap&
couplingMap_(GridIdType<bulkId>, GridIdType<lowDimId>)
226 {
return bulkCouplingData_; }
229 LowDimCouplingMap&
couplingMap_(GridIdType<lowDimId>, GridIdType<bulkId>)
230 {
return lowDimCouplingData_; }
235 template<
class Embeddings,
class Gr
idGeometry>
237 makeInsertionToGridIndexMap_(std::shared_ptr<const Embeddings> embeddings,
const GridGeometry& gridGeometry)
const
241 std::unordered_map< GridIndexType, GridIndexType > map;
242 for (
const auto& e : elements(gridGeometry.gridView()))
243 map.insert( std::make_pair( embeddings->template insertionIndex<bulkId>(e), gridGeometry.elementMapper().index(e) ) );
248 BulkCouplingMap bulkCouplingData_;
249 LowDimCouplingMap lowDimCouplingData_;
Defines the index types used for grid and local indices.
std::size_t numCorners(Shape shape)
Returns the number of corners of a given geometry.
Definition: throatproperties.hh:215
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:39
Base class for the coupling mapper that sets up and stores the coupling maps between two domains of d...
Definition: couplingmapperbase.hh:51
const BulkCouplingMap & couplingMap(GridIdType< bulkId >, GridIdType< lowDimId >) const
returns coupling data for bulk -> lowDim
Definition: couplingmapperbase.hh:156
static constexpr GridIdType<(dim==bulkDim ? bulkId :lowDimId) > gridId()
Allow retrievment of grid id for a given grid dimension.
Definition: couplingmapperbase.hh:142
static constexpr auto facetGridId
Definition: couplingmapperbase.hh:130
typename std::conditional< id==bulkId, BulkStencil, LowDimStencil >::type Stencil
Export the stencil type for the provided grid index.
Definition: couplingmapperbase.hh:134
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:210
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:150
LowDimCouplingMap & couplingMap_(GridIdType< lowDimId >, GridIdType< bulkId >)
returns non-const coupling data for lowDim -> bulk
Definition: couplingmapperbase.hh:229
const LowDimCouplingMap & couplingMap(GridIdType< lowDimId >, GridIdType< bulkId >) const
returns coupling data for lowDim -> bulk
Definition: couplingmapperbase.hh:160
void update_(const BulkFVG &bulkFvGridGeometry, const LowDimFVG &lowDimFvGridGeometry, std::shared_ptr< const Embeddings > embeddings, AddCouplingEntryPolicy &&addCouplingEntryPolicy)
Update coupling maps.
Definition: couplingmapperbase.hh:175
static constexpr auto bulkGridId
Export grid ids.
Definition: couplingmapperbase.hh:129
typename std::conditional< i==bulkId, BulkCouplingMap, LowDimCouplingMap >::type CouplingMap
Export the coupling map type.
Definition: couplingmapperbase.hh:138
BulkCouplingMap & couplingMap_(GridIdType< bulkId >, GridIdType< lowDimId >)
returns non-const coupling data for bulk -> lowDim
Definition: couplingmapperbase.hh:225