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>
55template<
class Scalar>
class ParallelWellInfo;
56template<
class Scalar>
struct PerforationData;
57template<
class Scalar>
class ConnFracStatistics;
59enum class WellStatus : std::uint8_t;
66template<
typename Scalar,
typename IndexTraits>
85 static const std::uint64_t
event_mask = ScheduleEvents::WELL_STATUS_CHANGE
86 | ScheduleEvents::PRODUCTION_UPDATE
87 | ScheduleEvents::INJECTION_UPDATE;
101 : phaseUsageInfo_(pu)
108 return this->wells_.size();
111 std::vector<std::string>
wells()
const
113 return this->wells_.wells();
124 return this->phaseUsageInfo_;
132 void init(
const std::vector<Scalar>& cellPressures,
133 const std::vector<Scalar>& cellTemperatures,
134 const Schedule& schedule,
135 const std::vector<Well>& wells_ecl,
137 const int report_step,
140 const SummaryState& summary_state,
141 const bool enableDistributedWells);
143 void resize(
const std::vector<Well>& wells_ecl,
145 const Schedule& schedule,
146 const bool handle_ms_well,
147 const std::size_t numCells,
149 const SummaryState& summary_state,
150 const bool enable_distributed_wells,
154 const std::vector<Scalar>& new_rates)
156 auto& [owner, rates] = this->well_rates.at(wellName);
165 return this->well_rates.find(wellName) != this->well_rates.end();
170 this->well_rates.clear();
174 std::vector<data::Connection>& to_connections,
179 const std::function<
bool(
const std::size_t)>& wasDynamicallyClosed,
183 const std::function<
bool(
const std::string&)>& wasDynamicallyClosed,
184 const std::function<
double(
const std::string&)>& wellEffFac,
185 const std::function<
void(
int,
double)>& copt)
const;
197 const std::vector<std::vector<int>>& segment_inlets,
198 const std::vector<std::vector<int>>& segment_perforations,
199 const std::vector<Scalar>& perforation_rates,
202 std::vector<Scalar>& segment_rates);
208 const std::vector<WellStatus>& well_status);
214 return this->global_well_info.value().in_injecting_group(
name);
219 return this->global_well_info.value().in_producing_group(
name);
224 return this->global_well_info.value().is_open(
name);
229 return this->global_well_info.value().efficiency_scaling_factor(
name);
237 const int report_step,
238 const SummaryState& summary_state);
242 for (
size_t i = 0; i < this->
size(); ++i) {
243 this->wells_[i].alq_state.reset_count();
250 return this->global_well_info.value().well_index(
name);
255 return this->global_well_info.value().well_name(
index);
259 const std::string& wellName)
const;
264 return this->global_well_info.value().isRank0();
276 return phaseUsageInfo_.numActivePhases();
281 {
return this->wells_[well_index].surface_rates; }
282 const std::vector<Scalar>&
wellRates(std::size_t well_index)
const
283 {
return this->wells_[well_index].surface_rates; }
285 const std::string&
name(std::size_t well_index)
const
287 return this->wells_.well_name(well_index);
290 std::optional<std::size_t>
index(
const std::string& well_name)
const
292 return this->wells_.well_index(well_name);
297 return this->wells_[well_index];
302 return this->wells_[well_name];
307 return this->wells_[well_index];
312 return this->wells_[well_name];
335 bool has(
const std::string& well_name)
const
337 return this->wells_.has(well_name);
342 template<
class Serializer>
345 serializer(well_rates);
346 if (serializer.isSerializing()) {
347 serializer(wells_.size());
349 std::size_t serialized_size = 0;
350 serializer(serialized_size);
351 if (serialized_size != wells_.size()) {
352 OPM_THROW(std::runtime_error,
"Error deserializing WellState: size mismatch");
355 for (
auto& w : wells_) {
358 serializer(permanently_inactive_well_names_);
362 return std::ranges::find(this->permanently_inactive_well_names_, wname) !=
363 this->permanently_inactive_well_names_.end();
367 bool enableDistributedWells_ =
false;
382 std::optional<GlobalWellInfo<Scalar>> global_well_info;
387 std::map<std::string, std::pair<bool, std::vector<Scalar>>> well_rates;
390 std::vector<std::string> permanently_inactive_well_names_;
397 void base_init(
const std::vector<Scalar>& cellPressures,
398 const std::vector<Scalar>& cellTemperatures,
399 const std::vector<Well>& wells_ecl,
402 const SummaryState& summary_state);
404 void initSingleWell(
const std::vector<Scalar>& cellPressures,
405 const std::vector<Scalar>& cellTemperatures,
409 const SummaryState& summary_state);
411 void initSingleProducer(
const Well&
well,
413 Scalar pressure_first_connection,
414 Scalar temperature_first_connection,
416 const SummaryState& summary_state);
418 void initSingleInjector(
const Well&
well,
420 Scalar pressure_first_connection,
421 Scalar temperature_first_connection,
423 const SummaryState& summary_state);
426 const std::vector<std::vector<int>>& segment_inlets,
427 const std::vector<std::vector<int>>& segment_perforations,
428 const std::vector<Scalar>& perforation_rates,
431 std::vector<Scalar>& segment_rates);
433 void reportConnections(std::vector<data::Connection>& connections,
434 std::size_t well_index,
435 const int* globalCellIdxMap)
const;
438 reportSegmentResults(
const int well_id,
440 const int seg_no)
const;
442 void reportConnectionFactors(
const std::size_t well_index,
443 std::vector<data::Connection>& connections)
const;
445 void reportConnectionPressuresAndRates(
const std::size_t well_index,
446 std::vector<data::Connection>& connections)
const;
448 void reportConnectionFilterCake(
const std::size_t well_index,
449 std::vector<data::Connection>& connections)
const;
451 void reportConnectionFracture(
const std::size_t well_index,
452 std::vector<data::Connection>& connections)
const;
455 std::vector<data::Connection>& connections)
const;
Definition: ConnFracStatistics.hpp:37
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:217
Definition: GasLiftGroupInfo.hpp:38
Definition: SingleWellState.hpp:44
Definition: WellContainer.hpp:46
Definition: WellState.hpp:68
bool has(const std::string &well_name) const
Definition: WellState.hpp:335
void openWell(std::size_t well_index)
void clearWellRates()
Definition: WellState.hpp:168
bool isProductionGrup(const std::string &name) const
Definition: WellState.hpp:217
bool wellIsOwned(std::size_t well_index, const std::string &wellName) const
SingleWellState< Scalar, IndexTraits > & operator[](std::size_t well_index)
Definition: WellState.hpp:305
constexpr int numPhases() const
The number of phases present.
Definition: WellState.hpp:274
SingleWellState< Scalar, IndexTraits > & well(std::size_t well_index)
Definition: WellState.hpp:325
bool hasWellRates(const std::string &wellName) const
Definition: WellState.hpp:163
bool is_permanently_inactive_well(const std::string &wname) const
Definition: WellState.hpp:361
std::string globalIdxToWellName(const int index)
Definition: WellState.hpp:253
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)
static const int gasPhaseIdx
Definition: WellState.hpp:95
bool isInjectionGrup(const std::string &name) const
Definition: WellState.hpp:212
int wellNameToGlobalIdx(const std::string &name)
Definition: WellState.hpp:248
static const int waterPhaseIdx
Definition: WellState.hpp:93
void reportIntervalConnectionOilProduction(const double dt, const std::function< bool(const std::string &)> &wasDynamicallyClosed, const std::function< double(const std::string &)> &wellEffFac, const std::function< void(int, double)> &copt) const
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:240
const SingleWellState< Scalar, IndexTraits > & operator[](const std::string &well_name) const
Definition: WellState.hpp:300
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:153
int numWells() const
Definition: WellState.hpp:116
static const int oilPhaseIdx
Definition: WellState.hpp:94
Scalar getGlobalEfficiencyScalingFactor(const std::string &name) const
Definition: WellState.hpp:227
const std::vector< Scalar > & currentWellRates(const std::string &wellName) const
const PhaseUsageInfo< IndexTraits > & phaseUsageInfo() const
Definition: WellState.hpp:122
std::vector< std::string > wells() const
Definition: WellState.hpp:111
bool isRank0() const
Definition: WellState.hpp:263
const SingleWellState< Scalar, IndexTraits > & well(const std::string &well_name) const
Definition: WellState.hpp:320
static const std::uint64_t event_mask
Definition: WellState.hpp:85
static WellState serializationTestObject(const ParallelWellInfo< Scalar > &pinfo)
std::size_t size() const
Definition: WellState.hpp:106
void stopWell(std::size_t well_index)
WellState(const PhaseUsageInfo< IndexTraits > &pu)
Definition: WellState.hpp:100
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:315
const SingleWellState< Scalar, IndexTraits > & operator[](std::size_t well_index) const
Definition: WellState.hpp:295
bool isOpen(const std::string &name) const
Definition: WellState.hpp:222
void shutWell(std::size_t well_index)
bool wellIsOwned(const std::string &wellName) const
const std::vector< Scalar > & wellRates(std::size_t well_index) const
Definition: WellState.hpp:282
std::vector< Scalar > & wellRates(std::size_t well_index)
One rate per well and phase.
Definition: WellState.hpp:280
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, const bool thermal)
void updateWellsDefaultALQ(const Schedule &schedule, const int report_step, const SummaryState &summary_state)
void serializeOp(Serializer &serializer)
Definition: WellState.hpp:343
SingleWellState< Scalar, IndexTraits > & operator[](const std::string &well_name)
Definition: WellState.hpp:310
std::optional< std::size_t > index(const std::string &well_name) const
Definition: WellState.hpp:290
void initWellStateMSWell(const std::vector< Well > &wells_ecl, const WellState *prev_well_state, const bool thermal)
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)
void updateStatus(std::size_t well_index, WellStatus status)
SingleWellState< Scalar, IndexTraits > & well(const std::string &well_name)
Definition: WellState.hpp:330
const std::string & name(std::size_t well_index) const
Definition: WellState.hpp:285
data::Wells report(const int *globalCellIdxMap, const std::function< bool(const std::size_t)> &wasDynamicallyClosed, const RsConstInfo &rsConst=RsConstInfo{}) const
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:71
Scalar value
Definition: WellState.hpp:82
RsConstInfo(const bool en, const Scalar val)
Definition: WellState.hpp:73
bool enabled
Definition: WellState.hpp:79