version 3.10.0
Loading...
Searching...
No Matches
discretization/pq1bubble/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//
14#ifndef DUMUX_DISCRETIZATION_PQ1BUBBLE_GRID_GEOMETRY_HH
15#define DUMUX_DISCRETIZATION_PQ1BUBBLE_GRID_GEOMETRY_HH
16
17#include <utility>
18#include <unordered_map>
19
20#include <dune/grid/common/mcmgmapper.hh>
21
23
26
29
37
39
40namespace Dumux {
41
42namespace Detail {
43template<class GV, class T>
44using PQ1BubbleGeometryHelper_t = Dune::Std::detected_or_t<
47 T
48>;
49} // end namespace Detail
50
51template <class GridView>
53{
54 using DofMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
55
60 static Dune::MCMGLayout layout()
61 {
62 return [](Dune::GeometryType gt, int dimgrid) {
63 return (gt.dim() == dimgrid) || (gt.dim() == 0);
64 };
65 }
66};
67
74template<class GridView, class MapperTraits = PQ1BubbleMapperTraits<GridView>>
84
91template<class Scalar,
92 class GV,
93 bool enableCaching = true,
96: public BaseGridGeometry<GV, Traits>
97{
99 using ParentType = BaseGridGeometry<GV, Traits>;
100 using GridIndexType = typename IndexTraits<GV>::GridIndex;
101 using LocalIndexType = typename IndexTraits<GV>::LocalIndex;
102
103 using Element = typename GV::template Codim<0>::Entity;
104 using CoordScalar = typename GV::ctype;
105 static const int dim = GV::dimension;
106 static const int dimWorld = GV::dimensionworld;
107
108 static_assert(dim > 1, "Only implemented for dim > 1");
109
110public:
114
116 using LocalView = typename Traits::template LocalView<ThisType, true>;
118 using SubControlVolume = typename Traits::SubControlVolume;
120 using SubControlVolumeFace = typename Traits::SubControlVolumeFace;
124 using DofMapper = typename Traits::DofMapper;
128 using GridView = GV;
131
134 : ParentType(gridView)
135 , dofMapper_(gridView, Traits::layout())
136 , cache_(*this)
137 , periodicGridTraits_(this->gridView().grid())
138 {
139 update_();
140 }
141
143 const DofMapper& dofMapper() const
144 { return dofMapper_; }
145
147 std::size_t numScv() const
148 { return numScv_; }
149
151 std::size_t numScvf() const
152 { return numScvf_; }
153
155 std::size_t numBoundaryScvf() const
156 { return numBoundaryScvf_; }
157
159 std::size_t numDofs() const
160 { return this->dofMapper().size(); }
161
164 {
166 update_();
167 }
168
171 {
172 ParentType::update(std::move(gridView));
173 update_();
174 }
175
177 const FeCache& feCache() const
178 { return feCache_; }
179
181 bool dofOnBoundary(GridIndexType dofIdx) const
182 { return boundaryDofIndices_[dofIdx]; }
183
185 bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
186 { return periodicDofMap_.count(dofIdx); }
187
189 GridIndexType periodicallyMappedDof(GridIndexType dofIdx) const
190 { return periodicDofMap_.at(dofIdx); }
191
193 const std::unordered_map<GridIndexType, GridIndexType>& periodicDofMap() const
194 { return periodicDofMap_; }
195
198 { return { gg.cache_ }; }
199
200private:
201
202 class PQ1BubbleGridGeometryCache
203 {
204 friend class PQ1BubbleFVGridGeometry;
205 public:
208
209 explicit PQ1BubbleGridGeometryCache(const PQ1BubbleFVGridGeometry& gg)
210 : gridGeometry_(&gg)
211 {}
212
213 const PQ1BubbleFVGridGeometry& gridGeometry() const
214 { return *gridGeometry_; }
215
217 const std::vector<SubControlVolume>& scvs(GridIndexType eIdx) const
218 { return scvs_[eIdx]; }
219
221 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx) const
222 { return scvfs_[eIdx]; }
223
225 bool hasBoundaryScvf(GridIndexType eIdx) const
226 { return hasBoundaryScvf_[eIdx]; }
227
229 const std::vector<std::array<LocalIndexType, 2>>& scvfBoundaryGeometryKeys(GridIndexType eIdx) const
230 { return scvfBoundaryGeometryKeys_.at(eIdx); }
231
232 private:
233 void clear_()
234 {
235 scvs_.clear();
236 scvfs_.clear();
237 hasBoundaryScvf_.clear();
238 scvfBoundaryGeometryKeys_.clear();
239 }
240
241 std::vector<std::vector<SubControlVolume>> scvs_;
242 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
243 std::vector<bool> hasBoundaryScvf_;
244 std::unordered_map<GridIndexType, std::vector<std::array<LocalIndexType, 2>>> scvfBoundaryGeometryKeys_;
245
246 const PQ1BubbleFVGridGeometry* gridGeometry_;
247 };
248
249public:
252 using Cache = PQ1BubbleGridGeometryCache;
253
254private:
255 using GeometryHelper = typename Cache::GeometryHelper;
256
257 void update_()
258 {
259 cache_.clear_();
260 dofMapper_.update(this->gridView());
261
262 auto numElements = this->gridView().size(0);
263 cache_.scvs_.resize(numElements);
264 cache_.scvfs_.resize(numElements);
265 cache_.hasBoundaryScvf_.resize(numElements, false);
266
267 boundaryDofIndices_.assign(numDofs(), false);
268
269 numScv_ = 0;
270 numScvf_ = 0;
271 numBoundaryScvf_ = 0;
272
273 // Build the scvs and scv faces
274 for (const auto& element : elements(this->gridView()))
275 {
276 auto eIdx = this->elementMapper().index(element);
277
278 // get the element geometry
279 auto elementGeometry = element.geometry();
280 const auto refElement = referenceElement(elementGeometry);
281
282 // instantiate the geometry helper
283 GeometryHelper geometryHelper(elementGeometry);
284
285 numScv_ += geometryHelper.numScv();
286 // construct the sub control volumes
287 cache_.scvs_[eIdx].resize(geometryHelper.numScv());
288 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < geometryHelper.numScv(); ++scvLocalIdx)
289 {
290 auto corners = geometryHelper.getScvCorners(scvLocalIdx);
291 cache_.scvs_[eIdx][scvLocalIdx] = SubControlVolume(
292 geometryHelper.scvVolume(scvLocalIdx, corners),
293 geometryHelper.dofPosition(scvLocalIdx),
294 Dumux::center(corners),
295 scvLocalIdx,
296 eIdx,
297 geometryHelper.dofIndex(this->dofMapper(), element, scvLocalIdx),
298 geometryHelper.isOverlappingScv(scvLocalIdx)
299 );
300 }
301
302 // construct the sub control volume faces
303 numScvf_ += geometryHelper.numInteriorScvf();
304 cache_.scvfs_[eIdx].resize(geometryHelper.numInteriorScvf());
305 LocalIndexType scvfLocalIdx = 0;
306 for (; scvfLocalIdx < geometryHelper.numInteriorScvf(); ++scvfLocalIdx)
307 {
308 const auto scvPair = geometryHelper.getScvPairForScvf(scvfLocalIdx);
309 const auto corners = geometryHelper.getScvfCorners(scvfLocalIdx);
310 const auto area = Dumux::convexPolytopeVolume<dim-1>(
311 geometryHelper.getInteriorScvfGeometryType(scvfLocalIdx),
312 [&](unsigned int i){ return corners[i]; }
313 );
314
315 cache_.scvfs_[eIdx][scvfLocalIdx] = SubControlVolumeFace(
316 Dumux::center(corners),
317 area,
318 geometryHelper.normal(corners, scvPair),
319 std::move(scvPair),
320 scvfLocalIdx,
321 geometryHelper.isOverlappingScvf(scvfLocalIdx)
322 );
323 }
324
325 // construct the sub control volume faces on the domain boundary
326 for (const auto& intersection : intersections(this->gridView(), element))
327 {
328 if (intersection.boundary() && !intersection.neighbor())
329 {
330 cache_.hasBoundaryScvf_[eIdx] = true;
331
332 const auto localFacetIndex = intersection.indexInInside();
333 const auto numBoundaryScvf = geometryHelper.numBoundaryScvf(localFacetIndex);
334 numScvf_ += numBoundaryScvf;
335 numBoundaryScvf_ += numBoundaryScvf;
336
337 for (unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < numBoundaryScvf; ++isScvfLocalIdx)
338 {
339 // find the scvs this scvf is belonging to
340 const auto scvPair = geometryHelper.getScvPairForBoundaryScvf(localFacetIndex, isScvfLocalIdx);
341 const auto corners = geometryHelper.getBoundaryScvfCorners(localFacetIndex, isScvfLocalIdx);
342 const auto area = Dumux::convexPolytopeVolume<dim-1>(
343 geometryHelper.getBoundaryScvfGeometryType(isScvfLocalIdx),
344 [&](unsigned int i){ return corners[i]; }
345 );
346 cache_.scvfs_[eIdx].emplace_back(
347 Dumux::center(corners),
348 area,
349 intersection.centerUnitOuterNormal(),
350 std::move(scvPair),
351 scvfLocalIdx,
352 typename SubControlVolumeFace::Traits::BoundaryFlag{ intersection },
353 geometryHelper.isOverlappingBoundaryScvf(localFacetIndex)
354 );
355
356 // store look-up map to construct boundary scvf geometries
357 cache_.scvfBoundaryGeometryKeys_[eIdx].emplace_back(std::array<LocalIndexType, 2>{{
358 static_cast<LocalIndexType>(localFacetIndex),
359 static_cast<LocalIndexType>(isScvfLocalIdx)
360 }});
361
362 // increment local counter
363 scvfLocalIdx++;
364 }
365
366 // TODO also move this to helper class
367
368 // add all vertices on the intersection to the set of boundary vertices
369 for (int localVIdx = 0; localVIdx < numBoundaryScvf; ++localVIdx)
370 {
371 const auto vIdx = refElement.subEntity(localFacetIndex, 1, localVIdx, dim);
372 const auto vIdxGlobal = this->dofMapper().subIndex(element, vIdx, dim);
373 boundaryDofIndices_[vIdxGlobal] = true;
374 }
375 }
376
377 // inform the grid geometry if we have periodic boundaries
378 else if (periodicGridTraits_.isPeriodic(intersection))
379 {
380 this->setPeriodic();
381
382 // find the mapped periodic vertex of all vertices on periodic boundaries
383 const auto fIdx = intersection.indexInInside();
384 const auto numFaceVerts = refElement.size(fIdx, 1, dim);
385 const auto eps = 1e-7*(elementGeometry.corner(1) - elementGeometry.corner(0)).two_norm();
386 for (int localVIdx = 0; localVIdx < numFaceVerts; ++localVIdx)
387 {
388 const auto vIdx = refElement.subEntity(fIdx, 1, localVIdx, dim);
389 const auto vIdxGlobal = this->dofMapper().subIndex(element, vIdx, dim);
390 const auto vPos = elementGeometry.corner(vIdx);
391
392 const auto& outside = intersection.outside();
393 const auto outsideGeometry = outside.geometry();
394 for (const auto& isOutside : intersections(this->gridView(), outside))
395 {
396 // only check periodic vertices of the periodic neighbor
397 if (periodicGridTraits_.isPeriodic(isOutside))
398 {
399 const auto fIdxOutside = isOutside.indexInInside();
400 const auto numFaceVertsOutside = refElement.size(fIdxOutside, 1, dim);
401 for (int localVIdxOutside = 0; localVIdxOutside < numFaceVertsOutside; ++localVIdxOutside)
402 {
403 const auto vIdxOutside = refElement.subEntity(fIdxOutside, 1, localVIdxOutside, dim);
404 const auto vPosOutside = outsideGeometry.corner(vIdxOutside);
405 const auto shift = std::abs((this->bBoxMax()-this->bBoxMin())*intersection.centerUnitOuterNormal());
406 if (std::abs((vPosOutside-vPos).two_norm() - shift) < eps)
407 periodicDofMap_[vIdxGlobal] = this->dofMapper().subIndex(outside, vIdxOutside, dim);
408 }
409 }
410 }
411 }
412 }
413 }
414 }
415
416 // error check: periodic boundaries currently don't work for pq1bubble in parallel
417 if (this->isPeriodic() && this->gridView().comm().size() > 1)
418 DUNE_THROW(Dune::NotImplemented, "Periodic boundaries for pq1bubble method for parallel simulations!");
419 }
420
421 DofMapper dofMapper_;
422
423 const FeCache feCache_;
424
425 std::size_t numScv_;
426 std::size_t numScvf_;
427 std::size_t numBoundaryScvf_;
428
429 // vertices on the boundary
430 std::vector<bool> boundaryDofIndices_;
431
432 // a map for periodic boundary vertices
433 std::unordered_map<GridIndexType, GridIndexType> periodicDofMap_;
434
435 Cache cache_;
436
438};
439
440} // end namespace Dumux
441
442#endif
Base class for grid geometries.
Compute the center point of a convex polytope geometry or a random-access container of corner points.
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
const GlobalCoordinate & bBoxMax() const
The coordinate of the corner of the GridView's bounding box with the largest values.
Definition basegridgeometry.hh:156
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
const GlobalCoordinate & bBoxMin() const
The coordinate of the corner of the GridView's bounding box with the smallest values.
Definition basegridgeometry.hh:149
bool isPeriodic() const
Returns if the grid geometry is periodic (at all)
Definition basegridgeometry.hh:162
Definition pq1bubblefecache.hh:29
Base class for the finite volume geometry vector for pq1bubble models This builds up the sub control ...
Definition discretization/pq1bubble/fvelementgeometry.hh:40
Base class for the finite volume geometry vector for pq1bubble schemes This builds up the sub control...
Definition discretization/pq1bubble/fvgridgeometry.hh:97
void update(const GridView &gridView)
update all geometries (call this after grid adaption)
Definition discretization/pq1bubble/fvgridgeometry.hh:163
friend LocalView localView(const PQ1BubbleFVGridGeometry &gg)
local view of this object (constructed with the internal cache)
Definition discretization/pq1bubble/fvgridgeometry.hh:197
PQ1BubbleGridGeometryCache Cache
Definition discretization/pq1bubble/fvgridgeometry.hh:252
static constexpr DiscretizationMethod discMethod
Definition discretization/pq1bubble/fvgridgeometry.hh:113
std::size_t numBoundaryScvf() const
The total number of boundary sub control volume faces.
Definition discretization/pq1bubble/fvgridgeometry.hh:155
std::size_t numScv() const
The total number of sub control volumes.
Definition discretization/pq1bubble/fvgridgeometry.hh:147
std::size_t numScvf() const
The total number of sub control volume faces.
Definition discretization/pq1bubble/fvgridgeometry.hh:151
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition discretization/pq1bubble/fvgridgeometry.hh:177
GridIndexType periodicallyMappedDof(GridIndexType dofIdx) const
The index of the vertex / d.o.f. on the other side of the periodic boundary.
Definition discretization/pq1bubble/fvgridgeometry.hh:189
DiscretizationMethods::PQ1Bubble DiscretizationMethod
Definition discretization/pq1bubble/fvgridgeometry.hh:112
Extrusion_t< PQ1BubbleDefaultGridGeometryTraits< GridView > > Extrusion
Definition discretization/pq1bubble/fvgridgeometry.hh:122
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::SubControlVolumeFace SubControlVolumeFace
Definition discretization/pq1bubble/fvgridgeometry.hh:120
std::size_t numDofs() const
The total number of degrees of freedom.
Definition discretization/pq1bubble/fvgridgeometry.hh:159
bool dofOnBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on the boundary.
Definition discretization/pq1bubble/fvgridgeometry.hh:181
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::DofMapper DofMapper
Definition discretization/pq1bubble/fvgridgeometry.hh:124
const DofMapper & dofMapper() const
The dofMapper.
Definition discretization/pq1bubble/fvgridgeometry.hh:143
const std::unordered_map< GridIndexType, GridIndexType > & periodicDofMap() const
Returns the map between dofs across periodic boundaries.
Definition discretization/pq1bubble/fvgridgeometry.hh:193
GridView GridView
Definition discretization/pq1bubble/fvgridgeometry.hh:128
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a vertex / d.o.f. is on a periodic boundary.
Definition discretization/pq1bubble/fvgridgeometry.hh:185
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::template LocalView< ThisType, true > LocalView
Definition discretization/pq1bubble/fvgridgeometry.hh:116
typename PQ1BubbleDefaultGridGeometryTraits< GridView >::SubControlVolume SubControlVolume
Definition discretization/pq1bubble/fvgridgeometry.hh:118
typename PeriodicGridTraits< typename GridView::Grid >::SupportsPeriodicity SupportsPeriodicity
Definition discretization/pq1bubble/fvgridgeometry.hh:130
PQ1BubbleFVGridGeometry(const GridView gridView)
Constructor.
Definition discretization/pq1bubble/fvgridgeometry.hh:133
void update(GridView &&gridView)
update all geometries (call this after grid adaption)
Definition discretization/pq1bubble/fvgridgeometry.hh:170
Dumux::PQ1BubbleFECache< CoordScalar, Scalar, dim > FeCache
Definition discretization/pq1bubble/fvgridgeometry.hh:126
A class to create sub control volume and sub control volume face geometries per element.
Definition discretization/pq1bubble/geometryhelper.hh:166
Class for a sub control volume face in the cvfe method, i.e a part of the boundary of a sub control v...
Definition discretization/pq1bubble/subcontrolvolumeface.hh:60
the sub control volume for the pq1bubble scheme
Definition discretization/pq1bubble/subcontrolvolume.hh:56
Defines the default element and vertex mapper types.
Base class for the local finite volume geometry for the pq1bubble method This builds up the sub contr...
Helper class constructing the dual grid finite volume geometries for the cvfe discretizazion method.
the sub control volume for the cvfe scheme
Base class for a sub control volume face.
Helper classes to compute the integration elements.
BaseGridGeometry(std::shared_ptr< BaseImplementation > impl)
Constructor from a BaseImplementation.
Definition basegridgeometry.hh:72
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.
The available discretization methods in Dumux.
Distance implementation details.
Definition cvfelocalresidual.hh:25
Dune::Std::detected_or_t< Dumux::PQ1BubbleGeometryHelper< GV, typename T::SubControlVolume, typename T::SubControlVolumeFace >, SpecifiesGeometryHelper, T > PQ1BubbleGeometryHelper_t
Definition discretization/pq1bubble/fvgridgeometry.hh:44
typename T::GeometryHelper SpecifiesGeometryHelper
Definition basegridgeometry.hh:30
CVFE< CVFEMethods::PQ1Bubble > PQ1Bubble
Definition method.hh:108
Definition adapt.hh:17
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition extrusion.hh:166
Grid properties related to periodicity.
A finite element cache for P1/Q1 function with bubble.
Definition defaultmappertraits.hh:23
typename GridView::IndexSet::IndexType GridIndex
Definition indextraits.hh:27
unsigned int LocalIndex
Definition indextraits.hh:28
The default traits for the pq1bubble finite volume grid geometry Defines the scv and scvf types and t...
Definition discretization/pq1bubble/fvgridgeometry.hh:77
PQ1BubbleSubControlVolume< GridView > SubControlVolume
Definition discretization/pq1bubble/fvgridgeometry.hh:78
PQ1BubbleSubControlVolumeFace< GridView > SubControlVolumeFace
Definition discretization/pq1bubble/fvgridgeometry.hh:79
PQ1BubbleFVElementGeometry< GridGeometry, enableCache > LocalView
Definition discretization/pq1bubble/fvgridgeometry.hh:82
Definition discretization/pq1bubble/fvgridgeometry.hh:53
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > DofMapper
Definition discretization/pq1bubble/fvgridgeometry.hh:54
static Dune::MCMGLayout layout()
layout for elements and vertices
Definition discretization/pq1bubble/fvgridgeometry.hh:60
Definition periodicgridtraits.hh:34
Definition periodicgridtraits.hh:33
Compute the volume of several common geometry types.