version 3.10-dev
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// 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_SCV_AND_SCVF_ITERATORS_HH
13#define DUMUX_SCV_AND_SCVF_ITERATORS_HH
14
15#include <dune/common/iteratorrange.hh>
16#include <dune/common/iteratorfacades.hh>
17
18namespace Dumux {
19
25template<class SubControlVolume, class Vector, class FVElementGeometry>
26class ScvIterator : public Dune::ForwardIteratorFacade<ScvIterator<SubControlVolume,
27 Vector,
28 FVElementGeometry>,
29 const SubControlVolume>
30{
32 using Iterator = typename Vector::const_iterator;
33public:
34 ScvIterator(const Iterator& it, const FVElementGeometry& fvGeometry)
35 : it_(it), fvGeometryPtr_(&fvGeometry) {}
36
37 ScvIterator() : it_(Iterator()), fvGeometryPtr_(nullptr) {}
38
40 const SubControlVolume& dereference() const
41 {
42 return fvGeometryPtr_->scv(*it_);
43 }
44
45 bool equals(const ThisType& other) const
46 {
47 return it_ == other.it_;
48 }
49
50 void increment()
51 {
52 ++it_;
53 }
54
55private:
56 Iterator it_;
57 const FVElementGeometry* fvGeometryPtr_;
58};
59
65template<class SubControlVolumeFace, class Vector, class FVElementGeometry>
66class ScvfIterator : public Dune::ForwardIteratorFacade<ScvfIterator<SubControlVolumeFace,
67 Vector,
68 FVElementGeometry>,
69 const SubControlVolumeFace>
70{
72 using Iterator = typename Vector::const_iterator;
73public:
74 ScvfIterator(const Iterator& it, const FVElementGeometry& fvGeometry)
75 : it_(it), fvGeometryPtr_(&fvGeometry) {}
76
77 ScvfIterator() : it_(Iterator()), fvGeometryPtr_(nullptr) {}
78
80 const SubControlVolumeFace& dereference() const
81 {
82 return fvGeometryPtr_->scvf(*it_);
83 }
84
85 bool equals(const ThisType& other) const
86 {
87 return it_ == other.it_;
88 }
89
90 void increment()
91 {
92 it_++;
93 }
94
95private:
96 Iterator it_;
97 const FVElementGeometry* fvGeometryPtr_;
98};
99
105template<class SubControlVolumeFace, class Vector, class FVElementGeometry>
106class SkippingScvfIterator : public Dune::ForwardIteratorFacade<SkippingScvfIterator<SubControlVolumeFace,
107 Vector,
108 FVElementGeometry>,
109 const SubControlVolumeFace>
110{
112 using Iterator = typename Vector::const_iterator;
113public:
114
115 SkippingScvfIterator() : it_(Iterator()), fvGeometryPtr_(nullptr) {}
116
117 static ThisType makeBegin(const Vector& vector, const FVElementGeometry& fvGeometry, const std::size_t scvIdx)
118 {
119 auto begin = vector.begin();
120 const auto end = vector.end();
121
122 while (begin != end && fvGeometry.scvf(*begin).insideScvIdx() != scvIdx)
123 ++begin;
124
125 return SkippingScvfIterator(begin, end, fvGeometry, scvIdx);
126 }
127
128 static ThisType makeEnd(const Vector& vector, const FVElementGeometry& fvGeometry, const std::size_t scvIdx)
129 {
130 return SkippingScvfIterator(vector.end(), vector.end(), fvGeometry, scvIdx);
131 }
132
134 const SubControlVolumeFace& dereference() const
135 {
136 return fvGeometryPtr_->scvf(*it_);
137 }
138
139 bool equals(const ThisType& other) const
140 {
141 return it_ == other.it_;
142 }
143
145 {
146 ++it_;
147 while (it_ != itEnd_ && dereference().insideScvIdx() != scvIdx_)
148 ++it_;
149 }
150
151private:
152
153 SkippingScvfIterator(const Iterator& itBegin, const Iterator& itEnd, const FVElementGeometry& fvGeometry, const std::size_t scvIdx)
154 : it_(itBegin), fvGeometryPtr_(&fvGeometry), itEnd_(itEnd), scvIdx_(scvIdx) {}
155
156 Iterator it_;
157 const FVElementGeometry* fvGeometryPtr_;
158 const Iterator itEnd_;
159 std::size_t scvIdx_;
160};
161
162} // end namespace Dumux
163
164#endif
Iterators over sub control volumes.
Definition: scvandscvfiterators.hh:30
bool equals(const ThisType &other) const
Definition: scvandscvfiterators.hh:45
ScvIterator(const Iterator &it, const FVElementGeometry &fvGeometry)
Definition: scvandscvfiterators.hh:34
const SubControlVolume & dereference() const
dereferencing yields a subcontrol volume
Definition: scvandscvfiterators.hh:40
void increment()
Definition: scvandscvfiterators.hh:50
ScvIterator()
Definition: scvandscvfiterators.hh:37
Iterators over sub control volume faces of an fv geometry.
Definition: scvandscvfiterators.hh:70
ScvfIterator()
Definition: scvandscvfiterators.hh:77
void increment()
Definition: scvandscvfiterators.hh:90
ScvfIterator(const Iterator &it, const FVElementGeometry &fvGeometry)
Definition: scvandscvfiterators.hh:74
const SubControlVolumeFace & dereference() const
dereferencing yields a subcontrol volume face
Definition: scvandscvfiterators.hh:80
bool equals(const ThisType &other) const
Definition: scvandscvfiterators.hh:85
Iterators over sub control volume faces of an fv geometry and a given sub control volume.
Definition: scvandscvfiterators.hh:110
bool equals(const ThisType &other) const
Definition: scvandscvfiterators.hh:139
const SubControlVolumeFace & dereference() const
dereferencing yields a subcontrol volume face
Definition: scvandscvfiterators.hh:134
SkippingScvfIterator()
Definition: scvandscvfiterators.hh:115
void increment()
Definition: scvandscvfiterators.hh:144
static ThisType makeEnd(const Vector &vector, const FVElementGeometry &fvGeometry, const std::size_t scvIdx)
Definition: scvandscvfiterators.hh:128
static ThisType makeBegin(const Vector &vector, const FVElementGeometry &fvGeometry, const std::size_t scvIdx)
Definition: scvandscvfiterators.hh:117
Definition: adapt.hh:17