20 #ifndef OPM_WELL_CONTAINER_HEADER_INCLUDED
21 #define OPM_WELL_CONTAINER_HEADER_INCLUDED
23 #include <initializer_list>
26 #include <unordered_map>
51 WellContainer(std::initializer_list<std::pair<std::string,T>> init_list) {
52 for (
const auto& [name, value] : init_list)
53 this->add(name, value);
57 return this->index_map.empty();
60 std::size_t size()
const {
61 return this->m_data.size();
64 T& add(
const std::string& name, T&& value) {
65 if (index_map.count(name) != 0)
66 throw std::logic_error(
"An object with name: " + name +
" already exists in container");
68 this->index_map.emplace(name, this->m_data.size());
69 this->m_data.push_back(std::forward<T>(value));
70 return this->m_data.back();
73 T& add(
const std::string& name,
const 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(value);
79 return this->m_data.back();
82 bool has(
const std::string& name)
const {
83 return (index_map.count(name) != 0);
91 if (this->index_map == other.index_map)
92 this->m_data = other.m_data;
94 for (
const auto& [name, index] : this->index_map)
95 this->update_if(index, name, other);
103 void copy_welldata(
const WellContainer<T>& other,
const std::string& name) {
104 auto this_index = this->index_map.at(name);
105 auto other_index = other.index_map.at(name);
106 this->m_data[this_index] = other.m_data[other_index];
109 T& operator[](std::size_t index) {
110 return this->m_data.at(index);
113 const T& operator[](std::size_t index)
const {
114 return this->m_data.at(index);
117 T& operator[](
const std::string& name) {
118 auto index = this->index_map.at(name);
119 return this->m_data[index];
122 const T& operator[](
const std::string& name)
const {
123 auto index = this->index_map.at(name);
124 return this->m_data[index];
128 this->m_data.clear();
129 this->index_map.clear();
132 typename std::vector<T>::const_iterator begin()
const {
133 return this->m_data.begin();
136 typename std::vector<T>::const_iterator end()
const {
137 return this->m_data.end();
140 const std::vector<T>& data()
const {
144 std::optional<int> well_index(
const std::string& wname)
const {
145 auto index_iter = this->index_map.find(wname);
146 if (index_iter != this->index_map.end())
147 return index_iter->second;
152 const std::string& well_name(std::size_t well_index)
const {
153 for (
const auto& [wname, windex] : this->index_map) {
154 if (windex == well_index)
157 throw std::logic_error(
"No such well");
160 std::vector<std::string> wells()
const {
161 std::vector<std::string> wlist;
162 for (
const auto& [wname, _] : this->index_map) {
164 wlist.push_back(wname);
171 void update_if(std::size_t index,
const std::string& name,
const WellContainer<T>& other) {
172 auto other_iter = other.index_map.find(name);
173 if (other_iter == other.index_map.end())
176 auto other_index = other_iter->second;
177 this->m_data[index] = other.m_data[other_index];
181 std::vector<T> m_data;
182 std::unordered_map<std::string, std::size_t> index_map;
Definition: WellContainer.hpp:45
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27