22#ifndef OPM_WELLINTERFACE_IMPL_HEADER_INCLUDED
23#define OPM_WELLINTERFACE_IMPL_HEADER_INCLUDED
26#ifndef OPM_WELLINTERFACE_HEADER_INCLUDED
31#include <opm/common/Exceptions.hpp>
33#include <opm/input/eclipse/Schedule/ScheduleTypes.hpp>
34#include <opm/input/eclipse/Schedule/Well/WDFAC.hpp>
43#include <dune/common/version.hh>
50#include <fmt/format.h>
56 template<
typename TypeTag>
63 const int pvtRegionIdx,
64 const int num_conservation_quantities,
66 const int index_of_well,
74 num_conservation_quantities,
82 if (well.isInjector()) {
83 auto injectorType = this->
well_ecl_.injectorType();
84 if (injectorType == InjectorType::GAS) {
92 template<
typename TypeTag>
95 init(
const std::vector<Scalar>& ,
97 const std::vector<Scalar>& B_avg,
98 const bool changed_to_open_this_step)
100 this->gravity_ = gravity_arg;
102 this->changed_to_open_this_step_ = changed_to_open_this_step;
108 template<
typename TypeTag>
113 if constexpr (has_polymer) {
114 return this->wpolymer_();
124 template<
typename TypeTag>
129 if constexpr (has_foam) {
130 return this->wfoam_();
138 template<
typename TypeTag>
143 if constexpr (has_brine) {
144 return this->wsalt_();
150 template<
typename TypeTag>
155 if constexpr (has_micp) {
156 return this->wmicrobes_();
162 template<
typename TypeTag>
167 if constexpr (has_micp) {
168 return this->woxygen_();
174 template<
typename TypeTag>
179 if constexpr (has_micp) {
180 return this->wurea_();
186 template<
typename TypeTag>
196 if (stoppedOrZeroRateTarget(groupStateHelper, deferred_logger)) {
200 const auto& summaryState = simulator.vanguard().summaryState();
201 const auto& schedule = simulator.vanguard().schedule();
202 const auto& well = this->well_ecl_;
203 auto& ws = well_state.
well(this->index_of_well_);
205 bool is_grup =
false;
206 if (well.isInjector()) {
207 from = WellInjectorCMode2String(ws.injection_cmode);
208 is_grup = ws.injection_cmode == Well::InjectorCMode::GRUP;
210 from = WellProducerCMode2String(ws.production_cmode);
211 is_grup = ws.production_cmode == Well::ProducerCMode::GRUP;
214 const int episodeIdx = simulator.episodeIndex();
215 const int iterationIdx = simulator.model().newtonMethod().numIterations();
216 const int nupcol = schedule[episodeIdx].nupcol();
217 const bool oscillating = std::count(this->well_control_log_.begin(), this->well_control_log_.end(), from) >= this->param_.max_number_of_well_switches_;
218 if (oscillating && !is_grup) {
220 const bool output = std::count(this->well_control_log_.begin(), this->well_control_log_.end(), from) == this->param_.max_number_of_well_switches_;
222 const auto msg = fmt::format(
" The control mode for well {} is oscillating. \n"
223 "We don't allow for more than {} switches after NUPCOL iterations. (NUPCOL = {}) \n"
224 "The control is kept at {}.",
225 this->name(), this->param_.max_number_of_well_switches_, nupcol, from);
226 deferred_logger.
info(msg);
228 this->well_control_log_.push_back(from);
232 bool changed =
false;
233 if (iog == IndividualOrGroup::Individual) {
234 changed = this->checkIndividualConstraints(ws, summaryState, deferred_logger);
235 }
else if (iog == IndividualOrGroup::Group) {
236 changed = this->checkGroupConstraints(
237 groupStateHelper, schedule, summaryState,
true, well_state, deferred_logger
240 assert(iog == IndividualOrGroup::Both);
241 changed = this->checkConstraints(groupStateHelper, schedule, summaryState, well_state, deferred_logger);
247 if (well.isInjector()) {
248 to = WellInjectorCMode2String(ws.injection_cmode);
250 to = WellProducerCMode2String(ws.production_cmode);
252 std::ostringstream ss;
253 ss <<
" Switching control mode for well " << this->name()
257 ss <<
" on rank " << cc.rank();
259 deferred_logger.
debug(ss.str());
264 if (iterationIdx >= nupcol || this->well_control_log_.empty()) {
265 this->well_control_log_.push_back(from);
267 updateWellStateWithTarget(simulator, groupStateHelper, well_state, deferred_logger);
268 updatePrimaryVariables(groupStateHelper, deferred_logger);
274 template<
typename TypeTag>
279 const Well::InjectionControls& inj_controls,
280 const Well::ProductionControls& prod_controls,
284 const bool fixed_control,
285 const bool fixed_status,
286 const bool solving_with_zero_rate)
289 const auto& summary_state = simulator.vanguard().summaryState();
290 const auto& schedule = simulator.vanguard().schedule();
291 auto& ws = well_state.
well(this->index_of_well_);
293 if (this->isInjector()) {
294 from = WellInjectorCMode2String(ws.injection_cmode);
296 from = WellProducerCMode2String(ws.production_cmode);
298 const bool oscillating = std::count(this->well_control_log_.begin(), this->well_control_log_.end(), from) >= this->param_.max_number_of_well_switches_;
300 if (oscillating || this->wellUnderZeroRateTarget(groupStateHelper, deferred_logger) || !(well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
304 const Scalar sgn = this->isInjector() ? 1.0 : -1.0;
305 if (!this->wellIsStopped()){
306 if (wqTotal*sgn <= 0.0 && !fixed_status){
310 bool changed =
false;
311 if (!fixed_control) {
314 if (solving_with_zero_rate) {
316 "Well {}: solving_with_zero_rate should not be true when fixed_control is false",
317 this->name()), deferred_logger);
323 const bool hasGroupControl = this->isInjector() ? inj_controls.hasControl(Well::InjectorCMode::GRUP) :
324 prod_controls.hasControl(Well::ProducerCMode::GRUP);
325 bool isGroupControl = ws.production_cmode == Well::ProducerCMode::GRUP || ws.injection_cmode == Well::InjectorCMode::GRUP;
326 if (! (isGroupControl && !this->param_.check_group_constraints_inner_well_iterations_)) {
327 changed = this->checkIndividualConstraints(ws, summary_state, deferred_logger, inj_controls, prod_controls);
329 if (hasGroupControl && this->param_.check_group_constraints_inner_well_iterations_) {
330 changed = changed || this->checkGroupConstraints(
331 groupStateHelper, schedule, summary_state,
false, well_state, deferred_logger
336 const bool thp_controlled = this->isInjector() ? ws.injection_cmode == Well::InjectorCMode::THP :
337 ws.production_cmode == Well::ProducerCMode::THP;
339 ws.thp = this->getTHPConstraint(summary_state);
342 updateWellStateWithTarget(simulator, groupStateHelper, well_state, deferred_logger);
344 updatePrimaryVariables(groupStateHelper, deferred_logger);
349 }
else if (!fixed_status){
351 const Scalar bhp = well_state.
well(this->index_of_well_).bhp;
352 Scalar prod_limit = prod_controls.bhp_limit;
353 Scalar inj_limit = inj_controls.bhp_limit;
354 const bool has_thp = this->wellHasTHPConstraints(summary_state);
356 std::vector<Scalar> rates(this->num_conservation_quantities_);
357 if (this->isInjector()){
359 calculateBhpFromThp(well_state, rates,
362 this->getRefDensity(),
364 inj_limit = std::min(bhp_thp,
static_cast<Scalar>(inj_controls.bhp_limit));
369 calculateMinimumBhpFromThp(well_state,
372 this->getRefDensity());
373 prod_limit = std::max(bhp_min,
static_cast<Scalar>(prod_controls.bhp_limit));
376 const Scalar bhp_diff = (this->isInjector())? inj_limit - bhp: bhp - prod_limit;
379 well_state.
well(this->index_of_well_).bhp = (this->isInjector())? inj_limit : prod_limit;
381 well_state.
well(this->index_of_well_).thp = this->getTHPConstraint(summary_state);
392 template<
typename TypeTag>
396 const double simulation_time,
399 WellTestState& well_test_state,
401 std::map<std::string, double>& open_times,
405 const auto& group_state = groupStateHelper.
groupState();
406 deferred_logger.
info(
" well " + this->name() +
" is being tested");
413 auto guard = groupStateHelper_copy.
pushWellState(well_state_copy);
414 auto& ws = well_state_copy.
well(this->indexOfWell());
416 const auto& summary_state = simulator.vanguard().summaryState();
417 const bool has_thp_limit = this->wellHasTHPConstraints(summary_state);
418 if (this->isProducer()) {
419 ws.production_cmode = has_thp_limit ? Well::ProducerCMode::THP : Well::ProducerCMode::BHP;
421 ws.injection_cmode = has_thp_limit ? Well::InjectorCMode::THP : Well::InjectorCMode::BHP;
426 scaleSegmentRatesAndPressure(well_state_copy);
427 calculateExplicitQuantities(simulator, groupStateHelper_copy, deferred_logger);
428 updatePrimaryVariables(groupStateHelper_copy, deferred_logger);
430 if (this->isProducer()) {
431 const auto& schedule = simulator.vanguard().schedule();
432 const auto report_step = simulator.episodeIndex();
433 const auto& glo = schedule.glo(report_step);
435 gliftBeginTimeStepWellTestUpdateALQ(simulator,
443 WellTestState welltest_state_temp;
445 bool testWell =
true;
450 const std::size_t original_number_closed_completions = welltest_state_temp.num_closed_completions();
451 bool converged = solveWellForTesting(simulator, groupStateHelper_copy, well_state_copy, deferred_logger);
453 const auto msg = fmt::format(
"WTEST: Well {} is not solvable (physical)", this->name());
454 deferred_logger.
debug(msg);
459 updateWellOperability(simulator, well_state_copy, groupStateHelper_copy, deferred_logger);
460 if ( !this->isOperableAndSolvable() ) {
461 const auto msg = fmt::format(
"WTEST: Well {} is not operable (physical)", this->name());
462 deferred_logger.
debug(msg);
465 std::vector<Scalar> potentials;
467 computeWellPotentials(simulator, well_state_copy, groupStateHelper_copy, potentials, deferred_logger);
468 }
catch (
const std::exception& e) {
469 const std::string msg = fmt::format(
"well {}: computeWellPotentials() "
470 "failed during testing for re-opening: ",
471 this->name(), e.what());
472 deferred_logger.
info(msg);
475 const int np = well_state_copy.
numPhases();
476 for (
int p = 0; p < np; ++p) {
477 ws.well_potentials[p] = std::max(
Scalar{0.0}, potentials[p]);
479 const bool under_zero_target = this->wellUnderZeroGroupRateTarget(groupStateHelper_copy, deferred_logger);
480 this->updateWellTestState(well_state_copy.
well(this->indexOfWell()),
486 this->closeCompletions(welltest_state_temp);
492 if ( welltest_state_temp.num_closed_wells() > 0 ||
493 (original_number_closed_completions == welltest_state_temp.num_closed_completions()) ) {
499 if (!welltest_state_temp.well_is_closed(this->name())) {
500 well_test_state.open_well(this->name());
502 std::string msg = std::string(
"well ") + this->name() + std::string(
" is re-opened");
503 deferred_logger.
info(msg);
506 for (
const auto& completion : this->well_ecl_.getCompletions()) {
507 if (!welltest_state_temp.completion_is_closed(this->name(), completion.first))
508 well_test_state.open_completion(this->name(), completion.first);
510 well_state = well_state_copy;
511 open_times.try_emplace(this->name(), well_test_state.lastTestTime(this->name()));
518 template<
typename TypeTag>
528 const auto& summary_state = simulator.vanguard().summaryState();
529 const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
530 const auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
531 const auto& ws = well_state.
well(this->indexOfWell());
532 const auto pmode_orig = ws.production_cmode;
533 const auto imode_orig = ws.injection_cmode;
534 bool converged =
false;
537 if (!this->param_.local_well_solver_control_switching_){
538 converged = this->iterateWellEqWithControl(simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state, deferred_logger);
540 if (this->param_.use_implicit_ipr_ && this->well_ecl_.isProducer() && (well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
541 converged = solveWellWithOperabilityCheck(
542 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state, deferred_logger
545 converged = this->iterateWellEqWithSwitching(
546 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state, deferred_logger,
552 }
catch (NumericalProblem& e ) {
553 const std::string msg =
"Inner well iterations failed for well " + this->name() +
" Treat the well as unconverged. ";
554 deferred_logger.
warning(
"INNER_ITERATION_FAILED", msg);
559 if (ws.production_cmode != pmode_orig || ws.injection_cmode != imode_orig) {
561 if (this->isInjector()) {
562 from = WellInjectorCMode2String(imode_orig);
563 to = WellInjectorCMode2String(ws.injection_cmode);
565 from = WellProducerCMode2String(pmode_orig);
566 to = WellProducerCMode2String(ws.production_cmode);
568 const auto msg = fmt::format(
" Well {} switched from {} to {} during local solve", this->name(), from, to);
569 deferred_logger.
debug(msg);
570 const int episodeIdx = simulator.episodeIndex();
571 const int iterationIdx = simulator.model().newtonMethod().numIterations();
572 const auto& schedule = simulator.vanguard().schedule();
573 const int nupcol = schedule[episodeIdx].nupcol();
577 if (iterationIdx >= nupcol || this->well_control_log_.empty()) {
578 this->well_control_log_.push_back(from);
586 template<
typename TypeTag>
591 const Well::InjectionControls& inj_controls,
592 const Well::ProductionControls& prod_controls,
598 const auto& summary_state = simulator.vanguard().summaryState();
599 bool converged =
true;
600 auto& ws = well_state.
well(this->index_of_well_);
602 if (this->wellIsStopped()) {
604 const bool use_vfpexplicit = this->operability_status_.use_vfpexplicit;
605 this->operability_status_.use_vfpexplicit =
true;
606 auto bhp_target = estimateOperableBhp(simulator, dt, groupStateHelper, summary_state, well_state, deferred_logger);
607 if (!bhp_target.has_value()) {
609 const auto msg = fmt::format(
"estimateOperableBhp: Did not find operable BHP for well {}", this->name());
610 deferred_logger.
debug(msg);
613 converged = solveWellWithZeroRate(simulator, dt, groupStateHelper, well_state, deferred_logger);
615 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
616 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
620 ws.thp = this->getTHPConstraint(summary_state);
621 const Scalar bhp = std::max(bhp_target.value(),
622 static_cast<Scalar>(prod_controls.bhp_limit));
623 solveWellWithBhp(simulator, dt, bhp, groupStateHelper, well_state, deferred_logger);
624 this->operability_status_.use_vfpexplicit = use_vfpexplicit;
628 converged = this->iterateWellEqWithSwitching(
629 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state, deferred_logger,
634 const bool isThp = ws.production_cmode == Well::ProducerCMode::THP;
636 if (converged && !stoppedOrZeroRateTarget(groupStateHelper, deferred_logger) && isThp) {
637 auto rates = well_state.
well(this->index_of_well_).surface_rates;
638 this->adaptRatesForVFP(rates);
639 this->updateIPRImplicit(simulator, groupStateHelper, well_state, deferred_logger);
643 this->operability_status_.use_vfpexplicit =
true;
646 const Scalar reltol = 1e-3;
647 const Scalar cur_bhp = ws.bhp;
648 if (bhp_stable.has_value() && cur_bhp - bhp_stable.value() > cur_bhp*reltol){
649 const auto msg = fmt::format(
"Well {} converged to an unstable solution, re-solving", this->name());
650 deferred_logger.
debug(msg);
652 simulator, dt, bhp_stable.value(), groupStateHelper, well_state, deferred_logger
655 ws.thp = this->getTHPConstraint(summary_state);
656 converged = this->iterateWellEqWithSwitching(
657 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state, deferred_logger,
666 this->operability_status_.use_vfpexplicit =
true;
668 auto bhp_target = estimateOperableBhp(
669 simulator, dt, groupStateHelper, summary_state, well_state, deferred_logger
671 if (!bhp_target.has_value()) {
674 converged = solveWellWithZeroRate(simulator, dt, groupStateHelper, well_state, deferred_logger);
676 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
677 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
681 const Scalar bhp = std::max(bhp_target.value(),
682 static_cast<Scalar>(prod_controls.bhp_limit));
684 simulator, dt, bhp, groupStateHelper, well_state, deferred_logger
686 ws.thp = this->getTHPConstraint(summary_state);
687 const auto msg = fmt::format(
"Well {} did not converge, re-solving with explicit fractions for VFP caculations.", this->name());
688 deferred_logger.
debug(msg);
689 converged = this->iterateWellEqWithSwitching(simulator, dt,
701 this->operability_status_.can_obtain_bhp_with_thp_limit = !this->wellIsStopped();
702 this->operability_status_.obey_thp_limit_under_bhp_limit = !this->wellIsStopped();
706 template<
typename TypeTag>
707 std::optional<typename WellInterface<TypeTag>::Scalar>
712 const SummaryState& summary_state,
716 if (!this->wellHasTHPConstraints(summary_state)) {
718 const bool converged = solveWellWithBhp(
719 simulator, dt, bhp_limit, groupStateHelper, well_state, deferred_logger
721 if (!converged || this->wellIsStopped()) {
732 const bool converged = solveWellWithBhp(
733 simulator, dt, bhp_min, groupStateHelper, well_state, deferred_logger
735 if (!converged || this->wellIsStopped()) {
738 this->updateIPRImplicit(simulator, groupStateHelper, well_state, deferred_logger);
739 auto rates = well_state.
well(this->index_of_well_).surface_rates;
740 this->adaptRatesForVFP(rates);
744 template<
typename TypeTag>
761 auto group_guard = groupStateHelper_copy.
pushGroupState(group_state);
763 auto inj_controls = Well::InjectionControls(0);
764 auto prod_controls = Well::ProductionControls(0);
765 auto& ws = well_state.
well(this->index_of_well_);
766 auto cmode_inj = ws.injection_cmode;
767 auto cmode_prod = ws.production_cmode;
768 if (this->isInjector()) {
769 inj_controls.addControl(Well::InjectorCMode::BHP);
770 inj_controls.bhp_limit = bhp;
771 inj_controls.cmode = Well::InjectorCMode::BHP;
772 ws.injection_cmode = Well::InjectorCMode::BHP;
774 prod_controls.addControl(Well::ProducerCMode::BHP);
775 prod_controls.bhp_limit = bhp;
776 prod_controls.cmode = Well::ProducerCMode::BHP;
777 ws.production_cmode = Well::ProducerCMode::BHP;
782 const bool converged = this->iterateWellEqWithSwitching(
783 simulator, dt, inj_controls, prod_controls, groupStateHelper_copy,
784 well_state, deferred_logger,
789 ws.injection_cmode = cmode_inj;
790 ws.production_cmode = cmode_prod;
794 template<
typename TypeTag>
805 const auto well_status_orig = this->wellStatus_;
808 auto inj_controls = Well::InjectionControls(0);
809 auto prod_controls = Well::ProductionControls(0);
814 const bool converged = this->iterateWellEqWithSwitching(
815 simulator, dt, inj_controls, prod_controls,
823 this->wellStatus_ = well_status_orig;
827 template<
typename TypeTag>
836 const double dt = simulator.timeStepSize();
838 const auto& summary_state = simulator.vanguard().summaryState();
839 auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
840 auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
841 this->onlyKeepBHPandTHPcontrols(summary_state, well_state, inj_controls, prod_controls);
843 bool converged =
false;
846 if (!this->param_.local_well_solver_control_switching_){
847 converged = this->iterateWellEqWithControl(
848 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state, deferred_logger
851 if (this->param_.use_implicit_ipr_ && this->well_ecl_.isProducer() && (well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
852 converged = this->solveWellWithOperabilityCheck(
853 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state, deferred_logger
856 converged = this->iterateWellEqWithSwitching(
857 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state, deferred_logger,
865 }
catch (NumericalProblem& e ) {
866 const std::string msg =
"Inner well iterations failed for well " + this->name() +
" Treat the well as unconverged. ";
867 deferred_logger.
warning(
"INNER_ITERATION_FAILED", msg);
872 deferred_logger.
debug(
"WellTest: Well equation for well " + this->name() +
" converged");
875 const int max_iter = this->param_.max_welleq_iter_;
876 deferred_logger.
debug(
"WellTest: Well equation for well " + this->name() +
" failed converging in "
882 template<
typename TypeTag>
891 if (!this->isOperableAndSolvable() && !this->wellIsStopped())
896 const double dt = simulator.timeStepSize();
897 bool converged = iterateWellEquations(simulator, dt, groupStateHelper, well_state, deferred_logger);
907 auto& ws = well_state.
well(this->indexOfWell());
908 bool thp_control =
false;
909 if (this->well_ecl_.isInjector()) {
910 thp_control = ws.injection_cmode == Well::InjectorCMode::THP;
912 ws.injection_cmode = Well::InjectorCMode::BHP;
913 if (this->well_control_log_.empty()) {
914 this->well_control_log_.push_back(WellInjectorCMode2String(Well::InjectorCMode::THP));
918 thp_control = ws.production_cmode == Well::ProducerCMode::THP;
920 ws.production_cmode = Well::ProducerCMode::BHP;
921 if (this->well_control_log_.empty()) {
922 this->well_control_log_.push_back(WellProducerCMode2String(Well::ProducerCMode::THP));
927 const std::string msg = std::string(
"The newly opened well ") + this->name()
928 + std::string(
" with THP control did not converge during inner iterations, we try again with bhp control");
929 deferred_logger.
debug(msg);
930 converged = this->iterateWellEquations(simulator, dt, groupStateHelper, well_state, deferred_logger);
935 const int max_iter = this->param_.max_welleq_iter_;
936 deferred_logger.
debug(
"Compute initial well solution for well " + this->name() +
". Failed to converge in "
938 well_state = well_state0;
944 template <
typename TypeTag>
954 prepareWellBeforeAssembling(simulator, dt, groupStateHelper, well_state, deferred_logger);
955 assembleWellEqWithoutIteration(simulator, groupStateHelper, dt, well_state, deferred_logger,
961 template <
typename TypeTag>
969 const bool solving_with_zero_rate)
972 const auto& summary_state = simulator.vanguard().summaryState();
973 const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
974 const auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
977 assembleWellEqWithoutIteration(simulator, groupStateHelper, dt, inj_controls, prod_controls, well_state, deferred_logger, solving_with_zero_rate);
982 template<
typename TypeTag>
992 const bool old_well_operable = this->operability_status_.isOperableAndSolvable();
994 if (this->param_.check_well_operability_iter_)
995 checkWellOperability(simulator, well_state, groupStateHelper, deferred_logger);
998 const int iteration_idx = simulator.model().newtonMethod().numIterations();
999 if (iteration_idx < this->param_.max_niter_inner_well_iter_ || this->well_ecl_.isMultiSegment()) {
1000 const auto& ws = well_state.
well(this->indexOfWell());
1001 const bool nonzero_rate_original =
1002 std::any_of(ws.surface_rates.begin(),
1003 ws.surface_rates.begin() + well_state.
numPhases(),
1004 [](
Scalar rate) { return rate != Scalar(0.0); });
1006 this->operability_status_.solvable =
true;
1007 if (number_of_well_reopenings_ >= this->param_.max_well_status_switch_) {
1009 if (number_of_well_reopenings_ == this->param_.max_well_status_switch_) {
1010 const std::string msg = fmt::format(
"well {} is oscillating between open and stop. \n"
1011 "We don't allow for more than {} re-openings "
1012 "and the well is therefore kept stopped.",
1013 this->name(), number_of_well_reopenings_);
1014 deferred_logger.
debug(msg);
1017 changed_to_stopped_this_step_ =
true;
1018 bool converged_zero_rate = this->solveWellWithZeroRate(
1019 simulator, dt, groupStateHelper, well_state, deferred_logger
1021 if (this->param_.shut_unsolvable_wells_ && !converged_zero_rate ) {
1022 this->operability_status_.solvable =
false;
1025 number_of_well_reopenings_++;
1028 bool converged = this->iterateWellEquations(
1029 simulator, dt, groupStateHelper, well_state, deferred_logger
1033 const bool zero_target = this->wellUnderZeroRateTarget(groupStateHelper, deferred_logger);
1034 if (this->wellIsStopped() && !zero_target && nonzero_rate_original) {
1038 this->operability_status_.resetOperability();
1040 deferred_logger.
debug(
" " + this->name() +
" is re-opened after being stopped during local solve");
1041 number_of_well_reopenings_++;
1045 if (this->param_.shut_unsolvable_wells_) {
1046 this->operability_status_.solvable =
false;
1050 if (this->operability_status_.has_negative_potentials) {
1051 auto well_state_copy = well_state;
1052 std::vector<Scalar> potentials;
1054 computeWellPotentials(simulator, well_state_copy, groupStateHelper, potentials, deferred_logger);
1055 }
catch (
const std::exception& e) {
1056 const std::string msg = fmt::format(
"well {}: computeWellPotentials() failed "
1057 "during attempt to recompute potentials for well: ",
1058 this->name(), e.what());
1059 deferred_logger.
info(msg);
1060 this->operability_status_.has_negative_potentials =
true;
1062 auto& ws = well_state.
well(this->indexOfWell());
1064 for (
int p = 0; p < np; ++p) {
1065 ws.well_potentials[p] = std::max(
Scalar{0.0}, potentials[p]);
1068 this->changed_to_open_this_step_ =
false;
1069 changed_to_stopped_this_step_ =
false;
1071 const bool well_operable = this->operability_status_.isOperableAndSolvable();
1072 if (!well_operable) {
1075 this->solveWellWithZeroRate(
1076 simulator, dt, groupStateHelper, well_state, deferred_logger
1078 }
catch (
const std::exception& e) {
1079 const std::string msg = fmt::format(
"well {}: solveWellWithZeroRate() failed "
1080 "during attempt to solve with zero rate for well: ",
1081 this->name(), e.what());
1082 deferred_logger.
info(msg);
1084 auto& ws = well_state.
well(this->indexOfWell());
1086 for (
int p = 0; p < np; ++p) {
1087 ws.surface_rates[p] =
Scalar{0.0};
1090 if (old_well_operable) {
1091 deferred_logger.
debug(
" well " + this->name() +
" gets STOPPED during iteration ");
1092 changed_to_stopped_this_step_ =
true;
1094 }
else if (well_state.
isOpen(this->name())) {
1096 if (!old_well_operable) {
1097 deferred_logger.
debug(
" well " + this->name() +
" gets REVIVED during iteration ");
1098 this->changed_to_open_this_step_ =
true;
1103 template<
typename TypeTag>
1107 if(!this->operability_status_.solvable)
1110 for (
int perfIdx = 0; perfIdx < this->number_of_local_perforations_; ++perfIdx) {
1111 const auto cellIdx = this->cells()[perfIdx];
1112 const auto it = cellRates_.find(cellIdx);
1113 RateVector rates = (it == cellRates_.end()) ? 0.0 : it->second;
1114 for (
auto i=0*RateVector::dimension; i < RateVector::dimension; ++i)
1116 rates[i] += connectionRates_[perfIdx][i];
1118 cellRates_.insert_or_assign(cellIdx, rates);
1122 template<
typename TypeTag>
1126 for (
int perfIdx = 0; perfIdx < this->number_of_local_perforations_; ++perfIdx) {
1127 if (this->cells()[perfIdx] == cellIdx) {
1128 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
1129 return connectionRates_[perfIdx][activeCompIdx].value();
1133 OPM_THROW(std::invalid_argument,
"The well with name " + this->name()
1141 template<
typename TypeTag>
1150 if (!this->param_.check_well_operability_) {
1154 if (this->wellIsStopped() && !changed_to_stopped_this_step_) {
1158 updateWellOperability(simulator, well_state, groupStateHelper, deferred_logger);
1159 if (!this->operability_status_.isOperableAndSolvable()) {
1160 this->operability_status_.use_vfpexplicit =
true;
1161 deferred_logger.
debug(
"EXPLICIT_LOOKUP_VFP",
1162 "well not operable, trying with explicit vfp lookup: " + this->name());
1163 updateWellOperability(simulator, well_state, groupStateHelper, deferred_logger);
1169 template<
typename TypeTag>
1179 const auto& summary_state = simulator.vanguard().summaryState();
1180 const auto& well_name = this->name();
1181 if (!this->wellHasTHPConstraints(summary_state)) {
1182 const std::string msg = fmt::format(
"GLIFT WTEST: Well {} does not have THP constraints", well_name);
1183 deferred_logger.
info(msg);
1186 const auto& schedule = simulator.vanguard().schedule();
1187 const auto report_step_idx = simulator.episodeIndex();
1188 const auto& glo = schedule.glo(report_step_idx);
1189 if (!glo.has_well(well_name)) {
1190 const std::string msg = fmt::format(
1191 "GLIFT WTEST: Well {} : Gas lift not activated: "
1192 "WLIFTOPT is probably missing. Skipping.", well_name);
1193 deferred_logger.
info(msg);
1196 const auto& gl_well = glo.well(well_name);
1199 std::unique_ptr<GasLiftSingleWell> glift =
1200 initializeGliftWellTest_<GasLiftSingleWell>(simulator,
1205 auto [wtest_alq, success] = glift->wellTestALQ();
1207 const auto& unit_system = schedule.getUnits();
1209 well_state.
well(well_name).alq_state.set(wtest_alq);
1211 "GLIFT WTEST: Well {} : Setting ALQ to optimized value = {}",
1212 well_name, unit_system.from_si(UnitSystem::measure::gas_surface_rate, wtest_alq));
1215 if (!gl_well.use_glo()) {
1217 "GLIFT WTEST: Well {} : Gas lift optimization deactivated. Setting ALQ to WLIFTOPT item 3 = {}",
1219 unit_system.from_si(UnitSystem::measure::gas_surface_rate, well_state.
well(well_name).alq_state.get()));
1224 "GLIFT WTEST: Well {} : Gas lift optimization failed, no ALQ set.",
1228 deferred_logger.
info(msg);
1231 template<
typename TypeTag>
1240 if (this->param_.local_well_solver_control_switching_) {
1241 const bool success = updateWellOperabilityFromWellEq(simulator, groupStateHelper, deferred_logger);
1243 this->operability_status_.solvable =
false;
1244 deferred_logger.
debug(
"Operability check using well equations did not converge for well "
1245 + this->name() +
". Mark the well as unsolvable." );
1249 this->operability_status_.resetOperability();
1251 bool thp_controlled = this->isInjector() ? well_state.
well(this->index_of_well_).injection_cmode == Well::InjectorCMode::THP:
1252 well_state.
well(this->index_of_well_).production_cmode == Well::ProducerCMode::THP;
1253 bool bhp_controlled = this->isInjector() ? well_state.
well(this->index_of_well_).injection_cmode == Well::InjectorCMode::BHP:
1254 well_state.
well(this->index_of_well_).production_cmode == Well::ProducerCMode::BHP;
1258 bool check_thp = thp_controlled || this->operability_status_.thp_limit_violated_but_not_switched;
1259 if (check_thp || bhp_controlled) {
1260 updateIPR(simulator, deferred_logger);
1261 checkOperabilityUnderBHPLimit(well_state, simulator, deferred_logger);
1265 checkOperabilityUnderTHPLimit(simulator, well_state, groupStateHelper, deferred_logger);
1269 template<
typename TypeTag>
1278 assert(this->param_.local_well_solver_control_switching_);
1279 this->operability_status_.resetOperability();
1282 const double dt = simulator.timeStepSize();
1286 auto guard = groupStateHelper_copy.
pushWellState(well_state_copy);
1288 bool converged = iterateWellEquations(simulator, dt, groupStateHelper_copy, well_state_copy, deferred_logger);
1292 template<
typename TypeTag>
1300 template<
typename TypeTag>
1310 const auto& well = this->well_ecl_;
1311 const int well_index = this->index_of_well_;
1312 auto& ws = well_state.
well(well_index);
1314 const auto& summaryState = simulator.vanguard().summaryState();
1315 const auto& schedule = simulator.vanguard().schedule();
1319 ws.primaryvar.resize(0);
1321 if (this->wellIsStopped()) {
1322 for (
int p = 0; p<np; ++p) {
1323 ws.surface_rates[p] = 0;
1329 if (this->isInjector() )
1331 const auto& controls = well.injectionControls(summaryState);
1333 InjectorType injectorType = controls.injector_type;
1335 switch (injectorType) {
1336 case InjectorType::WATER:
1338 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1341 case InjectorType::OIL:
1343 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1346 case InjectorType::GAS:
1348 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1352 OPM_DEFLOG_THROW(std::runtime_error,
"Expected WATER, OIL or GAS as type for injectors " + this->name(), deferred_logger );
1355 const auto current = ws.injection_cmode;
1358 case Well::InjectorCMode::RATE:
1360 ws.surface_rates[phasePos] = (1.0 - this->rsRvInj()) * controls.surface_rate;
1361 if(this->rsRvInj() > 0) {
1362 if (injectorType == InjectorType::OIL && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1363 const int gas_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1364 ws.surface_rates[gas_pos] = controls.surface_rate * this->rsRvInj();
1365 }
else if (injectorType == InjectorType::GAS && FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1366 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1367 ws.surface_rates[oil_pos] = controls.surface_rate * this->rsRvInj();
1369 OPM_DEFLOG_THROW(std::runtime_error,
"Expected OIL or GAS as type for injectors when RS/RV (item 10) is non-zero " + this->name(), deferred_logger );
1375 case Well::InjectorCMode::RESV:
1377 std::vector<Scalar> convert_coeff(this->number_of_phases_, 1.0);
1378 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, convert_coeff);
1379 const Scalar coeff = convert_coeff[phasePos];
1380 ws.surface_rates[phasePos] = controls.reservoir_rate/coeff;
1384 case Well::InjectorCMode::THP:
1386 auto rates = ws.surface_rates;
1391 this->getRefDensity(),
1394 ws.thp = this->getTHPConstraint(summaryState);
1399 Scalar total_rate = std::accumulate(rates.begin(), rates.end(), 0.0);
1400 if (total_rate <= 0.0)
1401 ws.surface_rates = ws.well_potentials;
1405 case Well::InjectorCMode::BHP:
1407 ws.bhp = controls.bhp_limit;
1409 for (
int p = 0; p<np; ++p) {
1410 total_rate += ws.surface_rates[p];
1415 if (total_rate <= 0.0)
1416 ws.surface_rates = ws.well_potentials;
1420 case Well::InjectorCMode::GRUP:
1422 assert(well.isAvailableForGroupControl());
1423 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
1424 const Scalar efficiencyFactor = well.getEfficiencyFactor() *
1425 well_state[well.name()].efficiency_scaling_factor;
1426 std::optional<Scalar> target =
1427 this->getGroupInjectionTargetRate(group,
1433 ws.surface_rates[phasePos] = *target;
1436 case Well::InjectorCMode::CMODE_UNDEFINED:
1438 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name(), deferred_logger );
1448 ws.surface_rates[phasePos] = std::max(
Scalar{1.e-7}, ws.surface_rates[phasePos]);
1451 ws.bhp = controls.bhp_limit;
1457 const auto current = ws.production_cmode;
1458 const auto& controls = well.productionControls(summaryState);
1460 case Well::ProducerCMode::ORAT:
1462 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1463 Scalar current_rate = -ws.surface_rates[oil_pos];
1466 if (current_rate > 0.0) {
1467 for (
int p = 0; p<np; ++p) {
1468 ws.surface_rates[p] *= controls.oil_rate/current_rate;
1471 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1472 double control_fraction = fractions[oil_pos];
1473 if (control_fraction != 0.0) {
1474 for (
int p = 0; p<np; ++p) {
1475 ws.surface_rates[p] = - fractions[p] * controls.oil_rate/control_fraction;
1481 case Well::ProducerCMode::WRAT:
1483 const int water_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1484 Scalar current_rate = -ws.surface_rates[water_pos];
1487 if (current_rate > 0.0) {
1488 for (
int p = 0; p<np; ++p) {
1489 ws.surface_rates[p] *= controls.water_rate/current_rate;
1492 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1493 const Scalar control_fraction = fractions[water_pos];
1494 if (control_fraction != 0.0) {
1495 for (
int p = 0; p<np; ++p) {
1496 ws.surface_rates[p] = - fractions[p] * controls.water_rate / control_fraction;
1502 case Well::ProducerCMode::GRAT:
1504 const int gas_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1505 Scalar current_rate = -ws.surface_rates[gas_pos];
1508 if (current_rate > 0.0) {
1509 for (
int p = 0; p<np; ++p) {
1510 ws.surface_rates[p] *= controls.gas_rate/current_rate;
1513 const std::vector<Scalar > fractions = initialWellRateFractions(simulator, well_state);
1514 const Scalar control_fraction = fractions[gas_pos];
1515 if (control_fraction != 0.0) {
1516 for (
int p = 0; p<np; ++p) {
1517 ws.surface_rates[p] = - fractions[p] * controls.gas_rate / control_fraction;
1525 case Well::ProducerCMode::LRAT:
1527 const int water_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1528 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1529 Scalar current_rate = - ws.surface_rates[water_pos]
1530 - ws.surface_rates[oil_pos];
1533 if (current_rate > 0.0) {
1534 for (
int p = 0; p<np; ++p) {
1535 ws.surface_rates[p] *= controls.liquid_rate/current_rate;
1538 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1539 const Scalar control_fraction = fractions[water_pos] + fractions[oil_pos];
1540 if (control_fraction != 0.0) {
1541 for (
int p = 0; p<np; ++p) {
1542 ws.surface_rates[p] = - fractions[p] * controls.liquid_rate / control_fraction;
1548 case Well::ProducerCMode::CRAT:
1551 fmt::format(
"CRAT control not supported, well {}", this->name()),
1554 case Well::ProducerCMode::RESV:
1556 std::vector<Scalar> convert_coeff(this->number_of_phases_, 1.0);
1557 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, ws.surface_rates, convert_coeff);
1558 Scalar total_res_rate = 0.0;
1559 for (
int p = 0; p<np; ++p) {
1560 total_res_rate -= ws.surface_rates[p] * convert_coeff[p];
1562 if (controls.prediction_mode) {
1565 if (total_res_rate > 0.0) {
1566 for (
int p = 0; p<np; ++p) {
1567 ws.surface_rates[p] *= controls.resv_rate/total_res_rate;
1570 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1571 for (
int p = 0; p<np; ++p) {
1572 ws.surface_rates[p] = - fractions[p] * controls.resv_rate / convert_coeff[p];
1576 std::vector<Scalar> hrates(this->number_of_phases_,0.);
1577 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
1578 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1579 hrates[phase_pos] = controls.water_rate;
1581 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1582 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1583 hrates[phase_pos] = controls.oil_rate;
1585 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1586 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1587 hrates[phase_pos] = controls.gas_rate;
1589 std::vector<Scalar> hrates_resv(this->number_of_phases_,0.);
1590 this->rateConverter_.calcReservoirVoidageRates( 0, this->pvtRegionIdx_, hrates, hrates_resv);
1591 Scalar target = std::accumulate(hrates_resv.begin(), hrates_resv.end(), 0.0);
1594 if (total_res_rate > 0.0) {
1595 for (
int p = 0; p<np; ++p) {
1596 ws.surface_rates[p] *= target/total_res_rate;
1599 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1600 for (
int p = 0; p<np; ++p) {
1601 ws.surface_rates[p] = - fractions[p] * target / convert_coeff[p];
1607 case Well::ProducerCMode::BHP:
1609 ws.bhp = controls.bhp_limit;
1611 for (
int p = 0; p<np; ++p) {
1612 total_rate -= ws.surface_rates[p];
1617 if (total_rate <= 0.0){
1618 for (
int p = 0; p<np; ++p) {
1619 ws.surface_rates[p] = -ws.well_potentials[p];
1624 case Well::ProducerCMode::THP:
1626 const bool update_success = updateWellStateWithTHPTargetProd(simulator, well_state, groupStateHelper, deferred_logger);
1628 if (!update_success) {
1632 auto rates = ws.surface_rates;
1633 this->adaptRatesForVFP(rates);
1635 well_state, rates, well, summaryState, this->getRefDensity(), deferred_logger);
1637 ws.thp = this->getTHPConstraint(summaryState);
1641 const Scalar total_rate = -std::accumulate(rates.begin(), rates.end(), 0.0);
1642 if (total_rate <= 0.0) {
1643 for (
int p = 0; p < this->number_of_phases_; ++p) {
1644 ws.surface_rates[p] = -ws.well_potentials[p];
1650 case Well::ProducerCMode::GRUP:
1652 assert(well.isAvailableForGroupControl());
1653 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
1654 const Scalar efficiencyFactor = well.getEfficiencyFactor() *
1655 well_state[well.name()].efficiency_scaling_factor;
1656 Scalar scale = this->getGroupProductionTargetRate(group,
1663 for (
int p = 0; p<np; ++p) {
1664 ws.surface_rates[p] *= scale;
1666 ws.trivial_group_target =
false;
1670 ws.trivial_group_target =
true;
1674 case Well::ProducerCMode::CMODE_UNDEFINED:
1677 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name() , deferred_logger);
1683 ws.bhp = controls.bhp_limit;
1688 template<
typename TypeTag>
1694 const auto& well_state = groupStateHelper.
wellState();
1696 const bool isGroupControlled = this->wellUnderGroupControl(well_state.well(this->index_of_well_));
1697 if (!isGroupControlled) {
1699 const auto& summaryState = groupStateHelper.
summaryState();
1700 return this->wellUnderZeroRateTargetIndividual(summaryState, well_state);
1702 return this->wellUnderZeroGroupRateTarget(groupStateHelper, deferred_logger, isGroupControlled);
1706 template <
typename TypeTag>
1710 const std::optional<bool> group_control)
const
1712 const auto& well_state = groupStateHelper.
wellState();
1714 const bool isGroupControlled = group_control.value_or(this->wellUnderGroupControl(well_state.well(this->index_of_well_)));
1715 if (isGroupControlled) {
1716 return this->zeroGroupRateTarget(groupStateHelper, deferred_logger);
1721 template<
typename TypeTag>
1729 return this->wellIsStopped()
1730 || this->wellUnderZeroRateTarget(groupStateHelper, deferred_logger);
1733 template<
typename TypeTag>
1734 std::vector<typename WellInterface<TypeTag>::Scalar>
1740 const int np = this->number_of_phases_;
1741 std::vector<Scalar> scaling_factor(np);
1742 const auto& ws = well_state.
well(this->index_of_well_);
1744 Scalar total_potentials = 0.0;
1745 for (
int p = 0; p<np; ++p) {
1746 total_potentials += ws.well_potentials[p];
1748 if (total_potentials > 0) {
1749 for (
int p = 0; p<np; ++p) {
1750 scaling_factor[p] = ws.well_potentials[p] / total_potentials;
1752 return scaling_factor;
1757 const int nperf = this->number_of_local_perforations_;
1758 for (
int perf = 0; perf < nperf; ++perf) {
1759 total_tw += this->well_index_[perf];
1761 total_tw = this->parallelWellInfo().communication().sum(total_tw);
1763 for (
int perf = 0; perf < nperf; ++perf) {
1764 const int cell_idx = this->well_cells_[perf];
1765 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
1766 const auto& fs = intQuants.fluidState();
1767 const Scalar well_tw_fraction = this->well_index_[perf] / total_tw;
1768 Scalar total_mobility = 0.0;
1769 for (
int p = 0; p < np; ++p) {
1770 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
1771 total_mobility += fs.invB(canonical_phase_idx).value() * intQuants.mobility(canonical_phase_idx).value();
1773 for (
int p = 0; p < np; ++p) {
1774 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
1775 scaling_factor[p] += well_tw_fraction * fs.invB(canonical_phase_idx).value() * intQuants.mobility(canonical_phase_idx).value() / total_mobility;
1778 return scaling_factor;
1783 template <
typename TypeTag>
1790 assert(this->isProducer());
1794 auto& ws = well_state.
well(this->index_of_well_);
1795 int nonzero_rate_index = -1;
1796 const Scalar floating_point_error_epsilon = 1e-14;
1797 for (
int p = 0; p < this->number_of_phases_; ++p) {
1798 if (std::abs(ws.surface_rates[p]) > floating_point_error_epsilon) {
1799 if (nonzero_rate_index == -1) {
1800 nonzero_rate_index = p;
1809 std::vector<Scalar> well_q_s(this->number_of_phases_, 0.0);
1810 bool rates_evaluated_at_1bar =
false;
1812 const auto& summary_state = simulator.vanguard().summaryState();
1813 const auto& prod_controls = this->well_ecl_.productionControls(summary_state);
1814 const double bhp_limit = std::max(prod_controls.bhp_limit, 1.0 * unit::barsa);
1815 this->computeWellRatesWithBhp(simulator, bhp_limit, well_q_s, deferred_logger);
1817 rates_evaluated_at_1bar = (bhp_limit < 1.1 * unit::barsa);
1819 if (std::any_of(well_q_s.begin(), well_q_s.end(), [](
Scalar q) { return q > 0.0; })) {
1821 if (!rates_evaluated_at_1bar) {
1822 this->computeWellRatesWithBhp(simulator, 1.0 * unit::barsa, well_q_s, deferred_logger);
1823 rates_evaluated_at_1bar =
true;
1826 for (
auto& q : well_q_s) {
1827 q = std::min(q,
Scalar{0.0});
1832 if (nonzero_rate_index == -1) {
1836 const Scalar factor = rates_evaluated_at_1bar ? 0.5 : 1.0;
1837 for (
int p = 0; p < this->number_of_phases_; ++p) {
1838 ws.surface_rates[p] = factor * well_q_s[p];
1847 const Scalar initial_nonzero_rate = ws.surface_rates[nonzero_rate_index];
1848 const Scalar computed_rate = well_q_s[nonzero_rate_index];
1849 if (std::abs(initial_nonzero_rate) < std::abs(computed_rate)) {
1851 const Scalar factor = initial_nonzero_rate / computed_rate;
1852 assert(factor < 1.0);
1853 for (
int p = 0; p < this->number_of_phases_; ++p) {
1855 if (p != nonzero_rate_index) {
1856 ws.surface_rates[p] = factor * well_q_s[p];
1865 for (
int p = 0; p < this->number_of_phases_; ++p) {
1866 ws.surface_rates[p] = well_q_s[p];
1870 template <
typename TypeTag>
1871 template<
class Value>
1874 getTw(std::vector<Value>& Tw,
1877 const Value& trans_mult,
1880 OPM_TIMEFUNCTION_LOCAL(Subsystem::Wells);
1883 if (
static_cast<std::size_t
>(perf) >= this->well_cells_.size()) {
1884 OPM_THROW(std::invalid_argument,
"The perforation index exceeds the size of the local containers - possibly wellIndex was called with a global instead of a local perforation index!");
1887 if constexpr (! Indices::gasEnabled) {
1891 const auto& wdfac = this->well_ecl_.getWDFAC();
1893 if (! wdfac.useDFactor() || (this->well_index_[perf] == 0.0)) {
1897 const Scalar d = this->computeConnectionDFactor(perf, intQuants, ws);
1904 const auto& connection = this->well_ecl_.getConnections()[ws.
perf_data.ecl_index[perf]];
1905 const Scalar Kh = connection.Kh();
1906 const Scalar scaling = 3.141592653589 * Kh * connection.wpimult();
1907 const unsigned gas_comp_idx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
1910 const Scalar cell_pressure = getValue(intQuants.fluidState().pressure(FluidSystem::gasPhaseIdx));
1911 const Scalar drawdown = cell_pressure - connection_pressure;
1912 const Scalar invB = getValue(intQuants.fluidState().invB(FluidSystem::gasPhaseIdx));
1913 const Scalar mob_g = getValue(intQuants.mobility(FluidSystem::gasPhaseIdx)) * invB;
1915 const Scalar b = 2 * scaling / getValue(Tw[gas_comp_idx]);
1916 const Scalar c = -2 * scaling * mob_g * drawdown;
1918 Scalar consistent_Q = -1.0e20;
1920 const Scalar r2n = b*b + 4*a*c;
1922 const Scalar rn = std::sqrt(r2n);
1923 const Scalar xn1 = (b-rn)*0.5/a;
1927 const Scalar xn2 = (b+rn)*0.5/a;
1928 if (xn2 <= 0 && xn2 > consistent_Q) {
1934 const Scalar r2p = b*b - 4*a*c;
1936 const Scalar rp = std::sqrt(r2p);
1937 const Scalar xp1 = (rp-b)*0.5/a;
1938 if (xp1 > 0 && xp1 < consistent_Q) {
1941 const Scalar xp2 = -(rp+b)*0.5/a;
1942 if (xp2 > 0 && xp2 < consistent_Q) {
1946 Tw[gas_comp_idx] = 1.0 / (1.0 / (trans_mult * this->well_index_[perf]) + (consistent_Q/2 * d / scaling));
1949 template <
typename TypeTag>
1955 if (! this->well_ecl_.getWDFAC().useDFactor()) {
1959 auto& d_factor = ws.
perf_data.connection_d_factor;
1961 for (
int perf = 0; perf < this->number_of_local_perforations_; ++perf) {
1962 const int cell_idx = this->well_cells_[perf];
1963 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
1965 d_factor[perf] = this->computeConnectionDFactor(perf, intQuants, ws);
1969 template <
typename TypeTag>
1976 auto rhoGS = [regIdx = this->pvtRegionIdx()]() {
1977 return FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, regIdx);
1981 auto gas_visc = [connection_pressure = ws.
perf_data.pressure[perf],
1983 regIdx = this->pvtRegionIdx(), &intQuants]()
1985 const auto rv = getValue(intQuants.fluidState().Rv());
1987 const auto& gasPvt = FluidSystem::gasPvt();
1992 const Scalar rv_sat = gasPvt.saturatedOilVaporizationFactor
1993 (regIdx, temperature, connection_pressure);
1995 if (! (rv < rv_sat)) {
1996 return gasPvt.saturatedViscosity(regIdx, temperature,
1997 connection_pressure);
2000 return gasPvt.viscosity(regIdx, temperature, connection_pressure,
2001 rv, getValue(intQuants.fluidState().Rvw()));
2004 const auto& connection = this->well_ecl_.getConnections()
2007 return this->well_ecl_.getWDFAC().getDFactor(rhoGS, gas_visc, connection);
2011 template <
typename TypeTag>
2017 auto connCF = [&connIx = std::as_const(ws.
perf_data.ecl_index),
2018 &conns = this->well_ecl_.getConnections()]
2021 return conns[connIx[perf]].CF();
2024 auto obtain = [](
const Eval& value)
2026 return getValue(value);
2029 auto& tmult = ws.
perf_data.connection_compaction_tmult;
2030 auto& ctf = ws.
perf_data.connection_transmissibility_factor;
2032 for (
int perf = 0; perf < this->number_of_local_perforations_; ++perf) {
2033 const int cell_idx = this->well_cells_[perf];
2035 getTransMult(trans_mult, simulator, cell_idx, obtain);
2036 tmult[perf] = trans_mult;
2038 ctf[perf] = connCF(perf) * tmult[perf];
2043 template<
typename TypeTag>
2047 if constexpr (Indices::oilEnabled) {
2048 return fs.pressure(FluidSystem::oilPhaseIdx);
2049 }
else if constexpr (Indices::gasEnabled) {
2050 return fs.pressure(FluidSystem::gasPhaseIdx);
2052 return fs.pressure(FluidSystem::waterPhaseIdx);
2056 template <
typename TypeTag>
2057 template<
class Value,
class Callback>
2063 Callback& extendEval)
const
2065 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2066 trans_mult = simulator.problem().template wellTransMultiplier<Value>(intQuants, cell_idx, extendEval);
2069 template <
typename TypeTag>
2070 template<
class Value,
class Callback>
2074 const int local_perf_index,
2075 std::vector<Value>& mob,
2076 Callback& extendEval,
2079 auto relpermArray = []()
2081 if constexpr (std::is_same_v<Value, Scalar>) {
2082 return std::array<Scalar,3>{};
2084 return std::array<Eval,3>{};
2087 if (
static_cast<std::size_t
>(local_perf_index) >= this->well_cells_.size()) {
2088 OPM_THROW(std::invalid_argument,
"The perforation index exceeds the size of the local containers - possibly getMobility was called with a global instead of a local perforation index!");
2090 const int cell_idx = this->well_cells_[local_perf_index];
2091 assert (
int(mob.size()) == this->num_conservation_quantities_);
2092 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2093 const auto& materialLawManager = simulator.problem().materialLawManager();
2097 const int satid = this->saturation_table_number_[local_perf_index] - 1;
2098 const int satid_elem = materialLawManager->satnumRegionIdx(cell_idx);
2099 if (satid == satid_elem) {
2100 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2101 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2105 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2106 mob[activeCompIdx] = extendEval(intQuants.mobility(phaseIdx));
2108 if constexpr (has_solvent) {
2109 mob[Indices::contiSolventEqIdx] = extendEval(intQuants.solventMobility());
2112 const auto& paramsCell = materialLawManager->connectionMaterialLawParams(satid, cell_idx);
2113 auto relativePerms = relpermArray();
2114 MaterialLaw::relativePermeabilities(relativePerms, paramsCell, intQuants.fluidState());
2117 materialLawManager->connectionMaterialLawParams(satid_elem, cell_idx);
2120 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2121 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2125 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2126 mob[activeCompIdx] = extendEval(relativePerms[phaseIdx] / intQuants.fluidState().viscosity(phaseIdx));
2130 if constexpr (has_solvent) {
2131 OPM_DEFLOG_THROW(std::runtime_error,
"individual mobility for wells does not work in combination with solvent", deferred_logger);
2135 if (this->isInjector() && !this->inj_fc_multiplier_.empty()) {
2136 const auto perf_ecl_index = this->perforationData()[local_perf_index].ecl_index;
2137 const auto& connections = this->well_ecl_.getConnections();
2138 const auto& connection = connections[perf_ecl_index];
2139 if (connection.filterCakeActive()) {
2140 std::transform(mob.begin(), mob.end(), mob.begin(),
2141 [mult = this->inj_fc_multiplier_[local_perf_index] ](
const auto val)
2142 { return val * mult; });
2148 template<
typename TypeTag>
2157 const auto& summary_state = simulator.vanguard().summaryState();
2159 auto bhp_at_thp_limit = computeBhpAtThpLimitProdWithAlq(
2160 simulator, groupStateHelper, summary_state, this->getALQ(well_state), deferred_logger,
false);
2161 if (bhp_at_thp_limit) {
2162 std::vector<Scalar> rates(this->number_of_phases_, 0.0);
2163 if (thp_update_iterations) {
2164 computeWellRatesWithBhpIterations(simulator, *bhp_at_thp_limit,
2165 groupStateHelper, rates, deferred_logger);
2167 computeWellRatesWithBhp(simulator, *bhp_at_thp_limit,
2168 rates, deferred_logger);
2170 auto& ws = well_state.
well(this->name());
2171 ws.surface_rates = rates;
2172 ws.bhp = *bhp_at_thp_limit;
2173 ws.thp = this->getTHPConstraint(summary_state);
2180 template<
typename TypeTag>
2181 std::optional<typename WellInterface<TypeTag>::Scalar>
2186 const SummaryState& summary_state,
2192 const auto& groupStateHelper = simulator.problem().wellModel().groupStateHelper();
2194 auto well_guard = groupStateHelper_copy.
pushWellState(well_state_copy);
2195 const double dt = simulator.timeStepSize();
2196 const bool converged = this->solveWellWithBhp(
2197 simulator, dt, bhp, groupStateHelper_copy, well_state_copy, deferred_logger
2201 auto rates = well_state_copy.
well(this->index_of_well_).surface_rates;
2203 for (std::size_t p = 0; p < rates.size(); ++p) {
2204 zero_rates &= rates[p] == 0.0;
2208 if (zero_rates || !converged) {
2209 return this->computeBhpAtThpLimitProdWithAlq(simulator, groupStateHelper_copy, summary_state, alq_value, deferred_logger,
false);
2211 this->updateIPRImplicit(simulator, groupStateHelper_copy, well_state_copy, deferred_logger);
2212 this->adaptRatesForVFP(rates);
2216 template <
typename TypeTag>
2221 const std::vector<Scalar>& mobility,
2224 const int np = this->number_of_phases_;
2225 for (
int p = 0; p < np; ++p) {
2228 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
2229 const auto connMob =
2230 mobility[FluidSystem::activePhaseToActiveCompIdx(p)] * fs.invB(canonical_phase_idx).value();
2232 connPI[p] = connPICalc(connMob);
2235 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) &&
2236 FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx))
2238 const auto io = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
2239 const auto ig = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
2241 const auto vapoil = connPI[ig] * fs.Rv().value();
2242 const auto disgas = connPI[io] * fs.Rs().value();
2244 connPI[io] += vapoil;
2245 connPI[ig] += disgas;
2250 template <
typename TypeTag>
2254 const Phase preferred_phase,
2256 const std::vector<Scalar>& mobility,
2261 if (preferred_phase == Phase::GAS) {
2262 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
2264 else if (preferred_phase == Phase::OIL) {
2265 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
2267 else if (preferred_phase == Phase::WATER) {
2268 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
2272 fmt::format(
"Unsupported Injector Type ({}) "
2273 "for well {} during connection I.I. calculation",
2274 static_cast<int>(preferred_phase), this->name()),
2278 const auto mt = std::accumulate(mobility.begin(), mobility.end(), 0.0);
2279 const int canonicalPhaseIdx = FluidSystem::activeToCanonicalPhaseIdx(phase_pos);
2280 connII[phase_pos] = connIICalc(mt * fs.invB(canonicalPhaseIdx).value());
2283 template<
typename TypeTag>
2284 template<
class GasLiftSingleWell>
2285 std::unique_ptr<GasLiftSingleWell>
2294 auto& comm = simulator.vanguard().grid().comm();
2295 ecl_well_map.try_emplace(this->name(), &(this->wellEcl()), this->indexOfWell());
2298 simulator.vanguard().schedule(),
2299 simulator.vanguard().summaryState(),
2300 simulator.episodeIndex(),
2301 simulator.model().newtonMethod().numIterations(),
2310 std::set<int> sync_groups;
2311 const auto& summary_state = simulator.vanguard().summaryState();
2312 return std::make_unique<GasLiftSingleWell>(*
this,
#define OPM_DEFLOG_THROW(Exception, message, deferred_logger)
Definition: DeferredLoggingErrorHelpers.hpp:45
Definition: DeferredLogger.hpp:57
void info(const std::string &tag, const std::string &message)
void warning(const std::string &tag, const std::string &message)
void debug(const std::string &tag, const std::string &message)
Definition: GasLiftGroupInfo.hpp:46
Definition: GroupStateHelper.hpp:53
GroupState< Scalar > & groupState() const
Definition: GroupStateHelper.hpp:180
const SummaryState & summaryState() const
Definition: GroupStateHelper.hpp:257
const WellState< Scalar, IndexTraits > & wellState() const
Definition: GroupStateHelper.hpp:306
WellStateGuard pushWellState(WellState< Scalar, IndexTraits > &well_state)
Definition: GroupStateHelper.hpp:195
GroupStateGuard pushGroupState(GroupState< Scalar > &group_state)
Definition: GroupStateHelper.hpp:190
Definition: GroupState.hpp:41
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:198
Definition: SingleWellState.hpp:43
Scalar temperature
Definition: SingleWellState.hpp:105
PerfData< Scalar > perf_data
Definition: SingleWellState.hpp:128
Class for computing BHP limits.
Definition: WellBhpThpCalculator.hpp:41
Scalar calculateMinimumBhpFromThp(const WellState< Scalar, IndexTraits > &well_state, const Well &well, const SummaryState &summaryState, const Scalar rho) const
Scalar mostStrictBhpFromBhpLimits(const SummaryState &summaryState) const
Obtain the most strict BHP from BHP limits.
bool isStableSolution(const WellState< Scalar, IndexTraits > &well_state, const Well &well, const std::vector< Scalar > &rates, const SummaryState &summaryState) const
EvalWell calculateBhpFromThp(const WellState< Scalar, IndexTraits > &well_state, const std::vector< EvalWell > &rates, const Well &well, const SummaryState &summaryState, const Scalar rho, DeferredLogger &deferred_logger) const
std::optional< Scalar > estimateStableBhp(const WellState< Scalar, IndexTraits > &well_state, const Well &well, const std::vector< Scalar > &rates, const Scalar rho, const SummaryState &summaryState) const
Well well_ecl_
Definition: WellInterfaceGeneric.hpp:304
int number_of_local_perforations_
Definition: WellInterfaceGeneric.hpp:340
FluidSystem::Scalar wsolvent_
Definition: WellInterfaceGeneric.hpp:380
Definition: WellInterfaceIndices.hpp:34
bool solveWellWithOperabilityCheck(const Simulator &simulator, const double dt, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, const GroupStateHelperType &groupStateHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:589
Scalar woxygen() const
Definition: WellInterface_impl.hpp:165
BlackOilFluidState< Eval, FluidSystem, energyModuleType==EnergyModules::ConstantTemperature,(energyModuleType==EnergyModules::FullyImplicitThermal||energyModuleType==EnergyModules::SequentialImplicitThermal), Indices::compositionSwitchIdx >=0, has_watVapor, has_brine, has_saltPrecip, has_disgas_in_water, Indices::numPhases > FluidState
Definition: WellInterface.hpp:139
IndividualOrGroup
Definition: WellInterface.hpp:259
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: WellInterface.hpp:82
void assembleWellEqWithoutIteration(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, const double dt, WellStateType &well_state, DeferredLogger &deferred_logger, const bool solving_with_zero_rate)
Definition: WellInterface_impl.hpp:964
Scalar computeConnectionDFactor(const int perf, const IntensiveQuantities &intQuants, const SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:1972
void checkWellOperability(const Simulator &simulator, const WellStateType &well_state, const GroupStateHelperType &groupStateHelper, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:1144
std::optional< Scalar > computeBhpAtThpLimitProdWithAlqUsingIPR(const Simulator &simulator, const WellStateType &well_state, Scalar bhp, const SummaryState &summary_state, const Scalar alq_value, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:2183
void wellTesting(const Simulator &simulator, const double simulation_time, const GroupStateHelperType &groupStateHelper, WellStateType &well_state, WellTestState &welltest_state, GLiftEclWells &ecl_well_map, std::map< std::string, double > &open_times, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:395
typename WellInterfaceFluidSystem< FluidSystem >::RateConverterType RateConverterType
Definition: WellInterface.hpp:105
Scalar wfoam() const
Definition: WellInterface_impl.hpp:127
void getTransMult(Value &trans_mult, const Simulator &simulator, const int cell_idx, Callback &extendEval) const
Definition: WellInterface_impl.hpp:2060
std::vector< RateVector > connectionRates_
Definition: WellInterface.hpp:388
void computeConnLevelProdInd(const FluidState &fs, const std::function< Scalar(const Scalar)> &connPICalc, const std::vector< Scalar > &mobility, Scalar *connPI) const
Definition: WellInterface_impl.hpp:2219
bool iterateWellEquations(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:521
void gliftBeginTimeStepWellTestUpdateALQ(const Simulator &simulator, WellStateType &well_state, const GroupState< Scalar > &group_state, GLiftEclWells &ecl_well_map, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:1172
Scalar volumetricSurfaceRateForConnection(int cellIdx, int phaseIdx) const
Definition: WellInterface_impl.hpp:1124
virtual void init(const std::vector< Scalar > &depth_arg, const Scalar gravity_arg, const std::vector< Scalar > &B_avg, const bool changed_to_open_this_step)
Definition: WellInterface_impl.hpp:95
void getTw(std::vector< Value > &wi, const int perf, const IntensiveQuantities &intQuants, const Value &trans_mult, const SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:1874
void getMobility(const Simulator &simulator, const int local_perf_index, std::vector< Value > &mob, Callback &extendEval, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:2073
GetPropType< TypeTag, Properties::IntensiveQuantities > IntensiveQuantities
Definition: WellInterface.hpp:87
bool wellUnderZeroGroupRateTarget(const GroupStateHelperType &groupStateHelper, DeferredLogger &deferred_logger, const std::optional< bool > group_control=std::nullopt) const
Definition: WellInterface_impl.hpp:1708
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: WellInterface.hpp:83
bool updateWellStateWithTHPTargetProd(const Simulator &simulator, WellStateType &well_state, const GroupStateHelperType &groupStateHelper, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:2151
std::vector< Scalar > initialWellRateFractions(const Simulator &ebosSimulator, const WellStateType &well_state) const
Definition: WellInterface_impl.hpp:1736
virtual void updateWellStateWithTarget(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1303
void updateConnectionDFactor(const Simulator &simulator, SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:1952
Eval getPerfCellPressure(const FluidState &fs) const
Definition: WellInterface_impl.hpp:2045
void initializeProducerWellState(const Simulator &simulator, WellStateType &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1786
void updateWellOperability(const Simulator &simulator, const WellStateType &well_state, const GroupStateHelperType &groupStateHelper, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:1234
bool updateWellControl(const Simulator &simulator, const IndividualOrGroup iog, const GroupStateHelperType &groupStateHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:189
void addCellRates(std::map< int, RateVector > &cellRates_) const
Definition: WellInterface_impl.hpp:1105
bool updateWellControlAndStatusLocalIteration(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, const Scalar WQTotal, WellStateType &well_state, DeferredLogger &deferred_logger, const bool fixed_control, const bool fixed_status, const bool solving_with_zero_rate)
Definition: WellInterface_impl.hpp:277
bool wellUnderZeroRateTarget(const GroupStateHelperType &groupStateHelper, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1691
typename Base::ModelParameters ModelParameters
Definition: WellInterface.hpp:111
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: WellInterface.hpp:84
static constexpr bool has_solvent
Definition: WellInterface.hpp:113
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: WellInterface.hpp:90
void updateConnectionTransmissibilityFactor(const Simulator &simulator, SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:2014
void computeConnLevelInjInd(const FluidState &fs, const Phase preferred_phase, const std::function< Scalar(const Scalar)> &connIICalc, const std::vector< Scalar > &mobility, Scalar *connII, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:2253
typename GasLiftGroupInfo< Scalar, IndexTraits >::GLiftEclWells GLiftEclWells
Definition: WellInterface.hpp:92
std::unique_ptr< GasLiftSingleWell > initializeGliftWellTest_(const Simulator &simulator, WellStateType &well_state, const GroupState< Scalar > &group_state, GLiftEclWells &ecl_well_map, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:2287
Scalar wsalt() const
Definition: WellInterface_impl.hpp:141
bool solveWellWithZeroRate(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:797
bool updateWellOperabilityFromWellEq(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:1272
typename Base::Eval Eval
Definition: WellInterface.hpp:96
bool stoppedOrZeroRateTarget(const GroupStateHelperType &groupStateHelper, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1724
WellInterface(const Well &well, const ParallelWellInfo< Scalar > &pw_info, const int time_step, const ModelParameters ¶m, const RateConverterType &rate_converter, const int pvtRegionIdx, const int num_conservation_quantities, const int num_phases, const int index_of_well, const std::vector< PerforationData< Scalar > > &perf_data)
Constructor.
Definition: WellInterface_impl.hpp:58
void solveWellEquation(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:885
Scalar wpolymer() const
Definition: WellInterface_impl.hpp:111
GetPropType< TypeTag, Properties::Indices > Indices
Definition: WellInterface.hpp:86
bool solveWellForTesting(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:830
Scalar wurea() const
Definition: WellInterface_impl.hpp:177
Scalar wmicrobes() const
Definition: WellInterface_impl.hpp:153
void prepareWellBeforeAssembling(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:985
virtual void scaleSegmentRatesAndPressure(WellStateType &well_state) const
Definition: WellInterface_impl.hpp:1295
std::optional< Scalar > estimateOperableBhp(const Simulator &ebos_simulator, const double dt, const GroupStateHelperType &groupStateHelper, const SummaryState &summary_state, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:709
bool solveWellWithBhp(const Simulator &simulator, const double dt, const Scalar bhp, const GroupStateHelperType &groupStateHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:747
static constexpr bool has_zFraction
Definition: WellInterface.hpp:114
void assembleWellEq(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:947
Definition: WellState.hpp:66
constexpr int numPhases() const
The number of phases present.
Definition: WellState.hpp:249
const SingleWellState< Scalar, IndexTraits > & well(std::size_t well_index) const
Definition: WellState.hpp:290
bool isOpen(const std::string &name) const
Definition: WellState.hpp:197
@ NONE
Definition: DeferredLogger.hpp:46
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Phase
Phase indices for reservoir coupling, we currently only support black-oil phases (oil,...
Definition: ReservoirCoupling.hpp:141
Definition: blackoilbioeffectsmodules.hh:43
std::string to_string(const ConvergenceReport::ReservoirFailure::Type t)
Static data associated with a well perforation.
Definition: PerforationData.hpp:30