3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_DISCRETIZATION_FACECENTERED_DIAMOND_FV_GRID_GEOMETRY
25#define DUMUX_DISCRETIZATION_FACECENTERED_DIAMOND_FV_GRID_GEOMETRY
26
27#include <memory>
28#include <unordered_map>
29
30#include <dune/grid/common/mcmgmapper.hh>
31#include <dune/geometry/type.hh>
32
35#include <dumux/common/math.hh>
43
48
49namespace Dumux {
50
57template<class GridView>
59{
62 using DofMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GridView>;
63
64 template<class GridGeometry, bool enableCache>
66};
67
72template<class GV,
73 bool enableCaching = true,
76: public BaseGridGeometry<GV, Traits>
77{
80 using GridIndexType = typename IndexTraits<GV>::GridIndex;
81 using LocalIndexType = typename IndexTraits<GV>::SmallLocalIndex;
82 using Element = typename GV::template Codim<0>::Entity;
84
85 using Scalar = typename GV::ctype;
86
87 static const int dim = GV::dimension;
88 static const int dimWorld = GV::dimensionworld;
89
90 static_assert(dim > 1, "Only implemented for dim > 1");
91
92public:
96 static constexpr bool cachingEnabled = true;
97
99 using LocalView = typename Traits::template LocalView<ThisType, true>;
101 using SubControlVolume = typename Traits::SubControlVolume;
103 using SubControlVolumeFace = typename Traits::SubControlVolumeFace;
105 using GridView = GV;
107 using DofMapper = typename Traits::DofMapper;
112
114 FaceCenteredDiamondFVGridGeometry(const GridView& gridView, const std::string& paramGroup = "")
116 , dofMapper_(gridView, Dune::mcmgLayout(Dune::Codim<1>{}))
117 , cache_(*this)
118 {
119 update_();
120 }
121
123 std::size_t numScv() const
124 { return numScv_; }
125
127 std::size_t numScvf() const
128 { return numScvf_; }
129
131 std::size_t numBoundaryScvf() const
132 { return numBoundaryScvf_; }
133
135 std::size_t numDofs() const
136 { return this->gridView().size(1); }
137
140 {
142 update_();
143 }
144
147 {
148 ParentType::update(std::move(gridView));
149 update_();
150 }
151
153 const FeCache& feCache() const
154 { return feCache_; }
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:
182 explicit FCDiamondGridGeometryCache(const FaceCenteredDiamondFVGridGeometry& gg)
183 : gridGeometry_(&gg)
184 {}
185
186 const FaceCenteredDiamondFVGridGeometry& gridGeometry() const
187 { return *gridGeometry_; }
188
190 const std::vector<SubControlVolume>& scvs(GridIndexType eIdx) const
191 { return scvs_[eIdx]; }
192
194 const std::vector<SubControlVolumeFace>& scvfs(GridIndexType eIdx) const
195 { return scvfs_[eIdx]; }
196
198 bool hasBoundaryScvf(GridIndexType eIdx) const
199 { return hasBoundaryScvf_[eIdx]; }
200
201 private:
202 void clear_()
203 {
204 scvs_.clear();
205 scvfs_.clear();
206 hasBoundaryScvf_.clear();
207 }
208
209 std::vector<std::vector<SubControlVolume>> scvs_;
210 std::vector<std::vector<SubControlVolumeFace>> scvfs_;
211 std::vector<bool> hasBoundaryScvf_;
212
213 const FaceCenteredDiamondFVGridGeometry* gridGeometry_;
214 };
215
216public:
219 using Cache = FCDiamondGridGeometryCache;
220private:
221
223 void update_()
224 {
225 // clear containers (necessary after grid refinement)
226 cache_.clear_();
227 dofMapper_.update(this->gridView());
228
229 // determine size of containers
230 const auto numElements = this->gridView().size(0);
231 cache_.scvs_.resize(numElements);
232 cache_.scvfs_.resize(numElements);
233 cache_.hasBoundaryScvf_.resize(numElements, false);
234
235 numScv_ = 0;
236 numScvf_ = 0;
237 numBoundaryScvf_ = 0;
238
239 // Build the scvs and scv faces
240 for (const auto& element : elements(this->gridView()))
241 {
242 const auto eIdx = this->elementMapper().index(element);
243
244 const auto geometry = element.geometry();
245 GeometryHelper geometryHelper(geometry);
246
247 // build the scvs
248 cache_.scvs_[eIdx].reserve(geometryHelper.numScv());
249 numScv_ += geometryHelper.numScv();
250 for (LocalIndexType localScvIdx = 0; localScvIdx < geometryHelper.numScv(); ++localScvIdx)
251 {
252 const auto dofIndex = dofMapper().subIndex(element, localScvIdx, 1);
253 const auto& corners = geometryHelper.getScvCorners(localScvIdx);
254 const auto volume = Dumux::convexPolytopeVolume<dim>(
255 SubControlVolume::Traits::geometryType(geometry.type()),
256 [&](unsigned int i){ return corners[i]; }
257 );
258
259 cache_.scvs_[eIdx].emplace_back(
260 volume,
261 geometryHelper.facetCenter(localScvIdx),
262 Dumux::center(corners),
263 localScvIdx,
264 eIdx,
265 dofIndex
266 );
267 }
268
269 // build interior scvfs
270 LocalIndexType localScvfIdx = 0;
271 cache_.scvfs_[eIdx].reserve(geometryHelper.numInteriorScvf());
272 numScvf_ += geometryHelper.numInteriorScvf();
273 for (; localScvfIdx < geometryHelper.numInteriorScvf(); ++localScvfIdx)
274 {
275 const auto& corners = geometryHelper.getScvfCorners(localScvfIdx);
276 const auto& scvPair = geometryHelper.getInsideOutsideScvForScvf(localScvfIdx);
277 const auto area = Dumux::convexPolytopeVolume<dim-1>(
278 SubControlVolumeFace::Traits::interiorGeometryType(geometry.type()),
279 [&](unsigned int i){ return corners[i]; }
280 );
281
282 cache_.scvfs_[eIdx].emplace_back(
283 Dumux::center(corners),
284 area,
285 geometryHelper.normal(corners, scvPair),
286 scvPair,
287 localScvfIdx
288 );
289 }
290
291 // build boundary scvfs
292 for (const auto& intersection : intersections(this->gridView(), element))
293 {
294 if (onDomainBoundary_(intersection))
295 {
296 cache_.hasBoundaryScvf_[eIdx] = true;
297
298 const LocalIndexType localFacetIndex = intersection.indexInInside();
299 const auto geo = intersection.geometry();
300 cache_.scvfs_[eIdx].emplace_back(
301 geo.center(),
302 geo.volume(),
303 intersection.centerUnitOuterNormal(),
304 std::array<LocalIndexType, 2>{{localFacetIndex, localFacetIndex}},
305 localScvfIdx,
306 typename SubControlVolumeFace::Traits::BoundaryFlag{ intersection }
307 );
308
309 // increment local and global counters
310 ++localScvfIdx;
311 ++numBoundaryScvf_;
312 ++numScvf_;
313 }
314
315 // handle periodic boundaries
316 if (onPeriodicBoundary_(intersection))
317 {
318 const LocalIndexType localFacetIndex = intersection.indexInInside();
319 const auto dofIndex = dofMapper().subIndex(element, localFacetIndex, 1);
320
321 this->setPeriodic();
322
323 const auto& otherElement = intersection.outside();
324
325 LocalIndexType otherIntersectionLocalIdx = 0;
326 bool periodicFaceFound = false;
327
328 for (const auto& otherIntersection : intersections(this->gridView(), otherElement))
329 {
330 if (periodicFaceFound)
331 continue;
332
333 if (Dune::FloatCmp::eq(intersection.centerUnitOuterNormal()*otherIntersection.centerUnitOuterNormal(), -1.0, 1e-7))
334 {
335 const auto periodicDofIdx = dofMapper().subIndex(otherElement, otherIntersectionLocalIdx, 1);
336 periodicFaceMap_[dofIndex] = periodicDofIdx;
337 periodicFaceFound = true;
338 }
339
340 ++otherIntersectionLocalIdx;
341 }
342 }
343 }
344 }
345 }
346
347 bool onDomainBoundary_(const typename GridView::Intersection& intersection) const
348 {
349 return !intersection.neighbor() && intersection.boundary();
350 }
351
352 bool onProcessorBoundary_(const typename GridView::Intersection& intersection) const
353 {
354 return !intersection.neighbor() && !intersection.boundary();
355 }
356
357 bool onPeriodicBoundary_(const typename GridView::Intersection& intersection) const
358 {
359 return intersection.boundary() && intersection.neighbor();
360 }
361
362 DofMapper dofMapper_;
363
364 std::size_t numScv_;
365 std::size_t numScvf_;
366 std::size_t numBoundaryScvf_;
367
368 // a map for periodic boundary vertices
369 std::unordered_map<GridIndexType, GridIndexType> periodicFaceMap_;
370
371 const FeCache feCache_;
372
373 Cache cache_;
374};
375
376} // end namespace Dumux
377
378#endif
Defines the default element and vertex mapper types.
Defines the index types used for grid and local indices.
Define some often used mathematical functions.
Check the overlap size for different discretization methods.
Base class for grid geometries.
Helper classes to compute the integration elements.
The available discretization methods in Dumux.
A finite element cache for the non-conforming FE spaces RT and CR.
Compute the center point of a convex polytope geometry or a random-access container of corner points.
Compute the volume of several common geometry types.
auto volume(const Geometry &geo, unsigned int integrationOrder=4)
The volume of a given geometry.
Definition: volume.hh:171
auto convexPolytopeVolume(Dune::GeometryType type, const CornerF &c)
Compute the volume of several common geometry types.
Definition: volume.hh:53
Corners::value_type center(const Corners &corners)
The center of a given list of corners.
Definition: center.hh:36
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:251
Definition: deprecated.hh:149
CVFE< CVFEMethods::CR_RT > FCDiamond
Definition: method.hh:90
Definition: defaultmappertraits.hh:35
Structure to define the index types used for grid and local indices.
Definition: indextraits.hh:38
Base class for all grid geometries.
Definition: basegridgeometry.hh:61
const ElementMapper & elementMapper() const
Returns the mapper for elements to indices for constant grids.
Definition: basegridgeometry.hh:121
void setPeriodic(bool value=true)
Set the periodicity of the grid geometry.
Definition: basegridgeometry.hh:178
Element element(GridIndexType eIdx) const
Get an element from a global element index.
Definition: basegridgeometry.hh:151
const GridView & gridView() const
Return the gridView this grid geometry object lives on.
Definition: basegridgeometry.hh:109
void update(const GridView &gridView)
Update all fvElementGeometries (call this after grid adaption)
Definition: basegridgeometry.hh:97
Element-wise grid geometry (local view)
Definition: discretization/facecentered/diamond/fvelementgeometry.hh:44
The default traits for the face-centered diamond finite volume grid geometry Defines the scv and scvf...
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:59
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > DofMapper
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:62
Grid geometry for the diamond discretization.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:77
static constexpr bool cachingEnabled
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:96
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:114
GV GridView
export the grid view type
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:105
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:123
FCDiamondGridGeometryCache Cache
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:219
typename Traits::SubControlVolumeFace SubControlVolumeFace
export the type of sub control volume
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:103
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:153
Extrusion_t< Traits > Extrusion
export the type of extrusion
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:109
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:95
std::size_t numBoundaryScvf() const
The total number of boundary sub control volume faces.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:131
std::size_t numDofs() const
the total number of dofs
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:135
void update(GridView &&gridView)
update all fvElementGeometries (call this after grid adaption)
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:146
const DofMapper & dofMapper() const
Return a reference to the dof mapper.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:157
NonconformingFECache< Scalar, Scalar, dim > FeCache
export the finite element cache type
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:111
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:99
typename Traits::SubControlVolume SubControlVolume
export the type of sub control volume
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:101
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:127
void update(const GridView &gridView)
update all fvElementGeometries (call this after grid adaption)
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:139
typename Traits::DofMapper DofMapper
export the dof mapper type
Definition: discretization/facecentered/diamond/fvgridgeometry.hh:107
Helper class to construct SCVs and SCVFs for the diamond scheme.
Definition: discretization/facecentered/diamond/geometryhelper.hh:267
GlobalPosition facetCenter(unsigned int localFacetIndex) const
Definition: discretization/facecentered/diamond/geometryhelper.hh:356
ScvfCornerStorage getScvfCorners(unsigned int localEdgeIndex) const
Create a corner storage with the scvf corners for a given edge (codim-2) index.
Definition: discretization/facecentered/diamond/geometryhelper.hh:315
std::size_t numInteriorScvf()
number of interior sub control volume faces (number of codim-2 entities)
Definition: discretization/facecentered/diamond/geometryhelper.hh:377
std::array< LocalIndexType, 2 > getInsideOutsideScvForScvf(unsigned int localEdgeIndex)
Definition: discretization/facecentered/diamond/geometryhelper.hh:361
ScvCornerStorage getScvCorners(unsigned int localFacetIndex) const
Create a corner storage with the scv corners for a given face (codim-1) index.
Definition: discretization/facecentered/diamond/geometryhelper.hh:287
GlobalPosition normal(const ScvfCornerStorage &p, const std::array< LocalIndexType, 2 > &scvPair)
Definition: discretization/facecentered/diamond/geometryhelper.hh:389
std::size_t numScv()
number of sub control volumes (number of codim-1 entities)
Definition: discretization/facecentered/diamond/geometryhelper.hh:383
Face centered diamond subcontrolvolume face.
Definition: discretization/facecentered/diamond/subcontrolvolume.hh:74
The SCVF implementation for diamond.
Definition: discretization/facecentered/diamond/subcontrolvolumeface.hh:75
Definition: method.hh:58
Definition: nonconformingfecache.hh:41