My Project
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 WELL_ORDER_HPP
20#define WELL_ORDER_HPP
21
22#include <initializer_list>
23#include <string>
24#include <unordered_map>
25#include <vector>
26#include <optional>
27
28namespace Opm {
29
30/*
31 The purpose of this small class is to ensure that well and group name always
32 come in the order they are defined in the deck.
33*/
34
35
36using Map = std::unordered_map<std::string, std::size_t>;
37
38class NameOrder {
39public:
40 NameOrder() = default;
41 explicit NameOrder(std::initializer_list<std::string> names);
42 explicit NameOrder(const std::vector<std::string>& names);
43 void add(const std::string& name);
44 std::vector<std::string> sort(std::vector<std::string> names) const;
45 const std::vector<std::string>& names() const;
46 bool has(const std::string& wname) const;
47 std::size_t size() const;
48
49 template<class Serializer>
50 void serializeOp(Serializer& serializer) {
51 serializer(m_index_map);
52 serializer(m_name_list);
53 }
54
55 static NameOrder serializationTestObject();
56
57 const std::string& operator[](std::size_t index) const;
58 bool operator==(const NameOrder& other) const;
59 std::vector<std::string>::const_iterator begin() const;
60 std::vector<std::string>::const_iterator end() const;
61
62private:
63 Map m_index_map;
64 std::vector<std::string> m_name_list;
65};
66
67
69public:
70 GroupOrder() = default;
71 explicit GroupOrder(std::size_t max_groups);
72 void add(const std::string& name);
73 const std::vector<std::string>& names() const;
74 bool has(const std::string& wname) const;
75 std::vector<std::optional<std::string>> restart_groups() const;
76
77 template<class Serializer>
78 void serializeOp(Serializer& serializer) {
79 serializer(m_name_list);
80 serializer(m_max_groups);
81 }
82 static GroupOrder serializationTestObject();
83
84 bool operator==(const GroupOrder& other) const;
85 std::vector<std::string>::const_iterator begin() const;
86 std::vector<std::string>::const_iterator end() const;
87
88private:
89 std::vector<std::string> m_name_list;
90 std::size_t m_max_groups;
91
92};
93
94
95
96
97}
98#endif
Definition: NameOrder.hpp:68
Definition: NameOrder.hpp:38
Class for (de-)serializing.
Definition: Serializer.hpp:75
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29