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> 35 #include <opm/simulators/wells/GlobalWellInfo.hpp> 36 #include <opm/simulators/wells/PerfData.hpp> 37 #include <opm/simulators/wells/SegmentState.hpp> 38 #include <opm/simulators/wells/SingleWellState.hpp> 39 #include <opm/simulators/wells/WellContainer.hpp> 41 #include <opm/simulators/utils/ParallelCommunication.hpp> 56 template<
class Scalar>
class ParallelWellInfo;
57 template<
class Scalar>
struct PerforationData;
58 template<
class Scalar>
class ConnFracStatistics;
60 enum class WellStatus : std::uint8_t;
64 template<typename Scalar, typename IndexTraits>
83 static const std::uint64_t event_mask = ScheduleEvents::WELL_STATUS_CHANGE
84 | ScheduleEvents::PRODUCTION_UPDATE
85 | ScheduleEvents::INJECTION_UPDATE;
91 static const int waterPhaseIdx = IndexTraits::waterPhaseIdx;
92 static const int oilPhaseIdx = IndexTraits::oilPhaseIdx;
93 static const int gasPhaseIdx = IndexTraits::gasPhaseIdx;
104 std::size_t size()
const 106 return this->wells_.size();
109 std::vector<std::string> wells()
const 111 return this->wells_.wells();
120 const PhaseUsageInfo<IndexTraits>& phaseUsageInfo()
const 122 return this->phaseUsageInfo_;
125 const ParallelWellInfo<Scalar>& parallelWellInfo(std::size_t well_index)
const;
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,
134 const std::vector<std::reference_wrapper<ParallelWellInfo<Scalar>>>& parallel_well_info,
135 const int report_step,
136 const WellState* prevState,
137 const std::vector<std::vector<PerforationData<Scalar>>>& well_perf_data,
138 const SummaryState& summary_state,
139 const bool enableDistributedWells);
141 void resize(
const std::vector<Well>& wells_ecl,
142 const std::vector<std::reference_wrapper<ParallelWellInfo<Scalar>>>& parallel_well_info,
143 const Schedule& schedule,
144 const bool handle_ms_well,
145 const std::size_t numCells,
146 const std::vector<std::vector<PerforationData<Scalar>>>& well_perf_data,
147 const SummaryState& summary_state,
148 const bool enable_distributed_wells,
151 void setCurrentWellRates(
const std::string& wellName,
152 const std::vector<Scalar>& new_rates)
154 auto& [owner, rates] = this->well_rates.at(wellName);
159 const std::vector<Scalar>& currentWellRates(
const std::string& wellName)
const;
161 bool hasWellRates(
const std::string& wellName)
const 163 return this->well_rates.find(wellName) != this->well_rates.end();
166 void clearWellRates()
168 this->well_rates.clear();
171 void gatherVectorsOnRoot(
const std::vector<data::Connection>& from_connections,
172 std::vector<data::Connection>& to_connections,
173 const Parallel::Communication& comm)
const;
176 report(
const int* globalCellIdxMap,
177 const std::function<
bool(
const std::size_t)>& wasDynamicallyClosed,
178 const RsConstInfo& rsConst = RsConstInfo{})
const;
180 void reportConnections(std::vector<data::Connection>& connections,
181 std::size_t well_index,
182 const int* globalCellIdxMap)
const;
187 void initWellStateMSWell(
const std::vector<Well>& wells_ecl,
188 const WellState* prev_well_state,
191 static void calculateSegmentRates(
const ParallelWellInfo<Scalar>& pw_info,
192 const std::vector<std::vector<int>>& segment_inlets,
193 const std::vector<std::vector<int>>& segment_perforations,
194 const std::vector<Scalar>& perforation_rates,
197 std::vector<Scalar>& segment_rates);
200 void communicateGroupRates(
const Parallel::Communication& comm);
202 void updateGlobalIsGrup(
const Parallel::Communication& comm,
203 const std::vector<WellStatus>& well_status);
204 void updateEfficiencyScalingFactor(
const std::string& wellName,
207 bool isInjectionGrup(
const std::string& name)
const 209 return this->global_well_info.value().in_injecting_group(name);
212 bool isProductionGrup(
const std::string& name)
const 214 return this->global_well_info.value().in_producing_group(name);
217 bool isOpen(
const std::string& name)
const 219 return this->global_well_info.value().is_open(name);
222 Scalar getGlobalEfficiencyScalingFactor(
const std::string& name)
const 224 return this->global_well_info.value().efficiency_scaling_factor(name);
231 void updateWellsDefaultALQ(
const Schedule& schedule,
232 const int report_step,
233 const SummaryState& summary_state);
235 void gliftTimeStepInit()
237 for (
size_t i = 0; i < this->size(); ++i) {
238 this->wells_[i].alq_state.reset_count();
243 int wellNameToGlobalIdx(
const std::string& name)
245 return this->global_well_info.value().well_index(name);
248 std::string globalIdxToWellName(
const int index)
250 return this->global_well_info.value().well_name(index);
253 bool wellIsOwned(std::size_t well_index,
254 const std::string& wellName)
const;
256 bool wellIsOwned(
const std::string& wellName)
const;
258 bool isRank0()
const {
259 return this->global_well_info.value().isRank0();
262 void updateStatus(std::size_t well_index, WellStatus status);
264 void openWell(std::size_t well_index);
265 void shutWell(std::size_t well_index);
266 void stopWell(std::size_t well_index);
271 return phaseUsageInfo_.numActivePhases();
276 {
return this->wells_[well_index].surface_rates; }
277 const std::vector<Scalar>& wellRates(std::size_t well_index)
const 278 {
return this->wells_[well_index].surface_rates; }
280 const std::string& name(std::size_t well_index)
const 282 return this->wells_.well_name(well_index);
285 std::optional<std::size_t> index(
const std::string& well_name)
const 287 return this->wells_.well_index(well_name);
290 const SingleWellState<Scalar, IndexTraits>& operator[](std::size_t well_index)
const 292 return this->wells_[well_index];
295 const SingleWellState<Scalar, IndexTraits>& operator[](
const std::string& well_name)
const 297 return this->wells_[well_name];
300 SingleWellState<Scalar, IndexTraits>& operator[](std::size_t well_index)
302 return this->wells_[well_index];
305 SingleWellState<Scalar, IndexTraits>& operator[](
const std::string& well_name)
307 return this->wells_[well_name];
310 const SingleWellState<Scalar, IndexTraits>& well(std::size_t well_index)
const 312 return this->operator[](well_index);
315 const SingleWellState<Scalar, IndexTraits>& well(
const std::string& well_name)
const 317 return this->operator[](well_name);
320 SingleWellState<Scalar, IndexTraits>& well(std::size_t well_index)
322 return this->operator[](well_index);
325 SingleWellState<Scalar, IndexTraits>& well(
const std::string& well_name)
327 return this->operator[](well_name);
330 bool has(
const std::string& well_name)
const 332 return this->wells_.has(well_name);
335 bool operator==(
const WellState&)
const;
337 template<
class Serializer>
338 void serializeOp(Serializer& serializer)
340 serializer(well_rates);
341 if (serializer.isSerializing()) {
342 serializer(wells_.size());
344 std::size_t serialized_size = 0;
345 serializer(serialized_size);
346 if (serialized_size != wells_.size()) {
347 OPM_THROW(std::runtime_error,
"Error deserializing WellState: size mismatch");
350 for (
auto& w : wells_) {
353 serializer(permanently_inactive_well_names_);
356 bool is_permanently_inactive_well(
const std::string& wname)
const {
357 return std::ranges::find(this->permanently_inactive_well_names_, wname) !=
358 this->permanently_inactive_well_names_.end();
362 bool enableDistributedWells_ =
false;
364 PhaseUsageInfo<IndexTraits> phaseUsageInfo_;
369 WellContainer<SingleWellState<Scalar, IndexTraits>> wells_;
377 std::optional<GlobalWellInfo<Scalar>> global_well_info;
382 std::map<std::string, std::pair<bool, std::vector<Scalar>>> well_rates;
385 std::vector<std::string> permanently_inactive_well_names_;
388 reportSegmentResults(
const int well_id,
390 const int seg_no)
const;
398 void base_init(
const std::vector<Scalar>& cellPressures,
399 const std::vector<Scalar>& cellTemperatures,
400 const std::vector<Well>& wells_ecl,
401 const std::vector<std::reference_wrapper<ParallelWellInfo<Scalar>>>& parallel_well_info,
402 const std::vector<std::vector<PerforationData<Scalar>>>& well_perf_data,
403 const SummaryState& summary_state);
405 void initSingleWell(
const std::vector<Scalar>& cellPressures,
406 const std::vector<Scalar>& cellTemperatures,
408 const std::vector<PerforationData<Scalar>>& well_perf_data,
409 const ParallelWellInfo<Scalar>& well_info,
410 const SummaryState& summary_state);
412 void initSingleProducer(
const Well& well,
413 const ParallelWellInfo<Scalar>& well_info,
414 Scalar pressure_first_connection,
415 Scalar temperature_first_connection,
416 const std::vector<PerforationData<Scalar>>& well_perf_data,
417 const SummaryState& summary_state);
419 void initSingleInjector(
const Well& well,
420 const ParallelWellInfo<Scalar>& well_info,
421 Scalar pressure_first_connection,
422 Scalar temperature_first_connection,
423 const std::vector<PerforationData<Scalar>>& well_perf_data,
424 const SummaryState& summary_state);
426 static void calculateSegmentRatesBeforeSum(
const ParallelWellInfo<Scalar>& pw_info,
427 const std::vector<std::vector<int>>& segment_inlets,
428 const std::vector<std::vector<int>>& segment_perforations,
429 const std::vector<Scalar>& perforation_rates,
432 std::vector<Scalar>& segment_rates);
434 void reportConnectionFactors(
const std::size_t well_index,
435 std::vector<data::Connection>& connections)
const;
437 void reportConnectionPressuresAndRates(
const std::size_t well_index,
438 std::vector<data::Connection>& connections)
const;
440 void reportConnectionFilterCake(
const std::size_t well_index,
441 std::vector<data::Connection>& connections)
const;
443 void reportFractureStatistics(
const std::vector<ConnFracStatistics<Scalar>>& stats,
444 std::vector<data::Connection>& connections)
const;
450 #endif // OPM_WELLSTATEFULLYIMPLICITBLACKOIL_HEADER_INCLUDED std::vector< Scalar > & wellRates(std::size_t well_index)
One rate per well and phase.
Definition: WellState.hpp:275
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
Definition: WellState.hpp:68
Class encapsulating some information about parallel wells.
Definition: MSWellHelpers.hpp:34
Definition: GasLiftGroupInfo.hpp:38
constexpr int numPhases() const
The number of phases present.
Definition: WellState.hpp:269
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition: TemperatureModel.hpp:65