14#ifndef DUMUX_DISCRETIZATION_PQ3_GRID_GEOMETRY_HH
15#define DUMUX_DISCRETIZATION_PQ3_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>
56template<
class GG,
bool enableCache>
61template<
class GV,
class T>
63 std::conditional_t<enablesHybridCVFE<T>,
82 using DofMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GV>;
86 return [](Dune::GeometryType gt,
int ) -> std::size_t {
87 if (gt.dim() == 0)
return 1;
88 if (gt.dim() == 1)
return 2;
90 if (gt == Dune::GeometryTypes::cube(2))
return 4;
91 if (gt == Dune::GeometryTypes::simplex(2))
return 1;
94 if (gt == Dune::GeometryTypes::cube(3))
return 8;
106template<
class GridView,
118template<
class GridView,
122:
public MapperTraits,
public QuadratureTraits
127 template<
class Gr
idGeometry,
bool enableCache>
135 if constexpr (GridView::dimension == 1)
137 else if constexpr (GridView::dimension == 2)
139 else if constexpr (GridView::dimension == 3)
151template<
class Scalar,
153 bool enableCaching =
true,
154 class Traits = PQ3DefaultGridGeometryTraits<GV>>
163 using Element =
typename GV::template Codim<0>::Entity;
164 using CoordScalar =
typename GV::ctype;
165 static const int dim = GV::dimension;
166 static const int dimWorld = GV::dimensionworld;
168 static_assert(dim > 1,
"Only implemented for dim > 1");
195 using FeCache = Dune::LagrangeLocalFiniteElementCache<CoordScalar, Scalar, dim, 3>;
209 : ParentType(std::move(gg))
210 , dofMapper_(this->
gridView(), Traits::layout())
212 , periodicGridTraits_(this->
gridView().grid())
223 {
return dofMapper_; }
232 {
return numBoundaryScvf_; }
256 template<
class LocalKey>
258 {
return GeometryHelper::dofIndex(dofMapper_,
element, localKey, this->
gridView().grid().globalIdSet()); }
261 {
return boundaryDofIndices_[dofIdx]; }
264 {
return periodicDofMap_.count(dofIdx); }
267 {
return periodicDofMap_.at(dofIdx); }
270 {
return periodicDofMap_; }
273 {
return { gg.cache_ }; }
277 class PQ3GridGeometryCache
287 const PQ3FVGridGeometry& gridGeometry()
const
288 {
return *gridGeometry_; }
290 const std::vector<SubControlVolume>& scvs(GridIndexType eIdx)
const
291 {
return scvs_[eIdx]; }
293 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx)
const
294 {
return scvfs_[eIdx]; }
296 bool hasBoundaryScvf(GridIndexType eIdx)
const
297 {
return hasBoundaryScvf_[eIdx]; }
299 const std::vector<std::array<LocalIndexType, 2>>& scvfBoundaryGeometryKeys(GridIndexType eIdx)
const
300 {
return scvfBoundaryGeometryKeys_.at(eIdx); }
302 auto boundaryFaces(GridIndexType eIdx)
const -> std::span<const BoundaryFace>
304 if (
auto it = boundaryFaces_.find(eIdx); it != boundaryFaces_.end())
309 const auto& boundaryFaceScvfRanges(GridIndexType eIdx)
const
310 {
return boundaryFaceScvfRanges_.at(eIdx); }
317 hasBoundaryScvf_.clear();
318 scvfBoundaryGeometryKeys_.clear();
319 boundaryFaces_.clear();
320 boundaryFaceScvfRanges_.clear();
323 std::vector<std::vector<SubControlVolume>> scvs_;
324 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
325 std::vector<bool> hasBoundaryScvf_;
326 std::unordered_map<GridIndexType, std::vector<std::array<LocalIndexType, 2>>> scvfBoundaryGeometryKeys_;
327 std::unordered_map<GridIndexType, Dune::ReservedVector<typename PQ3FVGridGeometry::BoundaryFace, 2*dim>> boundaryFaces_;
328 std::unordered_map<GridIndexType, Dune::ReservedVector<std::array<LocalIndexType, 2>, 2*dim>> boundaryFaceScvfRanges_;
330 const PQ3FVGridGeometry* gridGeometry_;
337 using GeometryHelper =
typename Cache::GeometryHelper;
342 dofMapper_.update(this->
gridView());
344 const auto& gidSet = this->
gridView().grid().globalIdSet();
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;
360 auto elementGeometry =
element.geometry();
361 const auto& localCoefficients = this->
feCache().get(
element.type()).localCoefficients();
363 GeometryHelper geometryHelper(elementGeometry);
365 numScv_ += geometryHelper.numScv();
366 cache_.scvs_[eIdx].resize(geometryHelper.numScv());
368 for (LocalIndexType keyIdx = 0; keyIdx < localCoefficients.size(); ++keyIdx)
370 const auto& localKey = localCoefficients.localKey(keyIdx);
371 if (localKey.codim() == dim)
373 const auto localIdx = localKey.subEntity();
374 auto corners = geometryHelper.getScvCorners(localIdx);
376 geometryHelper.scvVolume(localIdx, corners),
377 geometryHelper.dofPosition(localKey),
382 geometryHelper.dofIndex(this->dofMapper(),
element, localKey, gidSet),
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)
411 LocalIndexType numBoundaryFaces = 0;
412 for (
const auto& intersection : intersections(this->
gridView(),
element))
414 if (intersection.boundary() && !intersection.neighbor())
416 cache_.hasBoundaryScvf_[eIdx] =
true;
418 const auto isGeometry = intersection.geometry();
422 intersection.centerUnitOuterNormal(),
424 static_cast<LocalIndexType
>(intersection.indexInInside()),
425 typename BoundaryFace::Traits::BoundaryFlag{intersection}
428 const auto localFacetIndex = intersection.indexInInside();
429 const auto numBoundaryScvf = GeometryHelper::numBoundaryScvf(elementGeometry.type(), localFacetIndex);
433 cache_.boundaryFaceScvfRanges_[eIdx].push_back(std::array<LocalIndexType, 2>{{
438 for (
unsigned int isScvfLocalIdx = 0; isScvfLocalIdx <
numBoundaryScvf; ++isScvfLocalIdx)
440 const auto scvPair = geometryHelper.getScvPairForBoundaryScvf(localFacetIndex, isScvfLocalIdx);
441 const auto corners = geometryHelper.getBoundaryScvfCorners(localFacetIndex, isScvfLocalIdx);
443 geometryHelper.getBoundaryScvfGeometryType(isScvfLocalIdx),
444 [&](
unsigned int i){
return corners[i]; }
446 cache_.scvfs_[eIdx].emplace_back(
449 intersection.centerUnitOuterNormal(),
452 typename SubControlVolumeFace::Traits::BoundaryFlag{ intersection },
453 geometryHelper.isOverlappingBoundaryScvf(localFacetIndex)
456 cache_.scvfBoundaryGeometryKeys_[eIdx].emplace_back(std::array<LocalIndexType, 2>{{
457 static_cast<LocalIndexType
>(localFacetIndex),
458 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), gidSet);
469 boundaryDofIndices_[dofIdxGlobal] =
true;
474 else if (periodicGridTraits_.isPeriodic(intersection))
478 const auto eps = 1e-7*(elementGeometry.corner(1) - elementGeometry.corner(0)).two_norm();
479 for (
int localDofIdx = 0; localDofIdx < localCoefficients.size(); ++localDofIdx)
481 if (!GeometryHelper::localDofOnIntersection(elementGeometry.type(), intersection.indexInInside(), localCoefficients.localKey(localDofIdx)))
484 const auto dofIdxGlobal = GeometryHelper::dofIndex(this->
dofMapper(),
element, localCoefficients.localKey(localDofIdx), gidSet);
485 const auto dofPos = geometryHelper.dofPosition(localCoefficients.localKey(localDofIdx));
487 const auto& outside = intersection.outside();
488 const auto outsideGeometry = outside.geometry();
489 const auto& localCoefficientsOut = this->
feCache().get(outsideGeometry.type()).localCoefficients();
490 for (
const auto& isOutside : intersections(this->
gridView(), outside))
492 if (isOutside.boundary() && isOutside.neighbor())
494 for (
int localDofIdxOut = 0; localDofIdxOut < localCoefficientsOut.size(); ++localDofIdxOut)
496 const auto& localKeyOut = localCoefficientsOut.localKey(localDofIdxOut);
497 if (!GeometryHelper::localDofOnIntersection(outsideGeometry.type(), isOutside.indexInInside(), localKeyOut))
500 const auto dofIdxGlobalOut = GeometryHelper::dofIndex(this->
dofMapper(), outside, localKeyOut, gidSet);
501 const auto dofPosOutside = GeometryHelper::dofPosition(outsideGeometry, localKeyOut);
502 const auto shift = std::abs((this->
bBoxMax()-this->
bBoxMin())*intersection.centerUnitOuterNormal());
503 if (std::abs((dofPosOutside-dofPos).two_norm() - shift) < eps)
504 periodicDofMap_[dofIdxGlobal] = dofIdxGlobalOut;
514 DUNE_THROW(Dune::NotImplemented,
"Periodic boundaries for pq3 method for parallel simulations!");
520 std::size_t numScvf_;
521 std::size_t numBoundaryScvf_;
522 std::vector<bool> boundaryDofIndices_;
523 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 for the order...
Definition discretization/pq3/geometryhelper.hh:53
Base class for the finite volume geometry vector for pq2 models This builds up the sub control volume...
Definition discretization/pq2/fvelementgeometry.hh:48
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
Finite volume geometry for the pq3 hybrid CVFE scheme (order-3 Lagrange elements).
Definition discretization/pq3/fvgridgeometry.hh:157
typename PQ3DefaultGridGeometryTraits< GridView >::IntersectionQuadratureRule IntersectionQuadratureRule
Definition discretization/pq3/fvgridgeometry.hh:204
Dune::LagrangeLocalFiniteElementCache< CoordScalar, Scalar, dim, 3 > FeCache
Definition discretization/pq3/fvgridgeometry.hh:195
typename PQ3DefaultGridGeometryTraits< GridView >::ScvQuadratureRule ScvQuadratureRule
Definition discretization/pq3/fvgridgeometry.hh:201
PQ3FVGridGeometry(const GridView &gridView)
Constructor.
Definition discretization/pq3/fvgridgeometry.hh:218
typename PQ3DefaultGridGeometryTraits< GridView >::ScvfQuadratureRule ScvfQuadratureRule
Definition discretization/pq3/fvgridgeometry.hh:202
std::size_t numScv() const
Definition discretization/pq3/fvgridgeometry.hh:225
friend LocalView localView(const PQ3FVGridGeometry &gg)
Definition discretization/pq3/fvgridgeometry.hh:272
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
Definition discretization/pq3/fvgridgeometry.hh:263
bool dofOnBoundary(GridIndexType dofIdx) const
Definition discretization/pq3/fvgridgeometry.hh:260
const DofMapper & dofMapper() const
Definition discretization/pq3/fvgridgeometry.hh:222
auto dofIndex(const Element &element, const LocalKey &localKey) const
Definition discretization/pq3/fvgridgeometry.hh:257
Experimental::BoundaryFace< GridView > BoundaryFace
Definition discretization/pq3/fvgridgeometry.hh:189
const FeCache & feCache() const
Definition discretization/pq3/fvgridgeometry.hh:249
GridView GridView
Definition discretization/pq3/fvgridgeometry.hh:197
typename PQ3DefaultGridGeometryTraits< GridView >::template LocalView< ThisType, true > LocalView
Definition discretization/pq3/fvgridgeometry.hh:183
static constexpr std::size_t maxNumElementDofs
Definition discretization/pq3/fvgridgeometry.hh:178
static constexpr bool enableHybridCVFE
Definition discretization/pq3/fvgridgeometry.hh:175
std::size_t numDofs() const
Definition discretization/pq3/fvgridgeometry.hh:234
const std::unordered_map< GridIndexType, GridIndexType > & periodicDofMap() const
Definition discretization/pq3/fvgridgeometry.hh:269
void update(const GridView &gridView)
Definition discretization/pq3/fvgridgeometry.hh:237
DiscretizationMethods::PQ3 DiscretizationMethod
Definition discretization/pq3/fvgridgeometry.hh:172
typename PQ3DefaultGridGeometryTraits< GridView >::BoundaryFaceQuadratureRule BoundaryFaceQuadratureRule
Definition discretization/pq3/fvgridgeometry.hh:205
GridIndexType periodicallyMappedDof(GridIndexType dofIdx) const
Definition discretization/pq3/fvgridgeometry.hh:266
typename PeriodicGridTraits< typename GridView::Grid >::SupportsPeriodicity SupportsPeriodicity
Definition discretization/pq3/fvgridgeometry.hh:199
typename PQ3DefaultGridGeometryTraits< GridView >::SubControlVolume SubControlVolume
Definition discretization/pq3/fvgridgeometry.hh:185
typename PQ3DefaultGridGeometryTraits< GridView >::DofMapper DofMapper
Definition discretization/pq3/fvgridgeometry.hh:193
void update(GridView &&gridView)
Definition discretization/pq3/fvgridgeometry.hh:243
std::size_t numBoundaryScvf() const
Definition discretization/pq3/fvgridgeometry.hh:231
std::size_t numScvf() const
Definition discretization/pq3/fvgridgeometry.hh:228
PQ3GridGeometryCache Cache
Definition discretization/pq3/fvgridgeometry.hh:334
typename PQ3DefaultGridGeometryTraits< GridView >::SubControlVolumeFace SubControlVolumeFace
Definition discretization/pq3/fvgridgeometry.hh:187
BasicGridGeometry_t< GridView, PQ3DefaultGridGeometryTraits< GridView > > BasicGridGeometry
Definition discretization/pq3/fvgridgeometry.hh:181
PQ3FVGridGeometry(std::shared_ptr< BasicGridGeometry > gg)
Constructor with shared basic grid geometry.
Definition discretization/pq3/fvgridgeometry.hh:208
static constexpr DiscretizationMethod discMethod
Definition discretization/pq3/fvgridgeometry.hh:173
typename PQ3DefaultGridGeometryTraits< GridView >::ElementQuadratureRule ElementQuadratureRule
Definition discretization/pq3/fvgridgeometry.hh:203
Extrusion_t< PQ3DefaultGridGeometryTraits< GridView > > Extrusion
Definition discretization/pq3/fvgridgeometry.hh:191
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...
the sub control volume for the cvfe scheme
Base class for a sub control volume face.
Helper class constructing the dual grid finite volume geometries for the pq3 cvfe discretization meth...
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 > PQ3QuadratureTraits
Quadrature rule traits for PQ3 discretization.
Definition discretization/pq3/fvgridgeometry.hh:112
The available discretization methods in Dumux.
Definition cvfelocalresidual.hh:25
static constexpr bool enablesHybridCVFE
Definition discretization/pq1bubble/fvgridgeometry.hh:51
Dune::Std::detected_or_t< std::conditional_t< enablesHybridCVFE< T >, Dumux::HybridPQ3GeometryHelper< GV, typename T::SubControlVolume, typename T::SubControlVolumeFace >, void >, SpecifiesGeometryHelper, T > PQ3GeometryHelper_t
Definition discretization/pq3/fvgridgeometry.hh:62
typename T::GeometryHelper SpecifiesGeometryHelper
Definition basegridgeometry.hh:30
CVFE< CVFEMethods::PQ3 > PQ3
Definition method.hh:128
PQ2SubControlVolume< GV > PQ3SubControlVolume
Definition discretization/pq3/fvgridgeometry.hh:50
PQ2FVElementGeometry< GG, enableCache > PQ3FVElementGeometry
Definition discretization/pq3/fvgridgeometry.hh:57
PQ2SubControlVolumeFace< GV > PQ3SubControlVolumeFace
Definition discretization/pq3/fvgridgeometry.hh:53
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition extrusion.hh:236
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
Default traits for the pq3 finite volume grid geometry.
Definition discretization/pq3/fvgridgeometry.hh:123
static constexpr std::size_t maxNumElementDofs
Definition discretization/pq3/fvgridgeometry.hh:133
std::true_type EnableHybridCVFE
Definition discretization/pq3/fvgridgeometry.hh:130
PQ3SubControlVolumeFace< GridView > SubControlVolumeFace
Definition discretization/pq3/fvgridgeometry.hh:125
PQ3SubControlVolume< GridView > SubControlVolume
Definition discretization/pq3/fvgridgeometry.hh:124
PQ3FVElementGeometry< GridGeometry, enableCache > LocalView
Definition discretization/pq3/fvgridgeometry.hh:128
Mapper traits for PQ3: vertices get 1 DOF, edges get 2 DOFs, quad faces/elements get 4 DOFs,...
Definition discretization/pq3/fvgridgeometry.hh:81
Dune::MultipleCodimMultipleGeomTypeMapper< GV > DofMapper
Definition discretization/pq3/fvgridgeometry.hh:82
static Dune::MCMGLayout layout()
Definition discretization/pq3/fvgridgeometry.hh:84
Definition periodicgridtraits.hh:24
Definition periodicgridtraits.hh:23
Dune-based quadrature rule with specified order.
Definition quadraturerules.hh:66
Compute the volume of several common geometry types.