version 3.11-dev
Loading...
Searching...
No Matches
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{
86 using ParentType = BaseGridGeometry<GV, Traits>;
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 = "")
131 : ParentType(gridView)
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:
206 using DofHelper = typename GeometryHelper::DofHelper;
207
208 explicit FCDiamondGridGeometryCache(const FaceCenteredDiamondFVGridGeometry& gg)
209 : gridGeometry_(&gg)
210 {}
211
212 const FaceCenteredDiamondFVGridGeometry& gridGeometry() const
213 { return *gridGeometry_; }
214
216 const std::vector<SubControlVolume>& scvs(GridIndexType eIdx) const
217 { return scvs_[eIdx]; }
218
220 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx) const
221 { return scvfs_[eIdx]; }
222
224 bool hasBoundaryScvf(GridIndexType eIdx) const
225 { return hasBoundaryScvf_[eIdx]; }
226
228 const auto& boundaryFaces(GridIndexType eIdx) const
229 { return boundaryFaces_[eIdx]; }
230
232 const auto& boundaryFaceScvfRanges(GridIndexType eIdx) const
233 { return boundaryFaceScvfRanges_[eIdx]; }
234
235 private:
236 void clear_()
237 {
238 scvs_.clear();
239 scvfs_.clear();
240 hasBoundaryScvf_.clear();
241 boundaryFaces_.clear();
242 boundaryFaceScvfRanges_.clear();
243 }
244
245 std::vector<std::vector<SubControlVolume>> scvs_;
246 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
247 std::vector<bool> hasBoundaryScvf_;
248 std::vector<Dune::ReservedVector<BoundaryFace, 2*dim>> boundaryFaces_;
249 std::vector<Dune::ReservedVector<std::array<LocalIndexType, 2>, 2*dim>> boundaryFaceScvfRanges_;
250
251 const FaceCenteredDiamondFVGridGeometry* gridGeometry_;
252 };
253
254public:
257 using Cache = FCDiamondGridGeometryCache;
258private:
259 using GeometryHelper = typename Cache::GeometryHelper;
260
262 void update_()
263 {
264 // clear containers (necessary after grid refinement)
265 cache_.clear_();
266 dofMapper_.update(this->gridView());
267
268 // determine size of containers
269 const auto numElements = this->gridView().size(0);
270 cache_.scvs_.resize(numElements);
271 cache_.scvfs_.resize(numElements);
272 cache_.hasBoundaryScvf_.resize(numElements, false);
273 cache_.boundaryFaces_.resize(numElements);
274 cache_.boundaryFaceScvfRanges_.resize(numElements);
275
276 boundaryDofIndices_.assign(numDofs(), false);
277
278 numScv_ = 0;
279 numScvf_ = 0;
280 numBoundaryScvf_ = 0;
281
282 // Build the scvs and scv faces
283 for (const auto& element : elements(this->gridView()))
284 {
285 const auto eIdx = this->elementMapper().index(element);
286
287 const auto geometry = element.geometry();
288 GeometryHelper geometryHelper(geometry);
289
290 // build the scvs
291 cache_.scvs_[eIdx].reserve(geometryHelper.numScv());
292 numScv_ += geometryHelper.numScv();
293 for (LocalIndexType localScvIdx = 0; localScvIdx < geometryHelper.numScv(); ++localScvIdx)
294 {
295 const auto dofIndex = dofMapper().subIndex(element, localScvIdx, 1);
296 const auto& corners = geometryHelper.getScvCorners(localScvIdx);
298 SubControlVolume::Traits::geometryType(geometry.type()),
299 [&](unsigned int i){ return corners[i]; }
300 );
301
302 cache_.scvs_[eIdx].emplace_back(
303 volume,
304 geometryHelper.facetCenter(localScvIdx),
305 Dumux::center(corners),
306 localScvIdx,
307 eIdx,
308 dofIndex
309 );
310 }
311
312 // build interior scvfs
313 LocalIndexType localScvfIdx = 0;
314 cache_.scvfs_[eIdx].reserve(geometryHelper.numInteriorScvf());
315 numScvf_ += geometryHelper.numInteriorScvf();
316 for (; localScvfIdx < geometryHelper.numInteriorScvf(); ++localScvfIdx)
317 {
318 const auto& corners = geometryHelper.getScvfCorners(localScvfIdx);
319 const auto& scvPair = geometryHelper.getInsideOutsideScvForScvf(localScvfIdx);
320 const auto area = Dumux::convexPolytopeVolume<dim-1>(
321 SubControlVolumeFace::Traits::interiorGeometryType(geometry.type()),
322 [&](unsigned int i){ return corners[i]; }
323 );
324
325 cache_.scvfs_[eIdx].emplace_back(
326 Dumux::center(corners),
327 area,
328 geometryHelper.normal(corners, scvPair),
329 scvPair,
330 localScvfIdx
331 );
332 }
333
334 // build boundary scvfs
335 LocalIndexType numBoundaryFaces = 0;
336 for (const auto& intersection : intersections(this->gridView(), element))
337 {
338 if (onDomainBoundary_(intersection))
339 {
340 // store information that the face dof is on a boundary
341 const LocalIndexType localFacetIndex = intersection.indexInInside();
342 const auto dofIndex = dofMapper().subIndex(element, localFacetIndex, 1);
343 boundaryDofIndices_[dofIndex] = true;
344
345 // and that the element has a boundary face
346 cache_.hasBoundaryScvf_[eIdx] = true;
347
348 // add boundary face
349 {
350 const auto geo = intersection.geometry();
351 cache_.boundaryFaces_[eIdx].push_back(BoundaryFace{
352 geo.center(),
353 geo.volume(),
354 intersection.centerUnitOuterNormal(),
355 numBoundaryFaces++,
356 static_cast<LocalIndexType>(localFacetIndex),
357 typename BoundaryFace::Traits::BoundaryFlag{intersection}
358 });
359
360 // record the scvf subrange for this boundary face: {offset, count=1}
361 cache_.boundaryFaceScvfRanges_[eIdx].push_back(std::array<LocalIndexType, 2>{{
362 localScvfIdx, 1
363 }});
364 }
365
366 // add boundary scvf
367 const auto geo = intersection.geometry();
368 cache_.scvfs_[eIdx].emplace_back(
369 geo.center(),
370 geo.volume(),
371 intersection.centerUnitOuterNormal(),
372 std::array<LocalIndexType, 2>{{localFacetIndex, localFacetIndex}},
373 localScvfIdx,
374 typename SubControlVolumeFace::Traits::BoundaryFlag{ intersection }
375 );
376
377 // increment local and global counters
378 ++localScvfIdx;
379 ++numBoundaryScvf_;
380 ++numScvf_;
381 }
382
383 // handle periodic boundaries
384 if (onPeriodicBoundary_(intersection))
385 {
386 const LocalIndexType localFacetIndex = intersection.indexInInside();
387 const auto dofIndex = dofMapper().subIndex(element, localFacetIndex, 1);
388
389 this->setPeriodic();
390
391 const auto& otherElement = intersection.outside();
392
393 LocalIndexType otherIntersectionLocalIdx = 0;
394 bool periodicFaceFound = false;
395
396 for (const auto& otherIntersection : intersections(this->gridView(), otherElement))
397 {
398 if (periodicFaceFound)
399 continue;
400
401 if (Dune::FloatCmp::eq(intersection.centerUnitOuterNormal()*otherIntersection.centerUnitOuterNormal(), -1.0, 1e-7))
402 {
403 const auto periodicDofIdx = dofMapper().subIndex(otherElement, otherIntersectionLocalIdx, 1);
404 periodicFaceMap_[dofIndex] = periodicDofIdx;
405 periodicFaceFound = true;
406 }
407
408 ++otherIntersectionLocalIdx;
409 }
410 }
411 }
412 }
413 }
414
415 bool onDomainBoundary_(const typename GridView::Intersection& intersection) const
416 {
417 return !intersection.neighbor() && intersection.boundary();
418 }
419
420 bool onProcessorBoundary_(const typename GridView::Intersection& intersection) const
421 {
422 return !intersection.neighbor() && !intersection.boundary();
423 }
424
425 bool onPeriodicBoundary_(const typename GridView::Intersection& intersection) const
426 {
427 return periodicGridTraits_.isPeriodic(intersection);
428 }
429
430 // faces on the boundary
431 std::vector<bool> boundaryDofIndices_;
432
433 DofMapper dofMapper_;
434
435 std::size_t numScv_;
436 std::size_t numScvf_;
437 std::size_t numBoundaryScvf_;
438
439 // a map for periodic boundary vertices
440 std::unordered_map<GridIndexType, GridIndexType> periodicFaceMap_;
441
442 const FeCache feCache_;
443
444 Cache cache_;
445
447};
448
449} // end namespace Dumux
450
451#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.
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
Definition basegridgeometry.hh:142
const GridView & gridView() const
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:256
Class for a boundary face related to primary grid elements (dune intersections).
Definition boundaryface.hh:69
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
Experimental::BoundaryFace< GV > BoundaryFace
Definition discretization/facecentered/diamond/fvgridgeometry.hh:127
friend LocalView localView(const FaceCenteredDiamondFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition discretization/facecentered/diamond/fvgridgeometry.hh:194
DiscretizationMethods::FCDiamond DiscretizationMethod
Definition discretization/facecentered/diamond/fvgridgeometry.hh:100
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
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
Definition discretization/facecentered/diamond/fvgridgeometry.hh:121
FCDiamondGridGeometryCache Cache
Definition discretization/facecentered/diamond/fvgridgeometry.hh:257
typename Traits::SubControlVolumeFace SubControlVolumeFace
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
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
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
Definition discretization/facecentered/diamond/fvgridgeometry.hh:123
NonconformingFECache< Scalar, Scalar, dim > FeCache
Definition discretization/facecentered/diamond/fvgridgeometry.hh:119
typename Traits::template LocalView< ThisType, true > LocalView
Definition discretization/facecentered/diamond/fvgridgeometry.hh:107
typename Traits::SubControlVolume SubControlVolume
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
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.
Element-wise grid geometry (local view).
Helper class to construct SCVs and SCVFs for the diamond scheme.
Face centered diamond subcontrolvolume face.
The SCVF implementation for diamond.
Helper classes to compute the integration elements.
CVFE::DefaultQuadratureTraits< GridView, ScvRule, ScvfRule > FaceCenteredDiamondQuadratureTraits
Quadrature rule traits for FaceCenteredDiamond discretization.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:56
BaseGridGeometry(std::shared_ptr< BaseImplementation > impl)
Constructor from a BaseImplementation.
Definition basegridgeometry.hh:72
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.
Definition cvfelocalresidual.hh:25
Dune::Std::detected_or_t< Dumux::DiamondGeometryHelper< GV, typename T::SubControlVolume, typename T::SubControlVolumeFace >, SpecifiesGeometryHelper, T > FaceCenteredDiamondGeometryHelper_t
Definition discretization/facecentered/diamond/fvgridgeometry.hh:44
typename T::GeometryHelper SpecifiesGeometryHelper
Definition basegridgeometry.hh:30
PQ1Nonconforming FCDiamond
Definition method.hh:119
Definition adapt.hh:17
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition extrusion.hh:257
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
The default traits for the face-centered diamond finite volume grid geometry Defines the scv and scvf...
Definition discretization/facecentered/diamond/fvgridgeometry.hh:66
FaceCenteredDiamondFVElementGeometry< GridGeometry, enableCache > LocalView
Definition discretization/facecentered/diamond/fvgridgeometry.hh:72
FaceCenteredDiamondSubControlVolume< GridView > SubControlVolume
Definition discretization/facecentered/diamond/fvgridgeometry.hh:67
FaceCenteredDiamondSubControlVolumeFace< GridView > SubControlVolumeFace
Definition discretization/facecentered/diamond/fvgridgeometry.hh:68
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > DofMapper
Definition discretization/facecentered/diamond/fvgridgeometry.hh:69
typename GridView::IndexSet::IndexType GridIndex
Definition indextraits.hh:27
std::uint_least8_t SmallLocalIndex
Definition indextraits.hh:29
Definition periodicgridtraits.hh:24
Definition periodicgridtraits.hh:23
Compute the volume of several common geometry types.