14#ifndef DUMUX_DISCRETIZATION_PQ2_GRID_GEOMETRY_HH
15#define DUMUX_DISCRETIZATION_PQ2_GRID_GEOMETRY_HH
22#include <unordered_map>
26#include <dune/grid/common/mcmgmapper.hh>
27#include <dune/geometry/type.hh>
28#include <dune/localfunctions/lagrange/lagrangelfecache.hh>
53template<
class GV,
class T>
55 std::conditional_t<enablesHybridCVFE<T>,
64template <
class Gr
idView>
67 using DofMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
75 return [](Dune::GeometryType gt,
int dimgrid) {
76 return (gt.dim() == 0) || (gt.dim() == 1)
77 || (gt.dim() == dimgrid && gt == Dune::GeometryTypes::cube(dimgrid))
78 || (dimgrid == 3 && gt == Dune::GeometryTypes::cube(dimgrid-1));
87template<
class GridView,
101template<
class Gr
idView,
class MapperTraits = PQ2MapperTraits<Gr
idView>,
class QuadratureTraits = PQ2QuadratureTraits<Gr
idView>>
103:
public MapperTraits,
public QuadratureTraits
108 template<
class Gr
idGeometry,
bool enableCache>
117 if constexpr (GridView::dimension == 1)
119 else if constexpr (GridView::dimension == 2)
121 else if constexpr (GridView::dimension == 3)
132template<
class Scalar,
134 bool enableCaching =
true,
135 class Traits = PQ2DefaultGridGeometryTraits<GV>>
144 using Element =
typename GV::template Codim<0>::Entity;
145 using CoordScalar =
typename GV::ctype;
146 static const int dim = GV::dimension;
147 static const int dimWorld = GV::dimensionworld;
149 static_assert(dim > 1,
"Only implemented for dim > 1");
176 using FeCache = Dune::LagrangeLocalFiniteElementCache<CoordScalar, Scalar, dim, 2>;
195 , dofMapper_(this->
gridView(), Traits::layout())
197 , periodicGridTraits_(this->
gridView().grid())
209 {
return dofMapper_; }
221 {
return numBoundaryScvf_; }
247 {
return boundaryDofIndices_[dofIdx]; }
251 {
return periodicDofMap_.count(dofIdx); }
255 {
return periodicDofMap_.at(dofIdx); }
259 {
return periodicDofMap_; }
263 {
return { gg.cache_ }; }
267 class PQ2GridGeometryCache
279 {
return *gridGeometry_; }
282 const std::vector<SubControlVolume>&
scvs(GridIndexType eIdx)
const
283 {
return scvs_[eIdx]; }
286 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx)
const
287 {
return scvfs_[eIdx]; }
290 bool hasBoundaryScvf(GridIndexType eIdx)
const
291 {
return hasBoundaryScvf_[eIdx]; }
294 const std::vector<std::array<LocalIndexType, 2>>& scvfBoundaryGeometryKeys(GridIndexType eIdx)
const
295 {
return scvfBoundaryGeometryKeys_.at(eIdx); }
298 auto boundaryFaces(GridIndexType eIdx)
const -> std::span<const BoundaryFace>
300 if (
auto it = boundaryFaces_.find(eIdx); it != boundaryFaces_.end())
310 hasBoundaryScvf_.clear();
311 scvfBoundaryGeometryKeys_.clear();
312 boundaryFaces_.clear();
315 std::vector<std::vector<SubControlVolume>> scvs_;
316 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
317 std::vector<bool> hasBoundaryScvf_;
318 std::unordered_map<GridIndexType, std::vector<std::array<LocalIndexType, 2>>> scvfBoundaryGeometryKeys_;
319 std::unordered_map<GridIndexType, Dune::ReservedVector<typename PQ2FVGridGeometry::BoundaryFace, 2*dim>> boundaryFaces_;
330 using GeometryHelper =
typename Cache::GeometryHelper;
335 dofMapper_.update(this->
gridView());
337 auto numElements = this->
gridView().size(0);
338 cache_.scvs_.resize(numElements);
339 cache_.scvfs_.resize(numElements);
340 cache_.hasBoundaryScvf_.resize(numElements,
false);
342 boundaryDofIndices_.assign(
numDofs(),
false);
346 numBoundaryScvf_ = 0;
354 auto elementGeometry =
element.geometry();
356 const auto& localCoefficients = this->
feCache().get(
element.type()).localCoefficients();
359 GeometryHelper geometryHelper(elementGeometry);
361 numScv_ += geometryHelper.numScv();
363 cache_.scvs_[eIdx].resize(geometryHelper.numScv());
365 for (LocalIndexType keyIdx = 0; keyIdx < localCoefficients.size(); ++keyIdx)
367 const auto& localKey = localCoefficients.localKey(keyIdx);
369 if(localKey.codim() == dim)
371 const auto localIdx = localKey.subEntity();
373 auto corners = geometryHelper.getScvCorners(localIdx);
375 geometryHelper.scvVolume(localIdx, corners),
376 geometryHelper.dofPosition(localKey),
381 geometryHelper.dofIndex(this->dofMapper(),
element, localKey),
388 const auto numInteriorScvfs = GeometryHelper::numInteriorScvf(elementGeometry.type());
389 numScvf_ += numInteriorScvfs;
390 cache_.scvfs_[eIdx].resize(numInteriorScvfs);
391 LocalIndexType scvfLocalIdx = 0;
392 for (; scvfLocalIdx < numInteriorScvfs; ++scvfLocalIdx)
394 const auto scvPair = geometryHelper.getScvPairForScvf(scvfLocalIdx);
395 const auto corners = geometryHelper.getScvfCorners(scvfLocalIdx);
397 geometryHelper.getInteriorScvfGeometryType(scvfLocalIdx),
398 [&](
unsigned int i){
return corners[i]; }
404 geometryHelper.normal(corners, scvPair),
407 geometryHelper.isOverlappingScvf(scvfLocalIdx)
412 LocalIndexType numBoundaryFaces = 0;
413 for (
const auto& intersection : intersections(this->
gridView(),
element))
415 if (intersection.boundary() && !intersection.neighbor())
417 cache_.hasBoundaryScvf_[eIdx] =
true;
420 const auto isGeometry = intersection.geometry();
424 intersection.centerUnitOuterNormal(),
426 static_cast<LocalIndexType
>(intersection.indexInInside()),
427 typename BoundaryFace::Traits::BoundaryFlag{intersection}
430 const auto localFacetIndex = intersection.indexInInside();
431 const auto numBoundaryScvf = GeometryHelper::numBoundaryScvf(elementGeometry.type(), localFacetIndex);
435 for (
unsigned int isScvfLocalIdx = 0; isScvfLocalIdx <
numBoundaryScvf; ++isScvfLocalIdx)
438 const auto scvPair = geometryHelper.getScvPairForBoundaryScvf(localFacetIndex, isScvfLocalIdx);
439 const auto corners = geometryHelper.getBoundaryScvfCorners(localFacetIndex, isScvfLocalIdx);
441 geometryHelper.getBoundaryScvfGeometryType(isScvfLocalIdx),
442 [&](
unsigned int i){
return corners[i]; }
444 cache_.scvfs_[eIdx].emplace_back(
447 intersection.centerUnitOuterNormal(),
450 typename SubControlVolumeFace::Traits::BoundaryFlag{ intersection },
451 geometryHelper.isOverlappingBoundaryScvf(localFacetIndex)
455 cache_.scvfBoundaryGeometryKeys_[eIdx].emplace_back(std::array<LocalIndexType, 2>{{
456 static_cast<LocalIndexType
>(localFacetIndex),
457 static_cast<LocalIndexType
>(isScvfLocalIdx)
464 for (LocalIndexType keyIdx = 0; keyIdx < localCoefficients.size(); ++keyIdx)
466 if(GeometryHelper::localDofOnIntersection(elementGeometry.type(), intersection.indexInInside(), localCoefficients.localKey(keyIdx)))
468 const auto dofIdxGlobal = GeometryHelper::dofIndex(this->
dofMapper(),
element, localCoefficients.localKey(keyIdx));
469 boundaryDofIndices_[dofIdxGlobal] =
true;
475 else if (periodicGridTraits_.
isPeriodic(intersection))
480 const auto eps = 1e-7*(elementGeometry.corner(1) - elementGeometry.corner(0)).two_norm();
481 for (
int localDofIdx = 0; localDofIdx < localCoefficients.size(); ++localDofIdx)
483 if(!GeometryHelper::localDofOnIntersection(elementGeometry.type(), intersection.indexInInside(), localCoefficients.localKey(localDofIdx)))
486 const auto dofIdxGlobal = GeometryHelper::dofIndex(this->
dofMapper(),
element, localCoefficients.localKey(localDofIdx));
487 const auto dofPos = geometryHelper.dofPosition(localCoefficients.localKey(localDofIdx));
489 const auto& outside = intersection.outside();
490 const auto outsideGeometry = outside.geometry();
491 const auto& localCoefficientsOut = this->
feCache().get(outsideGeometry.type()).localCoefficients();
492 for (
const auto& isOutside : intersections(this->
gridView(), outside))
495 if (isOutside.boundary() && isOutside.neighbor())
497 for (
int localDofIdxOut = 0; localDofIdxOut < localCoefficientsOut.size(); ++localDofIdxOut)
499 const auto& localKeyOut = localCoefficientsOut.localKey(localDofIdxOut);
500 if(!GeometryHelper::localDofOnIntersection(outsideGeometry.type(), isOutside.indexInInside(), localKeyOut))
503 const auto dofIdxGlobalOut = GeometryHelper::dofIndex(this->
dofMapper(), outside, localKeyOut);
504 const auto dofPosOutside = GeometryHelper::dofPosition(outsideGeometry, localKeyOut);
505 const auto shift = std::abs((this->
bBoxMax()-this->
bBoxMin())*intersection.centerUnitOuterNormal());
506 if (std::abs((dofPosOutside-dofPos).two_norm() - shift) < eps)
507 periodicDofMap_[dofIdxGlobal] = dofIdxGlobalOut;
518 DUNE_THROW(Dune::NotImplemented,
"Periodic boundaries for pq2 method for parallel simulations!");
526 std::size_t numScvf_;
527 std::size_t numBoundaryScvf_;
530 std::vector<bool> boundaryDofIndices_;
533 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.
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
Class for a boundary face related to primary grid elements (dune intersections)
Definition: boundaryface.hh:69
const GlobalPosition & center() const
The center of the face.
Definition: boundaryface.hh:103
A class to create sub control volume and sub control volume face geometries per element.
Definition: discretization/pq2/geometryhelper.hh:51
Base class for the finite volume geometry vector for pq2 models This builds up the sub control volume...
Definition: discretization/pq2/fvelementgeometry.hh:48
Base class for the finite volume geometry vector for pq2 schemes This builds up the sub control volum...
Definition: discretization/pq2/fvgridgeometry.hh:138
Dune::LagrangeLocalFiniteElementCache< CoordScalar, Scalar, dim, 2 > FeCache
export the finite element cache type
Definition: discretization/pq2/fvgridgeometry.hh:176
typename Traits::DofMapper DofMapper
export dof mapper type
Definition: discretization/pq2/fvgridgeometry.hh:174
PQ2FVGridGeometry(const GridView &gridView)
Constructor.
Definition: discretization/pq2/fvgridgeometry.hh:203
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/pq2/fvgridgeometry.hh:216
const DofMapper & dofMapper() const
The dofMapper.
Definition: discretization/pq2/fvgridgeometry.hh:208
typename Traits::IntersectionQuadratureRule IntersectionQuadratureRule
the quadrature rule type for intersections
Definition: discretization/pq2/fvgridgeometry.hh:188
bool dofOnBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition: discretization/pq2/fvgridgeometry.hh:246
typename Traits::BoundaryFaceQuadratureRule BoundaryFaceQuadratureRule
the quadrature rule type for boundary faces
Definition: discretization/pq2/fvgridgeometry.hh:190
typename Traits::ScvQuadratureRule ScvQuadratureRule
the quadrature rule type for scvs
Definition: discretization/pq2/fvgridgeometry.hh:182
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition: discretization/pq2/fvgridgeometry.hh:242
void update(const GridView &gridView)
update all geometries (call this after grid adaption)
Definition: discretization/pq2/fvgridgeometry.hh:228
friend LocalView localView(const PQ2FVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition: discretization/pq2/fvgridgeometry.hh:262
typename Traits::ElementQuadratureRule ElementQuadratureRule
the quadrature rule type for elements
Definition: discretization/pq2/fvgridgeometry.hh:186
static constexpr bool enableHybridCVFE
Definition: discretization/pq2/fvgridgeometry.hh:156
std::size_t numBoundaryScvf() const
The total number of boundary sub control volume faces.
Definition: discretization/pq2/fvgridgeometry.hh:220
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/pq2/fvgridgeometry.hh:212
PQ2GridGeometryCache Cache
Definition: discretization/pq2/fvgridgeometry.hh:327
PQ2FVGridGeometry(std::shared_ptr< BasicGridGeometry > gg)
Constructor with basic grid geometry used to share state with another grid geometry on the same grid ...
Definition: discretization/pq2/fvgridgeometry.hh:193
typename Traits::ScvfQuadratureRule ScvfQuadratureRule
the quadrature rule type for scvfs
Definition: discretization/pq2/fvgridgeometry.hh:184
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: discretization/pq2/fvgridgeometry.hh:168
void update(GridView &&gridView)
update all geometries (call this after grid adaption)
Definition: discretization/pq2/fvgridgeometry.hh:235
typename Traits::template LocalView< ThisType, true > LocalView
export the type of the fv element geometry (the local view type)
Definition: discretization/pq2/fvgridgeometry.hh:164
GridIndexType periodicallyMappedDof(GridIndexType dofIdx) const
The index of the vertex / d.o.f. on the other side of the periodic boundary.
Definition: discretization/pq2/fvgridgeometry.hh:254
static constexpr std::size_t maxNumElementDofs
Definition: discretization/pq2/fvgridgeometry.hh:159
const std::unordered_map< GridIndexType, GridIndexType > & periodicDofMap() const
Returns the map between dofs across periodic boundaries.
Definition: discretization/pq2/fvgridgeometry.hh:258
static constexpr DiscretizationMethod discMethod
Definition: discretization/pq2/fvgridgeometry.hh:154
BasicGridGeometry_t< GV, Traits > BasicGridGeometry
export basic grid geometry type for the alternative constructor
Definition: discretization/pq2/fvgridgeometry.hh:162
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on a periodic boundary.
Definition: discretization/pq2/fvgridgeometry.hh:250
GV GridView
export the grid view type
Definition: discretization/pq2/fvgridgeometry.hh:178
typename PeriodicGridTraits< typename GV::Grid >::SupportsPeriodicity SupportsPeriodicity
export whether the grid(geometry) supports periodicity
Definition: discretization/pq2/fvgridgeometry.hh:180
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: discretization/pq2/fvgridgeometry.hh:166
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: discretization/pq2/fvgridgeometry.hh:224
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition: discretization/pq2/fvgridgeometry.hh:172
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/pq2/subcontrolvolumeface.hh:58
the sub control volume for the pq2 scheme
Definition: discretization/pq2/subcontrolvolume.hh:55
Defines the default element and vertex mapper types.
Base class for the finite volume geometry vector for the pq1bubble method This builds up the sub cont...
Base class for the local finite volume geometry for the pq2 method This builds up the sub control vol...
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::HybridPQ2GeometryHelper< GV, typename T::SubControlVolume, typename T::SubControlVolumeFace >, void >, SpecifiesGeometryHelper, T > PQ2GeometryHelper_t
Definition: discretization/pq2/fvgridgeometry.hh:61
typename T::GeometryHelper SpecifiesGeometryHelper
Definition: basegridgeometry.hh:30
CVFE< CVFEMethods::PQ2 > PQ2
Definition: method.hh:118
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:236
std::ranges::range auto scvs(const FVElementGeometry &fvGeometry, const LocalDof &localDof)
Definition: localdof.hh:79
Grid properties related to periodicity.
Quadrature rule traits for discretization schemes.
Definition: quadraturerules.hh:85
Definition: defaultmappertraits.hh:23
Structure to define the index types used for grid and local indices.
Definition: indextraits.hh:26
The default traits for the pq2 finite volume grid geometry Defines the scv and scvf types and the map...
Definition: discretization/pq2/fvgridgeometry.hh:104
static constexpr std::size_t maxNumElementDofs
Definition: discretization/pq2/fvgridgeometry.hh:115
std::true_type EnableHybridCVFE
Definition: discretization/pq2/fvgridgeometry.hh:111
Definition: discretization/pq2/fvgridgeometry.hh:66
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > DofMapper
Definition: discretization/pq2/fvgridgeometry.hh:67
static Dune::MCMGLayout layout()
layout for vertices and edges and elements (and faces in 3D) for the case of cubes
Definition: discretization/pq2/fvgridgeometry.hh:73
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.