26#ifndef DUMUX_DISCRETIZATION_BOX_GRID_FVGEOMETRY_HH
27#define DUMUX_DISCRETIZATION_BOX_GRID_FVGEOMETRY_HH
29#include <unordered_map>
31#include <dune/geometry/referenceelements.hh>
32#include <dune/localfunctions/lagrange/pqkfactory.hh>
51template<
class Gr
idView,
class MapperTraits = DefaultMapperTraits<Gr
idView>>
58 template<
class Gr
idGeometry,
bool enableCache>
70 bool enableGridGeometryCache =
false,
80template<
class Scalar,
class GV,
class Traits>
89 using Element =
typename GV::template Codim<0>::Entity;
90 using CoordScalar =
typename GV::ctype;
91 static const int dim = GV::dimension;
92 static const int dimWorld = GV::dimensionworld;
94 using ReferenceElements =
typename Dune::ReferenceElements<CoordScalar, dim>;
97 typename Traits::SubControlVolume,
98 typename Traits::SubControlVolumeFace>;
113 using FeCache = Dune::PQkLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
138 {
return numBoundaryScvf_; }
152 auto numElements = this->
gridView().size(0);
153 scvs_.resize(numElements);
154 scvfs_.resize(numElements);
155 hasBoundaryScvf_.resize(numElements,
false);
157 boundaryDofIndices_.assign(
numDofs(),
false);
161 numBoundaryScvf_ = 0;
169 numScv_ +=
element.subEntities(dim);
170 numScvf_ +=
element.subEntities(dim-1);
173 auto elementGeometry =
element.geometry();
174 const auto referenceElement = ReferenceElements::general(elementGeometry.type());
177 GeometryHelper geometryHelper(elementGeometry);
180 scvs_[eIdx].resize(elementGeometry.corners());
181 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
192 LocalIndexType scvfLocalIdx = 0;
193 scvfs_[eIdx].resize(
element.subEntities(dim-1));
194 for (; scvfLocalIdx <
element.subEntities(dim-1); ++scvfLocalIdx)
197 std::vector<LocalIndexType> localScvIndices({
static_cast<LocalIndexType
>(referenceElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
198 static_cast<LocalIndexType
>(referenceElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
204 std::move(localScvIndices),
209 for (
const auto& intersection : intersections(this->
gridView(),
element))
211 if (intersection.boundary() && !intersection.neighbor())
213 const auto isGeometry = intersection.geometry();
214 hasBoundaryScvf_[eIdx] =
true;
217 numScvf_ += isGeometry.corners();
218 numBoundaryScvf_ += isGeometry.corners();
220 for (
unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < isGeometry.corners(); ++isScvfLocalIdx)
223 const LocalIndexType insideScvIdx =
static_cast<LocalIndexType
>(referenceElement.subEntity(intersection.indexInInside(), 1, isScvfLocalIdx, dim));
224 std::vector<LocalIndexType> localScvIndices = {insideScvIdx, insideScvIdx};
226 scvfs_[eIdx].emplace_back(geometryHelper,
231 std::move(localScvIndices),
240 const auto fIdx = intersection.indexInInside();
241 const auto numFaceVerts = referenceElement.size(fIdx, 1, dim);
242 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
244 const auto vIdx = referenceElement.subEntity(fIdx, 1, localVIdx, dim);
246 boundaryDofIndices_[vIdxGlobal] =
true;
251 else if (intersection.boundary() && intersection.neighbor())
256 const auto fIdx = intersection.indexInInside();
257 const auto numFaceVerts = referenceElement.size(fIdx, 1, dim);
258 const auto eps = 1e-7*(elementGeometry.corner(1) - elementGeometry.corner(0)).two_norm();
259 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
261 const auto vIdx = referenceElement.subEntity(fIdx, 1, localVIdx, dim);
263 const auto vPos = elementGeometry.corner(vIdx);
265 const auto& outside = intersection.outside();
266 const auto outsideGeometry = outside.geometry();
267 for (
const auto& isOutside : intersections(this->
gridView(), outside))
270 if (isOutside.boundary() && isOutside.neighbor())
272 const auto fIdxOutside = isOutside.indexInInside();
273 const auto numFaceVertsOutside = referenceElement.size(fIdxOutside, 1, dim);
274 for (
int localVIdxOutside = 0; localVIdxOutside < numFaceVertsOutside; ++localVIdxOutside)
276 const auto vIdxOutside = referenceElement.subEntity(fIdxOutside, 1, localVIdxOutside, dim);
277 const auto vPosOutside = outsideGeometry.corner(vIdxOutside);
278 const auto shift = std::abs((this->
bBoxMax()-this->
bBoxMin())*intersection.centerUnitOuterNormal());
279 if (std::abs((vPosOutside-vPos).two_norm() - shift) < eps)
280 periodicVertexMap_[vIdxGlobal] = this->
vertexMapper().subIndex(outside, vIdxOutside, dim);
291 DUNE_THROW(Dune::NotImplemented,
"Periodic boundaries for box method for parallel simulations!");
299 const std::vector<SubControlVolume>&
scvs(GridIndexType eIdx)
const
300 {
return scvs_[eIdx]; }
303 const std::vector<SubControlVolumeFace>&
scvfs(GridIndexType eIdx)
const
304 {
return scvfs_[eIdx]; }
308 {
return boundaryDofIndices_[dofIdx]; }
312 {
return periodicVertexMap_.count(dofIdx); }
316 {
return periodicVertexMap_.at(dofIdx); }
320 {
return periodicVertexMap_; }
324 {
return hasBoundaryScvf_[eIdx]; }
328 const FeCache feCache_;
330 std::vector<std::vector<SubControlVolume>> scvs_;
331 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
334 std::size_t numScvf_;
335 std::size_t numBoundaryScvf_;
338 std::vector<bool> boundaryDofIndices_;
339 std::vector<bool> hasBoundaryScvf_;
342 std::unordered_map<GridIndexType, GridIndexType> periodicVertexMap_;
352template<
class Scalar,
class GV,
class Traits>
360 static const int dim = GV::dimension;
361 static const int dimWorld = GV::dimensionworld;
363 using Element =
typename GV::template Codim<0>::Entity;
364 using CoordScalar =
typename GV::ctype;
366 using ReferenceElements =
typename Dune::ReferenceElements<CoordScalar, dim>;
381 using FeCache = Dune::PQkLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
406 {
return numBoundaryScvf_; }
417 boundaryDofIndices_.assign(
numDofs(),
false);
423 numBoundaryScvf_ = 0;
426 numScv_ +=
element.subEntities(dim);
427 numScvf_ +=
element.subEntities(dim-1);
429 const auto elementGeometry =
element.geometry();
430 const auto referenceElement = ReferenceElements::general(elementGeometry.type());
433 for (
const auto& intersection : intersections(this->
gridView(),
element))
435 if (intersection.boundary() && !intersection.neighbor())
437 const auto isGeometry = intersection.geometry();
438 numScvf_ += isGeometry.corners();
439 numBoundaryScvf_ += isGeometry.corners();
443 const auto fIdx = intersection.indexInInside();
444 const auto numFaceVerts = referenceElement.size(fIdx, 1, dim);
445 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
447 const auto vIdx = referenceElement.subEntity(fIdx, 1, localVIdx, dim);
449 boundaryDofIndices_[vIdxGlobal] =
true;
454 else if (intersection.boundary() && intersection.neighbor())
459 const auto fIdx = intersection.indexInInside();
460 const auto numFaceVerts = referenceElement.size(fIdx, 1, dim);
461 const auto eps = 1e-7*(elementGeometry.corner(1) - elementGeometry.corner(0)).two_norm();
462 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
464 const auto vIdx = referenceElement.subEntity(fIdx, 1, localVIdx, dim);
466 const auto vPos = elementGeometry.corner(vIdx);
468 const auto& outside = intersection.outside();
469 const auto outsideGeometry = outside.geometry();
470 for (
const auto& isOutside : intersections(this->
gridView(), outside))
473 if (isOutside.boundary() && isOutside.neighbor())
475 const auto fIdxOutside = isOutside.indexInInside();
476 const auto numFaceVertsOutside = referenceElement.size(fIdxOutside, 1, dim);
477 for (
int localVIdxOutside = 0; localVIdxOutside < numFaceVertsOutside; ++localVIdxOutside)
479 const auto vIdxOutside = referenceElement.subEntity(fIdxOutside, 1, localVIdxOutside, dim);
480 const auto vPosOutside = outsideGeometry.corner(vIdxOutside);
481 const auto shift = std::abs((this->
bBoxMax()-this->
bBoxMin())*intersection.centerUnitOuterNormal());
482 if (std::abs((vPosOutside-vPos).two_norm() - shift) < eps)
483 periodicVertexMap_[vIdxGlobal] = this->
vertexMapper().subIndex(outside, vIdxOutside, dim);
494 DUNE_THROW(Dune::NotImplemented,
"Periodic boundaries for box method for parallel simulations!");
503 {
return boundaryDofIndices_[dofIdx]; }
507 {
return periodicVertexMap_.count(dofIdx); }
511 {
return periodicVertexMap_.at(dofIdx); }
515 {
return periodicVertexMap_; }
519 const FeCache feCache_;
524 std::size_t numScvf_;
525 std::size_t numBoundaryScvf_;
528 std::vector<bool> boundaryDofIndices_;
531 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.
The available discretization methods in Dumux.
Base class for grid geometries.
BaseGridGeometry(const GridView &gridView)
Constructor computes the bouding box of the entire domain, for e.g. setting boundary conditions.
Definition basegridgeometry.hh:77
DiscretizationMethod
The available discretization methods in Dumux.
Definition method.hh:37
@ box
Definition method.hh:38
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:119
void setPeriodic(bool value=true)
Set the periodicity of the grid geometry.
Definition basegridgeometry.hh:189
const GlobalCoordinate & bBoxMax() const
The coordinate of the corner of the GridView's bounding box with the largest values.
Definition basegridgeometry.hh:177
Element element(GridIndexType eIdx) const
Get an element from a global element index.
Definition basegridgeometry.hh:163
const VertexMapper & vertexMapper() const
Returns the mapper for vertices to indices for constant grids.
Definition basegridgeometry.hh:113
const GridView & gridView() const
Return the gridView this grid geometry object lives on.
Definition basegridgeometry.hh:107
void update()
Update all fvElementGeometries (do this again after grid adaption).
Definition basegridgeometry.hh:90
const GlobalCoordinate & bBoxMin() const
The coordinate of the corner of the GridView's bounding box with the smallest values.
Definition basegridgeometry.hh:170
bool isPeriodic() const
Returns if the grid geometry is periodic (at all).
Definition basegridgeometry.hh:183
Create sub control volumes and sub control volume face geometries.
Definition boxgeometryhelper.hh:37
Base class for the finite volume geometry vector for box models This builds up the sub control volume...
Definition discretization/box/fvelementgeometry.hh:48
The default traits for the box finite volume grid geometry Defines the scv and scvf types and the map...
Definition discretization/box/fvgridgeometry.hh:54
BoxSubControlVolume< GridView > SubControlVolume
Definition discretization/box/fvgridgeometry.hh:55
BoxSubControlVolumeFace< GridView > SubControlVolumeFace
Definition discretization/box/fvgridgeometry.hh:56
BoxFVElementGeometry< GridGeometry, enableCache > LocalView
Definition discretization/box/fvgridgeometry.hh:59
Base class for the finite volume geometry vector for box schemes This builds up the sub control volum...
Definition discretization/box/fvgridgeometry.hh:72
GV GridView
export the grid view type
Definition discretization/box/fvgridgeometry.hh:115
const std::vector< SubControlVolume > & scvs(GridIndexType eIdx) const
Get the local scvs for an element.
Definition discretization/box/fvgridgeometry.hh:299
Dune::PQkLocalFiniteElementCache< CoordScalar, Scalar, dim, 1 > FeCache
export the finite element cache type
Definition discretization/box/fvgridgeometry.hh:113
const std::vector< SubControlVolumeFace > & scvfs(GridIndexType eIdx) const
Get the local scvfs for an element.
Definition discretization/box/fvgridgeometry.hh:303
const std::unordered_map< GridIndexType, GridIndexType > & periodicVertexMap() const
Returns the map between dofs across periodic boundaries.
Definition discretization/box/fvgridgeometry.hh:319
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:315
bool hasBoundaryScvf(GridIndexType eIdx) const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition discretization/box/fvgridgeometry.hh:323
std::size_t numDofs() const
The total number of degrees of freedom.
Definition discretization/box/fvgridgeometry.hh:141
std::size_t numScv() const
The total number of sub control volumes.
Definition discretization/box/fvgridgeometry.hh:128
void update()
update all fvElementGeometries (do this again after grid adaption)
Definition discretization/box/fvgridgeometry.hh:145
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition discretization/box/fvgridgeometry.hh:295
std::size_t numBoundaryScvf() const
Definition discretization/box/fvgridgeometry.hh:137
static constexpr DiscretizationMethod discMethod
export discretization method
Definition discretization/box/fvgridgeometry.hh:102
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition discretization/box/fvgridgeometry.hh:109
const DofMapper & dofMapper() const
Definition discretization/box/fvgridgeometry.hh:124
typename Traits::template LocalView< ThisType, true > LocalView
export the type of the fv element geometry (the local view type)
Definition discretization/box/fvgridgeometry.hh:105
BoxFVGridGeometry(const GridView gridView)
Constructor.
Definition discretization/box/fvgridgeometry.hh:118
bool dofOnBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition discretization/box/fvgridgeometry.hh:307
std::size_t numScvf() const
The total number of sun control volume faces.
Definition discretization/box/fvgridgeometry.hh:132
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on a periodic boundary.
Definition discretization/box/fvgridgeometry.hh:311
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition discretization/box/fvgridgeometry.hh:107
typename Traits::VertexMapper DofMapper
export dof mapper type
Definition discretization/box/fvgridgeometry.hh:111
std::size_t numBoundaryScvf() const
Definition discretization/box/fvgridgeometry.hh:405
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on a periodic boundary.
Definition discretization/box/fvgridgeometry.hh:506
GV GridView
export the grid view type
Definition discretization/box/fvgridgeometry.hh:383
typename Traits::template LocalView< ThisType, false > LocalView
export the type of the fv element geometry (the local view type)
Definition discretization/box/fvgridgeometry.hh:373
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition discretization/box/fvgridgeometry.hh:377
void update()
update all fvElementGeometries (do this again after grid adaption)
Definition discretization/box/fvgridgeometry.hh:413
static constexpr DiscretizationMethod discMethod
export discretization method
Definition discretization/box/fvgridgeometry.hh:370
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition discretization/box/fvgridgeometry.hh:375
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:510
Dune::PQkLocalFiniteElementCache< CoordScalar, Scalar, dim, 1 > FeCache
export the finite element cache type
Definition discretization/box/fvgridgeometry.hh:381
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition discretization/box/fvgridgeometry.hh:498
std::size_t numScvf() const
The total number of sun control volume faces.
Definition discretization/box/fvgridgeometry.hh:400
typename Traits::VertexMapper DofMapper
export dof mapper type
Definition discretization/box/fvgridgeometry.hh:379
bool dofOnBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition discretization/box/fvgridgeometry.hh:502
BoxFVGridGeometry(const GridView gridView)
Constructor.
Definition discretization/box/fvgridgeometry.hh:386
const DofMapper & dofMapper() const
Definition discretization/box/fvgridgeometry.hh:392
std::size_t numDofs() const
The total number of degrees of freedom.
Definition discretization/box/fvgridgeometry.hh:409
const std::unordered_map< GridIndexType, GridIndexType > & periodicVertexMap() const
Returns the map between dofs across periodic boundaries.
Definition discretization/box/fvgridgeometry.hh:514
std::size_t numScv() const
The total number of sub control volumes.
Definition discretization/box/fvgridgeometry.hh:396
the sub control volume for the box scheme
Definition discretization/box/subcontrolvolume.hh:88
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:93
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.