24#ifndef DUMUX_FACETCOUPLING_MAPPER_BASE_HH
25#define DUMUX_FACETCOUPLING_MAPPER_BASE_HH
28#include <unordered_map>
32#include <dune/common/indices.hh>
33#include <dune/common/exceptions.hh>
48template<
class BulkFVG,
54 using BulkGridView =
typename BulkFVG::GridView;
57 using LowDimGridView =
typename LowDimFVG::GridView;
58 using LowDimElement =
typename LowDimGridView::template Codim<0>::Entity;
62 static constexpr int bulkDim = BulkGridView::dimension;
63 static constexpr int lowDimDim = LowDimGridView::dimension;
64 static_assert(bulkDim == lowDimDim+1,
"Lower-dimensional geometry is not of codim 1 w.r.t. bulk geometry!");
67 static constexpr auto bulkDiscMethod = BulkFVG::discMethod;
70 template<
class Embeddings >
73 using GCBulkGridView =
typename Embeddings::template GridView<bulkId>;
74 using GCLowDimGridView =
typename Embeddings::template GridView<lowDimId>;
75 static constexpr bool bulkMatch = std::is_same<GCBulkGridView, BulkGridView>::value;
76 static constexpr bool lowDimMatch = std::is_same<GCLowDimGridView, LowDimGridView>::value;
77 static_assert(bulkMatch,
"The bulk domain id does not match the provided bulk grid geometry");
78 static_assert(lowDimMatch,
"The lowDim domain id does not match the provided lowDim grid geometry");
81 static constexpr bool value = bulkMatch && lowDimMatch;
88 struct BulkCouplingData
91 std::vector< LowDimIndexType > couplingStencil;
94 std::vector< LowDimIndexType > couplingElementStencil;
97 std::unordered_map< LowDimIndexType, std::vector<BulkIndexType> > dofToCouplingScvfMap;
100 std::unordered_map< LowDimIndexType, std::vector<BulkIndexType> > elementToScvfMap;
107 struct LowDimCouplingData
110 std::vector< BulkIndexType > couplingStencil;
113 using Embedment = std::pair< BulkIndexType, std::vector<BulkIndexType> >;
114 std::vector< Embedment > embedments;
118 using BulkCouplingMap = std::unordered_map<BulkIndexType, BulkCouplingData>;
119 using LowDimCouplingMap = std::unordered_map<LowDimIndexType, LowDimCouplingData>;
122 using LowDimStencil = std::vector<LowDimIndexType>;
123 using BulkStencil = std::vector<BulkIndexType>;
126 template<std::
size_t id>
127 using GridIdType = Dune::index_constant<id>;
135 template<std::
size_t id>
136 using Stencil =
typename std::conditional<id == bulkId, BulkStencil, LowDimStencil>::type;
139 template<std::
size_t i, std::
size_t j>
140 using CouplingMap =
typename std::conditional<i == bulkId, BulkCouplingMap, LowDimCouplingMap>::type;
144 static constexpr GridIdType< (dim == bulkDim ? bulkId : lowDimId) >
gridId()
145 {
return GridIdType< (dim == bulkDim ? bulkId : lowDimId) >(); }
151 template<
class Embeddings >
152 void update(
const BulkFVG& bulkFvGridGeometry,
153 const LowDimFVG& lowDimFvGridGeometry,
154 std::shared_ptr<const Embeddings> embeddings)
155 { DUNE_THROW(Dune::NotImplemented,
"Implementation does not provide an update() function."); }
158 const BulkCouplingMap&
couplingMap(GridIdType<bulkId>, GridIdType<lowDimId>)
const
159 {
return bulkCouplingData_; }
162 const LowDimCouplingMap&
couplingMap(GridIdType<lowDimId>, GridIdType<bulkId>)
const
163 {
return lowDimCouplingData_; }
176 template<
class Embeddings,
typename AddCouplingEntryPolicy >
177 void update_(
const BulkFVG& bulkFvGridGeometry,
178 const LowDimFVG& lowDimFvGridGeometry,
179 std::shared_ptr<const Embeddings> embeddings,
180 AddCouplingEntryPolicy&& addCouplingEntryPolicy)
183 static_assert(IsValidDomainId<Embeddings>::value,
"Grid type mismatch. Please review the provided domain id offset.");
186 bulkCouplingData_.clear();
187 lowDimCouplingData_.clear();
190 const auto bulkInsertionToElemIdxMap = makeInsertionToGridIndexMap_(embeddings, bulkFvGridGeometry);
193 for (
const auto& element : elements(lowDimFvGridGeometry.gridView()))
195 auto adjoinedEntities = embeddings->template adjoinedEntityIndices<lowDimId>(element);
198 if (adjoinedEntities.size() == 0)
202 std::for_each(adjoinedEntities.begin(), adjoinedEntities.end(), [&] (
auto& idx) { idx = bulkInsertionToElemIdxMap.at(idx); });
205 addCouplingEntryPolicy(std::move(adjoinedEntities), element, lowDimFvGridGeometry, bulkFvGridGeometry);
210 template<
class Gr
idGeometry>
211 std::vector< typename IndexTraits<typename GridGeometry::GridView>::GridIndex >
213 const GridGeometry& gridGeometry)
215 static constexpr int dim = GridGeometry::GridView::dimension;
218 const auto numCorners = element.subEntities(dim);
219 std::vector< GridIndexType > nodalDofs(
numCorners);
221 nodalDofs[i] = gridGeometry.vertexMapper().subIndex(element, i, dim);
227 BulkCouplingMap&
couplingMap_(GridIdType<bulkId>, GridIdType<lowDimId>)
228 {
return bulkCouplingData_; }
231 LowDimCouplingMap&
couplingMap_(GridIdType<lowDimId>, GridIdType<bulkId>)
232 {
return lowDimCouplingData_; }
237 template<
class Embeddings,
class Gr
idGeometry>
239 makeInsertionToGridIndexMap_(std::shared_ptr<const Embeddings> embeddings,
const GridGeometry& gridGeometry)
const
243 std::unordered_map< GridIndexType, GridIndexType > map;
244 for (
const auto& e : elements(gridGeometry.gridView()))
245 map.insert( std::make_pair( embeddings->template insertionIndex<bulkId>(e), gridGeometry.elementMapper().index(e) ) );
250 BulkCouplingMap bulkCouplingData_;
251 LowDimCouplingMap lowDimCouplingData_;
Defines the index types used for grid and local indices.
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
std::size_t numCorners(Shape shape)
Returns the number of corners of a given geometry.
Definition: throatproperties.hh:232
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:53
const BulkCouplingMap & couplingMap(GridIdType< bulkId >, GridIdType< lowDimId >) const
returns coupling data for bulk -> lowDim
Definition: couplingmapperbase.hh:158
static constexpr GridIdType<(dim==bulkDim ? bulkId :lowDimId) > gridId()
Allow retrievment of grid id for a given grid dimension.
Definition: couplingmapperbase.hh:144
static constexpr auto facetGridId
Definition: couplingmapperbase.hh:132
typename std::conditional< id==bulkId, BulkStencil, LowDimStencil >::type Stencil
Export the stencil type for the provided grid index.
Definition: couplingmapperbase.hh:136
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:212
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:152
LowDimCouplingMap & couplingMap_(GridIdType< lowDimId >, GridIdType< bulkId >)
returns non-const coupling data for lowDim -> bulk
Definition: couplingmapperbase.hh:231
const LowDimCouplingMap & couplingMap(GridIdType< lowDimId >, GridIdType< bulkId >) const
returns coupling data for lowDim -> bulk
Definition: couplingmapperbase.hh:162
void update_(const BulkFVG &bulkFvGridGeometry, const LowDimFVG &lowDimFvGridGeometry, std::shared_ptr< const Embeddings > embeddings, AddCouplingEntryPolicy &&addCouplingEntryPolicy)
Update coupling maps.
Definition: couplingmapperbase.hh:177
static constexpr auto bulkGridId
Export grid ids.
Definition: couplingmapperbase.hh:131
typename std::conditional< i==bulkId, BulkCouplingMap, LowDimCouplingMap >::type CouplingMap
Export the coupling map type.
Definition: couplingmapperbase.hh:140
BulkCouplingMap & couplingMap_(GridIdType< bulkId >, GridIdType< lowDimId >)
returns non-const coupling data for bulk -> lowDim
Definition: couplingmapperbase.hh:227