version 3.8
discretization/porenetwork/fvelementgeometry.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_PNM_FV_ELEMENT_GEOMETRY_HH
13#define DUMUX_DISCRETIZATION_PNM_FV_ELEMENT_GEOMETRY_HH
14
15#include <optional>
16#include <array>
17#include <utility>
18
19#include <dune/geometry/type.hh>
20
23
25
32template<class GG, bool enableFVGridGeometryCache>
34
36template<class GG>
37class PNMFVElementGeometry<GG, true>
38{
39 using GridView = typename GG::GridView;
40 static constexpr int dim = GridView::dimension;
41 static constexpr int dimWorld = GridView::dimensionworld;
42 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
43 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
44 using CoordScalar = typename GridView::ctype;
45 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
46public:
48 using SubControlVolume = typename GG::SubControlVolume;
50 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
52 using GridGeometry = GG;
54 using Element = typename GridView::template Codim<0>::Entity;
56 static constexpr std::size_t maxNumElementScvs = 2;
57
60 : gridGeometryPtr_(&gridGeometry) {}
61
63 const SubControlVolume& scv(LocalIndexType scvIdx) const
64 {
65 return gridGeometry().scvs(eIdx_)[scvIdx];
66 }
67
69 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
70 {
71 return gridGeometry().scvfs(eIdx_)[scvfIdx];
72 }
73
79 friend inline auto scvs(const PNMFVElementGeometry& fvGeometry)
80 {
81 const auto& g = fvGeometry.gridGeometry();
82 using Iter = typename std::decay_t<decltype(g.scvs(fvGeometry.eIdx_))>::const_iterator;
83 return Dune::IteratorRange<Iter>(g.scvs(fvGeometry.eIdx_).begin(), g.scvs(fvGeometry.eIdx_).end());
84 }
85
91 friend inline auto scvfs(const PNMFVElementGeometry& fvGeometry)
92 {
93 const auto& g = fvGeometry.gridGeometry();
94 using Iter = typename std::decay_t<decltype(g.scvfs(fvGeometry.eIdx_))>::const_iterator;
95 return Dune::IteratorRange<Iter>(g.scvfs(fvGeometry.eIdx_).begin(), g.scvfs(fvGeometry.eIdx_).end());
96 }
97
99 const FeLocalBasis& feLocalBasis() const
100 {
101 return gridGeometry().feCache().get(element_->type()).localBasis();
102 }
103
105 std::size_t numScv() const
106 {
107 return gridGeometry().scvs(eIdx_).size();
108 }
109
111 std::size_t numScvf() const
112 {
113 return gridGeometry().scvfs(eIdx_).size();
114 }
115
122 {
123 this->bindElement(element);
124 return std::move(*this);
125 }
126
130 void bind(const Element& element) &
131 { this->bindElement(element); }
132
139 {
140 this->bindElement(element);
141 return std::move(*this);
142 }
143
147 void bindElement(const Element& element) &
148 {
149 element_ = element;
150 eIdx_ = gridGeometry().elementMapper().index(element);
151 }
152
154 bool isBound() const
155 { return static_cast<bool>(element_); }
156
158 const Element& element() const
159 { return *element_; }
160
163 { return *gridGeometryPtr_; }
164
166 bool hasBoundaryScvf() const
167 { return gridGeometry().hasBoundaryScvf(eIdx_); }
168
170 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
171 {
172 const auto geo = element().geometry();
173 return {
174 Dune::GeometryTypes::simplex(dim),
175 std::array{{ geo.corner(scv.indexInElement()), geo.center() }}
176 };
177 }
178
180 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
181 { return { scvf.center() }; }
182
183private:
184 std::optional<Element> element_;
185 const GridGeometry* gridGeometryPtr_;
186
187 GridIndexType eIdx_;
188};
189
191template<class GG>
192class PNMFVElementGeometry<GG, false>
193{
194 using GridView = typename GG::GridView;
195 static constexpr int dim = GridView::dimension;
196 static constexpr int dimWorld = GridView::dimensionworld;
197 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
198 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
199 using CoordScalar = typename GridView::ctype;
200 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
201
202public:
204 using SubControlVolume = typename GG::SubControlVolume;
206 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
208 using GridGeometry = GG;
210 using Element = typename GridView::template Codim<0>::Entity;
212 static constexpr std::size_t maxNumElementScvs = 2;
213
216 : gridGeometryPtr_(&gridGeometry) {}
217
219 const SubControlVolume& scv(LocalIndexType scvIdx) const
220 {
221 return scvs_[scvIdx];
222 }
223
225 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
226 {
227 return scvfs_[0];
228 }
229
235 friend inline auto scvs(const PNMFVElementGeometry& fvGeometry)
236 {
237 using Iter = typename std::decay_t<decltype(fvGeometry.scvs_)>::const_iterator;
238 return Dune::IteratorRange<Iter>(fvGeometry.scvs_.begin(), fvGeometry.scvs_.end());
239 }
240
246 friend inline auto scvfs(const PNMFVElementGeometry& fvGeometry)
247 {
248 using Iter = typename std::decay_t<decltype(fvGeometry.scvfs_)>::const_iterator;
249 return Dune::IteratorRange<Iter>(fvGeometry.scvfs_.begin(), fvGeometry.scvfs_.end());
250 }
251
253 const FeLocalBasis& feLocalBasis() const
254 {
255 return gridGeometry().feCache().get(element_->type()).localBasis();
256 }
257
259 std::size_t numScv() const
260 {
261 return scvs_.size();
262 }
263
265 std::size_t numScvf() const
266 {
267 return scvfs_.size();
268 }
269
276 {
277 this->bindElement(element);
278 return std::move(*this);
279 }
280
284 void bind(const Element& element) &
285 { this->bindElement(element); }
286
293 {
294 this->bindElement(element);
295 return std::move(*this);
296 }
297
301 void bindElement(const Element& element) &
302 {
303 element_ = element;
304 eIdx_ = gridGeometry().elementMapper().index(element);
305 makeElementGeometries(element);
306 }
307
309 bool isBound() const
310 { return static_cast<bool>(element_); }
311
313 const Element& element() const
314 { return *element_; }
315
318 { return *gridGeometryPtr_; }
319
321 bool hasBoundaryScvf() const
322 { return hasBoundaryScvf_; }
323
325 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
326 {
327 const auto geo = element().geometry();
328 return {
329 Dune::GeometryTypes::simplex(dim),
330 std::array{{ geo.corner(scv.indexInElement()), geo.center() }}
331 };
332 }
333
335 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
336 { return { scvf.center() }; }
337
338private:
339
340 void makeElementGeometries(const Element& element)
341 {
342 hasBoundaryScvf_ = false;
343
344 // get the element geometry
345 auto elementGeometry = element.geometry();
346
347 // construct the sub control volumes
348 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
349 {
350 // get associated dof index
351 const auto dofIdxGlobal = gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim);
352
353 // get the corners
354 auto corners = std::array{elementGeometry.corner(scvLocalIdx), elementGeometry.center()};
355
356 // get the fractional volume associated with the scv
357 const auto volume = gridGeometry().poreVolume(dofIdxGlobal) / gridGeometry().coordinationNumber(dofIdxGlobal);
358
359 // add scv to the local container
360 scvs_[scvLocalIdx] = SubControlVolume(dofIdxGlobal,
361 scvLocalIdx,
362 eIdx_,
363 std::move(corners),
364 volume);
365
366 if (gridGeometry().poreLabel(dofIdxGlobal) > 0)
367 hasBoundaryScvf_ = true;
368 }
369
370 // construct the inner sub control volume face
371 auto unitOuterNormal = elementGeometry.corner(1) - elementGeometry.corner(0);
372 unitOuterNormal /= unitOuterNormal.two_norm();
373 LocalIndexType scvfLocalIdx = 0;
374 scvfs_[0] = SubControlVolumeFace(elementGeometry.center(),
375 std::move(unitOuterNormal),
376 gridGeometry().throatCrossSectionalArea(gridGeometry().elementMapper().index(element)),
377 scvfLocalIdx++,
378 std::array<LocalIndexType, 2>({0, 1}));
379 }
380
382 std::optional<Element> element_;
383 GridIndexType eIdx_;
384
386 const GridGeometry* gridGeometryPtr_;
387
389 std::array<SubControlVolume, 2> scvs_;
390 std::array<SubControlVolumeFace, 1> scvfs_;
391
392 bool hasBoundaryScvf_ = false;
393};
394
395} // end namespace Dumux::PoreNetwork
396
397#endif
Base class for the finite volume geometry for porenetwork models.
Definition: discretization/porenetwork/gridgeometry.hh:477
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: discretization/porenetwork/fvelementgeometry.hh:219
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: discretization/porenetwork/fvelementgeometry.hh:206
void bind(const Element &element) &
Definition: discretization/porenetwork/fvelementgeometry.hh:284
const Element & element() const
The bound element.
Definition: discretization/porenetwork/fvelementgeometry.hh:313
PNMFVElementGeometry bind(const Element &element) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: discretization/porenetwork/fvelementgeometry.hh:275
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/porenetwork/fvelementgeometry.hh:259
PNMFVElementGeometry bindElement(const Element &element) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: discretization/porenetwork/fvelementgeometry.hh:292
GG GridGeometry
export type of finite volume grid geometry
Definition: discretization/porenetwork/fvelementgeometry.hh:208
SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace &scvf) const
Create the geometry of a given sub control volume face.
Definition: discretization/porenetwork/fvelementgeometry.hh:335
friend auto scvfs(const PNMFVElementGeometry &fvGeometry)
Definition: discretization/porenetwork/fvelementgeometry.hh:246
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: discretization/porenetwork/fvelementgeometry.hh:317
void bindElement(const Element &element) &
Definition: discretization/porenetwork/fvelementgeometry.hh:301
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: discretization/porenetwork/fvelementgeometry.hh:204
PNMFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: discretization/porenetwork/fvelementgeometry.hh:215
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/porenetwork/fvelementgeometry.hh:265
typename GridView::template Codim< 0 >::Entity Element
export element type
Definition: discretization/porenetwork/fvelementgeometry.hh:210
SubControlVolume::Traits::Geometry geometry(const SubControlVolume &scv) const
Create the geometry of a given sub control volume.
Definition: discretization/porenetwork/fvelementgeometry.hh:325
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: discretization/porenetwork/fvelementgeometry.hh:225
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: discretization/porenetwork/fvelementgeometry.hh:309
friend auto scvs(const PNMFVElementGeometry &fvGeometry)
Definition: discretization/porenetwork/fvelementgeometry.hh:235
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/porenetwork/fvelementgeometry.hh:321
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: discretization/porenetwork/fvelementgeometry.hh:253
const Element & element() const
The bound element.
Definition: discretization/porenetwork/fvelementgeometry.hh:158
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: discretization/porenetwork/fvelementgeometry.hh:48
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: discretization/porenetwork/fvelementgeometry.hh:162
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: discretization/porenetwork/fvelementgeometry.hh:50
SubControlVolume::Traits::Geometry geometry(const SubControlVolume &scv) const
Create the geometry of a given sub control volume.
Definition: discretization/porenetwork/fvelementgeometry.hh:170
SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace &scvf) const
Create the geometry of a given sub control volume face.
Definition: discretization/porenetwork/fvelementgeometry.hh:180
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/porenetwork/fvelementgeometry.hh:166
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: discretization/porenetwork/fvelementgeometry.hh:69
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: discretization/porenetwork/fvelementgeometry.hh:154
friend auto scvfs(const PNMFVElementGeometry &fvGeometry)
Definition: discretization/porenetwork/fvelementgeometry.hh:91
PNMFVElementGeometry bind(const Element &element) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: discretization/porenetwork/fvelementgeometry.hh:121
void bind(const Element &element) &
Definition: discretization/porenetwork/fvelementgeometry.hh:130
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/porenetwork/fvelementgeometry.hh:111
GG GridGeometry
export type of finite volume grid geometry
Definition: discretization/porenetwork/fvelementgeometry.hh:52
void bindElement(const Element &element) &
Definition: discretization/porenetwork/fvelementgeometry.hh:147
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/porenetwork/fvelementgeometry.hh:105
PNMFVElementGeometry bindElement(const Element &element) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: discretization/porenetwork/fvelementgeometry.hh:138
typename GridView::template Codim< 0 >::Entity Element
export element type
Definition: discretization/porenetwork/fvelementgeometry.hh:54
PNMFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: discretization/porenetwork/fvelementgeometry.hh:59
friend auto scvs(const PNMFVElementGeometry &fvGeometry)
Definition: discretization/porenetwork/fvelementgeometry.hh:79
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: discretization/porenetwork/fvelementgeometry.hh:99
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: discretization/porenetwork/fvelementgeometry.hh:63
Base class for the local geometry for porenetworks.
Definition: discretization/porenetwork/fvelementgeometry.hh:33
auto volume(const Geometry &geo, unsigned int integrationOrder=4)
The volume of a given geometry.
Definition: volume.hh:159
Defines the index types used for grid and local indices.
Definition: discretization/porenetwork/fvelementgeometry.hh:24
Class providing iterators over sub control volumes and sub control volume faces of an element.
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:27
unsigned int LocalIndex
Definition: indextraits.hh:28