3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
multidomain/facet/box/fvelementgeometry.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_BOX_FV_ELEMENT_GEOMETRY_HH
25#define DUMUX_FACETCOUPLING_BOX_FV_ELEMENT_GEOMETRY_HH
26
27#include <algorithm>
28#include <optional>
29
30#include <dune/geometry/type.hh>
31
35
36namespace Dumux {
37
47template<class GG, bool enableGridGeometryCache>
49
51template<class GG>
53{
54 using GridView = typename GG::GridView;
55 static constexpr int dim = GridView::dimension;
56 static constexpr int dimWorld = GridView::dimensionworld;
57 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
58 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
59 using CoordScalar = typename GridView::ctype;
60 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
61public:
63 using Element = typename GridView::template Codim<0>::Entity;
65 using SubControlVolume = typename GG::SubControlVolume;
67 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
69 using GridGeometry = GG;
71 static constexpr std::size_t maxNumElementScvs = (1<<dim);
72
75 : gridGeometryPtr_(&gridGeometry)
76 {}
77
79 const SubControlVolume& scv(LocalIndexType scvIdx) const
80 { return gridGeometry().scvs(eIdx_)[scvIdx]; }
81
83 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
84 { return gridGeometry().scvfs(eIdx_)[scvfIdx]; }
85
91 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
93 {
94 const auto& g = fvGeometry.gridGeometry();
95 using Iter = typename std::vector<SubControlVolume>::const_iterator;
96 return Dune::IteratorRange<Iter>(g.scvs(fvGeometry.eIdx_).begin(), g.scvs(fvGeometry.eIdx_).end());
97 }
98
104 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
106 {
107 const auto& g = fvGeometry.gridGeometry();
108 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
109 return Dune::IteratorRange<Iter>(g.scvfs(fvGeometry.eIdx_).begin(), g.scvfs(fvGeometry.eIdx_).end());
110 }
111
113 const FeLocalBasis& feLocalBasis() const
114 { return gridGeometry().feCache().get(element_->type()).localBasis(); }
115
117 std::size_t numScv() const
118 { return gridGeometry().scvs(eIdx_).size(); }
119
121 std::size_t numScvf() const
122 { return gridGeometry().scvfs(eIdx_).size(); }
123
130 {
131 this->bindElement(element);
132 return std::move(*this);
133 }
134
138 void bind(const Element& element) &
139 { this->bindElement(element); }
140
147 {
148 this->bindElement(element);
149 return std::move(*this);
150 }
151
155 void bindElement(const Element& element) &
156 {
157 element_ = element;
158 eIdx_ = gridGeometry().elementMapper().index(element);
159 }
160
163 { return *gridGeometryPtr_; }
164
166 bool isBound() const
167 { return static_cast<bool>(element_); }
168
170 const Element& element() const
171 { return *element_; }
172
173private:
174 const GridGeometry* gridGeometryPtr_;
175
176 GridIndexType eIdx_;
177 std::optional<Element> element_;
178};
179
181template<class GG>
183{
184 using GridView = typename GG::GridView;
185 static constexpr int dim = GridView::dimension;
186 static constexpr int dimWorld = GridView::dimensionworld;
187
188 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
189 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
190
191 using CoordScalar = typename GridView::ctype;
192 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
193
194 using GeometryHelper = BoxGeometryHelper<GridView, dim,
195 typename GG::SubControlVolume,
196 typename GG::SubControlVolumeFace>;
197public:
199 using Element = typename GridView::template Codim<0>::Entity;
201 using SubControlVolume = typename GG::SubControlVolume;
203 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
205 using GridGeometry = GG;
207 static constexpr std::size_t maxNumElementScvs = (1<<dim);
208
211 : gridGeometryPtr_(&gridGeometry)
212 {}
213
215 const SubControlVolume& scv(LocalIndexType scvIdx) const
216 { return scvs_[scvIdx]; }
217
219 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
220 { return scvfs_[scvfIdx]; }
221
227 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
229 {
230 using Iter = typename std::vector<SubControlVolume>::const_iterator;
231 return Dune::IteratorRange<Iter>(fvGeometry.scvs_.begin(), fvGeometry.scvs_.end());
232 }
233
239 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
241 {
242 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
243 return Dune::IteratorRange<Iter>(fvGeometry.scvfs_.begin(), fvGeometry.scvfs_.end());
244 }
245
247 const FeLocalBasis& feLocalBasis() const
248 { return gridGeometry().feCache().get(element_->type()).localBasis(); }
249
251 std::size_t numScv() const
252 { return scvs_.size(); }
253
255 std::size_t numScvf() const
256 { return scvfs_.size(); }
257
264 {
265 this->bindElement(element);
266 return std::move(*this);
267 }
268
272 void bind(const Element& element) &
273 { this->bindElement(element); }
274
281 {
282 this->bindElement(element);
283 return std::move(*this);
284 }
285
289 void bindElement(const Element& element) &
290 {
291 element_ = element;
292 eIdx_ = gridGeometry().elementMapper().index(element);
293 makeElementGeometries_();
294 }
295
298 { return *gridGeometryPtr_; }
299
301 bool isBound() const
302 { return static_cast<bool>(element_); }
303
305 const Element& element() const
306 { return *element_; }
307
308private:
309
310 void makeElementGeometries_()
311 {
312 // get the element geometry
313 const auto& element = *element_;
314 const auto elementGeometry = element.geometry();
315 const auto refElement = referenceElement(elementGeometry);
316
317 // get the sub control volume geometries of this element
318 GeometryHelper geometryHelper(elementGeometry);
319
320 // construct the sub control volumes
321 scvs_.clear();
322 scvs_.reserve(elementGeometry.corners());
323 using LocalIndexType = typename SubControlVolumeFace::Traits::LocalIndexType;
324 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
325 scvs_.emplace_back(geometryHelper,
326 scvLocalIdx,
327 eIdx_,
328 gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim));
329
330 // construct the sub control volume faces
331 const auto numInnerScvf = (dim==1) ? 1 : element.subEntities(dim-1);
332 scvfs_.clear();
333 scvfs_.reserve(numInnerScvf);
334
335 unsigned int scvfLocalIdx = 0;
336 for (; scvfLocalIdx < numInnerScvf; ++scvfLocalIdx)
337 {
338 // find the local scv indices this scvf is connected to
339 std::vector<LocalIndexType> localScvIndices({static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
340 static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
341
342 // create the sub-control volume face
343 scvfs_.emplace_back(geometryHelper,
344 element,
345 elementGeometry,
346 scvfLocalIdx,
347 std::move(localScvIndices));
348 }
349
350 // construct the sub control volume faces on the domain/interior boundaries
351 // skip handled facets (necessary for e.g. Dune::FoamGrid)
352 std::vector<unsigned int> handledFacets;
353 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
354 {
355 if (std::count(handledFacets.begin(), handledFacets.end(), intersection.indexInInside()))
356 continue;
357
358 handledFacets.push_back(intersection.indexInInside());
359
360 // determine if all corners live on the facet grid
361 const auto isGeometry = intersection.geometry();
362 const auto numFaceCorners = isGeometry.corners();
363 const auto idxInInside = intersection.indexInInside();
364 const auto boundary = intersection.boundary();
365
366 std::vector<LocalIndexType> vIndicesLocal(numFaceCorners);
367 for (int i = 0; i < numFaceCorners; ++i)
368 vIndicesLocal[i] = static_cast<LocalIndexType>(refElement.subEntity(idxInInside, 1, i, dim));
369
370 // if all vertices are living on the facet grid, this is an interiour boundary
371 const bool isOnFacet = gridGeometry().isOnInteriorBoundary(element, intersection);
372
373 if (isOnFacet || boundary)
374 {
375 for (unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < isGeometry.corners(); ++isScvfLocalIdx)
376 {
377 // find the inside scv this scvf is belonging to (localIdx = element local vertex index)
378 std::vector<LocalIndexType> localScvIndices = {vIndicesLocal[isScvfLocalIdx], vIndicesLocal[isScvfLocalIdx]};
379
380 // create the sub-control volume face
381 scvfs_.emplace_back(geometryHelper,
382 intersection,
383 isGeometry,
384 isScvfLocalIdx,
385 scvfLocalIdx,
386 std::move(localScvIndices),
387 boundary,
388 isOnFacet);
389
390 // increment local counter
391 scvfLocalIdx++;
392 }
393 }
394 }
395 }
396
398 const GridGeometry* gridGeometryPtr_;
399
401 GridIndexType eIdx_;
402 std::optional<Element> element_;
403
405 std::vector<SubControlVolume> scvs_;
406 std::vector<SubControlVolumeFace> scvfs_;
407};
408
409} // end namespace Dumux
410
411#endif
Defines the index types used for grid and local indices.
Helper class constructing the dual grid finite volume geometries for the box discretizazion method.
Class providing iterators over sub control volumes and sub control volume faces of an element.
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:39
unsigned int LocalIndex
Definition: indextraits.hh:40
Create sub control volumes and sub control volume face geometries.
Definition: boxgeometryhelper.hh:269
Base class for the element-local finite volume geometry for box models in the context of models consi...
Definition: multidomain/facet/box/fvelementgeometry.hh:48
void bindElement(const Element &element) &
Definition: multidomain/facet/box/fvelementgeometry.hh:155
GG GridGeometry
export type of finite volume grid geometry
Definition: multidomain/facet/box/fvelementgeometry.hh:69
BoxFacetCouplingFVElementGeometry bind(const Element &element) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: multidomain/facet/box/fvelementgeometry.hh:129
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: multidomain/facet/box/fvelementgeometry.hh:166
void bind(const Element &element) &
Definition: multidomain/facet/box/fvelementgeometry.hh:138
std::size_t numScv() const
The total number of sub control volumes.
Definition: multidomain/facet/box/fvelementgeometry.hh:117
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: multidomain/facet/box/fvelementgeometry.hh:79
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:105
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: multidomain/facet/box/fvelementgeometry.hh:83
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: multidomain/facet/box/fvelementgeometry.hh:65
BoxFacetCouplingFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: multidomain/facet/box/fvelementgeometry.hh:74
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: multidomain/facet/box/fvelementgeometry.hh:162
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:92
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: multidomain/facet/box/fvelementgeometry.hh:67
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: multidomain/facet/box/fvelementgeometry.hh:121
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: multidomain/facet/box/fvelementgeometry.hh:113
const Element & element() const
The bound element.
Definition: multidomain/facet/box/fvelementgeometry.hh:170
typename GridView::template Codim< 0 >::Entity Element
export type of the element
Definition: multidomain/facet/box/fvelementgeometry.hh:63
BoxFacetCouplingFVElementGeometry bindElement(const Element &element) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: multidomain/facet/box/fvelementgeometry.hh:146
void bindElement(const Element &element) &
Definition: multidomain/facet/box/fvelementgeometry.hh:289
BoxFacetCouplingFVElementGeometry bindElement(const Element &element) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: multidomain/facet/box/fvelementgeometry.hh:280
BoxFacetCouplingFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: multidomain/facet/box/fvelementgeometry.hh:210
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: multidomain/facet/box/fvelementgeometry.hh:215
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: multidomain/facet/box/fvelementgeometry.hh:203
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: multidomain/facet/box/fvelementgeometry.hh:247
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:240
void bind(const Element &element) &
Definition: multidomain/facet/box/fvelementgeometry.hh:272
std::size_t numScv() const
The total number of sub control volumes.
Definition: multidomain/facet/box/fvelementgeometry.hh:251
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: multidomain/facet/box/fvelementgeometry.hh:301
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: multidomain/facet/box/fvelementgeometry.hh:255
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:228
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: multidomain/facet/box/fvelementgeometry.hh:201
typename GridView::template Codim< 0 >::Entity Element
export type of the element
Definition: multidomain/facet/box/fvelementgeometry.hh:199
GG GridGeometry
export type of finite volume grid geometry
Definition: multidomain/facet/box/fvelementgeometry.hh:205
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: multidomain/facet/box/fvelementgeometry.hh:297
const Element & element() const
The bound element.
Definition: multidomain/facet/box/fvelementgeometry.hh:305
BoxFacetCouplingFVElementGeometry bind(const Element &element) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: multidomain/facet/box/fvelementgeometry.hh:263
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: multidomain/facet/box/fvelementgeometry.hh:219