3.4
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
32
34
41template<class GG, bool enableFVGridGeometryCache>
43
45template<class GG>
46class PNMFVElementGeometry<GG, true>
47{
48 using GridView = typename GG::GridView;
49 static constexpr int dim = GridView::dimension;
50 static constexpr int dimWorld = GridView::dimensionworld;
51 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
52 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
53 using CoordScalar = typename GridView::ctype;
54 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
55public:
57 using SubControlVolume = typename GG::SubControlVolume;
59 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
61 using GridGeometry = GG;
63 using Element = typename GridView::template Codim<0>::Entity;
65 static constexpr std::size_t maxNumElementScvs = 2;
66
69 : gridGeometryPtr_(&gridGeometry) {}
70
72 const SubControlVolume& scv(LocalIndexType scvIdx) const
73 {
74 return gridGeometry().scvs(eIdx_)[scvIdx];
75 }
76
78 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
79 {
80 return gridGeometry().scvfs(eIdx_)[scvfIdx];
81 }
82
88 friend inline auto scvs(const PNMFVElementGeometry& fvGeometry)
89 {
90 const auto& g = fvGeometry.gridGeometry();
91 using Iter = typename std::decay_t<decltype(g.scvs(fvGeometry.eIdx_))>::const_iterator;
92 return Dune::IteratorRange<Iter>(g.scvs(fvGeometry.eIdx_).begin(), g.scvs(fvGeometry.eIdx_).end());
93 }
94
100 friend inline auto scvfs(const PNMFVElementGeometry& fvGeometry)
101 {
102 const auto& g = fvGeometry.gridGeometry();
103 using Iter = typename std::decay_t<decltype(g.scvfs(fvGeometry.eIdx_))>::const_iterator;
104 return Dune::IteratorRange<Iter>(g.scvfs(fvGeometry.eIdx_).begin(), g.scvfs(fvGeometry.eIdx_).end());
105 }
106
108 const FeLocalBasis& feLocalBasis() const
109 {
110 return gridGeometry().feCache().get(element_->type()).localBasis();
111 }
112
114 std::size_t numScv() const
115 {
116 return gridGeometry().scvs(eIdx_).size();
117 }
118
120 std::size_t numScvf() const
121 {
122 return gridGeometry().scvfs(eIdx_).size();
123 }
124
128 void bind(const Element& element)
129 {
130 this->bindElement(element);
131 }
132
136 void bindElement(const Element& element)
137 {
138 element_ = element;
139 eIdx_ = gridGeometry().elementMapper().index(element);
140 }
141
143 bool isBound() const
144 { return static_cast<bool>(element_); }
145
147 const Element& element() const
148 { return *element_; }
149
152 { return *gridGeometryPtr_; }
153
155 bool hasBoundaryScvf() const
156 { return gridGeometry().hasBoundaryScvf(eIdx_); }
157
158private:
159 std::optional<Element> element_;
160 const GridGeometry* gridGeometryPtr_;
161
162 GridIndexType eIdx_;
163};
164
166template<class GG>
167class PNMFVElementGeometry<GG, false>
168{
169 using GridView = typename GG::GridView;
170 static constexpr int dim = GridView::dimension;
171 static constexpr int dimWorld = GridView::dimensionworld;
172 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
173 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
174 using CoordScalar = typename GridView::ctype;
175 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
176
177public:
179 using SubControlVolume = typename GG::SubControlVolume;
181 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
183 using GridGeometry = GG;
185 using Element = typename GridView::template Codim<0>::Entity;
187 static constexpr std::size_t maxNumElementScvs = 2;
188
191 : gridGeometryPtr_(&gridGeometry) {}
192
194 const SubControlVolume& scv(LocalIndexType scvIdx) const
195 {
196 return scvs_[scvIdx];
197 }
198
200 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
201 {
202 return scvfs_[0];
203 }
204
210 friend inline auto scvs(const PNMFVElementGeometry& fvGeometry)
211 {
212 using Iter = typename std::decay_t<decltype(fvGeometry.scvs_)>::const_iterator;
213 return Dune::IteratorRange<Iter>(fvGeometry.scvs_.begin(), fvGeometry.scvs_.end());
214 }
215
221 friend inline auto scvfs(const PNMFVElementGeometry& fvGeometry)
222 {
223 using Iter = typename std::decay_t<decltype(fvGeometry.scvfs_)>::const_iterator;
224 return Dune::IteratorRange<Iter>(fvGeometry.scvfs_.begin(), fvGeometry.scvfs_.end());
225 }
226
228 const FeLocalBasis& feLocalBasis() const
229 {
230 return gridGeometry().feCache().get(element_->type()).localBasis();
231 }
232
234 std::size_t numScv() const
235 {
236 return scvs_.size();
237 }
238
240 std::size_t numScvf() const
241 {
242 return scvfs_.size();
243 }
244
248 void bind(const Element& element)
249 {
250 this->bindElement(element);
251 }
252
256 void bindElement(const Element& element)
257 {
258 element_ = element;
259 eIdx_ = gridGeometry().elementMapper().index(element);
260 makeElementGeometries(element);
261 }
262
264 bool isBound() const
265 { return static_cast<bool>(element_); }
266
268 const Element& element() const
269 { return *element_; }
270
273 { return *gridGeometryPtr_; }
274
276 bool hasBoundaryScvf() const
277 { return hasBoundaryScvf_; }
278
279private:
280
281 void makeElementGeometries(const Element& element)
282 {
283 hasBoundaryScvf_ = false;
284
285 // get the element geometry
286 auto elementGeometry = element.geometry();
287
288 // construct the sub control volumes
289 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
290 {
291 // get asssociated dof index
292 const auto dofIdxGlobal = gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim);
293
294 // get the corners
295 auto corners = std::array{elementGeometry.corner(scvLocalIdx), elementGeometry.center()};
296
297 // get the fractional volume asssociated with the scv
298 const auto volume = gridGeometry().poreVolume(dofIdxGlobal) / gridGeometry().coordinationNumber(dofIdxGlobal);
299
300 // add scv to the local container
301 scvs_[scvLocalIdx] = SubControlVolume(dofIdxGlobal,
302 scvLocalIdx,
303 eIdx_,
304 std::move(corners),
305 volume);
306
307 if (gridGeometry().poreLabel(dofIdxGlobal) > 0)
308 hasBoundaryScvf_ = true;
309 }
310
311 // construct the inner sub control volume face
312 auto unitOuterNormal = elementGeometry.corner(1) - elementGeometry.corner(0);
313 unitOuterNormal /= unitOuterNormal.two_norm();
314 LocalIndexType scvfLocalIdx = 0;
315 scvfs_[0] = SubControlVolumeFace(elementGeometry.center(),
316 std::move(unitOuterNormal),
317 gridGeometry().throatCrossSectionalArea(gridGeometry().elementMapper().index(element)),
318 scvfLocalIdx++,
319 std::array<LocalIndexType, 2>({0, 1}));
320 }
321
323 std::optional<Element> element_;
324 GridIndexType eIdx_;
325
327 const GridGeometry* gridGeometryPtr_;
328
330 std::array<SubControlVolume, 2> scvs_;
331 std::array<SubControlVolumeFace, 1> scvfs_;
332
333 bool hasBoundaryScvf_ = false;
334};
335
336} // end namespace Dumux::PoreNetwork
337
338#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.
Definition: discretization/porenetwork/fvelementgeometry.hh:33
Scalar volume(Shape shape, Scalar inscribedRadius)
Returns the volume of a given geometry based on the inscribed radius.
Definition: poreproperties.hh:73
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:42
const Element & element() const
The bound element.
Definition: discretization/porenetwork/fvelementgeometry.hh:147
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: discretization/porenetwork/fvelementgeometry.hh:57
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: discretization/porenetwork/fvelementgeometry.hh:151
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: discretization/porenetwork/fvelementgeometry.hh:59
void bindElement(const Element &element)
Definition: discretization/porenetwork/fvelementgeometry.hh:136
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/porenetwork/fvelementgeometry.hh:155
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: discretization/porenetwork/fvelementgeometry.hh:78
void bind(const Element &element)
Definition: discretization/porenetwork/fvelementgeometry.hh:128
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: discretization/porenetwork/fvelementgeometry.hh:143
friend auto scvfs(const PNMFVElementGeometry &fvGeometry)
Definition: discretization/porenetwork/fvelementgeometry.hh:100
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/porenetwork/fvelementgeometry.hh:120
GG GridGeometry
export type of finite volume grid geometry
Definition: discretization/porenetwork/fvelementgeometry.hh:61
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/porenetwork/fvelementgeometry.hh:114
typename GridView::template Codim< 0 >::Entity Element
export element type
Definition: discretization/porenetwork/fvelementgeometry.hh:63
PNMFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: discretization/porenetwork/fvelementgeometry.hh:68
friend auto scvs(const PNMFVElementGeometry &fvGeometry)
Definition: discretization/porenetwork/fvelementgeometry.hh:88
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: discretization/porenetwork/fvelementgeometry.hh:108
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: discretization/porenetwork/fvelementgeometry.hh:72
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: discretization/porenetwork/fvelementgeometry.hh:194
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: discretization/porenetwork/fvelementgeometry.hh:181
const Element & element() const
The bound element.
Definition: discretization/porenetwork/fvelementgeometry.hh:268
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/porenetwork/fvelementgeometry.hh:234
GG GridGeometry
export type of finite volume grid geometry
Definition: discretization/porenetwork/fvelementgeometry.hh:183
void bindElement(const Element &element)
Definition: discretization/porenetwork/fvelementgeometry.hh:256
friend auto scvfs(const PNMFVElementGeometry &fvGeometry)
Definition: discretization/porenetwork/fvelementgeometry.hh:221
void bind(const Element &element)
Definition: discretization/porenetwork/fvelementgeometry.hh:248
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: discretization/porenetwork/fvelementgeometry.hh:272
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: discretization/porenetwork/fvelementgeometry.hh:179
PNMFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: discretization/porenetwork/fvelementgeometry.hh:190
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/porenetwork/fvelementgeometry.hh:240
typename GridView::template Codim< 0 >::Entity Element
export element type
Definition: discretization/porenetwork/fvelementgeometry.hh:185
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: discretization/porenetwork/fvelementgeometry.hh:200
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: discretization/porenetwork/fvelementgeometry.hh:264
friend auto scvs(const PNMFVElementGeometry &fvGeometry)
Definition: discretization/porenetwork/fvelementgeometry.hh:210
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/porenetwork/fvelementgeometry.hh:276
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: discretization/porenetwork/fvelementgeometry.hh:228
Base class for the finite volume geometry for porenetwork models.
Definition: discretization/porenetwork/gridgeometry.hh:488