My Project
Loading...
Searching...
No Matches
NameOrder.hpp
1/*
2 Copyright 2021 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#ifndef NAME_ORDER_HPP
20#define NAME_ORDER_HPP
21
22#include <cstddef>
23#include <initializer_list>
24#include <optional>
25#include <string>
26#include <unordered_map>
27#include <vector>
28
29namespace Opm {
30
31// The purpose of this small class is to ensure that well and group name
32// always come in the order they are defined in the deck.
33
35{
36public:
37 NameOrder() = default;
38 explicit NameOrder(std::initializer_list<std::string> names);
39 explicit NameOrder(const std::vector<std::string>& names);
40
41 void add(const std::string& name);
42 std::vector<std::string> sort(std::vector<std::string> names) const;
43 const std::vector<std::string>& names() const;
44 bool has(const std::string& wname) const;
45
46 template <class Serializer>
47 void serializeOp(Serializer& serializer)
48 {
49 serializer(m_index_map);
50 serializer(m_name_list);
51 }
52
53 static NameOrder serializationTestObject();
54
55 const std::string& operator[](std::size_t index) const;
56 bool operator==(const NameOrder& other) const;
57
58 auto begin() const { return this->m_name_list.begin(); }
59 auto end() const { return this->m_name_list.end(); }
60 auto size() const { return this->m_name_list.size(); }
61
62private:
63 std::unordered_map<std::string, std::size_t> m_index_map;
64 std::vector<std::string> m_name_list;
65};
66
69{
70public:
74 GroupOrder() = default;
75
80 explicit GroupOrder(std::size_t max_groups);
81
84
88 void add(const std::string& name);
89
94 const std::vector<std::string>& names() const
95 {
96 return this->name_list_;
97 }
98
106 std::vector<std::string> names(const std::string& pattern) const;
107
113 bool has(const std::string& gname) const;
114
120 std::vector<std::optional<std::string>> restart_groups() const;
121
128 bool operator==(const GroupOrder& other) const;
129
133 auto begin() const { return this->name_list_.begin(); }
134
136 auto end() const { return this->name_list_.end(); }
137
143 template <class Serializer>
144 void serializeOp(Serializer& serializer)
145 {
146 serializer(this->name_list_);
147 serializer(this->max_groups_);
148 }
149
150private:
152 std::size_t max_groups_{};
153
155 std::vector<std::string> name_list_{};
156};
157
158} // namespace Opm
159
160#endif // NAME_ORDER_HPP
Collection of group names with built-in ordering.
Definition NameOrder.hpp:69
GroupOrder()=default
Default constructor.
auto begin() const
Start of group name sequence.
Definition NameOrder.hpp:133
static GroupOrder serializationTestObject()
Create a serialisation test object.
Definition NameOrder.cpp:109
void add(const std::string &name)
Add a group name to ordered collection.
Definition NameOrder.cpp:119
bool has(const std::string &gname) const
Group name existence predicate.
Definition NameOrder.cpp:128
void serializeOp(Serializer &serializer)
Convert between byte array and object representation.
Definition NameOrder.hpp:144
auto end() const
End of group name sequence.
Definition NameOrder.hpp:136
bool operator==(const GroupOrder &other) const
Equality predicate.
Definition NameOrder.cpp:174
const std::vector< std::string > & names() const
Retrieve current list of group names.
Definition NameOrder.hpp:94
std::vector< std::optional< std::string > > restart_groups() const
Retrieve sequence of group names ordered appropriately for restart file output.
Definition NameOrder.cpp:162
Definition NameOrder.hpp:35
Class for (de-)serializing.
Definition Serializer.hpp:94
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30