26#ifndef DUMUX_DISCRETIZATION_PQ1BUBBLE_GRID_GEOMETRY_HH
27#define DUMUX_DISCRETIZATION_PQ1BUBBLE_GRID_GEOMETRY_HH
30#include <unordered_map>
32#include <dune/grid/common/mcmgmapper.hh>
52template <
class Gr
idView>
55 using DofMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
63 return [](Dune::GeometryType gt,
int dimgrid) {
64 return (gt.dim() == dimgrid) || (gt.dim() == 0);
75template<
class Gr
idView,
class MapperTraits = PQ1BubbleMapperTraits<Gr
idView>>
82 template<
class Gr
idGeometry,
bool enableCache>
94 bool enableCaching =
true,
104 using Element =
typename GV::template Codim<0>::Entity;
105 using CoordScalar =
typename GV::ctype;
106 static const int dim = GV::dimension;
107 static const int dimWorld = GV::dimensionworld;
110 GV,
typename Traits::SubControlVolume,
typename Traits::SubControlVolumeFace
113 static_assert(dim > 1,
"Only implemented for dim > 1");
138 , dofMapper_(
gridView, Traits::layout())
146 {
return dofMapper_; }
158 {
return numBoundaryScvf_; }
184 {
return boundaryDofIndices_[dofIdx]; }
188 {
return periodicVertexMap_.count(dofIdx); }
192 {
return periodicVertexMap_.at(dofIdx); }
196 {
return periodicVertexMap_; }
200 {
return { gg.cache_ }; }
204 class PQ1BubbleGridGeometryCache
213 {
return *gridGeometry_; }
216 const std::vector<SubControlVolume>& scvs(GridIndexType eIdx)
const
217 {
return scvs_[eIdx]; }
220 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx)
const
221 {
return scvfs_[eIdx]; }
224 bool hasBoundaryScvf(GridIndexType eIdx)
const
225 {
return hasBoundaryScvf_[eIdx]; }
228 const std::vector<std::array<LocalIndexType, 2>>& scvfBoundaryGeometryKeys(GridIndexType eIdx)
const
229 {
return scvfBoundaryGeometryKeys_.at(eIdx); }
236 hasBoundaryScvf_.clear();
237 scvfBoundaryGeometryKeys_.clear();
240 std::vector<std::vector<SubControlVolume>> scvs_;
241 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
242 std::vector<bool> hasBoundaryScvf_;
243 std::unordered_map<GridIndexType, std::vector<std::array<LocalIndexType, 2>>> scvfBoundaryGeometryKeys_;
251 using Cache = PQ1BubbleGridGeometryCache;
257 dofMapper_.update(this->
gridView());
259 auto numElements = this->
gridView().size(0);
260 cache_.scvs_.resize(numElements);
261 cache_.scvfs_.resize(numElements);
262 cache_.hasBoundaryScvf_.resize(numElements,
false);
264 boundaryDofIndices_.assign(
numDofs(),
false);
268 numBoundaryScvf_ = 0;
276 auto elementGeometry =
element.geometry();
277 const auto refElement = referenceElement(elementGeometry);
282 numScv_ += geometryHelper.
numScv();
284 cache_.scvs_[eIdx].resize(geometryHelper.
numScv());
285 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < geometryHelper.
numScv(); ++scvLocalIdx)
289 geometryHelper.
scvVolume(scvLocalIdx, corners),
302 LocalIndexType scvfLocalIdx = 0;
303 for (; scvfLocalIdx < geometryHelper.
numInteriorScvf(); ++scvfLocalIdx)
309 [&](
unsigned int i){
return corners[i]; }
315 geometryHelper.
normal(corners, scvPair),
323 for (
const auto& intersection : intersections(this->
gridView(),
element))
325 if (intersection.boundary() && !intersection.neighbor())
327 cache_.hasBoundaryScvf_[eIdx] =
true;
329 const auto localFacetIndex = intersection.indexInInside();
334 for (
unsigned int isScvfLocalIdx = 0; isScvfLocalIdx <
numBoundaryScvf; ++isScvfLocalIdx)
340 Dune::GeometryTypes::cube(dim-1),
341 [&](
unsigned int i){
return corners[i]; }
343 cache_.scvfs_[eIdx].emplace_back(
346 intersection.centerUnitOuterNormal(),
349 typename SubControlVolumeFace::Traits::BoundaryFlag{ intersection }
353 cache_.scvfBoundaryGeometryKeys_[eIdx].emplace_back(std::array<LocalIndexType, 2>{{
354 static_cast<LocalIndexType
>(localFacetIndex),
355 static_cast<LocalIndexType
>(isScvfLocalIdx)
367 const auto vIdx = refElement.subEntity(localFacetIndex, 1, localVIdx, dim);
369 boundaryDofIndices_[vIdxGlobal] =
true;
374 else if (intersection.boundary() && intersection.neighbor())
379 const auto fIdx = intersection.indexInInside();
380 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
381 const auto eps = 1e-7*(elementGeometry.corner(1) - elementGeometry.corner(0)).two_norm();
382 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
384 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
386 const auto vPos = elementGeometry.corner(vIdx);
388 const auto& outside = intersection.outside();
389 const auto outsideGeometry = outside.geometry();
390 for (
const auto& isOutside : intersections(this->
gridView(), outside))
393 if (isOutside.boundary() && isOutside.neighbor())
395 const auto fIdxOutside = isOutside.indexInInside();
396 const auto numFaceVertsOutside = refElement.size(fIdxOutside, 1, dim);
397 for (
int localVIdxOutside = 0; localVIdxOutside < numFaceVertsOutside; ++localVIdxOutside)
399 const auto vIdxOutside = refElement.subEntity(fIdxOutside, 1, localVIdxOutside, dim);
400 const auto vPosOutside = outsideGeometry.corner(vIdxOutside);
401 const auto shift = std::abs((this->
bBoxMax()-this->
bBoxMin())*intersection.centerUnitOuterNormal());
402 if (std::abs((vPosOutside-vPos).two_norm() - shift) < eps)
403 periodicVertexMap_[vIdxGlobal] = this->
dofMapper().subIndex(outside, vIdxOutside, dim);
414 DUNE_THROW(Dune::NotImplemented,
"Periodic boundaries for pq1bubble method for parallel simulations!");
422 std::size_t numScvf_;
423 std::size_t numBoundaryScvf_;
426 std::vector<bool> boundaryDofIndices_;
429 std::unordered_map<GridIndexType, GridIndexType> periodicVertexMap_;
Defines the default element and vertex mapper types.
Defines the index types used for grid and local indices.
Base class for grid geometries.
Helper classes to compute the integration elements.
The available discretization methods in Dumux.
A finite element cache for P1/Q1 function with bubble.
Compute the center point of a convex polytope geometry or a random-access container of corner points.
Compute the volume of several common geometry types.
auto convexPolytopeVolume(Dune::GeometryType type, const CornerF &c)
Compute the volume of several common geometry types.
Definition: volume.hh:53
Corners::value_type center(const Corners &corners)
The center of a given list of corners.
Definition: center.hh:36
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:251
CVFE< CVFEMethods::PQ1Bubble > PQ1Bubble
Definition: method.hh:97
Definition: defaultmappertraits.hh:35
Structure to define the index types used for grid and local indices.
Definition: indextraits.hh:38
Base class for all grid geometries.
Definition: basegridgeometry.hh:61
const ElementMapper & elementMapper() const
Returns the mapper for elements to indices for constant grids.
Definition: basegridgeometry.hh:121
void setPeriodic(bool value=true)
Set the periodicity of the grid geometry.
Definition: basegridgeometry.hh:178
const GlobalCoordinate & bBoxMax() const
The coordinate of the corner of the GridView's bounding box with the largest values.
Definition: basegridgeometry.hh:165
Element element(GridIndexType eIdx) const
Get an element from a global element index.
Definition: basegridgeometry.hh:151
const GridView & gridView() const
Return the gridView this grid geometry object lives on.
Definition: basegridgeometry.hh:109
void update(const GridView &gridView)
Update all fvElementGeometries (call this after grid adaption)
Definition: basegridgeometry.hh:97
const GlobalCoordinate & bBoxMin() const
The coordinate of the corner of the GridView's bounding box with the smallest values.
Definition: basegridgeometry.hh:158
bool isPeriodic() const
Returns if the grid geometry is periodic (at all)
Definition: basegridgeometry.hh:171
Base class for the finite volume geometry vector for pq1bubble models This builds up the sub control ...
Definition: discretization/pq1bubble/fvelementgeometry.hh:52
Definition: discretization/pq1bubble/fvgridgeometry.hh:54
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > DofMapper
Definition: discretization/pq1bubble/fvgridgeometry.hh:55
static Dune::MCMGLayout layout()
layout for elements and vertices
Definition: discretization/pq1bubble/fvgridgeometry.hh:61
The default traits for the pq1bubble finite volume grid geometry Defines the scv and scvf types and t...
Definition: discretization/pq1bubble/fvgridgeometry.hh:78
Base class for the finite volume geometry vector for pq1bubble schemes This builds up the sub control...
Definition: discretization/pq1bubble/fvgridgeometry.hh:98
void update(const GridView &gridView)
update all geometries (call this after grid adaption)
Definition: discretization/pq1bubble/fvgridgeometry.hh:165
friend LocalView localView(const PQ1BubbleFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition: discretization/pq1bubble/fvgridgeometry.hh:199
PQ1BubbleGridGeometryCache Cache
Definition: discretization/pq1bubble/fvgridgeometry.hh:251
static constexpr DiscretizationMethod discMethod
Definition: discretization/pq1bubble/fvgridgeometry.hh:118
std::size_t numBoundaryScvf() const
The total number of boundary sub control volume faces.
Definition: discretization/pq1bubble/fvgridgeometry.hh:157
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/pq1bubble/fvgridgeometry.hh:149
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/pq1bubble/fvgridgeometry.hh:153
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition: discretization/pq1bubble/fvgridgeometry.hh:179
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:191
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition: discretization/pq1bubble/fvgridgeometry.hh:127
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: discretization/pq1bubble/fvgridgeometry.hh:125
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: discretization/pq1bubble/fvgridgeometry.hh:161
const std::unordered_map< GridIndexType, GridIndexType > & periodicVertexMap() const
Returns the map between dofs across periodic boundaries.
Definition: discretization/pq1bubble/fvgridgeometry.hh:195
bool dofOnBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition: discretization/pq1bubble/fvgridgeometry.hh:183
typename Traits::DofMapper DofMapper
export dof mapper type
Definition: discretization/pq1bubble/fvgridgeometry.hh:129
const DofMapper & dofMapper() const
The dofMapper.
Definition: discretization/pq1bubble/fvgridgeometry.hh:145
GV GridView
export the grid view type
Definition: discretization/pq1bubble/fvgridgeometry.hh:133
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on a periodic boundary.
Definition: discretization/pq1bubble/fvgridgeometry.hh:187
typename Traits::template LocalView< ThisType, true > LocalView
export the type of the fv element geometry (the local view type)
Definition: discretization/pq1bubble/fvgridgeometry.hh:121
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: discretization/pq1bubble/fvgridgeometry.hh:123
PQ1BubbleFVGridGeometry(const GridView gridView)
Constructor.
Definition: discretization/pq1bubble/fvgridgeometry.hh:136
void update(GridView &&gridView)
update all geometries (call this after grid adaption)
Definition: discretization/pq1bubble/fvgridgeometry.hh:172
Dumux::PQ1BubbleFECache< CoordScalar, Scalar, dim > FeCache
export the finite element cache type
Definition: discretization/pq1bubble/fvgridgeometry.hh:131
A class to create sub control volume and sub control volume face geometries per element.
Definition: discretization/pq1bubble/geometryhelper.hh:178
bool isOverlappingScvf(unsigned int localScvfIndex) const
Definition: discretization/pq1bubble/geometryhelper.hh:413
auto dofIndex(const DofMapper &dofMapper, const Element &element, unsigned int localScvIdx) const
Definition: discretization/pq1bubble/geometryhelper.hh:375
std::size_t numScv() const
number of sub control volumes (number of codim-1 entities)
Definition: discretization/pq1bubble/geometryhelper.hh:355
std::size_t numBoundaryScvf(unsigned int localFacetIndex) const
number of boundary sub control volume faces for face localFacetIndex
Definition: discretization/pq1bubble/geometryhelper.hh:349
std::size_t numInteriorScvf() const
number of interior sub control volume faces
Definition: discretization/pq1bubble/geometryhelper.hh:343
ScvfCornerStorage getBoundaryScvfCorners(unsigned int localFacetIndex, unsigned int indexInFacet) const
Create the sub control volume face geometries on the boundary.
Definition: discretization/pq1bubble/geometryhelper.hh:300
GlobalPosition dofPosition(unsigned int localScvIdx) const
Definition: discretization/pq1bubble/geometryhelper.hh:383
std::array< LocalIndexType, 2 > getScvPairForScvf(unsigned int localScvfIndex) const
Definition: discretization/pq1bubble/geometryhelper.hh:391
Dune::GeometryType getInteriorScvfGeometryType(unsigned int localScvfIdx) const
Definition: discretization/pq1bubble/geometryhelper.hh:290
bool isOverlappingScv(unsigned int localScvIndex) const
Definition: discretization/pq1bubble/geometryhelper.hh:421
Scalar scvVolume(unsigned int localScvIdx, const ScvCornerStorage &p) const
get scv volume
Definition: discretization/pq1bubble/geometryhelper.hh:361
ScvfCornerStorage getScvfCorners(unsigned int localScvfIdx) const
Create a vector with the corners of sub control volume faces.
Definition: discretization/pq1bubble/geometryhelper.hh:254
std::array< LocalIndexType, 2 > getScvPairForBoundaryScvf(unsigned int localFacetIndex, unsigned int localIsScvfIndex) const
Definition: discretization/pq1bubble/geometryhelper.hh:406
GlobalPosition normal(const ScvfCornerStorage &p, const std::array< LocalIndexType, 2 > &scvPair)
Definition: discretization/pq1bubble/geometryhelper.hh:307
ScvCornerStorage getScvCorners(unsigned int localScvIdx) const
Create a vector with the scv corners.
Definition: discretization/pq1bubble/geometryhelper.hh:198
Definition: pq1bubblefecache.hh:41
the sub control volume for the pq1bubble scheme
Definition: discretization/pq1bubble/subcontrolvolume.hh:68
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:72
Base class for the local finite volume geometry for the pq1bubble method This builds up the sub contr...
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 cvfe discretizazion method.