version 3.11-dev
Loading...
Searching...
No Matches
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).")]]
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
150 {
151 element_ = element;
152 elementGeometry_.emplace(element.geometry());
153 eIdx_ = gridGeometry().elementMapper().index(element);
154 }
155
158 { return ggCache_->gridGeometry(); }
159
161 bool isBound() const
162 { return static_cast<bool>(element_); }
163
165 const Element& element() const
166 { return *element_; }
167
169 const typename Element::Geometry& elementGeometry() const
170 { return *elementGeometry_; }
171
173 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
174 {
175 assert(isBound());
176 const auto geo = element().geometry();
177 return { Dune::GeometryTypes::cube(dim), GeometryHelper(geo).getScvCorners(scv.indexInElement()) };
178 }
179
181 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
182 {
183 assert(isBound());
184 using ScvfGeometry = typename SubControlVolumeFace::Traits::Geometry;
185 const GeometryHelper geometryHelper(element().geometry());
186 if (scvf.boundary() || scvf.interiorBoundary())
187 return {
188 Dune::GeometryTypes::cube(ScvfGeometry::mydimension),
189 geometryHelper.getBoundaryScvfCorners(
190 scvf.facetIndexInElement(),
191 scvf.indexInElementFacet()
192 )
193 };
194
195 return {
196 Dune::GeometryTypes::cube(ScvfGeometry::mydimension),
197 geometryHelper.getScvfCorners(scvf.index())
198 };
199 }
200
201private:
202 const GGCache* ggCache_;
203
204 GridIndexType eIdx_;
205 std::optional<Element> element_;
206 std::optional<typename Element::Geometry> elementGeometry_;
207};
208
210template<class GG>
212{
213 using GridView = typename GG::GridView;
214 static constexpr int dim = GridView::dimension;
215 static constexpr int dimWorld = GridView::dimensionworld;
216
217 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
218 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
219
220 using CoordScalar = typename GridView::ctype;
221 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
222 using GGCache = typename GG::Cache;
223 using GeometryHelper = typename GGCache::GeometryHelper;
224public:
226 using Element = typename GridView::template Codim<0>::Entity;
228 using SubControlVolume = typename GG::SubControlVolume;
230 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
232 using GridGeometry = GG;
234 static constexpr std::size_t maxNumElementScvs = (1<<dim);
235
237 [[deprecated("This Constructor is deprecated and will be removed after release 3.11. Always use localView(gridGeometry).")]]
240
242 BoxFacetCouplingFVElementGeometry(const GGCache& ggCache)
243 : ggCache_(&ggCache) {}
244
246 const SubControlVolume& scv(LocalIndexType scvIdx) const
247 { return scvs_[scvIdx]; }
248
250 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
251 { return scvfs_[scvfIdx]; }
252
258 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
260 {
261 using Iter = typename std::vector<SubControlVolume>::const_iterator;
262 return Dune::IteratorRange<Iter>(fvGeometry.scvs_.begin(), fvGeometry.scvs_.end());
263 }
264
270 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
272 {
273 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
274 return Dune::IteratorRange<Iter>(fvGeometry.scvfs_.begin(), fvGeometry.scvfs_.end());
275 }
276
278 const FeLocalBasis& feLocalBasis() const
279 { return gridGeometry().feCache().get(element_->type()).localBasis(); }
280
282 std::size_t numScv() const
283 { return scvs_.size(); }
284
286 std::size_t numScvf() const
287 { return scvfs_.size(); }
288
295 {
296 this->bindElement(element);
297 return std::move(*this);
298 }
299
303 void bind(const Element& element) &
304 { this->bindElement(element); }
305
312 {
313 this->bindElement(element);
314 return std::move(*this);
315 }
316
321 {
322 element_ = element;
323 elementGeometry_.emplace(element.geometry());
324 eIdx_ = gridGeometry().elementMapper().index(element);
325 makeElementGeometries_();
326 }
327
330 { return ggCache_->gridGeometry(); }
331
333 bool isBound() const
334 { return static_cast<bool>(element_); }
335
337 const Element& element() const
338 { return *element_; }
339
341 const typename Element::Geometry& elementGeometry() const
342 { return *elementGeometry_; }
343
345 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
346 {
347 assert(isBound());
348 const auto geo = element().geometry();
349 return { Dune::GeometryTypes::cube(dim), GeometryHelper(geo).getScvCorners(scv.indexInElement()) };
350 }
351
353 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
354 {
355 assert(isBound());
356 using ScvfGeometry = typename SubControlVolumeFace::Traits::Geometry;
357 GeometryHelper geometryHelper(element().geometry());
358
359 if (scvf.boundary() || scvf.interiorBoundary())
360 return {
361 Dune::GeometryTypes::cube(ScvfGeometry::mydimension),
362 geometryHelper.getBoundaryScvfCorners(
363 scvf.facetIndexInElement(),
364 scvf.indexInElementFacet()
365 )
366 };
367
368 return {
369 Dune::GeometryTypes::cube(ScvfGeometry::mydimension),
370 geometryHelper.getScvfCorners(scvf.index())
371 };
372 }
373
374private:
375
376 void makeElementGeometries_()
377 {
378 // get the element geometry
379 const auto& element = *element_;
380 const auto elementGeometry = element.geometry();
381 const auto refElement = referenceElement(elementGeometry);
382
383 // get the sub control volume geometries of this element
384 GeometryHelper geometryHelper(elementGeometry);
385
386 // construct the sub control volumes
387 scvs_.clear();
388 scvs_.reserve(elementGeometry.corners());
389 using LocalIndexType = typename SubControlVolumeFace::Traits::LocalIndexType;
390 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
391 scvs_.emplace_back(geometryHelper.getScvCorners(scvLocalIdx),
392 scvLocalIdx,
393 eIdx_,
394 gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim));
395
396 // construct the sub control volume faces
397 const auto numInnerScvf = (dim==1) ? 1 : element.subEntities(dim-1);
398 scvfs_.clear();
399 scvfs_.reserve(numInnerScvf);
400
401 LocalIndexType scvfLocalIdx = 0;
402 for (; scvfLocalIdx < numInnerScvf; ++scvfLocalIdx)
403 {
404 // find the local scv indices this scvf is connected to
405 std::array<LocalIndexType, 2> localScvIndices{{
406 static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
407 static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))
408 }};
409
410 // create the sub-control volume face
411 scvfs_.emplace_back(geometryHelper,
412 element,
413 scvfLocalIdx,
414 std::move(localScvIndices));
415 }
416
417 // construct the sub control volume faces on the domain/interior boundaries
418 // skip handled facets (necessary for e.g. Dune::FoamGrid)
419 std::vector<unsigned int> handledFacets;
420 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
421 {
422 if (std::count(handledFacets.begin(), handledFacets.end(), intersection.indexInInside()))
423 continue;
424
425 handledFacets.push_back(intersection.indexInInside());
426
427 // determine if all corners live on the facet grid
428 const auto isGeometry = intersection.geometry();
429 const auto numFaceCorners = isGeometry.corners();
430 const auto idxInInside = intersection.indexInInside();
431 const auto boundary = intersection.boundary();
432
433 std::vector<LocalIndexType> vIndicesLocal(numFaceCorners);
434 for (int i = 0; i < numFaceCorners; ++i)
435 vIndicesLocal[i] = static_cast<LocalIndexType>(refElement.subEntity(idxInInside, 1, i, dim));
436
437 // if all vertices are living on the facet grid, this is an interiour boundary
438 const bool isOnFacet = gridGeometry().isOnInteriorBoundary(element, intersection);
439
440 if (isOnFacet || boundary)
441 {
442 for (unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < isGeometry.corners(); ++isScvfLocalIdx)
443 {
444 // find the inside scv this scvf is belonging to (localIdx = element local vertex index)
445 std::array<LocalIndexType, 2> localScvIndices{{
446 vIndicesLocal[isScvfLocalIdx], vIndicesLocal[isScvfLocalIdx]
447 }};
448
449 // create the sub-control volume face
450 scvfs_.emplace_back(geometryHelper,
451 intersection,
452 isScvfLocalIdx,
453 scvfLocalIdx,
454 std::move(localScvIndices),
455 boundary,
456 isOnFacet);
457
458 // increment local counter
459 scvfLocalIdx++;
460 }
461 }
462 }
463 }
464
466 GridIndexType eIdx_;
467 std::optional<Element> element_;
468 std::optional<typename Element::Geometry> elementGeometry_;
469
471 const GGCache* ggCache_;
472
474 std::vector<SubControlVolume> scvs_;
475 std::vector<SubControlVolumeFace> scvfs_;
476};
477
478} // end namespace Dumux
479
480#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:320
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:311
BoxFacetCouplingFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition multidomain/facet/box/fvelementgeometry.hh:238
const Element::Geometry & elementGeometry() const
The geometry of the bound element.
Definition multidomain/facet/box/fvelementgeometry.hh:341
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition multidomain/facet/box/fvelementgeometry.hh:246
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition multidomain/facet/box/fvelementgeometry.hh:230
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition multidomain/facet/box/fvelementgeometry.hh:278
SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace &scvf) const
Create the geometry of a given sub control volume face.
Definition multidomain/facet/box/fvelementgeometry.hh:353
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition multidomain/facet/box/fvelementgeometry.hh:271
void bind(const Element &element) &
Definition multidomain/facet/box/fvelementgeometry.hh:303
BoxFacetCouplingFVElementGeometry(const GGCache &ggCache)
Constructor.
Definition multidomain/facet/box/fvelementgeometry.hh:242
std::size_t numScv() const
The total number of sub control volumes.
Definition multidomain/facet/box/fvelementgeometry.hh:282
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition multidomain/facet/box/fvelementgeometry.hh:333
std::size_t numScvf() const
The total number of sub control volume faces.
Definition multidomain/facet/box/fvelementgeometry.hh:286
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition multidomain/facet/box/fvelementgeometry.hh:259
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition multidomain/facet/box/fvelementgeometry.hh:228
typename GridView::template Codim< 0 >::Entity Element
export type of the element
Definition multidomain/facet/box/fvelementgeometry.hh:226
GG GridGeometry
export type of finite volume grid geometry
Definition multidomain/facet/box/fvelementgeometry.hh:232
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition multidomain/facet/box/fvelementgeometry.hh:329
SubControlVolume::Traits::Geometry geometry(const SubControlVolume &scv) const
Create the geometry of a given sub control volume.
Definition multidomain/facet/box/fvelementgeometry.hh:345
const Element & element() const
The bound element.
Definition multidomain/facet/box/fvelementgeometry.hh:337
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:294
static constexpr std::size_t maxNumElementScvs
the maximum number of scvs per element (2^dim for cubes)
Definition multidomain/facet/box/fvelementgeometry.hh:234
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition multidomain/facet/box/fvelementgeometry.hh:250
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:181
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition multidomain/facet/box/fvelementgeometry.hh:161
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 Element::Geometry & elementGeometry() const
The geometry of the bound element.
Definition multidomain/facet/box/fvelementgeometry.hh:169
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition multidomain/facet/box/fvelementgeometry.hh:77
static constexpr std::size_t maxNumElementScvs
the maximum number of scvs per element (2^dim for cubes)
Definition multidomain/facet/box/fvelementgeometry.hh:61
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:157
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:173
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:165
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