26#ifndef DUMUX_DISCRETIZATION_BOX_GRID_FVGEOMETRY_HH
27#define DUMUX_DISCRETIZATION_BOX_GRID_FVGEOMETRY_HH
30#include <unordered_map>
32#include <dune/localfunctions/lagrange/lagrangelfecache.hh>
52template<
class Gr
idView,
class MapperTraits = DefaultMapperTraits<Gr
idView>>
59 template<
class Gr
idGeometry,
bool enableCache>
71 bool enableGridGeometryCache =
false,
81template<
class Scalar,
class GV,
class Traits>
90 using Element =
typename GV::template Codim<0>::Entity;
91 using CoordScalar =
typename GV::ctype;
92 static const int dim = GV::dimension;
93 static const int dimWorld = GV::dimensionworld;
96 typename Traits::SubControlVolume,
97 typename Traits::SubControlVolumeFace>;
115 using FeCache = Dune::LagrangeLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
129 {
return this->vertexMapper(); }
142 {
return numBoundaryScvf_; }
146 {
return this->vertexMapper().size(); }
149 [[deprecated(
"Use update(gridView) instead! Will be removed after release 3.5.")]]
152 ParentType::update();
159 ParentType::update(gridView);
166 ParentType::update(std::move(gridView));
175 const std::vector<SubControlVolume>&
scvs(GridIndexType eIdx)
const
176 {
return scvs_[eIdx]; }
179 const std::vector<SubControlVolumeFace>&
scvfs(GridIndexType eIdx)
const
180 {
return scvfs_[eIdx]; }
184 {
return boundaryDofIndices_[dofIdx]; }
188 {
return periodicVertexMap_.count(dofIdx); }
192 {
return periodicVertexMap_.at(dofIdx); }
196 {
return periodicVertexMap_; }
200 {
return hasBoundaryScvf_[eIdx]; }
208 auto numElements = this->gridView().size(0);
209 scvs_.resize(numElements);
210 scvfs_.resize(numElements);
211 hasBoundaryScvf_.resize(numElements,
false);
213 boundaryDofIndices_.assign(numDofs(),
false);
217 numBoundaryScvf_ = 0;
219 for (
const auto& element : elements(this->gridView()))
222 auto eIdx = this->elementMapper().index(element);
225 numScv_ += element.subEntities(dim);
226 numScvf_ += element.subEntities(dim-1);
229 auto elementGeometry = element.geometry();
230 const auto refElement = referenceElement(elementGeometry);
233 GeometryHelper geometryHelper(elementGeometry);
236 scvs_[eIdx].resize(elementGeometry.corners());
237 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
239 const auto dofIdxGlobal = this->vertexMapper().subIndex(element, scvLocalIdx, dim);
241 scvs_[eIdx][scvLocalIdx] = SubControlVolume(geometryHelper,
248 LocalIndexType scvfLocalIdx = 0;
249 scvfs_[eIdx].resize(element.subEntities(dim-1));
250 for (; scvfLocalIdx < element.subEntities(dim-1); ++scvfLocalIdx)
253 std::vector<LocalIndexType> localScvIndices({
static_cast<LocalIndexType
>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
254 static_cast<LocalIndexType
>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
256 scvfs_[eIdx][scvfLocalIdx] = SubControlVolumeFace(geometryHelper,
260 std::move(localScvIndices),
265 for (
const auto& intersection : intersections(this->gridView(), element))
267 if (intersection.boundary() && !intersection.neighbor())
269 const auto isGeometry = intersection.geometry();
270 hasBoundaryScvf_[eIdx] =
true;
273 numScvf_ += isGeometry.corners();
274 numBoundaryScvf_ += isGeometry.corners();
276 for (
unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < isGeometry.corners(); ++isScvfLocalIdx)
279 const LocalIndexType insideScvIdx =
static_cast<LocalIndexType
>(refElement.subEntity(intersection.indexInInside(), 1, isScvfLocalIdx, dim));
280 std::vector<LocalIndexType> localScvIndices = {insideScvIdx, insideScvIdx};
282 scvfs_[eIdx].emplace_back(geometryHelper,
287 std::move(localScvIndices),
296 const auto fIdx = intersection.indexInInside();
297 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
298 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
300 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
301 const auto vIdxGlobal = this->vertexMapper().subIndex(element, vIdx, dim);
302 boundaryDofIndices_[vIdxGlobal] =
true;
307 else if (intersection.boundary() && intersection.neighbor())
312 const auto fIdx = intersection.indexInInside();
313 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
314 const auto eps = 1e-7*(elementGeometry.corner(1) - elementGeometry.corner(0)).two_norm();
315 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
317 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
318 const auto vIdxGlobal = this->vertexMapper().subIndex(element, vIdx, dim);
319 const auto vPos = elementGeometry.corner(vIdx);
321 const auto& outside = intersection.outside();
322 const auto outsideGeometry = outside.geometry();
323 for (
const auto& isOutside : intersections(this->gridView(), outside))
326 if (isOutside.boundary() && isOutside.neighbor())
328 const auto fIdxOutside = isOutside.indexInInside();
329 const auto numFaceVertsOutside = refElement.size(fIdxOutside, 1, dim);
330 for (
int localVIdxOutside = 0; localVIdxOutside < numFaceVertsOutside; ++localVIdxOutside)
332 const auto vIdxOutside = refElement.subEntity(fIdxOutside, 1, localVIdxOutside, dim);
333 const auto vPosOutside = outsideGeometry.corner(vIdxOutside);
334 const auto shift = std::abs((this->bBoxMax()-this->bBoxMin())*intersection.centerUnitOuterNormal());
335 if (std::abs((vPosOutside-vPos).two_norm() - shift) < eps)
336 periodicVertexMap_[vIdxGlobal] = this->vertexMapper().subIndex(outside, vIdxOutside, dim);
346 if (this->isPeriodic() && this->gridView().comm().size() > 1)
347 DUNE_THROW(Dune::NotImplemented,
"Periodic boundaries for box method for parallel simulations!");
350 const FeCache feCache_;
352 std::vector<std::vector<SubControlVolume>> scvs_;
353 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
356 std::size_t numScvf_;
357 std::size_t numBoundaryScvf_;
360 std::vector<bool> boundaryDofIndices_;
361 std::vector<bool> hasBoundaryScvf_;
364 std::unordered_map<GridIndexType, GridIndexType> periodicVertexMap_;
374template<
class Scalar,
class GV,
class Traits>
382 static const int dim = GV::dimension;
383 static const int dimWorld = GV::dimensionworld;
385 using Element =
typename GV::template Codim<0>::Entity;
386 using CoordScalar =
typename GV::ctype;
404 using FeCache = Dune::LagrangeLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
418 {
return this->vertexMapper(); }
431 {
return numBoundaryScvf_; }
435 {
return this->vertexMapper().size(); }
438 [[deprecated(
"Use update(gridView) instead! Will be removed after release 3.5.")]]
441 ParentType::update();
448 ParentType::update(gridView);
455 ParentType::update(std::move(gridView));
465 {
return boundaryDofIndices_[dofIdx]; }
469 {
return periodicVertexMap_.count(dofIdx); }
473 {
return periodicVertexMap_.at(dofIdx); }
477 {
return periodicVertexMap_; }
483 boundaryDofIndices_.assign(numDofs(),
false);
489 numBoundaryScvf_ = 0;
490 for (
const auto& element : elements(this->gridView()))
492 numScv_ += element.subEntities(dim);
493 numScvf_ += element.subEntities(dim-1);
495 const auto elementGeometry = element.geometry();
496 const auto refElement = referenceElement(elementGeometry);
499 for (
const auto& intersection : intersections(this->gridView(), element))
501 if (intersection.boundary() && !intersection.neighbor())
503 const auto isGeometry = intersection.geometry();
504 numScvf_ += isGeometry.corners();
505 numBoundaryScvf_ += isGeometry.corners();
509 const auto fIdx = intersection.indexInInside();
510 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
511 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
513 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
514 const auto vIdxGlobal = this->vertexMapper().subIndex(element, vIdx, dim);
515 boundaryDofIndices_[vIdxGlobal] =
true;
520 else if (intersection.boundary() && intersection.neighbor())
525 const auto fIdx = intersection.indexInInside();
526 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
527 const auto eps = 1e-7*(elementGeometry.corner(1) - elementGeometry.corner(0)).two_norm();
528 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
530 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
531 const auto vIdxGlobal = this->vertexMapper().subIndex(element, vIdx, dim);
532 const auto vPos = elementGeometry.corner(vIdx);
534 const auto& outside = intersection.outside();
535 const auto outsideGeometry = outside.geometry();
536 for (
const auto& isOutside : intersections(this->gridView(), outside))
539 if (isOutside.boundary() && isOutside.neighbor())
541 const auto fIdxOutside = isOutside.indexInInside();
542 const auto numFaceVertsOutside = refElement.size(fIdxOutside, 1, dim);
543 for (
int localVIdxOutside = 0; localVIdxOutside < numFaceVertsOutside; ++localVIdxOutside)
545 const auto vIdxOutside = refElement.subEntity(fIdxOutside, 1, localVIdxOutside, dim);
546 const auto vPosOutside = outsideGeometry.corner(vIdxOutside);
547 const auto shift = std::abs((this->bBoxMax()-this->bBoxMin())*intersection.centerUnitOuterNormal());
548 if (std::abs((vPosOutside-vPos).two_norm() - shift) < eps)
549 periodicVertexMap_[vIdxGlobal] = this->vertexMapper().subIndex(outside, vIdxOutside, dim);
559 if (this->isPeriodic() && this->gridView().comm().size() > 1)
560 DUNE_THROW(Dune::NotImplemented,
"Periodic boundaries for box method for parallel simulations!");
563 const FeCache feCache_;
568 std::size_t numScvf_;
569 std::size_t numBoundaryScvf_;
572 std::vector<bool> boundaryDofIndices_;
575 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.
Helper classes to compute the integration elements.
Base class for grid geometries.
The available discretization methods in Dumux.
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:177
Struture to define the index types used for grid and local indices.
Definition: indextraits.hh:38
Base class for all finite volume grid geometries.
Definition: basegridgeometry.hh:51
GV GridView
export the grid view type
Definition: basegridgeometry.hh:66
Create sub control volumes and sub control volume face geometries.
Definition: boxgeometryhelper.hh:36
Base class for the finite volume geometry vector for box models This builds up the sub control volume...
Definition: discretization/box/fvelementgeometry.hh:49
The default traits for the box finite volume grid geometry Defines the scv and scvf types and the map...
Definition: discretization/box/fvgridgeometry.hh:55
Base class for the finite volume geometry vector for box schemes This builds up the sub control volum...
Definition: discretization/box/fvgridgeometry.hh:73
Base class for the finite volume geometry vector for box schemes This builds up the sub control volum...
Definition: discretization/box/fvgridgeometry.hh:84
const std::vector< SubControlVolume > & scvs(GridIndexType eIdx) const
Get the local scvs for an element.
Definition: discretization/box/fvgridgeometry.hh:175
const std::vector< SubControlVolumeFace > & scvfs(GridIndexType eIdx) const
Get the local scvfs for an element.
Definition: discretization/box/fvgridgeometry.hh:179
const std::unordered_map< GridIndexType, GridIndexType > & periodicVertexMap() const
Returns the map between dofs across periodic boundaries.
Definition: discretization/box/fvgridgeometry.hh:195
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:191
bool hasBoundaryScvf(GridIndexType eIdx) const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/box/fvgridgeometry.hh:199
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: discretization/box/fvgridgeometry.hh:145
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/box/fvgridgeometry.hh:132
void update()
update all fvElementGeometries (do this again after grid adaption)
Definition: discretization/box/fvgridgeometry.hh:150
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:141
Dune::LagrangeLocalFiniteElementCache< CoordScalar, Scalar, dim, 1 > FeCache
export the finite element cache type
Definition: discretization/box/fvgridgeometry.hh:115
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:128
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition: discretization/box/fvgridgeometry.hh:111
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:120
bool dofOnBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition: discretization/box/fvgridgeometry.hh:183
std::size_t numScvf() const
The total number of sun control volume faces.
Definition: discretization/box/fvgridgeometry.hh:136
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on a periodic boundary.
Definition: discretization/box/fvgridgeometry.hh:187
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:107
typename Traits::VertexMapper DofMapper
export dof mapper type
Definition: discretization/box/fvgridgeometry.hh:113
Base class for the finite volume geometry vector for box schemes This builds up the sub control volum...
Definition: discretization/box/fvgridgeometry.hh:377
std::size_t numBoundaryScvf() const
Definition: discretization/box/fvgridgeometry.hh:430
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on a periodic boundary.
Definition: discretization/box/fvgridgeometry.hh:468
typename Traits::template LocalView< ThisType, false > LocalView
export the type of the fv element geometry (the local view type)
Definition: discretization/box/fvgridgeometry.hh:394
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: discretization/box/fvgridgeometry.hh:398
void update()
update all fvElementGeometries (do this again after grid adaption)
Definition: discretization/box/fvgridgeometry.hh:439
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: discretization/box/fvgridgeometry.hh:396
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:472
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition: discretization/box/fvgridgeometry.hh:460
std::size_t numScvf() const
The total number of sun control volume faces.
Definition: discretization/box/fvgridgeometry.hh:425
typename Traits::VertexMapper DofMapper
export dof mapper type
Definition: discretization/box/fvgridgeometry.hh:402
bool dofOnBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition: discretization/box/fvgridgeometry.hh:464
BoxFVGridGeometry(const GridView gridView)
Constructor.
Definition: discretization/box/fvgridgeometry.hh:409
const DofMapper & dofMapper() const
Definition: discretization/box/fvgridgeometry.hh:417
void update(GridView &&gridView)
update all fvElementGeometries (call this after grid adaption)
Definition: discretization/box/fvgridgeometry.hh:453
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition: discretization/box/fvgridgeometry.hh:400
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: discretization/box/fvgridgeometry.hh:434
const std::unordered_map< GridIndexType, GridIndexType > & periodicVertexMap() const
Returns the map between dofs across periodic boundaries.
Definition: discretization/box/fvgridgeometry.hh:476
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/box/fvgridgeometry.hh:421
void update(const GridView &gridView)
update all fvElementGeometries (call this after grid adaption)
Definition: discretization/box/fvgridgeometry.hh:446
Dune::LagrangeLocalFiniteElementCache< CoordScalar, Scalar, dim, 1 > FeCache
export the finite element cache type
Definition: discretization/box/fvgridgeometry.hh:404
the sub control volume for the box scheme
Definition: discretization/box/subcontrolvolume.hh:89
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.