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/material/fluidsystems/PhaseUsageInfo.hpp>
31#include <opm/input/eclipse/Schedule/Events.hpp>
33#include <opm/output/data/Wells.hpp>
56template<
class Scalar>
class ParallelWellInfo;
57template<
class Scalar>
struct PerforationData;
58template<
class Scalar>
class ConnFracStatistics;
60enum class WellStatus : std::uint8_t;
64template<
typename Scalar,
typename IndexTraits>
83 static const std::uint64_t
event_mask = ScheduleEvents::WELL_STATUS_CHANGE
84 | ScheduleEvents::PRODUCTION_UPDATE
85 | ScheduleEvents::INJECTION_UPDATE;
106 return this->wells_.size();
109 std::vector<std::string>
wells()
const
111 return this->wells_.wells();
122 return this->phaseUsageInfo_;
130 void init(
const std::vector<Scalar>& cellPressures,
131 const std::vector<Scalar>& cellTemperatures,
132 const Schedule& schedule,
133 const std::vector<Well>& wells_ecl,
135 const int report_step,
138 const SummaryState& summary_state,
139 const bool enableDistributedWells);
141 void resize(
const std::vector<Well>& wells_ecl,
143 const Schedule& schedule,
144 const bool handle_ms_well,
145 const std::size_t numCells,
147 const SummaryState& summary_state,
148 const bool enable_distributed_wells);
151 const std::vector<Scalar>& new_rates)
153 auto& [owner, rates] = this->well_rates.at(wellName);
162 return this->well_rates.find(wellName) != this->well_rates.end();
167 this->well_rates.clear();
171 std::vector<data::Connection>& to_connections,
176 const std::function<
bool(
const int)>& wasDynamicallyClosed,
180 std::size_t well_index,
181 const int* globalCellIdxMap)
const;
188 const std::vector<std::vector<int>>& segment_inlets,
189 const std::vector<std::vector<int>>& segment_perforations,
190 const std::vector<Scalar>& perforation_rates,
193 std::vector<Scalar>& segment_rates);
199 const std::vector<WellStatus>& well_status);
205 return this->global_well_info.value().in_injecting_group(
name);
210 return this->global_well_info.value().in_producing_group(
name);
215 return this->global_well_info.value().is_open(
name);
220 return this->global_well_info.value().efficiency_scaling_factor(
name);
228 const int report_step,
229 const SummaryState& summary_state);
233 for (
size_t i = 0; i < this->
size(); ++i) {
234 this->wells_[i].alq_state.reset_count();
241 return this->global_well_info.value().well_index(
name);
246 return this->global_well_info.value().well_name(
index);
250 const std::string& wellName)
const;
255 return this->global_well_info.value().isRank0();
267 return phaseUsageInfo_.numActivePhases();
272 {
return this->wells_[well_index].surface_rates; }
273 const std::vector<Scalar>&
wellRates(std::size_t well_index)
const
274 {
return this->wells_[well_index].surface_rates; }
276 const std::string&
name(std::size_t well_index)
const
278 return this->wells_.well_name(well_index);
281 std::optional<std::size_t>
index(
const std::string& well_name)
const
283 return this->wells_.well_index(well_name);
288 return this->wells_[well_index];
293 return this->wells_[well_name];
298 return this->wells_[well_index];
303 return this->wells_[well_name];
326 bool has(
const std::string& well_name)
const
328 return this->wells_.has(well_name);
333 template<
class Serializer>
336 serializer(well_rates);
337 if (serializer.isSerializing()) {
338 serializer(wells_.size());
340 std::size_t
size = 0;
342 if (
size != wells_.size()) {
343 OPM_THROW(std::runtime_error,
"Error deserializing WellState: size mismatch");
346 for (
auto& w : wells_) {
349 serializer(permanently_inactive_well_names_);
353 return std::ranges::find(this->permanently_inactive_well_names_, wname) !=
354 this->permanently_inactive_well_names_.end();
358 bool enableDistributedWells_ =
false;
373 std::optional<GlobalWellInfo<Scalar>> global_well_info;
378 std::map<std::string, std::pair<bool, std::vector<Scalar>>> well_rates;
381 std::vector<std::string> permanently_inactive_well_names_;
384 reportSegmentResults(
const int well_id,
386 const int seg_no)
const;
394 void base_init(
const std::vector<Scalar>& cellPressures,
395 const std::vector<Scalar>& cellTemperatures,
396 const std::vector<Well>& wells_ecl,
399 const SummaryState& summary_state);
401 void initSingleWell(
const std::vector<Scalar>& cellPressures,
402 const std::vector<Scalar>& cellTemperatures,
406 const SummaryState& summary_state);
408 void initSingleProducer(
const Well&
well,
410 Scalar pressure_first_connection,
412 const SummaryState& summary_state);
414 void initSingleInjector(
const Well&
well,
416 Scalar pressure_first_connection,
417 Scalar temperature_first_connection,
419 const SummaryState& summary_state);
422 const std::vector<std::vector<int>>& segment_inlets,
423 const std::vector<std::vector<int>>& segment_perforations,
424 const std::vector<Scalar>& perforation_rates,
427 std::vector<Scalar>& segment_rates);
429 void reportConnectionFactors(
const std::size_t well_index,
430 std::vector<data::Connection>& connections)
const;
432 void reportConnectionPressuresAndRates(
const std::size_t well_index,
433 std::vector<data::Connection>& connections)
const;
435 void reportConnectionFilterCake(
const std::size_t well_index,
436 std::vector<data::Connection>& connections)
const;
439 std::vector<data::Connection>& connections)
const;
Definition: ConnFracStatistics.hpp:37
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:198
Definition: GasLiftGroupInfo.hpp:38
Definition: SingleWellState.hpp:44
Definition: WellContainer.hpp:46
Definition: WellState.hpp:66
bool has(const std::string &well_name) const
Definition: WellState.hpp:326
void reportConnections(std::vector< data::Connection > &connections, std::size_t well_index, const int *globalCellIdxMap) const
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)
void clearWellRates()
Definition: WellState.hpp:165
bool isProductionGrup(const std::string &name) const
Definition: WellState.hpp:208
bool wellIsOwned(std::size_t well_index, const std::string &wellName) const
void openWell(int well_index)
SingleWellState< Scalar, IndexTraits > & operator[](std::size_t well_index)
Definition: WellState.hpp:296
constexpr int numPhases() const
The number of phases present.
Definition: WellState.hpp:265
SingleWellState< Scalar, IndexTraits > & well(std::size_t well_index)
Definition: WellState.hpp:316
bool hasWellRates(const std::string &wellName) const
Definition: WellState.hpp:160
bool is_permanently_inactive_well(const std::string &wname) const
Definition: WellState.hpp:352
std::string globalIdxToWellName(const int index)
Definition: WellState.hpp:244
const ParallelWellInfo< Scalar > & parallelWellInfo(std::size_t well_index) const
void updateGlobalIsGrup(const Parallel::Communication &comm, const std::vector< WellStatus > &well_status)
void communicateGroupRates(const Parallel::Communication &comm)
data::Wells report(const int *globalCellIdxMap, const std::function< bool(const int)> &wasDynamicallyClosed, const RsConstInfo &rsConst=RsConstInfo{}) const
static const int gasPhaseIdx
Definition: WellState.hpp:93
bool isInjectionGrup(const std::string &name) const
Definition: WellState.hpp:203
void initWellStateMSWell(const std::vector< Well > &wells_ecl, const WellState *prev_well_state)
init the MS well related.
int wellNameToGlobalIdx(const std::string &name)
Definition: WellState.hpp:239
static const int waterPhaseIdx
Definition: WellState.hpp:91
void stopWell(int well_index)
void gatherVectorsOnRoot(const std::vector< data::Connection > &from_connections, std::vector< data::Connection > &to_connections, const Parallel::Communication &comm) const
void gliftTimeStepInit()
Definition: WellState.hpp:231
const SingleWellState< Scalar, IndexTraits > & operator[](const std::string &well_name) const
Definition: WellState.hpp:291
bool operator==(const WellState &) const
WellState(const ParallelWellInfo< Scalar > &pinfo)
void setCurrentWellRates(const std::string &wellName, const std::vector< Scalar > &new_rates)
Definition: WellState.hpp:150
int numWells() const
Definition: WellState.hpp:114
static const int oilPhaseIdx
Definition: WellState.hpp:92
Scalar getGlobalEfficiencyScalingFactor(const std::string &name) const
Definition: WellState.hpp:218
const std::vector< Scalar > & currentWellRates(const std::string &wellName) const
const PhaseUsageInfo< IndexTraits > & phaseUsageInfo() const
Definition: WellState.hpp:120
std::vector< std::string > wells() const
Definition: WellState.hpp:109
bool isRank0() const
Definition: WellState.hpp:254
const SingleWellState< Scalar, IndexTraits > & well(const std::string &well_name) const
Definition: WellState.hpp:311
static const std::uint64_t event_mask
Definition: WellState.hpp:83
static WellState serializationTestObject(const ParallelWellInfo< Scalar > &pinfo)
std::size_t size() const
Definition: WellState.hpp:104
WellState(const PhaseUsageInfo< IndexTraits > &pu)
Definition: WellState.hpp:98
void updateStatus(int well_index, WellStatus status)
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)
void updateEfficiencyScalingFactor(const std::string &wellName, const Scalar value)
const SingleWellState< Scalar, IndexTraits > & well(std::size_t well_index) const
Definition: WellState.hpp:306
const SingleWellState< Scalar, IndexTraits > & operator[](std::size_t well_index) const
Definition: WellState.hpp:286
bool isOpen(const std::string &name) const
Definition: WellState.hpp:213
bool wellIsOwned(const std::string &wellName) const
const std::vector< Scalar > & wellRates(std::size_t well_index) const
Definition: WellState.hpp:273
std::vector< Scalar > & wellRates(std::size_t well_index)
One rate per well and phase.
Definition: WellState.hpp:271
void updateWellsDefaultALQ(const Schedule &schedule, const int report_step, const SummaryState &summary_state)
void serializeOp(Serializer &serializer)
Definition: WellState.hpp:334
SingleWellState< Scalar, IndexTraits > & operator[](const std::string &well_name)
Definition: WellState.hpp:301
std::optional< std::size_t > index(const std::string &well_name) const
Definition: WellState.hpp:281
void shutWell(int well_index)
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)
SingleWellState< Scalar, IndexTraits > & well(const std::string &well_name)
Definition: WellState.hpp:321
const std::string & name(std::size_t well_index) const
Definition: WellState.hpp:276
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: blackoilbioeffectsmodules.hh:45
Static data associated with a well perforation.
Definition: PerforationData.hpp:30
Definition: WellState.hpp:69
Scalar value
Definition: WellState.hpp:80
RsConstInfo(const bool en, const Scalar val)
Definition: WellState.hpp:71
bool enabled
Definition: WellState.hpp:77