14#ifndef DUMUX_DISCRETIZATION_PQ1BUBBLE_GRID_GEOMETRY_HH
15#define DUMUX_DISCRETIZATION_PQ1BUBBLE_GRID_GEOMETRY_HH
18#include <unordered_map>
21#include <dune/grid/common/mcmgmapper.hh>
50 = Dune::Std::detected_or_t<std::false_type, EnableHybridCVFE, T>{};
52template<
class GV,
class T>
54 std::conditional_t<enablesHybridCVFE<T>,
63template <
class Gr
idView, std::
size_t numCubeBubbles = 1>
66 using DofMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
67 static_assert(numCubeBubbles == 1 || numCubeBubbles == 2,
68 "PQ1BubbleMapperTraits supports numCubeBubbles = 1 or 2");
76 return [](Dune::GeometryType gt,
int dimgrid) {
80 if (gt.dim() == dimgrid)
92template<
class GridView,
105template<
class Gr
idView,
class MapperTraits = PQ1BubbleMapperTraits<Gr
idView>,
class QuadratureTraits = PQ1BubbleQuadratureTraits<Gr
idView>>
107:
public MapperTraits,
public QuadratureTraits
112 template<
class Gr
idGeometry,
bool enableCache>
116 + MapperTraits::numCubeBubbleDofs;
125template<
class BaseTraits>
136template<
class Scalar,
138 bool enableCaching =
true,
148 using Element =
typename GV::template Codim<0>::Entity;
149 using CoordScalar =
typename GV::ctype;
150 static const int dim = GV::dimension;
151 static const int dimWorld = GV::dimensionworld;
153 static_assert(dim > 1,
"Only implemented for dim > 1");
194 , dofMapper_(this->
gridView(), Traits::layout())
196 , periodicGridTraits_(this->
gridView().grid())
208 {
return dofMapper_; }
220 {
return numBoundaryScvf_; }
246 {
return boundaryDofIndices_[dofIdx]; }
250 {
return periodicDofMap_.count(dofIdx); }
254 {
return periodicDofMap_.at(dofIdx); }
258 {
return periodicDofMap_; }
262 {
return { gg.cache_ }; }
265 class PQ1BubbleGridGeometryCache
277 {
return *gridGeometry_; }
280 const std::vector<SubControlVolume>&
scvs(GridIndexType eIdx)
const
281 {
return scvs_[eIdx]; }
284 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx)
const
285 {
return scvfs_[eIdx]; }
288 bool hasBoundaryScvf(GridIndexType eIdx)
const
289 {
return hasBoundaryScvf_[eIdx]; }
292 const std::vector<std::array<LocalIndexType, 2>>& scvfBoundaryGeometryKeys(GridIndexType eIdx)
const
293 {
return scvfBoundaryGeometryKeys_.at(eIdx); }
300 hasBoundaryScvf_.clear();
301 scvfBoundaryGeometryKeys_.clear();
304 std::vector<std::vector<SubControlVolume>> scvs_;
305 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
306 std::vector<bool> hasBoundaryScvf_;
307 std::unordered_map<GridIndexType, std::vector<std::array<LocalIndexType, 2>>> scvfBoundaryGeometryKeys_;
315 using Cache = PQ1BubbleGridGeometryCache;
318 using GeometryHelper =
typename Cache::GeometryHelper;
323 dofMapper_.update(this->
gridView());
325 auto numElements = this->
gridView().size(0);
326 cache_.scvs_.resize(numElements);
327 cache_.scvfs_.resize(numElements);
328 cache_.hasBoundaryScvf_.resize(numElements,
false);
330 boundaryDofIndices_.assign(
numDofs(),
false);
334 numBoundaryScvf_ = 0;
342 auto elementGeometry =
element.geometry();
343 if (!
enableHybridCVFE && elementGeometry.type().isCube() && Traits::numCubeBubbleDofs > 1)
344 DUNE_THROW(Dune::NotImplemented,
"Multiple bubble dofs for cube elements only for hybrid scheme.");
346 const auto refElement = referenceElement(elementGeometry);
347 const auto& localCoefficients = this->
feCache().
get(
element.type()).localCoefficients();
350 GeometryHelper geometryHelper(elementGeometry);
352 numScv_ += geometryHelper.numScv();
354 cache_.scvs_[eIdx].resize(geometryHelper.numScv());
357 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < geometryHelper.numScv(); ++scvLocalIdx)
359 auto corners = geometryHelper.getScvCorners(scvLocalIdx);
361 geometryHelper.scvVolume(scvLocalIdx, corners),
362 geometryHelper.dofPosition(scvLocalIdx),
366 GeometryHelper::dofIndex(this->dofMapper(),
element, localCoefficients.localKey(scvLocalIdx)),
367 geometryHelper.isOverlappingScv(scvLocalIdx)
372 const auto numInteriorScvfs = GeometryHelper::numInteriorScvf(elementGeometry.type());
373 numScvf_ += numInteriorScvfs;
374 cache_.scvfs_[eIdx].resize(numInteriorScvfs);
375 LocalIndexType scvfLocalIdx = 0;
376 for (; scvfLocalIdx < numInteriorScvfs; ++scvfLocalIdx)
378 const auto scvPair = geometryHelper.getScvPairForScvf(scvfLocalIdx);
379 const auto corners = geometryHelper.getScvfCorners(scvfLocalIdx);
381 geometryHelper.getInteriorScvfGeometryType(scvfLocalIdx),
382 [&](
unsigned int i){
return corners[i]; }
388 geometryHelper.normal(corners, scvPair),
391 geometryHelper.isOverlappingScvf(scvfLocalIdx)
396 for (
const auto& intersection : intersections(this->
gridView(),
element))
398 if (intersection.boundary() && !intersection.neighbor())
400 cache_.hasBoundaryScvf_[eIdx] =
true;
402 const auto localFacetIndex = intersection.indexInInside();
403 const auto numBoundaryScvf = GeometryHelper::numBoundaryScvf(elementGeometry.type(), localFacetIndex);
407 for (
unsigned int isScvfLocalIdx = 0; isScvfLocalIdx <
numBoundaryScvf; ++isScvfLocalIdx)
410 const auto scvPair = geometryHelper.getScvPairForBoundaryScvf(localFacetIndex, isScvfLocalIdx);
411 const auto corners = geometryHelper.getBoundaryScvfCorners(localFacetIndex, isScvfLocalIdx);
413 geometryHelper.getBoundaryScvfGeometryType(isScvfLocalIdx),
414 [&](
unsigned int i){
return corners[i]; }
416 cache_.scvfs_[eIdx].emplace_back(
419 intersection.centerUnitOuterNormal(),
422 typename SubControlVolumeFace::Traits::BoundaryFlag{ intersection },
423 geometryHelper.isOverlappingBoundaryScvf(localFacetIndex)
427 cache_.scvfBoundaryGeometryKeys_[eIdx].emplace_back(std::array<LocalIndexType, 2>{{
428 static_cast<LocalIndexType
>(localFacetIndex),
429 static_cast<LocalIndexType
>(isScvfLocalIdx)
436 const auto numDofsIntersection = GeometryHelper::numLocalDofsIntersection(elementGeometry.type(), localFacetIndex);
439 for (
int ilocalDofIdx = 0; ilocalDofIdx < numDofsIntersection; ++ilocalDofIdx)
441 auto localDofIdx = GeometryHelper::localDofIndexIntersection(elementGeometry.type(), localFacetIndex, ilocalDofIdx);
442 const auto vIdxGlobal = GeometryHelper::dofIndex(this->
dofMapper(),
element, localCoefficients.localKey(localDofIdx));
443 boundaryDofIndices_[vIdxGlobal] =
true;
448 else if (periodicGridTraits_.
isPeriodic(intersection))
453 const auto fIdx = intersection.indexInInside();
454 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
455 const auto eps = 1e-7*(elementGeometry.corner(1) - elementGeometry.corner(0)).two_norm();
456 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
458 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
460 const auto vPos = elementGeometry.corner(vIdx);
462 const auto& outside = intersection.outside();
463 const auto outsideGeometry = outside.geometry();
464 for (
const auto& isOutside : intersections(this->
gridView(), outside))
467 if (periodicGridTraits_.
isPeriodic(isOutside))
469 const auto fIdxOutside = isOutside.indexInInside();
470 const auto numFaceVertsOutside = refElement.size(fIdxOutside, 1, dim);
471 for (
int localVIdxOutside = 0; localVIdxOutside < numFaceVertsOutside; ++localVIdxOutside)
473 const auto vIdxOutside = refElement.subEntity(fIdxOutside, 1, localVIdxOutside, dim);
474 const auto vPosOutside = outsideGeometry.corner(vIdxOutside);
475 const auto shift = std::abs((this->
bBoxMax()-this->
bBoxMin())*intersection.centerUnitOuterNormal());
476 if (std::abs((vPosOutside-vPos).two_norm() - shift) < eps)
477 periodicDofMap_[vIdxGlobal] = this->
dofMapper().subIndex(outside, vIdxOutside, dim);
488 DUNE_THROW(Dune::NotImplemented,
"Periodic boundaries for pq1bubble method for parallel simulations!");
496 std::size_t numScvf_;
497 std::size_t numBoundaryScvf_;
500 std::vector<bool> boundaryDofIndices_;
503 std::unordered_map<GridIndexType, GridIndexType> periodicDofMap_;
Base class for grid geometries.
Compute the center point of a convex polytope geometry or a random-access container of corner points.
Base class for all grid geometries.
Definition: basegridgeometry.hh:52
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
Get an element from a global element index.
Definition: basegridgeometry.hh:142
const GridView & gridView() const
Return the gridView this grid geometry object lives on.
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
Definition: discretization/pq1bubble/geometryhelper.hh:500
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:42
Base class for the finite volume geometry vector for pq1bubble schemes This builds up the sub control...
Definition: discretization/pq1bubble/fvgridgeometry.hh:142
void update(const GridView &gridView)
update all geometries (call this after grid adaption)
Definition: discretization/pq1bubble/fvgridgeometry.hh:227
friend LocalView localView(const PQ1BubbleFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition: discretization/pq1bubble/fvgridgeometry.hh:261
PQ1BubbleGridGeometryCache Cache
Definition: discretization/pq1bubble/fvgridgeometry.hh:315
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:192
static constexpr DiscretizationMethod discMethod
Definition: discretization/pq1bubble/fvgridgeometry.hh:158
std::size_t numBoundaryScvf() const
The total number of boundary sub control volume faces.
Definition: discretization/pq1bubble/fvgridgeometry.hh:219
Dumux::PQ1BubbleFECache< CoordScalar, Scalar, dim, Traits::numCubeBubbleDofs > FeCache
export the finite element cache type
Definition: discretization/pq1bubble/fvgridgeometry.hh:177
typename Traits::ElementQuadratureRule ElementQuadratureRule
the quadrature rule type for elements
Definition: discretization/pq1bubble/fvgridgeometry.hh:187
PQ1BubbleFVGridGeometry(const GridView &gridView)
Constructor.
Definition: discretization/pq1bubble/fvgridgeometry.hh:202
BasicGridGeometry_t< GV, Traits > BasicGridGeometry
export basic grid geometry type for the alternative constructor
Definition: discretization/pq1bubble/fvgridgeometry.hh:165
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/pq1bubble/fvgridgeometry.hh:211
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/pq1bubble/fvgridgeometry.hh:215
static constexpr std::size_t maxNumElementDofs
Definition: discretization/pq1bubble/fvgridgeometry.hh:162
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition: discretization/pq1bubble/fvgridgeometry.hh:241
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:253
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition: discretization/pq1bubble/fvgridgeometry.hh:173
static constexpr bool enableHybridCVFE
Definition: discretization/pq1bubble/fvgridgeometry.hh:160
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: discretization/pq1bubble/fvgridgeometry.hh:171
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: discretization/pq1bubble/fvgridgeometry.hh:223
bool dofOnBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition: discretization/pq1bubble/fvgridgeometry.hh:245
typename Traits::DofMapper DofMapper
export dof mapper type
Definition: discretization/pq1bubble/fvgridgeometry.hh:175
const DofMapper & dofMapper() const
The dofMapper.
Definition: discretization/pq1bubble/fvgridgeometry.hh:207
const std::unordered_map< GridIndexType, GridIndexType > & periodicDofMap() const
Returns the map between dofs across periodic boundaries.
Definition: discretization/pq1bubble/fvgridgeometry.hh:257
typename Traits::ScvfQuadratureRule ScvfQuadratureRule
the quadrature rule type for scvfs
Definition: discretization/pq1bubble/fvgridgeometry.hh:185
GV GridView
export the grid view type
Definition: discretization/pq1bubble/fvgridgeometry.hh:179
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on a periodic boundary.
Definition: discretization/pq1bubble/fvgridgeometry.hh:249
typename Traits::template LocalView< ThisType, true > LocalView
export the type of the fv element geometry (the local view type)
Definition: discretization/pq1bubble/fvgridgeometry.hh:167
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: discretization/pq1bubble/fvgridgeometry.hh:169
typename Traits::ScvQuadratureRule ScvQuadratureRule
the quadrature rule type for scvs
Definition: discretization/pq1bubble/fvgridgeometry.hh:183
typename PeriodicGridTraits< typename GV::Grid >::SupportsPeriodicity SupportsPeriodicity
export whether the grid(geometry) supports periodicity
Definition: discretization/pq1bubble/fvgridgeometry.hh:181
void update(GridView &&gridView)
update all geometries (call this after grid adaption)
Definition: discretization/pq1bubble/fvgridgeometry.hh:234
typename Traits::IntersectionQuadratureRule IntersectionQuadratureRule
the quadrature rule type for intersections
Definition: discretization/pq1bubble/fvgridgeometry.hh:189
A class to create sub control volume and sub control volume face geometries per element.
Definition: discretization/pq1bubble/geometryhelper.hh:167
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:42
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
The available discretization methods in Dumux.
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:60
typename T::EnableHybridCVFE EnableHybridCVFE
Definition: discretization/pq1bubble/fvgridgeometry.hh:46
static constexpr bool enablesHybridCVFE
Definition: discretization/pq1bubble/fvgridgeometry.hh:50
typename T::GeometryHelper SpecifiesGeometryHelper
Definition: basegridgeometry.hh:30
CVFE< CVFEMethods::PQ1Bubble > PQ1Bubble
Definition: method.hh:112
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:166
std::ranges::range auto scvs(const FVElementGeometry &fvGeometry, const LocalDof &localDof)
Definition: localdof.hh:79
Grid properties related to periodicity.
A finite element cache for P1/Q1 function with bubble.
Quadrature rule traits for discretization schemes.
Definition: quadraturerules.hh:84
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:128
std::true_type EnableHybridCVFE
Definition: discretization/pq1bubble/fvgridgeometry.hh:128
Structure to define the index types used for grid and local indices.
Definition: indextraits.hh:26
The default traits for the pq1bubble finite volume grid geometry Defines the scv and scvf types and t...
Definition: discretization/pq1bubble/fvgridgeometry.hh:108
static constexpr std::size_t maxNumElementDofs
Definition: discretization/pq1bubble/fvgridgeometry.hh:115
Definition: discretization/pq1bubble/fvgridgeometry.hh:65
static constexpr std::size_t numCubeBubbleDofs
Definition: discretization/pq1bubble/fvgridgeometry.hh:69
static Dune::MCMGLayout layout()
Layout for elements (numCubeBubbleDofs) and vertices.
Definition: discretization/pq1bubble/fvgridgeometry.hh:74
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > DofMapper
Definition: discretization/pq1bubble/fvgridgeometry.hh:66
Definition: periodicgridtraits.hh:24
bool isPeriodic(const typename Grid::LeafIntersection &intersection) const
Definition: periodicgridtraits.hh:28
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.