21#ifndef OPM_WELLSTATEFULLYIMPLICITBLACKOIL_HEADER_INCLUDED
22#define OPM_WELLSTATEFULLYIMPLICITBLACKOIL_HEADER_INCLUDED
24#include <dune/common/version.hh>
25#include <dune/common/parallel/mpihelper.hh>
27#include <opm/common/ErrorMacros.hpp>
29#include <opm/input/eclipse/Schedule/Events.hpp>
31#include <opm/output/data/Wells.hpp>
55template<
class Scalar>
class ParallelWellInfo;
56template<
class Scalar>
struct PerforationData;
57template<
class Scalar>
class ConnFracStatistics;
67 static const std::uint64_t
event_mask = ScheduleEvents::WELL_STATUS_CHANGE
68 | ScheduleEvents::PRODUCTION_UPDATE
69 | ScheduleEvents::INJECTION_UPDATE;
87 return this->wells_.size();
90 std::vector<std::string>
wells()
const
92 return this->wells_.wells();
105 void init(
const std::vector<Scalar>& cellPressures,
106 const std::vector<Scalar>& cellTemperatures,
107 const Schedule& schedule,
108 const std::vector<Well>& wells_ecl,
110 const int report_step,
113 const SummaryState& summary_state,
114 const bool enableDistributedWells);
116 void resize(
const std::vector<Well>& wells_ecl,
118 const Schedule& schedule,
119 const bool handle_ms_well,
120 const std::size_t numCells,
122 const SummaryState& summary_state,
123 const bool enable_distributed_wells);
126 const std::vector<Scalar>& new_rates)
128 auto& [owner, rates] = this->well_rates.at(wellName);
137 return this->well_rates.find(wellName) != this->well_rates.end();
142 this->well_rates.clear();
146 std::vector<data::Connection>& to_connections,
151 const std::function<
bool(
const int)>& wasDynamicallyClosed)
const;
155 std::size_t well_index,
156 const int* globalCellIdxMap)
const;
163 const std::vector<std::vector<int>>& segment_inlets,
164 const std::vector<std::vector<int>>& segment_perforations,
165 const std::vector<Scalar>& perforation_rates,
168 std::vector<Scalar>& segment_rates);
179 return this->global_well_info.value().in_injecting_group(
name);
184 return this->global_well_info.value().in_producing_group(
name);
189 return this->global_well_info.value().is_open(
name);
194 return this->global_well_info.value().efficiency_scaling_factor(
name);
202 const int report_step,
203 const SummaryState& summary_state);
207 for (
size_t i = 0; i < this->
size(); ++i) {
208 this->wells_[i].alq_state.reset_count();
215 return this->global_well_info.value().well_index(
name);
220 return this->global_well_info.value().well_name(
index);
224 const std::string& wellName)
const;
229 return this->global_well_info.value().isRank0();
246 return this->phase_usage_;
251 {
return this->wells_[well_index].surface_rates; }
252 const std::vector<Scalar>&
wellRates(std::size_t well_index)
const
253 {
return this->wells_[well_index].surface_rates; }
255 const std::string&
name(std::size_t well_index)
const
257 return this->wells_.well_name(well_index);
260 std::optional<std::size_t>
index(
const std::string& well_name)
const
262 return this->wells_.well_index(well_name);
267 return this->wells_[well_index];
272 return this->wells_[well_name];
277 return this->wells_[well_index];
282 return this->wells_[well_name];
305 bool has(
const std::string& well_name)
const
307 return this->wells_.has(well_name);
312 template<
class Serializer>
315 serializer(well_rates);
316 if (serializer.isSerializing()) {
317 serializer(wells_.size());
319 std::size_t
size = 0;
321 if (
size != wells_.size()) {
322 OPM_THROW(std::runtime_error,
"Error deserializing WellState: size mismatch");
325 for (
auto& w : wells_) {
328 serializer(permanently_inactive_well_names_);
332 return std::find(this->permanently_inactive_well_names_.begin(), this->permanently_inactive_well_names_.end(), wname) != this->permanently_inactive_well_names_.end();
336 bool enableDistributedWells_ =
false;
351 std::optional<GlobalWellInfo<Scalar>> global_well_info;
356 std::map<std::string, std::pair<bool, std::vector<Scalar>>> well_rates;
359 std::vector<std::string> permanently_inactive_well_names_;
362 reportSegmentResults(
const int well_id,
364 const int seg_no)
const;
372 void base_init(
const std::vector<Scalar>& cellPressures,
373 const std::vector<Scalar>& cellTemperatures,
374 const std::vector<Well>& wells_ecl,
377 const SummaryState& summary_state);
379 void initSingleWell(
const std::vector<Scalar>& cellPressures,
380 const std::vector<Scalar>& cellTemperatures,
384 const SummaryState& summary_state);
386 void initSingleProducer(
const Well&
well,
388 Scalar pressure_first_connection,
390 const SummaryState& summary_state);
392 void initSingleInjector(
const Well&
well,
394 Scalar pressure_first_connection,
395 Scalar temperature_first_connection,
397 const SummaryState& summary_state);
400 const std::vector<std::vector<int>>& segment_inlets,
401 const std::vector<std::vector<int>>& segment_perforations,
402 const std::vector<Scalar>& perforation_rates,
405 std::vector<Scalar>& segment_rates);
407 void reportConnectionFactors(
const std::size_t well_index,
408 std::vector<data::Connection>& connections)
const;
410 void reportConnectionPressuresAndRates(
const std::size_t well_index,
412 std::vector<data::Connection>& connections)
const;
414 void reportConnectionFilterCake(
const std::size_t well_index,
415 std::vector<data::Connection>& connections)
const;
418 std::vector<data::Connection>& connections)
const;
@ Liquid
Definition: BlackoilPhases.hpp:42
@ Aqua
Definition: BlackoilPhases.hpp:42
@ Vapour
Definition: BlackoilPhases.hpp:42
Definition: ConnFracStatistics.hpp:37
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:195
Definition: SingleWellState.hpp:42
Definition: WellContainer.hpp:46
Definition: WellState.hpp:65
data::Wells report(const int *globalCellIdxMap, const std::function< bool(const int)> &wasDynamicallyClosed) const
std::vector< std::string > wells() const
Definition: WellState.hpp:90
bool isInjectionGrup(const std::string &name) const
Definition: WellState.hpp:177
std::string globalIdxToWellName(const int index)
Definition: WellState.hpp:218
bool is_permanently_inactive_well(const std::string &wname) const
Definition: WellState.hpp:331
void initWellStateMSWell(const std::vector< Well > &wells_ecl, const WellState *prev_well_state)
init the MS well related.
static const std::uint64_t event_mask
Definition: WellState.hpp:67
const SingleWellState< Scalar > & well(const std::string &well_name) const
Definition: WellState.hpp:290
SingleWellState< Scalar > & well(std::size_t well_index)
Definition: WellState.hpp:295
const SingleWellState< Scalar > & well(std::size_t well_index) const
Definition: WellState.hpp:285
const SingleWellState< Scalar > & operator[](std::size_t well_index) const
Definition: WellState.hpp:265
void reportConnections(std::vector< data::Connection > &connections, const PhaseUsage &pu, std::size_t well_index, const int *globalCellIdxMap) const
const std::vector< Scalar > & currentWellRates(const std::string &wellName) const
bool operator==(const WellState &) const
const ParallelWellInfo< Scalar > & parallelWellInfo(std::size_t well_index) const
SingleWellState< Scalar > & well(const std::string &well_name)
Definition: WellState.hpp:300
bool wellIsOwned(std::size_t well_index, const std::string &wellName) const
int numPhases() const
The number of phases present.
Definition: WellState.hpp:239
bool isOpen(const std::string &name) const
Definition: WellState.hpp:187
void serializeOp(Serializer &serializer)
Definition: WellState.hpp:313
void openWell(int well_index)
void resize(const std::vector< Well > &wells_ecl, const std::vector< std::reference_wrapper< ParallelWellInfo< Scalar > > > ¶llel_well_info, const Schedule &schedule, const bool handle_ms_well, const std::size_t numCells, const std::vector< std::vector< PerforationData< Scalar > > > &well_perf_data, const SummaryState &summary_state, const bool enable_distributed_wells)
std::optional< std::size_t > index(const std::string &well_name) const
Definition: WellState.hpp:260
void gliftTimeStepInit()
Definition: WellState.hpp:205
const PhaseUsage & phaseUsage() const
Definition: WellState.hpp:244
void updateEfficiencyScalingFactor(const std::string &wellName, const Scalar value)
bool wellIsOwned(const std::string &wellName) const
void init(const std::vector< Scalar > &cellPressures, const std::vector< Scalar > &cellTemperatures, const Schedule &schedule, const std::vector< Well > &wells_ecl, const std::vector< std::reference_wrapper< ParallelWellInfo< Scalar > > > ¶llel_well_info, const int report_step, const WellState *prevState, const std::vector< std::vector< PerforationData< Scalar > > > &well_perf_data, const SummaryState &summary_state, const bool enableDistributedWells)
const std::vector< Scalar > & wellRates(std::size_t well_index) const
Definition: WellState.hpp:252
void communicateGroupRates(const Parallel::Communication &comm)
bool has(const std::string &well_name) const
Definition: WellState.hpp:305
void clearWellRates()
Definition: WellState.hpp:140
int wellNameToGlobalIdx(const std::string &name)
Definition: WellState.hpp:213
SingleWellState< Scalar > & operator[](std::size_t well_index)
Definition: WellState.hpp:275
static WellState serializationTestObject(const ParallelWellInfo< Scalar > &pinfo)
const std::string & name(std::size_t well_index) const
Definition: WellState.hpp:255
bool hasWellRates(const std::string &wellName) const
Definition: WellState.hpp:135
void updateWellsDefaultALQ(const Schedule &schedule, const int report_step, const SummaryState &summary_state)
void setCurrentWellRates(const std::string &wellName, const std::vector< Scalar > &new_rates)
Definition: WellState.hpp:125
void updateStatus(int well_index, WellStatus status)
SingleWellState< Scalar > & operator[](const std::string &well_name)
Definition: WellState.hpp:280
const SingleWellState< Scalar > & operator[](const std::string &well_name) const
Definition: WellState.hpp:270
bool isProductionGrup(const std::string &name) const
Definition: WellState.hpp:182
void gatherVectorsOnRoot(const std::vector< data::Connection > &from_connections, std::vector< data::Connection > &to_connections, const Parallel::Communication &comm) const
WellState(const ParallelWellInfo< Scalar > &pinfo)
void stopWell(int well_index)
void shutWell(int well_index)
static const int Gas
Definition: WellState.hpp:74
static const int Oil
Definition: WellState.hpp:73
WellState(const PhaseUsage &pu)
Definition: WellState.hpp:79
std::vector< Scalar > & wellRates(std::size_t well_index)
One rate per well and phase.
Definition: WellState.hpp:250
std::size_t size() const
Definition: WellState.hpp:85
bool isRank0() const
Definition: WellState.hpp:228
int numWells() const
Definition: WellState.hpp:95
void updateGlobalIsGrup(const Parallel::Communication &comm)
static const int Water
Definition: WellState.hpp:72
Scalar getGlobalEfficiencyScalingFactor(const std::string &name) const
Definition: WellState.hpp:192
static void calculateSegmentRates(const ParallelWellInfo< Scalar > &pw_info, const std::vector< std::vector< int > > &segment_inlets, const std::vector< std::vector< int > > &segment_perforations, const std::vector< Scalar > &perforation_rates, const int np, const int segment, std::vector< Scalar > &segment_rates)
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: blackoilboundaryratevector.hh:39
Static data associated with a well perforation.
Definition: PerforationData.hpp:30
Definition: BlackoilPhases.hpp:46
int num_phases
Definition: BlackoilPhases.hpp:54