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>;
194 : ParentType(std::move(gg))
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
274 using DofHelper =
typename GeometryHelper::DofHelper;
280 const PQ2FVGridGeometry& gridGeometry()
const
281 {
return *gridGeometry_; }
284 const std::vector<SubControlVolume>& scvs(GridIndexType eIdx)
const
285 {
return scvs_[eIdx]; }
288 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx)
const
289 {
return scvfs_[eIdx]; }
292 bool hasBoundaryScvf(GridIndexType eIdx)
const
293 {
return hasBoundaryScvf_[eIdx]; }
296 const std::vector<std::array<LocalIndexType, 2>>& scvfBoundaryGeometryKeys(GridIndexType eIdx)
const
297 {
return scvfBoundaryGeometryKeys_.at(eIdx); }
300 auto boundaryFaces(GridIndexType eIdx)
const -> std::span<const BoundaryFace>
302 if (
auto it = boundaryFaces_.find(eIdx); it != boundaryFaces_.end())
308 const auto& boundaryFaceScvfRanges(GridIndexType eIdx)
const
309 {
return boundaryFaceScvfRanges_.at(eIdx); }
316 hasBoundaryScvf_.clear();
317 scvfBoundaryGeometryKeys_.clear();
318 boundaryFaces_.clear();
319 boundaryFaceScvfRanges_.clear();
322 std::vector<std::vector<SubControlVolume>> scvs_;
323 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
324 std::vector<bool> hasBoundaryScvf_;
325 std::unordered_map<GridIndexType, std::vector<std::array<LocalIndexType, 2>>> scvfBoundaryGeometryKeys_;
326 std::unordered_map<GridIndexType, Dune::ReservedVector<typename PQ2FVGridGeometry::BoundaryFace, 2*dim>> boundaryFaces_;
327 std::unordered_map<GridIndexType, Dune::ReservedVector<std::array<LocalIndexType, 2>, 2*dim>> boundaryFaceScvfRanges_;
329 const PQ2FVGridGeometry* gridGeometry_;
338 using GeometryHelper =
typename Cache::GeometryHelper;
339 using DofHelper =
typename GeometryHelper::DofHelper;
344 dofMapper_.update(this->
gridView());
346 auto numElements = this->
gridView().size(0);
347 cache_.scvs_.resize(numElements);
348 cache_.scvfs_.resize(numElements);
349 cache_.hasBoundaryScvf_.resize(numElements,
false);
351 boundaryDofIndices_.assign(
numDofs(),
false);
355 numBoundaryScvf_ = 0;
363 auto elementGeometry =
element.geometry();
365 const auto& localCoefficients = this->
feCache().get(
element.type()).localCoefficients();
368 GeometryHelper geometryHelper(elementGeometry);
370 numScv_ += geometryHelper.numScv();
372 cache_.scvs_[eIdx].resize(geometryHelper.numScv());
374 for (LocalIndexType keyIdx = 0; keyIdx < localCoefficients.size(); ++keyIdx)
376 const auto& localKey = localCoefficients.localKey(keyIdx);
378 if(localKey.codim() == dim)
380 const auto localIdx = localKey.subEntity();
382 auto corners = geometryHelper.getScvCorners(localIdx);
384 geometryHelper.scvVolume(localIdx, corners),
385 DofHelper::dofPosition(elementGeometry, localKey),
390 DofHelper::dofIndex(this->dofMapper(),
element, localKey),
397 const auto numInteriorScvfs = GeometryHelper::numInteriorScvf(elementGeometry.type());
398 numScvf_ += numInteriorScvfs;
399 cache_.scvfs_[eIdx].resize(numInteriorScvfs);
400 LocalIndexType scvfLocalIdx = 0;
401 for (; scvfLocalIdx < numInteriorScvfs; ++scvfLocalIdx)
403 const auto scvPair = geometryHelper.getScvPairForScvf(scvfLocalIdx);
404 const auto corners = geometryHelper.getScvfCorners(scvfLocalIdx);
406 geometryHelper.getInteriorScvfGeometryType(scvfLocalIdx),
407 [&](
unsigned int i){
return corners[i]; }
413 geometryHelper.normal(corners, scvPair),
416 geometryHelper.isOverlappingScvf(scvfLocalIdx)
421 LocalIndexType numBoundaryFaces = 0;
422 for (
const auto& intersection : intersections(this->
gridView(),
element))
424 if (intersection.boundary() && !intersection.neighbor())
426 cache_.hasBoundaryScvf_[eIdx] =
true;
429 const auto isGeometry = intersection.geometry();
433 intersection.centerUnitOuterNormal(),
435 static_cast<LocalIndexType
>(intersection.indexInInside()),
436 typename BoundaryFace::Traits::BoundaryFlag{intersection}
439 const auto localFacetIndex = intersection.indexInInside();
440 const auto numBoundaryScvf = GeometryHelper::numBoundaryScvf(elementGeometry.type(), localFacetIndex);
445 cache_.boundaryFaceScvfRanges_[eIdx].push_back(std::array<LocalIndexType, 2>{{
450 for (
unsigned int isScvfLocalIdx = 0; isScvfLocalIdx <
numBoundaryScvf; ++isScvfLocalIdx)
453 const auto scvPair = geometryHelper.getScvPairForBoundaryScvf(localFacetIndex, isScvfLocalIdx);
454 const auto corners = geometryHelper.getBoundaryScvfCorners(localFacetIndex, isScvfLocalIdx);
456 geometryHelper.getBoundaryScvfGeometryType(isScvfLocalIdx),
457 [&](
unsigned int i){
return corners[i]; }
459 cache_.scvfs_[eIdx].emplace_back(
462 intersection.centerUnitOuterNormal(),
465 typename SubControlVolumeFace::Traits::BoundaryFlag{ intersection },
466 geometryHelper.isOverlappingBoundaryScvf(localFacetIndex)
470 cache_.scvfBoundaryGeometryKeys_[eIdx].emplace_back(std::array<LocalIndexType, 2>{{
471 static_cast<LocalIndexType
>(localFacetIndex),
472 static_cast<LocalIndexType
>(isScvfLocalIdx)
479 for (LocalIndexType keyIdx = 0; keyIdx < localCoefficients.size(); ++keyIdx)
481 if(DofHelper::localDofOnIntersection(elementGeometry.type(), intersection.indexInInside(), localCoefficients.localKey(keyIdx)))
483 const auto dofIdxGlobal = DofHelper::dofIndex(this->
dofMapper(),
element, localCoefficients.localKey(keyIdx));
484 boundaryDofIndices_[dofIdxGlobal] =
true;
490 else if (periodicGridTraits_.isPeriodic(intersection))
495 const auto eps = 1e-7*(elementGeometry.corner(1) - elementGeometry.corner(0)).two_norm();
496 for (
int localDofIdx = 0; localDofIdx < localCoefficients.size(); ++localDofIdx)
498 if(!DofHelper::localDofOnIntersection(elementGeometry.type(), intersection.indexInInside(), localCoefficients.localKey(localDofIdx)))
501 const auto dofIdxGlobal = DofHelper::dofIndex(this->
dofMapper(),
element, localCoefficients.localKey(localDofIdx));
502 const auto dofPos = DofHelper::dofPosition(elementGeometry, localCoefficients.localKey(localDofIdx));
504 const auto& outside = intersection.outside();
505 const auto outsideGeometry = outside.geometry();
506 const auto& localCoefficientsOut = this->
feCache().get(outsideGeometry.type()).localCoefficients();
507 for (
const auto& isOutside : intersections(this->
gridView(), outside))
510 if (isOutside.boundary() && isOutside.neighbor())
512 for (
int localDofIdxOut = 0; localDofIdxOut < localCoefficientsOut.size(); ++localDofIdxOut)
514 const auto& localKeyOut = localCoefficientsOut.localKey(localDofIdxOut);
515 if(!DofHelper::localDofOnIntersection(outsideGeometry.type(), isOutside.indexInInside(), localKeyOut))
518 const auto dofIdxGlobalOut = DofHelper::dofIndex(this->
dofMapper(), outside, localKeyOut);
519 const auto dofPosOutside = DofHelper::dofPosition(outsideGeometry, localKeyOut);
520 const auto shift = std::abs((this->
bBoxMax()-this->
bBoxMin())*intersection.centerUnitOuterNormal());
521 if (std::abs((dofPosOutside-dofPos).two_norm() - shift) < eps)
522 periodicDofMap_[dofIdxGlobal] = dofIdxGlobalOut;
533 DUNE_THROW(Dune::NotImplemented,
"Periodic boundaries for pq2 method for parallel simulations!");
541 std::size_t numScvf_;
542 std::size_t numBoundaryScvf_;
545 std::vector<bool> boundaryDofIndices_;
548 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
A class to create sub control volume and sub control volume face geometries per element.
Definition discretization/pq2/geometryhelper.hh:55
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
Definition discretization/pq2/fvgridgeometry.hh:176
typename PQ2DefaultGridGeometryTraits< GridView >::DofMapper DofMapper
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 PQ2DefaultGridGeometryTraits< GridView >::IntersectionQuadratureRule IntersectionQuadratureRule
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 PQ2DefaultGridGeometryTraits< GridView >::BoundaryFaceQuadratureRule BoundaryFaceQuadratureRule
Definition discretization/pq2/fvgridgeometry.hh:190
typename PQ2DefaultGridGeometryTraits< GridView >::ScvQuadratureRule ScvQuadratureRule
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
Experimental::BoundaryFace< GridView > BoundaryFace
Definition discretization/pq2/fvgridgeometry.hh:170
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 PQ2DefaultGridGeometryTraits< GridView >::ElementQuadratureRule ElementQuadratureRule
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:335
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 PQ2DefaultGridGeometryTraits< GridView >::ScvfQuadratureRule ScvfQuadratureRule
Definition discretization/pq2/fvgridgeometry.hh:184
typename PQ2DefaultGridGeometryTraits< GridView >::SubControlVolumeFace SubControlVolumeFace
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 PQ2DefaultGridGeometryTraits< GridView >::template LocalView< ThisType, true > LocalView
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< GridView, PQ2DefaultGridGeometryTraits< GridView > > BasicGridGeometry
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
GridView GridView
Definition discretization/pq2/fvgridgeometry.hh:178
typename PeriodicGridTraits< typename GridView::Grid >::SupportsPeriodicity SupportsPeriodicity
Definition discretization/pq2/fvgridgeometry.hh:180
typename PQ2DefaultGridGeometryTraits< GridView >::SubControlVolume SubControlVolume
Definition discretization/pq2/fvgridgeometry.hh:166
DiscretizationMethods::PQ2 DiscretizationMethod
Definition discretization/pq2/fvgridgeometry.hh:153
std::size_t numDofs() const
The total number of degrees of freedom.
Definition discretization/pq2/fvgridgeometry.hh:224
Extrusion_t< PQ2DefaultGridGeometryTraits< GridView > > 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: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 > PQ2QuadratureTraits
Quadrature rule traits for PQ2 discretization.
Definition discretization/pq2/fvgridgeometry.hh:93
The available discretization methods in Dumux.
Definition cvfelocalresidual.hh:25
static constexpr bool enablesHybridCVFE
Definition discretization/pq1bubble/fvgridgeometry.hh:51
typename T::GeometryHelper SpecifiesGeometryHelper
Definition basegridgeometry.hh:30
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:54
CVFE< CVFEMethods::PQ2 > PQ2
Definition method.hh:132
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition extrusion.hh:257
Grid properties related to periodicity.
Quadrature rule traits for discretization schemes.
Definition quadraturerules.hh:85
Definition defaultmappertraits.hh:23
typename GridView::IndexSet::IndexType GridIndex
Definition indextraits.hh:27
unsigned int LocalIndex
Definition indextraits.hh:28
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
PQ2FVElementGeometry< GridGeometry, enableCache > LocalView
Definition discretization/pq2/fvgridgeometry.hh:109
PQ2SubControlVolumeFace< GridView > SubControlVolumeFace
Definition discretization/pq2/fvgridgeometry.hh:106
PQ2SubControlVolume< GridView > SubControlVolume
Definition discretization/pq2/fvgridgeometry.hh:105
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
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.