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(simulator, well_state, 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 wgHelper, schedule, summaryState,
true, well_state, deferred_logger
240 assert(iog == IndividualOrGroup::Both);
241 changed = this->checkConstraints(wgHelper, 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, wgHelper, well_state, deferred_logger);
268 updatePrimaryVariables(simulator, well_state, 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)
288 const auto& summary_state = simulator.vanguard().summaryState();
289 const auto& schedule = simulator.vanguard().schedule();
290 auto& ws = well_state.
well(this->index_of_well_);
292 if (this->isInjector()) {
293 from = WellInjectorCMode2String(ws.injection_cmode);
295 from = WellProducerCMode2String(ws.production_cmode);
297 const bool oscillating = std::count(this->well_control_log_.begin(), this->well_control_log_.end(), from) >= this->param_.max_number_of_well_switches_;
299 if (oscillating || this->wellUnderZeroRateTarget(simulator, well_state, deferred_logger) || !(well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
303 const Scalar sgn = this->isInjector() ? 1.0 : -1.0;
304 if (!this->wellIsStopped()){
305 if (wqTotal*sgn <= 0.0 && !fixed_status){
309 bool changed =
false;
310 if (!fixed_control) {
315 const bool hasGroupControl = this->isInjector() ? inj_controls.hasControl(Well::InjectorCMode::GRUP) :
316 prod_controls.hasControl(Well::ProducerCMode::GRUP);
317 bool isGroupControl = ws.production_cmode == Well::ProducerCMode::GRUP || ws.injection_cmode == Well::InjectorCMode::GRUP;
318 if (! (isGroupControl && !this->param_.check_group_constraints_inner_well_iterations_)) {
319 changed = this->checkIndividualConstraints(ws, summary_state, deferred_logger, inj_controls, prod_controls);
321 if (hasGroupControl && this->param_.check_group_constraints_inner_well_iterations_) {
322 changed = changed || this->checkGroupConstraints(
323 wgHelper, schedule, summary_state,
false, well_state, deferred_logger
328 const bool thp_controlled = this->isInjector() ? ws.injection_cmode == Well::InjectorCMode::THP :
329 ws.production_cmode == Well::ProducerCMode::THP;
331 ws.thp = this->getTHPConstraint(summary_state);
334 updateWellStateWithTarget(simulator, wgHelper, well_state, deferred_logger);
336 updatePrimaryVariables(simulator, well_state, deferred_logger);
341 }
else if (!fixed_status){
343 const Scalar bhp = well_state.
well(this->index_of_well_).bhp;
344 Scalar prod_limit = prod_controls.bhp_limit;
345 Scalar inj_limit = inj_controls.bhp_limit;
346 const bool has_thp = this->wellHasTHPConstraints(summary_state);
348 std::vector<Scalar> rates(this->num_conservation_quantities_);
349 if (this->isInjector()){
351 calculateBhpFromThp(well_state, rates,
354 this->getRefDensity(),
356 inj_limit = std::min(bhp_thp,
static_cast<Scalar>(inj_controls.bhp_limit));
361 calculateMinimumBhpFromThp(well_state,
364 this->getRefDensity());
365 prod_limit = std::max(bhp_min,
static_cast<Scalar>(prod_controls.bhp_limit));
368 const Scalar bhp_diff = (this->isInjector())? inj_limit - bhp: bhp - prod_limit;
371 well_state.
well(this->index_of_well_).bhp = (this->isInjector())? inj_limit : prod_limit;
373 well_state.
well(this->index_of_well_).thp = this->getTHPConstraint(summary_state);
384 template<
typename TypeTag>
388 const double simulation_time,
391 WellTestState& well_test_state,
393 std::map<std::string, double>& open_times,
397 const auto& group_state = wgHelper.
groupState();
398 deferred_logger.
info(
" well " + this->name() +
" is being tested");
406 auto& ws = well_state_copy.
well(this->indexOfWell());
408 const auto& summary_state = simulator.vanguard().summaryState();
409 const bool has_thp_limit = this->wellHasTHPConstraints(summary_state);
410 if (this->isProducer()) {
411 ws.production_cmode = has_thp_limit ? Well::ProducerCMode::THP : Well::ProducerCMode::BHP;
413 ws.injection_cmode = has_thp_limit ? Well::InjectorCMode::THP : Well::InjectorCMode::BHP;
418 scaleSegmentRatesAndPressure(well_state_copy);
419 calculateExplicitQuantities(simulator, well_state_copy, deferred_logger);
420 updatePrimaryVariables(simulator, well_state_copy, deferred_logger);
422 if (this->isProducer()) {
423 const auto& schedule = simulator.vanguard().schedule();
424 const auto report_step = simulator.episodeIndex();
425 const auto& glo = schedule.glo(report_step);
427 gliftBeginTimeStepWellTestUpdateALQ(simulator,
435 WellTestState welltest_state_temp;
437 bool testWell =
true;
442 const std::size_t original_number_closed_completions = welltest_state_temp.num_closed_completions();
443 bool converged = solveWellForTesting(simulator, wgHelper_copy, well_state_copy, deferred_logger);
445 const auto msg = fmt::format(
"WTEST: Well {} is not solvable (physical)", this->name());
446 deferred_logger.
debug(msg);
451 updateWellOperability(simulator, well_state_copy, wgHelper_copy, deferred_logger);
452 if ( !this->isOperableAndSolvable() ) {
453 const auto msg = fmt::format(
"WTEST: Well {} is not operable (physical)", this->name());
454 deferred_logger.
debug(msg);
457 std::vector<Scalar> potentials;
459 computeWellPotentials(simulator, well_state_copy, wgHelper_copy, potentials, deferred_logger);
460 }
catch (
const std::exception& e) {
461 const std::string msg = fmt::format(
"well {}: computeWellPotentials() "
462 "failed during testing for re-opening: ",
463 this->name(), e.what());
464 deferred_logger.
info(msg);
467 const int np = well_state_copy.
numPhases();
468 for (
int p = 0; p < np; ++p) {
469 ws.well_potentials[p] = std::max(
Scalar{0.0}, potentials[p]);
471 const bool under_zero_target = this->wellUnderZeroGroupRateTarget(simulator, well_state_copy, deferred_logger);
472 this->updateWellTestState(well_state_copy.
well(this->indexOfWell()),
478 this->closeCompletions(welltest_state_temp);
484 if ( welltest_state_temp.num_closed_wells() > 0 ||
485 (original_number_closed_completions == welltest_state_temp.num_closed_completions()) ) {
491 if (!welltest_state_temp.well_is_closed(this->name())) {
492 well_test_state.open_well(this->name());
494 std::string msg = std::string(
"well ") + this->name() + std::string(
" is re-opened");
495 deferred_logger.
info(msg);
498 for (
const auto& completion : this->well_ecl_.getCompletions()) {
499 if (!welltest_state_temp.completion_is_closed(this->name(), completion.first))
500 well_test_state.open_completion(this->name(), completion.first);
502 well_state = well_state_copy;
503 open_times.try_emplace(this->name(), well_test_state.lastTestTime(this->name()));
510 template<
typename TypeTag>
520 const auto& summary_state = simulator.vanguard().summaryState();
521 const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
522 const auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
523 const auto& ws = well_state.
well(this->indexOfWell());
524 const auto pmode_orig = ws.production_cmode;
525 const auto imode_orig = ws.injection_cmode;
526 bool converged =
false;
529 if (!this->param_.local_well_solver_control_switching_){
530 converged = this->iterateWellEqWithControl(simulator, dt, inj_controls, prod_controls, wgHelper, well_state, deferred_logger);
532 if (this->param_.use_implicit_ipr_ && this->well_ecl_.isProducer() && (well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
533 converged = solveWellWithOperabilityCheck(
534 simulator, dt, inj_controls, prod_controls, wgHelper, well_state, deferred_logger
537 converged = this->iterateWellEqWithSwitching(
538 simulator, dt, inj_controls, prod_controls, wgHelper, well_state, deferred_logger
543 }
catch (NumericalProblem& e ) {
544 const std::string msg =
"Inner well iterations failed for well " + this->name() +
" Treat the well as unconverged. ";
545 deferred_logger.
warning(
"INNER_ITERATION_FAILED", msg);
550 if (ws.production_cmode != pmode_orig || ws.injection_cmode != imode_orig) {
552 if (this->isInjector()) {
553 from = WellInjectorCMode2String(imode_orig);
554 to = WellInjectorCMode2String(ws.injection_cmode);
556 from = WellProducerCMode2String(pmode_orig);
557 to = WellProducerCMode2String(ws.production_cmode);
559 const auto msg = fmt::format(
" Well {} switched from {} to {} during local solve", this->name(), from, to);
560 deferred_logger.
debug(msg);
561 const int episodeIdx = simulator.episodeIndex();
562 const int iterationIdx = simulator.model().newtonMethod().numIterations();
563 const auto& schedule = simulator.vanguard().schedule();
564 const int nupcol = schedule[episodeIdx].nupcol();
568 if (iterationIdx >= nupcol || this->well_control_log_.empty()) {
569 this->well_control_log_.push_back(from);
577 template<
typename TypeTag>
582 const Well::InjectionControls& inj_controls,
583 const Well::ProductionControls& prod_controls,
589 const auto& summary_state = simulator.vanguard().summaryState();
590 bool converged =
true;
591 auto& ws = well_state.
well(this->index_of_well_);
593 if (this->wellIsStopped()) {
595 const bool use_vfpexplicit = this->operability_status_.use_vfpexplicit;
596 this->operability_status_.use_vfpexplicit =
true;
597 auto bhp_target = estimateOperableBhp(simulator, dt, wgHelper, summary_state, well_state, deferred_logger);
598 if (!bhp_target.has_value()) {
600 const auto msg = fmt::format(
"estimateOperableBhp: Did not find operable BHP for well {}", this->name());
601 deferred_logger.
debug(msg);
604 converged = solveWellWithZeroRate(simulator, dt, wgHelper, well_state, deferred_logger);
606 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
607 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
611 ws.thp = this->getTHPConstraint(summary_state);
612 const Scalar bhp = std::max(bhp_target.value(),
613 static_cast<Scalar>(prod_controls.bhp_limit));
614 solveWellWithBhp(simulator, dt, bhp, wgHelper, well_state, deferred_logger);
615 this->operability_status_.use_vfpexplicit = use_vfpexplicit;
619 converged = this->iterateWellEqWithSwitching(
620 simulator, dt, inj_controls, prod_controls, wgHelper, well_state, deferred_logger
624 const bool isThp = ws.production_cmode == Well::ProducerCMode::THP;
626 if (converged && !stoppedOrZeroRateTarget(simulator, well_state, deferred_logger) && isThp) {
627 auto rates = well_state.
well(this->index_of_well_).surface_rates;
628 this->adaptRatesForVFP(rates);
629 this->updateIPRImplicit(simulator, well_state, deferred_logger);
633 this->operability_status_.use_vfpexplicit =
true;
636 const Scalar reltol = 1e-3;
637 const Scalar cur_bhp = ws.bhp;
638 if (bhp_stable.has_value() && cur_bhp - bhp_stable.value() > cur_bhp*reltol){
639 const auto msg = fmt::format(
"Well {} converged to an unstable solution, re-solving", this->name());
640 deferred_logger.
debug(msg);
642 simulator, dt, bhp_stable.value(), wgHelper, well_state, deferred_logger
645 ws.thp = this->getTHPConstraint(summary_state);
646 converged = this->iterateWellEqWithSwitching(
647 simulator, dt, inj_controls, prod_controls, wgHelper, well_state, deferred_logger
655 this->operability_status_.use_vfpexplicit =
true;
657 auto bhp_target = estimateOperableBhp(
658 simulator, dt, wgHelper, summary_state, well_state, deferred_logger
660 if (!bhp_target.has_value()) {
663 converged = solveWellWithZeroRate(simulator, dt, wgHelper, well_state, deferred_logger);
665 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
666 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
670 const Scalar bhp = std::max(bhp_target.value(),
671 static_cast<Scalar>(prod_controls.bhp_limit));
673 simulator, dt, bhp, wgHelper, well_state, deferred_logger
675 ws.thp = this->getTHPConstraint(summary_state);
676 const auto msg = fmt::format(
"Well {} did not converge, re-solving with explicit fractions for VFP caculations.", this->name());
677 deferred_logger.
debug(msg);
678 converged = this->iterateWellEqWithSwitching(simulator, dt,
687 this->operability_status_.can_obtain_bhp_with_thp_limit = !this->wellIsStopped();
688 this->operability_status_.obey_thp_limit_under_bhp_limit = !this->wellIsStopped();
692 template<
typename TypeTag>
693 std::optional<typename WellInterface<TypeTag>::Scalar>
698 const SummaryState& summary_state,
702 if (!this->wellHasTHPConstraints(summary_state)) {
704 const bool converged = solveWellWithBhp(
705 simulator, dt, bhp_limit, wgHelper, well_state, deferred_logger
707 if (!converged || this->wellIsStopped()) {
718 const bool converged = solveWellWithBhp(
719 simulator, dt, bhp_min, wgHelper, well_state, deferred_logger
721 if (!converged || this->wellIsStopped()) {
724 this->updateIPRImplicit(simulator, well_state, deferred_logger);
725 auto rates = well_state.
well(this->index_of_well_).surface_rates;
726 this->adaptRatesForVFP(rates);
730 template<
typename TypeTag>
749 auto inj_controls = Well::InjectionControls(0);
750 auto prod_controls = Well::ProductionControls(0);
751 auto& ws = well_state.
well(this->index_of_well_);
752 auto cmode_inj = ws.injection_cmode;
753 auto cmode_prod = ws.production_cmode;
754 if (this->isInjector()) {
755 inj_controls.addControl(Well::InjectorCMode::BHP);
756 inj_controls.bhp_limit = bhp;
757 inj_controls.cmode = Well::InjectorCMode::BHP;
758 ws.injection_cmode = Well::InjectorCMode::BHP;
760 prod_controls.addControl(Well::ProducerCMode::BHP);
761 prod_controls.bhp_limit = bhp;
762 prod_controls.cmode = Well::ProducerCMode::BHP;
763 ws.production_cmode = Well::ProducerCMode::BHP;
768 const bool converged = this->iterateWellEqWithSwitching(
769 simulator, dt, inj_controls, prod_controls, wgHelper_copy,
770 well_state, deferred_logger,
true
772 ws.injection_cmode = cmode_inj;
773 ws.production_cmode = cmode_prod;
777 template<
typename TypeTag>
788 const auto well_status_orig = this->wellStatus_;
798 auto inj_controls = Well::InjectionControls(0);
799 auto prod_controls = Well::ProductionControls(0);
800 const bool converged = this->iterateWellEqWithSwitching(
801 simulator, dt, inj_controls, prod_controls, wgHelper_copy, well_state,
802 deferred_logger,
true,
true
804 this->wellStatus_ = well_status_orig;
808 template<
typename TypeTag>
817 const double dt = simulator.timeStepSize();
819 const auto& summary_state = simulator.vanguard().summaryState();
820 auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
821 auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
822 this->onlyKeepBHPandTHPcontrols(summary_state, well_state, inj_controls, prod_controls);
824 bool converged =
false;
827 if (!this->param_.local_well_solver_control_switching_){
828 converged = this->iterateWellEqWithControl(
829 simulator, dt, inj_controls, prod_controls, wgHelper, well_state, deferred_logger
832 if (this->param_.use_implicit_ipr_ && this->well_ecl_.isProducer() && (well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
833 converged = this->solveWellWithOperabilityCheck(
834 simulator, dt, inj_controls, prod_controls, wgHelper, well_state, deferred_logger
837 converged = this->iterateWellEqWithSwitching(
838 simulator, dt, inj_controls, prod_controls, wgHelper, well_state, deferred_logger
843 }
catch (NumericalProblem& e ) {
844 const std::string msg =
"Inner well iterations failed for well " + this->name() +
" Treat the well as unconverged. ";
845 deferred_logger.
warning(
"INNER_ITERATION_FAILED", msg);
850 deferred_logger.
debug(
"WellTest: Well equation for well " + this->name() +
" converged");
853 const int max_iter = this->param_.max_welleq_iter_;
854 deferred_logger.
debug(
"WellTest: Well equation for well " + this->name() +
" failed converging in "
860 template<
typename TypeTag>
869 if (!this->isOperableAndSolvable() && !this->wellIsStopped())
874 const double dt = simulator.timeStepSize();
875 bool converged = iterateWellEquations(simulator, dt, wgHelper, well_state, deferred_logger);
885 auto& ws = well_state.
well(this->indexOfWell());
886 bool thp_control =
false;
887 if (this->well_ecl_.isInjector()) {
888 thp_control = ws.injection_cmode == Well::InjectorCMode::THP;
890 ws.injection_cmode = Well::InjectorCMode::BHP;
891 if (this->well_control_log_.empty()) {
892 this->well_control_log_.push_back(WellInjectorCMode2String(Well::InjectorCMode::THP));
896 thp_control = ws.production_cmode == Well::ProducerCMode::THP;
898 ws.production_cmode = Well::ProducerCMode::BHP;
899 if (this->well_control_log_.empty()) {
900 this->well_control_log_.push_back(WellProducerCMode2String(Well::ProducerCMode::THP));
905 const std::string msg = std::string(
"The newly opened well ") + this->name()
906 + std::string(
" with THP control did not converge during inner iterations, we try again with bhp control");
907 deferred_logger.
debug(msg);
908 converged = this->iterateWellEquations(simulator, dt, wgHelper, well_state, deferred_logger);
913 const int max_iter = this->param_.max_welleq_iter_;
914 deferred_logger.
debug(
"Compute initial well solution for well " + this->name() +
". Failed to converge in "
916 well_state = well_state0;
922 template <
typename TypeTag>
932 const auto& group_state = wgHelper.
groupState();
933 prepareWellBeforeAssembling(simulator, dt, wgHelper, well_state, deferred_logger);
934 assembleWellEqWithoutIteration(simulator, dt, well_state, group_state, deferred_logger);
939 template <
typename TypeTag>
949 const auto& summary_state = simulator.vanguard().summaryState();
950 const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
951 const auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
954 assembleWellEqWithoutIteration(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
959 template<
typename TypeTag>
969 const bool old_well_operable = this->operability_status_.isOperableAndSolvable();
971 if (this->param_.check_well_operability_iter_)
972 checkWellOperability(simulator, well_state, wgHelper, deferred_logger);
975 const int iteration_idx = simulator.model().newtonMethod().numIterations();
976 if (iteration_idx < this->param_.max_niter_inner_well_iter_ || this->well_ecl_.isMultiSegment()) {
977 const auto& ws = well_state.
well(this->indexOfWell());
978 const bool nonzero_rate_original =
979 std::any_of(ws.surface_rates.begin(),
980 ws.surface_rates.begin() + well_state.
numPhases(),
981 [](
Scalar rate) { return rate != Scalar(0.0); });
983 this->operability_status_.solvable =
true;
984 if (number_of_well_reopenings_ >= this->param_.max_well_status_switch_) {
986 if (number_of_well_reopenings_ == this->param_.max_well_status_switch_) {
987 const std::string msg = fmt::format(
"well {} is oscillating between open and stop. \n"
988 "We don't allow for more than {} re-openings "
989 "and the well is therefore kept stopped.",
990 this->name(), number_of_well_reopenings_);
991 deferred_logger.
debug(msg);
994 changed_to_stopped_this_step_ =
true;
995 bool converged_zero_rate = this->solveWellWithZeroRate(
996 simulator, dt, wgHelper, well_state, deferred_logger
998 if (this->param_.shut_unsolvable_wells_ && !converged_zero_rate ) {
999 this->operability_status_.solvable =
false;
1002 number_of_well_reopenings_++;
1005 bool converged = this->iterateWellEquations(
1006 simulator, dt, wgHelper, well_state, deferred_logger
1010 const bool zero_target = this->wellUnderZeroRateTarget(simulator, well_state, deferred_logger);
1011 if (this->wellIsStopped() && !zero_target && nonzero_rate_original) {
1015 this->operability_status_.resetOperability();
1017 deferred_logger.
debug(
" " + this->name() +
" is re-opened after being stopped during local solve");
1018 number_of_well_reopenings_++;
1022 if (this->param_.shut_unsolvable_wells_) {
1023 this->operability_status_.solvable =
false;
1027 if (this->operability_status_.has_negative_potentials) {
1028 auto well_state_copy = well_state;
1029 std::vector<Scalar> potentials;
1031 computeWellPotentials(simulator, well_state_copy, wgHelper, potentials, deferred_logger);
1032 }
catch (
const std::exception& e) {
1033 const std::string msg = fmt::format(
"well {}: computeWellPotentials() failed "
1034 "during attempt to recompute potentials for well: ",
1035 this->name(), e.what());
1036 deferred_logger.
info(msg);
1037 this->operability_status_.has_negative_potentials =
true;
1039 auto& ws = well_state.
well(this->indexOfWell());
1041 for (
int p = 0; p < np; ++p) {
1042 ws.well_potentials[p] = std::max(
Scalar{0.0}, potentials[p]);
1045 this->changed_to_open_this_step_ =
false;
1046 changed_to_stopped_this_step_ =
false;
1048 const bool well_operable = this->operability_status_.isOperableAndSolvable();
1049 if (!well_operable) {
1052 this->solveWellWithZeroRate(
1053 simulator, dt, wgHelper, well_state, deferred_logger
1055 }
catch (
const std::exception& e) {
1056 const std::string msg = fmt::format(
"well {}: solveWellWithZeroRate() failed "
1057 "during attempt to solve with zero rate for well: ",
1058 this->name(), e.what());
1059 deferred_logger.
info(msg);
1061 auto& ws = well_state.
well(this->indexOfWell());
1063 for (
int p = 0; p < np; ++p) {
1064 ws.surface_rates[p] =
Scalar{0.0};
1067 if (old_well_operable) {
1068 deferred_logger.
debug(
" well " + this->name() +
" gets STOPPED during iteration ");
1069 changed_to_stopped_this_step_ =
true;
1071 }
else if (well_state.
isOpen(this->name())) {
1073 if (!old_well_operable) {
1074 deferred_logger.
debug(
" well " + this->name() +
" gets REVIVED during iteration ");
1075 this->changed_to_open_this_step_ =
true;
1080 template<
typename TypeTag>
1084 if(!this->operability_status_.solvable)
1087 for (
int perfIdx = 0; perfIdx < this->number_of_local_perforations_; ++perfIdx) {
1088 const auto cellIdx = this->cells()[perfIdx];
1089 const auto it = cellRates_.find(cellIdx);
1090 RateVector rates = (it == cellRates_.end()) ? 0.0 : it->second;
1091 for (
auto i=0*RateVector::dimension; i < RateVector::dimension; ++i)
1093 rates[i] += connectionRates_[perfIdx][i];
1095 cellRates_.insert_or_assign(cellIdx, rates);
1099 template<
typename TypeTag>
1103 for (
int perfIdx = 0; perfIdx < this->number_of_local_perforations_; ++perfIdx) {
1104 if (this->cells()[perfIdx] == cellIdx) {
1105 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
1106 return connectionRates_[perfIdx][activeCompIdx].value();
1110 OPM_THROW(std::invalid_argument,
"The well with name " + this->name()
1118 template<
typename TypeTag>
1127 if (!this->param_.check_well_operability_) {
1131 if (this->wellIsStopped() && !changed_to_stopped_this_step_) {
1135 updateWellOperability(simulator, well_state, wgHelper, deferred_logger);
1136 if (!this->operability_status_.isOperableAndSolvable()) {
1137 this->operability_status_.use_vfpexplicit =
true;
1138 deferred_logger.
debug(
"EXPLICIT_LOOKUP_VFP",
1139 "well not operable, trying with explicit vfp lookup: " + this->name());
1140 updateWellOperability(simulator, well_state, wgHelper, deferred_logger);
1146 template<
typename TypeTag>
1156 const auto& summary_state = simulator.vanguard().summaryState();
1157 const auto& well_name = this->name();
1158 if (!this->wellHasTHPConstraints(summary_state)) {
1159 const std::string msg = fmt::format(
"GLIFT WTEST: Well {} does not have THP constraints", well_name);
1160 deferred_logger.
info(msg);
1163 const auto& schedule = simulator.vanguard().schedule();
1164 const auto report_step_idx = simulator.episodeIndex();
1165 const auto& glo = schedule.glo(report_step_idx);
1166 if (!glo.has_well(well_name)) {
1167 const std::string msg = fmt::format(
1168 "GLIFT WTEST: Well {} : Gas lift not activated: "
1169 "WLIFTOPT is probably missing. Skipping.", well_name);
1170 deferred_logger.
info(msg);
1173 const auto& gl_well = glo.well(well_name);
1176 std::unique_ptr<GasLiftSingleWell> glift =
1177 initializeGliftWellTest_<GasLiftSingleWell>(simulator,
1182 auto [wtest_alq, success] = glift->wellTestALQ();
1184 const auto& unit_system = schedule.getUnits();
1186 well_state.
well(well_name).alq_state.set(wtest_alq);
1188 "GLIFT WTEST: Well {} : Setting ALQ to optimized value = {}",
1189 well_name, unit_system.from_si(UnitSystem::measure::gas_surface_rate, wtest_alq));
1192 if (!gl_well.use_glo()) {
1194 "GLIFT WTEST: Well {} : Gas lift optimization deactivated. Setting ALQ to WLIFTOPT item 3 = {}",
1196 unit_system.from_si(UnitSystem::measure::gas_surface_rate, well_state.
well(well_name).alq_state.get()));
1201 "GLIFT WTEST: Well {} : Gas lift optimization failed, no ALQ set.",
1205 deferred_logger.
info(msg);
1208 template<
typename TypeTag>
1217 if (this->param_.local_well_solver_control_switching_) {
1218 const bool success = updateWellOperabilityFromWellEq(simulator, wgHelper, deferred_logger);
1220 this->operability_status_.solvable =
false;
1221 deferred_logger.
debug(
"Operability check using well equations did not converge for well "
1222 + this->name() +
". Mark the well as unsolvable." );
1226 this->operability_status_.resetOperability();
1228 bool thp_controlled = this->isInjector() ? well_state.
well(this->index_of_well_).injection_cmode == Well::InjectorCMode::THP:
1229 well_state.
well(this->index_of_well_).production_cmode == Well::ProducerCMode::THP;
1230 bool bhp_controlled = this->isInjector() ? well_state.
well(this->index_of_well_).injection_cmode == Well::InjectorCMode::BHP:
1231 well_state.
well(this->index_of_well_).production_cmode == Well::ProducerCMode::BHP;
1235 bool check_thp = thp_controlled || this->operability_status_.thp_limit_violated_but_not_switched;
1236 if (check_thp || bhp_controlled) {
1237 updateIPR(simulator, deferred_logger);
1238 checkOperabilityUnderBHPLimit(well_state, simulator, deferred_logger);
1242 checkOperabilityUnderTHPLimit(simulator, well_state, wgHelper, deferred_logger);
1246 template<
typename TypeTag>
1255 assert(this->param_.local_well_solver_control_switching_);
1256 this->operability_status_.resetOperability();
1259 const double dt = simulator.timeStepSize();
1265 bool converged = iterateWellEquations(simulator, dt, wgHelper_copy, well_state_copy, deferred_logger);
1269 template<
typename TypeTag>
1277 template<
typename TypeTag>
1286 const auto& group_state = wgHelper.
groupState();
1288 const auto& well = this->well_ecl_;
1289 const int well_index = this->index_of_well_;
1290 auto& ws = well_state.
well(well_index);
1292 const auto& summaryState = simulator.vanguard().summaryState();
1293 const auto& schedule = simulator.vanguard().schedule();
1297 ws.primaryvar.resize(0);
1299 if (this->wellIsStopped()) {
1300 for (
int p = 0; p<np; ++p) {
1301 ws.surface_rates[p] = 0;
1307 if (this->isInjector() )
1309 const auto& controls = well.injectionControls(summaryState);
1311 InjectorType injectorType = controls.injector_type;
1313 switch (injectorType) {
1314 case InjectorType::WATER:
1316 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1319 case InjectorType::OIL:
1321 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1324 case InjectorType::GAS:
1326 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1330 OPM_DEFLOG_THROW(std::runtime_error,
"Expected WATER, OIL or GAS as type for injectors " + this->name(), deferred_logger );
1333 const auto current = ws.injection_cmode;
1336 case Well::InjectorCMode::RATE:
1338 ws.surface_rates[phasePos] = (1.0 - this->rsRvInj()) * controls.surface_rate;
1339 if(this->rsRvInj() > 0) {
1340 if (injectorType == InjectorType::OIL && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1341 const int gas_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1342 ws.surface_rates[gas_pos] = controls.surface_rate * this->rsRvInj();
1343 }
else if (injectorType == InjectorType::GAS && FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1344 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1345 ws.surface_rates[oil_pos] = controls.surface_rate * this->rsRvInj();
1347 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 );
1353 case Well::InjectorCMode::RESV:
1355 std::vector<Scalar> convert_coeff(this->number_of_phases_, 1.0);
1356 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, convert_coeff);
1357 const Scalar coeff = convert_coeff[phasePos];
1358 ws.surface_rates[phasePos] = controls.reservoir_rate/coeff;
1362 case Well::InjectorCMode::THP:
1364 auto rates = ws.surface_rates;
1369 this->getRefDensity(),
1372 ws.thp = this->getTHPConstraint(summaryState);
1377 Scalar total_rate = std::accumulate(rates.begin(), rates.end(), 0.0);
1378 if (total_rate <= 0.0)
1379 ws.surface_rates = ws.well_potentials;
1383 case Well::InjectorCMode::BHP:
1385 ws.bhp = controls.bhp_limit;
1387 for (
int p = 0; p<np; ++p) {
1388 total_rate += ws.surface_rates[p];
1393 if (total_rate <= 0.0)
1394 ws.surface_rates = ws.well_potentials;
1398 case Well::InjectorCMode::GRUP:
1400 assert(well.isAvailableForGroupControl());
1401 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
1402 const Scalar efficiencyFactor = well.getEfficiencyFactor() *
1403 well_state[well.name()].efficiency_scaling_factor;
1404 std::optional<Scalar> target =
1405 this->getGroupInjectionTargetRate(group,
1414 ws.surface_rates[phasePos] = *target;
1417 case Well::InjectorCMode::CMODE_UNDEFINED:
1419 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name(), deferred_logger );
1429 ws.surface_rates[phasePos] = std::max(
Scalar{1.e-7}, ws.surface_rates[phasePos]);
1432 ws.bhp = controls.bhp_limit;
1438 const auto current = ws.production_cmode;
1439 const auto& controls = well.productionControls(summaryState);
1441 case Well::ProducerCMode::ORAT:
1443 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1444 Scalar current_rate = -ws.surface_rates[oil_pos];
1447 if (current_rate > 0.0) {
1448 for (
int p = 0; p<np; ++p) {
1449 ws.surface_rates[p] *= controls.oil_rate/current_rate;
1452 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1453 double control_fraction = fractions[oil_pos];
1454 if (control_fraction != 0.0) {
1455 for (
int p = 0; p<np; ++p) {
1456 ws.surface_rates[p] = - fractions[p] * controls.oil_rate/control_fraction;
1462 case Well::ProducerCMode::WRAT:
1464 const int water_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1465 Scalar current_rate = -ws.surface_rates[water_pos];
1468 if (current_rate > 0.0) {
1469 for (
int p = 0; p<np; ++p) {
1470 ws.surface_rates[p] *= controls.water_rate/current_rate;
1473 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1474 const Scalar control_fraction = fractions[water_pos];
1475 if (control_fraction != 0.0) {
1476 for (
int p = 0; p<np; ++p) {
1477 ws.surface_rates[p] = - fractions[p] * controls.water_rate / control_fraction;
1483 case Well::ProducerCMode::GRAT:
1485 const int gas_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1486 Scalar current_rate = -ws.surface_rates[gas_pos];
1489 if (current_rate > 0.0) {
1490 for (
int p = 0; p<np; ++p) {
1491 ws.surface_rates[p] *= controls.gas_rate/current_rate;
1494 const std::vector<Scalar > fractions = initialWellRateFractions(simulator, well_state);
1495 const Scalar control_fraction = fractions[gas_pos];
1496 if (control_fraction != 0.0) {
1497 for (
int p = 0; p<np; ++p) {
1498 ws.surface_rates[p] = - fractions[p] * controls.gas_rate / control_fraction;
1506 case Well::ProducerCMode::LRAT:
1508 const int water_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1509 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1510 Scalar current_rate = - ws.surface_rates[water_pos]
1511 - ws.surface_rates[oil_pos];
1514 if (current_rate > 0.0) {
1515 for (
int p = 0; p<np; ++p) {
1516 ws.surface_rates[p] *= controls.liquid_rate/current_rate;
1519 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1520 const Scalar control_fraction = fractions[water_pos] + fractions[oil_pos];
1521 if (control_fraction != 0.0) {
1522 for (
int p = 0; p<np; ++p) {
1523 ws.surface_rates[p] = - fractions[p] * controls.liquid_rate / control_fraction;
1529 case Well::ProducerCMode::CRAT:
1532 fmt::format(
"CRAT control not supported, well {}", this->name()),
1535 case Well::ProducerCMode::RESV:
1537 std::vector<Scalar> convert_coeff(this->number_of_phases_, 1.0);
1538 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, ws.surface_rates, convert_coeff);
1539 Scalar total_res_rate = 0.0;
1540 for (
int p = 0; p<np; ++p) {
1541 total_res_rate -= ws.surface_rates[p] * convert_coeff[p];
1543 if (controls.prediction_mode) {
1546 if (total_res_rate > 0.0) {
1547 for (
int p = 0; p<np; ++p) {
1548 ws.surface_rates[p] *= controls.resv_rate/total_res_rate;
1551 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1552 for (
int p = 0; p<np; ++p) {
1553 ws.surface_rates[p] = - fractions[p] * controls.resv_rate / convert_coeff[p];
1557 std::vector<Scalar> hrates(this->number_of_phases_,0.);
1558 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
1559 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1560 hrates[phase_pos] = controls.water_rate;
1562 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1563 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1564 hrates[phase_pos] = controls.oil_rate;
1566 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1567 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1568 hrates[phase_pos] = controls.gas_rate;
1570 std::vector<Scalar> hrates_resv(this->number_of_phases_,0.);
1571 this->rateConverter_.calcReservoirVoidageRates( 0, this->pvtRegionIdx_, hrates, hrates_resv);
1572 Scalar target = std::accumulate(hrates_resv.begin(), hrates_resv.end(), 0.0);
1575 if (total_res_rate > 0.0) {
1576 for (
int p = 0; p<np; ++p) {
1577 ws.surface_rates[p] *= target/total_res_rate;
1580 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1581 for (
int p = 0; p<np; ++p) {
1582 ws.surface_rates[p] = - fractions[p] * target / convert_coeff[p];
1588 case Well::ProducerCMode::BHP:
1590 ws.bhp = controls.bhp_limit;
1592 for (
int p = 0; p<np; ++p) {
1593 total_rate -= ws.surface_rates[p];
1598 if (total_rate <= 0.0){
1599 for (
int p = 0; p<np; ++p) {
1600 ws.surface_rates[p] = -ws.well_potentials[p];
1605 case Well::ProducerCMode::THP:
1607 const bool update_success = updateWellStateWithTHPTargetProd(simulator, well_state, wgHelper, deferred_logger);
1609 if (!update_success) {
1613 auto rates = ws.surface_rates;
1614 this->adaptRatesForVFP(rates);
1616 well_state, rates, well, summaryState, this->getRefDensity(), deferred_logger);
1618 ws.thp = this->getTHPConstraint(summaryState);
1622 const Scalar total_rate = -std::accumulate(rates.begin(), rates.end(), 0.0);
1623 if (total_rate <= 0.0) {
1624 for (
int p = 0; p < this->number_of_phases_; ++p) {
1625 ws.surface_rates[p] = -ws.well_potentials[p];
1631 case Well::ProducerCMode::GRUP:
1633 assert(well.isAvailableForGroupControl());
1634 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
1635 const Scalar efficiencyFactor = well.getEfficiencyFactor() *
1636 well_state[well.name()].efficiency_scaling_factor;
1637 Scalar scale = this->getGroupProductionTargetRate(group,
1647 for (
int p = 0; p<np; ++p) {
1648 ws.surface_rates[p] *= scale;
1650 ws.trivial_group_target =
false;
1654 ws.trivial_group_target =
true;
1658 case Well::ProducerCMode::CMODE_UNDEFINED:
1661 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name() , deferred_logger);
1667 ws.bhp = controls.bhp_limit;
1672 template<
typename TypeTag>
1681 const bool isGroupControlled = this->wellUnderGroupControl(well_state.
well(this->index_of_well_));
1682 if (!isGroupControlled) {
1684 const auto& summaryState = simulator.vanguard().summaryState();
1685 return this->wellUnderZeroRateTargetIndividual(summaryState, well_state);
1687 return this->wellUnderZeroGroupRateTarget(simulator, well_state, deferred_logger, isGroupControlled);
1691 template <
typename TypeTag>
1696 const std::optional<bool> group_control)
const
1699 const bool isGroupControlled = group_control.value_or(this->wellUnderGroupControl(well_state.
well(this->index_of_well_)));
1700 if (isGroupControlled) {
1701 const auto& summaryState = simulator.vanguard().summaryState();
1702 const auto& group_state = simulator.problem().wellModel().groupState();
1703 const auto& schedule = simulator.vanguard().schedule();
1704 return this->zeroGroupRateTarget(summaryState, schedule, well_state, group_state, deferred_logger);
1709 template<
typename TypeTag>
1718 return this->wellIsStopped()
1719 || this->wellUnderZeroRateTarget(simulator, well_state, deferred_logger);
1722 template<
typename TypeTag>
1723 std::vector<typename WellInterface<TypeTag>::Scalar>
1729 const int np = this->number_of_phases_;
1730 std::vector<Scalar> scaling_factor(np);
1731 const auto& ws = well_state.
well(this->index_of_well_);
1733 Scalar total_potentials = 0.0;
1734 for (
int p = 0; p<np; ++p) {
1735 total_potentials += ws.well_potentials[p];
1737 if (total_potentials > 0) {
1738 for (
int p = 0; p<np; ++p) {
1739 scaling_factor[p] = ws.well_potentials[p] / total_potentials;
1741 return scaling_factor;
1746 const int nperf = this->number_of_local_perforations_;
1747 for (
int perf = 0; perf < nperf; ++perf) {
1748 total_tw += this->well_index_[perf];
1750 total_tw = this->parallelWellInfo().communication().sum(total_tw);
1752 for (
int perf = 0; perf < nperf; ++perf) {
1753 const int cell_idx = this->well_cells_[perf];
1754 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
1755 const auto& fs = intQuants.fluidState();
1756 const Scalar well_tw_fraction = this->well_index_[perf] / total_tw;
1757 Scalar total_mobility = 0.0;
1758 for (
int p = 0; p < np; ++p) {
1759 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
1760 total_mobility += fs.invB(canonical_phase_idx).value() * intQuants.mobility(canonical_phase_idx).value();
1762 for (
int p = 0; p < np; ++p) {
1763 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
1764 scaling_factor[p] += well_tw_fraction * fs.invB(canonical_phase_idx).value() * intQuants.mobility(canonical_phase_idx).value() / total_mobility;
1767 return scaling_factor;
1772 template <
typename TypeTag>
1779 assert(this->isProducer());
1783 auto& ws = well_state.
well(this->index_of_well_);
1784 int nonzero_rate_index = -1;
1785 const Scalar floating_point_error_epsilon = 1e-14;
1786 for (
int p = 0; p < this->number_of_phases_; ++p) {
1787 if (std::abs(ws.surface_rates[p]) > floating_point_error_epsilon) {
1788 if (nonzero_rate_index == -1) {
1789 nonzero_rate_index = p;
1798 std::vector<Scalar> well_q_s(this->number_of_phases_, 0.0);
1799 bool rates_evaluated_at_1bar =
false;
1801 const auto& summary_state = simulator.vanguard().summaryState();
1802 const auto& prod_controls = this->well_ecl_.productionControls(summary_state);
1803 const double bhp_limit = std::max(prod_controls.bhp_limit, 1.0 * unit::barsa);
1804 this->computeWellRatesWithBhp(simulator, bhp_limit, well_q_s, deferred_logger);
1806 rates_evaluated_at_1bar = (bhp_limit < 1.1 * unit::barsa);
1808 if (std::any_of(well_q_s.begin(), well_q_s.end(), [](
Scalar q) { return q > 0.0; })) {
1810 if (!rates_evaluated_at_1bar) {
1811 this->computeWellRatesWithBhp(simulator, 1.0 * unit::barsa, well_q_s, deferred_logger);
1812 rates_evaluated_at_1bar =
true;
1815 for (
auto& q : well_q_s) {
1816 q = std::min(q,
Scalar{0.0});
1821 if (nonzero_rate_index == -1) {
1825 const Scalar factor = rates_evaluated_at_1bar ? 0.5 : 1.0;
1826 for (
int p = 0; p < this->number_of_phases_; ++p) {
1827 ws.surface_rates[p] = factor * well_q_s[p];
1836 const Scalar initial_nonzero_rate = ws.surface_rates[nonzero_rate_index];
1837 const Scalar computed_rate = well_q_s[nonzero_rate_index];
1838 if (std::abs(initial_nonzero_rate) < std::abs(computed_rate)) {
1840 const Scalar factor = initial_nonzero_rate / computed_rate;
1841 assert(factor < 1.0);
1842 for (
int p = 0; p < this->number_of_phases_; ++p) {
1844 if (p != nonzero_rate_index) {
1845 ws.surface_rates[p] = factor * well_q_s[p];
1854 for (
int p = 0; p < this->number_of_phases_; ++p) {
1855 ws.surface_rates[p] = well_q_s[p];
1859 template <
typename TypeTag>
1860 std::vector<typename WellInterface<TypeTag>::Scalar>
1867 OPM_TIMEFUNCTION_LOCAL(Subsystem::Wells);
1870 if (
static_cast<std::size_t
>(perf) >= this->well_cells_.size()) {
1871 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!");
1873 auto wi = std::vector<Scalar>
1874 (this->num_conservation_quantities_, this->well_index_[perf] * trans_mult);
1876 if constexpr (! Indices::gasEnabled) {
1880 const auto& wdfac = this->well_ecl_.getWDFAC();
1882 if (! wdfac.useDFactor() || (this->well_index_[perf] == 0.0)) {
1886 const Scalar d = this->computeConnectionDFactor(perf, intQuants, ws);
1893 const auto& connection = this->well_ecl_.getConnections()[ws.
perf_data.ecl_index[perf]];
1894 const Scalar Kh = connection.Kh();
1895 const Scalar scaling = 3.141592653589 * Kh * connection.wpimult();
1896 const unsigned gas_comp_idx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
1899 const Scalar cell_pressure = getValue(intQuants.fluidState().pressure(FluidSystem::gasPhaseIdx));
1900 const Scalar drawdown = cell_pressure - connection_pressure;
1901 const Scalar invB = getValue(intQuants.fluidState().invB(FluidSystem::gasPhaseIdx));
1902 const Scalar mob_g = getValue(intQuants.mobility(FluidSystem::gasPhaseIdx)) * invB;
1904 const Scalar b = 2*scaling/wi[gas_comp_idx];
1905 const Scalar c = -2*scaling*mob_g*drawdown;
1907 Scalar consistent_Q = -1.0e20;
1909 const Scalar r2n = b*b + 4*a*c;
1911 const Scalar rn = std::sqrt(r2n);
1912 const Scalar xn1 = (b-rn)*0.5/a;
1916 const Scalar xn2 = (b+rn)*0.5/a;
1917 if (xn2 <= 0 && xn2 > consistent_Q) {
1923 const Scalar r2p = b*b - 4*a*c;
1925 const Scalar rp = std::sqrt(r2p);
1926 const Scalar xp1 = (rp-b)*0.5/a;
1927 if (xp1 > 0 && xp1 < consistent_Q) {
1930 const Scalar xp2 = -(rp+b)*0.5/a;
1931 if (xp2 > 0 && xp2 < consistent_Q) {
1935 wi[gas_comp_idx] = 1.0/(1.0/(trans_mult * this->well_index_[perf]) + (consistent_Q/2 * d / scaling));
1940 template <
typename TypeTag>
1946 if (! this->well_ecl_.getWDFAC().useDFactor()) {
1950 auto& d_factor = ws.
perf_data.connection_d_factor;
1952 for (
int perf = 0; perf < this->number_of_local_perforations_; ++perf) {
1953 const int cell_idx = this->well_cells_[perf];
1954 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
1956 d_factor[perf] = this->computeConnectionDFactor(perf, intQuants, ws);
1960 template <
typename TypeTag>
1967 auto rhoGS = [regIdx = this->pvtRegionIdx()]() {
1968 return FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, regIdx);
1972 auto gas_visc = [connection_pressure = ws.
perf_data.pressure[perf],
1974 regIdx = this->pvtRegionIdx(), &intQuants]()
1976 const auto rv = getValue(intQuants.fluidState().Rv());
1978 const auto& gasPvt = FluidSystem::gasPvt();
1983 const Scalar rv_sat = gasPvt.saturatedOilVaporizationFactor
1984 (regIdx, temperature, connection_pressure);
1986 if (! (rv < rv_sat)) {
1987 return gasPvt.saturatedViscosity(regIdx, temperature,
1988 connection_pressure);
1991 return gasPvt.viscosity(regIdx, temperature, connection_pressure,
1992 rv, getValue(intQuants.fluidState().Rvw()));
1995 const auto& connection = this->well_ecl_.getConnections()
1998 return this->well_ecl_.getWDFAC().getDFactor(rhoGS, gas_visc, connection);
2002 template <
typename TypeTag>
2008 auto connCF = [&connIx = std::as_const(ws.
perf_data.ecl_index),
2009 &conns = this->well_ecl_.getConnections()]
2012 return conns[connIx[perf]].CF();
2015 auto& tmult = ws.
perf_data.connection_compaction_tmult;
2016 auto& ctf = ws.
perf_data.connection_transmissibility_factor;
2018 for (
int perf = 0; perf < this->number_of_local_perforations_; ++perf) {
2019 const int cell_idx = this->well_cells_[perf];
2021 const auto& intQuants = simulator.model()
2022 .intensiveQuantities(cell_idx, 0);
2024 tmult[perf] = simulator.problem()
2025 .template wellTransMultiplier<double>(intQuants, cell_idx);
2027 ctf[perf] = connCF(perf) * tmult[perf];
2032 template<
typename TypeTag>
2036 if constexpr (Indices::oilEnabled) {
2037 return fs.pressure(FluidSystem::oilPhaseIdx);
2038 }
else if constexpr (Indices::gasEnabled) {
2039 return fs.pressure(FluidSystem::gasPhaseIdx);
2041 return fs.pressure(FluidSystem::waterPhaseIdx);
2045 template <
typename TypeTag>
2046 template<
class Value,
class Callback>
2050 const int local_perf_index,
2051 std::vector<Value>& mob,
2052 Callback& extendEval,
2055 auto relpermArray = []()
2057 if constexpr (std::is_same_v<Value, Scalar>) {
2058 return std::array<Scalar,3>{};
2060 return std::array<Eval,3>{};
2063 if (
static_cast<std::size_t
>(local_perf_index) >= this->well_cells_.size()) {
2064 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!");
2066 const int cell_idx = this->well_cells_[local_perf_index];
2067 assert (
int(mob.size()) == this->num_conservation_quantities_);
2068 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2069 const auto& materialLawManager = simulator.problem().materialLawManager();
2073 const int satid = this->saturation_table_number_[local_perf_index] - 1;
2074 const int satid_elem = materialLawManager->satnumRegionIdx(cell_idx);
2075 if (satid == satid_elem) {
2076 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2077 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2081 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2082 mob[activeCompIdx] = extendEval(intQuants.mobility(phaseIdx));
2084 if constexpr (has_solvent) {
2085 mob[Indices::contiSolventEqIdx] = extendEval(intQuants.solventMobility());
2088 const auto& paramsCell = materialLawManager->connectionMaterialLawParams(satid, cell_idx);
2089 auto relativePerms = relpermArray();
2090 MaterialLaw::relativePermeabilities(relativePerms, paramsCell, intQuants.fluidState());
2093 materialLawManager->connectionMaterialLawParams(satid_elem, cell_idx);
2096 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2097 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2101 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2102 mob[activeCompIdx] = extendEval(relativePerms[phaseIdx] / intQuants.fluidState().viscosity(phaseIdx));
2106 if constexpr (has_solvent) {
2107 OPM_DEFLOG_THROW(std::runtime_error,
"individual mobility for wells does not work in combination with solvent", deferred_logger);
2111 if (this->isInjector() && !this->inj_fc_multiplier_.empty()) {
2112 const auto perf_ecl_index = this->perforationData()[local_perf_index].ecl_index;
2113 const auto& connections = this->well_ecl_.getConnections();
2114 const auto& connection = connections[perf_ecl_index];
2115 if (connection.filterCakeActive()) {
2116 std::transform(mob.begin(), mob.end(), mob.begin(),
2117 [mult = this->inj_fc_multiplier_[local_perf_index] ](
const auto val)
2118 { return val * mult; });
2124 template<
typename TypeTag>
2133 const auto& summary_state = simulator.vanguard().summaryState();
2135 auto bhp_at_thp_limit = computeBhpAtThpLimitProdWithAlq(
2136 simulator, wgHelper, summary_state, this->getALQ(well_state), deferred_logger,
false);
2137 if (bhp_at_thp_limit) {
2138 std::vector<Scalar> rates(this->number_of_phases_, 0.0);
2139 if (thp_update_iterations) {
2140 computeWellRatesWithBhpIterations(simulator, *bhp_at_thp_limit,
2141 wgHelper, rates, deferred_logger);
2143 computeWellRatesWithBhp(simulator, *bhp_at_thp_limit,
2144 rates, deferred_logger);
2146 auto& ws = well_state.
well(this->name());
2147 ws.surface_rates = rates;
2148 ws.bhp = *bhp_at_thp_limit;
2149 ws.thp = this->getTHPConstraint(summary_state);
2156 template <
typename TypeTag>
2161 const std::vector<Scalar>& mobility,
2164 const int np = this->number_of_phases_;
2165 for (
int p = 0; p < np; ++p) {
2168 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
2169 const auto connMob =
2170 mobility[FluidSystem::activePhaseToActiveCompIdx(p)] * fs.invB(canonical_phase_idx).value();
2172 connPI[p] = connPICalc(connMob);
2175 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) &&
2176 FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx))
2178 const auto io = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
2179 const auto ig = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
2181 const auto vapoil = connPI[ig] * fs.Rv().value();
2182 const auto disgas = connPI[io] * fs.Rs().value();
2184 connPI[io] += vapoil;
2185 connPI[ig] += disgas;
2190 template <
typename TypeTag>
2194 const Phase preferred_phase,
2196 const std::vector<Scalar>& mobility,
2201 if (preferred_phase == Phase::GAS) {
2202 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
2204 else if (preferred_phase == Phase::OIL) {
2205 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
2207 else if (preferred_phase == Phase::WATER) {
2208 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
2212 fmt::format(
"Unsupported Injector Type ({}) "
2213 "for well {} during connection I.I. calculation",
2214 static_cast<int>(preferred_phase), this->name()),
2218 const auto mt = std::accumulate(mobility.begin(), mobility.end(), 0.0);
2219 const int canonicalPhaseIdx = FluidSystem::activeToCanonicalPhaseIdx(phase_pos);
2220 connII[phase_pos] = connIICalc(mt * fs.invB(canonicalPhaseIdx).value());
2223 template<
typename TypeTag>
2224 template<
class GasLiftSingleWell>
2225 std::unique_ptr<GasLiftSingleWell>
2234 auto& comm = simulator.vanguard().grid().comm();
2235 ecl_well_map.try_emplace(this->name(), &(this->wellEcl()), this->indexOfWell());
2238 simulator.vanguard().schedule(),
2239 simulator.vanguard().summaryState(),
2240 simulator.episodeIndex(),
2241 simulator.model().newtonMethod().numIterations(),
2250 std::set<int> sync_groups;
2251 const auto& summary_state = simulator.vanguard().summaryState();
2252 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: GroupState.hpp:41
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:198
Definition: SingleWellState.hpp:43
Scalar temperature
Definition: SingleWellState.hpp:102
PerfData< Scalar > perf_data
Definition: SingleWellState.hpp:125
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
Definition: WellGroupHelper.hpp:51
const GroupState< Scalar > & groupState() const
Definition: WellGroupHelper.hpp:175
GroupStateGuard pushGroupState(GroupState< Scalar > &group_state)
Definition: WellGroupHelper.hpp:185
const WellState< Scalar, IndexTraits > & wellState() const
Definition: WellGroupHelper.hpp:256
WellStateGuard pushWellState(WellState< Scalar, IndexTraits > &well_state)
Definition: WellGroupHelper.hpp:190
Well well_ecl_
Definition: WellInterfaceGeneric.hpp:304
int number_of_local_perforations_
Definition: WellInterfaceGeneric.hpp:340
FluidSystem::Scalar wsolvent_
Definition: WellInterfaceGeneric.hpp:380
const std::vector< FluidSystem::Scalar > & wellIndex() const
Definition: WellInterfaceGeneric.hpp:152
Definition: WellInterfaceIndices.hpp:34
std::optional< Scalar > estimateOperableBhp(const Simulator &ebos_simulator, const double dt, const WellGroupHelperType &wgHelper, const SummaryState &summary_state, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:695
Scalar woxygen() const
Definition: WellInterface_impl.hpp:165
IndividualOrGroup
Definition: WellInterface.hpp:253
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: WellInterface.hpp:82
bool updateWellOperabilityFromWellEq(const Simulator &simulator, const WellGroupHelperType &wgHelper, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:1249
virtual void updateWellStateWithTarget(const Simulator &simulator, const WellGroupHelperType &wgHelper, WellStateType &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1280
Scalar computeConnectionDFactor(const int perf, const IntensiveQuantities &intQuants, const SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:1963
typename WellInterfaceFluidSystem< FluidSystem >::RateConverterType RateConverterType
Definition: WellInterface.hpp:105
BlackOilFluidState< Eval, FluidSystem, has_temperature, has_energy, Indices::compositionSwitchIdx >=0, has_watVapor, has_brine, has_saltPrecip, has_disgas_in_water, Indices::numPhases > FluidState
Definition: WellInterface.hpp:139
Scalar wfoam() const
Definition: WellInterface_impl.hpp:127
std::vector< RateVector > connectionRates_
Definition: WellInterface.hpp:378
void computeConnLevelProdInd(const FluidState &fs, const std::function< Scalar(const Scalar)> &connPICalc, const std::vector< Scalar > &mobility, Scalar *connPI) const
Definition: WellInterface_impl.hpp:2159
bool solveWellForTesting(const Simulator &simulator, const WellGroupHelperType &wgHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:811
bool solveWellWithBhp(const Simulator &simulator, const double dt, const Scalar bhp, const WellGroupHelperType &wgHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:733
void gliftBeginTimeStepWellTestUpdateALQ(const Simulator &simulator, WellStateType &well_state, const GroupState< Scalar > &group_state, GLiftEclWells &ecl_well_map, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:1149
Scalar volumetricSurfaceRateForConnection(int cellIdx, int phaseIdx) const
Definition: WellInterface_impl.hpp:1101
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
bool iterateWellEquations(const Simulator &simulator, const double dt, const WellGroupHelperType &wgHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:513
void getMobility(const Simulator &simulator, const int local_perf_index, std::vector< Value > &mob, Callback &extendEval, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:2049
void solveWellEquation(const Simulator &simulator, const WellGroupHelperType &wgHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:863
void assembleWellEq(const Simulator &simulator, const double dt, const WellGroupHelperType &wgHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:925
void assembleWellEqWithoutIteration(const Simulator &simulator, const double dt, WellStateType &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:942
GetPropType< TypeTag, Properties::IntensiveQuantities > IntensiveQuantities
Definition: WellInterface.hpp:87
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: WellInterface.hpp:83
std::vector< Scalar > initialWellRateFractions(const Simulator &ebosSimulator, const WellStateType &well_state) const
Definition: WellInterface_impl.hpp:1725
void updateConnectionDFactor(const Simulator &simulator, SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:1943
Eval getPerfCellPressure(const FluidState &fs) const
Definition: WellInterface_impl.hpp:2034
void initializeProducerWellState(const Simulator &simulator, WellStateType &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1775
void addCellRates(std::map< int, RateVector > &cellRates_) const
Definition: WellInterface_impl.hpp:1082
bool wellUnderZeroGroupRateTarget(const Simulator &simulator, const WellStateType &well_state, DeferredLogger &deferred_logger, std::optional< bool > group_control=std::nullopt) const
Definition: WellInterface_impl.hpp:1693
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:2005
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:2193
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:2227
bool updateWellStateWithTHPTargetProd(const Simulator &simulator, WellStateType &well_state, const WellGroupHelperType &wgHelper, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:2127
Scalar wsalt() const
Definition: WellInterface_impl.hpp:141
bool updateWellControlAndStatusLocalIteration(const Simulator &simulator, const WellGroupHelperType &wgHelper, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, const Scalar WQTotal, WellStateType &well_state, DeferredLogger &deferred_logger, const bool fixed_control=false, const bool fixed_status=false)
Definition: WellInterface_impl.hpp:277
typename Base::Eval Eval
Definition: WellInterface.hpp:96
bool solveWellWithZeroRate(const Simulator &simulator, const double dt, const WellGroupHelperType &wgHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:780
bool wellUnderZeroRateTarget(const Simulator &simulator, const WellStateType &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1675
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
Scalar wpolymer() const
Definition: WellInterface_impl.hpp:111
bool updateWellControl(const Simulator &simulator, const IndividualOrGroup iog, const WellGroupHelperType &wgHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:189
void wellTesting(const Simulator &simulator, const double simulation_time, const WellGroupHelperType &wgHelper, WellStateType &well_state, WellTestState &welltest_state, GLiftEclWells &ecl_well_map, std::map< std::string, double > &open_times, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:387
GetPropType< TypeTag, Properties::Indices > Indices
Definition: WellInterface.hpp:86
bool solveWellWithOperabilityCheck(const Simulator &simulator, const double dt, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, const WellGroupHelperType &wgHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:580
void checkWellOperability(const Simulator &simulator, const WellStateType &well_state, const WellGroupHelperType &wgHelper, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:1121
Scalar wurea() const
Definition: WellInterface_impl.hpp:177
void updateWellOperability(const Simulator &simulator, const WellStateType &well_state, const WellGroupHelperType &wgHelper, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:1211
Scalar wmicrobes() const
Definition: WellInterface_impl.hpp:153
virtual void scaleSegmentRatesAndPressure(WellStateType &well_state) const
Definition: WellInterface_impl.hpp:1272
void prepareWellBeforeAssembling(const Simulator &simulator, const double dt, const WellGroupHelperType &wgHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:962
static constexpr bool has_zFraction
Definition: WellInterface.hpp:114
bool stoppedOrZeroRateTarget(const Simulator &simulator, const WellStateType &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1712
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
Definition: blackoilbioeffectsmodules.hh:43
std::string to_string(const ConvergenceReport::ReservoirFailure::Type t)
Static data associated with a well perforation.
Definition: PerforationData.hpp:30