version 3.11-dev
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// SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_FACETCOUPLING_BOX_FV_ELEMENT_GEOMETRY_HH
13#define DUMUX_FACETCOUPLING_BOX_FV_ELEMENT_GEOMETRY_HH
14
15#include <algorithm>
16#include <optional>
17
18#include <dune/geometry/type.hh>
19
23
24namespace Dumux {
25
35template<class GG, bool enableGridGeometryCache>
37
39template<class GG>
41{
42 using GridView = typename GG::GridView;
43 static constexpr int dim = GridView::dimension;
44 static constexpr int dimWorld = GridView::dimensionworld;
45 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
46 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
47 using CoordScalar = typename GridView::ctype;
48 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
49 using GGCache = typename GG::Cache;
50 using GeometryHelper = typename GGCache::GeometryHelper;
51public:
53 using Element = typename GridView::template Codim<0>::Entity;
55 using SubControlVolume = typename GG::SubControlVolume;
57 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
59 using GridGeometry = GG;
61 static constexpr std::size_t maxNumElementScvs = (1<<dim);
62
64 [[deprecated("This Constructor is deprecated and will be removed after release 3.11. Always use localView(gridGeometry).")]]
66 : BoxFacetCouplingFVElementGeometry(gridGeometry.cache_) {}
67
69 BoxFacetCouplingFVElementGeometry(const GGCache& ggCache)
70 : ggCache_(&ggCache) {}
71
73 const SubControlVolume& scv(LocalIndexType scvIdx) const
74 { return ggCache_->scvs(eIdx_)[scvIdx]; }
75
77 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
78 { return ggCache_->scvfs(eIdx_)[scvfIdx]; }
79
85 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
87 {
88 using Iter = typename std::vector<SubControlVolume>::const_iterator;
89 const auto& s = fvGeometry.ggCache_->scvs(fvGeometry.eIdx_);
90 return Dune::IteratorRange<Iter>(s.begin(), s.end());
91 }
92
98 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
100 {
101 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
102 const auto& s = fvGeometry.ggCache_->scvfs(fvGeometry.eIdx_);
103 return Dune::IteratorRange<Iter>(s.begin(), s.end());
104 }
105
107 const FeLocalBasis& feLocalBasis() const
108 { return gridGeometry().feCache().get(element_->type()).localBasis(); }
109
111 std::size_t numScv() const
112 { return ggCache_->scvs(eIdx_).size(); }
113
115 std::size_t numScvf() const
116 { return ggCache_->scvfs(eIdx_).size(); }
117
124 {
125 this->bindElement(element);
126 return std::move(*this);
127 }
128
132 void bind(const Element& element) &
133 { this->bindElement(element); }
134
141 {
142 this->bindElement(element);
143 return std::move(*this);
144 }
145
149 void bindElement(const Element& element) &
150 {
151 element_ = element;
152 eIdx_ = gridGeometry().elementMapper().index(element);
153 }
154
157 { return ggCache_->gridGeometry(); }
158
160 bool isBound() const
161 { return static_cast<bool>(element_); }
162
164 const Element& element() const
165 { return *element_; }
166
168 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
169 {
170 assert(isBound());
171 const auto geo = element().geometry();
172 return { Dune::GeometryTypes::cube(dim), GeometryHelper(geo).getScvCorners(scv.indexInElement()) };
173 }
174
176 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
177 {
178 assert(isBound());
179 using ScvfGeometry = typename SubControlVolumeFace::Traits::Geometry;
180 const GeometryHelper geometryHelper(element().geometry());
181 if (scvf.boundary() || scvf.interiorBoundary())
182 return {
183 Dune::GeometryTypes::cube(ScvfGeometry::mydimension),
184 geometryHelper.getBoundaryScvfCorners(
185 scvf.facetIndexInElement(),
186 scvf.indexInElementFacet()
187 )
188 };
189
190 return {
191 Dune::GeometryTypes::cube(ScvfGeometry::mydimension),
192 geometryHelper.getScvfCorners(scvf.index())
193 };
194 }
195
196private:
197 const GGCache* ggCache_;
198
199 GridIndexType eIdx_;
200 std::optional<Element> element_;
201};
202
204template<class GG>
206{
207 using GridView = typename GG::GridView;
208 static constexpr int dim = GridView::dimension;
209 static constexpr int dimWorld = GridView::dimensionworld;
210
211 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
212 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
213
214 using CoordScalar = typename GridView::ctype;
215 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
216 using GGCache = typename GG::Cache;
217 using GeometryHelper = typename GGCache::GeometryHelper;
218public:
220 using Element = typename GridView::template Codim<0>::Entity;
222 using SubControlVolume = typename GG::SubControlVolume;
224 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
226 using GridGeometry = GG;
228 static constexpr std::size_t maxNumElementScvs = (1<<dim);
229
231 [[deprecated("This Constructor is deprecated and will be removed after release 3.11. Always use localView(gridGeometry).")]]
233 : BoxFacetCouplingFVElementGeometry(gridGeometry.cache_) {}
234
236 BoxFacetCouplingFVElementGeometry(const GGCache& ggCache)
237 : ggCache_(&ggCache) {}
238
240 const SubControlVolume& scv(LocalIndexType scvIdx) const
241 { return scvs_[scvIdx]; }
242
244 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
245 { return scvfs_[scvfIdx]; }
246
252 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
254 {
255 using Iter = typename std::vector<SubControlVolume>::const_iterator;
256 return Dune::IteratorRange<Iter>(fvGeometry.scvs_.begin(), fvGeometry.scvs_.end());
257 }
258
264 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
266 {
267 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
268 return Dune::IteratorRange<Iter>(fvGeometry.scvfs_.begin(), fvGeometry.scvfs_.end());
269 }
270
272 const FeLocalBasis& feLocalBasis() const
273 { return gridGeometry().feCache().get(element_->type()).localBasis(); }
274
276 std::size_t numScv() const
277 { return scvs_.size(); }
278
280 std::size_t numScvf() const
281 { return scvfs_.size(); }
282
289 {
290 this->bindElement(element);
291 return std::move(*this);
292 }
293
297 void bind(const Element& element) &
298 { this->bindElement(element); }
299
306 {
307 this->bindElement(element);
308 return std::move(*this);
309 }
310
314 void bindElement(const Element& element) &
315 {
316 element_ = element;
317 eIdx_ = gridGeometry().elementMapper().index(element);
318 makeElementGeometries_();
319 }
320
323 { return ggCache_->gridGeometry(); }
324
326 bool isBound() const
327 { return static_cast<bool>(element_); }
328
330 const Element& element() const
331 { return *element_; }
332
334 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
335 {
336 assert(isBound());
337 const auto geo = element().geometry();
338 return { Dune::GeometryTypes::cube(dim), GeometryHelper(geo).getScvCorners(scv.indexInElement()) };
339 }
340
342 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
343 {
344 assert(isBound());
345 using ScvfGeometry = typename SubControlVolumeFace::Traits::Geometry;
346 GeometryHelper geometryHelper(element().geometry());
347
348 if (scvf.boundary() || scvf.interiorBoundary())
349 return {
350 Dune::GeometryTypes::cube(ScvfGeometry::mydimension),
351 geometryHelper.getBoundaryScvfCorners(
352 scvf.facetIndexInElement(),
353 scvf.indexInElementFacet()
354 )
355 };
356
357 return {
358 Dune::GeometryTypes::cube(ScvfGeometry::mydimension),
359 geometryHelper.getScvfCorners(scvf.index())
360 };
361 }
362
363private:
364
365 void makeElementGeometries_()
366 {
367 // get the element geometry
368 const auto& element = *element_;
369 const auto elementGeometry = element.geometry();
370 const auto refElement = referenceElement(elementGeometry);
371
372 // get the sub control volume geometries of this element
373 GeometryHelper geometryHelper(elementGeometry);
374
375 // construct the sub control volumes
376 scvs_.clear();
377 scvs_.reserve(elementGeometry.corners());
378 using LocalIndexType = typename SubControlVolumeFace::Traits::LocalIndexType;
379 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
380 scvs_.emplace_back(geometryHelper.getScvCorners(scvLocalIdx),
381 scvLocalIdx,
382 eIdx_,
383 gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim));
384
385 // construct the sub control volume faces
386 const auto numInnerScvf = (dim==1) ? 1 : element.subEntities(dim-1);
387 scvfs_.clear();
388 scvfs_.reserve(numInnerScvf);
389
390 LocalIndexType scvfLocalIdx = 0;
391 for (; scvfLocalIdx < numInnerScvf; ++scvfLocalIdx)
392 {
393 // find the local scv indices this scvf is connected to
394 std::array<LocalIndexType, 2> localScvIndices{{
395 static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
396 static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))
397 }};
398
399 // create the sub-control volume face
400 scvfs_.emplace_back(geometryHelper,
401 element,
402 scvfLocalIdx,
403 std::move(localScvIndices));
404 }
405
406 // construct the sub control volume faces on the domain/interior boundaries
407 // skip handled facets (necessary for e.g. Dune::FoamGrid)
408 std::vector<unsigned int> handledFacets;
409 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
410 {
411 if (std::count(handledFacets.begin(), handledFacets.end(), intersection.indexInInside()))
412 continue;
413
414 handledFacets.push_back(intersection.indexInInside());
415
416 // determine if all corners live on the facet grid
417 const auto isGeometry = intersection.geometry();
418 const auto numFaceCorners = isGeometry.corners();
419 const auto idxInInside = intersection.indexInInside();
420 const auto boundary = intersection.boundary();
421
422 std::vector<LocalIndexType> vIndicesLocal(numFaceCorners);
423 for (int i = 0; i < numFaceCorners; ++i)
424 vIndicesLocal[i] = static_cast<LocalIndexType>(refElement.subEntity(idxInInside, 1, i, dim));
425
426 // if all vertices are living on the facet grid, this is an interiour boundary
427 const bool isOnFacet = gridGeometry().isOnInteriorBoundary(element, intersection);
428
429 if (isOnFacet || boundary)
430 {
431 for (unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < isGeometry.corners(); ++isScvfLocalIdx)
432 {
433 // find the inside scv this scvf is belonging to (localIdx = element local vertex index)
434 std::array<LocalIndexType, 2> localScvIndices{{
435 vIndicesLocal[isScvfLocalIdx], vIndicesLocal[isScvfLocalIdx]
436 }};
437
438 // create the sub-control volume face
439 scvfs_.emplace_back(geometryHelper,
440 intersection,
441 isScvfLocalIdx,
442 scvfLocalIdx,
443 std::move(localScvIndices),
444 boundary,
445 isOnFacet);
446
447 // increment local counter
448 scvfLocalIdx++;
449 }
450 }
451 }
452 }
453
455 GridIndexType eIdx_;
456 std::optional<Element> element_;
457
459 const GGCache* ggCache_;
460
462 std::vector<SubControlVolume> scvs_;
463 std::vector<SubControlVolumeFace> scvfs_;
464};
465
466} // end namespace Dumux
467
468#endif
Helper class constructing the dual grid finite volume geometries for the box discretizazion method.
void bindElement(const Element &element) &
Definition: multidomain/facet/box/fvelementgeometry.hh:314
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:305
BoxFacetCouplingFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: multidomain/facet/box/fvelementgeometry.hh:232
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: multidomain/facet/box/fvelementgeometry.hh:240
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: multidomain/facet/box/fvelementgeometry.hh:224
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: multidomain/facet/box/fvelementgeometry.hh:272
SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace &scvf) const
Create the geometry of a given sub control volume face.
Definition: multidomain/facet/box/fvelementgeometry.hh:342
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:265
void bind(const Element &element) &
Definition: multidomain/facet/box/fvelementgeometry.hh:297
BoxFacetCouplingFVElementGeometry(const GGCache &ggCache)
Constructor.
Definition: multidomain/facet/box/fvelementgeometry.hh:236
std::size_t numScv() const
The total number of sub control volumes.
Definition: multidomain/facet/box/fvelementgeometry.hh:276
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: multidomain/facet/box/fvelementgeometry.hh:326
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: multidomain/facet/box/fvelementgeometry.hh:280
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:253
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: multidomain/facet/box/fvelementgeometry.hh:222
typename GridView::template Codim< 0 >::Entity Element
export type of the element
Definition: multidomain/facet/box/fvelementgeometry.hh:220
GG GridGeometry
export type of finite volume grid geometry
Definition: multidomain/facet/box/fvelementgeometry.hh:226
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: multidomain/facet/box/fvelementgeometry.hh:322
SubControlVolume::Traits::Geometry geometry(const SubControlVolume &scv) const
Create the geometry of a given sub control volume.
Definition: multidomain/facet/box/fvelementgeometry.hh:334
const Element & element() const
The bound element.
Definition: multidomain/facet/box/fvelementgeometry.hh:330
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:288
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: multidomain/facet/box/fvelementgeometry.hh:244
void bindElement(const Element &element) &
Definition: multidomain/facet/box/fvelementgeometry.hh:149
BoxFacetCouplingFVElementGeometry(const GGCache &ggCache)
Constructor.
Definition: multidomain/facet/box/fvelementgeometry.hh:69
GG GridGeometry
export type of finite volume grid geometry
Definition: multidomain/facet/box/fvelementgeometry.hh:59
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:123
SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace &scvf) const
Create the geometry of a given sub control volume face.
Definition: multidomain/facet/box/fvelementgeometry.hh:176
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: multidomain/facet/box/fvelementgeometry.hh:160
void bind(const Element &element) &
Definition: multidomain/facet/box/fvelementgeometry.hh:132
std::size_t numScv() const
The total number of sub control volumes.
Definition: multidomain/facet/box/fvelementgeometry.hh:111
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: multidomain/facet/box/fvelementgeometry.hh:73
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:99
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: multidomain/facet/box/fvelementgeometry.hh:77
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: multidomain/facet/box/fvelementgeometry.hh:55
BoxFacetCouplingFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: multidomain/facet/box/fvelementgeometry.hh:65
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: multidomain/facet/box/fvelementgeometry.hh:156
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:86
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: multidomain/facet/box/fvelementgeometry.hh:57
SubControlVolume::Traits::Geometry geometry(const SubControlVolume &scv) const
Create the geometry of a given sub control volume.
Definition: multidomain/facet/box/fvelementgeometry.hh:168
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: multidomain/facet/box/fvelementgeometry.hh:115
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: multidomain/facet/box/fvelementgeometry.hh:107
const Element & element() const
The bound element.
Definition: multidomain/facet/box/fvelementgeometry.hh:164
typename GridView::template Codim< 0 >::Entity Element
export type of the element
Definition: multidomain/facet/box/fvelementgeometry.hh:53
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:140
Base class for the element-local finite volume geometry for box models in the context of models consi...
Definition: multidomain/facet/box/fvelementgeometry.hh:36
Defines the index types used for grid and local indices.
Definition: adapt.hh:17
Class providing iterators over sub control volumes and sub control volume faces of an element.
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:27
unsigned int LocalIndex
Definition: indextraits.hh:28