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>
60template<
class Gr
idView,
class MapperTraits = DefaultMapperTraits<Gr
idView>>
67 template<
class Gr
idGeometry,
bool enableCache>
71 using FacetMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
84 bool enableGridGeometryCache =
false,
98template<
class Scalar,
class GV,
class Traits>
104 using GridIndexType =
typename GV::IndexSet::IndexType;
106 using Element =
typename GV::template Codim<0>::Entity;
107 using CoordScalar =
typename GV::ctype;
108 static const int dim = GV::dimension;
109 static const int dimWorld = GV::dimensionworld;
110 static_assert(dim == 2 || dim == 3,
"The box-dfm GridGeometry is only implemented in 2 or 3 dimensions.");
113 typename Traits::SubControlVolume,
114 typename Traits::SubControlVolumeFace>;
132 using FeCache = Dune::LagrangeLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
137 template<
class FractureGr
idAdapter >
141 update_(fractureGridAdapter);
160 {
return numBoundaryScvf_; }
164 {
return this->
gridView().size(dim); }
167 template<
class FractureGr
idAdapter >
171 update_(fractureGridAdapter);
175 template<
class FractureGr
idAdapter >
179 update_(fractureGridAdapter);
185 const std::vector<SubControlVolume>&
scvs(GridIndexType eIdx)
const {
return scvs_[eIdx]; }
187 const std::vector<SubControlVolumeFace>&
scvfs(GridIndexType eIdx)
const {
return scvfs_[eIdx]; }
189 bool dofOnBoundary(
unsigned int dofIdx)
const {
return boundaryDofIndices_[dofIdx]; }
191 bool dofOnFracture(
unsigned int dofIdx)
const {
return fractureDofIndices_[dofIdx]; }
197 { DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box-dfm scheme"); }
201 {
return std::unordered_map<std::size_t, std::size_t>(); }
205 template<
class FractureGr
idAdapter >
206 void update_(
const FractureGridAdapter& fractureGridAdapter)
211 auto numElements = this->gridView().size(0);
212 scvs_.resize(numElements);
213 scvfs_.resize(numElements);
215 boundaryDofIndices_.assign(numDofs(),
false);
216 fractureDofIndices_.assign(this->gridView.size(dim),
false);
220 numBoundaryScvf_ = 0;
222 for (
const auto& element : elements(this->gridView()))
225 auto eIdx = this->elementMapper().index(element);
228 numScv_ += element.subEntities(dim);
229 numScvf_ += element.subEntities(dim-1);
232 auto elementGeometry = element.geometry();
233 const auto refElement = referenceElement(elementGeometry);
236 GeometryHelper geometryHelper(elementGeometry);
239 scvs_[eIdx].resize(elementGeometry.corners());
240 using LocalIndexType =
typename SubControlVolumeFace::Traits::LocalIndexType;
241 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
243 const auto dofIdxGlobal = this->vertexMapper().subIndex(element, scvLocalIdx, dim);
245 scvs_[eIdx][scvLocalIdx] = SubControlVolume(geometryHelper,
252 LocalIndexType scvfLocalIdx = 0;
253 scvfs_[eIdx].resize(element.subEntities(dim-1));
254 for (; scvfLocalIdx < element.subEntities(dim-1); ++scvfLocalIdx)
257 std::vector<LocalIndexType> localScvIndices({
static_cast<LocalIndexType
>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
258 static_cast<LocalIndexType
>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
260 scvfs_[eIdx][scvfLocalIdx] = SubControlVolumeFace(geometryHelper,
264 std::move(localScvIndices));
278 LocalIndexType scvLocalIdx =
element.subEntities(dim);
279 for (
const auto& intersection : intersections(this->gridView(), element))
282 const auto& isGeometry = intersection.geometry();
284 const auto idxInInside = intersection.indexInInside();
286 std::vector<GridIndexType> isVertexIndices(numCorners);
287 for (
unsigned int vIdxLocal = 0; vIdxLocal <
numCorners; ++vIdxLocal)
288 isVertexIndices[vIdxLocal] = this->vertexMapper().subIndex(element,
289 refElement.subEntity(idxInInside, 1, vIdxLocal, dim),
292 if (intersection.boundary() && !intersection.neighbor())
294 numScvf_ += isGeometry.corners();
295 numBoundaryScvf_ += isGeometry.corners();
297 for (
unsigned int isScvfLocalIdx = 0; isScvfLocalIdx <
numCorners; ++isScvfLocalIdx)
300 const LocalIndexType insideScvIdx =
static_cast<LocalIndexType
>(refElement.subEntity(idxInInside, 1, isScvfLocalIdx, dim));
301 std::vector<LocalIndexType> localScvIndices = {insideScvIdx, insideScvIdx};
302 scvfs_[eIdx].emplace_back(geometryHelper,
307 std::move(localScvIndices));
312 const auto numFaceVerts = refElement.size(idxInInside, 1, dim);
313 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
315 const auto vIdx = refElement.subEntity(idxInInside, 1, localVIdx, dim);
316 const auto vIdxGlobal = this->vertexMapper().subIndex(element, vIdx, dim);
317 boundaryDofIndices_[vIdxGlobal] =
true;
321 else if (intersection.boundary() && intersection.neighbor())
322 DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box-dfm scheme");
325 if (fractureGridAdapter.composeFacetElement(isVertexIndices))
327 for (
auto vIdx : isVertexIndices)
328 fractureDofIndices_[vIdx] =
true;
332 const auto curNumScvs = scvs_[eIdx].size();
333 scvs_[eIdx].reserve(curNumScvs+numCorners);
334 for (
unsigned int vIdxLocal = 0; vIdxLocal <
numCorners; ++vIdxLocal)
335 scvs_[eIdx].emplace_back(geometryHelper,
339 static_cast<LocalIndexType
>(refElement.subEntity(idxInInside, 1, vIdxLocal, dim)),
343 isVertexIndices[vIdxLocal]);
348 const auto& faceRefElement = referenceElement(isGeometry);
349 for (
unsigned int edgeIdx = 0; edgeIdx < faceRefElement.size(1); ++edgeIdx)
352 std::vector<LocalIndexType> localScvIndices({
static_cast<LocalIndexType
>(faceRefElement.subEntity(edgeIdx, 1, 0, dim-1)),
353 static_cast<LocalIndexType
>(faceRefElement.subEntity(edgeIdx, 1, 1, dim-1))});
356 std::for_each( localScvIndices.begin(),
357 localScvIndices.end(),
358 [curNumScvs] (
auto& elemLocalIdx) { elemLocalIdx += curNumScvs; } );
362 scvfs_[eIdx].emplace_back(geometryHelper,
367 std::move(localScvIndices),
368 intersection.boundary());
376 std::vector<LocalIndexType> localScvIndices({0, 1});
379 std::for_each( localScvIndices.begin(),
380 localScvIndices.end(),
381 [curNumScvs] (
auto& elemLocalIdx) { elemLocalIdx += curNumScvs; } );
385 scvfs_[eIdx].emplace_back(geometryHelper,
390 std::move(localScvIndices),
391 intersection.boundary());
398 const FeCache feCache_;
400 std::vector<std::vector<SubControlVolume>> scvs_;
401 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
405 std::size_t numScvf_;
406 std::size_t numBoundaryScvf_;
409 std::vector<bool> boundaryDofIndices_;
410 std::vector<bool> fractureDofIndices_;
420template<
class Scalar,
class GV,
class Traits>
426 using GridIndexType =
typename GV::IndexSet::IndexType;
428 static const int dim = GV::dimension;
429 static const int dimWorld = GV::dimensionworld;
431 using Element =
typename GV::template Codim<0>::Entity;
432 using Intersection =
typename GV::Intersection;
433 using CoordScalar =
typename GV::ctype;
451 using FeCache = Dune::LagrangeLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
456 template<
class FractureGr
idAdapter >
461 update_(fractureGridAdapter);
480 {
return numBoundaryScvf_; }
484 {
return this->
gridView().size(dim); }
487 template<
class FractureGr
idAdapter >
491 updateFacetMapper_();
492 update_(fractureGridAdapter);
496 template<
class FractureGr
idAdapter >
500 updateFacetMapper_();
501 update_(fractureGridAdapter);
507 bool dofOnBoundary(
unsigned int dofIdx)
const {
return boundaryDofIndices_[dofIdx]; }
509 bool dofOnFracture(
unsigned int dofIdx)
const {
return fractureDofIndices_[dofIdx]; }
515 {
return facetOnFracture_[facetMapper_.subIndex(
element, intersection.indexInInside(), 1)]; }
519 { DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box-dfm scheme"); }
523 {
return std::unordered_map<std::size_t, std::size_t>(); }
527 void updateFacetMapper_()
529 facetMapper_.update(this->gridView());
532 template<
class FractureGr
idAdapter >
533 void update_(
const FractureGridAdapter& fractureGridAdapter)
535 boundaryDofIndices_.assign(numDofs(),
false);
536 fractureDofIndices_.assign(numDofs(),
false);
537 facetOnFracture_.assign(this->gridView().size(1),
false);
543 numBoundaryScvf_ = 0;
544 for (
const auto& element : elements(this->gridView()))
546 numScv_ += element.subEntities(dim);
547 numScvf_ += element.subEntities(dim-1);
549 const auto elementGeometry = element.geometry();
550 const auto refElement = referenceElement(elementGeometry);
553 for (
const auto& intersection : intersections(this->gridView(), element))
556 const auto& isGeometry = intersection.geometry();
557 const auto numCorners = isGeometry.corners();
558 const auto idxInInside = intersection.indexInInside();
560 std::vector<GridIndexType> isVertexIndices(numCorners);
561 for (
unsigned int vIdxLocal = 0; vIdxLocal < numCorners; ++vIdxLocal)
562 isVertexIndices[vIdxLocal] = this->vertexMapper().subIndex(element,
563 refElement.subEntity(idxInInside, 1, vIdxLocal, dim),
566 if (intersection.boundary() && !intersection.neighbor())
568 numScvf_ += numCorners;
569 numBoundaryScvf_ += numCorners;
573 const auto fIdx = intersection.indexInInside();
574 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
575 for (
int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
577 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
578 const auto vIdxGlobal = this->vertexMapper().subIndex(element, vIdx, dim);
579 boundaryDofIndices_[vIdxGlobal] =
true;
584 else if (intersection.boundary() && intersection.neighbor())
585 DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box-dfm scheme");
588 if (fractureGridAdapter.composeFacetElement(isVertexIndices))
590 facetOnFracture_[facetMapper_.subIndex(element, idxInInside, 1)] =
true;
591 for (
auto vIdx : isVertexIndices)
592 fractureDofIndices_[vIdx] =
true;
594 const auto isGeometry = intersection.geometry();
595 numScv_ += isGeometry.corners();
596 numScvf_ += dim == 3 ? referenceElement(isGeometry).size(1) : 1;
602 const FeCache feCache_;
607 std::size_t numScvf_;
608 std::size_t numBoundaryScvf_;
611 std::vector<bool> boundaryDofIndices_;
612 std::vector<bool> fractureDofIndices_;
615 typename Traits::FacetMapper facetMapper_;
616 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.
Base class for grid geometries.
Helper classes to compute the integration elements.
The available discretization methods in Dumux.
BaseGridGeometry(std::shared_ptr< BaseImplementation > impl)
Constructor from a BaseImplementation.
Definition basegridgeometry.hh:81
@ element
Definition fieldtype.hh:35
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition adapt.hh:29
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition extrusion.hh:251
Definition deprecated.hh:149
CVFE< CVFEMethods::PQ1 > Box
Definition method.hh:83
std::size_t numCorners(Shape shape)
Returns the number of corners of a given geometry.
Definition throatproperties.hh:232
Element element(GridIndexType eIdx) const
Get an element from a global element index.
Definition basegridgeometry.hh:151
const VertexMapper & vertexMapper() const
Returns the mapper for vertices to indices for constant grids.
Definition basegridgeometry.hh:115
const GridView & gridView() const
Return the gridView this grid geometry object lives on.
Definition basegridgeometry.hh:109
void update(const GridView &gridView)
Update all fvElementGeometries (call this after grid adaption).
Definition basegridgeometry.hh:97
Base class for the finite volume geometry vector for box discrete fracture model.
Definition porousmediumflow/boxdfm/fvelementgeometry.hh:53
The default traits for the box finite volume grid geometry.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:63
BoxDfmSubControlVolume< GridView > SubControlVolume
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:64
BoxDfmSubControlVolumeFace< GridView > SubControlVolumeFace
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:65
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > FacetMapper
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:71
BoxDfmFVElementGeometry< GridGeometry, enableCache > LocalView
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:68
Base class for the finite volume geometry vector for box schemes.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:86
typename Traits::SubControlVolume SubControlVolume
Export the type of sub control volume.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:124
Dune::LagrangeLocalFiniteElementCache< CoordScalar, Scalar, dim, 1 > FeCache
Export the finite element cache type.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:132
std::unordered_map< std::size_t, std::size_t > periodicVertexMap() const
Returns the map between dofs across periodic boundaries.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:200
const std::vector< SubControlVolumeFace > & scvfs(GridIndexType eIdx) const
Get the local scvfs for an element.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:187
std::size_t numDofs() const
The total number of degrees of freedom.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:163
typename Traits::VertexMapper DofMapper
Export dof mapper type.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:130
BoxDfmFVGridGeometry(const GridView gridView, const FractureGridAdapter &fractureGridAdapter)
Constructor.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:138
GV GridView
Export the grid view type.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:134
void update(GridView &&gridView, const FractureGridAdapter &fractureGridAdapter)
update all fvElementGeometries (call this after grid adaption)
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:176
const std::vector< SubControlVolume > & scvs(GridIndexType eIdx) const
Get the local scvs for an element.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:185
Extrusion_t< Traits > Extrusion
Export the extrusion type.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:128
typename Traits::template LocalView< ThisType, true > LocalView
Export the type of the fv element geometry (the local view type).
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:122
const DofMapper & dofMapper() const
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:146
std::size_t numScvf() const
The total number of sun control volume faces.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:154
std::size_t numScv() const
The total number of sub control volumes.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:150
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:196
DiscretizationMethods::Box DiscretizationMethod
export the discretization method this geometry belongs to
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:118
std::size_t numBoundaryScvf() const
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:159
static constexpr DiscretizationMethod discMethod
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:119
bool dofOnBoundary(unsigned int dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:189
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:183
void update(const GridView &gridView, const FractureGridAdapter &fractureGridAdapter)
update all fvElementGeometries (call this after grid adaption)
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:168
typename Traits::SubControlVolumeFace SubControlVolumeFace
Export the type of sub control volume.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:126
bool dofOnPeriodicBoundary(std::size_t dofIdx) const
Periodic boundaries are not supported for the box-dfm scheme.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:193
bool dofOnFracture(unsigned int dofIdx) const
If a vertex / d.o.f. is on a fracture.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:191
Extrusion_t< Traits > Extrusion
Export the extrusion type.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:447
bool dofOnBoundary(unsigned int dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:507
bool dofOnPeriodicBoundary(std::size_t dofIdx) const
Periodic boundaries are not supported for the box-dfm scheme.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:511
BoxDfmFVGridGeometry(const GridView gridView, const FractureGridAdapter &fractureGridAdapter)
Constructor.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:457
std::size_t numScv() const
The total number of sub control volumes.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:470
bool isOnFracture(const Element &element, const Intersection &intersection) const
Returns true if an intersection coincides with a fracture element.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:514
std::unordered_map< std::size_t, std::size_t > periodicVertexMap() const
Returns the map between dofs across periodic boundaries.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:522
std::size_t numDofs() const
The total number of degrees of freedom.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:483
static constexpr DiscretizationMethod discMethod
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:438
std::size_t numBoundaryScvf() const
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:479
void update(const GridView &gridView, const FractureGridAdapter &fractureGridAdapter)
update all fvElementGeometries (call this after grid adaption)
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:488
GV GridView
export the grid view type
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:453
typename Traits::VertexMapper DofMapper
export dof mapper type
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:449
typename Traits::template LocalView< ThisType, false > LocalView
export the type of the fv element geometry (the local view type)
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:441
std::size_t numScvf() const
The total number of sun control volume faces.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:474
Dune::LagrangeLocalFiniteElementCache< CoordScalar, Scalar, dim, 1 > FeCache
export the finite element cache type
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:451
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:505
const DofMapper & dofMapper() const
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:466
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:445
DiscretizationMethods::Box DiscretizationMethod
export the discretization method this geometry belongs to
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:437
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:443
bool dofOnFracture(unsigned int dofIdx) const
If a vertex / d.o.f. is on a fracture.
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:509
void update(GridView &&gridView, const FractureGridAdapter &fractureGridAdapter)
update all fvElementGeometries (call this after grid adaption)
Definition porousmediumflow/boxdfm/fvgridgeometry.hh:497
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:518
Create sub control volumes and sub control volume face geometries.
Definition porousmediumflow/boxdfm/geometryhelper.hh:59
the sub control volume for the box discrete fracture scheme
Definition porousmediumflow/boxdfm/subcontrolvolume.hh:76
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:77
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.