14#ifndef DUMUX_DISCRETIZATION_BOX_GRID_FVGEOMETRY_HH
15#define DUMUX_DISCRETIZATION_BOX_GRID_FVGEOMETRY_HH
18#include <unordered_map>
22#include <dune/localfunctions/lagrange/lagrangelfecache.hh>
39template<
class GV,
class T>
51template<
class Gr
idView,
class ScvRule = Dumux::QuadratureRules::M
idpo
intQuadrature,
class ScvfRule = Dumux::QuadratureRules::M
idpo
intQuadrature>
60template<
class Gr
idView,
class MapperTraits = DefaultMapperTraits<Gr
idView>,
class QuadratureTraits = BoxQuadratureTraits<Gr
idView>>
62:
public MapperTraits,
public QuadratureTraits
67 template<
class Gr
idGeometry,
bool enableCache>
79 bool enableGridGeometryCache =
false,
89template<
class Scalar,
class GV,
class Traits>
98 using Element =
typename GV::template Codim<0>::Entity;
99 using CoordScalar =
typename GV::ctype;
100 static const int dim = GV::dimension;
101 static const int dimWorld = GV::dimensionworld;
121 using FeCache = Dune::LagrangeLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
135 , periodicGridTraits_(this->gridView().grid())
148 {
return this->vertexMapper(); }
161 {
return numBoundaryScvf_; }
165 {
return this->vertexMapper().size(); }
171 ParentType::update(gridView);
178 ParentType::update(std::move(gridView));
188 {
return boundaryDofIndices_[dofIdx]; }
192 {
return periodicDofMap_.count(dofIdx); }
196 {
return periodicDofMap_.at(dofIdx); }
200 {
return periodicDofMap_; }
204 {
return { gg.cache_ }; }
208 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_;
261 using GeometryHelper =
typename Cache::GeometryHelper;
267 const auto numElements = this->gridView().size(0);
268 cache_.scvs_.resize(numElements);
269 cache_.scvfs_.resize(numElements);
270 cache_.hasBoundaryScvf_.resize(numElements,
false);
272 boundaryDofIndices_.assign(numDofs(),
false);
276 numBoundaryScvf_ = 0;
278 for (
const auto& element : elements(this->gridView()))
281 const auto eIdx = this->elementMapper().index(element);
284 numScv_ += element.subEntities(dim);
285 numScvf_ += element.subEntities(dim-1);
288 auto elementGeometry = element.geometry();
289 const auto refElement = referenceElement(elementGeometry);
292 GeometryHelper geometryHelper(elementGeometry);
295 cache_.scvs_[eIdx].resize(elementGeometry.corners());
296 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
298 const auto dofIdxGlobal = this->vertexMapper().subIndex(element, scvLocalIdx, dim);
301 geometryHelper.getScvCorners(scvLocalIdx),
309 LocalIndexType scvfLocalIdx = 0;
310 cache_.scvfs_[eIdx].resize(element.subEntities(dim-1));
311 for (; scvfLocalIdx < element.subEntities(dim-1); ++scvfLocalIdx)
314 std::array<LocalIndexType, 2> localScvIndices{{
315 static_cast<LocalIndexType
>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
316 static_cast<LocalIndexType
>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))
319 const auto& corners = geometryHelper.getScvfCorners(scvfLocalIdx);
322 geometryHelper.normal(corners, localScvIndices),
325 std::move(localScvIndices)
330 for (
const auto& intersection : intersections(this->gridView(), element))
332 if (intersection.boundary() && !intersection.neighbor())
334 const auto isGeometry = intersection.geometry();
335 cache_.hasBoundaryScvf_[eIdx] =
true;
338 numScvf_ += isGeometry.corners();
339 numBoundaryScvf_ += isGeometry.corners();
341 for (
unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < isGeometry.corners(); ++isScvfLocalIdx)
344 const LocalIndexType insideScvIdx =
static_cast<LocalIndexType
>(refElement.subEntity(intersection.indexInInside(), 1, isScvfLocalIdx, dim));
345 std::array<LocalIndexType, 2> localScvIndices{{insideScvIdx, insideScvIdx}};
347 cache_.scvfs_[eIdx].emplace_back(
348 geometryHelper.getBoundaryScvfCorners(intersection.indexInInside(), isScvfLocalIdx),
349 intersection.centerUnitOuterNormal(),
353 std::move(localScvIndices)
356 cache_.scvfBoundaryGeometryKeys_[eIdx].emplace_back(std::array<LocalIndexType, 2>{{
357 static_cast<LocalIndexType
>(intersection.indexInInside()),
358 static_cast<LocalIndexType
>(isScvfLocalIdx)
367 const auto fIdx = intersection.indexInInside();
368 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
369 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
371 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
372 const auto vIdxGlobal = this->vertexMapper().subIndex(element, vIdx, dim);
373 boundaryDofIndices_[vIdxGlobal] =
true;
378 else if (periodicGridTraits_.isPeriodic(intersection))
383 const auto fIdx = intersection.indexInInside();
384 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
385 const auto eps = 1e-7*(elementGeometry.corner(1) - elementGeometry.corner(0)).two_norm();
386 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
388 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
389 const auto vIdxGlobal = this->vertexMapper().subIndex(element, vIdx, dim);
390 const auto vPos = elementGeometry.corner(vIdx);
392 const auto& outside = intersection.outside();
393 const auto outsideGeometry = outside.geometry();
394 for (
const auto& isOutside : intersections(this->gridView(), outside))
397 if (periodicGridTraits_.isPeriodic(isOutside))
399 const auto fIdxOutside = isOutside.indexInInside();
400 const auto numFaceVertsOutside = refElement.size(fIdxOutside, 1, dim);
401 for (
int localVIdxOutside = 0; localVIdxOutside < numFaceVertsOutside; ++localVIdxOutside)
403 const auto vIdxOutside = refElement.subEntity(fIdxOutside, 1, localVIdxOutside, dim);
404 const auto vPosOutside = outsideGeometry.corner(vIdxOutside);
405 const auto shift = std::abs((this->bBoxMax()-this->bBoxMin())*intersection.centerUnitOuterNormal());
406 if (std::abs((vPosOutside-vPos).two_norm() - shift) < eps)
407 periodicDofMap_[vIdxGlobal] = this->vertexMapper().subIndex(outside, vIdxOutside, dim);
417 if (this->isPeriodic() && this->gridView().comm().size() > 1)
418 DUNE_THROW(Dune::NotImplemented,
"Periodic boundaries for box method for parallel simulations!");
421 const FeCache feCache_;
424 std::size_t numScvf_;
425 std::size_t numBoundaryScvf_;
428 std::vector<bool> boundaryDofIndices_;
431 std::unordered_map<GridIndexType, GridIndexType> periodicDofMap_;
445template<
class Scalar,
class GV,
class Traits>
453 static const int dim = GV::dimension;
454 static const int dimWorld = GV::dimensionworld;
456 using Element =
typename GV::template Codim<0>::Entity;
457 using CoordScalar =
typename GV::ctype;
477 using FeCache = Dune::LagrangeLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
491 , periodicGridTraits_(this->gridView().grid())
504 {
return this->vertexMapper(); }
517 {
return numBoundaryScvf_; }
521 {
return this->vertexMapper().size(); }
527 ParentType::update(gridView);
534 ParentType::update(std::move(gridView));
544 {
return boundaryDofIndices_[dofIdx]; }
548 {
return periodicDofMap_.count(dofIdx); }
552 {
return periodicDofMap_.at(dofIdx); }
556 {
return periodicDofMap_; }
560 {
return { gg.cache_ }; }
564 class BoxGridGeometryCache
575 const BoxFVGridGeometry& gridGeometry()
const
576 {
return *gridGeometry_; }
579 const BoxFVGridGeometry* gridGeometry_;
591 boundaryDofIndices_.assign(numDofs(),
false);
597 numBoundaryScvf_ = 0;
598 for (
const auto& element : elements(this->gridView()))
600 numScv_ += element.subEntities(dim);
601 numScvf_ += element.subEntities(dim-1);
603 const auto elementGeometry = element.geometry();
604 const auto refElement = referenceElement(elementGeometry);
607 for (
const auto& intersection : intersections(this->gridView(), element))
609 if (intersection.boundary() && !intersection.neighbor())
611 const auto isGeometry = intersection.geometry();
612 numScvf_ += isGeometry.corners();
613 numBoundaryScvf_ += isGeometry.corners();
617 const auto fIdx = intersection.indexInInside();
618 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
619 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
621 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
622 const auto vIdxGlobal = this->vertexMapper().subIndex(element, vIdx, dim);
623 boundaryDofIndices_[vIdxGlobal] =
true;
628 else if (periodicGridTraits_.isPeriodic(intersection))
633 const auto fIdx = intersection.indexInInside();
634 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
635 const auto eps = 1e-7*(elementGeometry.corner(1) - elementGeometry.corner(0)).two_norm();
636 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
638 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
639 const auto vIdxGlobal = this->vertexMapper().subIndex(element, vIdx, dim);
640 const auto vPos = elementGeometry.corner(vIdx);
642 const auto& outside = intersection.outside();
643 const auto outsideGeometry = outside.geometry();
644 for (
const auto& isOutside : intersections(this->gridView(), outside))
647 if (periodicGridTraits_.isPeriodic(isOutside))
649 const auto fIdxOutside = isOutside.indexInInside();
650 const auto numFaceVertsOutside = refElement.size(fIdxOutside, 1, dim);
651 for (
int localVIdxOutside = 0; localVIdxOutside < numFaceVertsOutside; ++localVIdxOutside)
653 const auto vIdxOutside = refElement.subEntity(fIdxOutside, 1, localVIdxOutside, dim);
654 const auto vPosOutside = outsideGeometry.corner(vIdxOutside);
655 const auto shift = std::abs((this->bBoxMax()-this->bBoxMin())*intersection.centerUnitOuterNormal());
656 if (std::abs((vPosOutside-vPos).two_norm() - shift) < eps)
657 periodicDofMap_[vIdxGlobal] = this->vertexMapper().subIndex(outside, vIdxOutside, dim);
667 if (this->isPeriodic() && this->gridView().comm().size() > 1)
668 DUNE_THROW(Dune::NotImplemented,
"Periodic boundaries for box method for parallel simulations!");
671 const FeCache feCache_;
676 std::size_t numScvf_;
677 std::size_t numBoundaryScvf_;
680 std::vector<bool> boundaryDofIndices_;
683 std::unordered_map<GridIndexType, GridIndexType> periodicDofMap_;
Base class for grid geometries.
Helper class constructing the dual grid finite volume geometries for the box discretizazion method.
Base class for all grid geometries.
Definition: basegridgeometry.hh:52
typename BaseImplementation::GridView GridView
export the grid view type
Definition: basegridgeometry.hh:60
Base class for the finite volume geometry vector for box models This builds up the sub control volume...
Definition: discretization/box/fvelementgeometry.hh:44
Base class for the finite volume geometry vector for box schemes This builds up the sub control volum...
Definition: discretization/box/fvgridgeometry.hh:448
std::size_t numBoundaryScvf() const
Definition: discretization/box/fvgridgeometry.hh:516
friend LocalView localView(const BoxFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition: discretization/box/fvgridgeometry.hh:559
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on a periodic boundary.
Definition: discretization/box/fvgridgeometry.hh:547
typename Traits::template LocalView< ThisType, false > LocalView
export the type of the fv element geometry (the local view type)
Definition: discretization/box/fvgridgeometry.hh:467
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: discretization/box/fvgridgeometry.hh:471
BoxFVGridGeometry(const GridView &gridView)
Constructor.
Definition: discretization/box/fvgridgeometry.hh:497
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: discretization/box/fvgridgeometry.hh:469
typename Traits::ScvQuadratureRule ScvQuadratureRule
export the scv interpolation point data type
Definition: discretization/box/fvgridgeometry.hh:483
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:551
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition: discretization/box/fvgridgeometry.hh:539
BoxGridGeometryCache Cache
Definition: discretization/box/fvgridgeometry.hh:585
std::size_t numScvf() const
The total number of sun control volume faces.
Definition: discretization/box/fvgridgeometry.hh:511
typename Traits::VertexMapper DofMapper
export dof mapper type
Definition: discretization/box/fvgridgeometry.hh:475
BasicGridGeometry_t< GV, Traits > BasicGridGeometry
export basic grid geometry type for the alternative constructor
Definition: discretization/box/fvgridgeometry.hh:465
bool dofOnBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition: discretization/box/fvgridgeometry.hh:543
typename Traits::ScvfQuadratureRule ScvfQuadratureRule
the quadrature rule type for scvfs
Definition: discretization/box/fvgridgeometry.hh:485
const DofMapper & dofMapper() const
Definition: discretization/box/fvgridgeometry.hh:503
typename PeriodicGridTraits< typename GV::Grid >::SupportsPeriodicity SupportsPeriodicity
export whether the grid(geometry) supports periodicity
Definition: discretization/box/fvgridgeometry.hh:481
void update(GridView &&gridView)
update all fvElementGeometries (call this after grid adaption)
Definition: discretization/box/fvgridgeometry.hh:532
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition: discretization/box/fvgridgeometry.hh:473
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: discretization/box/fvgridgeometry.hh:520
BoxFVGridGeometry(std::shared_ptr< BasicGridGeometry > gg)
Constructor with basic grid geometry used to share state with another grid geometry on the same grid ...
Definition: discretization/box/fvgridgeometry.hh:488
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/box/fvgridgeometry.hh:507
void update(const GridView &gridView)
update all fvElementGeometries (call this after grid adaption)
Definition: discretization/box/fvgridgeometry.hh:525
Dune::LagrangeLocalFiniteElementCache< CoordScalar, Scalar, dim, 1 > FeCache
export the finite element cache type
Definition: discretization/box/fvgridgeometry.hh:477
const std::unordered_map< GridIndexType, GridIndexType > & periodicDofMap() const
Returns the map between dofs across periodic boundaries.
Definition: discretization/box/fvgridgeometry.hh:555
Base class for the finite volume geometry vector for box schemes This builds up the sub control volum...
Definition: discretization/box/fvgridgeometry.hh:92
friend LocalView localView(const BoxFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition: discretization/box/fvgridgeometry.hh:203
BoxGridGeometryCache Cache
Definition: discretization/box/fvgridgeometry.hh:258
void update(const GridView &gridView)
update all fvElementGeometries (call this after grid adaption)
Definition: discretization/box/fvgridgeometry.hh:169
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:195
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: discretization/box/fvgridgeometry.hh:164
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/box/fvgridgeometry.hh:151
BasicGridGeometry_t< GV, Traits > BasicGridGeometry
export basic grid geometry type for the alternative constructor
Definition: discretization/box/fvgridgeometry.hh:109
typename Traits::ScvQuadratureRule ScvQuadratureRule
export the scv interpolation point data type
Definition: discretization/box/fvgridgeometry.hh:127
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition: discretization/box/fvgridgeometry.hh:183
std::size_t numBoundaryScvf() const
Definition: discretization/box/fvgridgeometry.hh:160
typename Traits::ScvfQuadratureRule ScvfQuadratureRule
the quadrature rule type for scvfs
Definition: discretization/box/fvgridgeometry.hh:129
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:147
const std::unordered_map< GridIndexType, GridIndexType > & periodicDofMap() const
Returns the map between dofs across periodic boundaries.
Definition: discretization/box/fvgridgeometry.hh:199
BoxFVGridGeometry(const GridView &gridView)
Constructor.
Definition: discretization/box/fvgridgeometry.hh:141
BoxFVGridGeometry(std::shared_ptr< BasicGridGeometry > gg)
Constructor with basic grid geometry used to share state with another grid geometry on the same grid ...
Definition: discretization/box/fvgridgeometry.hh:132
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition: discretization/box/fvgridgeometry.hh:117
typename PeriodicGridTraits< typename GV::Grid >::SupportsPeriodicity SupportsPeriodicity
export whether the grid(geometry) supports periodicity
Definition: discretization/box/fvgridgeometry.hh:125
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
bool dofOnBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition: discretization/box/fvgridgeometry.hh:187
std::size_t numScvf() const
The total number of sun control volume faces.
Definition: discretization/box/fvgridgeometry.hh:155
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on a periodic boundary.
Definition: discretization/box/fvgridgeometry.hh:191
void update(GridView &&gridView)
update all fvElementGeometries (call this after grid adaption)
Definition: discretization/box/fvgridgeometry.hh:176
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
Base class for the finite volume geometry vector for box schemes This builds up the sub control volum...
Definition: discretization/box/fvgridgeometry.hh:81
Create sub control volumes and sub control volume face geometries.
Definition: boxgeometryhelper.hh:257
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:60
the sub control volume for the box scheme
Definition: discretization/box/subcontrolvolume.hh:58
Defines the default element and vertex mapper types.
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.
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
The available discretization methods in Dumux.
Dune::Std::detected_or_t< Dumux::BoxGeometryHelper< GV, GV::dimension, typename T::SubControlVolume, typename T::SubControlVolumeFace >, SpecifiesGeometryHelper, T > BoxGeometryHelper_t
Definition: discretization/box/fvgridgeometry.hh:44
typename T::GeometryHelper SpecifiesGeometryHelper
Definition: basegridgeometry.hh:30
CVFE< CVFEMethods::PQ1 > Box
Definition: method.hh:98
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.
The default traits for the box finite volume grid geometry Defines the scv and scvf types and the map...
Definition: discretization/box/fvgridgeometry.hh:63
Quadrature rule traits for discretization schemes.
Definition: quadraturerules.hh:84
Structure to define the index types used for grid and local indices.
Definition: indextraits.hh:26
Definition: periodicgridtraits.hh:24