version 3.11-dev
discretization/facecentered/diamond/fvgridgeometry.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_DISCRETIZATION_FACECENTERED_DIAMOND_FV_GRID_GEOMETRY
13#define DUMUX_DISCRETIZATION_FACECENTERED_DIAMOND_FV_GRID_GEOMETRY
14
15#include <memory>
16#include <unordered_map>
17
18#include <dune/grid/common/mcmgmapper.hh>
19#include <dune/geometry/type.hh>
20
23#include <dumux/common/math.hh>
31
37
39
40namespace Dumux {
41
42namespace Detail {
43template<class GV, class T>
44using FaceCenteredDiamondGeometryHelper_t = Dune::Std::detected_or_t<
47 T
48>;
49} // end namespace Detail
50
55template<class GridView, class ScvRule = Dumux::QuadratureRules::MidpointQuadrature, class ScvfRule = Dumux::QuadratureRules::MidpointQuadrature>
57
64template<class GridView, class QuadratureTraits = FaceCenteredDiamondQuadratureTraits<GridView>>
65struct FaceCenteredDiamondDefaultGridGeometryTraits : public DefaultMapperTraits<GridView>, public QuadratureTraits
66{
69 using DofMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
70
71 template<class GridGeometry, bool enableCache>
73};
74
79template<class GV,
80 bool enableCaching = true,
83: public BaseGridGeometry<GV, Traits>
84{
87 using GridIndexType = typename IndexTraits<GV>::GridIndex;
88 using LocalIndexType = typename IndexTraits<GV>::SmallLocalIndex;
89 using Element = typename GV::template Codim<0>::Entity;
90
91 using Scalar = typename GV::ctype;
92
93 static const int dim = GV::dimension;
94 static const int dimWorld = GV::dimensionworld;
95
96 static_assert(dim > 1, "Only implemented for dim > 1");
97
98public:
102 static constexpr bool cachingEnabled = true;
103
104 static constexpr bool enableHybridCVFE = false;
105
107 using LocalView = typename Traits::template LocalView<ThisType, true>;
109 using SubControlVolume = typename Traits::SubControlVolume;
111 using SubControlVolumeFace = typename Traits::SubControlVolumeFace;
113 using GridView = GV;
115 using DofMapper = typename Traits::DofMapper;
123 using ScvQuadratureRule = typename Traits::ScvQuadratureRule;
125 using ScvfQuadratureRule = typename Traits::ScvfQuadratureRule;
128
130 FaceCenteredDiamondFVGridGeometry(const GridView& gridView, const std::string& paramGroup = "")
132 , dofMapper_(gridView, Dune::mcmgLayout(Dune::Codim<1>{}))
133 , cache_(*this)
134 , periodicGridTraits_(this->gridView().grid())
135 {
136 update_();
137 }
138
140 std::size_t numScv() const
141 { return numScv_; }
142
144 std::size_t numScvf() const
145 { return numScvf_; }
146
148 std::size_t numBoundaryScvf() const
149 { return numBoundaryScvf_; }
150
152 std::size_t numDofs() const
153 { return this->gridView().size(1); }
154
157 {
159 update_();
160 }
161
164 {
165 ParentType::update(std::move(gridView));
166 update_();
167 }
168
170 const FeCache& feCache() const
171 { return feCache_; }
172
174 bool dofOnBoundary(GridIndexType dofIdx) const
175 { return boundaryDofIndices_[dofIdx]; }
176
178 const DofMapper& dofMapper() const
179 { return dofMapper_; }
180
182 bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
183 { return periodicFaceMap_.count(dofIdx); }
184
186 GridIndexType periodicallyMappedDof(GridIndexType dofIdx) const
187 { return periodicFaceMap_.at(dofIdx); }
188
190 const std::unordered_map<GridIndexType, GridIndexType>& periodicDofMap() const
191 { return periodicFaceMap_; }
192
195 { return { gg.cache_ }; }
196
197private:
198
199 class FCDiamondGridGeometryCache
200 {
202 public:
205
206 explicit FCDiamondGridGeometryCache(const FaceCenteredDiamondFVGridGeometry& gg)
207 : gridGeometry_(&gg)
208 {}
209
210 const FaceCenteredDiamondFVGridGeometry& gridGeometry() const
211 { return *gridGeometry_; }
212
214 const std::vector<SubControlVolume>& scvs(GridIndexType eIdx) const
215 { return scvs_[eIdx]; }
216
218 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx) const
219 { return scvfs_[eIdx]; }
220
222 bool hasBoundaryScvf(GridIndexType eIdx) const
223 { return hasBoundaryScvf_[eIdx]; }
224
226 const auto& boundaryFaces(GridIndexType eIdx) const
227 { return boundaryFaces_[eIdx]; }
228
229 private:
230 void clear_()
231 {
232 scvs_.clear();
233 scvfs_.clear();
234 hasBoundaryScvf_.clear();
235 boundaryFaces_.clear();
236 }
237
238 std::vector<std::vector<SubControlVolume>> scvs_;
239 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
240 std::vector<bool> hasBoundaryScvf_;
241 std::vector<Dune::ReservedVector<BoundaryFace, 2*dim>> boundaryFaces_;
242
243 const FaceCenteredDiamondFVGridGeometry* gridGeometry_;
244 };
245
246public:
249 using Cache = FCDiamondGridGeometryCache;
250private:
251 using GeometryHelper = typename Cache::GeometryHelper;
252
254 void update_()
255 {
256 // clear containers (necessary after grid refinement)
257 cache_.clear_();
258 dofMapper_.update(this->gridView());
259
260 // determine size of containers
261 const auto numElements = this->gridView().size(0);
262 cache_.scvs_.resize(numElements);
263 cache_.scvfs_.resize(numElements);
264 cache_.hasBoundaryScvf_.resize(numElements, false);
265 cache_.boundaryFaces_.resize(numElements);
266
267 boundaryDofIndices_.assign(numDofs(), false);
268
269 numScv_ = 0;
270 numScvf_ = 0;
271 numBoundaryScvf_ = 0;
272
273 // Build the scvs and scv faces
274 for (const auto& element : elements(this->gridView()))
275 {
276 const auto eIdx = this->elementMapper().index(element);
277
278 const auto geometry = element.geometry();
279 GeometryHelper geometryHelper(geometry);
280
281 // build the scvs
282 cache_.scvs_[eIdx].reserve(geometryHelper.numScv());
283 numScv_ += geometryHelper.numScv();
284 for (LocalIndexType localScvIdx = 0; localScvIdx < geometryHelper.numScv(); ++localScvIdx)
285 {
286 const auto dofIndex = dofMapper().subIndex(element, localScvIdx, 1);
287 const auto& corners = geometryHelper.getScvCorners(localScvIdx);
288 const auto volume = Dumux::convexPolytopeVolume<dim>(
289 SubControlVolume::Traits::geometryType(geometry.type()),
290 [&](unsigned int i){ return corners[i]; }
291 );
292
293 cache_.scvs_[eIdx].emplace_back(
294 volume,
295 geometryHelper.facetCenter(localScvIdx),
296 Dumux::center(corners),
297 localScvIdx,
298 eIdx,
299 dofIndex
300 );
301 }
302
303 // build interior scvfs
304 LocalIndexType localScvfIdx = 0;
305 cache_.scvfs_[eIdx].reserve(geometryHelper.numInteriorScvf());
306 numScvf_ += geometryHelper.numInteriorScvf();
307 for (; localScvfIdx < geometryHelper.numInteriorScvf(); ++localScvfIdx)
308 {
309 const auto& corners = geometryHelper.getScvfCorners(localScvfIdx);
310 const auto& scvPair = geometryHelper.getInsideOutsideScvForScvf(localScvfIdx);
311 const auto area = Dumux::convexPolytopeVolume<dim-1>(
312 SubControlVolumeFace::Traits::interiorGeometryType(geometry.type()),
313 [&](unsigned int i){ return corners[i]; }
314 );
315
316 cache_.scvfs_[eIdx].emplace_back(
317 Dumux::center(corners),
318 area,
319 geometryHelper.normal(corners, scvPair),
320 scvPair,
321 localScvfIdx
322 );
323 }
324
325 // build boundary scvfs
326 LocalIndexType numBoundaryFaces = 0;
327 for (const auto& intersection : intersections(this->gridView(), element))
328 {
329 if (onDomainBoundary_(intersection))
330 {
331 // store information that the face dof is on a boundary
332 const LocalIndexType localFacetIndex = intersection.indexInInside();
333 const auto dofIndex = dofMapper().subIndex(element, localFacetIndex, 1);
334 boundaryDofIndices_[dofIndex] = true;
335
336 // and that the element has a boundary face
337 cache_.hasBoundaryScvf_[eIdx] = true;
338
339 // add boundary face
340 {
341 const auto geo = intersection.geometry();
342 cache_.boundaryFaces_[eIdx].push_back(BoundaryFace{
343 geo.center(),
344 geo.volume(),
345 intersection.centerUnitOuterNormal(),
346 numBoundaryFaces++,
347 static_cast<LocalIndexType>(localFacetIndex),
348 typename BoundaryFace::Traits::BoundaryFlag{intersection}
349 });
350 }
351
352 // add boundary scvf
353 const auto geo = intersection.geometry();
354 cache_.scvfs_[eIdx].emplace_back(
355 geo.center(),
356 geo.volume(),
357 intersection.centerUnitOuterNormal(),
358 std::array<LocalIndexType, 2>{{localFacetIndex, localFacetIndex}},
359 localScvfIdx,
360 typename SubControlVolumeFace::Traits::BoundaryFlag{ intersection }
361 );
362
363 // increment local and global counters
364 ++localScvfIdx;
365 ++numBoundaryScvf_;
366 ++numScvf_;
367 }
368
369 // handle periodic boundaries
370 if (onPeriodicBoundary_(intersection))
371 {
372 const LocalIndexType localFacetIndex = intersection.indexInInside();
373 const auto dofIndex = dofMapper().subIndex(element, localFacetIndex, 1);
374
375 this->setPeriodic();
376
377 const auto& otherElement = intersection.outside();
378
379 LocalIndexType otherIntersectionLocalIdx = 0;
380 bool periodicFaceFound = false;
381
382 for (const auto& otherIntersection : intersections(this->gridView(), otherElement))
383 {
384 if (periodicFaceFound)
385 continue;
386
387 if (Dune::FloatCmp::eq(intersection.centerUnitOuterNormal()*otherIntersection.centerUnitOuterNormal(), -1.0, 1e-7))
388 {
389 const auto periodicDofIdx = dofMapper().subIndex(otherElement, otherIntersectionLocalIdx, 1);
390 periodicFaceMap_[dofIndex] = periodicDofIdx;
391 periodicFaceFound = true;
392 }
393
394 ++otherIntersectionLocalIdx;
395 }
396 }
397 }
398 }
399 }
400
401 bool onDomainBoundary_(const typename GridView::Intersection& intersection) const
402 {
403 return !intersection.neighbor() && intersection.boundary();
404 }
405
406 bool onProcessorBoundary_(const typename GridView::Intersection& intersection) const
407 {
408 return !intersection.neighbor() && !intersection.boundary();
409 }
410
411 bool onPeriodicBoundary_(const typename GridView::Intersection& intersection) const
412 {
413 return periodicGridTraits_.isPeriodic(intersection);
414 }
415
416 // faces on the boundary
417 std::vector<bool> boundaryDofIndices_;
418
419 DofMapper dofMapper_;
420
421 std::size_t numScv_;
422 std::size_t numScvf_;
423 std::size_t numBoundaryScvf_;
424
425 // a map for periodic boundary vertices
426 std::unordered_map<GridIndexType, GridIndexType> periodicFaceMap_;
427
428 const FeCache feCache_;
429
430 Cache cache_;
431
432 PeriodicGridTraits<typename GridView::Grid> periodicGridTraits_;
433};
434
435} // end namespace Dumux
436
437#endif
Base class for grid geometries.
Implementation of a boundary face related to primary grid elements (dune intersections)
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:252
Class for a boundary face related to primary grid elements (dune intersections)
Definition: boundaryface.hh:69
const GlobalPosition & center() const
The center of the face.
Definition: boundaryface.hh:103
Element-wise grid geometry (local view)
Definition: discretization/facecentered/diamond/fvelementgeometry.hh:38
Grid geometry for the diamond discretization.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:84
static constexpr bool cachingEnabled
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:102
friend LocalView localView(const FaceCenteredDiamondFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:194
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:186
const std::unordered_map< GridIndexType, GridIndexType > & periodicDofMap() const
Returns the map between dofs across periodic boundaries.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:190
FaceCenteredDiamondFVGridGeometry(const GridView &gridView, const std::string &paramGroup="")
Constructor.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:130
GV GridView
export the grid view type
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:113
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:140
typename PeriodicGridTraits< typename GV::Grid >::SupportsPeriodicity SupportsPeriodicity
export whether the grid(geometry) supports periodicity
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:121
FCDiamondGridGeometryCache Cache
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:249
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:111
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a d.o.f. is on a periodic boundary.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:182
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:170
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:117
bool dofOnBoundary(GridIndexType dofIdx) const
If a face / d.o.f. is on the boundary.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:174
static constexpr DiscretizationMethod discMethod
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:101
std::size_t numBoundaryScvf() const
The total number of boundary sub control volume faces.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:148
static constexpr bool enableHybridCVFE
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:104
std::size_t numDofs() const
the total number of dofs
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:152
typename Traits::ScvfQuadratureRule ScvfQuadratureRule
the quadrature rule type for scvfs
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:125
void update(GridView &&gridView)
update all fvElementGeometries (call this after grid adaption)
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:163
const DofMapper & dofMapper() const
Return a reference to the dof mapper.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:178
typename Traits::ScvQuadratureRule ScvQuadratureRule
the quadrature rule type for scvs
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:123
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:107
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:109
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:144
void update(const GridView &gridView)
update all fvElementGeometries (call this after grid adaption)
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:156
typename Traits::DofMapper DofMapper
export the dof mapper type
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:115
The SCVF implementation for diamond.
Definition: discretization/facecentered/diamond/subcontrolvolumeface.hh:62
Face centered diamond subcontrolvolume face.
Definition: discretization/facecentered/diamond/subcontrolvolume.hh:62
Definition: nonconformingfecache.hh:29
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
Defines the index types used for grid and local indices.
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:48
typename T::GeometryHelper SpecifiesGeometryHelper
Definition: basegridgeometry.hh:30
CVFE< CVFEMethods::CR_RT > FCDiamond
Definition: method.hh:105
Definition: adapt.hh:17
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:236
std::ranges::range auto scvs(const FVElementGeometry &fvGeometry, const LocalDof &localDof)
Definition: localdof.hh:79
Definition: common/pdesolver.hh:24
A finite element cache for the non-conforming FE spaces RT and CR.
Grid properties related to periodicity.
Quadrature rule traits for discretization schemes.
Definition: quadraturerules.hh:85
Definition: defaultmappertraits.hh:23
Definition: method.hh:46
The default traits for the face-centered diamond finite volume grid geometry Defines the scv and scvf...
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:66
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > DofMapper
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:69
Structure to define the index types used for grid and local indices.
Definition: indextraits.hh:26
Definition: periodicgridtraits.hh:24
Compute the volume of several common geometry types.