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:
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
230 const auto& boundaryFaceScvfRanges(GridIndexType eIdx) const
231 { return boundaryFaceScvfRanges_[eIdx]; }
232
233 private:
234 void clear_()
235 {
236 scvs_.clear();
237 scvfs_.clear();
238 hasBoundaryScvf_.clear();
239 boundaryFaces_.clear();
240 boundaryFaceScvfRanges_.clear();
241 }
242
243 std::vector<std::vector<SubControlVolume>> scvs_;
244 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
245 std::vector<bool> hasBoundaryScvf_;
246 std::vector<Dune::ReservedVector<BoundaryFace, 2*dim>> boundaryFaces_;
247 std::vector<Dune::ReservedVector<std::array<LocalIndexType, 2>, 2*dim>> boundaryFaceScvfRanges_;
248
249 const FaceCenteredDiamondFVGridGeometry* gridGeometry_;
250 };
251
252public:
255 using Cache = FCDiamondGridGeometryCache;
256private:
257 using GeometryHelper = typename Cache::GeometryHelper;
258
260 void update_()
261 {
262 // clear containers (necessary after grid refinement)
263 cache_.clear_();
264 dofMapper_.update(this->gridView());
265
266 // determine size of containers
267 const auto numElements = this->gridView().size(0);
268 cache_.scvs_.resize(numElements);
269 cache_.scvfs_.resize(numElements);
270 cache_.hasBoundaryScvf_.resize(numElements, false);
271 cache_.boundaryFaces_.resize(numElements);
272 cache_.boundaryFaceScvfRanges_.resize(numElements);
273
274 boundaryDofIndices_.assign(numDofs(), false);
275
276 numScv_ = 0;
277 numScvf_ = 0;
278 numBoundaryScvf_ = 0;
279
280 // Build the scvs and scv faces
281 for (const auto& element : elements(this->gridView()))
282 {
283 const auto eIdx = this->elementMapper().index(element);
284
285 const auto geometry = element.geometry();
286 GeometryHelper geometryHelper(geometry);
287
288 // build the scvs
289 cache_.scvs_[eIdx].reserve(geometryHelper.numScv());
290 numScv_ += geometryHelper.numScv();
291 for (LocalIndexType localScvIdx = 0; localScvIdx < geometryHelper.numScv(); ++localScvIdx)
292 {
293 const auto dofIndex = dofMapper().subIndex(element, localScvIdx, 1);
294 const auto& corners = geometryHelper.getScvCorners(localScvIdx);
296 SubControlVolume::Traits::geometryType(geometry.type()),
297 [&](unsigned int i){ return corners[i]; }
298 );
299
300 cache_.scvs_[eIdx].emplace_back(
301 volume,
302 geometryHelper.facetCenter(localScvIdx),
303 Dumux::center(corners),
304 localScvIdx,
305 eIdx,
306 dofIndex
307 );
308 }
309
310 // build interior scvfs
311 LocalIndexType localScvfIdx = 0;
312 cache_.scvfs_[eIdx].reserve(geometryHelper.numInteriorScvf());
313 numScvf_ += geometryHelper.numInteriorScvf();
314 for (; localScvfIdx < geometryHelper.numInteriorScvf(); ++localScvfIdx)
315 {
316 const auto& corners = geometryHelper.getScvfCorners(localScvfIdx);
317 const auto& scvPair = geometryHelper.getInsideOutsideScvForScvf(localScvfIdx);
318 const auto area = Dumux::convexPolytopeVolume<dim-1>(
319 SubControlVolumeFace::Traits::interiorGeometryType(geometry.type()),
320 [&](unsigned int i){ return corners[i]; }
321 );
322
323 cache_.scvfs_[eIdx].emplace_back(
324 Dumux::center(corners),
325 area,
326 geometryHelper.normal(corners, scvPair),
327 scvPair,
328 localScvfIdx
329 );
330 }
331
332 // build boundary scvfs
333 LocalIndexType numBoundaryFaces = 0;
334 for (const auto& intersection : intersections(this->gridView(), element))
335 {
336 if (onDomainBoundary_(intersection))
337 {
338 // store information that the face dof is on a boundary
339 const LocalIndexType localFacetIndex = intersection.indexInInside();
340 const auto dofIndex = dofMapper().subIndex(element, localFacetIndex, 1);
341 boundaryDofIndices_[dofIndex] = true;
342
343 // and that the element has a boundary face
344 cache_.hasBoundaryScvf_[eIdx] = true;
345
346 // add boundary face
347 {
348 const auto geo = intersection.geometry();
349 cache_.boundaryFaces_[eIdx].push_back(BoundaryFace{
350 geo.center(),
351 geo.volume(),
352 intersection.centerUnitOuterNormal(),
353 numBoundaryFaces++,
354 static_cast<LocalIndexType>(localFacetIndex),
355 typename BoundaryFace::Traits::BoundaryFlag{intersection}
356 });
357
358 // record the scvf subrange for this boundary face: {offset, count=1}
359 cache_.boundaryFaceScvfRanges_[eIdx].push_back(std::array<LocalIndexType, 2>{{
360 localScvfIdx, 1
361 }});
362 }
363
364 // add boundary scvf
365 const auto geo = intersection.geometry();
366 cache_.scvfs_[eIdx].emplace_back(
367 geo.center(),
368 geo.volume(),
369 intersection.centerUnitOuterNormal(),
370 std::array<LocalIndexType, 2>{{localFacetIndex, localFacetIndex}},
371 localScvfIdx,
372 typename SubControlVolumeFace::Traits::BoundaryFlag{ intersection }
373 );
374
375 // increment local and global counters
376 ++localScvfIdx;
377 ++numBoundaryScvf_;
378 ++numScvf_;
379 }
380
381 // handle periodic boundaries
382 if (onPeriodicBoundary_(intersection))
383 {
384 const LocalIndexType localFacetIndex = intersection.indexInInside();
385 const auto dofIndex = dofMapper().subIndex(element, localFacetIndex, 1);
386
387 this->setPeriodic();
388
389 const auto& otherElement = intersection.outside();
390
391 LocalIndexType otherIntersectionLocalIdx = 0;
392 bool periodicFaceFound = false;
393
394 for (const auto& otherIntersection : intersections(this->gridView(), otherElement))
395 {
396 if (periodicFaceFound)
397 continue;
398
399 if (Dune::FloatCmp::eq(intersection.centerUnitOuterNormal()*otherIntersection.centerUnitOuterNormal(), -1.0, 1e-7))
400 {
401 const auto periodicDofIdx = dofMapper().subIndex(otherElement, otherIntersectionLocalIdx, 1);
402 periodicFaceMap_[dofIndex] = periodicDofIdx;
403 periodicFaceFound = true;
404 }
405
406 ++otherIntersectionLocalIdx;
407 }
408 }
409 }
410 }
411 }
412
413 bool onDomainBoundary_(const typename GridView::Intersection& intersection) const
414 {
415 return !intersection.neighbor() && intersection.boundary();
416 }
417
418 bool onProcessorBoundary_(const typename GridView::Intersection& intersection) const
419 {
420 return !intersection.neighbor() && !intersection.boundary();
421 }
422
423 bool onPeriodicBoundary_(const typename GridView::Intersection& intersection) const
424 {
425 return periodicGridTraits_.isPeriodic(intersection);
426 }
427
428 // faces on the boundary
429 std::vector<bool> boundaryDofIndices_;
430
431 DofMapper dofMapper_;
432
433 std::size_t numScv_;
434 std::size_t numScvf_;
435 std::size_t numBoundaryScvf_;
436
437 // a map for periodic boundary vertices
438 std::unordered_map<GridIndexType, GridIndexType> periodicFaceMap_;
439
440 const FeCache feCache_;
441
442 Cache cache_;
443
445};
446
447} // end namespace Dumux
448
449#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:252
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:255
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
CVFE< CVFEMethods::CR_RT > FCDiamond
Definition method.hh:109
Definition adapt.hh:17
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition extrusion.hh:236
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.