63 static const uint64_t event_mask = ScheduleEvents::WELL_STATUS_CHANGE + ScheduleEvents::PRODUCTION_UPDATE + ScheduleEvents::INJECTION_UPDATE;
65 static const int Water = BlackoilPhases::Aqua;
66 static const int Oil = BlackoilPhases::Liquid;
67 static const int Gas = BlackoilPhases::Vapour;
78 std::size_t size()
const {
79 return this->wells_.size();
82 std::vector<std::string> wells()
const {
83 return this->wells_.wells();
99 void init(
const std::vector<double>& cellPressures,
100 const Schedule& schedule,
101 const std::vector<Well>& wells_ecl,
102 const std::vector<std::reference_wrapper<ParallelWellInfo>>& parallel_well_info,
103 const int report_step,
105 const std::vector<std::vector<PerforationData>>& well_perf_data,
106 const SummaryState& summary_state);
108 void resize(
const std::vector<Well>& wells_ecl,
109 const std::vector<std::reference_wrapper<ParallelWellInfo>>& parallel_well_info,
110 const Schedule& schedule,
111 const bool handle_ms_well,
112 const std::size_t numCells,
113 const std::vector<std::vector<PerforationData>>& well_perf_data,
114 const SummaryState& summary_state);
116 void setCurrentWellRates(
const std::string& wellName,
const std::vector<double>& new_rates ) {
117 auto& [owner, rates] = this->well_rates.at(wellName);
122 const std::vector<double>& currentWellRates(
const std::string& wellName)
const;
124 bool hasWellRates(
const std::string& wellName)
const {
125 return this->well_rates.find(wellName) != this->well_rates.end();
128 void clearWellRates()
130 this->well_rates.clear();
133 void gatherVectorsOnRoot(
const std::vector< data::Connection >& from_connections,
134 std::vector< data::Connection >& to_connections,
135 const Parallel::Communication& comm)
const;
138 report(
const int* globalCellIdxMap,
139 const std::function<
bool(
const int)>& wasDynamicallyClosed)
const;
141 void reportConnections(std::vector<data::Connection>& connections,
const PhaseUsage &pu,
142 std::size_t well_index,
143 const int* globalCellIdxMap)
const;
149 static void calculateSegmentRates(
const std::vector<std::vector<int>>& segment_inlets,
const std::vector<std::vector<int>>&segment_perforations,
150 const std::vector<double>& perforation_rates,
const int np,
const int segment, std::vector<double>& segment_rates);
153 void communicateGroupRates(
const Parallel::Communication& comm);
155 void updateGlobalIsGrup(
const Parallel::Communication& comm);
157 bool isInjectionGrup(
const std::string& name)
const {
158 return this->global_well_info.value().in_injecting_group(name);
161 bool isProductionGrup(
const std::string& name)
const {
162 return this->global_well_info.value().in_producing_group(name);
165 double getALQ(
const std::string& name)
const
167 return this->alq_state.get(name);
170 void setALQ(
const std::string& name,
double value)
172 this->alq_state.set(name, value);
175 int gliftGetDebugCounter() {
176 return this->alq_state.get_debug_counter();
179 void gliftSetDebugCounter(
int value) {
180 return this->alq_state.set_debug_counter(value);
183 int gliftUpdateDebugCounter() {
184 return this->alq_state.update_debug_counter();
187 bool gliftCheckAlqOscillation(
const std::string &name)
const {
188 return this->alq_state.oscillation(name);
191 int gliftGetAlqDecreaseCount(
const std::string &name) {
192 return this->alq_state.get_decrement_count(name);
195 int gliftGetAlqIncreaseCount(
const std::string &name) {
196 return this->alq_state.get_increment_count(name);
199 void gliftUpdateAlqIncreaseCount(
const std::string &name,
bool increase) {
200 this->alq_state.update_count(name, increase);
203 void gliftTimeStepInit() {
204 this->alq_state.reset_count();
211 void updateWellsDefaultALQ(
const std::vector<Well>& wells_ecl,
const SummaryState& summary_state);
213 int wellNameToGlobalIdx(
const std::string &name) {
214 return this->global_well_info.value().well_index(name);
217 std::string globalIdxToWellName(
const int index) {
218 return this->global_well_info.value().well_name(index);
221 bool wellIsOwned(std::size_t well_index,
222 const std::string& wellName)
const;
224 bool wellIsOwned(
const std::string& wellName)
const;
226 void updateStatus(
int well_index, WellStatus status);
228 void openWell(
int well_index);
229 void shutWell(
int well_index);
230 void stopWell(
int well_index);
235 return this->phase_usage_.num_phases;
239 return this->phase_usage_;
243 std::vector<double>&
wellRates(std::size_t well_index) {
return this->wells_[well_index].surface_rates; }
244 const std::vector<double>&
wellRates(std::size_t well_index)
const {
return this->wells_[well_index].surface_rates; }
246 const std::string& name(std::size_t well_index)
const {
247 return this->wells_.well_name(well_index);
250 std::optional<std::size_t> index(
const std::string& well_name)
const {
251 return this->wells_.well_index(well_name);
254 const SingleWellState& operator[](std::size_t well_index)
const {
255 return this->wells_[well_index];
258 const SingleWellState& operator[](
const std::string& well_name)
const {
259 return this->wells_[well_name];
262 SingleWellState& operator[](std::size_t well_index) {
263 return this->wells_[well_index];
266 SingleWellState& operator[](
const std::string& well_name) {
267 return this->wells_[well_name];
270 const SingleWellState& well(std::size_t well_index)
const {
271 return this->operator[](well_index);
274 const SingleWellState& well(
const std::string& well_name)
const {
275 return this->operator[](well_name);
278 SingleWellState& well(std::size_t well_index) {
279 return this->operator[](well_index);
282 SingleWellState& well(
const std::string& well_name) {
283 return this->operator[](well_name);
286 bool has(
const std::string& well_name)
const {
287 return this->wells_.has(well_name);
290 bool operator==(
const WellState&)
const;
292 template<
class Serializer>
293 void serializeOp(Serializer& serializer)
295 serializer(alq_state);
296 serializer(well_rates);
297 if (serializer.isSerializing()) {
298 serializer(wells_.size());
300 std::size_t size = 0;
302 if (size != wells_.size()) {
303 OPM_THROW(std::runtime_error,
"Error deserializing WellState: size mismatch");
306 for (
auto& w : wells_) {
312 PhaseUsage phase_usage_;
317 WellContainer<SingleWellState> wells_;
325 std::optional<GlobalWellInfo> global_well_info;
331 std::map<std::string, std::pair<bool, std::vector<double>>> well_rates;
334 reportSegmentResults(
const int well_id,
336 const int seg_no)
const;
344 void base_init(
const std::vector<double>& cellPressures,
345 const std::vector<Well>& wells_ecl,
346 const std::vector<std::reference_wrapper<ParallelWellInfo>>& parallel_well_info,
347 const std::vector<std::vector<PerforationData>>& well_perf_data,
348 const SummaryState& summary_state);
350 void initSingleWell(
const std::vector<double>& cellPressures,
352 const std::vector<PerforationData>& well_perf_data,
353 const ParallelWellInfo& well_info,
354 const SummaryState& summary_state);
356 void initSingleProducer(
const Well& well,
357 const ParallelWellInfo& well_info,
358 double pressure_first_connection,
359 const std::vector<PerforationData>& well_perf_data,
360 const SummaryState& summary_state);
362 void initSingleInjector(
const Well& well,
363 const ParallelWellInfo& well_info,
364 double pressure_first_connection,
365 const std::vector<PerforationData>& well_perf_data,
366 const SummaryState& summary_state);