15#ifndef DUMUX_FACETCOUPLING_BOX_GRID_FVGEOMETRY_HH
16#define DUMUX_FACETCOUPLING_BOX_GRID_FVGEOMETRY_HH
21#include <dune/grid/common/mcmgmapper.hh>
22#include <dune/localfunctions/lagrange/lagrangelfecache.hh>
38template<
class GV,
class T>
53template<
class Gr
idView>
60 template<
class Gr
idGeometry,
bool enableCache>
64 using ElementMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
68 using FacetMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
80 bool enableGridGeometryCache =
false,
91template<
class Scalar,
class GV,
class Traits>
100 using Element =
typename GV::template Codim<0>::Entity;
101 using CoordScalar =
typename GV::ctype;
102 static const int dim = GV::dimension;
103 static const int dimWorld = GV::dimensionworld;
121 using FeCache = Dune::LagrangeLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
126 template<
class FacetGr
idView,
class CodimOneGr
idAdapter>
128 const FacetGridView& facetGridView,
130 bool verbose =
false)
134 update_(facetGridView, codimOneGridAdapter, verbose);
152 {
return numBoundaryScvf_; }
171 template<
class FacetGr
idView,
class CodimOneGr
idAdapter>
173 const FacetGridView& facetGridView,
175 bool verbose =
false)
178 update_(facetGridView, codimOneGridAdapter, verbose);
182 template<
class FacetGr
idView,
class CodimOneGr
idAdapter>
184 const FacetGridView& facetGridView,
186 bool verbose =
false)
189 update_(facetGridView, codimOneGridAdapter, verbose);
198 {
return boundaryDofIndices_[dofIdx]; }
202 {
return interiorBoundaryDofIndices_[dofIdx]; }
210 { DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box facet coupling scheme"); }
214 {
return { gg.cache_ }; }
217 class BoxFacetCouplingGridGeometryCache
223 using DofHelper =
typename GeometryHelper::DofHelper;
229 const BoxFacetCouplingFVGridGeometry& gridGeometry()
const
230 {
return *gridGeometry_; }
233 const std::vector<SubControlVolume>&
scvs(GridIndexType eIdx)
const
234 {
return scvs_[eIdx]; }
237 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx)
const
238 {
return scvfs_[eIdx]; }
248 std::vector<std::vector<SubControlVolume>> scvs_;
249 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
251 const BoxFacetCouplingFVGridGeometry* gridGeometry_;
257 using Cache = BoxFacetCouplingGridGeometryCache;
260 using GeometryHelper =
typename Cache::GeometryHelper;
262 template<
class FacetGr
idView,
class CodimOneGr
idAdapter>
263 void update_(
const FacetGridView& facetGridView,
265 bool verbose =
false)
268 this->
vertexMapper().enrich(facetGridView, codimOneGridAdapter, verbose);
274 const auto numElements = this->
gridView().size(0);
275 cache_.scvs_.resize(numElements);
276 cache_.scvfs_.resize(numElements);
277 boundaryDofIndices_.assign(numDof,
false);
278 interiorBoundaryDofIndices_.assign(numDof,
false);
283 numBoundaryScvf_ = 0;
289 numScv_ +=
element.subEntities(dim);
290 numScvf_ +=
element.subEntities(dim-1);
293 auto elementGeometry =
element.geometry();
294 const auto refElement = referenceElement(elementGeometry);
297 GeometryHelper geometryHelper(elementGeometry);
300 cache_.scvs_[eIdx].resize(elementGeometry.corners());
301 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
302 cache_.scvs_[eIdx][scvLocalIdx] =
SubControlVolume(geometryHelper.getScvCorners(scvLocalIdx),
305 this->vertexMapper().subIndex(
element, scvLocalIdx, dim));
308 LocalIndexType scvfLocalIdx = 0;
309 cache_.scvfs_[eIdx].resize(
element.subEntities(dim-1));
310 for (; scvfLocalIdx <
element.subEntities(dim-1); ++scvfLocalIdx)
313 std::array<LocalIndexType, 2> localScvIndices{{
314 static_cast<LocalIndexType
>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
315 static_cast<LocalIndexType
>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))
322 std::move(localScvIndices));
327 std::vector<unsigned int> handledFacets;
328 for (
const auto& intersection : intersections(this->
gridView(),
element))
330 if (std::count(handledFacets.begin(), handledFacets.end(), intersection.indexInInside()))
333 handledFacets.push_back(intersection.indexInInside());
336 const auto isGeometry = intersection.geometry();
337 const auto numFaceCorners = isGeometry.corners();
338 const auto idxInInside = intersection.indexInInside();
339 const auto boundary = intersection.boundary();
341 std::vector<LocalIndexType> vIndicesLocal(numFaceCorners);
342 for (
int i = 0; i < numFaceCorners; ++i)
343 vIndicesLocal[i] =
static_cast<LocalIndexType
>(refElement.subEntity(idxInInside, 1, i, dim));
345 std::vector<LocalIndexType> gridVertexIndices(numFaceCorners);
346 for (
int i = 0; i < numFaceCorners; ++i)
353 if (boundary && intersection.neighbor())
354 DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box facet coupling scheme");
356 if (isOnFacet || boundary)
359 numScvf_ += numFaceCorners;
360 numBoundaryScvf_ += int(boundary)*numFaceCorners;
362 for (
unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < numFaceCorners; ++isScvfLocalIdx)
365 std::array<LocalIndexType, 2> localScvIndices{{
366 vIndicesLocal[isScvfLocalIdx], vIndicesLocal[isScvfLocalIdx]
370 cache_.scvfs_[eIdx].emplace_back(geometryHelper,
374 std::move(localScvIndices),
379 const auto dofIndex = this->
vertexMapper().subIndex(
element, vIndicesLocal[isScvfLocalIdx], dim);
380 if (boundary) boundaryDofIndices_[ dofIndex ] = boundary && !isOnFacet;
381 if (isOnFacet) interiorBoundaryDofIndices_[ dofIndex ] = isOnFacet;
391 const FeCache feCache_;
395 std::size_t numScvf_;
396 std::size_t numBoundaryScvf_;
399 std::vector<bool> boundaryDofIndices_;
400 std::vector<bool> interiorBoundaryDofIndices_;
412template<
class Scalar,
class GV,
class Traits>
421 static const int dim = GV::dimension;
422 static const int dimWorld = GV::dimensionworld;
424 using Element =
typename GV::template Codim<0>::Entity;
425 using Intersection =
typename GV::Intersection;
426 using CoordScalar =
typename GV::ctype;
444 using FeCache = Dune::LagrangeLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
449 template<
class FacetGr
idView,
class CodimOneGr
idAdapter>
451 const FacetGridView& facetGridView,
453 bool verbose =
false)
458 update_(facetGridView, codimOneGridAdapter, verbose);
477 {
return numBoundaryScvf_; }
496 template<
class FacetGr
idView,
class CodimOneGr
idAdapter>
498 const FacetGridView& facetGridView,
500 bool verbose =
false)
503 updateFacetMapper_();
504 update_(facetGridView, codimOneGridAdapter, verbose);
508 template<
class FacetGr
idView,
class CodimOneGr
idAdapter>
510 const FacetGridView& facetGridView,
512 bool verbose =
false)
515 updateFacetMapper_();
516 update_(facetGridView, codimOneGridAdapter, verbose);
525 {
return boundaryDofIndices_[dofIdx]; }
529 {
return interiorBoundaryDofIndices_[dofIdx]; }
533 {
return facetIsOnInteriorBoundary_[ facetMapper_.subIndex(
element, intersection.indexInInside(), 1) ]; }
541 { DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the facet coupling scheme"); }
545 {
return { gg.cache_ }; }
549 class BoxFacetCouplingGridGeometryCache
555 using DofHelper =
typename GeometryHelper::DofHelper;
561 const BoxFacetCouplingFVGridGeometry& gridGeometry()
const
562 {
return *gridGeometry_; }
565 const BoxFacetCouplingFVGridGeometry* gridGeometry_;
571 using Cache = BoxFacetCouplingGridGeometryCache;
575 void updateFacetMapper_()
577 facetMapper_.update(this->
gridView());
580 template<
class FacetGr
idView,
class CodimOneGr
idAdapter>
581 void update_(
const FacetGridView& facetGridView,
586 this->vertexMapper().enrich(facetGridView, codimOneGridAdapter, verbose);
592 numBoundaryScvf_ = 0;
594 const auto numDof = numDofs();
595 boundaryDofIndices_.assign(numDof,
false);
596 interiorBoundaryDofIndices_.assign(numDof,
false);
597 facetIsOnInteriorBoundary_.assign(this->gridView().size(1),
false);
598 for (
const auto& element : elements(this->gridView()))
600 numScv_ += element.subEntities(dim);
601 numScvf_ += element.subEntities(dim-1);
603 const auto elementGeometry = element.geometry();
604 const auto refElement = referenceElement(elementGeometry);
608 std::vector<unsigned int> handledFacets;
609 for (
const auto& intersection : intersections(this->gridView(), element))
611 if (std::count(handledFacets.begin(), handledFacets.end(), intersection.indexInInside()))
614 handledFacets.push_back(intersection.indexInInside());
617 const auto isGeometry = intersection.geometry();
618 const auto numFaceCorners = isGeometry.corners();
619 const auto idxInInside = intersection.indexInInside();
620 const auto boundary = intersection.boundary();
622 std::vector<LocalIndexType> vIndicesLocal(numFaceCorners);
623 for (
int i = 0; i < numFaceCorners; ++i)
624 vIndicesLocal[i] =
static_cast<LocalIndexType
>(refElement.subEntity(idxInInside, 1, i, dim));
626 std::vector<GridIndexType> gridVertexIndices(numFaceCorners);
627 for (
int i = 0; i < numFaceCorners; ++i)
628 gridVertexIndices[i] = this->vertexMapper().vertexIndex(element, vIndicesLocal[i], dim);
634 if (boundary && intersection.neighbor())
635 DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box facet coupling scheme");
637 if (isOnFacet || boundary)
639 numScvf_ += numFaceCorners;
640 numBoundaryScvf_ += int(boundary)*numFaceCorners;
643 for (
int i = 0; i < numFaceCorners; ++i)
645 const auto dofIndex = this->vertexMapper().subIndex(element, vIndicesLocal[i], dim);
646 if (boundary) boundaryDofIndices_[ dofIndex ] = boundary && !isOnFacet;
649 interiorBoundaryDofIndices_[ dofIndex ] =
true;
650 facetIsOnInteriorBoundary_[ facetMapper_.subIndex(element, idxInInside, 1) ] =
true;
658 const FeCache feCache_;
663 std::size_t numScvf_;
664 std::size_t numBoundaryScvf_;
667 std::vector<bool> boundaryDofIndices_;
668 std::vector<bool> interiorBoundaryDofIndices_;
671 typename Traits::FacetMapper facetMapper_;
672 std::vector<bool> facetIsOnInteriorBoundary_;
Base class for grid geometries.
Helper class constructing the dual grid finite volume geometries for the box discretizazion method.
const ElementMapper & elementMapper() const
Returns the mapper for elements to indices for constant grids.
Definition basegridgeometry.hh:112
Element element(GridIndexType eIdx) const
Get an element from a global element index.
Definition basegridgeometry.hh:142
const VertexMapper & vertexMapper() const
Returns the mapper for vertices to indices for constant grids.
Definition basegridgeometry.hh:106
const GridView & gridView() const
Return the gridView this grid geometry object lives on.
Definition basegridgeometry.hh:100
void update(const GridView &gridView)
Update all fvElementGeometries (call this after grid adaption).
Definition basegridgeometry.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:36
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition multidomain/facet/box/fvgridgeometry.hh:436
BoxFacetCouplingFVGridGeometry(const GridView &gridView, const FacetGridView &facetGridView, const CodimOneGridAdapter &codimOneGridAdapter, bool verbose=false)
Constructor.
Definition multidomain/facet/box/fvgridgeometry.hh:450
std::size_t numScv() const
The total number of sub control volumes.
Definition multidomain/facet/box/fvgridgeometry.hh:467
std::size_t numScvf() const
The total number of sun control volume faces.
Definition multidomain/facet/box/fvgridgeometry.hh:471
GV GridView
export the grid view type
Definition multidomain/facet/box/fvgridgeometry.hh:446
DiscretizationMethods::Box DiscretizationMethod
export the discretization method this geometry belongs to
Definition multidomain/facet/box/fvgridgeometry.hh:430
std::size_t numDofs() const
The total number of degrees of freedom.
Definition multidomain/facet/box/fvgridgeometry.hh:480
void update(GridView &&gridView, const FacetGridView &facetGridView, const CodimOneGridAdapter &codimOneGridAdapter, bool verbose=false)
update all fvElementGeometries (call this after grid adaption)
Definition multidomain/facet/box/fvgridgeometry.hh:509
std::size_t numBoundaryScvf() const
Definition multidomain/facet/box/fvgridgeometry.hh:476
Dune::LagrangeLocalFiniteElementCache< CoordScalar, Scalar, dim, 1 > FeCache
export the finite element cache type
Definition multidomain/facet/box/fvgridgeometry.hh:444
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition multidomain/facet/box/fvgridgeometry.hh:520
typename Traits::VertexMapper DofMapper
export dof mapper type
Definition multidomain/facet/box/fvgridgeometry.hh:442
const DofMapper & dofMapper() const
Definition multidomain/facet/box/fvgridgeometry.hh:463
friend LocalView localView(const BoxFacetCouplingFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition multidomain/facet/box/fvgridgeometry.hh:544
static constexpr DiscretizationMethod discMethod
Definition multidomain/facet/box/fvgridgeometry.hh:431
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:434
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:540
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
Periodic boundaries are not supported for the box facet coupling scheme.
Definition multidomain/facet/box/fvgridgeometry.hh:536
BoxFacetCouplingGridGeometryCache Cache
Definition multidomain/facet/box/fvgridgeometry.hh:571
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition multidomain/facet/box/fvgridgeometry.hh:438
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition multidomain/facet/box/fvgridgeometry.hh:440
bool dofOnBoundary(unsigned int dofIdx) const
If a d.o.f. is on the boundary.
Definition multidomain/facet/box/fvgridgeometry.hh:524
void update(const GridView &gridView, const FacetGridView &facetGridView, const CodimOneGridAdapter &codimOneGridAdapter, bool verbose=false)
update all fvElementGeometries (call this after grid adaption)
Definition multidomain/facet/box/fvgridgeometry.hh:497
bool dofOnInteriorBoundary(unsigned int dofIdx) const
If a d.o.f. is on an interior boundary.
Definition multidomain/facet/box/fvgridgeometry.hh:528
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:532
bool dofOnInteriorBoundary(GridIndexType dofIdx) const
If a d.o.f. is on an interior boundary.
Definition multidomain/facet/box/fvgridgeometry.hh:201
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:209
void update(const GridView &gridView, const FacetGridView &facetGridView, const CodimOneGridAdapter &codimOneGridAdapter, bool verbose=false)
update all fvElementGeometries (call this after grid adaption)
Definition multidomain/facet/box/fvgridgeometry.hh:172
Dune::LagrangeLocalFiniteElementCache< CoordScalar, Scalar, dim, 1 > FeCache
export the finite element cache type
Definition multidomain/facet/box/fvgridgeometry.hh:121
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition multidomain/facet/box/fvgridgeometry.hh:117
static constexpr DiscretizationMethod discMethod
Definition multidomain/facet/box/fvgridgeometry.hh:108
BoxFacetCouplingGridGeometryCache Cache
Definition multidomain/facet/box/fvgridgeometry.hh:257
GV GridView
export the grid view type
Definition multidomain/facet/box/fvgridgeometry.hh:123
std::size_t numScv() const
The total number of sub control volumes.
Definition multidomain/facet/box/fvgridgeometry.hh:142
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
Periodic boundaries are not supported for the box facet coupling scheme.
Definition multidomain/facet/box/fvgridgeometry.hh:205
bool dofOnBoundary(GridIndexType dofIdx) const
If a d.o.f. is on the boundary.
Definition multidomain/facet/box/fvgridgeometry.hh:197
typename Traits::VertexMapper DofMapper
export dof mapper type
Definition multidomain/facet/box/fvgridgeometry.hh:119
std::size_t numBoundaryScvf() const
Definition multidomain/facet/box/fvgridgeometry.hh:151
const DofMapper & dofMapper() const
the vertex mapper is the dofMapper
Definition multidomain/facet/box/fvgridgeometry.hh:138
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition multidomain/facet/box/fvgridgeometry.hh:113
friend LocalView localView(const BoxFacetCouplingFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition multidomain/facet/box/fvgridgeometry.hh:213
std::size_t numScvf() const
The total number of sun control volume faces.
Definition multidomain/facet/box/fvgridgeometry.hh:146
void update(GridView &&gridView, const FacetGridView &facetGridView, const CodimOneGridAdapter &codimOneGridAdapter, bool verbose=false)
update all fvElementGeometries (call this after grid adaption)
Definition multidomain/facet/box/fvgridgeometry.hh:183
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition multidomain/facet/box/fvgridgeometry.hh:193
std::size_t numDofs() const
The total number of degrees of freedom.
Definition multidomain/facet/box/fvgridgeometry.hh:155
BoxFacetCouplingFVGridGeometry(const GridView &gridView, const FacetGridView &facetGridView, const CodimOneGridAdapter &codimOneGridAdapter, bool verbose=false)
Constructor.
Definition multidomain/facet/box/fvgridgeometry.hh:127
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:111
DiscretizationMethods::Box DiscretizationMethod
export the discretization method this geometry belongs to
Definition multidomain/facet/box/fvgridgeometry.hh:107
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition multidomain/facet/box/fvgridgeometry.hh:115
Base class for the finite volume geometry vector for box schemes in the context of coupled models whe...
Definition multidomain/facet/box/fvgridgeometry.hh:82
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:39
Create sub control volumes and sub control volume face geometries.
Definition boxgeometryhelper.hh:261
the sub control volume for the box scheme
Definition discretization/box/subcontrolvolume.hh:58
Adapter that allows retrieving information on a d-dimensional grid for entities of a (d-1)-dimensiona...
Definition codimonegridadapter.hh:40
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:180
A vertex mapper that allows for enrichment of nodes. Indication on where to enrich the nodes is done ...
Definition vertexmapper.hh:126
the sub control volume for the box scheme
Helper classes to compute the integration elements.
BaseGridGeometry(std::shared_ptr< BaseImplementation > impl)
Constructor from a BaseImplementation.
Definition basegridgeometry.hh:72
The available discretization methods in Dumux.
Base class for the element-local finite volume geometry for box models in the context of models consi...
Base class for a sub control volume face of the box method in the context of of models considering co...
Definition cvfelocalresidual.hh:25
Dune::Std::detected_or_t< Dumux::BoxGeometryHelper< GV, GV::dimension, typename T::SubControlVolume, typename T::SubControlVolumeFace >, SpecifiesGeometryHelper, T > BoxFacetCouplingGeometryHelper_t
Definition multidomain/facet/box/fvgridgeometry.hh:39
typename T::GeometryHelper SpecifiesGeometryHelper
Definition basegridgeometry.hh:30
CVFE< CVFEMethods::PQ1 > Box
Definition method.hh:102
std::ranges::range auto scvs(const FVElementGeometry &fvGeometry, const LocalDof &localDof)
Definition localdof.hh:82
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition extrusion.hh:257
Definition common/pdesolver.hh:24
The default traits for the finite volume grid geometry of the box scheme with coupling occurring acro...
Definition multidomain/facet/box/fvgridgeometry.hh:55
BoxFacetCouplingFVElementGeometry< GridGeometry, enableCache > LocalView
Definition multidomain/facet/box/fvgridgeometry.hh:61
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > FacetMapper
Definition multidomain/facet/box/fvgridgeometry.hh:68
BoxFacetCouplingSubControlVolumeFace< GridView > SubControlVolumeFace
Definition multidomain/facet/box/fvgridgeometry.hh:58
EnrichedVertexDofMapper< GridView > VertexMapper
Definition multidomain/facet/box/fvgridgeometry.hh:66
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > ElementMapper
Definition multidomain/facet/box/fvgridgeometry.hh:64
BoxSubControlVolume< GridView > SubControlVolume
Definition multidomain/facet/box/fvgridgeometry.hh:57
typename GridView::IndexSet::IndexType GridIndex
Definition indextraits.hh:27
unsigned int LocalIndex
Definition indextraits.hh:28
A vertex mapper that allows for enrichment of nodes. Indication on where to enrich the nodes is done ...