Loading...
Searching...
No Matches
RegionSetMatcher.hpp
/*
Copyright 2024 Equinor ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef REGION_SET_MATCHER_HPP
#define REGION_SET_MATCHER_HPP
#include <cstddef>
#include <iterator>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
namespace Opm {
class FIPRegionStatistics;
} // namespace Opm
namespace Opm {
class RegionSetMatcher;
class RegionSetMatchResult
{
public:
class RegionIndexRange
{
public:
class Iterator
{
public:
using iterator_category = std::forward_iterator_tag;
using value_type = int;
using difference_type = int;
using pointer = int*;
using reference = int&;
Iterator& operator++()
{
++this->i_;
return *this;
}
Iterator operator++(int)
{
auto iter = *this;
++(*this);
return iter;
}
reference operator*() { return this->i_; }
pointer operator->() { return &this->i_; }
bool operator==(Iterator that) const
{
return this->i_ == that.i_;
}
bool operator!=(Iterator that) const
{
return ! (*this == that);
}
friend class RegionIndexRange;
private:
explicit Iterator(int i) : i_{i} {}
int i_;
};
Iterator begin() const { return Iterator{this->begin_}; }
Iterator end() const { return Iterator{this->end_}; }
bool empty() const { return this->end_ <= this->begin_; }
std::string_view regionSet() const { return this->region_; }
friend class RegionSetMatchResult;
private:
int begin_{};
int end_{};
std::string_view region_{};
RegionIndexRange() = default;
RegionIndexRange(int beginID, int endID, std::string_view region)
: begin_ { beginID }
, end_ { endID }
, region_ { region }
{}
};
bool empty() const
{
return this->regionIDRange_.empty();
}
bool isScalar() const
{
return (this->regionIDRange_.size() == std::vector<int>::size_type{2})
&& (this->regionIDRange_.back() == this->regionIDRange_.front() + 1);
}
std::vector<std::string_view> regionSets() const;
std::size_t numRegionSets() const
{
return this->regionSets_.size();
}
RegionIndexRange regions(std::string_view regSet) const;
RegionIndexRange regions(const std::size_t regSet) const;
friend class RegionSetMatcher;
private:
std::vector<std::string> regionSets_{};
std::vector<std::vector<std::string>::size_type> regionSetIndex_{};
std::vector<int> regionIDRange_{};
void establishNameLookupIndex();
void addRegionIndices(const std::string& regSet,
int beginRegID,
int endRegID);
};
class RegionSetMatcher
{
public:
class SetDescriptor
{
public:
SetDescriptor& regionID(const int region);
SetDescriptor& regionID(std::string_view region);
const std::optional<int>& regionID() const
{
return this->regionId_;
}
SetDescriptor& vectorName(std::string_view vector);
const std::optional<std::string>& regionSet() const
{
return this->regionSet_;
}
private:
std::optional<std::string> regionSet_{};
std::optional<int> regionId_{};
};
RegionSetMatcher() = delete;
explicit RegionSetMatcher(const FIPRegionStatistics& fipRegStats);
RegionSetMatcher(const RegionSetMatcher& rhs) = delete;
RegionSetMatcher(RegionSetMatcher&& rhs);
RegionSetMatcher& operator=(const RegionSetMatcher& rhs) = delete;
RegionSetMatcher& operator=(RegionSetMatcher&& rhs);
~RegionSetMatcher();
RegionSetMatchResult findRegions(const SetDescriptor& regSet) const;
private:
class Impl;
std::unique_ptr<Impl> pImpl_{};
};
} // namespace Opm
#endif // REGION_SET_MATCHER_HPP
Opm::FIPRegionStatistics
Basic descriptive statistics about a model's fluid-in-place regions.
Definition FIPRegionStatistics.hpp:40
Opm::RegionSetMatchResult::RegionIndexRange::Iterator
Simple forward iterator over a region index range.
Definition RegionSetMatcher.hpp:52
Opm::RegionSetMatchResult::RegionIndexRange::Iterator::reference
int & reference
Iterator's reference type (return type from operator*())
Definition RegionSetMatcher.hpp:67
Opm::RegionSetMatchResult::RegionIndexRange::Iterator::regions
RegionIndexRange regions(std::string_view regSet) const
Inequality predicate.
Opm::RegionSetMatchResult::RegionIndexRange::Iterator::operator++
Iterator operator++(int)
Post-increment operator.
Definition RegionSetMatcher.hpp:82
Opm::RegionSetMatchResult::RegionIndexRange::Iterator::operator*
reference operator*()
Dereference operator.
Definition RegionSetMatcher.hpp:94
Opm::RegionSetMatchResult::RegionIndexRange::Iterator::iterator_category
std::forward_iterator_tag iterator_category
Iterator's category (forward iterator)
Definition RegionSetMatcher.hpp:55
Opm::RegionSetMatchResult::RegionIndexRange::Iterator::value_type
int value_type
Iterator's value type.
Definition RegionSetMatcher.hpp:58
Opm::RegionSetMatchResult::RegionIndexRange::Iterator::difference_type
int difference_type
Iterator's difference type.
Definition RegionSetMatcher.hpp:61
Opm::RegionSetMatchResult::RegionIndexRange::Iterator::operator->
pointer operator->()
Indirection operator.
Definition RegionSetMatcher.hpp:99
Opm::RegionSetMatchResult::RegionIndexRange::Iterator::pointer
int * pointer
Iterator's pointer type (return type from operator->())
Definition RegionSetMatcher.hpp:64
Opm::RegionSetMatchResult::RegionIndexRange::Iterator::regions
RegionIndexRange regions(const std::size_t regSet) const
Retrieve result set's region indices for a single region set.
Opm::RegionSetMatchResult::RegionIndexRange::Iterator::operator++
Iterator & operator++()
Pre-increment operator.
Definition RegionSetMatcher.hpp:72
Opm::RegionSetMatchResult::RegionIndexRange::Iterator::operator==
bool operator==(Iterator that) const
Equality predicate.
Definition RegionSetMatcher.hpp:106
Opm::RegionSetMatchResult::RegionIndexRange
Region Index Range for Single Region Set.
Definition RegionSetMatcher.hpp:48
Opm::RegionSetMatchResult
Result Set From RegionSetMatcher's Matching Process.
Definition RegionSetMatcher.hpp:44
Opm::RegionSetMatchResult::RegionSetMatcher
RegionSetMatcher()=delete
Default constructor.
Opm::RegionSetMatchResult::~RegionSetMatcher
~RegionSetMatcher()
Destructor.
Opm::RegionSetMatchResult::findRegions
RegionSetMatchResult findRegions(const SetDescriptor &regSet) const
Determine collection of region sets and corresponding region indices matching an input set descriptio...
Opm::RegionSetMatchResult::RegionSetMatcher
RegionSetMatcher(const FIPRegionStatistics &fipRegStats)
Constructor.
Opm::RegionSetMatchResult::operator=
RegionSetMatcher & operator=(RegionSetMatcher &&rhs)
Move-assignment operator.
Opm::RegionSetMatchResult::RegionSetMatcher
RegionSetMatcher(RegionSetMatcher &&rhs)
Move constructor.
Opm::RegionSetMatchResult::RegionSetMatcher
RegionSetMatcher(const RegionSetMatcher &rhs)=delete
Copy constructor.
Opm::RegionSetMatchResult::operator=
RegionSetMatcher & operator=(const RegionSetMatcher &rhs)=delete
Assignment operator.
Opm
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30