27#ifndef DUMUX_FACETCOUPLING_BOX_GRID_FVGEOMETRY_HH
28#define DUMUX_FACETCOUPLING_BOX_GRID_FVGEOMETRY_HH
32#include <dune/grid/common/mcmgmapper.hh>
33#include <dune/localfunctions/lagrange/pqkfactory.hh>
55template<
class Gr
idView>
62 template<
class Gr
idGeometry,
bool enableCache>
66 using ElementMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
70 using FacetMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
82 bool enableGridGeometryCache =
false,
93template<
class Scalar,
class GV,
class Traits>
102 using Element =
typename GV::template Codim<0>::Entity;
103 using CoordScalar =
typename GV::ctype;
104 static const int dim = GV::dimension;
105 static const int dimWorld = GV::dimensionworld;
124 using FeCache = Dune::PQkLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
134 {
return this->vertexMapper(); }
147 {
return numBoundaryScvf_; }
151 {
return this->vertexMapper().size(); }
164 template<
class FacetGr
idView,
class CodimOneGr
idAdapter>
165 void update(
const FacetGridView& facetGridView,
167 bool verbose =
false)
170 ParentType::update();
173 this->vertexMapper().enrich(facetGridView, codimOneGridAdapter, verbose);
176 const auto numDof = numDofs();
177 const auto numElements = this->gridView().size(0);
180 scvs_.resize(numElements);
181 scvfs_.resize(numElements);
182 boundaryDofIndices_.assign(numDof,
false);
183 interiorBoundaryDofIndices_.assign(numDof,
false);
188 numBoundaryScvf_ = 0;
189 for (
const auto& element : elements(this->gridView()))
191 auto eIdx = this->elementMapper().index(element);
194 numScv_ += element.subEntities(dim);
195 numScvf_ += element.subEntities(dim-1);
198 auto elementGeometry = element.geometry();
199 const auto refElement = referenceElement(elementGeometry);
206 scvs_[eIdx].reserve(elementGeometry.corners());
207 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
208 scvs_[eIdx].emplace_back(geometryHelper,
211 this->vertexMapper().subIndex(element, scvLocalIdx, dim));
214 LocalIndexType scvfLocalIdx = 0;
215 scvfs_[eIdx].clear();
216 scvfs_[eIdx].reserve(element.subEntities(dim-1));
217 for (; scvfLocalIdx < element.subEntities(dim-1); ++scvfLocalIdx)
220 std::vector<LocalIndexType> localScvIndices({
static_cast<LocalIndexType
>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
221 static_cast<LocalIndexType
>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
224 scvfs_[eIdx].emplace_back(geometryHelper,
228 std::move(localScvIndices));
233 std::vector<unsigned int> handledFacets;
234 for (
const auto& intersection : intersections(this->gridView(), element))
236 if (std::count(handledFacets.begin(), handledFacets.end(), intersection.indexInInside()))
239 handledFacets.push_back(intersection.indexInInside());
242 const auto isGeometry = intersection.geometry();
243 const auto numFaceCorners = isGeometry.corners();
244 const auto idxInInside = intersection.indexInInside();
245 const auto boundary = intersection.boundary();
247 std::vector<LocalIndexType> vIndicesLocal(numFaceCorners);
248 for (
int i = 0; i < numFaceCorners; ++i)
249 vIndicesLocal[i] =
static_cast<LocalIndexType
>(refElement.subEntity(idxInInside, 1, i, dim));
251 std::vector<LocalIndexType> gridVertexIndices(numFaceCorners);
252 for (
int i = 0; i < numFaceCorners; ++i)
253 gridVertexIndices[i] = this->vertexMapper().vertexIndex(element, vIndicesLocal[i], dim);
259 if (boundary && intersection.neighbor())
260 DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box facet coupling scheme");
263 if (isOnFacet || boundary)
266 numScvf_ += numFaceCorners;
267 numBoundaryScvf_ += int(boundary)*numFaceCorners;
269 for (
unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < numFaceCorners; ++isScvfLocalIdx)
272 std::vector<LocalIndexType> localScvIndices = {vIndicesLocal[isScvfLocalIdx], vIndicesLocal[isScvfLocalIdx]};
275 scvfs_[eIdx].emplace_back(geometryHelper,
280 std::move(localScvIndices),
285 const auto dofIndex = this->vertexMapper().subIndex(element, vIndicesLocal[isScvfLocalIdx], dim);
286 if (boundary) boundaryDofIndices_[ dofIndex ] = boundary;
287 if (isOnFacet) interiorBoundaryDofIndices_[ dofIndex ] = isOnFacet;
302 const std::vector<SubControlVolume>&
scvs(GridIndexType eIdx)
const
303 {
return scvs_[eIdx]; }
306 const std::vector<SubControlVolumeFace>&
scvfs(GridIndexType eIdx)
const
307 {
return scvfs_[eIdx]; }
311 {
return boundaryDofIndices_[dofIdx]; }
315 {
return interiorBoundaryDofIndices_[dofIdx]; }
323 { DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box facet coupling scheme"); }
327 {
return std::unordered_map<GridIndexType, GridIndexType>(); }
330 const FeCache feCache_;
332 std::vector<std::vector<SubControlVolume>> scvs_;
333 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
337 std::size_t numScvf_;
338 std::size_t numBoundaryScvf_;
341 std::vector<bool> boundaryDofIndices_;
342 std::vector<bool> interiorBoundaryDofIndices_;
352template<
class Scalar,
class GV,
class Traits>
361 static const int dim = GV::dimension;
362 static const int dimWorld = GV::dimensionworld;
364 using Element =
typename GV::template Codim<0>::Entity;
365 using Intersection =
typename GV::Intersection;
366 using CoordScalar =
typename GV::ctype;
383 using FeCache = Dune::PQkLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
390 , facetMapper_(gridView,
Dune::mcmgLayout(
Dune::template Codim<1>()))
396 {
return this->vertexMapper(); }
409 {
return numBoundaryScvf_; }
413 {
return this->vertexMapper().size(); }
426 template<
class FacetGr
idView,
class CodimOneGr
idAdapter>
427 void update(
const FacetGridView& facetGridView,
429 bool verbose =
false)
432 ParentType::update();
435 this->vertexMapper().enrich(facetGridView, codimOneGridAdapter, verbose);
441 numBoundaryScvf_ = 0;
443 const auto numDof = numDofs();
444 boundaryDofIndices_.assign(numDof,
false);
445 interiorBoundaryDofIndices_.assign(numDof,
false);
446 facetIsOnInteriorBoundary_.assign(this->gridView().size(1),
false);
447 for (
const auto& element : elements(this->gridView()))
449 numScv_ += element.subEntities(dim);
450 numScvf_ += element.subEntities(dim-1);
452 const auto elementGeometry = element.geometry();
453 const auto refElement = referenceElement(elementGeometry);
457 std::vector<unsigned int> handledFacets;
458 for (
const auto& intersection : intersections(this->gridView(), element))
460 if (std::count(handledFacets.begin(), handledFacets.end(), intersection.indexInInside()))
463 handledFacets.push_back(intersection.indexInInside());
466 const auto isGeometry = intersection.geometry();
467 const auto numFaceCorners = isGeometry.corners();
468 const auto idxInInside = intersection.indexInInside();
469 const auto boundary = intersection.boundary();
471 std::vector<LocalIndexType> vIndicesLocal(numFaceCorners);
472 for (
int i = 0; i < numFaceCorners; ++i)
473 vIndicesLocal[i] =
static_cast<LocalIndexType
>(refElement.subEntity(idxInInside, 1, i, dim));
475 std::vector<GridIndexType> gridVertexIndices(numFaceCorners);
476 for (
int i = 0; i < numFaceCorners; ++i)
477 gridVertexIndices[i] = this->vertexMapper().vertexIndex(element, vIndicesLocal[i], dim);
483 if (boundary && intersection.neighbor())
484 DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box facet coupling scheme");
486 if (isOnFacet || boundary)
488 numScvf_ += numFaceCorners;
489 numBoundaryScvf_ += int(boundary)*numFaceCorners;
492 for (
int i = 0; i < numFaceCorners; ++i)
494 const auto dofIndex = this->vertexMapper().subIndex(element, vIndicesLocal[i], dim);
495 if (boundary) boundaryDofIndices_[ dofIndex ] =
true;
498 interiorBoundaryDofIndices_[ dofIndex ] =
true;
499 facetIsOnInteriorBoundary_[ facetMapper_.subIndex(element, idxInInside, 1) ] =
true;
513 {
return boundaryDofIndices_[dofIdx]; }
517 {
return interiorBoundaryDofIndices_[dofIdx]; }
521 {
return facetIsOnInteriorBoundary_[ facetMapper_.subIndex(element, intersection.indexInInside(), 1) ]; }
529 { DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the facet coupling scheme"); }
533 {
return std::unordered_map<GridIndexType, GridIndexType>(); }
536 const FeCache feCache_;
541 std::size_t numScvf_;
542 std::size_t numBoundaryScvf_;
545 std::vector<bool> boundaryDofIndices_;
546 std::vector<bool> interiorBoundaryDofIndices_;
549 typename Traits::FacetMapper facetMapper_;
550 std::vector<bool> facetIsOnInteriorBoundary_;
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.
Helper classes to compute the integration elements.
DiscretizationMethod
The available discretization methods in Dumux.
Definition: method.hh:37
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:177
Definition: common/pdesolver.hh:35
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:49
GV GridView
export the grid view type
Definition: basegridgeometry.hh:64
Create sub control volumes and sub control volume face geometries.
Definition: boxgeometryhelper.hh:36
the sub control volume for the box scheme
Definition: discretization/box/subcontrolvolume.hh:88
Base class for the element-local finite volume geometry for box models in the context of models consi...
Definition: multidomain/facet/box/fvelementgeometry.hh:47
The default traits for the finite volume grid geometry of the box scheme with coupling occuring acros...
Definition: multidomain/facet/box/fvgridgeometry.hh:57
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > FacetMapper
Definition: multidomain/facet/box/fvgridgeometry.hh:70
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > ElementMapper
Definition: multidomain/facet/box/fvgridgeometry.hh:66
Base class for the finite volume geometry vector for box schemes in the context of coupled models whe...
Definition: multidomain/facet/box/fvgridgeometry.hh:84
Base class for the finite volume geometry vector for box schemes in the context of coupled models whe...
Definition: multidomain/facet/box/fvgridgeometry.hh:96
bool dofOnInteriorBoundary(GridIndexType dofIdx) const
If a d.o.f. is on an interior boundary.
Definition: multidomain/facet/box/fvgridgeometry.hh:314
GridIndexType periodicallyMappedDof(GridIndexType dofIdx) const
The index of the vertex / d.o.f. on the other side of the periodic boundary.
Definition: multidomain/facet/box/fvgridgeometry.hh:322
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition: multidomain/facet/box/fvgridgeometry.hh:120
const std::vector< SubControlVolume > & scvs(GridIndexType eIdx) const
Get the local scvs for an element.
Definition: multidomain/facet/box/fvgridgeometry.hh:302
std::size_t numScv() const
The total number of sub control volumes.
Definition: multidomain/facet/box/fvgridgeometry.hh:137
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
Periodic boundaries are not supported for the box facet coupling scheme.
Definition: multidomain/facet/box/fvgridgeometry.hh:318
bool dofOnBoundary(GridIndexType dofIdx) const
If a d.o.f. is on the boundary.
Definition: multidomain/facet/box/fvgridgeometry.hh:310
typename Traits::VertexMapper DofMapper
export dof mapper type
Definition: multidomain/facet/box/fvgridgeometry.hh:122
std::size_t numBoundaryScvf() const
Definition: multidomain/facet/box/fvgridgeometry.hh:146
void update(const FacetGridView &facetGridView, const CodimOneGridAdapter &codimOneGridAdapter, bool verbose=false)
update all fvElementGeometries (do this again after grid adaption)
Definition: multidomain/facet/box/fvgridgeometry.hh:165
const DofMapper & dofMapper() const
the vertex mapper is the dofMapper
Definition: multidomain/facet/box/fvgridgeometry.hh:133
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: multidomain/facet/box/fvgridgeometry.hh:116
std::size_t numScvf() const
The total number of sun control volume faces.
Definition: multidomain/facet/box/fvgridgeometry.hh:141
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition: multidomain/facet/box/fvgridgeometry.hh:298
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: multidomain/facet/box/fvgridgeometry.hh:150
typename Traits::template LocalView< ThisType, true > LocalView
export the type of the fv element geometry (the local view type)
Definition: multidomain/facet/box/fvgridgeometry.hh:114
Dune::PQkLocalFiniteElementCache< CoordScalar, Scalar, dim, 1 > FeCache
export the finite element cache type
Definition: multidomain/facet/box/fvgridgeometry.hh:124
BoxFacetCouplingFVGridGeometry(const GridView &gridView)
Constructor.
Definition: multidomain/facet/box/fvgridgeometry.hh:129
std::unordered_map< GridIndexType, GridIndexType > periodicVertexMap() const
Returns the map between dofs across periodic boundaries.
Definition: multidomain/facet/box/fvgridgeometry.hh:326
const std::vector< SubControlVolumeFace > & scvfs(GridIndexType eIdx) const
Get the local scvfs for an element.
Definition: multidomain/facet/box/fvgridgeometry.hh:306
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: multidomain/facet/box/fvgridgeometry.hh:118
Base class for the finite volume geometry vector for box schemes This builds up the sub control volum...
Definition: multidomain/facet/box/fvgridgeometry.hh:355
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: multidomain/facet/box/fvgridgeometry.hh:375
std::size_t numScv() const
The total number of sub control volumes.
Definition: multidomain/facet/box/fvgridgeometry.hh:399
std::size_t numScvf() const
The total number of sun control volume faces.
Definition: multidomain/facet/box/fvgridgeometry.hh:403
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: multidomain/facet/box/fvgridgeometry.hh:412
std::unordered_map< GridIndexType, GridIndexType > periodicVertexMap() const
Returns the map between dofs across periodic boundaries.
Definition: multidomain/facet/box/fvgridgeometry.hh:532
std::size_t numBoundaryScvf() const
Definition: multidomain/facet/box/fvgridgeometry.hh:408
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition: multidomain/facet/box/fvgridgeometry.hh:508
typename Traits::VertexMapper DofMapper
export dof mapper type
Definition: multidomain/facet/box/fvgridgeometry.hh:381
void update(const FacetGridView &facetGridView, const CodimOneGridAdapter &codimOneGridAdapter, bool verbose=false)
update all fvElementGeometries (do this again after grid adaption)
Definition: multidomain/facet/box/fvgridgeometry.hh:427
const DofMapper & dofMapper() const
Definition: multidomain/facet/box/fvgridgeometry.hh:395
typename Traits::template LocalView< ThisType, false > LocalView
export the type of the fv element geometry (the local view type)
Definition: multidomain/facet/box/fvgridgeometry.hh:373
GridIndexType periodicallyMappedDof(GridIndexType dofIdx) const
The index of the vertex / d.o.f. on the other side of the periodic boundary.
Definition: multidomain/facet/box/fvgridgeometry.hh:528
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
Periodic boundaries are not supported for the box facet coupling scheme.
Definition: multidomain/facet/box/fvgridgeometry.hh:524
Dune::PQkLocalFiniteElementCache< CoordScalar, Scalar, dim, 1 > FeCache
export the finite element cache type
Definition: multidomain/facet/box/fvgridgeometry.hh:383
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: multidomain/facet/box/fvgridgeometry.hh:377
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition: multidomain/facet/box/fvgridgeometry.hh:379
bool dofOnBoundary(unsigned int dofIdx) const
If a d.o.f. is on the boundary.
Definition: multidomain/facet/box/fvgridgeometry.hh:512
bool dofOnInteriorBoundary(unsigned int dofIdx) const
If a d.o.f. is on an interior boundary.
Definition: multidomain/facet/box/fvgridgeometry.hh:516
BoxFacetCouplingFVGridGeometry(const GridView gridView)
Constructor.
Definition: multidomain/facet/box/fvgridgeometry.hh:388
bool isOnInteriorBoundary(const Element &element, const Intersection &intersection) const
returns true if an intersection is on an interior boundary
Definition: multidomain/facet/box/fvgridgeometry.hh:520
Class for a sub control volume face in the box method, i.e a part of the boundary of a sub control vo...
Definition: multidomain/facet/box/subcontrolvolumeface.hh:52
Adapter that allows retrieving information on a d-dimensional grid for entities of a (d-1)-dimensiona...
Definition: codimonegridadapter.hh:52
bool composeFacetElement(const IndexStorage &bulkVertexIndices) const
Returns true if a given set of bulk vertex indices make up a facet grid element.
Definition: codimonegridadapter.hh:192
A vertex mapper that allows for enrichment of nodes. Indication on where to enrich the nodes is done ...
Definition: vertexmapper.hh:142
the sub control volume for the box scheme
Base class for a sub control volume face of the box method in the context of of models considering co...