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 <ranges>
17#include <unordered_map>
18
19#include <dune/grid/common/mcmgmapper.hh>
20#include <dune/geometry/type.hh>
21
24#include <dumux/common/math.hh>
32
38
40
41namespace Dumux {
42
43namespace Detail {
44template<class GV, class T>
45using FaceCenteredDiamondGeometryHelper_t = Dune::Std::detected_or_t<
48 T
49>;
50} // end namespace Detail
51
56template<class GridView, class ScvRule = Dumux::QuadratureRules::MidpointQuadrature, class ScvfRule = Dumux::QuadratureRules::MidpointQuadrature>
58
65template<class GridView, class QuadratureTraits = FaceCenteredDiamondQuadratureTraits<GridView>>
66struct FaceCenteredDiamondDefaultGridGeometryTraits : public DefaultMapperTraits<GridView>, public QuadratureTraits
67{
70 using DofMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
71
72 template<class GridGeometry, bool enableCache>
74};
75
80template<class GV,
81 bool enableCaching = true,
84: public BaseGridGeometry<GV, Traits>
85{
87 using ParentType = BaseGridGeometry<GV, Traits>;
88 using GridIndexType = typename IndexTraits<GV>::GridIndex;
89 using LocalIndexType = typename IndexTraits<GV>::SmallLocalIndex;
90 using Element = typename GV::template Codim<0>::Entity;
91
92 using Scalar = typename GV::ctype;
93
94 static const int dim = GV::dimension;
95 static const int dimWorld = GV::dimensionworld;
96
97 static_assert(dim > 1, "Only implemented for dim > 1");
98
99public:
103 static constexpr bool cachingEnabled = true;
104
105 static constexpr bool enableHybridCVFE = false;
106
108 using LocalView = typename Traits::template LocalView<ThisType, true>;
110 using SubControlVolume = typename Traits::SubControlVolume;
112 using SubControlVolumeFace = typename Traits::SubControlVolumeFace;
114 using GridView = GV;
116 using DofMapper = typename Traits::DofMapper;
124 using ScvQuadratureRule = typename Traits::ScvQuadratureRule;
126 using ScvfQuadratureRule = typename Traits::ScvfQuadratureRule;
129
131 FaceCenteredDiamondFVGridGeometry(const GridView& gridView, const std::string& paramGroup = "")
132 : ParentType(gridView)
133 , dofMapper_(gridView, Dune::mcmgLayout(Dune::Codim<1>{}))
134 , cache_(*this)
135 , periodicGridTraits_(this->gridView().grid())
136 {
137 update_();
138 }
139
141 std::size_t numScv() const
142 { return numScv_; }
143
145 std::size_t numScvf() const
146 { return numScvf_; }
147
149 std::size_t numBoundaryScvf() const
150 { return numBoundaryScvf_; }
151
153 std::size_t numDofs() const
154 { return this->gridView().size(1); }
155
158 {
160 update_();
161 }
162
165 {
166 ParentType::update(std::move(gridView));
167 update_();
168 }
169
171 const FeCache& feCache() const
172 { return feCache_; }
173
175 bool dofOnBoundary(GridIndexType dofIdx) const
176 { return boundaryDofIndices_[dofIdx]; }
177
179 const DofMapper& dofMapper() const
180 { return dofMapper_; }
181
183 bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
184 { return periodicFaceMap_.count(dofIdx); }
185
187 [[deprecated("Will be removed after release 3.11. Use periodicallyMappedDofs, returning a range of dofs")]]
188 GridIndexType periodicallyMappedDof(GridIndexType dofIdx) const
189 { return periodicFaceMap_.at(dofIdx)[0]; }
190
192 const std::ranges::range auto periodicallyMappedDofs(GridIndexType dofIdx) const
193 { return std::views::all(periodicFaceMap_.at(dofIdx)); }
194
196 const std::unordered_map<GridIndexType, std::array<GridIndexType, 1>>& periodicDofMap() const
197 { return periodicFaceMap_; }
198
201 { return { gg.cache_ }; }
202
203private:
204
205 class FCDiamondGridGeometryCache
206 {
208 public:
212 using DofHelper = typename GeometryHelper::DofHelper;
213
214 explicit FCDiamondGridGeometryCache(const FaceCenteredDiamondFVGridGeometry& gg)
215 : gridGeometry_(&gg)
216 {}
217
218 const FaceCenteredDiamondFVGridGeometry& gridGeometry() const
219 { return *gridGeometry_; }
220
222 const std::vector<SubControlVolume>& scvs(GridIndexType eIdx) const
223 { return scvs_[eIdx]; }
224
226 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx) const
227 { return scvfs_[eIdx]; }
228
230 bool hasBoundaryScvf(GridIndexType eIdx) const
231 { return hasBoundaryScvf_[eIdx]; }
232
234 const auto& boundaryFaces(GridIndexType eIdx) const
235 { return boundaryFaces_[eIdx]; }
236
238 const auto& boundaryFaceScvfRanges(GridIndexType eIdx) const
239 { return boundaryFaceScvfRanges_[eIdx]; }
240
241 private:
242 void clear_()
243 {
244 scvs_.clear();
245 scvfs_.clear();
246 hasBoundaryScvf_.clear();
247 boundaryFaces_.clear();
248 boundaryFaceScvfRanges_.clear();
249 }
250
251 std::vector<std::vector<SubControlVolume>> scvs_;
252 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
253 std::vector<bool> hasBoundaryScvf_;
254 std::vector<Dune::ReservedVector<BoundaryFace, 2*dim>> boundaryFaces_;
255 std::vector<Dune::ReservedVector<std::array<LocalIndexType, 2>, 2*dim>> boundaryFaceScvfRanges_;
256
257 const FaceCenteredDiamondFVGridGeometry* gridGeometry_;
258 };
259
260public:
263 using Cache = FCDiamondGridGeometryCache;
264private:
265 using GeometryHelper = typename Cache::GeometryHelper;
266
268 void update_()
269 {
270 // clear containers (necessary after grid refinement)
271 cache_.clear_();
272 dofMapper_.update(this->gridView());
273
274 // determine size of containers
275 const auto numElements = this->gridView().size(0);
276 cache_.scvs_.resize(numElements);
277 cache_.scvfs_.resize(numElements);
278 cache_.hasBoundaryScvf_.resize(numElements, false);
279 cache_.boundaryFaces_.resize(numElements);
280 cache_.boundaryFaceScvfRanges_.resize(numElements);
281
282 boundaryDofIndices_.assign(numDofs(), false);
283
284 numScv_ = 0;
285 numScvf_ = 0;
286 numBoundaryScvf_ = 0;
287
288 // Build the scvs and scv faces
289 for (const auto& element : elements(this->gridView()))
290 {
291 const auto eIdx = this->elementMapper().index(element);
292
293 const auto geometry = element.geometry();
294 GeometryHelper geometryHelper(geometry);
295
296 // build the scvs
297 cache_.scvs_[eIdx].reserve(geometryHelper.numScv());
298 numScv_ += geometryHelper.numScv();
299 for (LocalIndexType localScvIdx = 0; localScvIdx < geometryHelper.numScv(); ++localScvIdx)
300 {
301 const auto dofIndex = dofMapper().subIndex(element, localScvIdx, 1);
302 const auto& corners = geometryHelper.getScvCorners(localScvIdx);
304 SubControlVolume::Traits::geometryType(geometry.type()),
305 [&](unsigned int i){ return corners[i]; }
306 );
307
308 cache_.scvs_[eIdx].emplace_back(
309 volume,
310 geometryHelper.facetCenter(localScvIdx),
311 Dumux::center(corners),
312 localScvIdx,
313 eIdx,
314 dofIndex
315 );
316 }
317
318 // build interior scvfs
319 LocalIndexType localScvfIdx = 0;
320 cache_.scvfs_[eIdx].reserve(geometryHelper.numInteriorScvf());
321 numScvf_ += geometryHelper.numInteriorScvf();
322 for (; localScvfIdx < geometryHelper.numInteriorScvf(); ++localScvfIdx)
323 {
324 const auto& corners = geometryHelper.getScvfCorners(localScvfIdx);
325 const auto& scvPair = geometryHelper.getInsideOutsideScvForScvf(localScvfIdx);
326 const auto area = Dumux::convexPolytopeVolume<dim-1>(
327 SubControlVolumeFace::Traits::interiorGeometryType(geometry.type()),
328 [&](unsigned int i){ return corners[i]; }
329 );
330
331 cache_.scvfs_[eIdx].emplace_back(
332 Dumux::center(corners),
333 area,
334 geometryHelper.normal(corners, scvPair),
335 scvPair,
336 localScvfIdx
337 );
338 }
339
340 // build boundary scvfs
341 LocalIndexType numBoundaryFaces = 0;
342 for (const auto& intersection : intersections(this->gridView(), element))
343 {
344 if (onDomainBoundary_(intersection))
345 {
346 // store information that the face dof is on a boundary
347 const LocalIndexType localFacetIndex = intersection.indexInInside();
348 const auto dofIndex = dofMapper().subIndex(element, localFacetIndex, 1);
349 boundaryDofIndices_[dofIndex] = true;
350
351 // and that the element has a boundary face
352 cache_.hasBoundaryScvf_[eIdx] = true;
353
354 // add boundary face
355 {
356 const auto geo = intersection.geometry();
357 cache_.boundaryFaces_[eIdx].push_back(BoundaryFace{
358 geo.center(),
359 geo.volume(),
360 intersection.centerUnitOuterNormal(),
361 numBoundaryFaces++,
362 static_cast<LocalIndexType>(localFacetIndex),
363 typename BoundaryFace::Traits::BoundaryFlag{intersection}
364 });
365
366 // record the scvf subrange for this boundary face: {offset, count=1}
367 cache_.boundaryFaceScvfRanges_[eIdx].push_back(std::array<LocalIndexType, 2>{{
368 localScvfIdx, 1
369 }});
370 }
371
372 // add boundary scvf
373 const auto geo = intersection.geometry();
374 cache_.scvfs_[eIdx].emplace_back(
375 geo.center(),
376 geo.volume(),
377 intersection.centerUnitOuterNormal(),
378 std::array<LocalIndexType, 2>{{localFacetIndex, localFacetIndex}},
379 localScvfIdx,
380 typename SubControlVolumeFace::Traits::BoundaryFlag{ intersection }
381 );
382
383 // increment local and global counters
384 ++localScvfIdx;
385 ++numBoundaryScvf_;
386 ++numScvf_;
387 }
388
389 // handle periodic boundaries
390 if (onPeriodicBoundary_(intersection))
391 {
392 const LocalIndexType localFacetIndex = intersection.indexInInside();
393 const auto dofIndex = dofMapper().subIndex(element, localFacetIndex, 1);
394
395 this->setPeriodic();
396
397 const auto& otherElement = intersection.outside();
398
399 LocalIndexType otherIntersectionLocalIdx = 0;
400 bool periodicFaceFound = false;
401
402 for (const auto& otherIntersection : intersections(this->gridView(), otherElement))
403 {
404 if (periodicFaceFound)
405 continue;
406
407 if (Dune::FloatCmp::eq(intersection.centerUnitOuterNormal()*otherIntersection.centerUnitOuterNormal(), -1.0, 1e-7))
408 {
409 const auto periodicDofIdx = dofMapper().subIndex(otherElement, otherIntersectionLocalIdx, 1);
410 periodicFaceMap_[dofIndex][0] = periodicDofIdx;
411 periodicFaceFound = true;
412 }
413
414 ++otherIntersectionLocalIdx;
415 }
416 }
417 }
418 }
419 }
420
421 bool onDomainBoundary_(const typename GridView::Intersection& intersection) const
422 {
423 return !intersection.neighbor() && intersection.boundary();
424 }
425
426 bool onProcessorBoundary_(const typename GridView::Intersection& intersection) const
427 {
428 return !intersection.neighbor() && !intersection.boundary();
429 }
430
431 bool onPeriodicBoundary_(const typename GridView::Intersection& intersection) const
432 {
433 return periodicGridTraits_.isPeriodic(intersection);
434 }
435
436 // faces on the boundary
437 std::vector<bool> boundaryDofIndices_;
438
439 DofMapper dofMapper_;
440
441 std::size_t numScv_;
442 std::size_t numScvf_;
443 std::size_t numBoundaryScvf_;
444
445 // a map for periodic boundary vertices
446 std::unordered_map<GridIndexType, std::array<GridIndexType, 1>> periodicFaceMap_;
447
448 const FeCache feCache_;
449
450 Cache cache_;
451
453};
454
455} // end namespace Dumux
456
457#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:257
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:85
static constexpr bool cachingEnabled
Definition discretization/facecentered/diamond/fvgridgeometry.hh:103
Experimental::BoundaryFace< GV > BoundaryFace
Definition discretization/facecentered/diamond/fvgridgeometry.hh:128
friend LocalView localView(const FaceCenteredDiamondFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition discretization/facecentered/diamond/fvgridgeometry.hh:200
DiscretizationMethods::FCDiamond DiscretizationMethod
Definition discretization/facecentered/diamond/fvgridgeometry.hh:101
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:188
FaceCenteredDiamondFVGridGeometry(const GridView &gridView, const std::string &paramGroup="")
Constructor.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:131
GV GridView
Definition discretization/facecentered/diamond/fvgridgeometry.hh:114
std::size_t numScv() const
The total number of sub control volumes.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:141
typename PeriodicGridTraits< typename GV::Grid >::SupportsPeriodicity SupportsPeriodicity
Definition discretization/facecentered/diamond/fvgridgeometry.hh:122
FCDiamondGridGeometryCache Cache
Definition discretization/facecentered/diamond/fvgridgeometry.hh:263
typename Traits::SubControlVolumeFace SubControlVolumeFace
Definition discretization/facecentered/diamond/fvgridgeometry.hh:112
const std::ranges::range auto periodicallyMappedDofs(GridIndexType dofIdx) const
The index of the d.o.f. on the other side of the periodic boundary.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:192
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a d.o.f. is on a periodic boundary.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:183
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:171
Extrusion_t< Traits > Extrusion
Definition discretization/facecentered/diamond/fvgridgeometry.hh:118
bool dofOnBoundary(GridIndexType dofIdx) const
If a face / d.o.f. is on the boundary.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:175
static constexpr DiscretizationMethod discMethod
Definition discretization/facecentered/diamond/fvgridgeometry.hh:102
std::size_t numBoundaryScvf() const
The total number of boundary sub control volume faces.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:149
const std::unordered_map< GridIndexType, std::array< GridIndexType, 1 > > & periodicDofMap() const
Returns the map between dofs across periodic boundaries.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:196
static constexpr bool enableHybridCVFE
Definition discretization/facecentered/diamond/fvgridgeometry.hh:105
std::size_t numDofs() const
the total number of dofs
Definition discretization/facecentered/diamond/fvgridgeometry.hh:153
typename Traits::ScvfQuadratureRule ScvfQuadratureRule
Definition discretization/facecentered/diamond/fvgridgeometry.hh:126
void update(GridView &&gridView)
update all fvElementGeometries (call this after grid adaption)
Definition discretization/facecentered/diamond/fvgridgeometry.hh:164
const DofMapper & dofMapper() const
Return a reference to the dof mapper.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:179
typename Traits::ScvQuadratureRule ScvQuadratureRule
Definition discretization/facecentered/diamond/fvgridgeometry.hh:124
NonconformingFECache< Scalar, Scalar, dim > FeCache
Definition discretization/facecentered/diamond/fvgridgeometry.hh:120
typename Traits::template LocalView< ThisType, true > LocalView
Definition discretization/facecentered/diamond/fvgridgeometry.hh:108
typename Traits::SubControlVolume SubControlVolume
Definition discretization/facecentered/diamond/fvgridgeometry.hh:110
std::size_t numScvf() const
The total number of sub control volume faces.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:145
void update(const GridView &gridView)
update all fvElementGeometries (call this after grid adaption)
Definition discretization/facecentered/diamond/fvgridgeometry.hh:157
typename Traits::DofMapper DofMapper
Definition discretization/facecentered/diamond/fvgridgeometry.hh:116
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:57
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:45
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:86
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:67
FaceCenteredDiamondFVElementGeometry< GridGeometry, enableCache > LocalView
Definition discretization/facecentered/diamond/fvgridgeometry.hh:73
FaceCenteredDiamondSubControlVolume< GridView > SubControlVolume
Definition discretization/facecentered/diamond/fvgridgeometry.hh:68
FaceCenteredDiamondSubControlVolumeFace< GridView > SubControlVolumeFace
Definition discretization/facecentered/diamond/fvgridgeometry.hh:69
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > DofMapper
Definition discretization/facecentered/diamond/fvgridgeometry.hh:70
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.