3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * 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_PNM_FV_ELEMENT_GEOMETRY_HH
25#define DUMUX_DISCRETIZATION_PNM_FV_ELEMENT_GEOMETRY_HH
26
27#include <optional>
28#include <array>
29#include <utility>
30
33
35
42template<class GG, bool enableFVGridGeometryCache>
44
46template<class GG>
47class PNMFVElementGeometry<GG, true>
48{
49 using GridView = typename GG::GridView;
50 static constexpr int dim = GridView::dimension;
51 static constexpr int dimWorld = GridView::dimensionworld;
52 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
53 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
54 using CoordScalar = typename GridView::ctype;
55 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
56public:
58 using SubControlVolume = typename GG::SubControlVolume;
60 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
62 using GridGeometry = GG;
64 using Element = typename GridView::template Codim<0>::Entity;
66 static constexpr std::size_t maxNumElementScvs = 2;
67
70 : gridGeometryPtr_(&gridGeometry) {}
71
73 const SubControlVolume& scv(LocalIndexType scvIdx) const
74 {
75 return gridGeometry().scvs(eIdx_)[scvIdx];
76 }
77
79 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
80 {
81 return gridGeometry().scvfs(eIdx_)[scvfIdx];
82 }
83
89 friend inline auto scvs(const PNMFVElementGeometry& fvGeometry)
90 {
91 const auto& g = fvGeometry.gridGeometry();
92 using Iter = typename std::decay_t<decltype(g.scvs(fvGeometry.eIdx_))>::const_iterator;
93 return Dune::IteratorRange<Iter>(g.scvs(fvGeometry.eIdx_).begin(), g.scvs(fvGeometry.eIdx_).end());
94 }
95
101 friend inline auto scvfs(const PNMFVElementGeometry& fvGeometry)
102 {
103 const auto& g = fvGeometry.gridGeometry();
104 using Iter = typename std::decay_t<decltype(g.scvfs(fvGeometry.eIdx_))>::const_iterator;
105 return Dune::IteratorRange<Iter>(g.scvfs(fvGeometry.eIdx_).begin(), g.scvfs(fvGeometry.eIdx_).end());
106 }
107
109 const FeLocalBasis& feLocalBasis() const
110 {
111 return gridGeometry().feCache().get(element_->type()).localBasis();
112 }
113
115 std::size_t numScv() const
116 {
117 return gridGeometry().scvs(eIdx_).size();
118 }
119
121 std::size_t numScvf() const
122 {
123 return gridGeometry().scvfs(eIdx_).size();
124 }
125
132 {
133 this->bindElement(element);
134 return std::move(*this);
135 }
136
140 void bind(const Element& element) &
141 { this->bindElement(element); }
142
149 {
150 this->bindElement(element);
151 return std::move(*this);
152 }
153
157 void bindElement(const Element& element) &
158 {
159 element_ = element;
160 eIdx_ = gridGeometry().elementMapper().index(element);
161 }
162
164 bool isBound() const
165 { return static_cast<bool>(element_); }
166
168 const Element& element() const
169 { return *element_; }
170
173 { return *gridGeometryPtr_; }
174
176 bool hasBoundaryScvf() const
177 { return gridGeometry().hasBoundaryScvf(eIdx_); }
178
179private:
180 std::optional<Element> element_;
181 const GridGeometry* gridGeometryPtr_;
182
183 GridIndexType eIdx_;
184};
185
187template<class GG>
188class PNMFVElementGeometry<GG, false>
189{
190 using GridView = typename GG::GridView;
191 static constexpr int dim = GridView::dimension;
192 static constexpr int dimWorld = GridView::dimensionworld;
193 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
194 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
195 using CoordScalar = typename GridView::ctype;
196 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
197
198public:
200 using SubControlVolume = typename GG::SubControlVolume;
202 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
204 using GridGeometry = GG;
206 using Element = typename GridView::template Codim<0>::Entity;
208 static constexpr std::size_t maxNumElementScvs = 2;
209
212 : gridGeometryPtr_(&gridGeometry) {}
213
215 const SubControlVolume& scv(LocalIndexType scvIdx) const
216 {
217 return scvs_[scvIdx];
218 }
219
221 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
222 {
223 return scvfs_[0];
224 }
225
231 friend inline auto scvs(const PNMFVElementGeometry& fvGeometry)
232 {
233 using Iter = typename std::decay_t<decltype(fvGeometry.scvs_)>::const_iterator;
234 return Dune::IteratorRange<Iter>(fvGeometry.scvs_.begin(), fvGeometry.scvs_.end());
235 }
236
242 friend inline auto scvfs(const PNMFVElementGeometry& fvGeometry)
243 {
244 using Iter = typename std::decay_t<decltype(fvGeometry.scvfs_)>::const_iterator;
245 return Dune::IteratorRange<Iter>(fvGeometry.scvfs_.begin(), fvGeometry.scvfs_.end());
246 }
247
249 const FeLocalBasis& feLocalBasis() const
250 {
251 return gridGeometry().feCache().get(element_->type()).localBasis();
252 }
253
255 std::size_t numScv() const
256 {
257 return scvs_.size();
258 }
259
261 std::size_t numScvf() const
262 {
263 return scvfs_.size();
264 }
265
272 {
273 this->bindElement(element);
274 return std::move(*this);
275 }
276
280 void bind(const Element& element) &
281 { this->bindElement(element); }
282
289 {
290 this->bindElement(element);
291 return std::move(*this);
292 }
293
297 void bindElement(const Element& element) &
298 {
299 element_ = element;
300 eIdx_ = gridGeometry().elementMapper().index(element);
301 makeElementGeometries(element);
302 }
303
305 bool isBound() const
306 { return static_cast<bool>(element_); }
307
309 const Element& element() const
310 { return *element_; }
311
314 { return *gridGeometryPtr_; }
315
317 bool hasBoundaryScvf() const
318 { return hasBoundaryScvf_; }
319
320private:
321
322 void makeElementGeometries(const Element& element)
323 {
324 hasBoundaryScvf_ = false;
325
326 // get the element geometry
327 auto elementGeometry = element.geometry();
328
329 // construct the sub control volumes
330 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
331 {
332 // get associated dof index
333 const auto dofIdxGlobal = gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim);
334
335 // get the corners
336 auto corners = std::array{elementGeometry.corner(scvLocalIdx), elementGeometry.center()};
337
338 // get the fractional volume associated with the scv
339 const auto volume = gridGeometry().poreVolume(dofIdxGlobal) / gridGeometry().coordinationNumber(dofIdxGlobal);
340
341 // add scv to the local container
342 scvs_[scvLocalIdx] = SubControlVolume(dofIdxGlobal,
343 scvLocalIdx,
344 eIdx_,
345 std::move(corners),
346 volume);
347
348 if (gridGeometry().poreLabel(dofIdxGlobal) > 0)
349 hasBoundaryScvf_ = true;
350 }
351
352 // construct the inner sub control volume face
353 auto unitOuterNormal = elementGeometry.corner(1) - elementGeometry.corner(0);
354 unitOuterNormal /= unitOuterNormal.two_norm();
355 LocalIndexType scvfLocalIdx = 0;
356 scvfs_[0] = SubControlVolumeFace(elementGeometry.center(),
357 std::move(unitOuterNormal),
358 gridGeometry().throatCrossSectionalArea(gridGeometry().elementMapper().index(element)),
359 scvfLocalIdx++,
360 std::array<LocalIndexType, 2>({0, 1}));
361 }
362
364 std::optional<Element> element_;
365 GridIndexType eIdx_;
366
368 const GridGeometry* gridGeometryPtr_;
369
371 std::array<SubControlVolume, 2> scvs_;
372 std::array<SubControlVolumeFace, 1> scvfs_;
373
374 bool hasBoundaryScvf_ = false;
375};
376
377} // end namespace Dumux::PoreNetwork
378
379#endif
Defines the index types used for grid and local indices.
Class providing iterators over sub control volumes and sub control volume faces of an element.
auto volume(const Geometry &geo, unsigned int integrationOrder=4)
The volume of a given geometry.
Definition: volume.hh:171
Definition: discretization/porenetwork/fvelementgeometry.hh:34
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:39
unsigned int LocalIndex
Definition: indextraits.hh:40
Base class for the local geometry for porenetworks.
Definition: discretization/porenetwork/fvelementgeometry.hh:43
const Element & element() const
The bound element.
Definition: discretization/porenetwork/fvelementgeometry.hh:168
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: discretization/porenetwork/fvelementgeometry.hh:58
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: discretization/porenetwork/fvelementgeometry.hh:172
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: discretization/porenetwork/fvelementgeometry.hh:60
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/porenetwork/fvelementgeometry.hh:176
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: discretization/porenetwork/fvelementgeometry.hh:79
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: discretization/porenetwork/fvelementgeometry.hh:164
friend auto scvfs(const PNMFVElementGeometry &fvGeometry)
Definition: discretization/porenetwork/fvelementgeometry.hh:101
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:131
void bind(const Element &element) &
Definition: discretization/porenetwork/fvelementgeometry.hh:140
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/porenetwork/fvelementgeometry.hh:121
GG GridGeometry
export type of finite volume grid geometry
Definition: discretization/porenetwork/fvelementgeometry.hh:62
void bindElement(const Element &element) &
Definition: discretization/porenetwork/fvelementgeometry.hh:157
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/porenetwork/fvelementgeometry.hh:115
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:148
typename GridView::template Codim< 0 >::Entity Element
export element type
Definition: discretization/porenetwork/fvelementgeometry.hh:64
PNMFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: discretization/porenetwork/fvelementgeometry.hh:69
friend auto scvs(const PNMFVElementGeometry &fvGeometry)
Definition: discretization/porenetwork/fvelementgeometry.hh:89
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: discretization/porenetwork/fvelementgeometry.hh:109
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: discretization/porenetwork/fvelementgeometry.hh:73
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: discretization/porenetwork/fvelementgeometry.hh:215
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: discretization/porenetwork/fvelementgeometry.hh:202
void bind(const Element &element) &
Definition: discretization/porenetwork/fvelementgeometry.hh:280
const Element & element() const
The bound element.
Definition: discretization/porenetwork/fvelementgeometry.hh:309
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:271
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/porenetwork/fvelementgeometry.hh:255
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:288
GG GridGeometry
export type of finite volume grid geometry
Definition: discretization/porenetwork/fvelementgeometry.hh:204
friend auto scvfs(const PNMFVElementGeometry &fvGeometry)
Definition: discretization/porenetwork/fvelementgeometry.hh:242
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: discretization/porenetwork/fvelementgeometry.hh:313
void bindElement(const Element &element) &
Definition: discretization/porenetwork/fvelementgeometry.hh:297
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: discretization/porenetwork/fvelementgeometry.hh:200
PNMFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: discretization/porenetwork/fvelementgeometry.hh:211
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/porenetwork/fvelementgeometry.hh:261
typename GridView::template Codim< 0 >::Entity Element
export element type
Definition: discretization/porenetwork/fvelementgeometry.hh:206
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: discretization/porenetwork/fvelementgeometry.hh:221
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: discretization/porenetwork/fvelementgeometry.hh:305
friend auto scvs(const PNMFVElementGeometry &fvGeometry)
Definition: discretization/porenetwork/fvelementgeometry.hh:231
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/porenetwork/fvelementgeometry.hh:317
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: discretization/porenetwork/fvelementgeometry.hh:249
Base class for the finite volume geometry for porenetwork models.
Definition: discretization/porenetwork/gridgeometry.hh:489