version 3.8.0
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-FileCopyrightInfo: 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
37namespace Dumux {
38
39namespace Detail {
40template<class GV, class T>
41using FaceCenteredDiamondGeometryHelper_t = Dune::Std::detected_or_t<
44 T
45>;
46} // end namespace Detail
47
54template<class GridView>
64
69template<class GV,
70 bool enableCaching = true,
73: public BaseGridGeometry<GV, Traits>
74{
77 using GridIndexType = typename IndexTraits<GV>::GridIndex;
78 using LocalIndexType = typename IndexTraits<GV>::SmallLocalIndex;
79 using Element = typename GV::template Codim<0>::Entity;
80
81 using Scalar = typename GV::ctype;
82
83 static const int dim = GV::dimension;
84 static const int dimWorld = GV::dimensionworld;
85
86 static_assert(dim > 1, "Only implemented for dim > 1");
87
88public:
92 static constexpr bool cachingEnabled = true;
93
95 using LocalView = typename Traits::template LocalView<ThisType, true>;
97 using SubControlVolume = typename Traits::SubControlVolume;
99 using SubControlVolumeFace = typename Traits::SubControlVolumeFace;
101 using GridView = GV;
103 using DofMapper = typename Traits::DofMapper;
108
110 FaceCenteredDiamondFVGridGeometry(const GridView& gridView, const std::string& paramGroup = "")
112 , dofMapper_(gridView, Dune::mcmgLayout(Dune::Codim<1>{}))
113 , cache_(*this)
114 {
115 update_();
116 }
117
119 std::size_t numScv() const
120 { return numScv_; }
121
123 std::size_t numScvf() const
124 { return numScvf_; }
125
127 std::size_t numBoundaryScvf() const
128 { return numBoundaryScvf_; }
129
131 std::size_t numDofs() const
132 { return this->gridView().size(1); }
133
136 {
138 update_();
139 }
140
143 {
144 ParentType::update(std::move(gridView));
145 update_();
146 }
147
149 const FeCache& feCache() const
150 { return feCache_; }
151
153 bool dofOnBoundary(GridIndexType dofIdx) const
154 { return boundaryDofIndices_[dofIdx]; }
155
157 const DofMapper& dofMapper() const
158 { return dofMapper_; }
159
161 bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
162 { return periodicFaceMap_.count(dofIdx); }
163
165 GridIndexType periodicallyMappedDof(GridIndexType dofIdx) const
166 { return periodicFaceMap_.at(dofIdx); }
167
169 const std::unordered_map<GridIndexType, GridIndexType>& periodicVertexMap() const
170 { return periodicFaceMap_; }
171
174 { return { gg.cache_ }; }
175
176private:
177
178 class FCDiamondGridGeometryCache
179 {
181 public:
184
185 explicit FCDiamondGridGeometryCache(const FaceCenteredDiamondFVGridGeometry& gg)
186 : gridGeometry_(&gg)
187 {}
188
189 const FaceCenteredDiamondFVGridGeometry& gridGeometry() const
190 { return *gridGeometry_; }
191
193 const std::vector<SubControlVolume>& scvs(GridIndexType eIdx) const
194 { return scvs_[eIdx]; }
195
197 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx) const
198 { return scvfs_[eIdx]; }
199
201 bool hasBoundaryScvf(GridIndexType eIdx) const
202 { return hasBoundaryScvf_[eIdx]; }
203
204 private:
205 void clear_()
206 {
207 scvs_.clear();
208 scvfs_.clear();
209 hasBoundaryScvf_.clear();
210 }
211
212 std::vector<std::vector<SubControlVolume>> scvs_;
213 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
214 std::vector<bool> hasBoundaryScvf_;
215
216 const FaceCenteredDiamondFVGridGeometry* gridGeometry_;
217 };
218
219public:
222 using Cache = FCDiamondGridGeometryCache;
223private:
224 using GeometryHelper = typename Cache::GeometryHelper;
225
227 void update_()
228 {
229 // clear containers (necessary after grid refinement)
230 cache_.clear_();
231 dofMapper_.update(this->gridView());
232
233 // determine size of containers
234 const auto numElements = this->gridView().size(0);
235 cache_.scvs_.resize(numElements);
236 cache_.scvfs_.resize(numElements);
237 cache_.hasBoundaryScvf_.resize(numElements, false);
238
239 boundaryDofIndices_.assign(numDofs(), false);
240
241 numScv_ = 0;
242 numScvf_ = 0;
243 numBoundaryScvf_ = 0;
244
245 // Build the scvs and scv faces
246 for (const auto& element : elements(this->gridView()))
247 {
248 const auto eIdx = this->elementMapper().index(element);
249
250 const auto geometry = element.geometry();
251 GeometryHelper geometryHelper(geometry);
252
253 // build the scvs
254 cache_.scvs_[eIdx].reserve(geometryHelper.numScv());
255 numScv_ += geometryHelper.numScv();
256 for (LocalIndexType localScvIdx = 0; localScvIdx < geometryHelper.numScv(); ++localScvIdx)
257 {
258 const auto dofIndex = dofMapper().subIndex(element, localScvIdx, 1);
259 const auto& corners = geometryHelper.getScvCorners(localScvIdx);
260 const auto volume = Dumux::convexPolytopeVolume<dim>(
261 SubControlVolume::Traits::geometryType(geometry.type()),
262 [&](unsigned int i){ return corners[i]; }
263 );
264
265 cache_.scvs_[eIdx].emplace_back(
266 volume,
267 geometryHelper.facetCenter(localScvIdx),
268 Dumux::center(corners),
269 localScvIdx,
270 eIdx,
271 dofIndex
272 );
273 }
274
275 // build interior scvfs
276 LocalIndexType localScvfIdx = 0;
277 cache_.scvfs_[eIdx].reserve(geometryHelper.numInteriorScvf());
278 numScvf_ += geometryHelper.numInteriorScvf();
279 for (; localScvfIdx < geometryHelper.numInteriorScvf(); ++localScvfIdx)
280 {
281 const auto& corners = geometryHelper.getScvfCorners(localScvfIdx);
282 const auto& scvPair = geometryHelper.getInsideOutsideScvForScvf(localScvfIdx);
283 const auto area = Dumux::convexPolytopeVolume<dim-1>(
284 SubControlVolumeFace::Traits::interiorGeometryType(geometry.type()),
285 [&](unsigned int i){ return corners[i]; }
286 );
287
288 cache_.scvfs_[eIdx].emplace_back(
289 Dumux::center(corners),
290 area,
291 geometryHelper.normal(corners, scvPair),
292 scvPair,
293 localScvfIdx
294 );
295 }
296
297 // build boundary scvfs
298 for (const auto& intersection : intersections(this->gridView(), element))
299 {
300 if (onDomainBoundary_(intersection))
301 {
302 // store information that the face dof is on a boundary
303 const LocalIndexType localFacetIndex = intersection.indexInInside();
304 const auto dofIndex = dofMapper().subIndex(element, localFacetIndex, 1);
305 boundaryDofIndices_[dofIndex] = true;
306
307 // and that the element has a boundary face
308 cache_.hasBoundaryScvf_[eIdx] = true;
309
310 // add boundary scvf
311 const auto geo = intersection.geometry();
312 cache_.scvfs_[eIdx].emplace_back(
313 geo.center(),
314 geo.volume(),
315 intersection.centerUnitOuterNormal(),
316 std::array<LocalIndexType, 2>{{localFacetIndex, localFacetIndex}},
317 localScvfIdx,
318 typename SubControlVolumeFace::Traits::BoundaryFlag{ intersection }
319 );
320
321 // increment local and global counters
322 ++localScvfIdx;
323 ++numBoundaryScvf_;
324 ++numScvf_;
325 }
326
327 // handle periodic boundaries
328 if (onPeriodicBoundary_(intersection))
329 {
330 const LocalIndexType localFacetIndex = intersection.indexInInside();
331 const auto dofIndex = dofMapper().subIndex(element, localFacetIndex, 1);
332
333 this->setPeriodic();
334
335 const auto& otherElement = intersection.outside();
336
337 LocalIndexType otherIntersectionLocalIdx = 0;
338 bool periodicFaceFound = false;
339
340 for (const auto& otherIntersection : intersections(this->gridView(), otherElement))
341 {
342 if (periodicFaceFound)
343 continue;
344
345 if (Dune::FloatCmp::eq(intersection.centerUnitOuterNormal()*otherIntersection.centerUnitOuterNormal(), -1.0, 1e-7))
346 {
347 const auto periodicDofIdx = dofMapper().subIndex(otherElement, otherIntersectionLocalIdx, 1);
348 periodicFaceMap_[dofIndex] = periodicDofIdx;
349 periodicFaceFound = true;
350 }
351
352 ++otherIntersectionLocalIdx;
353 }
354 }
355 }
356 }
357 }
358
359 bool onDomainBoundary_(const typename GridView::Intersection& intersection) const
360 {
361 return !intersection.neighbor() && intersection.boundary();
362 }
363
364 bool onProcessorBoundary_(const typename GridView::Intersection& intersection) const
365 {
366 return !intersection.neighbor() && !intersection.boundary();
367 }
368
369 bool onPeriodicBoundary_(const typename GridView::Intersection& intersection) const
370 {
371 return intersection.boundary() && intersection.neighbor();
372 }
373
374 // faces on the boundary
375 std::vector<bool> boundaryDofIndices_;
376
377 DofMapper dofMapper_;
378
379 std::size_t numScv_;
380 std::size_t numScvf_;
381 std::size_t numBoundaryScvf_;
382
383 // a map for periodic boundary vertices
384 std::unordered_map<GridIndexType, GridIndexType> periodicFaceMap_;
385
386 const FeCache feCache_;
387
388 Cache cache_;
389};
390
391} // end namespace Dumux
392
393#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:255
Element-wise grid geometry (local view)
Definition discretization/facecentered/diamond/fvelementgeometry.hh:32
Grid geometry for the diamond discretization.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:74
static constexpr bool cachingEnabled
Definition discretization/facecentered/diamond/fvgridgeometry.hh:92
friend LocalView localView(const FaceCenteredDiamondFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition discretization/facecentered/diamond/fvgridgeometry.hh:173
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:165
FaceCenteredDiamondFVGridGeometry(const GridView &gridView, const std::string &paramGroup="")
Constructor.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:110
GV GridView
export the grid view type
Definition discretization/facecentered/diamond/fvgridgeometry.hh:101
std::size_t numScv() const
The total number of sub control volumes.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:119
FCDiamondGridGeometryCache Cache
Definition discretization/facecentered/diamond/fvgridgeometry.hh:222
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition discretization/facecentered/diamond/fvgridgeometry.hh:99
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a d.o.f. is on a periodic boundary.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:161
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:149
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition discretization/facecentered/diamond/fvgridgeometry.hh:105
bool dofOnBoundary(GridIndexType dofIdx) const
If a face / d.o.f. is on the boundary.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:153
const std::unordered_map< GridIndexType, GridIndexType > & periodicVertexMap() const
Returns the map between dofs across periodic boundaries // TODO rename to periodic dof map in fvassem...
Definition discretization/facecentered/diamond/fvgridgeometry.hh:169
static constexpr DiscretizationMethod discMethod
Definition discretization/facecentered/diamond/fvgridgeometry.hh:91
std::size_t numBoundaryScvf() const
The total number of boundary sub control volume faces.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:127
std::size_t numDofs() const
the total number of dofs
Definition discretization/facecentered/diamond/fvgridgeometry.hh:131
void update(GridView &&gridView)
update all fvElementGeometries (call this after grid adaption)
Definition discretization/facecentered/diamond/fvgridgeometry.hh:142
const DofMapper & dofMapper() const
Return a reference to the dof mapper.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:157
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:95
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition discretization/facecentered/diamond/fvgridgeometry.hh:97
std::size_t numScvf() const
The total number of sub control volume faces.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:123
void update(const GridView &gridView)
update all fvElementGeometries (call this after grid adaption)
Definition discretization/facecentered/diamond/fvgridgeometry.hh:135
typename Traits::DofMapper DofMapper
export the dof mapper type
Definition discretization/facecentered/diamond/fvgridgeometry.hh:103
The SCVF implementation for diamond.
Definition discretization/facecentered/diamond/subcontrolvolumeface.hh:63
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.
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:41
typename T::GeometryHelper SpecifiesGeometryHelper
Definition basegridgeometry.hh:30
CVFE< CVFEMethods::CR_RT > FCDiamond
Definition method.hh:101
Definition adapt.hh:17
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition extrusion.hh:166
Definition common/pdesolver.hh:24
A finite element cache for the non-conforming FE spaces RT and CR.
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:56
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > DofMapper
Definition discretization/facecentered/diamond/fvgridgeometry.hh:59
typename GridView::IndexSet::IndexType GridIndex
Definition indextraits.hh:27
std::uint_least8_t SmallLocalIndex
Definition indextraits.hh:29
Compute the volume of several common geometry types.