20#ifndef OPM_WELL_CONTAINER_HEADER_INCLUDED
21#define OPM_WELL_CONTAINER_HEADER_INCLUDED
23#include <initializer_list>
27#include <unordered_map>
50 WellContainer(std::initializer_list<std::pair<std::string,T>> init_list) {
51 for (
const auto& [name, value] : init_list)
52 this->
add(name, value);
59 result.m_data = {
data};
60 result.index_map = {{
"test1", 1}, {
"test2", 4}};
66 return this->index_map.empty();
70 return this->m_data.size();
73 T&
add(
const std::string& name, T&& value) {
74 if (index_map.count(name) != 0)
75 throw std::logic_error(
"An object with name: " + name +
" already exists in container");
77 this->index_map.emplace(name, this->m_data.size());
78 this->m_data.push_back(std::forward<T>(value));
79 return this->m_data.back();
82 T&
add(
const std::string& name,
const T& value) {
83 if (index_map.count(name) != 0)
84 throw std::logic_error(
"An object with name: " + name +
" already exists in container");
86 this->index_map.emplace(name, this->m_data.size());
87 this->m_data.push_back(value);
88 return this->m_data.back();
91 bool has(
const std::string& name)
const {
92 return (index_map.count(name) != 0);
100 if (this->index_map == other.index_map)
101 this->m_data = other.m_data;
103 for (
const auto& [name, index] : this->index_map)
104 this->update_if(index, name, other);
113 auto this_index = this->index_map.at(name);
114 auto other_index = other.index_map.at(name);
115 this->m_data[this_index] = other.m_data[other_index];
119 return this->m_data.at(index);
123 return this->m_data.at(index);
127 auto index = this->index_map.at(name);
128 return this->m_data[index];
132 auto index = this->index_map.at(name);
133 return this->m_data[index];
137 this->m_data.clear();
138 this->index_map.clear();
141 typename std::vector<T>::const_iterator
begin()
const {
142 return this->m_data.begin();
145 typename std::vector<T>::const_iterator
end()
const {
146 return this->m_data.end();
149 const std::vector<T>&
data()
const {
153 std::optional<int>
well_index(
const std::string& wname)
const {
154 auto index_iter = this->index_map.find(wname);
155 if (index_iter != this->index_map.end())
156 return index_iter->second;
162 for (
const auto& [wname, windex] : this->index_map) {
166 throw std::logic_error(
"No such well");
169 std::vector<std::string>
wells()
const {
170 std::vector<std::string> wlist;
171 for (
const auto& [wname, _] : this->index_map) {
173 wlist.push_back(wname);
178 template<
class Serializer>
182 serializer(index_map);
187 return this->m_data == rhs.m_data &&
188 this->index_map == rhs.index_map;
192 void update_if(std::size_t index,
const std::string& name,
const WellContainer<T>& other) {
193 auto other_iter = other.index_map.find(name);
194 if (other_iter == other.index_map.end())
197 auto other_index = other_iter->second;
198 this->m_data[index] = other.m_data[other_index];
202 std::vector<T> m_data;
203 std::unordered_map<std::string, std::size_t> index_map;
Definition: WellContainer.hpp:46
std::vector< std::string > wells() const
Definition: WellContainer.hpp:169
T & operator[](const std::string &name)
Definition: WellContainer.hpp:126
T & add(const std::string &name, const T &value)
Definition: WellContainer.hpp:82
bool empty() const
Definition: WellContainer.hpp:65
static WellContainer serializationTestObject(const T &data)
Definition: WellContainer.hpp:55
void copy_welldata(const WellContainer< T > &other)
Definition: WellContainer.hpp:99
const std::vector< T > & data() const
Definition: WellContainer.hpp:149
void clear()
Definition: WellContainer.hpp:136
bool has(const std::string &name) const
Definition: WellContainer.hpp:91
void copy_welldata(const WellContainer< T > &other, const std::string &name)
Definition: WellContainer.hpp:112
const T & operator[](const std::string &name) const
Definition: WellContainer.hpp:131
T & add(const std::string &name, T &&value)
Definition: WellContainer.hpp:73
std::vector< T >::const_iterator end() const
Definition: WellContainer.hpp:145
bool operator==(const WellContainer< T > &rhs) const
Definition: WellContainer.hpp:185
std::size_t size() const
Definition: WellContainer.hpp:69
const T & operator[](std::size_t index) const
Definition: WellContainer.hpp:122
const std::string & well_name(std::size_t well_index) const
Definition: WellContainer.hpp:161
T & operator[](std::size_t index)
Definition: WellContainer.hpp:118
WellContainer(std::initializer_list< std::pair< std::string, T > > init_list)
Definition: WellContainer.hpp:50
void serializeOp(Serializer &serializer)
Definition: WellContainer.hpp:179
std::optional< int > well_index(const std::string &wname) const
Definition: WellContainer.hpp:153
std::vector< T >::const_iterator begin() const
Definition: WellContainer.hpp:141
Definition: blackoilboundaryratevector.hh:37