26#ifndef DUMUX_DISCRETIZATION_BOX_GRID_FVGEOMETRY_HH
27#define DUMUX_DISCRETIZATION_BOX_GRID_FVGEOMETRY_HH
30#include <unordered_map>
34#include <dune/localfunctions/lagrange/lagrangelfecache.hh>
54template<
class Gr
idView,
class MapperTraits = DefaultMapperTraits<Gr
idView>>
61 template<
class Gr
idGeometry,
bool enableCache>
73 bool enableGridGeometryCache =
false,
83template<
class Scalar,
class GV,
class Traits>
92 using Element =
typename GV::template Codim<0>::Entity;
93 using CoordScalar =
typename GV::ctype;
94 static const int dim = GV::dimension;
95 static const int dimWorld = GV::dimensionworld;
98 typename Traits::SubControlVolume,
99 typename Traits::SubControlVolumeFace>;
121 using FeCache = Dune::LagrangeLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
149 {
return numBoundaryScvf_; }
175 [[deprecated(
"Will be removed after release 3.6")]]
176 const std::vector<SubControlVolume>&
scvs(GridIndexType eIdx)
const
177 {
return cache_.scvs_[eIdx]; }
180 [[deprecated(
"Will be removed after release 3.6")]]
181 const std::vector<SubControlVolumeFace>&
scvfs(GridIndexType eIdx)
const
182 {
return cache_.scvfs_[eIdx]; }
186 {
return boundaryDofIndices_[dofIdx]; }
190 {
return periodicVertexMap_.count(dofIdx); }
194 {
return periodicVertexMap_.at(dofIdx); }
198 {
return periodicVertexMap_; }
201 [[deprecated(
"Will be removed after release 3.6")]]
203 {
return cache_.hasBoundaryScvf_[eIdx]; }
207 {
return { gg.cache_ }; }
211 class BoxGridGeometryCache
219 const BoxFVGridGeometry& gridGeometry()
const
220 {
return *gridGeometry_; }
223 const std::vector<SubControlVolume>& scvs(GridIndexType eIdx)
const
224 {
return scvs_[eIdx]; }
227 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx)
const
228 {
return scvfs_[eIdx]; }
231 bool hasBoundaryScvf(GridIndexType eIdx)
const
232 {
return hasBoundaryScvf_[eIdx]; }
235 const std::vector<std::array<LocalIndexType, 2>>& scvfBoundaryGeometryKeys(GridIndexType eIdx)
const
236 {
return scvfBoundaryGeometryKeys_.at(eIdx); }
243 hasBoundaryScvf_.clear();
244 scvfBoundaryGeometryKeys_.clear();
247 std::vector<std::vector<SubControlVolume>> scvs_;
248 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
249 std::vector<bool> hasBoundaryScvf_;
250 std::unordered_map<GridIndexType, std::vector<std::array<LocalIndexType, 2>>> scvfBoundaryGeometryKeys_;
252 const BoxFVGridGeometry* gridGeometry_;
265 const auto numElements = this->
gridView().size(0);
266 cache_.scvs_.resize(numElements);
267 cache_.scvfs_.resize(numElements);
268 cache_.hasBoundaryScvf_.resize(numElements,
false);
270 boundaryDofIndices_.assign(
numDofs(),
false);
274 numBoundaryScvf_ = 0;
282 numScv_ +=
element.subEntities(dim);
283 numScvf_ +=
element.subEntities(dim-1);
286 auto elementGeometry =
element.geometry();
287 const auto refElement = referenceElement(elementGeometry);
290 GeometryHelper geometryHelper(elementGeometry);
293 cache_.scvs_[eIdx].resize(elementGeometry.corners());
294 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
307 LocalIndexType scvfLocalIdx = 0;
308 cache_.scvfs_[eIdx].resize(
element.subEntities(dim-1));
309 for (; scvfLocalIdx <
element.subEntities(dim-1); ++scvfLocalIdx)
312 std::vector<LocalIndexType> localScvIndices({
static_cast<LocalIndexType
>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
313 static_cast<LocalIndexType
>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
320 std::move(localScvIndices),
326 for (
const auto& intersection : intersections(this->
gridView(),
element))
328 if (intersection.boundary() && !intersection.neighbor())
330 const auto isGeometry = intersection.geometry();
331 cache_.hasBoundaryScvf_[eIdx] =
true;
334 numScvf_ += isGeometry.corners();
335 numBoundaryScvf_ += isGeometry.corners();
337 for (
unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < isGeometry.corners(); ++isScvfLocalIdx)
340 const LocalIndexType insideScvIdx =
static_cast<LocalIndexType
>(refElement.subEntity(intersection.indexInInside(), 1, isScvfLocalIdx, dim));
341 std::vector<LocalIndexType> localScvIndices = {insideScvIdx, insideScvIdx};
343 cache_.scvfs_[eIdx].emplace_back(
349 std::move(localScvIndices),
353 cache_.scvfBoundaryGeometryKeys_[eIdx].emplace_back(std::array<LocalIndexType, 2>{{
354 static_cast<LocalIndexType
>(intersection.indexInInside()),
355 static_cast<LocalIndexType
>(isScvfLocalIdx)
364 const auto fIdx = intersection.indexInInside();
365 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
366 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
368 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
370 boundaryDofIndices_[vIdxGlobal] =
true;
375 else if (intersection.boundary() && intersection.neighbor())
380 const auto fIdx = intersection.indexInInside();
381 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
382 const auto eps = 1e-7*(elementGeometry.corner(1) - elementGeometry.corner(0)).two_norm();
383 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
385 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
387 const auto vPos = elementGeometry.corner(vIdx);
389 const auto& outside = intersection.outside();
390 const auto outsideGeometry = outside.geometry();
391 for (
const auto& isOutside : intersections(this->
gridView(), outside))
394 if (isOutside.boundary() && isOutside.neighbor())
396 const auto fIdxOutside = isOutside.indexInInside();
397 const auto numFaceVertsOutside = refElement.size(fIdxOutside, 1, dim);
398 for (
int localVIdxOutside = 0; localVIdxOutside < numFaceVertsOutside; ++localVIdxOutside)
400 const auto vIdxOutside = refElement.subEntity(fIdxOutside, 1, localVIdxOutside, dim);
401 const auto vPosOutside = outsideGeometry.corner(vIdxOutside);
402 const auto shift = std::abs((this->
bBoxMax()-this->
bBoxMin())*intersection.centerUnitOuterNormal());
403 if (std::abs((vPosOutside-vPos).two_norm() - shift) < eps)
404 periodicVertexMap_[vIdxGlobal] = this->
vertexMapper().subIndex(outside, vIdxOutside, dim);
415 DUNE_THROW(Dune::NotImplemented,
"Periodic boundaries for box method for parallel simulations!");
418 const FeCache feCache_;
421 std::size_t numScvf_;
422 std::size_t numBoundaryScvf_;
425 std::vector<bool> boundaryDofIndices_;
428 std::unordered_map<GridIndexType, GridIndexType> periodicVertexMap_;
440template<
class Scalar,
class GV,
class Traits>
448 static const int dim = GV::dimension;
449 static const int dimWorld = GV::dimensionworld;
451 using Element =
typename GV::template Codim<0>::Entity;
452 using CoordScalar =
typename GV::ctype;
474 using FeCache = Dune::LagrangeLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
502 {
return numBoundaryScvf_; }
529 {
return boundaryDofIndices_[dofIdx]; }
533 {
return periodicVertexMap_.count(dofIdx); }
537 {
return periodicVertexMap_.at(dofIdx); }
541 {
return periodicVertexMap_; }
545 {
return { gg.cache_ }; }
549 class BoxGridGeometryCache
557 const BoxFVGridGeometry& gridGeometry()
const
558 {
return *gridGeometry_; }
561 const BoxFVGridGeometry* gridGeometry_;
573 boundaryDofIndices_.assign(
numDofs(),
false);
579 numBoundaryScvf_ = 0;
582 numScv_ +=
element.subEntities(dim);
583 numScvf_ +=
element.subEntities(dim-1);
585 const auto elementGeometry =
element.geometry();
586 const auto refElement = referenceElement(elementGeometry);
589 for (
const auto& intersection : intersections(this->
gridView(),
element))
591 if (intersection.boundary() && !intersection.neighbor())
593 const auto isGeometry = intersection.geometry();
594 numScvf_ += isGeometry.corners();
595 numBoundaryScvf_ += isGeometry.corners();
599 const auto fIdx = intersection.indexInInside();
600 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
601 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
603 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
605 boundaryDofIndices_[vIdxGlobal] =
true;
610 else if (intersection.boundary() && intersection.neighbor())
615 const auto fIdx = intersection.indexInInside();
616 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
617 const auto eps = 1e-7*(elementGeometry.corner(1) - elementGeometry.corner(0)).two_norm();
618 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
620 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
622 const auto vPos = elementGeometry.corner(vIdx);
624 const auto& outside = intersection.outside();
625 const auto outsideGeometry = outside.geometry();
626 for (
const auto& isOutside : intersections(this->
gridView(), outside))
629 if (isOutside.boundary() && isOutside.neighbor())
631 const auto fIdxOutside = isOutside.indexInInside();
632 const auto numFaceVertsOutside = refElement.size(fIdxOutside, 1, dim);
633 for (
int localVIdxOutside = 0; localVIdxOutside < numFaceVertsOutside; ++localVIdxOutside)
635 const auto vIdxOutside = refElement.subEntity(fIdxOutside, 1, localVIdxOutside, dim);
636 const auto vPosOutside = outsideGeometry.corner(vIdxOutside);
637 const auto shift = std::abs((this->
bBoxMax()-this->
bBoxMin())*intersection.centerUnitOuterNormal());
638 if (std::abs((vPosOutside-vPos).two_norm() - shift) < eps)
639 periodicVertexMap_[vIdxGlobal] = this->
vertexMapper().subIndex(outside, vIdxOutside, dim);
650 DUNE_THROW(Dune::NotImplemented,
"Periodic boundaries for box method for parallel simulations!");
653 const FeCache feCache_;
658 std::size_t numScvf_;
659 std::size_t numBoundaryScvf_;
662 std::vector<bool> boundaryDofIndices_;
665 std::unordered_map<GridIndexType, GridIndexType> periodicVertexMap_;
Defines the default element and vertex mapper types.
Defines the index types used for grid and local indices.
Helper class constructing the dual grid finite volume geometries for the box discretizazion method.
Base class for grid geometries.
Helper classes to compute the integration elements.
The available discretization methods in Dumux.
BaseGridGeometry(std::shared_ptr< BaseImplementation > impl)
Constructor from a BaseImplementation.
Definition basegridgeometry.hh:81
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::PQ1 > Box
Definition method.hh:83
typename GridView::IndexSet::IndexType GridIndex
Definition indextraits.hh:39
unsigned int LocalIndex
Definition indextraits.hh:40
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 VertexMapper & vertexMapper() const
Returns the mapper for vertices to indices for constant grids.
Definition basegridgeometry.hh:115
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
Create sub control volumes and sub control volume face geometries.
Definition boxgeometryhelper.hh:269
Base class for the finite volume geometry vector for box models This builds up the sub control volume...
Definition discretization/box/fvelementgeometry.hh:53
The default traits for the box finite volume grid geometry Defines the scv and scvf types and the map...
Definition discretization/box/fvgridgeometry.hh:57
BoxSubControlVolume< GridView > SubControlVolume
Definition discretization/box/fvgridgeometry.hh:58
BoxSubControlVolumeFace< GridView > SubControlVolumeFace
Definition discretization/box/fvgridgeometry.hh:59
BoxFVElementGeometry< GridGeometry, enableCache > LocalView
Definition discretization/box/fvgridgeometry.hh:62
Base class for the finite volume geometry vector for box schemes This builds up the sub control volum...
Definition discretization/box/fvgridgeometry.hh:75
GV GridView
export the grid view type
Definition discretization/box/fvgridgeometry.hh:123
const std::vector< SubControlVolume > & scvs(GridIndexType eIdx) const
Get the local scvs for an element.
Definition discretization/box/fvgridgeometry.hh:176
friend LocalView localView(const BoxFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition discretization/box/fvgridgeometry.hh:206
BoxGridGeometryCache Cache
Definition discretization/box/fvgridgeometry.hh:258
const std::vector< SubControlVolumeFace > & scvfs(GridIndexType eIdx) const
Get the local scvfs for an element.
Definition discretization/box/fvgridgeometry.hh:181
const std::unordered_map< GridIndexType, GridIndexType > & periodicVertexMap() const
Returns the map between dofs across periodic boundaries.
Definition discretization/box/fvgridgeometry.hh:197
void update(const GridView &gridView)
update all fvElementGeometries (call this after grid adaption)
Definition discretization/box/fvgridgeometry.hh:157
GridIndexType periodicallyMappedDof(GridIndexType dofIdx) const
The index of the vertex / d.o.f. on the other side of the periodic boundary.
Definition discretization/box/fvgridgeometry.hh:193
bool hasBoundaryScvf(GridIndexType eIdx) const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition discretization/box/fvgridgeometry.hh:202
std::size_t numDofs() const
The total number of degrees of freedom.
Definition discretization/box/fvgridgeometry.hh:152
std::size_t numScv() const
The total number of sub control volumes.
Definition discretization/box/fvgridgeometry.hh:139
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition discretization/box/fvgridgeometry.hh:171
std::size_t numBoundaryScvf() const
Definition discretization/box/fvgridgeometry.hh:148
DiscretizationMethods::Box DiscretizationMethod
export the discretization method this geometry belongs to
Definition discretization/box/fvgridgeometry.hh:107
static constexpr DiscretizationMethod discMethod
Definition discretization/box/fvgridgeometry.hh:108
Dune::LagrangeLocalFiniteElementCache< CoordScalar, Scalar, dim, 1 > FeCache
export the finite element cache type
Definition discretization/box/fvgridgeometry.hh:121
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition discretization/box/fvgridgeometry.hh:115
const DofMapper & dofMapper() const
Definition discretization/box/fvgridgeometry.hh:135
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition discretization/box/fvgridgeometry.hh:117
typename Traits::template LocalView< ThisType, true > LocalView
export the type of the fv element geometry (the local view type)
Definition discretization/box/fvgridgeometry.hh:111
BoxFVGridGeometry(const GridView gridView)
Constructor.
Definition discretization/box/fvgridgeometry.hh:126
bool dofOnBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition discretization/box/fvgridgeometry.hh:185
std::size_t numScvf() const
The total number of sun control volume faces.
Definition discretization/box/fvgridgeometry.hh:143
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on a periodic boundary.
Definition discretization/box/fvgridgeometry.hh:189
void update(GridView &&gridView)
update all fvElementGeometries (call this after grid adaption)
Definition discretization/box/fvgridgeometry.hh:164
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition discretization/box/fvgridgeometry.hh:113
typename Traits::VertexMapper DofMapper
export dof mapper type
Definition discretization/box/fvgridgeometry.hh:119
std::size_t numBoundaryScvf() const
Definition discretization/box/fvgridgeometry.hh:501
friend LocalView localView(const BoxFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition discretization/box/fvgridgeometry.hh:544
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on a periodic boundary.
Definition discretization/box/fvgridgeometry.hh:532
GV GridView
export the grid view type
Definition discretization/box/fvgridgeometry.hh:476
typename Traits::template LocalView< ThisType, false > LocalView
export the type of the fv element geometry (the local view type)
Definition discretization/box/fvgridgeometry.hh:464
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition discretization/box/fvgridgeometry.hh:468
static constexpr DiscretizationMethod discMethod
Definition discretization/box/fvgridgeometry.hh:461
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition discretization/box/fvgridgeometry.hh:466
GridIndexType periodicallyMappedDof(GridIndexType dofIdx) const
The index of the vertex / d.o.f. on the other side of the periodic boundary.
Definition discretization/box/fvgridgeometry.hh:536
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition discretization/box/fvgridgeometry.hh:524
BoxGridGeometryCache Cache
Definition discretization/box/fvgridgeometry.hh:567
std::size_t numScvf() const
The total number of sun control volume faces.
Definition discretization/box/fvgridgeometry.hh:496
typename Traits::VertexMapper DofMapper
export dof mapper type
Definition discretization/box/fvgridgeometry.hh:472
bool dofOnBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition discretization/box/fvgridgeometry.hh:528
BoxFVGridGeometry(const GridView gridView)
Constructor.
Definition discretization/box/fvgridgeometry.hh:479
const DofMapper & dofMapper() const
Definition discretization/box/fvgridgeometry.hh:488
DiscretizationMethods::Box DiscretizationMethod
export the discretization method this geometry belongs to
Definition discretization/box/fvgridgeometry.hh:460
void update(GridView &&gridView)
update all fvElementGeometries (call this after grid adaption)
Definition discretization/box/fvgridgeometry.hh:517
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition discretization/box/fvgridgeometry.hh:470
std::size_t numDofs() const
The total number of degrees of freedom.
Definition discretization/box/fvgridgeometry.hh:505
const std::unordered_map< GridIndexType, GridIndexType > & periodicVertexMap() const
Returns the map between dofs across periodic boundaries.
Definition discretization/box/fvgridgeometry.hh:540
std::size_t numScv() const
The total number of sub control volumes.
Definition discretization/box/fvgridgeometry.hh:492
void update(const GridView &gridView)
update all fvElementGeometries (call this after grid adaption)
Definition discretization/box/fvgridgeometry.hh:510
Dune::LagrangeLocalFiniteElementCache< CoordScalar, Scalar, dim, 1 > FeCache
export the finite element cache type
Definition discretization/box/fvgridgeometry.hh:474
the sub control volume for the box scheme
Definition discretization/box/subcontrolvolume.hh:72
Class for a sub control volume face in the box method, i.e a part of the boundary of a sub control vo...
Definition discretization/box/subcontrolvolumeface.hh:74
Base class for the local finite volume geometry for box models This builds up the sub control volumes...
the sub control volume for the box scheme
Base class for a sub control volume face.