14#ifndef DUMUX_DISCRETIZATION_PQ1BUBBLE_GRID_GEOMETRY_HH
15#define DUMUX_DISCRETIZATION_PQ1BUBBLE_GRID_GEOMETRY_HH
19#include <unordered_map>
23#include <dune/grid/common/mcmgmapper.hh>
50 =
typename T::EnableHybridCVFE;
54 = Dune::Std::detected_or_t<std::false_type, EnableHybridCVFE, T>{};
56template<
class GV,
class T>
58 std::conditional_t<enablesHybridCVFE<T>,
67template <
class Gr
idView, std::
size_t numCubeBubbles = 1>
70 using DofMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
71 static_assert(numCubeBubbles == 1 || numCubeBubbles == 2,
72 "PQ1BubbleMapperTraits supports numCubeBubbles = 1 or 2");
80 return [](Dune::GeometryType gt,
int dimgrid) {
84 if (gt.dim() == dimgrid)
96template<
class GridView,
110template<
class Gr
idView,
class MapperTraits = PQ1BubbleMapperTraits<Gr
idView>,
class QuadratureTraits = PQ1BubbleQuadratureTraits<Gr
idView>>
112:
public MapperTraits,
public QuadratureTraits
117 template<
class Gr
idGeometry,
bool enableCache>
121 + MapperTraits::numCubeBubbleDofs;
130template<
class BaseTraits>
141template<
class Scalar,
143 bool enableCaching =
true,
153 using Element =
typename GV::template Codim<0>::Entity;
154 using CoordScalar =
typename GV::ctype;
155 static const int dim = GV::dimension;
156 static const int dimWorld = GV::dimensionworld;
158 static_assert(dim > 1,
"Only implemented for dim > 1");
202 : ParentType(std::move(gg))
203 , dofMapper_(this->
gridView(), Traits::layout())
205 , periodicGridTraits_(this->
gridView().grid())
217 {
return dofMapper_; }
229 {
return numBoundaryScvf_; }
255 {
return boundaryDofIndices_[dofIdx]; }
259 {
return periodicDofMap_.count(dofIdx); }
262 [[deprecated(
"Will be removed after release 3.11. Use periodicallyMappedDofs, returning a range of dofs")]]
264 {
return periodicDofMap_.at(dofIdx)[0]; }
268 {
return std::views::all(periodicDofMap_.at(dofIdx)); }
271 const std::unordered_map<GridIndexType, std::vector<GridIndexType>>&
periodicDofMap()
const
272 {
return periodicDofMap_; }
276 {
return { gg.cache_ }; }
279 class PQ1BubbleGridGeometryCache
286 using DofHelper =
typename GeometryHelper::DofHelper;
292 const PQ1BubbleFVGridGeometry& gridGeometry()
const
293 {
return *gridGeometry_; }
296 const std::vector<SubControlVolume>& scvs(GridIndexType eIdx)
const
297 {
return scvs_[eIdx]; }
300 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx)
const
301 {
return scvfs_[eIdx]; }
304 bool hasBoundaryScvf(GridIndexType eIdx)
const
305 {
return hasBoundaryScvf_[eIdx]; }
308 const std::vector<std::array<LocalIndexType, 2>>& scvfBoundaryGeometryKeys(GridIndexType eIdx)
const
309 {
return scvfBoundaryGeometryKeys_.at(eIdx); }
312 auto boundaryFaces(GridIndexType eIdx)
const -> std::span<const BoundaryFace>
314 if (
auto it = boundaryFaces_.find(eIdx); it != boundaryFaces_.end())
320 const auto& boundaryFaceScvfRanges(GridIndexType eIdx)
const
321 {
return boundaryFaceScvfRanges_.at(eIdx); }
328 hasBoundaryScvf_.clear();
329 scvfBoundaryGeometryKeys_.clear();
330 boundaryFaces_.clear();
331 boundaryFaceScvfRanges_.clear();
334 std::vector<std::vector<SubControlVolume>> scvs_;
335 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
336 std::vector<bool> hasBoundaryScvf_;
337 std::unordered_map<GridIndexType, std::vector<std::array<LocalIndexType, 2>>> scvfBoundaryGeometryKeys_;
338 std::unordered_map<GridIndexType, Dune::ReservedVector<typename PQ1BubbleFVGridGeometry::BoundaryFace, 2*dim>> boundaryFaces_;
339 std::unordered_map<GridIndexType, Dune::ReservedVector<std::array<LocalIndexType, 2>, 2*dim>> boundaryFaceScvfRanges_;
341 const PQ1BubbleFVGridGeometry* gridGeometry_;
347 using Cache = PQ1BubbleGridGeometryCache;
350 using GeometryHelper =
typename Cache::GeometryHelper;
351 using DofHelper =
typename Cache::DofHelper;
356 dofMapper_.update(this->
gridView());
358 auto numElements = this->
gridView().size(0);
359 cache_.scvs_.resize(numElements);
360 cache_.scvfs_.resize(numElements);
361 cache_.hasBoundaryScvf_.resize(numElements,
false);
363 boundaryDofIndices_.assign(
numDofs(),
false);
364 periodicDofMap_.clear();
368 numBoundaryScvf_ = 0;
376 auto elementGeometry =
element.geometry();
377 if (!
enableHybridCVFE && elementGeometry.type().isCube() && Traits::numCubeBubbleDofs > 1)
378 DUNE_THROW(Dune::NotImplemented,
"Multiple bubble dofs for cube elements only for hybrid scheme.");
380 const auto refElement = referenceElement(elementGeometry);
381 const auto& localCoefficients = this->
feCache().
get(
element.type()).localCoefficients();
384 GeometryHelper geometryHelper(elementGeometry);
386 numScv_ += geometryHelper.numScv();
388 cache_.scvs_[eIdx].resize(geometryHelper.numScv());
391 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < geometryHelper.numScv(); ++scvLocalIdx)
393 auto corners = geometryHelper.getScvCorners(scvLocalIdx);
395 geometryHelper.scvVolume(scvLocalIdx, corners),
396 geometryHelper.dofPosition(scvLocalIdx),
400 DofHelper::dofIndex(this->dofMapper(),
element, localCoefficients.localKey(scvLocalIdx)),
401 geometryHelper.isOverlappingScv(scvLocalIdx)
406 const auto numInteriorScvfs = GeometryHelper::numInteriorScvf(elementGeometry.type());
407 numScvf_ += numInteriorScvfs;
408 cache_.scvfs_[eIdx].resize(numInteriorScvfs);
409 LocalIndexType scvfLocalIdx = 0;
410 for (; scvfLocalIdx < numInteriorScvfs; ++scvfLocalIdx)
412 const auto scvPair = geometryHelper.getScvPairForScvf(scvfLocalIdx);
413 const auto corners = geometryHelper.getScvfCorners(scvfLocalIdx);
415 geometryHelper.getInteriorScvfGeometryType(scvfLocalIdx),
416 [&](
unsigned int i){
return corners[i]; }
422 geometryHelper.normal(corners, scvPair),
425 geometryHelper.isOverlappingScvf(scvfLocalIdx)
430 LocalIndexType numBoundaryFaces = 0;
431 for (
const auto& intersection : intersections(this->
gridView(),
element))
433 if (intersection.boundary() && !intersection.neighbor())
435 cache_.hasBoundaryScvf_[eIdx] =
true;
438 const auto isGeometry = intersection.geometry();
442 intersection.centerUnitOuterNormal(),
444 static_cast<LocalIndexType
>(intersection.indexInInside()),
445 typename BoundaryFace::Traits::BoundaryFlag{intersection}
448 const auto localFacetIndex = intersection.indexInInside();
449 const auto numBoundaryScvf = GeometryHelper::numBoundaryScvf(elementGeometry.type(), localFacetIndex);
454 cache_.boundaryFaceScvfRanges_[eIdx].push_back(std::array<LocalIndexType, 2>{{
459 for (
unsigned int isScvfLocalIdx = 0; isScvfLocalIdx <
numBoundaryScvf; ++isScvfLocalIdx)
462 const auto scvPair = geometryHelper.getScvPairForBoundaryScvf(localFacetIndex, isScvfLocalIdx);
463 const auto corners = geometryHelper.getBoundaryScvfCorners(localFacetIndex, isScvfLocalIdx);
465 geometryHelper.getBoundaryScvfGeometryType(isScvfLocalIdx),
466 [&](
unsigned int i){
return corners[i]; }
468 cache_.scvfs_[eIdx].emplace_back(
471 intersection.centerUnitOuterNormal(),
474 typename SubControlVolumeFace::Traits::BoundaryFlag{ intersection },
475 geometryHelper.isOverlappingBoundaryScvf(localFacetIndex)
479 cache_.scvfBoundaryGeometryKeys_[eIdx].emplace_back(std::array<LocalIndexType, 2>{{
480 static_cast<LocalIndexType
>(localFacetIndex),
481 static_cast<LocalIndexType
>(isScvfLocalIdx)
488 const auto numDofsIntersection = DofHelper::numLocalDofsIntersection(elementGeometry.type(), localFacetIndex);
491 for (
int ilocalDofIdx = 0; ilocalDofIdx < numDofsIntersection; ++ilocalDofIdx)
493 auto localDofIdx = DofHelper::localDofIndexIntersection(elementGeometry.type(), localFacetIndex, ilocalDofIdx);
494 const auto vIdxGlobal = DofHelper::dofIndex(this->
dofMapper(),
element, localCoefficients.localKey(localDofIdx));
495 boundaryDofIndices_[vIdxGlobal] =
true;
500 else if (periodicGridTraits_.isPeriodic(intersection))
505 const auto fIdx = intersection.indexInInside();
506 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
507 const auto eps = 1e-7*(elementGeometry.corner(1) - elementGeometry.corner(0)).two_norm();
508 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
510 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
512 const auto vPos = elementGeometry.corner(vIdx);
514 const auto& outside = intersection.outside();
515 const auto outsideGeometry = outside.geometry();
516 for (
const auto& isOutside : intersections(this->
gridView(), outside))
519 if (periodicGridTraits_.isPeriodic(isOutside))
521 const auto fIdxOutside = isOutside.indexInInside();
522 const auto numFaceVertsOutside = refElement.size(fIdxOutside, 1, dim);
523 for (
int localVIdxOutside = 0; localVIdxOutside < numFaceVertsOutside; ++localVIdxOutside)
525 const auto vIdxOutside = refElement.subEntity(fIdxOutside, 1, localVIdxOutside, dim);
526 const auto vPosOutside = outsideGeometry.corner(vIdxOutside);
527 const auto shift = std::abs((this->
bBoxMax()-this->
bBoxMin())*intersection.centerUnitOuterNormal());
528 if ((vPosOutside - vPos + shift*intersection.centerUnitOuterNormal()).two_norm() < eps)
542 DUNE_THROW(Dune::NotImplemented,
"Periodic boundaries for pq1bubble method for parallel simulations!");
550 std::size_t numScvf_;
551 std::size_t numBoundaryScvf_;
554 std::vector<bool> boundaryDofIndices_;
557 std::unordered_map<GridIndexType, std::vector<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:461
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:44
Base class for the finite volume geometry vector for pq1bubble schemes This builds up the sub control...
Definition discretization/pq1bubble/fvgridgeometry.hh:147
void update(const GridView &gridView)
update all geometries (call this after grid adaption)
Definition discretization/pq1bubble/fvgridgeometry.hh:236
friend LocalView localView(const PQ1BubbleFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition discretization/pq1bubble/fvgridgeometry.hh:275
PQ1BubbleGridGeometryCache Cache
Definition discretization/pq1bubble/fvgridgeometry.hh:347
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:201
const std::unordered_map< GridIndexType, std::vector< GridIndexType > > & periodicDofMap() const
Returns the map between dofs across periodic boundaries.
Definition discretization/pq1bubble/fvgridgeometry.hh:271
static constexpr DiscretizationMethod discMethod
Definition discretization/pq1bubble/fvgridgeometry.hh:163
std::size_t numBoundaryScvf() const
The total number of boundary sub control volume faces.
Definition discretization/pq1bubble/fvgridgeometry.hh:228
Dumux::PQ1BubbleFECache< CoordScalar, Scalar, dim, PQ1BubbleDefaultGridGeometryTraits< GridView >::numCubeBubbleDofs > FeCache
Definition discretization/pq1bubble/fvgridgeometry.hh:184
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::ElementQuadratureRule ElementQuadratureRule
Definition discretization/pq1bubble/fvgridgeometry.hh:194
PQ1BubbleFVGridGeometry(const GridView &gridView)
Constructor.
Definition discretization/pq1bubble/fvgridgeometry.hh:211
BasicGridGeometry_t< GridView, PQ1BubbleDefaultGridGeometryTraits< GridView > > BasicGridGeometry
Definition discretization/pq1bubble/fvgridgeometry.hh:170
std::size_t numScv() const
The total number of sub control volumes.
Definition discretization/pq1bubble/fvgridgeometry.hh:220
std::size_t numScvf() const
The total number of sub control volume faces.
Definition discretization/pq1bubble/fvgridgeometry.hh:224
static constexpr std::size_t maxNumElementDofs
Definition discretization/pq1bubble/fvgridgeometry.hh:167
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition discretization/pq1bubble/fvgridgeometry.hh:250
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:263
DiscretizationMethods::PQ1Bubble DiscretizationMethod
Definition discretization/pq1bubble/fvgridgeometry.hh:162
const std::ranges::range auto periodicallyMappedDofs(GridIndexType dofIdx) const
The indices of the vertices / d.o.f. on the other side of the periodic boundary.
Definition discretization/pq1bubble/fvgridgeometry.hh:267
Extrusion_t< PQ1BubbleDefaultGridGeometryTraits< GridView > > Extrusion
Definition discretization/pq1bubble/fvgridgeometry.hh:180
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::BoundaryFaceQuadratureRule BoundaryFaceQuadratureRule
Definition discretization/pq1bubble/fvgridgeometry.hh:198
static constexpr bool enableHybridCVFE
Definition discretization/pq1bubble/fvgridgeometry.hh:165
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::SubControlVolumeFace SubControlVolumeFace
Definition discretization/pq1bubble/fvgridgeometry.hh:176
std::size_t numDofs() const
The total number of degrees of freedom.
Definition discretization/pq1bubble/fvgridgeometry.hh:232
bool dofOnBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition discretization/pq1bubble/fvgridgeometry.hh:254
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::DofMapper DofMapper
Definition discretization/pq1bubble/fvgridgeometry.hh:182
const DofMapper & dofMapper() const
The dofMapper.
Definition discretization/pq1bubble/fvgridgeometry.hh:216
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::ScvfQuadratureRule ScvfQuadratureRule
Definition discretization/pq1bubble/fvgridgeometry.hh:192
GridView GridView
Definition discretization/pq1bubble/fvgridgeometry.hh:186
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on a periodic boundary.
Definition discretization/pq1bubble/fvgridgeometry.hh:258
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::template LocalView< ThisType, true > LocalView
Definition discretization/pq1bubble/fvgridgeometry.hh:172
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::SubControlVolume SubControlVolume
Definition discretization/pq1bubble/fvgridgeometry.hh:174
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::ScvQuadratureRule ScvQuadratureRule
Definition discretization/pq1bubble/fvgridgeometry.hh:190
typename PeriodicGridTraits< typename GridView::Grid >::SupportsPeriodicity SupportsPeriodicity
Definition discretization/pq1bubble/fvgridgeometry.hh:188
void update(GridView &&gridView)
update all geometries (call this after grid adaption)
Definition discretization/pq1bubble/fvgridgeometry.hh:243
Experimental::BoundaryFace< GridView > BoundaryFace
Definition discretization/pq1bubble/fvgridgeometry.hh:178
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::IntersectionQuadratureRule IntersectionQuadratureRule
Definition discretization/pq1bubble/fvgridgeometry.hh:196
A class to create sub control volume and sub control volume face geometries per element.
Definition discretization/pq1bubble/geometryhelper.hh:176
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.
void closePeriodicDofMap(std::unordered_map< Index, std::vector< Index > > &periodicDofMap)
Map every degree of freedom to all others it is identified with.
Definition periodicdofmap.hh:48
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
void addPeriodicallyMappedDof(std::unordered_map< Index, std::vector< Index > > &periodicDofMap, std::type_identity_t< Index > dofIdx, std::type_identity_t< Index > periodicDofIdx)
Register a degree of freedom as periodically mapped to another one.
Definition periodicdofmap.hh:29
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:102
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:56
static constexpr bool enablesHybridCVFE
Definition discretization/pq1bubble/fvgridgeometry.hh:53
typename T::GeometryHelper SpecifiesGeometryHelper
Definition basegridgeometry.hh:30
typename T::EnableHybridCVFE EnableHybridCVFE
Definition discretization/pq1bubble/fvgridgeometry.hh:49
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
Helpers for maps between degrees of freedom identified across periodic boundaries.
Grid properties related to periodicity.
A finite element cache for P1/Q1 function with bubble.
Quadrature rule traits for discretization schemes.
Definition quadraturerules.hh:86
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:133
std::true_type EnableHybridCVFE
Definition discretization/pq1bubble/fvgridgeometry.hh:133
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:113
PQ1BubbleSubControlVolumeFace< GridView > SubControlVolumeFace
Definition discretization/pq1bubble/fvgridgeometry.hh:115
PQ1BubbleFVElementGeometry< GridGeometry, enableCache > LocalView
Definition discretization/pq1bubble/fvgridgeometry.hh:118
static constexpr std::size_t maxNumElementDofs
Definition discretization/pq1bubble/fvgridgeometry.hh:120
PQ1BubbleSubControlVolume< GridView > SubControlVolume
Definition discretization/pq1bubble/fvgridgeometry.hh:114
Definition discretization/pq1bubble/fvgridgeometry.hh:69
static constexpr std::size_t numCubeBubbleDofs
Definition discretization/pq1bubble/fvgridgeometry.hh:73
static Dune::MCMGLayout layout()
Layout for elements (numCubeBubbleDofs) and vertices.
Definition discretization/pq1bubble/fvgridgeometry.hh:78
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > DofMapper
Definition discretization/pq1bubble/fvgridgeometry.hh:70
Definition periodicgridtraits.hh:24
Definition periodicgridtraits.hh:23
Dune-based quadrature rule with specified order.
Definition quadraturerules.hh:67
Midpoint quadrature rule that uses scv/scvf centers.
Definition quadraturerules.hh:59
Compute the volume of several common geometry types.