14#ifndef DUMUX_DISCRETIZATION_PQ2_GRID_GEOMETRY_HH
15#define DUMUX_DISCRETIZATION_PQ2_GRID_GEOMETRY_HH
22#include <unordered_map>
25#include <dune/grid/common/mcmgmapper.hh>
26#include <dune/geometry/type.hh>
51template<
class GV,
class T>
53 std::conditional_t<enablesHybridCVFE<T>,
62template <
class Gr
idView>
65 using DofMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
73 return [](Dune::GeometryType gt,
int dimgrid) {
74 return (gt.dim() == 0) || (gt.dim() == 1)
75 || (gt.dim() == dimgrid && gt == Dune::GeometryTypes::cube(dimgrid))
76 || (dimgrid == 3 && gt == Dune::GeometryTypes::cube(dimgrid-1));
85template<
class GridView,
98template<
class Gr
idView,
class MapperTraits = PQ2MapperTraits<Gr
idView>,
class QuadratureTraits = PQ2QuadratureTraits<Gr
idView>>
100:
public MapperTraits,
public QuadratureTraits
105 template<
class Gr
idGeometry,
bool enableCache>
114 if constexpr (GridView::dimension == 1)
116 else if constexpr (GridView::dimension == 2)
118 else if constexpr (GridView::dimension == 3)
129template<
class Scalar,
131 bool enableCaching =
true,
132 class Traits = PQ2DefaultGridGeometryTraits<GV>>
141 using Element =
typename GV::template Codim<0>::Entity;
142 using CoordScalar =
typename GV::ctype;
143 static const int dim = GV::dimension;
144 static const int dimWorld = GV::dimensionworld;
146 static_assert(dim > 1,
"Only implemented for dim > 1");
188 , dofMapper_(this->
gridView(), Traits::layout())
190 , periodicGridTraits_(this->
gridView().grid())
202 {
return dofMapper_; }
214 {
return numBoundaryScvf_; }
240 {
return boundaryDofIndices_[dofIdx]; }
244 {
return periodicDofMap_.count(dofIdx); }
248 {
return periodicDofMap_.at(dofIdx); }
252 {
return periodicDofMap_; }
256 {
return { gg.cache_ }; }
260 class PQ2GridGeometryCache
272 {
return *gridGeometry_; }
275 const std::vector<SubControlVolume>&
scvs(GridIndexType eIdx)
const
276 {
return scvs_[eIdx]; }
279 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx)
const
280 {
return scvfs_[eIdx]; }
283 bool hasBoundaryScvf(GridIndexType eIdx)
const
284 {
return hasBoundaryScvf_[eIdx]; }
287 const std::vector<std::array<LocalIndexType, 2>>& scvfBoundaryGeometryKeys(GridIndexType eIdx)
const
288 {
return scvfBoundaryGeometryKeys_.at(eIdx); }
295 hasBoundaryScvf_.clear();
296 scvfBoundaryGeometryKeys_.clear();
299 std::vector<std::vector<SubControlVolume>> scvs_;
300 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
301 std::vector<bool> hasBoundaryScvf_;
302 std::unordered_map<GridIndexType, std::vector<std::array<LocalIndexType, 2>>> scvfBoundaryGeometryKeys_;
313 using GeometryHelper =
typename Cache::GeometryHelper;
318 dofMapper_.update(this->
gridView());
320 auto numElements = this->
gridView().size(0);
321 cache_.scvs_.resize(numElements);
322 cache_.scvfs_.resize(numElements);
323 cache_.hasBoundaryScvf_.resize(numElements,
false);
325 boundaryDofIndices_.assign(
numDofs(),
false);
329 numBoundaryScvf_ = 0;
337 auto elementGeometry =
element.geometry();
339 const auto& localCoefficients = this->
feCache().
get(
element.type()).localCoefficients();
342 GeometryHelper geometryHelper(elementGeometry);
344 numScv_ += geometryHelper.numScv();
346 cache_.scvs_[eIdx].resize(geometryHelper.numScv());
348 for (LocalIndexType keyIdx = 0; keyIdx < localCoefficients.size(); ++keyIdx)
350 const auto& localKey = localCoefficients.localKey(keyIdx);
352 if(localKey.codim() == dim)
354 const auto localIdx = localKey.subEntity();
356 auto corners = geometryHelper.getScvCorners(localIdx);
358 geometryHelper.scvVolume(localIdx, corners),
359 geometryHelper.dofPosition(localKey),
364 geometryHelper.dofIndex(this->dofMapper(),
element, localKey),
371 const auto numInteriorScvfs = GeometryHelper::numInteriorScvf(elementGeometry.type());
372 numScvf_ += numInteriorScvfs;
373 cache_.scvfs_[eIdx].resize(numInteriorScvfs);
374 LocalIndexType scvfLocalIdx = 0;
375 for (; scvfLocalIdx < numInteriorScvfs; ++scvfLocalIdx)
377 const auto scvPair = geometryHelper.getScvPairForScvf(scvfLocalIdx);
378 const auto corners = geometryHelper.getScvfCorners(scvfLocalIdx);
380 geometryHelper.getInteriorScvfGeometryType(scvfLocalIdx),
381 [&](
unsigned int i){
return corners[i]; }
387 geometryHelper.normal(corners, scvPair),
390 geometryHelper.isOverlappingScvf(scvfLocalIdx)
395 for (
const auto& intersection : intersections(this->
gridView(),
element))
397 if (intersection.boundary() && !intersection.neighbor())
399 cache_.hasBoundaryScvf_[eIdx] =
true;
401 const auto localFacetIndex = intersection.indexInInside();
402 const auto numBoundaryScvf = GeometryHelper::numBoundaryScvf(elementGeometry.type(), localFacetIndex);
406 for (
unsigned int isScvfLocalIdx = 0; isScvfLocalIdx <
numBoundaryScvf; ++isScvfLocalIdx)
409 const auto scvPair = geometryHelper.getScvPairForBoundaryScvf(localFacetIndex, isScvfLocalIdx);
410 const auto corners = geometryHelper.getBoundaryScvfCorners(localFacetIndex, isScvfLocalIdx);
412 geometryHelper.getBoundaryScvfGeometryType(isScvfLocalIdx),
413 [&](
unsigned int i){
return corners[i]; }
415 cache_.scvfs_[eIdx].emplace_back(
418 intersection.centerUnitOuterNormal(),
421 typename SubControlVolumeFace::Traits::BoundaryFlag{ intersection },
422 geometryHelper.isOverlappingBoundaryScvf(localFacetIndex)
426 cache_.scvfBoundaryGeometryKeys_[eIdx].emplace_back(std::array<LocalIndexType, 2>{{
427 static_cast<LocalIndexType
>(localFacetIndex),
428 static_cast<LocalIndexType
>(isScvfLocalIdx)
435 for (LocalIndexType keyIdx = 0; keyIdx < localCoefficients.size(); ++keyIdx)
437 if(GeometryHelper::localDofOnIntersection(elementGeometry.type(), intersection.indexInInside(), localCoefficients.localKey(keyIdx)))
439 const auto dofIdxGlobal = GeometryHelper::dofIndex(this->
dofMapper(),
element, localCoefficients.localKey(keyIdx));
440 boundaryDofIndices_[dofIdxGlobal] =
true;
446 else if (periodicGridTraits_.
isPeriodic(intersection))
451 const auto eps = 1e-7*(elementGeometry.corner(1) - elementGeometry.corner(0)).two_norm();
452 for (
int localDofIdx = 0; localDofIdx < localCoefficients.size(); ++localDofIdx)
454 if(!GeometryHelper::localDofOnIntersection(elementGeometry.type(), intersection.indexInInside(), localCoefficients.localKey(localDofIdx)))
457 const auto dofIdxGlobal = GeometryHelper::dofIndex(this->
dofMapper(),
element, localCoefficients.localKey(localDofIdx));
458 const auto dofPos = geometryHelper.dofPosition(localCoefficients.localKey(localDofIdx));
460 const auto& outside = intersection.outside();
461 const auto outsideGeometry = outside.geometry();
462 const auto& localCoefficientsOut = this->
feCache().
get(outsideGeometry.type()).localCoefficients();
463 for (
const auto& isOutside : intersections(this->
gridView(), outside))
466 if (isOutside.boundary() && isOutside.neighbor())
468 for (
int localDofIdxOut = 0; localDofIdxOut < localCoefficientsOut.size(); ++localDofIdxOut)
470 const auto& localKeyOut = localCoefficientsOut.localKey(localDofIdxOut);
471 if(!GeometryHelper::localDofOnIntersection(outsideGeometry.type(), isOutside.indexInInside(), localKeyOut))
474 const auto dofIdxGlobalOut = GeometryHelper::dofIndex(this->
dofMapper(), outside, localKeyOut);
475 const auto dofPosOutside = GeometryHelper::dofPosition(outsideGeometry, localKeyOut);
476 const auto shift = std::abs((this->
bBoxMax()-this->
bBoxMin())*intersection.centerUnitOuterNormal());
477 if (std::abs((dofPosOutside-dofPos).two_norm() - shift) < eps)
478 periodicDofMap_[dofIdxGlobal] = dofIdxGlobalOut;
489 DUNE_THROW(Dune::NotImplemented,
"Periodic boundaries for pq2 method for parallel simulations!");
497 std::size_t numScvf_;
498 std::size_t numBoundaryScvf_;
501 std::vector<bool> boundaryDofIndices_;
504 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
A class to create sub control volume and sub control volume face geometries per element.
Definition: discretization/pq2/geometryhelper.hh:50
Base class for the finite volume geometry vector for pq2 models This builds up the sub control volume...
Definition: discretization/pq2/fvelementgeometry.hh:47
Base class for the finite volume geometry vector for pq2 schemes This builds up the sub control volum...
Definition: discretization/pq2/fvgridgeometry.hh:135
typename Traits::DofMapper DofMapper
export dof mapper type
Definition: discretization/pq2/fvgridgeometry.hh:169
PQ2FVGridGeometry(const GridView &gridView)
Constructor.
Definition: discretization/pq2/fvgridgeometry.hh:196
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/pq2/fvgridgeometry.hh:209
const DofMapper & dofMapper() const
The dofMapper.
Definition: discretization/pq2/fvgridgeometry.hh:201
typename Traits::IntersectionQuadratureRule IntersectionQuadratureRule
the quadrature rule type for intersections
Definition: discretization/pq2/fvgridgeometry.hh:183
bool dofOnBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition: discretization/pq2/fvgridgeometry.hh:239
PQ2HierarchicalFECache< CoordScalar, Scalar, dim > FeCache
export the finite element cache type
Definition: discretization/pq2/fvgridgeometry.hh:171
typename Traits::ScvQuadratureRule ScvQuadratureRule
the quadrature rule type for scvs
Definition: discretization/pq2/fvgridgeometry.hh:177
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition: discretization/pq2/fvgridgeometry.hh:235
void update(const GridView &gridView)
update all geometries (call this after grid adaption)
Definition: discretization/pq2/fvgridgeometry.hh:221
friend LocalView localView(const PQ2FVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition: discretization/pq2/fvgridgeometry.hh:255
typename Traits::ElementQuadratureRule ElementQuadratureRule
the quadrature rule type for elements
Definition: discretization/pq2/fvgridgeometry.hh:181
static constexpr bool enableHybridCVFE
Definition: discretization/pq2/fvgridgeometry.hh:153
std::size_t numBoundaryScvf() const
The total number of boundary sub control volume faces.
Definition: discretization/pq2/fvgridgeometry.hh:213
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/pq2/fvgridgeometry.hh:205
PQ2GridGeometryCache Cache
Definition: discretization/pq2/fvgridgeometry.hh:310
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:186
typename Traits::ScvfQuadratureRule ScvfQuadratureRule
the quadrature rule type for scvfs
Definition: discretization/pq2/fvgridgeometry.hh:179
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: discretization/pq2/fvgridgeometry.hh:165
void update(GridView &&gridView)
update all geometries (call this after grid adaption)
Definition: discretization/pq2/fvgridgeometry.hh:228
typename Traits::template LocalView< ThisType, true > LocalView
export the type of the fv element geometry (the local view type)
Definition: discretization/pq2/fvgridgeometry.hh:161
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:247
static constexpr std::size_t maxNumElementDofs
Definition: discretization/pq2/fvgridgeometry.hh:156
const std::unordered_map< GridIndexType, GridIndexType > & periodicDofMap() const
Returns the map between dofs across periodic boundaries.
Definition: discretization/pq2/fvgridgeometry.hh:251
static constexpr DiscretizationMethod discMethod
Definition: discretization/pq2/fvgridgeometry.hh:151
BasicGridGeometry_t< GV, Traits > BasicGridGeometry
export basic grid geometry type for the alternative constructor
Definition: discretization/pq2/fvgridgeometry.hh:159
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on a periodic boundary.
Definition: discretization/pq2/fvgridgeometry.hh:243
GV GridView
export the grid view type
Definition: discretization/pq2/fvgridgeometry.hh:173
typename PeriodicGridTraits< typename GV::Grid >::SupportsPeriodicity SupportsPeriodicity
export whether the grid(geometry) supports periodicity
Definition: discretization/pq2/fvgridgeometry.hh:175
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: discretization/pq2/fvgridgeometry.hh:163
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: discretization/pq2/fvgridgeometry.hh:217
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition: discretization/pq2/fvgridgeometry.hh:167
Definition: pq2hierarchicalfecache.hh:29
const FiniteElementType & get(const Dune::GeometryType >) const
Get local finite element for given GeometryType.
Definition: pq2hierarchicalfecache.hh:44
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:59
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: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 P2/Q2 hierarchical function spaces.
Quadrature rule traits for discretization schemes.
Definition: quadraturerules.hh:84
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:101
static constexpr std::size_t maxNumElementDofs
Definition: discretization/pq2/fvgridgeometry.hh:112
std::true_type EnableHybridCVFE
Definition: discretization/pq2/fvgridgeometry.hh:108
Definition: discretization/pq2/fvgridgeometry.hh:64
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > DofMapper
Definition: discretization/pq2/fvgridgeometry.hh:65
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:71
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.