version 3.10-dev
porousmediumflow/boxdfm/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-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
17#ifndef DUMUX_POROUSMEDIUMFLOW_BOXDFM_FV_ELEMENT_GEOMETRY_HH
18#define DUMUX_POROUSMEDIUMFLOW_BOXDFM_FV_ELEMENT_GEOMETRY_HH
19
20#include <optional>
21#include <utility>
22
23#include <dune/geometry/type.hh>
24#include <dune/localfunctions/lagrange/pqkfactory.hh>
25
27#include "geometryhelper.hh"
28
29namespace Dumux {
30
40template<class GG, bool enableGridGeometryCache>
42
44template<class GG>
46{
47 using GridView = typename GG::GridView;
48 static constexpr int dim = GridView::dimension;
49 static constexpr int dimWorld = GridView::dimensionworld;
50 using GridIndexType = typename GridView::IndexSet::IndexType;
51 using CoordScalar = typename GridView::ctype;
52 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
53public:
55 using Element = typename GridView::template Codim<0>::Entity;
57 using SubControlVolume = typename GG::SubControlVolume;
59 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
61 using GridGeometry = GG;
62
65 static constexpr std::size_t maxNumElementScvs = (1<<dim)*3;
66
69 : gridGeometryPtr_(&gridGeometry) {}
70
72 const SubControlVolume& scv(std::size_t scvIdx) const
73 { return gridGeometry().scvs(eIdx_)[scvIdx]; }
74
76 const SubControlVolumeFace& scvf(std::size_t scvfIdx) const
77 { return gridGeometry().scvfs(eIdx_)[scvfIdx]; }
78
87 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
88 scvs(const BoxDfmFVElementGeometry& fvGeometry)
89 {
90 const auto& g = fvGeometry.gridGeometry();
91 using Iter = typename std::vector<SubControlVolume>::const_iterator;
92 return Dune::IteratorRange<Iter>(g.scvs(fvGeometry.eIdx_).begin(), g.scvs(fvGeometry.eIdx_).end());
93 }
94
103 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
105 {
106 const auto& g = fvGeometry.gridGeometry();
107 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
108 return Dune::IteratorRange<Iter>(g.scvfs(fvGeometry.eIdx_).begin(), g.scvfs(fvGeometry.eIdx_).end());
109 }
110
112 const FeLocalBasis& feLocalBasis() const
113 { return gridGeometry().feCache().get(element_->type()).localBasis(); }
114
116 std::size_t numScv() const
117 { return gridGeometry().scvs(eIdx_).size(); }
118
120 std::size_t numScvf() const
121 { return gridGeometry().scvfs(eIdx_).size(); }
122
129 {
130 this->bindElement(element);
131 return std::move(*this);
132 }
133
136 void bind(const Element& element) &
137 { this->bindElement(element); }
138
145 {
146 this->bindElement(element);
147 return std::move(*this);
148 }
149
156 void bindElement(const Element& element) &
157 {
158 element_ = element;
159 eIdx_ = gridGeometry().elementMapper().index(element);
160 }
161
164 { return *gridGeometryPtr_; }
165
167 bool isBound() const
168 { return static_cast<bool>(element_); }
169
171 const Element& element() const
172 { return *element_; }
173
175 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
176 {
177 if (scv.isOnFracture())
178 DUNE_THROW(Dune::InvalidStateException, "The geometry object cannot be defined for fracture scvs "
179 "because the number of known corners is insufficient. "
180 "You can do this manually by extracting the corners from this scv "
181 "and extruding them by the corresponding aperture. ");
182
183 const typename GG::GeometryHelper geometryHelper(element().geometry());
184 const auto corners = geometryHelper.getScvCorners(scv.index());
185 using ScvGeometry = typename SubControlVolume::Traits::Geometry;
186 return { Dune::GeometryTypes::cube(ScvGeometry::mydimension), corners };
187 }
188
190 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
191 {
192 if (scvf.isOnFracture())
193 DUNE_THROW(Dune::InvalidStateException, "The geometry object cannot be defined for fracture scvs "
194 "because the number of known corners is insufficient. "
195 "You can do this manually by extracting the corners from this scv "
196 "and extruding them by the corresponding aperture. ");
197 const typename GG::GeometryHelper geometryHelper(element().geometry());
198 const auto corners = geometryHelper.getScvfCorners(scvf.indexInElement());
199 using ScvfGeometry = typename SubControlVolumeFace::Traits::Geometry;
200 return { Dune::GeometryTypes::cube(ScvfGeometry::mydimension), corners };
201 }
202
203private:
204 const GridGeometry* gridGeometryPtr_;
205
206 std::optional<Element> element_;
207 GridIndexType eIdx_;
208};
209
211template<class GG>
213{
214 using GridView = typename GG::GridView;
215 static constexpr int dim = GridView::dimension;
216 static constexpr int dimWorld = GridView::dimensionworld;
217
218 using GridIndexType = typename GridView::IndexSet::IndexType;
219
220 using CoordScalar = typename GridView::ctype;
221 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
222 using GeometryHelper = typename GG::GeometryHelper;
223public:
225 using Element = typename GridView::template Codim<0>::Entity;
227 using SubControlVolume = typename GG::SubControlVolume;
229 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
231 using GridGeometry = GG;
234 static constexpr std::size_t maxNumElementScvs = (1<<dim)*3;
235
238 : gridGeometryPtr_(&gridGeometry) {}
239
241 const SubControlVolume& scv(std::size_t scvIdx) const
242 { return scvs_[scvIdx]; }
243
245 const SubControlVolumeFace& scvf(std::size_t scvfIdx) const
246 { return scvfs_[scvfIdx]; }
247
256 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
257 scvs(const BoxDfmFVElementGeometry& fvGeometry)
258 {
259 using Iter = typename std::vector<SubControlVolume>::const_iterator;
260 return Dune::IteratorRange<Iter>(fvGeometry.scvs_.begin(), fvGeometry.scvs_.end());
261 }
262
271 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
273 {
274 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
275 return Dune::IteratorRange<Iter>(fvGeometry.scvfs_.begin(), fvGeometry.scvfs_.end());
276 }
277
279 const FeLocalBasis& feLocalBasis() const
280 { return gridGeometry().feCache().get(element_->type()).localBasis(); }
281
283 std::size_t numScv() const
284 { return scvs_.size(); }
285
287 std::size_t numScvf() const
288 { return scvfs_.size(); }
289
296 {
297 this->bindElement(element);
298 return std::move(*this);
299 }
300
307 void bind(const Element& element) &
308 { this->bindElement(element); }
309
316 {
317 this->bindElement(element);
318 return std::move(*this);
319 }
320
325 void bindElement(const Element& element) &
326 {
327 element_ = element;
328 eIdx_ = gridGeometry().elementMapper().index(element);
329 makeElementGeometries_();
330 }
331
334 { return *gridGeometryPtr_; }
335
337 bool isBound() const
338 { return static_cast<bool>(element_); }
339
341 const Element& element() const
342 { return *element_; }
343
345 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
346 {
347 if (scv.isOnFracture())
348 DUNE_THROW(Dune::InvalidStateException, "The geometry object cannot be defined for fracture scvs "
349 "because the number of known corners is insufficient. "
350 "You can do this manually by extracting the corners from this scv "
351 "and extruding them by the corresponding aperture. ");
352
353 const GeometryHelper geometryHelper(element().geometry());
354 const auto corners = geometryHelper.getScvCorners(scv.index());
355 using ScvGeometry = typename SubControlVolume::Traits::Geometry;
356 return { Dune::GeometryTypes::cube(ScvGeometry::mydimension), corners };
357 }
358
360 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
361 {
362 if (scvf.isOnFracture())
363 DUNE_THROW(Dune::InvalidStateException, "The geometry object cannot be defined for fracture scvs "
364 "because the number of known corners is insufficient. "
365 "You can do this manually by extracting the corners from this scv "
366 "and extruding them by the corresponding aperture. ");
367 const GeometryHelper geometryHelper(element().geometry());
368 const auto corners = geometryHelper.getScvfCorners(scvf.indexInElement());
369 using ScvfGeometry = typename SubControlVolumeFace::Traits::Geometry;
370 return { Dune::GeometryTypes::cube(ScvfGeometry::mydimension), corners };
371 }
372
373private:
374
375 void makeElementGeometries_()
376 {
377 // get the element geometry
378 const auto& element = *element_;
379 const auto elementGeometry = element.geometry();
380 const auto refElement = referenceElement(element);
381
382 // get the sub control volume geometries of this element
383 GeometryHelper geometryHelper(elementGeometry);
384
385 // construct the sub control volumes
386 scvs_.resize(elementGeometry.corners());
387 using LocalIndexType = typename SubControlVolumeFace::Traits::LocalIndexType;
388 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
389 {
390 // get associated dof index
391 const auto dofIdxGlobal = gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim);
392
393 // add scv to the local container
394 scvs_[scvLocalIdx] = SubControlVolume(geometryHelper,
395 scvLocalIdx,
396 eIdx_,
397 dofIdxGlobal);
398 }
399
400 // construct the sub control volume faces
401 const auto numInnerScvf = (dim==1) ? 1 : element.subEntities(dim-1);
402 scvfs_.resize(numInnerScvf);
403
404 unsigned int scvfLocalIdx = 0;
405 for (; scvfLocalIdx < numInnerScvf; ++scvfLocalIdx)
406 {
407 // find the local scv indices this scvf is connected to
408 std::vector<LocalIndexType> localScvIndices({static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
409 static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
410
411 scvfs_[scvfLocalIdx] = SubControlVolumeFace(geometryHelper,
412 element,
413 elementGeometry,
414 scvfLocalIdx,
415 std::move(localScvIndices));
416 }
417
418 // construct the ...
419 // ... sub-control volume faces on the domain boundary
420 // ... sub-control volumes on fracture facets
421 // ... sub-control volume faces on fracture facets
422 // NOTE We do not construct fracture scvfs on boundaries here!
423 // That means specifying Neumann fluxes on only the fractures is not possible
424 // However, it is difficult to interpret this here as a fracture ending on the boundary
425 // could also be connected to a facet which is both boundary and fracture at the same time!
426 // In that case, the fracture boundary scvf wouldn't make sense. In order to do it properly
427 // we would have to find only those fractures that are at the boundary and aren't connected
428 // to a fracture which is a boundary.
429 LocalIndexType scvLocalIdx = element.subEntities(dim);
430 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
431 {
432 // first, obtain all vertex indices on this intersection
433 const auto& isGeometry = intersection.geometry();
434 const auto numCorners = isGeometry.corners();
435 const auto idxInInside = intersection.indexInInside();
436
437 std::vector<GridIndexType> isVertexIndices(numCorners);
438 for (unsigned int vIdxLocal = 0; vIdxLocal < numCorners; ++vIdxLocal)
439 isVertexIndices[vIdxLocal] = gridGeometry().vertexMapper().subIndex(element,
440 refElement.subEntity(idxInInside, 1, vIdxLocal, dim),
441 dim);
442
443 if (intersection.boundary())
444 {
445 for (unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < numCorners; ++isScvfLocalIdx)
446 {
447 // find the scv this scvf is connected to
448 const LocalIndexType insideScvIdx = static_cast<LocalIndexType>(refElement.subEntity(idxInInside, 1, isScvfLocalIdx, dim));
449 std::vector<LocalIndexType> localScvIndices = {insideScvIdx, insideScvIdx};
450
451 scvfs_.emplace_back(geometryHelper,
452 intersection,
453 isGeometry,
454 isScvfLocalIdx,
455 scvfLocalIdx,
456 std::move(localScvIndices));
457
458 // increment local counter
459 scvfLocalIdx++;
460 }
461 }
462
463 // maybe add fracture scvs & scvfs
464 if (this->gridGeometry().isOnFracture(element, intersection))
465 {
466 // add fracture scv for each vertex of intersection
467 const auto curNumScvs = scvs_.size();
468 scvs_.reserve(curNumScvs+numCorners);
469 for (unsigned int vIdxLocal = 0; vIdxLocal < numCorners; ++vIdxLocal)
470 scvs_.emplace_back(geometryHelper,
471 intersection,
472 isGeometry,
473 vIdxLocal,
474 static_cast<LocalIndexType>(refElement.subEntity(idxInInside, 1, vIdxLocal, dim)),
475 scvLocalIdx++,
476 idxInInside,
477 eIdx_,
478 isVertexIndices[vIdxLocal]);
479
480 // add fracture scvf for each edge of the intersection in 3d
481 if (dim == 3)
482 {
483 const auto& faceRefElement = referenceElement(isGeometry);
484 for (unsigned int edgeIdx = 0; edgeIdx < faceRefElement.size(1); ++edgeIdx)
485 {
486 // inside/outside scv indices in face local node numbering
487 std::vector<LocalIndexType> localScvIndices({static_cast<LocalIndexType>(faceRefElement.subEntity(edgeIdx, 1, 0, dim-1)),
488 static_cast<LocalIndexType>(faceRefElement.subEntity(edgeIdx, 1, 1, dim-1))});
489
490 // add offset to get the right scv indices
491 std::for_each( localScvIndices.begin(),
492 localScvIndices.end(),
493 [curNumScvs] (auto& elemLocalIdx) { elemLocalIdx += curNumScvs; } );
494
495 // add scvf
496 scvfs_.emplace_back(geometryHelper,
497 intersection,
498 isGeometry,
499 edgeIdx,
500 scvfLocalIdx++,
501 std::move(localScvIndices),
502 intersection.boundary());
503 }
504 }
505
506 // dim == 2, intersection is an edge, make 1 scvf
507 else
508 {
509 // inside/outside scv indices in face local node numbering
510 std::vector<LocalIndexType> localScvIndices({0, 1});
511
512 // add offset such that the fracture scvs above are addressed
513 std::for_each( localScvIndices.begin(),
514 localScvIndices.end(),
515 [curNumScvs] (auto& elemLocalIdx) { elemLocalIdx += curNumScvs; } );
516
517 // add scvf
518 scvfs_.emplace_back(geometryHelper,
519 intersection,
520 isGeometry,
521 /*idxOnIntersection*/0,
522 scvfLocalIdx++,
523 std::move(localScvIndices),
524 intersection.boundary());
525 }
526 }
527 }
528 }
529
531 std::optional<Element> element_;
532 GridIndexType eIdx_;
533
535 const GridGeometry* gridGeometryPtr_;
536
538 std::vector<SubControlVolume> scvs_;
539 std::vector<SubControlVolumeFace> scvfs_;
540};
541
542} // end namespace Dumux
543
544#endif
SubControlVolume::Traits::Geometry geometry(const SubControlVolume &scv) const
Create the geometry of a given sub control volume.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:345
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:279
const SubControlVolumeFace & scvf(std::size_t scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:245
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:333
BoxDfmFVElementGeometry 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: porousmediumflow/boxdfm/fvelementgeometry.hh:315
typename GridView::template Codim< 0 >::Entity Element
export type of the element
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:225
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:287
void bind(const Element &element) &
Binding of an element, has to be called before using the fvgeometries Prepares all the volume variabl...
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:307
BoxDfmFVElementGeometry 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: porousmediumflow/boxdfm/fvelementgeometry.hh:295
const Element & element() const
The bound element.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:341
SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace &scvf) const
Create the geometry of a given sub control volume face.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:360
BoxDfmFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:237
std::size_t numScv() const
The total number of sub control volumes.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:283
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:337
const SubControlVolume & scv(std::size_t scvIdx) const
Get a sub control volume with a local scv index.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:241
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxDfmFVElementGeometry &fvGeometry)
Iterator range for sub control volumes.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:257
GG GridGeometry
Export type of finite volume grid geometry.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:231
typename GG::SubControlVolumeFace SubControlVolumeFace
Export type of subcontrol volume face.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:229
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxDfmFVElementGeometry &fvGeometry)
Iterator range for sub control volumes faces.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:272
typename GG::SubControlVolume SubControlVolume
Export type of subcontrol volume.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:227
void bindElement(const Element &element) &
Binding of an element, has to be called before using the fvgeometries Prepares all the volume variabl...
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:325
typename GG::SubControlVolumeFace SubControlVolumeFace
Export type of subcontrol volume face.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:59
void bindElement(const Element &element) &
Binding of an element, has to be called before using the fvgeometries.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:156
std::size_t numScv() const
The total number of sub control volumes.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:116
const SubControlVolumeFace & scvf(std::size_t scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:76
GG GridGeometry
Export type of finite volume grid geometry.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:61
const Element & element() const
The bound element.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:171
void bind(const Element &element) &
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:136
BoxDfmFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:68
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:120
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:112
typename GridView::template Codim< 0 >::Entity Element
export type of the element
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:55
typename GG::SubControlVolume SubControlVolume
Export type of subcontrol volume.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:57
SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace &scvf) const
Create the geometry of a given sub control volume face.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:190
const SubControlVolume & scv(std::size_t scvIdx) const
Get a sub control volume with a local scv index.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:72
BoxDfmFVElementGeometry 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: porousmediumflow/boxdfm/fvelementgeometry.hh:128
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxDfmFVElementGeometry &fvGeometry)
Iterator range for sub control volumes.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:88
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:163
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:167
SubControlVolume::Traits::Geometry geometry(const SubControlVolume &scv) const
Create the geometry of a given sub control volume.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:175
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxDfmFVElementGeometry &fvGeometry)
Iterator range for sub control volumes faces.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:104
BoxDfmFVElementGeometry 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: porousmediumflow/boxdfm/fvelementgeometry.hh:144
Base class for the finite volume geometry vector for box discrete fracture model.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:41
std::size_t numCorners(Shape shape)
Returns the number of corners of a given geometry.
Definition: throatproperties.hh:220
Definition: adapt.hh:17
Helper class constructing the dual grid finite volume geometries for the box discrete fracture model.
Class providing iterators over sub control volumes and sub control volume faces of an element.