Line | Branch | Exec | Source |
---|---|---|---|
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-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder | ||
5 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
6 | // | ||
7 | /*! | ||
8 | * \file | ||
9 | * \ingroup Discretization | ||
10 | * \brief Class providing iterators over sub control volumes and sub control volume faces of an element. | ||
11 | */ | ||
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 | |||
18 | namespace Dumux { | ||
19 | |||
20 | /*! | ||
21 | * \ingroup Discretization | ||
22 | * \brief Iterators over sub control volumes | ||
23 | * \note usage: for(const auto& scv : scvs(fvGeometry)) | ||
24 | */ | ||
25 | template<class SubControlVolume, class Vector, class FVElementGeometry> | ||
26 | class ScvIterator : public Dune::ForwardIteratorFacade<ScvIterator<SubControlVolume, | ||
27 | Vector, | ||
28 | FVElementGeometry>, | ||
29 | const SubControlVolume> | ||
30 | { | ||
31 | using ThisType = ScvIterator<SubControlVolume, Vector, FVElementGeometry>; | ||
32 | using Iterator = typename Vector::const_iterator; | ||
33 | public: | ||
34 |
5/6✓ Branch 1 taken 144919782 times.
✓ Branch 2 taken 17688390 times.
✓ Branch 5 taken 6600 times.
✗ Branch 6 not taken.
✓ Branch 0 taken 57355904 times.
✓ Branch 3 taken 48356 times.
|
588784424 | ScvIterator(const Iterator& it, const FVElementGeometry& fvGeometry) |
35 | : it_(it), fvGeometryPtr_(&fvGeometry) {} | ||
36 | |||
37 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
|
26 | ScvIterator() : it_(Iterator()), fvGeometryPtr_(nullptr) {} |
38 | |||
39 | //! dereferencing yields a subcontrol volume | ||
40 | 592459178 | const SubControlVolume& dereference() const | |
41 | { | ||
42 |
19/22✓ Branch 3 taken 21257514 times.
✓ Branch 4 taken 1249902 times.
✓ Branch 8 taken 2935627 times.
✓ Branch 9 taken 14822 times.
✓ Branch 5 taken 725084 times.
✓ Branch 1 taken 57343671 times.
✓ Branch 2 taken 146145878 times.
✓ Branch 6 taken 12617993 times.
✓ Branch 7 taken 453545 times.
✓ Branch 10 taken 48356 times.
✓ Branch 11 taken 318400 times.
✓ Branch 12 taken 134400 times.
✓ Branch 13 taken 902096 times.
✓ Branch 14 taken 111930 times.
✓ Branch 15 taken 12166 times.
✓ Branch 18 taken 12381 times.
✓ Branch 19 taken 3471680 times.
✓ Branch 21 taken 901500 times.
✗ Branch 22 not taken.
✓ Branch 16 taken 535690 times.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
|
592459178 | return fvGeometryPtr_->scv(*it_); |
43 | } | ||
44 | |||
45 | 2 | bool equals(const ThisType& other) const | |
46 | { | ||
47 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | return it_ == other.it_; |
48 | } | ||
49 | |||
50 | 372364736 | void increment() | |
51 | { | ||
52 | 372364736 | ++it_; | |
53 | } | ||
54 | |||
55 | private: | ||
56 | Iterator it_; | ||
57 | const FVElementGeometry* fvGeometryPtr_; | ||
58 | }; | ||
59 | |||
60 | /*! | ||
61 | * \ingroup Discretization | ||
62 | * \brief Iterators over sub control volume faces of an fv geometry | ||
63 | * \note usage: for(const auto& scvf : scvfs(fvGeometry)) | ||
64 | */ | ||
65 | template<class SubControlVolumeFace, class Vector, class FVElementGeometry> | ||
66 | class ScvfIterator : public Dune::ForwardIteratorFacade<ScvfIterator<SubControlVolumeFace, | ||
67 | Vector, | ||
68 | FVElementGeometry>, | ||
69 | const SubControlVolumeFace> | ||
70 | { | ||
71 | using ThisType = ScvfIterator<SubControlVolumeFace, Vector, FVElementGeometry>; | ||
72 | using Iterator = typename Vector::const_iterator; | ||
73 | public: | ||
74 |
1/2✓ Branch 1 taken 7000 times.
✗ Branch 2 not taken.
|
283165474 | ScvfIterator(const Iterator& it, const FVElementGeometry& fvGeometry) |
75 | : it_(it), fvGeometryPtr_(&fvGeometry) {} | ||
76 | |||
77 | 16 | ScvfIterator() : it_(Iterator()), fvGeometryPtr_(nullptr) {} | |
78 | |||
79 | //! dereferencing yields a subcontrol volume face | ||
80 | 1429797818 | const SubControlVolumeFace& dereference() const | |
81 | { | ||
82 |
30/31✓ Branch 1 taken 6220394 times.
✓ Branch 2 taken 219248674 times.
✓ Branch 6 taken 15707688 times.
✓ Branch 7 taken 37054007 times.
✓ Branch 10 taken 31438650 times.
✓ Branch 11 taken 10107758 times.
✓ Branch 12 taken 12799051 times.
✓ Branch 13 taken 268389 times.
✓ Branch 14 taken 191494 times.
✓ Branch 15 taken 1045892 times.
✓ Branch 16 taken 1461670 times.
✓ Branch 17 taken 834384 times.
✓ Branch 18 taken 845976 times.
✓ Branch 19 taken 19788 times.
✓ Branch 20 taken 253406 times.
✓ Branch 21 taken 388332 times.
✓ Branch 22 taken 446858 times.
✓ Branch 23 taken 58403 times.
✓ Branch 24 taken 366251 times.
✓ Branch 25 taken 18328 times.
✓ Branch 26 taken 306660 times.
✓ Branch 27 taken 143386 times.
✓ Branch 8 taken 31837778 times.
✓ Branch 9 taken 12946731 times.
✓ Branch 4 taken 31669376 times.
✓ Branch 5 taken 22913857 times.
✓ Branch 3 taken 2801900 times.
✓ Branch 0 taken 22688 times.
✓ Branch 28 taken 27650 times.
✓ Branch 29 taken 70 times.
✗ Branch 30 not taken.
|
1429797818 | return fvGeometryPtr_->scvf(*it_); |
83 | } | ||
84 | |||
85 | 58738279 | bool equals(const ThisType& other) const | |
86 | { | ||
87 |
45/45✓ Branch 0 taken 24695732 times.
✓ Branch 1 taken 8801131 times.
✓ Branch 2 taken 414588985 times.
✓ Branch 3 taken 88347620 times.
✓ Branch 4 taken 116798830 times.
✓ Branch 5 taken 29297866 times.
✓ Branch 6 taken 360845759 times.
✓ Branch 7 taken 79263304 times.
✓ Branch 8 taken 59069819 times.
✓ Branch 9 taken 13562447 times.
✓ Branch 10 taken 121913619 times.
✓ Branch 11 taken 19122438 times.
✓ Branch 12 taken 105106804 times.
✓ Branch 13 taken 16812485 times.
✓ Branch 14 taken 39709832 times.
✓ Branch 15 taken 6872040 times.
✓ Branch 16 taken 24086100 times.
✓ Branch 17 taken 3477843 times.
✓ Branch 18 taken 87421948 times.
✓ Branch 19 taken 11772340 times.
✓ Branch 20 taken 47518936 times.
✓ Branch 21 taken 6396492 times.
✓ Branch 22 taken 7628056 times.
✓ Branch 23 taken 1462709 times.
✓ Branch 24 taken 3407018 times.
✓ Branch 25 taken 1098095 times.
✓ Branch 26 taken 1677038 times.
✓ Branch 27 taken 731577 times.
✓ Branch 28 taken 1271356 times.
✓ Branch 29 taken 1380630 times.
✓ Branch 30 taken 793632 times.
✓ Branch 31 taken 2932019 times.
✓ Branch 33 taken 466744 times.
✓ Branch 34 taken 99880 times.
✓ Branch 35 taken 643678 times.
✓ Branch 36 taken 160912 times.
✓ Branch 37 taken 3575040 times.
✓ Branch 38 taken 893760 times.
✓ Branch 39 taken 2021856 times.
✓ Branch 40 taken 505464 times.
✓ Branch 41 taken 1648992 times.
✓ Branch 42 taken 412248 times.
✓ Branch 43 taken 1024 times.
✓ Branch 44 taken 256 times.
✓ Branch 32 taken 691022 times.
|
1719729662 | return it_ == other.it_; |
88 | } | ||
89 | |||
90 | 1428701790 | void increment() | |
91 | { | ||
92 | 1428701790 | it_++; | |
93 | } | ||
94 | |||
95 | private: | ||
96 | Iterator it_; | ||
97 | const FVElementGeometry* fvGeometryPtr_; | ||
98 | }; | ||
99 | |||
100 | /*! | ||
101 | * \ingroup Discretization | ||
102 | * \brief Iterators over sub control volume faces of an fv geometry and a given sub control volume | ||
103 | * \note usage: for(const auto& scvf : scvfs(fvGeometry, scv)) | ||
104 | */ | ||
105 | template<class SubControlVolumeFace, class Vector, class FVElementGeometry> | ||
106 | class SkippingScvfIterator : public Dune::ForwardIteratorFacade<SkippingScvfIterator<SubControlVolumeFace, | ||
107 | Vector, | ||
108 | FVElementGeometry>, | ||
109 | const SubControlVolumeFace> | ||
110 | { | ||
111 | using ThisType = SkippingScvfIterator<SubControlVolumeFace, Vector, FVElementGeometry>; | ||
112 | using Iterator = typename Vector::const_iterator; | ||
113 | public: | ||
114 | |||
115 | 2 | SkippingScvfIterator() : it_(Iterator()), fvGeometryPtr_(nullptr) {} | |
116 | |||
117 | 111907112 | static ThisType makeBegin(const Vector& vector, const FVElementGeometry& fvGeometry, const std::size_t scvIdx) | |
118 | { | ||
119 | 111907112 | auto begin = vector.begin(); | |
120 | 111907112 | const auto end = vector.end(); | |
121 | |||
122 |
4/6✓ Branch 0 taken 633760004 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 631287804 times.
✓ Branch 4 taken 512715620 times.
✓ Branch 5 taken 109434912 times.
|
647841676 | while (begin != end && fvGeometry.scvf(*begin).insideScvIdx() != scvIdx) |
123 | 521852892 | ++begin; | |
124 | |||
125 | 111907112 | return SkippingScvfIterator(begin, end, fvGeometry, scvIdx); | |
126 | } | ||
127 | |||
128 | 111907112 | static ThisType makeEnd(const Vector& vector, const FVElementGeometry& fvGeometry, const std::size_t scvIdx) | |
129 | { | ||
130 | 111907112 | return SkippingScvfIterator(vector.end(), vector.end(), fvGeometry, scvIdx); | |
131 | } | ||
132 | |||
133 | //! dereferencing yields a subcontrol volume face | ||
134 | 1012235290 | const SubControlVolumeFace& dereference() const | |
135 | { | ||
136 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 990574528 times.
|
1012235290 | return fvGeometryPtr_->scvf(*it_); |
137 | } | ||
138 | |||
139 | 403445728 | bool equals(const ThisType& other) const | |
140 | { | ||
141 |
12/12✓ Branch 0 taken 26459131 times.
✓ Branch 1 taken 676 times.
✓ Branch 2 taken 81046915 times.
✓ Branch 3 taken 26715554 times.
✓ Branch 4 taken 196169816 times.
✓ Branch 5 taken 64304606 times.
✓ Branch 6 taken 1204154 times.
✓ Branch 7 taken 393271 times.
✓ Branch 8 taken 5383225 times.
✓ Branch 9 taken 1768304 times.
✓ Branch 10 taken 57 times.
✓ Branch 11 taken 19 times.
|
403445726 | return it_ == other.it_; |
142 | } | ||
143 | |||
144 | 310224230 | void increment() | |
145 | { | ||
146 | 310224230 | ++it_; | |
147 |
4/4✓ Branch 0 taken 691924241 times.
✓ Branch 1 taken 93182428 times.
✓ Branch 3 taken 474882439 times.
✓ Branch 4 taken 217041802 times.
|
785106669 | while (it_ != itEnd_ && dereference().insideScvIdx() != scvIdx_) |
148 | 474882439 | ++it_; | |
149 | 310224230 | } | |
150 | |||
151 | private: | ||
152 | |||
153 | 223814224 | SkippingScvfIterator(const Iterator& itBegin, const Iterator& itEnd, const FVElementGeometry& fvGeometry, const std::size_t scvIdx) | |
154 | 223814224 | : 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 | ||
165 |