3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
couplingmapperbase.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*****************************************************************************
4 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_FACETCOUPLING_MAPPER_BASE_HH
25#define DUMUX_FACETCOUPLING_MAPPER_BASE_HH
26
27#include <vector>
28#include <unordered_map>
29#include <algorithm>
30#include <memory>
31
32#include <dune/common/indices.hh>
33#include <dune/common/exceptions.hh>
35
36namespace Dumux {
37
48template< class BulkFVG,
49 class LowDimFVG,
50 std::size_t bulkId,
51 std::size_t lowDimId>
53{
54 using BulkGridView = typename BulkFVG::GridView;
55 using BulkIndexType = typename IndexTraits<BulkGridView>::GridIndex;
56
57 using LowDimGridView = typename LowDimFVG::GridView;
58 using LowDimElement = typename LowDimGridView::template Codim<0>::Entity;
59 using LowDimIndexType = typename IndexTraits<LowDimGridView>::GridIndex;
60
61 // make sure the grid geometry combination makes sense
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!");
65
66 // discretization method of the bulk domain
67 static constexpr auto bulkDiscMethod = BulkFVG::discMethod;
68
69 // helper struct to check validity of the given domain id offset
70 template< class Embeddings >
71 class IsValidDomainId
72 {
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");
79
80 public:
81 static constexpr bool value = bulkMatch && lowDimMatch;
82 };
83
88 struct BulkCouplingData
89 {
91 std::vector< LowDimIndexType > couplingStencil;
92
94 std::vector< LowDimIndexType > couplingElementStencil;
95
97 std::unordered_map< LowDimIndexType, std::vector<BulkIndexType> > dofToCouplingScvfMap;
98
100 std::unordered_map< LowDimIndexType, std::vector<BulkIndexType> > elementToScvfMap;
101 };
102
107 struct LowDimCouplingData
108 {
110 std::vector< BulkIndexType > couplingStencil;
111
113 using Embedment = std::pair< BulkIndexType, std::vector<BulkIndexType> >;
114 std::vector< Embedment > embedments;
115 };
116
118 using BulkCouplingMap = std::unordered_map<BulkIndexType, BulkCouplingData>;
119 using LowDimCouplingMap = std::unordered_map<LowDimIndexType, LowDimCouplingData>;
120
122 using LowDimStencil = std::vector<LowDimIndexType>;
123 using BulkStencil = std::vector<BulkIndexType>;
124
126 template<std::size_t id>
127 using GridIdType = Dune::index_constant<id>;
128
129public:
131 static constexpr auto bulkGridId = GridIdType<bulkId>();
132 static constexpr auto facetGridId = GridIdType<lowDimId>();
133
135 template<std::size_t id>
136 using Stencil = typename std::conditional<id == bulkId, BulkStencil, LowDimStencil>::type;
137
139 template<std::size_t i, std::size_t j>
140 using CouplingMap = typename std::conditional<i == bulkId, BulkCouplingMap, LowDimCouplingMap>::type;
141
143 template<int dim>
144 static constexpr GridIdType< (dim == bulkDim ? bulkId : lowDimId) > gridId()
145 { return GridIdType< (dim == bulkDim ? bulkId : lowDimId) >(); }
146
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."); }
156
158 const BulkCouplingMap& couplingMap(GridIdType<bulkId>, GridIdType<lowDimId>) const
159 { return bulkCouplingData_; }
160
162 const LowDimCouplingMap& couplingMap(GridIdType<lowDimId>, GridIdType<bulkId>) const
163 { return lowDimCouplingData_; }
164
165protected:
166
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)
181 {
182 // some static assertions on the grid creator
183 static_assert(IsValidDomainId<Embeddings>::value, "Grid type mismatch. Please review the provided domain id offset.");
184
185 // clear data
186 bulkCouplingData_.clear();
187 lowDimCouplingData_.clear();
188
189 // set up maps between element indices and insertion indices
190 const auto bulkInsertionToElemIdxMap = makeInsertionToGridIndexMap_(embeddings, bulkFvGridGeometry);
191
192 // set up coupling maps coming from the low dim domain
193 for (const auto& element : elements(lowDimFvGridGeometry.gridView()))
194 {
195 auto adjoinedEntities = embeddings->template adjoinedEntityIndices<lowDimId>(element);
196
197 // proceed only if element is embedded
198 if (adjoinedEntities.size() == 0)
199 continue;
200
201 // turn (insertion) indices into actual grid element indices ...
202 std::for_each(adjoinedEntities.begin(), adjoinedEntities.end(), [&] (auto& idx) { idx = bulkInsertionToElemIdxMap.at(idx); });
203
204 // ... and add them
205 addCouplingEntryPolicy(std::move(adjoinedEntities), element, lowDimFvGridGeometry, bulkFvGridGeometry);
206 }
207 }
208
210 template< class GridGeometry>
211 std::vector< typename IndexTraits<typename GridGeometry::GridView>::GridIndex >
212 extractNodalDofs_(const typename GridGeometry::GridView::template Codim<0>::Entity& element,
213 const GridGeometry& gridGeometry)
214 {
215 static constexpr int dim = GridGeometry::GridView::dimension;
216 using GridIndexType = typename IndexTraits<typename GridGeometry::GridView>::GridIndex;
217
218 const auto numCorners = element.subEntities(dim);
219 std::vector< GridIndexType > nodalDofs(numCorners);
220 for (unsigned int i = 0; i < numCorners; ++i)
221 nodalDofs[i] = gridGeometry.vertexMapper().subIndex(element, i, dim);
222
223 return nodalDofs;
224 }
225
227 BulkCouplingMap& couplingMap_(GridIdType<bulkId>, GridIdType<lowDimId>)
228 { return bulkCouplingData_; }
229
231 LowDimCouplingMap& couplingMap_(GridIdType<lowDimId>, GridIdType<bulkId>)
232 { return lowDimCouplingData_; }
233
234private:
235
237 template< class Embeddings, class GridGeometry>
238 std::unordered_map< typename IndexTraits<typename GridGeometry::GridView>::GridIndex, typename IndexTraits<typename GridGeometry::GridView>::GridIndex >
239 makeInsertionToGridIndexMap_(std::shared_ptr<const Embeddings> embeddings, const GridGeometry& gridGeometry) const
240 {
241 using GridIndexType = typename IndexTraits<typename GridGeometry::GridView>::GridIndex;
242
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) ) );
246
247 return map;
248 }
249
250 BulkCouplingMap bulkCouplingData_;
251 LowDimCouplingMap lowDimCouplingData_;
252};
253
254} // end namespace Dumux
255
256#endif
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