My Project
Loading...
Searching...
No Matches
RegionSetMatcher.hpp
1/*
2 Copyright 2024 Equinor ASA.
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM 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 OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef REGION_SET_MATCHER_HPP
21#define REGION_SET_MATCHER_HPP
22
23#include <cstddef>
24#include <iterator>
25#include <memory>
26#include <optional>
27#include <string>
28#include <string_view>
29#include <utility>
30#include <vector>
31
33
34namespace Opm {
35 class FIPRegionStatistics;
36} // namespace Opm
37
38namespace Opm {
39
40class RegionSetMatcher;
41
44{
45public:
48 {
49 public:
52 {
53 public:
55 using iterator_category = std::forward_iterator_tag;
56
58 using value_type = int;
59
61 using difference_type = int;
62
64 using pointer = int*;
65
67 using reference = int&;
68
73 {
74 ++this->i_;
75
76 return *this;
77 }
78
83 {
84 auto iter = *this;
85
86 ++(*this);
87
88 return iter;
89 }
90
94 reference operator*() { return this->i_; }
95
99 pointer operator->() { return &this->i_; }
100
106 bool operator==(Iterator that) const
107 {
108 return this->i_ == that.i_;
109 }
110
116 bool operator!=(Iterator that) const
117 {
118 return ! (*this == that);
119 }
120
121 friend class RegionIndexRange;
122
123 private:
129 Iterator(int i) : i_{i} {}
130
132 int i_;
133 };
134
136 Iterator begin() const { return { this->begin_ }; }
137
139 Iterator end() const { return { this->end_ }; }
140
142 bool empty() const { return this->end_ <= this->begin_; }
143
145 std::string_view regionSet() const { return this->region_; }
146
147 friend class RegionSetMatchResult;
148
149 private:
151 int begin_{};
152
154 int end_{};
155
157 std::string_view region_{};
158
164 RegionIndexRange() = default;
165
176 RegionIndexRange(int beginID, int endID, std::string_view region)
177 : begin_ { beginID }
178 , end_ { endID }
179 , region_ { region }
180 {}
181 };
182
186 bool empty() const
187 {
188 return this->regionIDRange_.empty();
189 }
190
198 bool isScalar() const
199 {
200 return (this->regionIDRange_.size() == std::vector<int>::size_type{2})
201 && (this->regionIDRange_.back() == this->regionIDRange_.front() + 1);
202 }
203
207 std::vector<std::string_view> regionSets() const;
208
212 std::size_t numRegionSets() const
213 {
214 return this->regionSets_.size();
215 }
216
226 RegionIndexRange regions(std::string_view regSet) const;
227
236 RegionIndexRange regions(const std::size_t regSet) const;
237
238 friend class RegionSetMatcher;
239
240private:
242 std::vector<std::string> regionSets_{};
243
248 std::vector<std::vector<std::string>::size_type> regionSetIndex_{};
249
251 std::vector<int> regionIDRange_{};
252
256 void establishNameLookupIndex();
257
269 void addRegionIndices(const std::string& regSet,
270 int beginRegID,
271 int endRegID);
272};
273
297class RegionSetMatcher
298{
299public:
303 class SetDescriptor
304 {
305 public:
313 SetDescriptor& regionID(const int region);
314
326 SetDescriptor& regionID(std::string_view region);
327
331 const std::optional<int>& regionID() const
332 {
333 return this->regionId_;
334 }
335
341 SetDescriptor& vectorName(std::string_view vector);
342
347 const std::optional<std::string>& regionSet() const
348 {
349 return this->regionSet_;
350 }
351
352 private:
355 std::optional<std::string> regionSet_{};
356
359 std::optional<int> regionId_{};
360 };
361
366
370 explicit RegionSetMatcher(const FIPRegionStatistics& fipRegStats);
371
377 RegionSetMatcher(const RegionSetMatcher& rhs) = delete;
378
382 RegionSetMatcher(RegionSetMatcher&& rhs);
383
391 RegionSetMatcher& operator=(const RegionSetMatcher& rhs) = delete;
392
398 RegionSetMatcher& operator=(RegionSetMatcher&& rhs);
399
404
424 RegionSetMatchResult findRegions(const SetDescriptor& regSet) const;
425
426private:
428 class Impl;
429
431 std::unique_ptr<Impl> pImpl_{};
432};
433
434} // namespace Opm
435
436#endif // REGION_SET_MATCHER_HPP
Basic descriptive statistics about a model's fluid-in-place regions.
Definition FIPRegionStatistics.hpp:40
Simple forward iterator over a region index range.
Definition RegionSetMatcher.hpp:52
int & reference
Iterator's reference type (return type from operator*())
Definition RegionSetMatcher.hpp:67
RegionIndexRange regions(std::string_view regSet) const
Inequality predicate.
Iterator operator++(int)
Post-increment operator.
Definition RegionSetMatcher.hpp:82
reference operator*()
Dereference operator.
Definition RegionSetMatcher.hpp:94
std::forward_iterator_tag iterator_category
Iterator's category (forward iterator)
Definition RegionSetMatcher.hpp:55
int value_type
Iterator's value type.
Definition RegionSetMatcher.hpp:58
int difference_type
Iterator's difference type.
Definition RegionSetMatcher.hpp:61
pointer operator->()
Indirection operator.
Definition RegionSetMatcher.hpp:99
int * pointer
Iterator's pointer type (return type from operator->())
Definition RegionSetMatcher.hpp:64
RegionIndexRange regions(const std::size_t regSet) const
Retrieve result set's region indices for a single region set.
Iterator & operator++()
Pre-increment operator.
Definition RegionSetMatcher.hpp:72
bool operator==(Iterator that) const
Equality predicate.
Definition RegionSetMatcher.hpp:106
Region Index Range for Single Region Set.
Definition RegionSetMatcher.hpp:48
Result Set From RegionSetMatcher's Matching Process.
Definition RegionSetMatcher.hpp:44
RegionSetMatcher()=delete
Default constructor.
~RegionSetMatcher()
Destructor.
RegionSetMatchResult findRegions(const SetDescriptor &regSet) const
Determine collection of region sets and corresponding region indices matching an input set descriptio...
RegionSetMatcher(const FIPRegionStatistics &fipRegStats)
Constructor.
RegionSetMatcher & operator=(RegionSetMatcher &&rhs)
Move-assignment operator.
RegionSetMatcher(RegionSetMatcher &&rhs)
Move constructor.
RegionSetMatcher(const RegionSetMatcher &rhs)=delete
Copy constructor.
RegionSetMatcher & operator=(const RegionSetMatcher &rhs)=delete
Assignment operator.
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30