3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
scvandscvfiterators.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_SCV_AND_SCVF_ITERATORS_HH
25#define DUMUX_SCV_AND_SCVF_ITERATORS_HH
26
27#include <dune/common/iteratorrange.hh>
28#include <dune/common/iteratorfacades.hh>
29
30namespace Dumux {
31
37template<class SubControlVolume, class Vector, class FVElementGeometry>
38class ScvIterator : public Dune::ForwardIteratorFacade<ScvIterator<SubControlVolume,
39 Vector,
40 FVElementGeometry>,
41 const SubControlVolume>
42{
44 using Iterator = typename Vector::const_iterator;
45public:
46 ScvIterator(const Iterator& it, const FVElementGeometry& fvGeometry)
47 : it_(it), fvGeometryPtr_(&fvGeometry) {}
48
49 ScvIterator() : it_(Iterator()), fvGeometryPtr_(nullptr) {}
50
52 const SubControlVolume& dereference() const
53 {
54 return fvGeometryPtr_->scv(*it_);
55 }
56
57 bool equals(const ThisType& other) const
58 {
59 return it_ == other.it_;
60 }
61
62 void increment()
63 {
64 ++it_;
65 }
66
67private:
68 Iterator it_;
69 const FVElementGeometry* fvGeometryPtr_;
70};
71
77template<class SubControlVolumeFace, class Vector, class FVElementGeometry>
78class ScvfIterator : public Dune::ForwardIteratorFacade<ScvfIterator<SubControlVolumeFace,
79 Vector,
80 FVElementGeometry>,
81 const SubControlVolumeFace>
82{
84 using Iterator = typename Vector::const_iterator;
85public:
86 ScvfIterator(const Iterator& it, const FVElementGeometry& fvGeometry)
87 : it_(it), fvGeometryPtr_(&fvGeometry) {}
88
89 ScvfIterator() : it_(Iterator()), fvGeometryPtr_(nullptr) {}
90
92 const SubControlVolumeFace& dereference() const
93 {
94 return fvGeometryPtr_->scvf(*it_);
95 }
96
97 bool equals(const ThisType& other) const
98 {
99 return it_ == other.it_;
100 }
101
103 {
104 it_++;
105 }
106
107private:
108 Iterator it_;
109 const FVElementGeometry* fvGeometryPtr_;
110};
111
117template<class SubControlVolumeFace, class Vector, class FVElementGeometry>
118class SkippingScvfIterator : public Dune::ForwardIteratorFacade<SkippingScvfIterator<SubControlVolumeFace,
119 Vector,
120 FVElementGeometry>,
121 const SubControlVolumeFace>
122{
124 using Iterator = typename Vector::const_iterator;
125public:
126
127 SkippingScvfIterator() : it_(Iterator()), fvGeometryPtr_(nullptr) {}
128
129 static ThisType makeBegin(const Vector& vector, const FVElementGeometry& fvGeometry, const std::size_t scvIdx)
130 {
131 auto begin = vector.begin();
132 const auto end = vector.end();
133
134 while (begin != end && fvGeometry.scvf(*begin).insideScvIdx() != scvIdx)
135 ++begin;
136
137 return SkippingScvfIterator(begin, end, fvGeometry, scvIdx);
138 }
139
140 static ThisType makeEnd(const Vector& vector, const FVElementGeometry& fvGeometry, const std::size_t scvIdx)
141 {
142 return SkippingScvfIterator(vector.end(), vector.end(), fvGeometry, scvIdx);
143 }
144
146 const SubControlVolumeFace& dereference() const
147 {
148 return fvGeometryPtr_->scvf(*it_);
149 }
150
151 bool equals(const ThisType& other) const
152 {
153 return it_ == other.it_;
154 }
155
157 {
158 ++it_;
159 while (it_ != itEnd_ && dereference().insideScvIdx() != scvIdx_)
160 ++it_;
161 }
162
163private:
164
165 SkippingScvfIterator(const Iterator& itBegin, const Iterator& itEnd, const FVElementGeometry& fvGeometry, const std::size_t scvIdx)
166 : it_(itBegin), fvGeometryPtr_(&fvGeometry), itEnd_(itEnd), scvIdx_(scvIdx) {}
167
168 Iterator it_;
169 const FVElementGeometry* fvGeometryPtr_;
170 const Iterator itEnd_;
171 std::size_t scvIdx_;
172};
173
174} // end namespace Dumux
175
176#endif
Definition: adapt.hh:29
Iterators over sub control volumes.
Definition: scvandscvfiterators.hh:42
bool equals(const ThisType &other) const
Definition: scvandscvfiterators.hh:57
ScvIterator(const Iterator &it, const FVElementGeometry &fvGeometry)
Definition: scvandscvfiterators.hh:46
const SubControlVolume & dereference() const
dereferencing yields a subcontrol volume
Definition: scvandscvfiterators.hh:52
void increment()
Definition: scvandscvfiterators.hh:62
ScvIterator()
Definition: scvandscvfiterators.hh:49
Iterators over sub control volume faces of an fv geometry.
Definition: scvandscvfiterators.hh:82
ScvfIterator()
Definition: scvandscvfiterators.hh:89
void increment()
Definition: scvandscvfiterators.hh:102
ScvfIterator(const Iterator &it, const FVElementGeometry &fvGeometry)
Definition: scvandscvfiterators.hh:86
const SubControlVolumeFace & dereference() const
dereferencing yields a subcontrol volume face
Definition: scvandscvfiterators.hh:92
bool equals(const ThisType &other) const
Definition: scvandscvfiterators.hh:97
Iterators over sub control volume faces of an fv geometry and a given sub control volume.
Definition: scvandscvfiterators.hh:122
bool equals(const ThisType &other) const
Definition: scvandscvfiterators.hh:151
const SubControlVolumeFace & dereference() const
dereferencing yields a subcontrol volume face
Definition: scvandscvfiterators.hh:146
SkippingScvfIterator()
Definition: scvandscvfiterators.hh:127
void increment()
Definition: scvandscvfiterators.hh:156
static ThisType makeEnd(const Vector &vector, const FVElementGeometry &fvGeometry, const std::size_t scvIdx)
Definition: scvandscvfiterators.hh:140
static ThisType makeBegin(const Vector &vector, const FVElementGeometry &fvGeometry, const std::size_t scvIdx)
Definition: scvandscvfiterators.hh:129