14#ifndef DUMUX_DISCRETIZATION_PQ1BUBBLE_GRID_GEOMETRY_HH
15#define DUMUX_DISCRETIZATION_PQ1BUBBLE_GRID_GEOMETRY_HH
18#include <unordered_map>
22#include <dune/grid/common/mcmgmapper.hh>
48 =
typename T::EnableHybridCVFE;
52 = Dune::Std::detected_or_t<std::false_type, EnableHybridCVFE, T>{};
54template<
class GV,
class T>
56 std::conditional_t<enablesHybridCVFE<T>,
65template <
class Gr
idView, std::
size_t numCubeBubbles = 1>
68 using DofMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
69 static_assert(numCubeBubbles == 1 || numCubeBubbles == 2,
70 "PQ1BubbleMapperTraits supports numCubeBubbles = 1 or 2");
78 return [](Dune::GeometryType gt,
int dimgrid) {
82 if (gt.dim() == dimgrid)
94template<
class GridView,
108template<
class Gr
idView,
class MapperTraits = PQ1BubbleMapperTraits<Gr
idView>,
class QuadratureTraits = PQ1BubbleQuadratureTraits<Gr
idView>>
110:
public MapperTraits,
public QuadratureTraits
115 template<
class Gr
idGeometry,
bool enableCache>
119 + MapperTraits::numCubeBubbleDofs;
128template<
class BaseTraits>
139template<
class Scalar,
141 bool enableCaching =
true,
151 using Element =
typename GV::template Codim<0>::Entity;
152 using CoordScalar =
typename GV::ctype;
153 static const int dim = GV::dimension;
154 static const int dimWorld = GV::dimensionworld;
156 static_assert(dim > 1,
"Only implemented for dim > 1");
200 : ParentType(std::move(gg))
201 , dofMapper_(this->
gridView(), Traits::layout())
203 , periodicGridTraits_(this->
gridView().grid())
215 {
return dofMapper_; }
227 {
return numBoundaryScvf_; }
253 {
return boundaryDofIndices_[dofIdx]; }
257 {
return periodicDofMap_.count(dofIdx); }
261 {
return periodicDofMap_.at(dofIdx); }
265 {
return periodicDofMap_; }
269 {
return { gg.cache_ }; }
272 class PQ1BubbleGridGeometryCache
279 using DofHelper =
typename GeometryHelper::DofHelper;
285 const PQ1BubbleFVGridGeometry& gridGeometry()
const
286 {
return *gridGeometry_; }
289 const std::vector<SubControlVolume>& scvs(GridIndexType eIdx)
const
290 {
return scvs_[eIdx]; }
293 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx)
const
294 {
return scvfs_[eIdx]; }
297 bool hasBoundaryScvf(GridIndexType eIdx)
const
298 {
return hasBoundaryScvf_[eIdx]; }
301 const std::vector<std::array<LocalIndexType, 2>>& scvfBoundaryGeometryKeys(GridIndexType eIdx)
const
302 {
return scvfBoundaryGeometryKeys_.at(eIdx); }
305 auto boundaryFaces(GridIndexType eIdx)
const -> std::span<const BoundaryFace>
307 if (
auto it = boundaryFaces_.find(eIdx); it != boundaryFaces_.end())
313 const auto& boundaryFaceScvfRanges(GridIndexType eIdx)
const
314 {
return boundaryFaceScvfRanges_.at(eIdx); }
321 hasBoundaryScvf_.clear();
322 scvfBoundaryGeometryKeys_.clear();
323 boundaryFaces_.clear();
324 boundaryFaceScvfRanges_.clear();
327 std::vector<std::vector<SubControlVolume>> scvs_;
328 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
329 std::vector<bool> hasBoundaryScvf_;
330 std::unordered_map<GridIndexType, std::vector<std::array<LocalIndexType, 2>>> scvfBoundaryGeometryKeys_;
331 std::unordered_map<GridIndexType, Dune::ReservedVector<typename PQ1BubbleFVGridGeometry::BoundaryFace, 2*dim>> boundaryFaces_;
332 std::unordered_map<GridIndexType, Dune::ReservedVector<std::array<LocalIndexType, 2>, 2*dim>> boundaryFaceScvfRanges_;
334 const PQ1BubbleFVGridGeometry* gridGeometry_;
340 using Cache = PQ1BubbleGridGeometryCache;
343 using GeometryHelper =
typename Cache::GeometryHelper;
344 using DofHelper =
typename Cache::DofHelper;
349 dofMapper_.update(this->
gridView());
351 auto numElements = this->
gridView().size(0);
352 cache_.scvs_.resize(numElements);
353 cache_.scvfs_.resize(numElements);
354 cache_.hasBoundaryScvf_.resize(numElements,
false);
356 boundaryDofIndices_.assign(
numDofs(),
false);
360 numBoundaryScvf_ = 0;
368 auto elementGeometry =
element.geometry();
369 if (!
enableHybridCVFE && elementGeometry.type().isCube() && Traits::numCubeBubbleDofs > 1)
370 DUNE_THROW(Dune::NotImplemented,
"Multiple bubble dofs for cube elements only for hybrid scheme.");
372 const auto refElement = referenceElement(elementGeometry);
373 const auto& localCoefficients = this->
feCache().
get(
element.type()).localCoefficients();
376 GeometryHelper geometryHelper(elementGeometry);
378 numScv_ += geometryHelper.numScv();
380 cache_.scvs_[eIdx].resize(geometryHelper.numScv());
383 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < geometryHelper.numScv(); ++scvLocalIdx)
385 auto corners = geometryHelper.getScvCorners(scvLocalIdx);
387 geometryHelper.scvVolume(scvLocalIdx, corners),
388 geometryHelper.dofPosition(scvLocalIdx),
392 DofHelper::dofIndex(this->dofMapper(),
element, localCoefficients.localKey(scvLocalIdx)),
393 geometryHelper.isOverlappingScv(scvLocalIdx)
398 const auto numInteriorScvfs = GeometryHelper::numInteriorScvf(elementGeometry.type());
399 numScvf_ += numInteriorScvfs;
400 cache_.scvfs_[eIdx].resize(numInteriorScvfs);
401 LocalIndexType scvfLocalIdx = 0;
402 for (; scvfLocalIdx < numInteriorScvfs; ++scvfLocalIdx)
404 const auto scvPair = geometryHelper.getScvPairForScvf(scvfLocalIdx);
405 const auto corners = geometryHelper.getScvfCorners(scvfLocalIdx);
407 geometryHelper.getInteriorScvfGeometryType(scvfLocalIdx),
408 [&](
unsigned int i){
return corners[i]; }
414 geometryHelper.normal(corners, scvPair),
417 geometryHelper.isOverlappingScvf(scvfLocalIdx)
422 LocalIndexType numBoundaryFaces = 0;
423 for (
const auto& intersection : intersections(this->
gridView(),
element))
425 if (intersection.boundary() && !intersection.neighbor())
427 cache_.hasBoundaryScvf_[eIdx] =
true;
430 const auto isGeometry = intersection.geometry();
434 intersection.centerUnitOuterNormal(),
436 static_cast<LocalIndexType
>(intersection.indexInInside()),
437 typename BoundaryFace::Traits::BoundaryFlag{intersection}
440 const auto localFacetIndex = intersection.indexInInside();
441 const auto numBoundaryScvf = GeometryHelper::numBoundaryScvf(elementGeometry.type(), localFacetIndex);
446 cache_.boundaryFaceScvfRanges_[eIdx].push_back(std::array<LocalIndexType, 2>{{
451 for (
unsigned int isScvfLocalIdx = 0; isScvfLocalIdx <
numBoundaryScvf; ++isScvfLocalIdx)
454 const auto scvPair = geometryHelper.getScvPairForBoundaryScvf(localFacetIndex, isScvfLocalIdx);
455 const auto corners = geometryHelper.getBoundaryScvfCorners(localFacetIndex, isScvfLocalIdx);
457 geometryHelper.getBoundaryScvfGeometryType(isScvfLocalIdx),
458 [&](
unsigned int i){
return corners[i]; }
460 cache_.scvfs_[eIdx].emplace_back(
463 intersection.centerUnitOuterNormal(),
466 typename SubControlVolumeFace::Traits::BoundaryFlag{ intersection },
467 geometryHelper.isOverlappingBoundaryScvf(localFacetIndex)
471 cache_.scvfBoundaryGeometryKeys_[eIdx].emplace_back(std::array<LocalIndexType, 2>{{
472 static_cast<LocalIndexType
>(localFacetIndex),
473 static_cast<LocalIndexType
>(isScvfLocalIdx)
480 const auto numDofsIntersection = DofHelper::numLocalDofsIntersection(elementGeometry.type(), localFacetIndex);
483 for (
int ilocalDofIdx = 0; ilocalDofIdx < numDofsIntersection; ++ilocalDofIdx)
485 auto localDofIdx = DofHelper::localDofIndexIntersection(elementGeometry.type(), localFacetIndex, ilocalDofIdx);
486 const auto vIdxGlobal = DofHelper::dofIndex(this->
dofMapper(),
element, localCoefficients.localKey(localDofIdx));
487 boundaryDofIndices_[vIdxGlobal] =
true;
492 else if (periodicGridTraits_.isPeriodic(intersection))
497 const auto fIdx = intersection.indexInInside();
498 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
499 const auto eps = 1e-7*(elementGeometry.corner(1) - elementGeometry.corner(0)).two_norm();
500 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
502 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
504 const auto vPos = elementGeometry.corner(vIdx);
506 const auto& outside = intersection.outside();
507 const auto outsideGeometry = outside.geometry();
508 for (
const auto& isOutside : intersections(this->
gridView(), outside))
511 if (periodicGridTraits_.isPeriodic(isOutside))
513 const auto fIdxOutside = isOutside.indexInInside();
514 const auto numFaceVertsOutside = refElement.size(fIdxOutside, 1, dim);
515 for (
int localVIdxOutside = 0; localVIdxOutside < numFaceVertsOutside; ++localVIdxOutside)
517 const auto vIdxOutside = refElement.subEntity(fIdxOutside, 1, localVIdxOutside, dim);
518 const auto vPosOutside = outsideGeometry.corner(vIdxOutside);
519 const auto shift = std::abs((this->
bBoxMax()-this->
bBoxMin())*intersection.centerUnitOuterNormal());
520 if (std::abs((vPosOutside-vPos).two_norm() - shift) < eps)
521 periodicDofMap_[vIdxGlobal] = this->
dofMapper().subIndex(outside, vIdxOutside, dim);
532 DUNE_THROW(Dune::NotImplemented,
"Periodic boundaries for pq1bubble method for parallel simulations!");
540 std::size_t numScvf_;
541 std::size_t numBoundaryScvf_;
544 std::vector<bool> boundaryDofIndices_;
547 std::unordered_map<GridIndexType, GridIndexType> periodicDofMap_;
Base class for grid geometries.
Implementation of a boundary face related to primary grid elements (dune intersections).
Compute the center point of a convex polytope geometry or a random-access container of corner points.
const ElementMapper & elementMapper() const
Returns the mapper for elements to indices for constant grids.
Definition basegridgeometry.hh:112
void setPeriodic(bool value=true)
Set the periodicity of the grid geometry.
Definition basegridgeometry.hh:169
const GlobalCoordinate & bBoxMax() const
The coordinate of the corner of the GridView's bounding box with the largest values.
Definition basegridgeometry.hh:156
Element element(GridIndexType eIdx) const
Definition basegridgeometry.hh:142
const GridView & gridView() const
Definition basegridgeometry.hh:100
void update(const GridView &gridView)
Update all fvElementGeometries (call this after grid adaption).
Definition basegridgeometry.hh:88
const GlobalCoordinate & bBoxMin() const
The coordinate of the corner of the GridView's bounding box with the smallest values.
Definition basegridgeometry.hh:149
bool isPeriodic() const
Returns if the grid geometry is periodic (at all).
Definition basegridgeometry.hh:162
Class for a boundary face related to primary grid elements (dune intersections).
Definition boundaryface.hh:69
Definition discretization/pq1bubble/geometryhelper.hh:479
Definition pq1bubblefecache.hh:29
const FiniteElementType & get(const Dune::GeometryType >) const
Get local finite element for given GeometryType.
Definition pq1bubblefecache.hh:48
Base class for the finite volume geometry vector for pq1bubble models This builds up the sub control ...
Definition discretization/pq1bubble/fvelementgeometry.hh:43
Base class for the finite volume geometry vector for pq1bubble schemes This builds up the sub control...
Definition discretization/pq1bubble/fvgridgeometry.hh:145
void update(const GridView &gridView)
update all geometries (call this after grid adaption)
Definition discretization/pq1bubble/fvgridgeometry.hh:234
friend LocalView localView(const PQ1BubbleFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition discretization/pq1bubble/fvgridgeometry.hh:268
PQ1BubbleGridGeometryCache Cache
Definition discretization/pq1bubble/fvgridgeometry.hh:340
PQ1BubbleFVGridGeometry(std::shared_ptr< BasicGridGeometry > gg)
Constructor with basic grid geometry used to share state with another grid geometry on the same grid ...
Definition discretization/pq1bubble/fvgridgeometry.hh:199
static constexpr DiscretizationMethod discMethod
Definition discretization/pq1bubble/fvgridgeometry.hh:161
std::size_t numBoundaryScvf() const
The total number of boundary sub control volume faces.
Definition discretization/pq1bubble/fvgridgeometry.hh:226
Dumux::PQ1BubbleFECache< CoordScalar, Scalar, dim, PQ1BubbleDefaultGridGeometryTraits< GridView >::numCubeBubbleDofs > FeCache
Definition discretization/pq1bubble/fvgridgeometry.hh:182
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::ElementQuadratureRule ElementQuadratureRule
Definition discretization/pq1bubble/fvgridgeometry.hh:192
PQ1BubbleFVGridGeometry(const GridView &gridView)
Constructor.
Definition discretization/pq1bubble/fvgridgeometry.hh:209
BasicGridGeometry_t< GridView, PQ1BubbleDefaultGridGeometryTraits< GridView > > BasicGridGeometry
Definition discretization/pq1bubble/fvgridgeometry.hh:168
std::size_t numScv() const
The total number of sub control volumes.
Definition discretization/pq1bubble/fvgridgeometry.hh:218
std::size_t numScvf() const
The total number of sub control volume faces.
Definition discretization/pq1bubble/fvgridgeometry.hh:222
static constexpr std::size_t maxNumElementDofs
Definition discretization/pq1bubble/fvgridgeometry.hh:165
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition discretization/pq1bubble/fvgridgeometry.hh:248
GridIndexType periodicallyMappedDof(GridIndexType dofIdx) const
The index of the vertex / d.o.f. on the other side of the periodic boundary.
Definition discretization/pq1bubble/fvgridgeometry.hh:260
DiscretizationMethods::PQ1Bubble DiscretizationMethod
Definition discretization/pq1bubble/fvgridgeometry.hh:160
Extrusion_t< PQ1BubbleDefaultGridGeometryTraits< GridView > > Extrusion
Definition discretization/pq1bubble/fvgridgeometry.hh:178
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::BoundaryFaceQuadratureRule BoundaryFaceQuadratureRule
Definition discretization/pq1bubble/fvgridgeometry.hh:196
static constexpr bool enableHybridCVFE
Definition discretization/pq1bubble/fvgridgeometry.hh:163
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::SubControlVolumeFace SubControlVolumeFace
Definition discretization/pq1bubble/fvgridgeometry.hh:174
std::size_t numDofs() const
The total number of degrees of freedom.
Definition discretization/pq1bubble/fvgridgeometry.hh:230
bool dofOnBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition discretization/pq1bubble/fvgridgeometry.hh:252
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::DofMapper DofMapper
Definition discretization/pq1bubble/fvgridgeometry.hh:180
const DofMapper & dofMapper() const
The dofMapper.
Definition discretization/pq1bubble/fvgridgeometry.hh:214
const std::unordered_map< GridIndexType, GridIndexType > & periodicDofMap() const
Returns the map between dofs across periodic boundaries.
Definition discretization/pq1bubble/fvgridgeometry.hh:264
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::ScvfQuadratureRule ScvfQuadratureRule
Definition discretization/pq1bubble/fvgridgeometry.hh:190
GridView GridView
Definition discretization/pq1bubble/fvgridgeometry.hh:184
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on a periodic boundary.
Definition discretization/pq1bubble/fvgridgeometry.hh:256
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::template LocalView< ThisType, true > LocalView
Definition discretization/pq1bubble/fvgridgeometry.hh:170
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::SubControlVolume SubControlVolume
Definition discretization/pq1bubble/fvgridgeometry.hh:172
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::ScvQuadratureRule ScvQuadratureRule
Definition discretization/pq1bubble/fvgridgeometry.hh:188
typename PeriodicGridTraits< typename GridView::Grid >::SupportsPeriodicity SupportsPeriodicity
Definition discretization/pq1bubble/fvgridgeometry.hh:186
void update(GridView &&gridView)
update all geometries (call this after grid adaption)
Definition discretization/pq1bubble/fvgridgeometry.hh:241
Experimental::BoundaryFace< GridView > BoundaryFace
Definition discretization/pq1bubble/fvgridgeometry.hh:176
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::IntersectionQuadratureRule IntersectionQuadratureRule
Definition discretization/pq1bubble/fvgridgeometry.hh:194
A class to create sub control volume and sub control volume face geometries per element.
Definition discretization/pq1bubble/geometryhelper.hh:175
Class for a sub control volume face in the cvfe method, i.e a part of the boundary of a sub control v...
Definition discretization/pq1bubble/subcontrolvolumeface.hh:58
the sub control volume for the pq1bubble scheme
Definition discretization/pq1bubble/subcontrolvolume.hh:55
Defines the default element and vertex mapper types.
Base class for the local finite volume geometry for the pq1bubble method This builds up the sub contr...
Helper class constructing the dual grid finite volume geometries for the cvfe discretizazion method.
the sub control volume for the cvfe scheme
Base class for a sub control volume face.
Helper classes to compute the integration elements.
Dune::Std::detected_or_t< Dumux::BasicGridGeometry< GV, typename T::ElementMapper, typename T::VertexMapper >, Detail::SpecifiesBaseGridGeometry, T > BasicGridGeometry_t
Type of the basic grid geometry implementation used as backend.
Definition basegridgeometry.hh:38
BaseGridGeometry(std::shared_ptr< BaseImplementation > impl)
Constructor from a BaseImplementation.
Definition basegridgeometry.hh:72
auto convexPolytopeVolume(Dune::GeometryType type, const CornerF &c)
Compute the volume of several common geometry types.
Definition volume.hh:41
Corners::value_type center(const Corners &corners)
The center of a given list of corners.
Definition center.hh:24
CVFE::DefaultQuadratureTraits< GridView, ScvRule, ScvfRule, ElementRule, IntersectionRule, BoundaryFaceRule > PQ1BubbleQuadratureTraits
Quadrature rule traits for PQ1Bubble discretization.
Definition discretization/pq1bubble/fvgridgeometry.hh:100
The available discretization methods in Dumux.
Definition cvfelocalresidual.hh:25
Dune::Std::detected_or_t< std::conditional_t< enablesHybridCVFE< T >, Dumux::HybridPQ1BubbleGeometryHelper< GV, typename T::SubControlVolume, typename T::SubControlVolumeFace, T::numCubeBubbleDofs >, Dumux::PQ1BubbleGeometryHelper< GV, typename T::SubControlVolume, typename T::SubControlVolumeFace > >, SpecifiesGeometryHelper, T > PQ1BubbleGeometryHelper_t
Definition discretization/pq1bubble/fvgridgeometry.hh:54
static constexpr bool enablesHybridCVFE
Definition discretization/pq1bubble/fvgridgeometry.hh:51
typename T::GeometryHelper SpecifiesGeometryHelper
Definition basegridgeometry.hh:30
typename T::EnableHybridCVFE EnableHybridCVFE
Definition discretization/pq1bubble/fvgridgeometry.hh:47
CVFE< CVFEMethods::PQ1Bubble > PQ1Bubble
Definition method.hh:126
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition extrusion.hh:257
Grid properties related to periodicity.
A finite element cache for P1/Q1 function with bubble.
Quadrature rule traits for discretization schemes.
Definition quadraturerules.hh:85
Definition defaultmappertraits.hh:23
The default traits for the hybrid pq1bubble finite volume grid geometry Defines the scv and scvf type...
Definition discretization/pq1bubble/fvgridgeometry.hh:131
std::true_type EnableHybridCVFE
Definition discretization/pq1bubble/fvgridgeometry.hh:131
typename GridView::IndexSet::IndexType GridIndex
Definition indextraits.hh:27
unsigned int LocalIndex
Definition indextraits.hh:28
The default traits for the pq1bubble finite volume grid geometry Defines the scv and scvf types and t...
Definition discretization/pq1bubble/fvgridgeometry.hh:111
PQ1BubbleSubControlVolumeFace< GridView > SubControlVolumeFace
Definition discretization/pq1bubble/fvgridgeometry.hh:113
PQ1BubbleFVElementGeometry< GridGeometry, enableCache > LocalView
Definition discretization/pq1bubble/fvgridgeometry.hh:116
static constexpr std::size_t maxNumElementDofs
Definition discretization/pq1bubble/fvgridgeometry.hh:118
PQ1BubbleSubControlVolume< GridView > SubControlVolume
Definition discretization/pq1bubble/fvgridgeometry.hh:112
Definition discretization/pq1bubble/fvgridgeometry.hh:67
static constexpr std::size_t numCubeBubbleDofs
Definition discretization/pq1bubble/fvgridgeometry.hh:71
static Dune::MCMGLayout layout()
Layout for elements (numCubeBubbleDofs) and vertices.
Definition discretization/pq1bubble/fvgridgeometry.hh:76
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > DofMapper
Definition discretization/pq1bubble/fvgridgeometry.hh:68
Definition periodicgridtraits.hh:24
Definition periodicgridtraits.hh:23
Dune-based quadrature rule with specified order.
Definition quadraturerules.hh:66
Midpoint quadrature rule that uses scv/scvf centers.
Definition quadraturerules.hh:58
Compute the volume of several common geometry types.