3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
discretization/staggered/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_STAGGERED_FV_ELEMENT_GEOMETRY_HH
25#define DUMUX_DISCRETIZATION_STAGGERED_FV_ELEMENT_GEOMETRY_HH
26
27#include <optional>
30
31namespace Dumux {
32
42template<class GG, bool enableGridGeometryCache>
44
53template<class GG>
54class StaggeredFVElementGeometry<GG, true> : public CCTpfaFVElementGeometry<GG, true>
55{
57 using GridView = typename GG::GridView;
58 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
59 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
60public:
62 using Element = typename GridView::template Codim<0>::Entity;
64 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
65
66 using ParentType::ParentType;
67
70 template<class CellCenterOrFaceFVGridGeometry>
71 StaggeredFVElementGeometry(const CellCenterOrFaceFVGridGeometry& gridGeometry)
72 : ParentType(gridGeometry.actualGridGeometry()) {}
73
75 using ParentType::scvf;
76 const SubControlVolumeFace& scvf(GridIndexType eIdx, LocalIndexType localScvfIdx) const
77 {
78 return this->gridGeometry().scvf(eIdx, localScvfIdx);
79 }
80};
81
90template<class GG>
92{
94 using GridView = typename GG::GridView;
95 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
96 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
97public:
99 using Element = typename GridView::template Codim<0>::Entity;
101 using SubControlVolume = typename GG::SubControlVolume;
103 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
105 using GridGeometry = GG;
106
109 template<class CellCenterOrFaceFVGridGeometry>
110 StaggeredFVElementGeometry(const CellCenterOrFaceFVGridGeometry& gridGeometry)
111 : gridGeometryPtr_(&gridGeometry.actualGridGeometry()) {}
112
115 : gridGeometryPtr_(&gridGeometry) {}
116
118 const SubControlVolumeFace& scvf(GridIndexType eIdx, LocalIndexType localScvfIdx) const
119 {
120 return scvf(this->gridGeometry().localToGlobalScvfIndex(eIdx, localScvfIdx));
121 }
122
125 const SubControlVolume& scv(GridIndexType scvIdx) const
126 {
127 if (scvIdx == scvIndices_[0])
128 return scvs_[0];
129 else
130 return neighborScvs_[findLocalIndex_(scvIdx, neighborScvIndices_)];
131 }
132
135 const SubControlVolumeFace& scvf(GridIndexType scvfIdx) const
136 {
137 auto it = std::find(scvfIndices_.begin(), scvfIndices_.end(), scvfIdx);
138 if (it != scvfIndices_.end())
139 return scvfs_[std::distance(scvfIndices_.begin(), it)];
140 else
141 return neighborScvfs_[findLocalIndex_(scvfIdx, neighborScvfIndices_)];
142 }
143
149 friend inline Dune::IteratorRange<typename std::array<SubControlVolume, 1>::const_iterator>
150 scvs(const ThisType& g)
151 {
152 using IteratorType = typename std::array<SubControlVolume, 1>::const_iterator;
153 return Dune::IteratorRange<IteratorType>(g.scvs_.begin(), g.scvs_.end());
154 }
155
161 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
162 scvfs(const ThisType& g)
163 {
164 using IteratorType = typename std::vector<SubControlVolumeFace>::const_iterator;
165 return Dune::IteratorRange<IteratorType>(g.scvfs_.begin(), g.scvfs_.end());
166 }
167
169 std::size_t numScv() const
170 { return scvs_.size(); }
171
173 std::size_t numScvf() const
174 { return scvfs_.size(); }
175
182 {
183 this->bind_(element);
184 return std::move(*this);
185 }
186
188 void bind(const Element& element) &
189 { this->bind_(element); }
190
197 {
198 this->bindElement_(element);
199 return std::move(*this);
200 }
201
203 void bindElement(const Element& element) &
204 { this->bindElement_(element); }
205
207 bool isBound() const
208 { return static_cast<bool>(element_); }
209
211 const Element& element() const
212 { return *element_; }
213
216 { return *gridGeometryPtr_; }
217
219 bool hasBoundaryScvf() const
220 { return hasBoundaryScvf_; }
221
222 typename SubControlVolumeFace::Traits::Geometry geometry (const SubControlVolumeFace& scvf) const
223 {
224 assert(isBound());
225 return scvf.geometry();
226 }
227
228private:
230 void bindElement_(const Element& element)
231 {
232 clear_();
233 element_ = element;
234 scvfs_.reserve(element.subEntities(1));
235 scvfIndices_.reserve(element.subEntities(1));
236 makeElementGeometries_();
237 }
238
241 void bind_(const Element& element)
242 {
243 bindElement_(element);
244
245 neighborScvs_.reserve(element.subEntities(1));
246 neighborScvfIndices_.reserve(element.subEntities(1));
247 neighborScvfs_.reserve(element.subEntities(1));
248
249 std::vector<GridIndexType> handledNeighbors;
250 handledNeighbors.reserve(element.subEntities(1));
251 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
252 {
253 if (intersection.neighbor())
254 {
255 const auto outside = intersection.outside();
256 const auto outsideIdx = gridGeometry().elementMapper().index(outside);
257
258 // make outside geometries only if not done yet (could happen on non-conforming grids)
259 if ( std::find(handledNeighbors.begin(), handledNeighbors.end(), outsideIdx) == handledNeighbors.end() )
260 {
261 makeNeighborGeometries_(outside, outsideIdx);
262 handledNeighbors.push_back(outsideIdx);
263 }
264 }
265 }
266 }
267
269 void makeElementGeometries_()
270 {
271 const auto& element = *element_;
272 const auto eIdx = gridGeometry().elementMapper().index(element);
273 scvs_[0] = SubControlVolume(element.geometry(), eIdx);
274 scvIndices_[0] = eIdx;
275
276 const auto& scvFaceIndices = gridGeometry().scvfIndicesOfScv(eIdx);
277 const auto& neighborVolVarIndices = gridGeometry().neighborVolVarIndices(eIdx);
278
279 typename GridGeometry::GeometryHelper geometryHelper(element, gridGeometry().gridView());
280
281 int scvfCounter = 0;
282 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
283 {
284 const auto& scvfNeighborVolVarIndex = neighborVolVarIndices[scvfCounter];
285
286 if (intersection.neighbor() || intersection.boundary())
287 {
288 geometryHelper.updateLocalFace(gridGeometry().intersectionMapper(), intersection);
289 std::vector<GridIndexType> scvIndices{eIdx, scvfNeighborVolVarIndex};
290 scvfs_.emplace_back(intersection,
291 intersection.geometry(),
292 scvFaceIndices[scvfCounter],
293 scvIndices,
294 geometryHelper);
295 scvfIndices_.emplace_back(scvFaceIndices[scvfCounter]);
296 scvfCounter++;
297
298 if (intersection.boundary())
299 hasBoundaryScvf_ = true;
300 }
301 }
302 }
303
305 void makeNeighborGeometries_(const Element& element, const GridIndexType eIdx)
306 {
307 // using ScvfGridIndexStorage = typename SubControlVolumeFace::Traits::GridIndexStorage;
308
309 // create the neighbor scv
310 neighborScvs_.emplace_back(element.geometry(), eIdx);
311 neighborScvIndices_.push_back(eIdx);
312
313 const auto& scvFaceIndices = gridGeometry().scvfIndicesOfScv(eIdx);
314 const auto& neighborVolVarIndices = gridGeometry().neighborVolVarIndices(eIdx);
315
316 typename GridGeometry::GeometryHelper geometryHelper(element, gridGeometry().gridView());
317
318 int scvfCounter = 0;
319 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
320 {
321 const auto& scvfNeighborVolVarIndex = neighborVolVarIndices[scvfCounter];
322 geometryHelper.updateLocalFace(gridGeometry().intersectionMapper(), intersection);
323
324 if (intersection.neighbor())
325 {
326 // only create subcontrol faces where the outside element is the bound element
327 if (intersection.outside() == *element_)
328 {
329 std::vector<GridIndexType> scvIndices{eIdx, scvfNeighborVolVarIndex};
330 neighborScvfs_.emplace_back(intersection,
331 intersection.geometry(),
332 scvFaceIndices[scvfCounter],
333 scvIndices,
334 geometryHelper);
335
336 neighborScvfIndices_.push_back(scvFaceIndices[scvfCounter]);
337 }
338 scvfCounter++;
339 }
340 else if (intersection.boundary())
341 scvfCounter++;
342 }
343 }
344
345 const LocalIndexType findLocalIndex_(const GridIndexType idx,
346 const std::vector<GridIndexType>& indices) const
347 {
348 auto it = std::find(indices.begin(), indices.end(), idx);
349 assert(it != indices.end() && "Could not find the scv/scvf! Make sure to properly bind this class!");
350 return std::distance(indices.begin(), it);
351 }
352
354 void clear_()
355 {
356 scvfIndices_.clear();
357 scvfs_.clear();
358
359 neighborScvIndices_.clear();
360 neighborScvfIndices_.clear();
361 neighborScvs_.clear();
362 neighborScvfs_.clear();
363
364 hasBoundaryScvf_ = false;
365 }
366
367 std::optional<Element> element_;
368 const GridGeometry* gridGeometryPtr_;
369
370 // local storage after binding an element
371 std::array<GridIndexType, 1> scvIndices_;
372 std::array<SubControlVolume, 1> scvs_;
373
374 std::vector<GridIndexType> scvfIndices_;
375 std::vector<SubControlVolumeFace> scvfs_;
376
377 std::vector<GridIndexType> neighborScvIndices_;
378 std::vector<SubControlVolume> neighborScvs_;
379
380 std::vector<GridIndexType> neighborScvfIndices_;
381 std::vector<SubControlVolumeFace> neighborScvfs_;
382
383 bool hasBoundaryScvf_ = false;
384};
385
386
387} // end namespace
388
389#endif
Defines the index types used for grid and local indices.
static ctype distance(const Dune::FieldVector< ctype, dimWorld > &a, const Dune::FieldVector< ctype, dimWorld > &b)
Compute the shortest distance between two points.
Definition: distance.hh:294
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:39
unsigned int LocalIndex
Definition: indextraits.hh:40
Stencil-local finite volume geometry (scvs and scvfs) for cell-centered TPFA models This builds up th...
Definition: discretization/cellcentered/tpfa/fvelementgeometry.hh:52
Stencil-local finite volume geometry (scvs and scvfs) for cell-centered TPFA models Specialization fo...
Definition: discretization/cellcentered/tpfa/fvelementgeometry.hh:62
typename GridView::template Codim< 0 >::Entity Element
export type of the element
Definition: discretization/cellcentered/tpfa/fvelementgeometry.hh:69
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: discretization/cellcentered/tpfa/fvelementgeometry.hh:73
Stencil-local finite volume geometry (scvs and scvfs) for staggered models This builds up the sub con...
Definition: discretization/staggered/fvelementgeometry.hh:43
const SubControlVolumeFace & scvf(GridIndexType eIdx, LocalIndexType localScvfIdx) const
Definition: discretization/staggered/fvelementgeometry.hh:76
StaggeredFVElementGeometry(const CellCenterOrFaceFVGridGeometry &gridGeometry)
Definition: discretization/staggered/fvelementgeometry.hh:71
Base class for the finite volume geometry vector for staggered models This locally builds up the sub ...
Definition: discretization/staggered/fvelementgeometry.hh:92
StaggeredFVElementGeometry 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/staggered/fvelementgeometry.hh:181
typename GridView::template Codim< 0 >::Entity Element
export type of the element
Definition: discretization/staggered/fvelementgeometry.hh:99
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/staggered/fvelementgeometry.hh:219
void bindElement(const Element &element) &
bind this local view to a specific element
Definition: discretization/staggered/fvelementgeometry.hh:203
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const ThisType &g)
Definition: discretization/staggered/fvelementgeometry.hh:162
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: discretization/staggered/fvelementgeometry.hh:101
SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace &scvf) const
Definition: discretization/staggered/fvelementgeometry.hh:222
const SubControlVolume & scv(GridIndexType scvIdx) const
Definition: discretization/staggered/fvelementgeometry.hh:125
StaggeredFVElementGeometry(const CellCenterOrFaceFVGridGeometry &gridGeometry)
Definition: discretization/staggered/fvelementgeometry.hh:110
std::size_t numScv() const
number of sub control volumes in this fv element geometry
Definition: discretization/staggered/fvelementgeometry.hh:169
const SubControlVolumeFace & scvf(GridIndexType eIdx, LocalIndexType localScvfIdx) const
Get a sub control volume face with an element index and a local scvf index.
Definition: discretization/staggered/fvelementgeometry.hh:118
const GridGeometry & gridGeometry() const
The grid finite volume geometry we are a restriction of.
Definition: discretization/staggered/fvelementgeometry.hh:215
std::size_t numScvf() const
number of sub control volumes in this fv element geometry
Definition: discretization/staggered/fvelementgeometry.hh:173
StaggeredFVElementGeometry 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/staggered/fvelementgeometry.hh:196
StaggeredFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: discretization/staggered/fvelementgeometry.hh:114
const Element & element() const
The bound element.
Definition: discretization/staggered/fvelementgeometry.hh:211
void bind(const Element &element) &
bind this local view to a specific element (full stencil)
Definition: discretization/staggered/fvelementgeometry.hh:188
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: discretization/staggered/fvelementgeometry.hh:207
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: discretization/staggered/fvelementgeometry.hh:103
friend Dune::IteratorRange< typename std::array< SubControlVolume, 1 >::const_iterator > scvs(const ThisType &g)
Definition: discretization/staggered/fvelementgeometry.hh:150
const SubControlVolumeFace & scvf(GridIndexType scvfIdx) const
Definition: discretization/staggered/fvelementgeometry.hh:135
GG GridGeometry
export type of finite volume grid geometry
Definition: discretization/staggered/fvelementgeometry.hh:105
Stencil-local finite volume geometry (scvs and scvfs) for cell-centered TPFA models This builds up th...