17#ifndef DUMUX_POROUSMEDIUMFLOW_BOXDFM_GRID_FVGEOMETRY_HH
18#define DUMUX_POROUSMEDIUMFLOW_BOXDFM_GRID_FVGEOMETRY_HH
21#include <unordered_map>
23#include <dune/localfunctions/lagrange/lagrangelfecache.hh>
24#include <dune/geometry/multilineargeometry.hh>
25#include <dune/grid/common/mcmgmapper.hh>
42template<
class GV,
class T>
58template<
class Gr
idView,
class MapperTraits = DefaultMapperTraits<Gr
idView>>
65 template<
class Gr
idGeometry,
bool enableCache>
69 using FacetMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
82 bool enableGridGeometryCache =
false,
96template<
class Scalar,
class GV,
class Traits>
105 using Element =
typename GV::template Codim<0>::Entity;
106 using CoordScalar =
typename GV::ctype;
107 static const int dim = GV::dimension;
108 static const int dimWorld = GV::dimensionworld;
109 static_assert(dim == 2 || dim == 3,
"The box-dfm GridGeometry is only implemented in 2 or 3 dimensions.");
127 using FeCache = Dune::LagrangeLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
132 template<
class FractureGr
idAdapter >
137 update_(fractureGridAdapter);
143 {
return this->vertexMapper(); }
156 {
return numBoundaryScvf_; }
160 {
return this->gridView().size(dim); }
163 template<
class FractureGr
idAdapter >
164 void update(
const GridView& gridView,
const FractureGridAdapter& fractureGridAdapter)
166 ParentType::update(gridView);
167 update_(fractureGridAdapter);
171 template<
class FractureGr
idAdapter >
174 ParentType::update(std::move(gridView));
175 update_(fractureGridAdapter);
181 bool dofOnBoundary(
unsigned int dofIdx)
const {
return boundaryDofIndices_[dofIdx]; }
183 bool dofOnFracture(
unsigned int dofIdx)
const {
return fractureDofIndices_[dofIdx]; }
189 { DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box-dfm scheme"); }
193 {
return { gg.cache_ }; }
197 class BoxDfmGridGeometryCache
208 const BoxDfmFVGridGeometry& gridGeometry()
const
209 {
return *gridGeometry_; }
212 const std::vector<SubControlVolume>&
scvs(GridIndexType eIdx)
const
213 {
return scvs_[eIdx]; }
216 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx)
const
217 {
return scvfs_[eIdx]; }
227 std::vector<std::vector<SubControlVolume>> scvs_;
228 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
230 const BoxDfmFVGridGeometry* gridGeometry_;
236 using Cache = BoxDfmGridGeometryCache;
239 using GeometryHelper =
typename Cache::GeometryHelper;
241 template<
class FractureGr
idAdapter >
242 void update_(
const FractureGridAdapter& fractureGridAdapter)
246 const auto numElements = this->gridView().size(0);
247 cache_.scvs_.resize(numElements);
248 cache_.scvfs_.resize(numElements);
250 boundaryDofIndices_.assign(numDofs(),
false);
251 fractureDofIndices_.assign(this->gridView.size(dim),
false);
255 numBoundaryScvf_ = 0;
257 for (
const auto& element : elements(this->gridView()))
260 const auto eIdx = this->elementMapper().index(element);
263 numScv_ += element.subEntities(dim);
264 numScvf_ += element.subEntities(dim-1);
267 auto elementGeometry = element.geometry();
268 const auto refElement = referenceElement(elementGeometry);
271 GeometryHelper geometryHelper(elementGeometry);
274 cache_.scvs_[eIdx].resize(elementGeometry.corners());
275 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
277 const auto dofIdxGlobal = this->vertexMapper().subIndex(element, scvLocalIdx, dim);
286 LocalIndexType scvfLocalIdx = 0;
287 cache_.scvfs_[eIdx].resize(element.subEntities(dim-1));
288 for (; scvfLocalIdx < element.subEntities(dim-1); ++scvfLocalIdx)
291 std::array<LocalIndexType, 2> localScvIndices{{
292 static_cast<LocalIndexType
>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
293 static_cast<LocalIndexType
>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))
299 std::move(localScvIndices));
313 LocalIndexType scvLocalIdx = element.subEntities(dim);
314 for (
const auto& intersection : intersections(this->gridView(), element))
317 const auto& isGeometry = intersection.geometry();
319 const auto idxInInside = intersection.indexInInside();
321 std::vector<GridIndexType> isVertexIndices(
numCorners);
322 for (
unsigned int vIdxLocal = 0; vIdxLocal <
numCorners; ++vIdxLocal)
323 isVertexIndices[vIdxLocal] = this->vertexMapper().subIndex(element,
324 refElement.subEntity(idxInInside, 1, vIdxLocal, dim),
327 if (intersection.boundary() && !intersection.neighbor())
329 numScvf_ += isGeometry.corners();
330 numBoundaryScvf_ += isGeometry.corners();
332 for (
unsigned int isScvfLocalIdx = 0; isScvfLocalIdx <
numCorners; ++isScvfLocalIdx)
335 const LocalIndexType insideScvIdx =
static_cast<LocalIndexType
>(refElement.subEntity(idxInInside, 1, isScvfLocalIdx, dim));
336 std::array<LocalIndexType, 2> localScvIndices{{insideScvIdx, insideScvIdx}};
337 cache_.scvfs_[eIdx].emplace_back(geometryHelper,
341 std::move(localScvIndices));
346 const auto numFaceVerts = refElement.size(idxInInside, 1, dim);
347 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
349 const auto vIdx = refElement.subEntity(idxInInside, 1, localVIdx, dim);
350 const auto vIdxGlobal = this->vertexMapper().subIndex(element, vIdx, dim);
351 boundaryDofIndices_[vIdxGlobal] =
true;
355 else if (intersection.boundary() && intersection.neighbor())
356 DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box-dfm scheme");
359 if (fractureGridAdapter.composeFacetElement(isVertexIndices))
361 for (
auto vIdx : isVertexIndices)
362 fractureDofIndices_[vIdx] =
true;
366 const auto curNumScvs = cache_.scvs_[eIdx].size();
367 cache_.scvs_[eIdx].reserve(curNumScvs+
numCorners);
368 for (
unsigned int vIdxLocal = 0; vIdxLocal <
numCorners; ++vIdxLocal)
369 cache_.scvs_[eIdx].emplace_back(geometryHelper,
373 static_cast<LocalIndexType
>(refElement.subEntity(idxInInside, 1, vIdxLocal, dim)),
377 isVertexIndices[vIdxLocal]);
382 const auto& faceRefElement = referenceElement(isGeometry);
383 for (
unsigned int edgeIdx = 0; edgeIdx < faceRefElement.size(1); ++edgeIdx)
386 std::array<LocalIndexType, 2> localScvIndices{{
387 static_cast<LocalIndexType
>(faceRefElement.subEntity(edgeIdx, 1, 0, dim-1)),
388 static_cast<LocalIndexType
>(faceRefElement.subEntity(edgeIdx, 1, 1, dim-1))
392 std::for_each( localScvIndices.begin(),
393 localScvIndices.end(),
394 [curNumScvs] (
auto& elemLocalIdx) { elemLocalIdx += curNumScvs; } );
398 cache_.scvfs_[eIdx].emplace_back(geometryHelper,
402 std::move(localScvIndices),
403 intersection.boundary());
411 std::array<LocalIndexType, 2> localScvIndices{{0, 1}};
414 std::for_each( localScvIndices.begin(),
415 localScvIndices.end(),
416 [curNumScvs] (
auto& elemLocalIdx) { elemLocalIdx += curNumScvs; } );
420 cache_.scvfs_[eIdx].emplace_back(geometryHelper,
424 std::move(localScvIndices),
425 intersection.boundary());
432 const FeCache feCache_;
436 std::size_t numScvf_;
437 std::size_t numBoundaryScvf_;
440 std::vector<bool> boundaryDofIndices_;
441 std::vector<bool> fractureDofIndices_;
453template<
class Scalar,
class GV,
class Traits>
459 using GridIndexType =
typename GV::IndexSet::IndexType;
461 static const int dim = GV::dimension;
462 static const int dimWorld = GV::dimensionworld;
464 using Element =
typename GV::template Codim<0>::Entity;
465 using Intersection =
typename GV::Intersection;
466 using CoordScalar =
typename GV::ctype;
484 using FeCache = Dune::LagrangeLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
489 template<
class FractureGr
idAdapter >
492 , facetMapper_(gridView,
Dune::mcmgLayout(
Dune::template Codim<1>()))
495 update_(fractureGridAdapter);
501 {
return this->vertexMapper(); }
514 {
return numBoundaryScvf_; }
518 {
return this->gridView().size(dim); }
521 template<
class FractureGr
idAdapter >
522 void update(
const GridView& gridView,
const FractureGridAdapter& fractureGridAdapter)
524 ParentType::update(gridView);
525 updateFacetMapper_();
526 update_(fractureGridAdapter);
530 template<
class FractureGr
idAdapter >
533 ParentType::update(std::move(gridView));
534 updateFacetMapper_();
535 update_(fractureGridAdapter);
541 bool dofOnBoundary(
unsigned int dofIdx)
const {
return boundaryDofIndices_[dofIdx]; }
543 bool dofOnFracture(
unsigned int dofIdx)
const {
return fractureDofIndices_[dofIdx]; }
548 bool isOnFracture(
const Element& element,
const Intersection& intersection)
const
549 {
return facetOnFracture_[facetMapper_.subIndex(element, intersection.indexInInside(), 1)]; }
553 { DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box-dfm scheme"); }
557 {
return { gg.cache_ }; }
560 class BoxDfmGridGeometryCache
571 const BoxDfmFVGridGeometry& gridGeometry()
const
572 {
return *gridGeometry_; }
575 const BoxDfmFVGridGeometry* gridGeometry_;
581 using Cache = BoxDfmGridGeometryCache;
585 void updateFacetMapper_()
587 facetMapper_.update(this->gridView());
590 template<
class FractureGr
idAdapter >
591 void update_(
const FractureGridAdapter& fractureGridAdapter)
593 boundaryDofIndices_.assign(numDofs(),
false);
594 fractureDofIndices_.assign(numDofs(),
false);
595 facetOnFracture_.assign(this->gridView().size(1),
false);
601 numBoundaryScvf_ = 0;
602 for (
const auto& element : elements(this->gridView()))
604 numScv_ += element.subEntities(dim);
605 numScvf_ += element.subEntities(dim-1);
607 const auto elementGeometry = element.geometry();
608 const auto refElement = referenceElement(elementGeometry);
611 for (
const auto& intersection : intersections(this->gridView(), element))
614 const auto& isGeometry = intersection.geometry();
616 const auto idxInInside = intersection.indexInInside();
618 std::vector<GridIndexType> isVertexIndices(
numCorners);
619 for (
unsigned int vIdxLocal = 0; vIdxLocal <
numCorners; ++vIdxLocal)
620 isVertexIndices[vIdxLocal] = this->vertexMapper().subIndex(element,
621 refElement.subEntity(idxInInside, 1, vIdxLocal, dim),
624 if (intersection.boundary() && !intersection.neighbor())
631 const auto fIdx = intersection.indexInInside();
632 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
633 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
635 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
636 const auto vIdxGlobal = this->vertexMapper().subIndex(element, vIdx, dim);
637 boundaryDofIndices_[vIdxGlobal] =
true;
642 else if (intersection.boundary() && intersection.neighbor())
643 DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box-dfm scheme");
646 if (fractureGridAdapter.composeFacetElement(isVertexIndices))
648 facetOnFracture_[facetMapper_.subIndex(element, idxInInside, 1)] =
true;
649 for (
auto vIdx : isVertexIndices)
650 fractureDofIndices_[vIdx] =
true;
652 const auto isGeometry = intersection.geometry();
653 numScv_ += isGeometry.corners();
654 numScvf_ += dim == 3 ? referenceElement(isGeometry).size(1) : 1;
660 const FeCache feCache_;
665 std::size_t numScvf_;
666 std::size_t numBoundaryScvf_;
669 std::vector<bool> boundaryDofIndices_;
670 std::vector<bool> fractureDofIndices_;
673 typename Traits::FacetMapper facetMapper_;
674 std::vector<bool> facetOnFracture_;
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 discrete fracture model.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:44
Base class for the finite volume geometry vector for box schemes This builds up the sub control volum...
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:456
Extrusion_t< Traits > Extrusion
Export the extrusion type.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:480
bool dofOnBoundary(unsigned int dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:541
bool dofOnPeriodicBoundary(std::size_t dofIdx) const
Periodic boundaries are not supported for the box-dfm scheme.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:545
BoxDfmFVGridGeometry(const GridView gridView, const FractureGridAdapter &fractureGridAdapter)
Constructor.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:490
std::size_t numScv() const
The total number of sub control volumes.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:504
bool isOnFracture(const Element &element, const Intersection &intersection) const
Returns true if an intersection coincides with a fracture element.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:548
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:517
BoxDfmGridGeometryCache Cache
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:581
std::size_t numBoundaryScvf() const
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:513
void update(const GridView &gridView, const FractureGridAdapter &fractureGridAdapter)
update all fvElementGeometries (call this after grid adaption)
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:522
typename Traits::VertexMapper DofMapper
export dof mapper type
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:482
typename Traits::template LocalView< ThisType, false > LocalView
export the type of the fv element geometry (the local view type)
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:474
std::size_t numScvf() const
The total number of sun control volume faces.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:508
Dune::LagrangeLocalFiniteElementCache< CoordScalar, Scalar, dim, 1 > FeCache
export the finite element cache type
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:484
friend LocalView localView(const BoxDfmFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:556
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:539
const DofMapper & dofMapper() const
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:500
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:478
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:476
bool dofOnFracture(unsigned int dofIdx) const
If a vertex / d.o.f. is on a fracture.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:543
void update(GridView &&gridView, const FractureGridAdapter &fractureGridAdapter)
update all fvElementGeometries (call this after grid adaption)
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:531
std::size_t periodicallyMappedDof(std::size_t dofIdx) const
The index of the vertex / d.o.f. on the other side of the periodic boundary.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:552
Base class for the finite volume geometry vector for box schemes that consider extra connectivity bet...
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:99
typename Traits::SubControlVolume SubControlVolume
Export the type of sub control volume.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:119
Dune::LagrangeLocalFiniteElementCache< CoordScalar, Scalar, dim, 1 > FeCache
Export the finite element cache type.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:127
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:159
typename Traits::VertexMapper DofMapper
Export dof mapper type.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:125
BoxDfmFVGridGeometry(const GridView gridView, const FractureGridAdapter &fractureGridAdapter)
Constructor.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:133
BoxDfmGridGeometryCache Cache
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:236
friend LocalView localView(const BoxDfmFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:192
void update(GridView &&gridView, const FractureGridAdapter &fractureGridAdapter)
update all fvElementGeometries (call this after grid adaption)
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:172
Extrusion_t< Traits > Extrusion
Export the extrusion type.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:123
typename Traits::template LocalView< ThisType, true > LocalView
Export the type of the fv element geometry (the local view type)
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:117
const DofMapper & dofMapper() const
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:142
std::size_t numScvf() const
The total number of sun control volume faces.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:150
std::size_t numScv() const
The total number of sub control volumes.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:146
std::size_t periodicallyMappedDof(std::size_t dofIdx) const
The index of the vertex / d.o.f. on the other side of the periodic boundary.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:188
std::size_t numBoundaryScvf() const
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:155
bool dofOnBoundary(unsigned int dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:181
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:179
void update(const GridView &gridView, const FractureGridAdapter &fractureGridAdapter)
update all fvElementGeometries (call this after grid adaption)
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:164
typename Traits::SubControlVolumeFace SubControlVolumeFace
Export the type of sub control volume.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:121
bool dofOnPeriodicBoundary(std::size_t dofIdx) const
Periodic boundaries are not supported for the box-dfm scheme.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:185
bool dofOnFracture(unsigned int dofIdx) const
If a vertex / d.o.f. is on a fracture.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:183
Base class for the finite volume geometry vector for box schemes.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:84
Create sub control volumes and sub control volume face geometries.
Definition: porousmediumflow/boxdfm/geometryhelper.hh:47
Class for a sub control volume face in the box discrete fracture method, i.e a part of the boundary o...
Definition: porousmediumflow/boxdfm/subcontrolvolumeface.hh:63
the sub control volume for the box discrete fracture scheme
Definition: porousmediumflow/boxdfm/subcontrolvolume.hh:62
Defines the default element and vertex mapper types.
Helper classes to compute the integration elements.
The available discretization methods in Dumux.
Dune::Std::detected_or_t< Dumux::BoxDfmGeometryHelper< GV, GV::dimension, typename T::SubControlVolume, typename T::SubControlVolumeFace >, SpecifiesGeometryHelper, T > BoxDfmGeometryHelper_t
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:47
typename T::GeometryHelper SpecifiesGeometryHelper
Definition: basegridgeometry.hh:30
CVFE< CVFEMethods::PQ1 > Box
Definition: method.hh:94
std::size_t numCorners(Shape shape)
Returns the number of corners of a given geometry.
Definition: throatproperties.hh:220
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
Definition: common/pdesolver.hh:24
Base class for the local finite volume geometry for the box discrete fracture model.
Helper class constructing the dual grid finite volume geometries for the box discrete fracture model.
the sub control volume for the box discrete fracture scheme
The sub control volume face class for the box discrete fracture model.
The default traits for the box finite volume grid geometry.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:61
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > FacetMapper
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:69
Structure to define the index types used for grid and local indices.
Definition: indextraits.hh:26