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
36
38
39namespace Dumux {
40
41namespace Detail {
42template<class GV, class T>
43using FaceCenteredDiamondGeometryHelper_t = Dune::Std::detected_or_t<
46 T
47>;
48} // end namespace Detail
49
54template<class GridView, class ScvRule = Dumux::QuadratureRules::MidpointQuadrature, class ScvfRule = Dumux::QuadratureRules::MidpointQuadrature>
56
63template<class GridView, class QuadratureTraits = FaceCenteredDiamondQuadratureTraits<GridView>>
64struct FaceCenteredDiamondDefaultGridGeometryTraits : public DefaultMapperTraits<GridView>, public QuadratureTraits
65{
68 using DofMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
69
70 template<class GridGeometry, bool enableCache>
72};
73
78template<class GV,
79 bool enableCaching = true,
82: public BaseGridGeometry<GV, Traits>
83{
86 using GridIndexType = typename IndexTraits<GV>::GridIndex;
87 using LocalIndexType = typename IndexTraits<GV>::SmallLocalIndex;
88 using Element = typename GV::template Codim<0>::Entity;
89
90 using Scalar = typename GV::ctype;
91
92 static const int dim = GV::dimension;
93 static const int dimWorld = GV::dimensionworld;
94
95 static_assert(dim > 1, "Only implemented for dim > 1");
96
97public:
101 static constexpr bool cachingEnabled = true;
102
104 using LocalView = typename Traits::template LocalView<ThisType, true>;
106 using SubControlVolume = typename Traits::SubControlVolume;
108 using SubControlVolumeFace = typename Traits::SubControlVolumeFace;
110 using GridView = GV;
112 using DofMapper = typename Traits::DofMapper;
120 using ScvQuadratureRule = typename Traits::ScvQuadratureRule;
122 using ScvfQuadratureRule = typename Traits::ScvfQuadratureRule;
123
125 FaceCenteredDiamondFVGridGeometry(const GridView& gridView, const std::string& paramGroup = "")
127 , dofMapper_(gridView, Dune::mcmgLayout(Dune::Codim<1>{}))
128 , cache_(*this)
129 , periodicGridTraits_(this->gridView().grid())
130 {
131 update_();
132 }
133
135 std::size_t numScv() const
136 { return numScv_; }
137
139 std::size_t numScvf() const
140 { return numScvf_; }
141
143 std::size_t numBoundaryScvf() const
144 { return numBoundaryScvf_; }
145
147 std::size_t numDofs() const
148 { return this->gridView().size(1); }
149
152 {
154 update_();
155 }
156
159 {
160 ParentType::update(std::move(gridView));
161 update_();
162 }
163
165 const FeCache& feCache() const
166 { return feCache_; }
167
169 bool dofOnBoundary(GridIndexType dofIdx) const
170 { return boundaryDofIndices_[dofIdx]; }
171
173 const DofMapper& dofMapper() const
174 { return dofMapper_; }
175
177 bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
178 { return periodicFaceMap_.count(dofIdx); }
179
181 GridIndexType periodicallyMappedDof(GridIndexType dofIdx) const
182 { return periodicFaceMap_.at(dofIdx); }
183
185 const std::unordered_map<GridIndexType, GridIndexType>& periodicDofMap() const
186 { return periodicFaceMap_; }
187
190 { return { gg.cache_ }; }
191
192private:
193
194 class FCDiamondGridGeometryCache
195 {
197 public:
200
201 explicit FCDiamondGridGeometryCache(const FaceCenteredDiamondFVGridGeometry& gg)
202 : gridGeometry_(&gg)
203 {}
204
205 const FaceCenteredDiamondFVGridGeometry& gridGeometry() const
206 { return *gridGeometry_; }
207
209 const std::vector<SubControlVolume>& scvs(GridIndexType eIdx) const
210 { return scvs_[eIdx]; }
211
213 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx) const
214 { return scvfs_[eIdx]; }
215
217 bool hasBoundaryScvf(GridIndexType eIdx) const
218 { return hasBoundaryScvf_[eIdx]; }
219
220 private:
221 void clear_()
222 {
223 scvs_.clear();
224 scvfs_.clear();
225 hasBoundaryScvf_.clear();
226 }
227
228 std::vector<std::vector<SubControlVolume>> scvs_;
229 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
230 std::vector<bool> hasBoundaryScvf_;
231
232 const FaceCenteredDiamondFVGridGeometry* gridGeometry_;
233 };
234
235public:
238 using Cache = FCDiamondGridGeometryCache;
239private:
240 using GeometryHelper = typename Cache::GeometryHelper;
241
243 void update_()
244 {
245 // clear containers (necessary after grid refinement)
246 cache_.clear_();
247 dofMapper_.update(this->gridView());
248
249 // determine size of containers
250 const auto numElements = this->gridView().size(0);
251 cache_.scvs_.resize(numElements);
252 cache_.scvfs_.resize(numElements);
253 cache_.hasBoundaryScvf_.resize(numElements, false);
254
255 boundaryDofIndices_.assign(numDofs(), false);
256
257 numScv_ = 0;
258 numScvf_ = 0;
259 numBoundaryScvf_ = 0;
260
261 // Build the scvs and scv faces
262 for (const auto& element : elements(this->gridView()))
263 {
264 const auto eIdx = this->elementMapper().index(element);
265
266 const auto geometry = element.geometry();
267 GeometryHelper geometryHelper(geometry);
268
269 // build the scvs
270 cache_.scvs_[eIdx].reserve(geometryHelper.numScv());
271 numScv_ += geometryHelper.numScv();
272 for (LocalIndexType localScvIdx = 0; localScvIdx < geometryHelper.numScv(); ++localScvIdx)
273 {
274 const auto dofIndex = dofMapper().subIndex(element, localScvIdx, 1);
275 const auto& corners = geometryHelper.getScvCorners(localScvIdx);
276 const auto volume = Dumux::convexPolytopeVolume<dim>(
277 SubControlVolume::Traits::geometryType(geometry.type()),
278 [&](unsigned int i){ return corners[i]; }
279 );
280
281 cache_.scvs_[eIdx].emplace_back(
282 volume,
283 geometryHelper.facetCenter(localScvIdx),
284 Dumux::center(corners),
285 localScvIdx,
286 eIdx,
287 dofIndex
288 );
289 }
290
291 // build interior scvfs
292 LocalIndexType localScvfIdx = 0;
293 cache_.scvfs_[eIdx].reserve(geometryHelper.numInteriorScvf());
294 numScvf_ += geometryHelper.numInteriorScvf();
295 for (; localScvfIdx < geometryHelper.numInteriorScvf(); ++localScvfIdx)
296 {
297 const auto& corners = geometryHelper.getScvfCorners(localScvfIdx);
298 const auto& scvPair = geometryHelper.getInsideOutsideScvForScvf(localScvfIdx);
299 const auto area = Dumux::convexPolytopeVolume<dim-1>(
300 SubControlVolumeFace::Traits::interiorGeometryType(geometry.type()),
301 [&](unsigned int i){ return corners[i]; }
302 );
303
304 cache_.scvfs_[eIdx].emplace_back(
305 Dumux::center(corners),
306 area,
307 geometryHelper.normal(corners, scvPair),
308 scvPair,
309 localScvfIdx
310 );
311 }
312
313 // build boundary scvfs
314 for (const auto& intersection : intersections(this->gridView(), element))
315 {
316 if (onDomainBoundary_(intersection))
317 {
318 // store information that the face dof is on a boundary
319 const LocalIndexType localFacetIndex = intersection.indexInInside();
320 const auto dofIndex = dofMapper().subIndex(element, localFacetIndex, 1);
321 boundaryDofIndices_[dofIndex] = true;
322
323 // and that the element has a boundary face
324 cache_.hasBoundaryScvf_[eIdx] = true;
325
326 // add boundary scvf
327 const auto geo = intersection.geometry();
328 cache_.scvfs_[eIdx].emplace_back(
329 geo.center(),
330 geo.volume(),
331 intersection.centerUnitOuterNormal(),
332 std::array<LocalIndexType, 2>{{localFacetIndex, localFacetIndex}},
333 localScvfIdx,
334 typename SubControlVolumeFace::Traits::BoundaryFlag{ intersection }
335 );
336
337 // increment local and global counters
338 ++localScvfIdx;
339 ++numBoundaryScvf_;
340 ++numScvf_;
341 }
342
343 // handle periodic boundaries
344 if (onPeriodicBoundary_(intersection))
345 {
346 const LocalIndexType localFacetIndex = intersection.indexInInside();
347 const auto dofIndex = dofMapper().subIndex(element, localFacetIndex, 1);
348
349 this->setPeriodic();
350
351 const auto& otherElement = intersection.outside();
352
353 LocalIndexType otherIntersectionLocalIdx = 0;
354 bool periodicFaceFound = false;
355
356 for (const auto& otherIntersection : intersections(this->gridView(), otherElement))
357 {
358 if (periodicFaceFound)
359 continue;
360
361 if (Dune::FloatCmp::eq(intersection.centerUnitOuterNormal()*otherIntersection.centerUnitOuterNormal(), -1.0, 1e-7))
362 {
363 const auto periodicDofIdx = dofMapper().subIndex(otherElement, otherIntersectionLocalIdx, 1);
364 periodicFaceMap_[dofIndex] = periodicDofIdx;
365 periodicFaceFound = true;
366 }
367
368 ++otherIntersectionLocalIdx;
369 }
370 }
371 }
372 }
373 }
374
375 bool onDomainBoundary_(const typename GridView::Intersection& intersection) const
376 {
377 return !intersection.neighbor() && intersection.boundary();
378 }
379
380 bool onProcessorBoundary_(const typename GridView::Intersection& intersection) const
381 {
382 return !intersection.neighbor() && !intersection.boundary();
383 }
384
385 bool onPeriodicBoundary_(const typename GridView::Intersection& intersection) const
386 {
387 return periodicGridTraits_.isPeriodic(intersection);
388 }
389
390 // faces on the boundary
391 std::vector<bool> boundaryDofIndices_;
392
393 DofMapper dofMapper_;
394
395 std::size_t numScv_;
396 std::size_t numScvf_;
397 std::size_t numBoundaryScvf_;
398
399 // a map for periodic boundary vertices
400 std::unordered_map<GridIndexType, GridIndexType> periodicFaceMap_;
401
402 const FeCache feCache_;
403
404 Cache cache_;
405
406 PeriodicGridTraits<typename GridView::Grid> periodicGridTraits_;
407};
408
409} // end namespace Dumux
410
411#endif
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:252
Element-wise grid geometry (local view)
Definition: discretization/facecentered/diamond/fvelementgeometry.hh:36
Grid geometry for the diamond discretization.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:83
static constexpr bool cachingEnabled
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:101
friend LocalView localView(const FaceCenteredDiamondFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:189
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:181
const std::unordered_map< GridIndexType, GridIndexType > & periodicDofMap() const
Returns the map between dofs across periodic boundaries.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:185
FaceCenteredDiamondFVGridGeometry(const GridView &gridView, const std::string &paramGroup="")
Constructor.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:125
GV GridView
export the grid view type
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:110
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:135
typename PeriodicGridTraits< typename GV::Grid >::SupportsPeriodicity SupportsPeriodicity
export whether the grid(geometry) supports periodicity
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:118
FCDiamondGridGeometryCache Cache
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:238
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:108
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a d.o.f. is on a periodic boundary.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:177
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:165
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:114
bool dofOnBoundary(GridIndexType dofIdx) const
If a face / d.o.f. is on the boundary.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:169
static constexpr DiscretizationMethod discMethod
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:100
std::size_t numBoundaryScvf() const
The total number of boundary sub control volume faces.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:143
std::size_t numDofs() const
the total number of dofs
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:147
typename Traits::ScvfQuadratureRule ScvfQuadratureRule
the quadrature rule type for scvfs
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:122
void update(GridView &&gridView)
update all fvElementGeometries (call this after grid adaption)
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:158
const DofMapper & dofMapper() const
Return a reference to the dof mapper.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:173
typename Traits::ScvQuadratureRule ScvQuadratureRule
the quadrature rule type for scvs
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:120
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:104
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:106
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:139
void update(const GridView &gridView)
update all fvElementGeometries (call this after grid adaption)
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:151
typename Traits::DofMapper DofMapper
export the dof mapper type
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:112
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:47
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:166
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:84
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:65
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > DofMapper
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:68
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.