12#ifndef DUMUX_DISCRETIZATION_FACECENTERED_DIAMOND_FV_GRID_GEOMETRY
13#define DUMUX_DISCRETIZATION_FACECENTERED_DIAMOND_FV_GRID_GEOMETRY
16#include <unordered_map>
18#include <dune/grid/common/mcmgmapper.hh>
19#include <dune/geometry/type.hh>
40template<
class GV,
class T>
54template<
class Gr
idView>
59 using DofMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
61 template<
class Gr
idGeometry,
bool enableCache>
70 bool enableCaching =
true,
79 using Element =
typename GV::template Codim<0>::Entity;
81 using Scalar =
typename GV::ctype;
83 static const int dim = GV::dimension;
84 static const int dimWorld = GV::dimensionworld;
86 static_assert(dim > 1,
"Only implemented for dim > 1");
128 {
return numBoundaryScvf_; }
132 {
return this->
gridView().size(1); }
154 {
return boundaryDofIndices_[dofIdx]; }
158 {
return dofMapper_; }
162 {
return periodicFaceMap_.count(dofIdx); }
166 {
return periodicFaceMap_.at(dofIdx); }
170 {
return periodicFaceMap_; }
173 [[deprecated(
"Will be removed after release 3.9. Use periodicDofMap() instead.")]]
179 {
return { gg.cache_ }; }
183 class FCDiamondGridGeometryCache
195 {
return *gridGeometry_; }
198 const std::vector<SubControlVolume>& scvs(GridIndexType eIdx)
const
199 {
return scvs_[eIdx]; }
202 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx)
const
203 {
return scvfs_[eIdx]; }
206 bool hasBoundaryScvf(GridIndexType eIdx)
const
207 {
return hasBoundaryScvf_[eIdx]; }
214 hasBoundaryScvf_.clear();
217 std::vector<std::vector<SubControlVolume>> scvs_;
218 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
219 std::vector<bool> hasBoundaryScvf_;
227 using Cache = FCDiamondGridGeometryCache;
229 using GeometryHelper =
typename Cache::GeometryHelper;
236 dofMapper_.update(this->
gridView());
239 const auto numElements = this->
gridView().size(0);
240 cache_.scvs_.resize(numElements);
241 cache_.scvfs_.resize(numElements);
242 cache_.hasBoundaryScvf_.resize(numElements,
false);
244 boundaryDofIndices_.assign(
numDofs(),
false);
248 numBoundaryScvf_ = 0;
255 const auto geometry =
element.geometry();
256 GeometryHelper geometryHelper(geometry);
259 cache_.scvs_[eIdx].reserve(geometryHelper.numScv());
260 numScv_ += geometryHelper.numScv();
261 for (LocalIndexType localScvIdx = 0; localScvIdx < geometryHelper.numScv(); ++localScvIdx)
264 const auto& corners = geometryHelper.getScvCorners(localScvIdx);
265 const auto volume = Dumux::convexPolytopeVolume<dim>(
266 SubControlVolume::Traits::geometryType(geometry.type()),
267 [&](
unsigned int i){ return corners[i]; }
270 cache_.scvs_[eIdx].emplace_back(
272 geometryHelper.facetCenter(localScvIdx),
281 LocalIndexType localScvfIdx = 0;
282 cache_.scvfs_[eIdx].reserve(geometryHelper.numInteriorScvf());
283 numScvf_ += geometryHelper.numInteriorScvf();
284 for (; localScvfIdx < geometryHelper.numInteriorScvf(); ++localScvfIdx)
286 const auto& corners = geometryHelper.getScvfCorners(localScvfIdx);
287 const auto& scvPair = geometryHelper.getInsideOutsideScvForScvf(localScvfIdx);
289 SubControlVolumeFace::Traits::interiorGeometryType(geometry.type()),
290 [&](
unsigned int i){
return corners[i]; }
293 cache_.scvfs_[eIdx].emplace_back(
296 geometryHelper.normal(corners, scvPair),
303 for (
const auto& intersection : intersections(this->
gridView(),
element))
305 if (onDomainBoundary_(intersection))
308 const LocalIndexType localFacetIndex = intersection.indexInInside();
310 boundaryDofIndices_[dofIndex] =
true;
313 cache_.hasBoundaryScvf_[eIdx] =
true;
316 const auto geo = intersection.geometry();
317 cache_.scvfs_[eIdx].emplace_back(
320 intersection.centerUnitOuterNormal(),
321 std::array<LocalIndexType, 2>{{localFacetIndex, localFacetIndex}},
323 typename SubControlVolumeFace::Traits::BoundaryFlag{ intersection }
333 if (onPeriodicBoundary_(intersection))
335 const LocalIndexType localFacetIndex = intersection.indexInInside();
340 const auto& otherElement = intersection.outside();
342 LocalIndexType otherIntersectionLocalIdx = 0;
343 bool periodicFaceFound =
false;
345 for (
const auto& otherIntersection : intersections(this->
gridView(), otherElement))
347 if (periodicFaceFound)
350 if (Dune::FloatCmp::eq(intersection.centerUnitOuterNormal()*otherIntersection.centerUnitOuterNormal(), -1.0, 1e-7))
352 const auto periodicDofIdx =
dofMapper().subIndex(otherElement, otherIntersectionLocalIdx, 1);
353 periodicFaceMap_[dofIndex] = periodicDofIdx;
354 periodicFaceFound =
true;
357 ++otherIntersectionLocalIdx;
364 bool onDomainBoundary_(
const typename GridView::Intersection& intersection)
const
366 return !intersection.neighbor() && intersection.boundary();
369 bool onProcessorBoundary_(
const typename GridView::Intersection& intersection)
const
371 return !intersection.neighbor() && !intersection.boundary();
374 bool onPeriodicBoundary_(
const typename GridView::Intersection& intersection)
const
376 return intersection.boundary() && intersection.neighbor();
380 std::vector<bool> boundaryDofIndices_;
382 DofMapper dofMapper_;
385 std::size_t numScvf_;
386 std::size_t numBoundaryScvf_;
389 std::unordered_map<GridIndexType, GridIndexType> periodicFaceMap_;
391 const FeCache feCache_;
Base class for grid geometries.
Compute the center point of a convex polytope geometry or a random-access container of corner points.
Check the overlap size for different discretization methods.
Base class for all grid geometries.
Definition: basegridgeometry.hh:52
const ElementMapper & elementMapper() const
Returns the mapper for elements to indices for constant grids.
Definition: basegridgeometry.hh:112
void setPeriodic(bool value=true)
Set the periodicity of the grid geometry.
Definition: basegridgeometry.hh:169
Element element(GridIndexType eIdx) const
Get an element from a global element index.
Definition: basegridgeometry.hh:142
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
Helper class to construct SCVs and SCVFs for the diamond scheme.
Definition: discretization/facecentered/diamond/geometryhelper.hh:255
Element-wise grid geometry (local view)
Definition: discretization/facecentered/diamond/fvelementgeometry.hh:32
Grid geometry for the diamond discretization.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:74
static constexpr bool cachingEnabled
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:92
friend LocalView localView(const FaceCenteredDiamondFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:178
GridIndexType periodicallyMappedDof(GridIndexType dofIdx) const
The index of the d.o.f. on the other side of the periodic boundary.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:165
const std::unordered_map< GridIndexType, GridIndexType > & periodicDofMap() const
Returns the map between dofs across periodic boundaries.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:169
FaceCenteredDiamondFVGridGeometry(const GridView &gridView, const std::string ¶mGroup="")
Constructor.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:110
GV GridView
export the grid view type
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:101
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:119
FCDiamondGridGeometryCache Cache
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:227
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:99
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a d.o.f. is on a periodic boundary.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:161
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:149
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:105
bool dofOnBoundary(GridIndexType dofIdx) const
If a face / d.o.f. is on the boundary.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:153
const std::unordered_map< GridIndexType, GridIndexType > & periodicVertexMap() const
Returns the map between dofs across periodic boundaries.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:174
static constexpr DiscretizationMethod discMethod
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:91
std::size_t numBoundaryScvf() const
The total number of boundary sub control volume faces.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:127
std::size_t numDofs() const
the total number of dofs
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:131
void update(GridView &&gridView)
update all fvElementGeometries (call this after grid adaption)
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:142
const DofMapper & dofMapper() const
Return a reference to the dof mapper.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:157
typename Traits::template LocalView< ThisType, true > LocalView
export the type of the fv element geometry (the local view type)
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:95
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:97
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:123
void update(const GridView &gridView)
update all fvElementGeometries (call this after grid adaption)
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:135
typename Traits::DofMapper DofMapper
export the dof mapper type
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:103
The SCVF implementation for diamond.
Definition: discretization/facecentered/diamond/subcontrolvolumeface.hh:63
Face centered diamond subcontrolvolume face.
Definition: discretization/facecentered/diamond/subcontrolvolume.hh:62
Defines the default element and vertex mapper types.
Helper classes to compute the integration elements.
auto volume(const Geometry &geo, unsigned int integrationOrder=4)
The volume of a given geometry.
Definition: volume.hh:159
auto convexPolytopeVolume(Dune::GeometryType type, const CornerF &c)
Compute the volume of several common geometry types.
Definition: volume.hh:41
Corners::value_type center(const Corners &corners)
The center of a given list of corners.
Definition: center.hh:24
Define some often used mathematical functions.
The available discretization methods in Dumux.
Dune::Std::detected_or_t< Dumux::DiamondGeometryHelper< GV, typename T::SubControlVolume, typename T::SubControlVolumeFace >, SpecifiesGeometryHelper, T > FaceCenteredDiamondGeometryHelper_t
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:45
typename T::GeometryHelper SpecifiesGeometryHelper
Definition: basegridgeometry.hh:30
CVFE< CVFEMethods::CR_RT > FCDiamond
Definition: method.hh:101
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:166
Definition: common/pdesolver.hh:24
Definition: defaultmappertraits.hh:23
The default traits for the face-centered diamond finite volume grid geometry Defines the scv and scvf...
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:56
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > DofMapper
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:59
Structure to define the index types used for grid and local indices.
Definition: indextraits.hh:26
Compute the volume of several common geometry types.