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,
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(simulator, well_state, 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 wgHelper, 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, wgHelper, well_state, deferred_logger);
344 updatePrimaryVariables(simulator, well_state, 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 = wgHelper.
groupState();
406 deferred_logger.
info(
" well " + this->name() +
" is being tested");
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, well_state_copy, deferred_logger);
428 updatePrimaryVariables(simulator, well_state_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, wgHelper_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, wgHelper_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, wgHelper_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(simulator, well_state_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, wgHelper, 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, wgHelper, well_state, deferred_logger
545 converged = this->iterateWellEqWithSwitching(
546 simulator, dt, inj_controls, prod_controls, wgHelper, 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, wgHelper, 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, wgHelper, 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, wgHelper, well_state, deferred_logger);
624 this->operability_status_.use_vfpexplicit = use_vfpexplicit;
628 converged = this->iterateWellEqWithSwitching(
629 simulator, dt, inj_controls, prod_controls, wgHelper, well_state, deferred_logger,
634 const bool isThp = ws.production_cmode == Well::ProducerCMode::THP;
636 if (converged && !stoppedOrZeroRateTarget(simulator, well_state, deferred_logger) && isThp) {
637 auto rates = well_state.
well(this->index_of_well_).surface_rates;
638 this->adaptRatesForVFP(rates);
639 this->updateIPRImplicit(simulator, wgHelper, 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(), wgHelper, well_state, deferred_logger
655 ws.thp = this->getTHPConstraint(summary_state);
656 converged = this->iterateWellEqWithSwitching(
657 simulator, dt, inj_controls, prod_controls, wgHelper, well_state, deferred_logger,
666 this->operability_status_.use_vfpexplicit =
true;
668 auto bhp_target = estimateOperableBhp(
669 simulator, dt, wgHelper, summary_state, well_state, deferred_logger
671 if (!bhp_target.has_value()) {
674 converged = solveWellWithZeroRate(simulator, dt, wgHelper, 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, wgHelper, 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, wgHelper, well_state, deferred_logger
721 if (!converged || this->wellIsStopped()) {
732 const bool converged = solveWellWithBhp(
733 simulator, dt, bhp_min, wgHelper, well_state, deferred_logger
735 if (!converged || this->wellIsStopped()) {
738 this->updateIPRImplicit(simulator, wgHelper, well_state, deferred_logger);
739 auto rates = well_state.
well(this->index_of_well_).surface_rates;
740 this->adaptRatesForVFP(rates);
744 template<
typename TypeTag>
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, wgHelper_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, wgHelper, 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, wgHelper, well_state, deferred_logger
856 converged = this->iterateWellEqWithSwitching(
857 simulator, dt, inj_controls, prod_controls, wgHelper, 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, wgHelper, 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, wgHelper, 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, wgHelper, well_state, deferred_logger);
955 assembleWellEqWithoutIteration(simulator, wgHelper, 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, wgHelper, 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, wgHelper, 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, wgHelper, 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, wgHelper, well_state, deferred_logger
1033 const bool zero_target = this->wellUnderZeroRateTarget(simulator, well_state, 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, wgHelper, 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, wgHelper, 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, wgHelper, 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, wgHelper, 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, wgHelper, 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, wgHelper, 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();
1288 bool converged = iterateWellEquations(simulator, dt, wgHelper_copy, well_state_copy, deferred_logger);
1292 template<
typename TypeTag>
1300 template<
typename TypeTag>
1309 const auto& group_state = wgHelper.
groupState();
1311 const auto& well = this->well_ecl_;
1312 const int well_index = this->index_of_well_;
1313 auto& ws = well_state.
well(well_index);
1315 const auto& summaryState = simulator.vanguard().summaryState();
1316 const auto& schedule = simulator.vanguard().schedule();
1320 ws.primaryvar.resize(0);
1322 if (this->wellIsStopped()) {
1323 for (
int p = 0; p<np; ++p) {
1324 ws.surface_rates[p] = 0;
1330 if (this->isInjector() )
1332 const auto& controls = well.injectionControls(summaryState);
1334 InjectorType injectorType = controls.injector_type;
1336 switch (injectorType) {
1337 case InjectorType::WATER:
1339 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1342 case InjectorType::OIL:
1344 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1347 case InjectorType::GAS:
1349 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1353 OPM_DEFLOG_THROW(std::runtime_error,
"Expected WATER, OIL or GAS as type for injectors " + this->name(), deferred_logger );
1356 const auto current = ws.injection_cmode;
1359 case Well::InjectorCMode::RATE:
1361 ws.surface_rates[phasePos] = (1.0 - this->rsRvInj()) * controls.surface_rate;
1362 if(this->rsRvInj() > 0) {
1363 if (injectorType == InjectorType::OIL && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1364 const int gas_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1365 ws.surface_rates[gas_pos] = controls.surface_rate * this->rsRvInj();
1366 }
else if (injectorType == InjectorType::GAS && FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1367 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1368 ws.surface_rates[oil_pos] = controls.surface_rate * this->rsRvInj();
1370 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 );
1376 case Well::InjectorCMode::RESV:
1378 std::vector<Scalar> convert_coeff(this->number_of_phases_, 1.0);
1379 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, convert_coeff);
1380 const Scalar coeff = convert_coeff[phasePos];
1381 ws.surface_rates[phasePos] = controls.reservoir_rate/coeff;
1385 case Well::InjectorCMode::THP:
1387 auto rates = ws.surface_rates;
1392 this->getRefDensity(),
1395 ws.thp = this->getTHPConstraint(summaryState);
1400 Scalar total_rate = std::accumulate(rates.begin(), rates.end(), 0.0);
1401 if (total_rate <= 0.0)
1402 ws.surface_rates = ws.well_potentials;
1406 case Well::InjectorCMode::BHP:
1408 ws.bhp = controls.bhp_limit;
1410 for (
int p = 0; p<np; ++p) {
1411 total_rate += ws.surface_rates[p];
1416 if (total_rate <= 0.0)
1417 ws.surface_rates = ws.well_potentials;
1421 case Well::InjectorCMode::GRUP:
1423 assert(well.isAvailableForGroupControl());
1424 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
1425 const Scalar efficiencyFactor = well.getEfficiencyFactor() *
1426 well_state[well.name()].efficiency_scaling_factor;
1427 std::optional<Scalar> target =
1428 this->getGroupInjectionTargetRate(group,
1437 ws.surface_rates[phasePos] = *target;
1440 case Well::InjectorCMode::CMODE_UNDEFINED:
1442 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name(), deferred_logger );
1452 ws.surface_rates[phasePos] = std::max(
Scalar{1.e-7}, ws.surface_rates[phasePos]);
1455 ws.bhp = controls.bhp_limit;
1461 const auto current = ws.production_cmode;
1462 const auto& controls = well.productionControls(summaryState);
1464 case Well::ProducerCMode::ORAT:
1466 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1467 Scalar current_rate = -ws.surface_rates[oil_pos];
1470 if (current_rate > 0.0) {
1471 for (
int p = 0; p<np; ++p) {
1472 ws.surface_rates[p] *= controls.oil_rate/current_rate;
1475 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1476 double control_fraction = fractions[oil_pos];
1477 if (control_fraction != 0.0) {
1478 for (
int p = 0; p<np; ++p) {
1479 ws.surface_rates[p] = - fractions[p] * controls.oil_rate/control_fraction;
1485 case Well::ProducerCMode::WRAT:
1487 const int water_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1488 Scalar current_rate = -ws.surface_rates[water_pos];
1491 if (current_rate > 0.0) {
1492 for (
int p = 0; p<np; ++p) {
1493 ws.surface_rates[p] *= controls.water_rate/current_rate;
1496 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1497 const Scalar control_fraction = fractions[water_pos];
1498 if (control_fraction != 0.0) {
1499 for (
int p = 0; p<np; ++p) {
1500 ws.surface_rates[p] = - fractions[p] * controls.water_rate / control_fraction;
1506 case Well::ProducerCMode::GRAT:
1508 const int gas_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1509 Scalar current_rate = -ws.surface_rates[gas_pos];
1512 if (current_rate > 0.0) {
1513 for (
int p = 0; p<np; ++p) {
1514 ws.surface_rates[p] *= controls.gas_rate/current_rate;
1517 const std::vector<Scalar > fractions = initialWellRateFractions(simulator, well_state);
1518 const Scalar control_fraction = fractions[gas_pos];
1519 if (control_fraction != 0.0) {
1520 for (
int p = 0; p<np; ++p) {
1521 ws.surface_rates[p] = - fractions[p] * controls.gas_rate / control_fraction;
1529 case Well::ProducerCMode::LRAT:
1531 const int water_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1532 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1533 Scalar current_rate = - ws.surface_rates[water_pos]
1534 - ws.surface_rates[oil_pos];
1537 if (current_rate > 0.0) {
1538 for (
int p = 0; p<np; ++p) {
1539 ws.surface_rates[p] *= controls.liquid_rate/current_rate;
1542 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1543 const Scalar control_fraction = fractions[water_pos] + fractions[oil_pos];
1544 if (control_fraction != 0.0) {
1545 for (
int p = 0; p<np; ++p) {
1546 ws.surface_rates[p] = - fractions[p] * controls.liquid_rate / control_fraction;
1552 case Well::ProducerCMode::CRAT:
1555 fmt::format(
"CRAT control not supported, well {}", this->name()),
1558 case Well::ProducerCMode::RESV:
1560 std::vector<Scalar> convert_coeff(this->number_of_phases_, 1.0);
1561 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, ws.surface_rates, convert_coeff);
1562 Scalar total_res_rate = 0.0;
1563 for (
int p = 0; p<np; ++p) {
1564 total_res_rate -= ws.surface_rates[p] * convert_coeff[p];
1566 if (controls.prediction_mode) {
1569 if (total_res_rate > 0.0) {
1570 for (
int p = 0; p<np; ++p) {
1571 ws.surface_rates[p] *= controls.resv_rate/total_res_rate;
1574 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1575 for (
int p = 0; p<np; ++p) {
1576 ws.surface_rates[p] = - fractions[p] * controls.resv_rate / convert_coeff[p];
1580 std::vector<Scalar> hrates(this->number_of_phases_,0.);
1581 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
1582 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1583 hrates[phase_pos] = controls.water_rate;
1585 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1586 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1587 hrates[phase_pos] = controls.oil_rate;
1589 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1590 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1591 hrates[phase_pos] = controls.gas_rate;
1593 std::vector<Scalar> hrates_resv(this->number_of_phases_,0.);
1594 this->rateConverter_.calcReservoirVoidageRates( 0, this->pvtRegionIdx_, hrates, hrates_resv);
1595 Scalar target = std::accumulate(hrates_resv.begin(), hrates_resv.end(), 0.0);
1598 if (total_res_rate > 0.0) {
1599 for (
int p = 0; p<np; ++p) {
1600 ws.surface_rates[p] *= target/total_res_rate;
1603 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1604 for (
int p = 0; p<np; ++p) {
1605 ws.surface_rates[p] = - fractions[p] * target / convert_coeff[p];
1611 case Well::ProducerCMode::BHP:
1613 ws.bhp = controls.bhp_limit;
1615 for (
int p = 0; p<np; ++p) {
1616 total_rate -= ws.surface_rates[p];
1621 if (total_rate <= 0.0){
1622 for (
int p = 0; p<np; ++p) {
1623 ws.surface_rates[p] = -ws.well_potentials[p];
1628 case Well::ProducerCMode::THP:
1630 const bool update_success = updateWellStateWithTHPTargetProd(simulator, well_state, wgHelper, deferred_logger);
1632 if (!update_success) {
1636 auto rates = ws.surface_rates;
1637 this->adaptRatesForVFP(rates);
1639 well_state, rates, well, summaryState, this->getRefDensity(), deferred_logger);
1641 ws.thp = this->getTHPConstraint(summaryState);
1645 const Scalar total_rate = -std::accumulate(rates.begin(), rates.end(), 0.0);
1646 if (total_rate <= 0.0) {
1647 for (
int p = 0; p < this->number_of_phases_; ++p) {
1648 ws.surface_rates[p] = -ws.well_potentials[p];
1654 case Well::ProducerCMode::GRUP:
1656 assert(well.isAvailableForGroupControl());
1657 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
1658 const Scalar efficiencyFactor = well.getEfficiencyFactor() *
1659 well_state[well.name()].efficiency_scaling_factor;
1660 Scalar scale = this->getGroupProductionTargetRate(group,
1670 for (
int p = 0; p<np; ++p) {
1671 ws.surface_rates[p] *= scale;
1673 ws.trivial_group_target =
false;
1677 ws.trivial_group_target =
true;
1681 case Well::ProducerCMode::CMODE_UNDEFINED:
1684 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name() , deferred_logger);
1690 ws.bhp = controls.bhp_limit;
1695 template<
typename TypeTag>
1704 const bool isGroupControlled = this->wellUnderGroupControl(well_state.
well(this->index_of_well_));
1705 if (!isGroupControlled) {
1707 const auto& summaryState = simulator.vanguard().summaryState();
1708 return this->wellUnderZeroRateTargetIndividual(summaryState, well_state);
1710 return this->wellUnderZeroGroupRateTarget(simulator, well_state, deferred_logger, isGroupControlled);
1714 template <
typename TypeTag>
1719 const std::optional<bool> group_control)
const
1722 const bool isGroupControlled = group_control.value_or(this->wellUnderGroupControl(well_state.
well(this->index_of_well_)));
1723 if (isGroupControlled) {
1724 const auto& summaryState = simulator.vanguard().summaryState();
1725 const auto& group_state = simulator.problem().wellModel().groupState();
1726 const auto& schedule = simulator.vanguard().schedule();
1727 return this->zeroGroupRateTarget(summaryState, schedule, well_state, group_state, deferred_logger);
1732 template<
typename TypeTag>
1741 return this->wellIsStopped()
1742 || this->wellUnderZeroRateTarget(simulator, well_state, deferred_logger);
1745 template<
typename TypeTag>
1746 std::vector<typename WellInterface<TypeTag>::Scalar>
1752 const int np = this->number_of_phases_;
1753 std::vector<Scalar> scaling_factor(np);
1754 const auto& ws = well_state.
well(this->index_of_well_);
1756 Scalar total_potentials = 0.0;
1757 for (
int p = 0; p<np; ++p) {
1758 total_potentials += ws.well_potentials[p];
1760 if (total_potentials > 0) {
1761 for (
int p = 0; p<np; ++p) {
1762 scaling_factor[p] = ws.well_potentials[p] / total_potentials;
1764 return scaling_factor;
1769 const int nperf = this->number_of_local_perforations_;
1770 for (
int perf = 0; perf < nperf; ++perf) {
1771 total_tw += this->well_index_[perf];
1773 total_tw = this->parallelWellInfo().communication().sum(total_tw);
1775 for (
int perf = 0; perf < nperf; ++perf) {
1776 const int cell_idx = this->well_cells_[perf];
1777 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
1778 const auto& fs = intQuants.fluidState();
1779 const Scalar well_tw_fraction = this->well_index_[perf] / total_tw;
1780 Scalar total_mobility = 0.0;
1781 for (
int p = 0; p < np; ++p) {
1782 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
1783 total_mobility += fs.invB(canonical_phase_idx).value() * intQuants.mobility(canonical_phase_idx).value();
1785 for (
int p = 0; p < np; ++p) {
1786 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
1787 scaling_factor[p] += well_tw_fraction * fs.invB(canonical_phase_idx).value() * intQuants.mobility(canonical_phase_idx).value() / total_mobility;
1790 return scaling_factor;
1795 template <
typename TypeTag>
1802 assert(this->isProducer());
1806 auto& ws = well_state.
well(this->index_of_well_);
1807 int nonzero_rate_index = -1;
1808 const Scalar floating_point_error_epsilon = 1e-14;
1809 for (
int p = 0; p < this->number_of_phases_; ++p) {
1810 if (std::abs(ws.surface_rates[p]) > floating_point_error_epsilon) {
1811 if (nonzero_rate_index == -1) {
1812 nonzero_rate_index = p;
1821 std::vector<Scalar> well_q_s(this->number_of_phases_, 0.0);
1822 bool rates_evaluated_at_1bar =
false;
1824 const auto& summary_state = simulator.vanguard().summaryState();
1825 const auto& prod_controls = this->well_ecl_.productionControls(summary_state);
1826 const double bhp_limit = std::max(prod_controls.bhp_limit, 1.0 * unit::barsa);
1827 this->computeWellRatesWithBhp(simulator, bhp_limit, well_q_s, deferred_logger);
1829 rates_evaluated_at_1bar = (bhp_limit < 1.1 * unit::barsa);
1831 if (std::any_of(well_q_s.begin(), well_q_s.end(), [](
Scalar q) { return q > 0.0; })) {
1833 if (!rates_evaluated_at_1bar) {
1834 this->computeWellRatesWithBhp(simulator, 1.0 * unit::barsa, well_q_s, deferred_logger);
1835 rates_evaluated_at_1bar =
true;
1838 for (
auto& q : well_q_s) {
1839 q = std::min(q,
Scalar{0.0});
1844 if (nonzero_rate_index == -1) {
1848 const Scalar factor = rates_evaluated_at_1bar ? 0.5 : 1.0;
1849 for (
int p = 0; p < this->number_of_phases_; ++p) {
1850 ws.surface_rates[p] = factor * well_q_s[p];
1859 const Scalar initial_nonzero_rate = ws.surface_rates[nonzero_rate_index];
1860 const Scalar computed_rate = well_q_s[nonzero_rate_index];
1861 if (std::abs(initial_nonzero_rate) < std::abs(computed_rate)) {
1863 const Scalar factor = initial_nonzero_rate / computed_rate;
1864 assert(factor < 1.0);
1865 for (
int p = 0; p < this->number_of_phases_; ++p) {
1867 if (p != nonzero_rate_index) {
1868 ws.surface_rates[p] = factor * well_q_s[p];
1877 for (
int p = 0; p < this->number_of_phases_; ++p) {
1878 ws.surface_rates[p] = well_q_s[p];
1882 template <
typename TypeTag>
1883 template<
class Value>
1886 getTw(std::vector<Value>& Tw,
1889 const Value& trans_mult,
1892 OPM_TIMEFUNCTION_LOCAL(Subsystem::Wells);
1895 if (
static_cast<std::size_t
>(perf) >= this->well_cells_.size()) {
1896 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!");
1899 if constexpr (! Indices::gasEnabled) {
1903 const auto& wdfac = this->well_ecl_.getWDFAC();
1905 if (! wdfac.useDFactor() || (this->well_index_[perf] == 0.0)) {
1909 const Scalar d = this->computeConnectionDFactor(perf, intQuants, ws);
1916 const auto& connection = this->well_ecl_.getConnections()[ws.
perf_data.ecl_index[perf]];
1917 const Scalar Kh = connection.Kh();
1918 const Scalar scaling = 3.141592653589 * Kh * connection.wpimult();
1919 const unsigned gas_comp_idx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
1922 const Scalar cell_pressure = getValue(intQuants.fluidState().pressure(FluidSystem::gasPhaseIdx));
1923 const Scalar drawdown = cell_pressure - connection_pressure;
1924 const Scalar invB = getValue(intQuants.fluidState().invB(FluidSystem::gasPhaseIdx));
1925 const Scalar mob_g = getValue(intQuants.mobility(FluidSystem::gasPhaseIdx)) * invB;
1927 const Scalar b = 2 * scaling / getValue(Tw[gas_comp_idx]);
1928 const Scalar c = -2 * scaling * mob_g * drawdown;
1930 Scalar consistent_Q = -1.0e20;
1932 const Scalar r2n = b*b + 4*a*c;
1934 const Scalar rn = std::sqrt(r2n);
1935 const Scalar xn1 = (b-rn)*0.5/a;
1939 const Scalar xn2 = (b+rn)*0.5/a;
1940 if (xn2 <= 0 && xn2 > consistent_Q) {
1946 const Scalar r2p = b*b - 4*a*c;
1948 const Scalar rp = std::sqrt(r2p);
1949 const Scalar xp1 = (rp-b)*0.5/a;
1950 if (xp1 > 0 && xp1 < consistent_Q) {
1953 const Scalar xp2 = -(rp+b)*0.5/a;
1954 if (xp2 > 0 && xp2 < consistent_Q) {
1958 Tw[gas_comp_idx] = 1.0 / (1.0 / (trans_mult * this->well_index_[perf]) + (consistent_Q/2 * d / scaling));
1961 template <
typename TypeTag>
1967 if (! this->well_ecl_.getWDFAC().useDFactor()) {
1971 auto& d_factor = ws.
perf_data.connection_d_factor;
1973 for (
int perf = 0; perf < this->number_of_local_perforations_; ++perf) {
1974 const int cell_idx = this->well_cells_[perf];
1975 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
1977 d_factor[perf] = this->computeConnectionDFactor(perf, intQuants, ws);
1981 template <
typename TypeTag>
1988 auto rhoGS = [regIdx = this->pvtRegionIdx()]() {
1989 return FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, regIdx);
1993 auto gas_visc = [connection_pressure = ws.
perf_data.pressure[perf],
1995 regIdx = this->pvtRegionIdx(), &intQuants]()
1997 const auto rv = getValue(intQuants.fluidState().Rv());
1999 const auto& gasPvt = FluidSystem::gasPvt();
2004 const Scalar rv_sat = gasPvt.saturatedOilVaporizationFactor
2005 (regIdx, temperature, connection_pressure);
2007 if (! (rv < rv_sat)) {
2008 return gasPvt.saturatedViscosity(regIdx, temperature,
2009 connection_pressure);
2012 return gasPvt.viscosity(regIdx, temperature, connection_pressure,
2013 rv, getValue(intQuants.fluidState().Rvw()));
2016 const auto& connection = this->well_ecl_.getConnections()
2019 return this->well_ecl_.getWDFAC().getDFactor(rhoGS, gas_visc, connection);
2023 template <
typename TypeTag>
2029 auto connCF = [&connIx = std::as_const(ws.
perf_data.ecl_index),
2030 &conns = this->well_ecl_.getConnections()]
2033 return conns[connIx[perf]].CF();
2036 auto obtain = [](
const Eval& value)
2038 return getValue(value);
2041 auto& tmult = ws.
perf_data.connection_compaction_tmult;
2042 auto& ctf = ws.
perf_data.connection_transmissibility_factor;
2044 for (
int perf = 0; perf < this->number_of_local_perforations_; ++perf) {
2045 const int cell_idx = this->well_cells_[perf];
2047 getTransMult(trans_mult, simulator, cell_idx, obtain);
2048 tmult[perf] = trans_mult;
2050 ctf[perf] = connCF(perf) * tmult[perf];
2055 template<
typename TypeTag>
2059 if constexpr (Indices::oilEnabled) {
2060 return fs.pressure(FluidSystem::oilPhaseIdx);
2061 }
else if constexpr (Indices::gasEnabled) {
2062 return fs.pressure(FluidSystem::gasPhaseIdx);
2064 return fs.pressure(FluidSystem::waterPhaseIdx);
2068 template <
typename TypeTag>
2069 template<
class Value,
class Callback>
2075 Callback& extendEval)
const
2077 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2078 trans_mult = simulator.problem().template wellTransMultiplier<Value>(intQuants, cell_idx, extendEval);
2081 template <
typename TypeTag>
2082 template<
class Value,
class Callback>
2086 const int local_perf_index,
2087 std::vector<Value>& mob,
2088 Callback& extendEval,
2091 auto relpermArray = []()
2093 if constexpr (std::is_same_v<Value, Scalar>) {
2094 return std::array<Scalar,3>{};
2096 return std::array<Eval,3>{};
2099 if (
static_cast<std::size_t
>(local_perf_index) >= this->well_cells_.size()) {
2100 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!");
2102 const int cell_idx = this->well_cells_[local_perf_index];
2103 assert (
int(mob.size()) == this->num_conservation_quantities_);
2104 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2105 const auto& materialLawManager = simulator.problem().materialLawManager();
2109 const int satid = this->saturation_table_number_[local_perf_index] - 1;
2110 const int satid_elem = materialLawManager->satnumRegionIdx(cell_idx);
2111 if (satid == satid_elem) {
2112 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2113 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2117 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2118 mob[activeCompIdx] = extendEval(intQuants.mobility(phaseIdx));
2120 if constexpr (has_solvent) {
2121 mob[Indices::contiSolventEqIdx] = extendEval(intQuants.solventMobility());
2124 const auto& paramsCell = materialLawManager->connectionMaterialLawParams(satid, cell_idx);
2125 auto relativePerms = relpermArray();
2126 MaterialLaw::relativePermeabilities(relativePerms, paramsCell, intQuants.fluidState());
2129 materialLawManager->connectionMaterialLawParams(satid_elem, cell_idx);
2132 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2133 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2137 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2138 mob[activeCompIdx] = extendEval(relativePerms[phaseIdx] / intQuants.fluidState().viscosity(phaseIdx));
2142 if constexpr (has_solvent) {
2143 OPM_DEFLOG_THROW(std::runtime_error,
"individual mobility for wells does not work in combination with solvent", deferred_logger);
2147 if (this->isInjector() && !this->inj_fc_multiplier_.empty()) {
2148 const auto perf_ecl_index = this->perforationData()[local_perf_index].ecl_index;
2149 const auto& connections = this->well_ecl_.getConnections();
2150 const auto& connection = connections[perf_ecl_index];
2151 if (connection.filterCakeActive()) {
2152 std::transform(mob.begin(), mob.end(), mob.begin(),
2153 [mult = this->inj_fc_multiplier_[local_perf_index] ](
const auto val)
2154 { return val * mult; });
2160 template<
typename TypeTag>
2169 const auto& summary_state = simulator.vanguard().summaryState();
2171 auto bhp_at_thp_limit = computeBhpAtThpLimitProdWithAlq(
2172 simulator, wgHelper, summary_state, this->getALQ(well_state), deferred_logger,
false);
2173 if (bhp_at_thp_limit) {
2174 std::vector<Scalar> rates(this->number_of_phases_, 0.0);
2175 if (thp_update_iterations) {
2176 computeWellRatesWithBhpIterations(simulator, *bhp_at_thp_limit,
2177 wgHelper, rates, deferred_logger);
2179 computeWellRatesWithBhp(simulator, *bhp_at_thp_limit,
2180 rates, deferred_logger);
2182 auto& ws = well_state.
well(this->name());
2183 ws.surface_rates = rates;
2184 ws.bhp = *bhp_at_thp_limit;
2185 ws.thp = this->getTHPConstraint(summary_state);
2192 template <
typename TypeTag>
2197 const std::vector<Scalar>& mobility,
2200 const int np = this->number_of_phases_;
2201 for (
int p = 0; p < np; ++p) {
2204 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
2205 const auto connMob =
2206 mobility[FluidSystem::activePhaseToActiveCompIdx(p)] * fs.invB(canonical_phase_idx).value();
2208 connPI[p] = connPICalc(connMob);
2211 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) &&
2212 FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx))
2214 const auto io = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
2215 const auto ig = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
2217 const auto vapoil = connPI[ig] * fs.Rv().value();
2218 const auto disgas = connPI[io] * fs.Rs().value();
2220 connPI[io] += vapoil;
2221 connPI[ig] += disgas;
2226 template <
typename TypeTag>
2230 const Phase preferred_phase,
2232 const std::vector<Scalar>& mobility,
2237 if (preferred_phase == Phase::GAS) {
2238 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
2240 else if (preferred_phase == Phase::OIL) {
2241 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
2243 else if (preferred_phase == Phase::WATER) {
2244 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
2248 fmt::format(
"Unsupported Injector Type ({}) "
2249 "for well {} during connection I.I. calculation",
2250 static_cast<int>(preferred_phase), this->name()),
2254 const auto mt = std::accumulate(mobility.begin(), mobility.end(), 0.0);
2255 const int canonicalPhaseIdx = FluidSystem::activeToCanonicalPhaseIdx(phase_pos);
2256 connII[phase_pos] = connIICalc(mt * fs.invB(canonicalPhaseIdx).value());
2259 template<
typename TypeTag>
2260 template<
class GasLiftSingleWell>
2261 std::unique_ptr<GasLiftSingleWell>
2270 auto& comm = simulator.vanguard().grid().comm();
2271 ecl_well_map.try_emplace(this->name(), &(this->wellEcl()), this->indexOfWell());
2274 simulator.vanguard().schedule(),
2275 simulator.vanguard().summaryState(),
2276 simulator.episodeIndex(),
2277 simulator.model().newtonMethod().numIterations(),
2286 std::set<int> sync_groups;
2287 const auto& summary_state = simulator.vanguard().summaryState();
2288 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:104
PerfData< Scalar > perf_data
Definition: SingleWellState.hpp:127
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:59
const GroupState< Scalar > & groupState() const
Definition: WellGroupHelper.hpp:183
GroupStateGuard pushGroupState(GroupState< Scalar > &group_state)
Definition: WellGroupHelper.hpp:193
const WellState< Scalar, IndexTraits > & wellState() const
Definition: WellGroupHelper.hpp:312
WellStateGuard pushWellState(WellState< Scalar, IndexTraits > &well_state)
Definition: WellGroupHelper.hpp:198
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
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:709
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:254
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: WellInterface.hpp:82
bool updateWellOperabilityFromWellEq(const Simulator &simulator, const WellGroupHelperType &wgHelper, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:1272
virtual void updateWellStateWithTarget(const Simulator &simulator, const WellGroupHelperType &wgHelper, WellStateType &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1303
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, const bool fixed_status, const bool solving_with_zero_rate)
Definition: WellInterface_impl.hpp:277
Scalar computeConnectionDFactor(const int perf, const IntensiveQuantities &intQuants, const SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:1984
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:2072
std::vector< RateVector > connectionRates_
Definition: WellInterface.hpp:376
void computeConnLevelProdInd(const FluidState &fs, const std::function< Scalar(const Scalar)> &connPICalc, const std::vector< Scalar > &mobility, Scalar *connPI) const
Definition: WellInterface_impl.hpp:2195
void assembleWellEqWithoutIteration(const Simulator &simulator, const WellGroupHelperType &wgHelper, const double dt, WellStateType &well_state, DeferredLogger &deferred_logger, const bool solving_with_zero_rate)
Definition: WellInterface_impl.hpp:964
bool solveWellForTesting(const Simulator &simulator, const WellGroupHelperType &wgHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:830
bool solveWellWithBhp(const Simulator &simulator, const double dt, const Scalar bhp, const WellGroupHelperType &wgHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:747
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:1886
bool iterateWellEquations(const Simulator &simulator, const double dt, const WellGroupHelperType &wgHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:521
void getMobility(const Simulator &simulator, const int local_perf_index, std::vector< Value > &mob, Callback &extendEval, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:2085
void solveWellEquation(const Simulator &simulator, const WellGroupHelperType &wgHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:885
void assembleWellEq(const Simulator &simulator, const double dt, const WellGroupHelperType &wgHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:947
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:1748
void updateConnectionDFactor(const Simulator &simulator, SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:1964
Eval getPerfCellPressure(const FluidState &fs) const
Definition: WellInterface_impl.hpp:2057
void initializeProducerWellState(const Simulator &simulator, WellStateType &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1798
void addCellRates(std::map< int, RateVector > &cellRates_) const
Definition: WellInterface_impl.hpp:1105
bool wellUnderZeroGroupRateTarget(const Simulator &simulator, const WellStateType &well_state, DeferredLogger &deferred_logger, std::optional< bool > group_control=std::nullopt) const
Definition: WellInterface_impl.hpp:1716
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:2026
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:2229
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:2263
bool updateWellStateWithTHPTargetProd(const Simulator &simulator, WellStateType &well_state, const WellGroupHelperType &wgHelper, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:2163
Scalar wsalt() const
Definition: WellInterface_impl.hpp:141
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:797
bool wellUnderZeroRateTarget(const Simulator &simulator, const WellStateType &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1698
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:395
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:589
void checkWellOperability(const Simulator &simulator, const WellStateType &well_state, const WellGroupHelperType &wgHelper, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:1144
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:1234
Scalar wmicrobes() const
Definition: WellInterface_impl.hpp:153
virtual void scaleSegmentRatesAndPressure(WellStateType &well_state) const
Definition: WellInterface_impl.hpp:1295
void prepareWellBeforeAssembling(const Simulator &simulator, const double dt, const WellGroupHelperType &wgHelper, WellStateType &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:985
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:1735
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