27#ifndef DUMUX_FACETCOUPLING_BOX_GRID_FVGEOMETRY_HH
28#define DUMUX_FACETCOUPLING_BOX_GRID_FVGEOMETRY_HH
33#include <dune/grid/common/mcmgmapper.hh>
34#include <dune/localfunctions/lagrange/lagrangelfecache.hh>
56template<
class Gr
idView>
63 template<
class Gr
idGeometry,
bool enableCache>
67 using ElementMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
71 using FacetMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
83 bool enableGridGeometryCache =
false,
94template<
class Scalar,
class GV,
class Traits>
103 using Element =
typename GV::template Codim<0>::Entity;
104 using CoordScalar =
typename GV::ctype;
105 static const int dim = GV::dimension;
106 static const int dimWorld = GV::dimensionworld;
126 using FeCache = Dune::LagrangeLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
131 template<
class FacetGr
idView,
class CodimOneGr
idAdapter>
133 const FacetGridView& facetGridView,
135 bool verbose =
false)
138 update_(facetGridView, codimOneGridAdapter, verbose);
143 {
return this->vertexMapper(); }
156 {
return numBoundaryScvf_; }
160 {
return this->vertexMapper().size(); }
175 template<
class FacetGr
idView,
class CodimOneGr
idAdapter>
177 const FacetGridView& facetGridView,
179 bool verbose =
false)
181 ParentType::update(gridView);
182 update_(facetGridView, codimOneGridAdapter, verbose);
186 template<
class FacetGr
idView,
class CodimOneGr
idAdapter>
188 const FacetGridView& facetGridView,
190 bool verbose =
false)
192 ParentType::update(std::move(gridView));
193 update_(facetGridView, codimOneGridAdapter, verbose);
201 const std::vector<SubControlVolume>&
scvs(GridIndexType eIdx)
const
202 {
return scvs_[eIdx]; }
205 const std::vector<SubControlVolumeFace>&
scvfs(GridIndexType eIdx)
const
206 {
return scvfs_[eIdx]; }
210 {
return boundaryDofIndices_[dofIdx]; }
214 {
return interiorBoundaryDofIndices_[dofIdx]; }
222 { DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box facet coupling scheme"); }
226 {
return std::unordered_map<GridIndexType, GridIndexType>(); }
230 template<
class FacetGr
idView,
class CodimOneGr
idAdapter>
231 void update_(
const FacetGridView& facetGridView,
233 bool verbose =
false)
236 this->vertexMapper().enrich(facetGridView, codimOneGridAdapter, verbose);
239 const auto numDof = numDofs();
240 const auto numElements = this->gridView().size(0);
243 scvs_.resize(numElements);
244 scvfs_.resize(numElements);
245 boundaryDofIndices_.assign(numDof,
false);
246 interiorBoundaryDofIndices_.assign(numDof,
false);
251 numBoundaryScvf_ = 0;
252 for (
const auto& element : elements(this->gridView()))
254 auto eIdx = this->elementMapper().index(element);
257 numScv_ += element.subEntities(dim);
258 numScvf_ += element.subEntities(dim-1);
261 auto elementGeometry = element.geometry();
262 const auto refElement = referenceElement(elementGeometry);
265 GeometryHelper geometryHelper(elementGeometry);
269 scvs_[eIdx].reserve(elementGeometry.corners());
270 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
271 scvs_[eIdx].emplace_back(geometryHelper,
274 this->vertexMapper().subIndex(element, scvLocalIdx, dim));
277 LocalIndexType scvfLocalIdx = 0;
278 scvfs_[eIdx].clear();
279 scvfs_[eIdx].reserve(element.subEntities(dim-1));
280 for (; scvfLocalIdx < element.subEntities(dim-1); ++scvfLocalIdx)
283 std::vector<LocalIndexType> localScvIndices({
static_cast<LocalIndexType
>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
284 static_cast<LocalIndexType
>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
287 scvfs_[eIdx].emplace_back(geometryHelper,
291 std::move(localScvIndices));
296 std::vector<unsigned int> handledFacets;
297 for (
const auto& intersection : intersections(this->gridView(),
element))
299 if (std::count(handledFacets.begin(), handledFacets.end(), intersection.indexInInside()))
302 handledFacets.push_back(intersection.indexInInside());
305 const auto isGeometry = intersection.geometry();
306 const auto numFaceCorners = isGeometry.corners();
307 const auto idxInInside = intersection.indexInInside();
308 const auto boundary = intersection.boundary();
310 std::vector<LocalIndexType> vIndicesLocal(numFaceCorners);
311 for (
int i = 0; i < numFaceCorners; ++i)
312 vIndicesLocal[i] =
static_cast<LocalIndexType
>(refElement.subEntity(idxInInside, 1, i, dim));
314 std::vector<LocalIndexType> gridVertexIndices(numFaceCorners);
315 for (
int i = 0; i < numFaceCorners; ++i)
316 gridVertexIndices[i] = this->vertexMapper().vertexIndex(element, vIndicesLocal[i], dim);
322 if (boundary && intersection.neighbor())
323 DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box facet coupling scheme");
326 if (isOnFacet || boundary)
329 numScvf_ += numFaceCorners;
330 numBoundaryScvf_ += int(boundary)*numFaceCorners;
332 for (
unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < numFaceCorners; ++isScvfLocalIdx)
335 std::vector<LocalIndexType> localScvIndices = {vIndicesLocal[isScvfLocalIdx], vIndicesLocal[isScvfLocalIdx]};
338 scvfs_[eIdx].emplace_back(geometryHelper,
343 std::move(localScvIndices),
348 const auto dofIndex = this->vertexMapper().subIndex(element, vIndicesLocal[isScvfLocalIdx], dim);
349 if (boundary) boundaryDofIndices_[ dofIndex ] = boundary;
350 if (isOnFacet) interiorBoundaryDofIndices_[ dofIndex ] = isOnFacet;
360 const FeCache feCache_;
362 std::vector<std::vector<SubControlVolume>> scvs_;
363 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
367 std::size_t numScvf_;
368 std::size_t numBoundaryScvf_;
371 std::vector<bool> boundaryDofIndices_;
372 std::vector<bool> interiorBoundaryDofIndices_;
382template<
class Scalar,
class GV,
class Traits>
391 static const int dim = GV::dimension;
392 static const int dimWorld = GV::dimensionworld;
394 using Element =
typename GV::template Codim<0>::Entity;
395 using Intersection =
typename GV::Intersection;
396 using CoordScalar =
typename GV::ctype;
414 using FeCache = Dune::LagrangeLocalFiniteElementCache<CoordScalar, Scalar, dim, 1>;
419 template<
class FacetGr
idView,
class CodimOneGr
idAdapter>
421 const FacetGridView& facetGridView,
423 bool verbose =
false)
425 , facetMapper_(gridView,
Dune::mcmgLayout(
Dune::template Codim<1>()))
427 update_(facetGridView, codimOneGridAdapter, verbose);
433 {
return this->vertexMapper(); }
446 {
return numBoundaryScvf_; }
450 {
return this->vertexMapper().size(); }
465 template<
class FacetGr
idView,
class CodimOneGr
idAdapter>
467 const FacetGridView& facetGridView,
469 bool verbose =
false)
471 ParentType::update(gridView);
472 updateFacetMapper_();
473 update_(facetGridView, codimOneGridAdapter, verbose);
477 template<
class FacetGr
idView,
class CodimOneGr
idAdapter>
479 const FacetGridView& facetGridView,
481 bool verbose =
false)
483 ParentType::update(std::move(gridView));
484 updateFacetMapper_();
485 update_(facetGridView, codimOneGridAdapter, verbose);
494 {
return boundaryDofIndices_[dofIdx]; }
498 {
return interiorBoundaryDofIndices_[dofIdx]; }
502 {
return facetIsOnInteriorBoundary_[ facetMapper_.subIndex(element, intersection.indexInInside(), 1) ]; }
510 { DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the facet coupling scheme"); }
514 {
return std::unordered_map<GridIndexType, GridIndexType>(); }
518 void updateFacetMapper_()
520 facetMapper_.update(this->gridView());
523 template<
class FacetGr
idView,
class CodimOneGr
idAdapter>
524 void update_(
const FacetGridView& facetGridView,
525 const CodimOneGridAdapter& codimOneGridAdapter,
529 this->vertexMapper().enrich(facetGridView, codimOneGridAdapter, verbose);
535 numBoundaryScvf_ = 0;
537 const auto numDof = numDofs();
538 boundaryDofIndices_.assign(numDof,
false);
539 interiorBoundaryDofIndices_.assign(numDof,
false);
540 facetIsOnInteriorBoundary_.assign(this->gridView().size(1),
false);
541 for (
const auto& element : elements(this->gridView()))
543 numScv_ += element.subEntities(dim);
544 numScvf_ += element.subEntities(dim-1);
546 const auto elementGeometry = element.geometry();
547 const auto refElement = referenceElement(elementGeometry);
551 std::vector<unsigned int> handledFacets;
552 for (
const auto& intersection : intersections(this->gridView(), element))
554 if (std::count(handledFacets.begin(), handledFacets.end(), intersection.indexInInside()))
557 handledFacets.push_back(intersection.indexInInside());
560 const auto isGeometry = intersection.geometry();
561 const auto numFaceCorners = isGeometry.corners();
562 const auto idxInInside = intersection.indexInInside();
563 const auto boundary = intersection.boundary();
565 std::vector<LocalIndexType> vIndicesLocal(numFaceCorners);
566 for (
int i = 0; i < numFaceCorners; ++i)
567 vIndicesLocal[i] =
static_cast<LocalIndexType
>(refElement.subEntity(idxInInside, 1, i, dim));
569 std::vector<GridIndexType> gridVertexIndices(numFaceCorners);
570 for (
int i = 0; i < numFaceCorners; ++i)
571 gridVertexIndices[i] = this->vertexMapper().vertexIndex(element, vIndicesLocal[i], dim);
574 const bool isOnFacet = codimOneGridAdapter.composeFacetElement(gridVertexIndices);
577 if (boundary && intersection.neighbor())
578 DUNE_THROW(Dune::InvalidStateException,
"Periodic boundaries are not supported by the box facet coupling scheme");
580 if (isOnFacet || boundary)
582 numScvf_ += numFaceCorners;
583 numBoundaryScvf_ += int(boundary)*numFaceCorners;
586 for (
int i = 0; i < numFaceCorners; ++i)
588 const auto dofIndex = this->vertexMapper().subIndex(element, vIndicesLocal[i], dim);
589 if (boundary) boundaryDofIndices_[ dofIndex ] =
true;
592 interiorBoundaryDofIndices_[ dofIndex ] =
true;
593 facetIsOnInteriorBoundary_[ facetMapper_.subIndex(element, idxInInside, 1) ] =
true;
601 const FeCache feCache_;
606 std::size_t numScvf_;
607 std::size_t numBoundaryScvf_;
610 std::vector<bool> boundaryDofIndices_;
611 std::vector<bool> interiorBoundaryDofIndices_;
614 typename Traits::FacetMapper facetMapper_;
615 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.
Base class for grid geometries.
Helper classes to compute the integration elements.
The available discretization methods in Dumux.
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
Structure to define the index types used for grid and local indices.
Definition: indextraits.hh:38
Base class for all grid geometries.
Definition: basegridgeometry.hh:61
typename BaseImplementation::GridView GridView
export the grid view type
Definition: basegridgeometry.hh:69
Create sub control volumes and sub control volume face geometries.
Definition: boxgeometryhelper.hh:269
the sub control volume for the box scheme
Definition: discretization/box/subcontrolvolume.hh:72
Base class for the element-local finite volume geometry for box models in the context of models consi...
Definition: multidomain/facet/box/fvelementgeometry.hh:48
The default traits for the finite volume grid geometry of the box scheme with coupling occurring acro...
Definition: multidomain/facet/box/fvgridgeometry.hh:58
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > FacetMapper
Definition: multidomain/facet/box/fvgridgeometry.hh:71
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > ElementMapper
Definition: multidomain/facet/box/fvgridgeometry.hh:67
Base class for the finite volume geometry vector for box schemes in the context of coupled models whe...
Definition: multidomain/facet/box/fvgridgeometry.hh:85
Base class for the finite volume geometry vector for box schemes in the context of coupled models whe...
Definition: multidomain/facet/box/fvgridgeometry.hh:97
bool dofOnInteriorBoundary(GridIndexType dofIdx) const
If a d.o.f. is on an interior boundary.
Definition: multidomain/facet/box/fvgridgeometry.hh:213
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:221
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:176
Dune::LagrangeLocalFiniteElementCache< CoordScalar, Scalar, dim, 1 > FeCache
export the finite element cache type
Definition: multidomain/facet/box/fvgridgeometry.hh:126
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition: multidomain/facet/box/fvgridgeometry.hh:122
const std::vector< SubControlVolume > & scvs(GridIndexType eIdx) const
Get the local scvs for an element.
Definition: multidomain/facet/box/fvgridgeometry.hh:201
std::size_t numScv() const
The total number of sub control volumes.
Definition: multidomain/facet/box/fvgridgeometry.hh:146
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
Periodic boundaries are not supported for the box facet coupling scheme.
Definition: multidomain/facet/box/fvgridgeometry.hh:217
bool dofOnBoundary(GridIndexType dofIdx) const
If a d.o.f. is on the boundary.
Definition: multidomain/facet/box/fvgridgeometry.hh:209
typename Traits::VertexMapper DofMapper
export dof mapper type
Definition: multidomain/facet/box/fvgridgeometry.hh:124
std::size_t numBoundaryScvf() const
Definition: multidomain/facet/box/fvgridgeometry.hh:155
const DofMapper & dofMapper() const
the vertex mapper is the dofMapper
Definition: multidomain/facet/box/fvgridgeometry.hh:142
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: multidomain/facet/box/fvgridgeometry.hh:118
std::size_t numScvf() const
The total number of sun control volume faces.
Definition: multidomain/facet/box/fvgridgeometry.hh:150
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:187
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition: multidomain/facet/box/fvgridgeometry.hh:197
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: multidomain/facet/box/fvgridgeometry.hh:159
BoxFacetCouplingFVGridGeometry(const GridView &gridView, const FacetGridView &facetGridView, const CodimOneGridAdapter &codimOneGridAdapter, bool verbose=false)
Constructor.
Definition: multidomain/facet/box/fvgridgeometry.hh:132
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:116
std::unordered_map< GridIndexType, GridIndexType > periodicVertexMap() const
Returns the map between dofs across periodic boundaries.
Definition: multidomain/facet/box/fvgridgeometry.hh:225
const std::vector< SubControlVolumeFace > & scvfs(GridIndexType eIdx) const
Get the local scvfs for an element.
Definition: multidomain/facet/box/fvgridgeometry.hh:205
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: multidomain/facet/box/fvgridgeometry.hh:120
Base class for the finite volume geometry vector for box schemes This builds up the sub control volum...
Definition: multidomain/facet/box/fvgridgeometry.hh:385
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: multidomain/facet/box/fvgridgeometry.hh:406
BoxFacetCouplingFVGridGeometry(const GridView &gridView, const FacetGridView &facetGridView, const CodimOneGridAdapter &codimOneGridAdapter, bool verbose=false)
Constructor.
Definition: multidomain/facet/box/fvgridgeometry.hh:420
std::size_t numScv() const
The total number of sub control volumes.
Definition: multidomain/facet/box/fvgridgeometry.hh:436
std::size_t numScvf() const
The total number of sun control volume faces.
Definition: multidomain/facet/box/fvgridgeometry.hh:440
std::size_t numDofs() const
The total number of degrees of freedom.
Definition: multidomain/facet/box/fvgridgeometry.hh:449
std::unordered_map< GridIndexType, GridIndexType > periodicVertexMap() const
Returns the map between dofs across periodic boundaries.
Definition: multidomain/facet/box/fvgridgeometry.hh:513
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:478
std::size_t numBoundaryScvf() const
Definition: multidomain/facet/box/fvgridgeometry.hh:445
Dune::LagrangeLocalFiniteElementCache< CoordScalar, Scalar, dim, 1 > FeCache
export the finite element cache type
Definition: multidomain/facet/box/fvgridgeometry.hh:414
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition: multidomain/facet/box/fvgridgeometry.hh:489
typename Traits::VertexMapper DofMapper
export dof mapper type
Definition: multidomain/facet/box/fvgridgeometry.hh:412
const DofMapper & dofMapper() const
Definition: multidomain/facet/box/fvgridgeometry.hh:432
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:404
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:509
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
Periodic boundaries are not supported for the box facet coupling scheme.
Definition: multidomain/facet/box/fvgridgeometry.hh:505
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: multidomain/facet/box/fvgridgeometry.hh:408
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition: multidomain/facet/box/fvgridgeometry.hh:410
bool dofOnBoundary(unsigned int dofIdx) const
If a d.o.f. is on the boundary.
Definition: multidomain/facet/box/fvgridgeometry.hh:493
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:466
bool dofOnInteriorBoundary(unsigned int dofIdx) const
If a d.o.f. is on an interior boundary.
Definition: multidomain/facet/box/fvgridgeometry.hh:497
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:501
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:53
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...