29#ifndef DUMUX_POROUSMEDIUMFLOW_BOXDFM_GRID_FVGEOMETRY_HH
30#define DUMUX_POROUSMEDIUMFLOW_BOXDFM_GRID_FVGEOMETRY_HH
33#include <unordered_map>
35#include <dune/localfunctions/lagrange/lagrangelfecache.hh>
36#include <dune/geometry/multilineargeometry.hh>
37#include <dune/grid/common/mcmgmapper.hh>
61template<
class Gr
idView,
class MapperTraits = DefaultMapperTraits<Gr
idView>>
68 template<
class Gr
idGeometry,
bool enableCache>
72 using FacetMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
85 bool enableGridGeometryCache =
false,
99template<
class Scalar,
class GV,
class Traits>
105 using GridIndexType =
typename GV::IndexSet::IndexType;
107 using Element =
typename GV::template Codim<0>::Entity;
108 using CoordScalar =
typename GV::ctype;
109 static const int dim = GV::dimension;
110 static const int dimWorld = GV::dimensionworld;
111 static_assert(dim == 2 || dim == 3,
"The box-dfm GridGeometry is only implemented in 2 or 3 dimensions.");
114 typename Traits::SubControlVolume,
115 typename Traits::SubControlVolumeFace>;
133 using FeCache = Dune::LagrangeLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
138 [[deprecated(
"Use BoxDfmFVGridGeometry(gridView, fractureGridAdapter) instead! Will be removed after release 3.5.")]]
142 template<
class FractureGr
idAdapter >
146 update_(fractureGridAdapter);
152 {
return this->vertexMapper(); }
165 {
return numBoundaryScvf_; }
169 {
return this->gridView().size(dim); }
172 template<
class FractureGr
idAdapter >
173 [[deprecated(
"Use update(gridView) instead! Will be removed after release 3.5.")]]
174 void update(
const FractureGridAdapter& fractureGridAdapter)
176 ParentType::update();
177 update_(fractureGridAdapter);
181 template<
class FractureGr
idAdapter >
182 void update(
const GridView& gridView,
const FractureGridAdapter& fractureGridAdapter)
184 ParentType::update(gridView);
185 update_(fractureGridAdapter);
189 template<
class FractureGr
idAdapter >
192 ParentType::update(std::move(gridView));
193 update_(fractureGridAdapter);
199 const std::vector<SubControlVolume>&
scvs(GridIndexType eIdx)
const {
return scvs_[eIdx]; }
201 const std::vector<SubControlVolumeFace>&
scvfs(GridIndexType eIdx)
const {
return scvfs_[eIdx]; }
203 bool dofOnBoundary(
unsigned int dofIdx)
const {
return boundaryDofIndices_[dofIdx]; }
205 bool dofOnFracture(
unsigned int dofIdx)
const {
return fractureDofIndices_[dofIdx]; }
211 { DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box-dfm scheme"); }
215 {
return std::unordered_map<std::size_t, std::size_t>(); }
219 template<
class FractureGr
idAdapter >
220 void update_(
const FractureGridAdapter& fractureGridAdapter)
225 auto numElements = this->gridView().size(0);
226 scvs_.resize(numElements);
227 scvfs_.resize(numElements);
229 boundaryDofIndices_.assign(numDofs(),
false);
230 fractureDofIndices_.assign(this->gridView.size(dim),
false);
234 numBoundaryScvf_ = 0;
236 for (
const auto& element : elements(this->gridView()))
239 auto eIdx = this->elementMapper().index(element);
242 numScv_ += element.subEntities(dim);
243 numScvf_ += element.subEntities(dim-1);
246 auto elementGeometry = element.geometry();
247 const auto refElement = referenceElement(elementGeometry);
250 GeometryHelper geometryHelper(elementGeometry);
253 scvs_[eIdx].resize(elementGeometry.corners());
254 using LocalIndexType =
typename SubControlVolumeFace::Traits::LocalIndexType;
255 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
257 const auto dofIdxGlobal = this->vertexMapper().subIndex(element, scvLocalIdx, dim);
259 scvs_[eIdx][scvLocalIdx] = SubControlVolume(geometryHelper,
266 LocalIndexType scvfLocalIdx = 0;
267 scvfs_[eIdx].resize(element.subEntities(dim-1));
268 for (; scvfLocalIdx < element.subEntities(dim-1); ++scvfLocalIdx)
271 std::vector<LocalIndexType> localScvIndices({
static_cast<LocalIndexType
>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
272 static_cast<LocalIndexType
>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
274 scvfs_[eIdx][scvfLocalIdx] = SubControlVolumeFace(geometryHelper,
278 std::move(localScvIndices));
292 LocalIndexType scvLocalIdx =
element.subEntities(dim);
293 for (
const auto& intersection : intersections(this->gridView(), element))
296 const auto& isGeometry = intersection.geometry();
298 const auto idxInInside = intersection.indexInInside();
300 std::vector<GridIndexType> isVertexIndices(
numCorners);
301 for (
unsigned int vIdxLocal = 0; vIdxLocal <
numCorners; ++vIdxLocal)
302 isVertexIndices[vIdxLocal] = this->vertexMapper().subIndex(element,
303 refElement.subEntity(idxInInside, 1, vIdxLocal, dim),
306 if (intersection.boundary() && !intersection.neighbor())
308 numScvf_ += isGeometry.corners();
309 numBoundaryScvf_ += isGeometry.corners();
311 for (
unsigned int isScvfLocalIdx = 0; isScvfLocalIdx <
numCorners; ++isScvfLocalIdx)
314 const LocalIndexType insideScvIdx =
static_cast<LocalIndexType
>(refElement.subEntity(idxInInside, 1, isScvfLocalIdx, dim));
315 std::vector<LocalIndexType> localScvIndices = {insideScvIdx, insideScvIdx};
316 scvfs_[eIdx].emplace_back(geometryHelper,
321 std::move(localScvIndices));
326 const auto numFaceVerts = refElement.size(idxInInside, 1, dim);
327 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
329 const auto vIdx = refElement.subEntity(idxInInside, 1, localVIdx, dim);
330 const auto vIdxGlobal = this->vertexMapper().subIndex(element, vIdx, dim);
331 boundaryDofIndices_[vIdxGlobal] =
true;
335 else if (intersection.boundary() && intersection.neighbor())
336 DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box-dfm scheme");
339 if (fractureGridAdapter.composeFacetElement(isVertexIndices))
341 for (
auto vIdx : isVertexIndices)
342 fractureDofIndices_[vIdx] =
true;
346 const auto curNumScvs = scvs_[eIdx].size();
348 for (
unsigned int vIdxLocal = 0; vIdxLocal <
numCorners; ++vIdxLocal)
349 scvs_[eIdx].emplace_back(geometryHelper,
353 static_cast<LocalIndexType
>(refElement.subEntity(idxInInside, 1, vIdxLocal, dim)),
357 isVertexIndices[vIdxLocal]);
362 const auto& faceRefElement = referenceElement(isGeometry);
363 for (
unsigned int edgeIdx = 0; edgeIdx < faceRefElement.size(1); ++edgeIdx)
366 std::vector<LocalIndexType> localScvIndices({
static_cast<LocalIndexType
>(faceRefElement.subEntity(edgeIdx, 1, 0, dim-1)),
367 static_cast<LocalIndexType
>(faceRefElement.subEntity(edgeIdx, 1, 1, dim-1))});
370 std::for_each( localScvIndices.begin(),
371 localScvIndices.end(),
372 [curNumScvs] (
auto& elemLocalIdx) { elemLocalIdx += curNumScvs; } );
376 scvfs_[eIdx].emplace_back(geometryHelper,
381 std::move(localScvIndices),
382 intersection.boundary());
390 std::vector<LocalIndexType> localScvIndices({0, 1});
393 std::for_each( localScvIndices.begin(),
394 localScvIndices.end(),
395 [curNumScvs] (
auto& elemLocalIdx) { elemLocalIdx += curNumScvs; } );
399 scvfs_[eIdx].emplace_back(geometryHelper,
404 std::move(localScvIndices),
405 intersection.boundary());
412 const FeCache feCache_;
414 std::vector<std::vector<SubControlVolume>> scvs_;
415 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
419 std::size_t numScvf_;
420 std::size_t numBoundaryScvf_;
423 std::vector<bool> boundaryDofIndices_;
424 std::vector<bool> fractureDofIndices_;
434template<
class Scalar,
class GV,
class Traits>
440 using GridIndexType =
typename GV::IndexSet::IndexType;
442 static const int dim = GV::dimension;
443 static const int dimWorld = GV::dimensionworld;
445 using Element =
typename GV::template Codim<0>::Entity;
446 using Intersection =
typename GV::Intersection;
447 using CoordScalar =
typename GV::ctype;
465 using FeCache = Dune::LagrangeLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
470 [[deprecated(
"Use BoxDfmFVGridGeometry(gridView, fractureGridAdapter) instead! Will be removed after release 3.5.")]]
473 , facetMapper_(gridView,
Dune::mcmgLayout(
Dune::template Codim<1>()))
476 template<
class FractureGr
idAdapter >
479 , facetMapper_(gridView,
Dune::mcmgLayout(
Dune::template Codim<1>()))
481 update_(fractureGridAdapter);
487 {
return this->vertexMapper(); }
500 {
return numBoundaryScvf_; }
504 {
return this->gridView().size(dim); }
507 template<
class FractureGr
idAdapter >
508 [[deprecated(
"Use update(gridView) instead! Will be removed after release 3.5.")]]
509 void update(
const FractureGridAdapter& fractureGridAdapter)
511 ParentType::update();
512 updateFacetMapper_();
513 update_(fractureGridAdapter);
517 template<
class FractureGr
idAdapter >
518 void update(
const GridView& gridView,
const FractureGridAdapter& fractureGridAdapter)
520 ParentType::update(gridView);
521 updateFacetMapper_();
522 update_(fractureGridAdapter);
526 template<
class FractureGr
idAdapter >
529 ParentType::update(std::move(gridView));
530 updateFacetMapper_();
531 update_(fractureGridAdapter);
537 bool dofOnBoundary(
unsigned int dofIdx)
const {
return boundaryDofIndices_[dofIdx]; }
539 bool dofOnFracture(
unsigned int dofIdx)
const {
return fractureDofIndices_[dofIdx]; }
544 bool isOnFracture(
const Element& element,
const Intersection& intersection)
const
545 {
return facetOnFracture_[facetMapper_.subIndex(element, intersection.indexInInside(), 1)]; }
549 { DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box-dfm scheme"); }
553 {
return std::unordered_map<std::size_t, std::size_t>(); }
557 void updateFacetMapper_()
559 if constexpr (Deprecated::hasUpdateGridView<typename Traits::FacetMapper, GridView>())
560 facetMapper_.update(this->gridView());
562 Deprecated::update(facetMapper_);
565 template<
class FractureGr
idAdapter >
566 void update_(
const FractureGridAdapter& fractureGridAdapter)
568 boundaryDofIndices_.assign(numDofs(),
false);
569 fractureDofIndices_.assign(numDofs(),
false);
570 facetOnFracture_.assign(this->gridView().size(1),
false);
576 numBoundaryScvf_ = 0;
577 for (
const auto& element : elements(this->gridView()))
579 numScv_ += element.subEntities(dim);
580 numScvf_ += element.subEntities(dim-1);
582 const auto elementGeometry = element.geometry();
583 const auto refElement = referenceElement(elementGeometry);
586 for (
const auto& intersection : intersections(this->gridView(), element))
589 const auto& isGeometry = intersection.geometry();
591 const auto idxInInside = intersection.indexInInside();
593 std::vector<GridIndexType> isVertexIndices(
numCorners);
594 for (
unsigned int vIdxLocal = 0; vIdxLocal <
numCorners; ++vIdxLocal)
595 isVertexIndices[vIdxLocal] = this->vertexMapper().subIndex(element,
596 refElement.subEntity(idxInInside, 1, vIdxLocal, dim),
599 if (intersection.boundary() && !intersection.neighbor())
606 const auto fIdx = intersection.indexInInside();
607 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
608 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
610 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
611 const auto vIdxGlobal = this->vertexMapper().subIndex(element, vIdx, dim);
612 boundaryDofIndices_[vIdxGlobal] =
true;
617 else if (intersection.boundary() && intersection.neighbor())
618 DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box-dfm scheme");
621 if (fractureGridAdapter.composeFacetElement(isVertexIndices))
623 facetOnFracture_[facetMapper_.subIndex(element, idxInInside, 1)] =
true;
624 for (
auto vIdx : isVertexIndices)
625 fractureDofIndices_[vIdx] =
true;
627 const auto isGeometry = intersection.geometry();
628 numScv_ += isGeometry.corners();
629 numScvf_ += dim == 3 ? referenceElement(isGeometry).size(1) : 1;
635 const FeCache feCache_;
640 std::size_t numScvf_;
641 std::size_t numBoundaryScvf_;
644 std::vector<bool> boundaryDofIndices_;
645 std::vector<bool> fractureDofIndices_;
648 typename Traits::FacetMapper facetMapper_;
649 std::vector<bool> facetOnFracture_;
Defines the default element and vertex mapper types.
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
Definition: common/pdesolver.hh:36
std::size_t numCorners(Shape shape)
Returns the number of corners of a given geometry.
Definition: throatproperties.hh:215
Base class for all finite volume grid geometries.
Definition: basegridgeometry.hh:51
GV GridView
export the grid view type
Definition: basegridgeometry.hh:66
Base class for the finite volume geometry vector for box discrete fracture model.
Definition: porousmediumflow/boxdfm/fvelementgeometry.hh:54
The default traits for the box finite volume grid geometry.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:64
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > FacetMapper
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:72
Base class for the finite volume geometry vector for box schemes.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:87
Base class for the finite volume geometry vector for box schemes that consider extra connectivity bet...
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:102
typename Traits::SubControlVolume SubControlVolume
Export the type of sub control volume.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:125
Dune::LagrangeLocalFiniteElementCache< CoordScalar, Scalar, dim, 1 > FeCache
Export the finite element cache type.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:133
std::unordered_map< std::size_t, std::size_t > periodicVertexMap() const
Returns the map between dofs across periodic boundaries.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:214
const std::vector< SubControlVolumeFace > & scvfs(GridIndexType eIdx) const
Get the local scvfs for an element.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:201
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:168
typename Traits::VertexMapper DofMapper
Export dof mapper type.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:131
BoxDfmFVGridGeometry(const GridView gridView)
Constructor.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:139
BoxDfmFVGridGeometry(const GridView gridView, const FractureGridAdapter &fractureGridAdapter)
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:143
void update(GridView &&gridView, const FractureGridAdapter &fractureGridAdapter)
update all fvElementGeometries (call this after grid adaption)
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:190
const std::vector< SubControlVolume > & scvs(GridIndexType eIdx) const
Get the local scvs for an element.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:199
Extrusion_t< Traits > Extrusion
Export the extrusion type.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:129
typename Traits::template LocalView< ThisType, true > LocalView
Export the type of the fv element geometry (the local view type)
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:123
const DofMapper & dofMapper() const
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:151
std::size_t numScvf() const
The total number of sun control volume faces.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:159
std::size_t numScv() const
The total number of sub control volumes.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:155
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:210
std::size_t numBoundaryScvf() const
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:164
bool dofOnBoundary(unsigned int dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:203
void update(const FractureGridAdapter &fractureGridAdapter)
Update all fvElementGeometries (do this again after grid adaption)
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:174
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:197
void update(const GridView &gridView, const FractureGridAdapter &fractureGridAdapter)
update all fvElementGeometries (call this after grid adaption)
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:182
typename Traits::SubControlVolumeFace SubControlVolumeFace
Export the type of sub control volume.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:127
bool dofOnPeriodicBoundary(std::size_t dofIdx) const
Periodic boundaries are not supported for the box-dfm scheme.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:207
bool dofOnFracture(unsigned int dofIdx) const
If a vertex / d.o.f. is on a fracture.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:205
Base class for the finite volume geometry vector for box schemes This builds up the sub control volum...
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:437
Extrusion_t< Traits > Extrusion
Export the extrusion type.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:461
bool dofOnBoundary(unsigned int dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:537
bool dofOnPeriodicBoundary(std::size_t dofIdx) const
Periodic boundaries are not supported for the box-dfm scheme.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:541
BoxDfmFVGridGeometry(const GridView gridView, const FractureGridAdapter &fractureGridAdapter)
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:477
std::size_t numScv() const
The total number of sub control volumes.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:490
bool isOnFracture(const Element &element, const Intersection &intersection) const
Returns true if an intersection coincides with a fracture element.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:544
std::unordered_map< std::size_t, std::size_t > periodicVertexMap() const
Returns the map between dofs across periodic boundaries.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:552
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:503
BoxDfmFVGridGeometry(const GridView gridView)
Constructor.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:471
std::size_t numBoundaryScvf() const
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:499
void update(const GridView &gridView, const FractureGridAdapter &fractureGridAdapter)
update all fvElementGeometries (call this after grid adaption)
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:518
typename Traits::VertexMapper DofMapper
export dof mapper type
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:463
typename Traits::template LocalView< ThisType, false > LocalView
export the type of the fv element geometry (the local view type)
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:455
std::size_t numScvf() const
The total number of sun control volume faces.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:494
Dune::LagrangeLocalFiniteElementCache< CoordScalar, Scalar, dim, 1 > FeCache
export the finite element cache type
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:465
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:535
const DofMapper & dofMapper() const
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:486
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:459
void update(const FractureGridAdapter &fractureGridAdapter)
Update all fvElementGeometries (do this again after grid adaption)
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:509
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:457
bool dofOnFracture(unsigned int dofIdx) const
If a vertex / d.o.f. is on a fracture.
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:539
void update(GridView &&gridView, const FractureGridAdapter &fractureGridAdapter)
update all fvElementGeometries (call this after grid adaption)
Definition: porousmediumflow/boxdfm/fvgridgeometry.hh:527
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:548
Create sub control volumes and sub control volume face geometries.
Definition: porousmediumflow/boxdfm/geometryhelper.hh:35
the sub control volume for the box discrete fracture scheme
Definition: porousmediumflow/boxdfm/subcontrolvolume.hh:96
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:99
Base class for the local finite volume geometry 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.
Helper class constructing the dual grid finite volume geometries for the box discrete fracture model.