version 3.10.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-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
56template<class GridView>
66
71template<class GV,
72 bool enableCaching = true,
75: public BaseGridGeometry<GV, Traits>
76{
78 using ParentType = BaseGridGeometry<GV, Traits>;
79 using GridIndexType = typename IndexTraits<GV>::GridIndex;
80 using LocalIndexType = typename IndexTraits<GV>::SmallLocalIndex;
81 using Element = typename GV::template Codim<0>::Entity;
82
83 using Scalar = typename GV::ctype;
84
85 static const int dim = GV::dimension;
86 static const int dimWorld = GV::dimensionworld;
87
88 static_assert(dim > 1, "Only implemented for dim > 1");
89
90public:
94 static constexpr bool cachingEnabled = true;
95
97 using LocalView = typename Traits::template LocalView<ThisType, true>;
99 using SubControlVolume = typename Traits::SubControlVolume;
101 using SubControlVolumeFace = typename Traits::SubControlVolumeFace;
103 using GridView = GV;
105 using DofMapper = typename Traits::DofMapper;
112
114 FaceCenteredDiamondFVGridGeometry(const GridView& gridView, const std::string& paramGroup = "")
115 : ParentType(gridView)
116 , dofMapper_(gridView, Dune::mcmgLayout(Dune::Codim<1>{}))
117 , cache_(*this)
118 , periodicGridTraits_(this->gridView().grid())
119 {
120 update_();
121 }
122
124 std::size_t numScv() const
125 { return numScv_; }
126
128 std::size_t numScvf() const
129 { return numScvf_; }
130
132 std::size_t numBoundaryScvf() const
133 { return numBoundaryScvf_; }
134
136 std::size_t numDofs() const
137 { return this->gridView().size(1); }
138
141 {
143 update_();
144 }
145
148 {
149 ParentType::update(std::move(gridView));
150 update_();
151 }
152
154 const FeCache& feCache() const
155 { return feCache_; }
156
158 bool dofOnBoundary(GridIndexType dofIdx) const
159 { return boundaryDofIndices_[dofIdx]; }
160
162 const DofMapper& dofMapper() const
163 { return dofMapper_; }
164
166 bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
167 { return periodicFaceMap_.count(dofIdx); }
168
170 GridIndexType periodicallyMappedDof(GridIndexType dofIdx) const
171 { return periodicFaceMap_.at(dofIdx); }
172
174 const std::unordered_map<GridIndexType, GridIndexType>& periodicDofMap() const
175 { return periodicFaceMap_; }
176
179 { return { gg.cache_ }; }
180
181private:
182
183 class FCDiamondGridGeometryCache
184 {
186 public:
189
190 explicit FCDiamondGridGeometryCache(const FaceCenteredDiamondFVGridGeometry& gg)
191 : gridGeometry_(&gg)
192 {}
193
194 const FaceCenteredDiamondFVGridGeometry& gridGeometry() const
195 { return *gridGeometry_; }
196
198 const std::vector<SubControlVolume>& scvs(GridIndexType eIdx) const
199 { return scvs_[eIdx]; }
200
202 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx) const
203 { return scvfs_[eIdx]; }
204
206 bool hasBoundaryScvf(GridIndexType eIdx) const
207 { return hasBoundaryScvf_[eIdx]; }
208
209 private:
210 void clear_()
211 {
212 scvs_.clear();
213 scvfs_.clear();
214 hasBoundaryScvf_.clear();
215 }
216
217 std::vector<std::vector<SubControlVolume>> scvs_;
218 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
219 std::vector<bool> hasBoundaryScvf_;
220
221 const FaceCenteredDiamondFVGridGeometry* gridGeometry_;
222 };
223
224public:
227 using Cache = FCDiamondGridGeometryCache;
228private:
229 using GeometryHelper = typename Cache::GeometryHelper;
230
232 void update_()
233 {
234 // clear containers (necessary after grid refinement)
235 cache_.clear_();
236 dofMapper_.update(this->gridView());
237
238 // determine size of containers
239 const auto numElements = this->gridView().size(0);
240 cache_.scvs_.resize(numElements);
241 cache_.scvfs_.resize(numElements);
242 cache_.hasBoundaryScvf_.resize(numElements, false);
243
244 boundaryDofIndices_.assign(numDofs(), false);
245
246 numScv_ = 0;
247 numScvf_ = 0;
248 numBoundaryScvf_ = 0;
249
250 // Build the scvs and scv faces
251 for (const auto& element : elements(this->gridView()))
252 {
253 const auto eIdx = this->elementMapper().index(element);
254
255 const auto geometry = element.geometry();
256 GeometryHelper geometryHelper(geometry);
257
258 // build the scvs
259 cache_.scvs_[eIdx].reserve(geometryHelper.numScv());
260 numScv_ += geometryHelper.numScv();
261 for (LocalIndexType localScvIdx = 0; localScvIdx < geometryHelper.numScv(); ++localScvIdx)
262 {
263 const auto dofIndex = dofMapper().subIndex(element, localScvIdx, 1);
264 const auto& corners = geometryHelper.getScvCorners(localScvIdx);
266 SubControlVolume::Traits::geometryType(geometry.type()),
267 [&](unsigned int i){ return corners[i]; }
268 );
269
270 cache_.scvs_[eIdx].emplace_back(
271 volume,
272 geometryHelper.facetCenter(localScvIdx),
273 Dumux::center(corners),
274 localScvIdx,
275 eIdx,
276 dofIndex
277 );
278 }
279
280 // build interior scvfs
281 LocalIndexType localScvfIdx = 0;
282 cache_.scvfs_[eIdx].reserve(geometryHelper.numInteriorScvf());
283 numScvf_ += geometryHelper.numInteriorScvf();
284 for (; localScvfIdx < geometryHelper.numInteriorScvf(); ++localScvfIdx)
285 {
286 const auto& corners = geometryHelper.getScvfCorners(localScvfIdx);
287 const auto& scvPair = geometryHelper.getInsideOutsideScvForScvf(localScvfIdx);
288 const auto area = Dumux::convexPolytopeVolume<dim-1>(
289 SubControlVolumeFace::Traits::interiorGeometryType(geometry.type()),
290 [&](unsigned int i){ return corners[i]; }
291 );
292
293 cache_.scvfs_[eIdx].emplace_back(
294 Dumux::center(corners),
295 area,
296 geometryHelper.normal(corners, scvPair),
297 scvPair,
298 localScvfIdx
299 );
300 }
301
302 // build boundary scvfs
303 for (const auto& intersection : intersections(this->gridView(), element))
304 {
305 if (onDomainBoundary_(intersection))
306 {
307 // store information that the face dof is on a boundary
308 const LocalIndexType localFacetIndex = intersection.indexInInside();
309 const auto dofIndex = dofMapper().subIndex(element, localFacetIndex, 1);
310 boundaryDofIndices_[dofIndex] = true;
311
312 // and that the element has a boundary face
313 cache_.hasBoundaryScvf_[eIdx] = true;
314
315 // add boundary scvf
316 const auto geo = intersection.geometry();
317 cache_.scvfs_[eIdx].emplace_back(
318 geo.center(),
319 geo.volume(),
320 intersection.centerUnitOuterNormal(),
321 std::array<LocalIndexType, 2>{{localFacetIndex, localFacetIndex}},
322 localScvfIdx,
323 typename SubControlVolumeFace::Traits::BoundaryFlag{ intersection }
324 );
325
326 // increment local and global counters
327 ++localScvfIdx;
328 ++numBoundaryScvf_;
329 ++numScvf_;
330 }
331
332 // handle periodic boundaries
333 if (onPeriodicBoundary_(intersection))
334 {
335 const LocalIndexType localFacetIndex = intersection.indexInInside();
336 const auto dofIndex = dofMapper().subIndex(element, localFacetIndex, 1);
337
338 this->setPeriodic();
339
340 const auto& otherElement = intersection.outside();
341
342 LocalIndexType otherIntersectionLocalIdx = 0;
343 bool periodicFaceFound = false;
344
345 for (const auto& otherIntersection : intersections(this->gridView(), otherElement))
346 {
347 if (periodicFaceFound)
348 continue;
349
350 if (Dune::FloatCmp::eq(intersection.centerUnitOuterNormal()*otherIntersection.centerUnitOuterNormal(), -1.0, 1e-7))
351 {
352 const auto periodicDofIdx = dofMapper().subIndex(otherElement, otherIntersectionLocalIdx, 1);
353 periodicFaceMap_[dofIndex] = periodicDofIdx;
354 periodicFaceFound = true;
355 }
356
357 ++otherIntersectionLocalIdx;
358 }
359 }
360 }
361 }
362 }
363
364 bool onDomainBoundary_(const typename GridView::Intersection& intersection) const
365 {
366 return !intersection.neighbor() && intersection.boundary();
367 }
368
369 bool onProcessorBoundary_(const typename GridView::Intersection& intersection) const
370 {
371 return !intersection.neighbor() && !intersection.boundary();
372 }
373
374 bool onPeriodicBoundary_(const typename GridView::Intersection& intersection) const
375 {
376 return periodicGridTraits_.isPeriodic(intersection);
377 }
378
379 // faces on the boundary
380 std::vector<bool> boundaryDofIndices_;
381
382 DofMapper dofMapper_;
383
384 std::size_t numScv_;
385 std::size_t numScvf_;
386 std::size_t numBoundaryScvf_;
387
388 // a map for periodic boundary vertices
389 std::unordered_map<GridIndexType, GridIndexType> periodicFaceMap_;
390
391 const FeCache feCache_;
392
393 Cache cache_;
394
396};
397
398} // end namespace Dumux
399
400#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.
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: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:76
static constexpr bool cachingEnabled
Definition discretization/facecentered/diamond/fvgridgeometry.hh:94
friend LocalView localView(const FaceCenteredDiamondFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition discretization/facecentered/diamond/fvgridgeometry.hh:178
DiscretizationMethods::FCDiamond DiscretizationMethod
Definition discretization/facecentered/diamond/fvgridgeometry.hh:92
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:170
const std::unordered_map< GridIndexType, GridIndexType > & periodicDofMap() const
Returns the map between dofs across periodic boundaries.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:174
FaceCenteredDiamondFVGridGeometry(const GridView &gridView, const std::string &paramGroup="")
Constructor.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:114
GV GridView
Definition discretization/facecentered/diamond/fvgridgeometry.hh:103
std::size_t numScv() const
The total number of sub control volumes.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:124
typename PeriodicGridTraits< typename GV::Grid >::SupportsPeriodicity SupportsPeriodicity
Definition discretization/facecentered/diamond/fvgridgeometry.hh:111
FCDiamondGridGeometryCache Cache
Definition discretization/facecentered/diamond/fvgridgeometry.hh:227
typename Traits::SubControlVolumeFace SubControlVolumeFace
Definition discretization/facecentered/diamond/fvgridgeometry.hh:101
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a d.o.f. is on a periodic boundary.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:166
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:154
Extrusion_t< Traits > Extrusion
Definition discretization/facecentered/diamond/fvgridgeometry.hh:107
bool dofOnBoundary(GridIndexType dofIdx) const
If a face / d.o.f. is on the boundary.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:158
static constexpr DiscretizationMethod discMethod
Definition discretization/facecentered/diamond/fvgridgeometry.hh:93
std::size_t numBoundaryScvf() const
The total number of boundary sub control volume faces.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:132
std::size_t numDofs() const
the total number of dofs
Definition discretization/facecentered/diamond/fvgridgeometry.hh:136
void update(GridView &&gridView)
update all fvElementGeometries (call this after grid adaption)
Definition discretization/facecentered/diamond/fvgridgeometry.hh:147
const DofMapper & dofMapper() const
Return a reference to the dof mapper.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:162
NonconformingFECache< Scalar, Scalar, dim > FeCache
Definition discretization/facecentered/diamond/fvgridgeometry.hh:109
typename Traits::template LocalView< ThisType, true > LocalView
Definition discretization/facecentered/diamond/fvgridgeometry.hh:97
typename Traits::SubControlVolume SubControlVolume
Definition discretization/facecentered/diamond/fvgridgeometry.hh:99
std::size_t numScvf() const
The total number of sub control volume faces.
Definition discretization/facecentered/diamond/fvgridgeometry.hh:128
void update(const GridView &gridView)
update all fvElementGeometries (call this after grid adaption)
Definition discretization/facecentered/diamond/fvgridgeometry.hh:140
typename Traits::DofMapper DofMapper
Definition discretization/facecentered/diamond/fvgridgeometry.hh:105
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.
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.
Distance implementation details.
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:43
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.
Grid properties related to periodicity.
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:58
FaceCenteredDiamondSubControlVolume< GridView > SubControlVolume
Definition discretization/facecentered/diamond/fvgridgeometry.hh:59
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > DofMapper
Definition discretization/facecentered/diamond/fvgridgeometry.hh:61
FaceCenteredDiamondFVElementGeometry< GridGeometry, enableCache > LocalView
Definition discretization/facecentered/diamond/fvgridgeometry.hh:64
FaceCenteredDiamondSubControlVolumeFace< GridView > SubControlVolumeFace
Definition discretization/facecentered/diamond/fvgridgeometry.hh:60
typename GridView::IndexSet::IndexType GridIndex
Definition indextraits.hh:27
std::uint_least8_t SmallLocalIndex
Definition indextraits.hh:29
Definition periodicgridtraits.hh:34
Definition periodicgridtraits.hh:33
Compute the volume of several common geometry types.