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>
51#include <fmt/format.h>
57 template<
typename TypeTag>
64 const int pvtRegionIdx,
65 const int num_conservation_quantities,
67 const int index_of_well,
75 num_conservation_quantities,
83 if (well.isInjector()) {
84 auto injectorType = this->
well_ecl_.injectorType();
85 if (injectorType == InjectorType::GAS) {
93 template<
typename TypeTag>
96 init(
const std::vector<Scalar>& ,
98 const std::vector<Scalar>& B_avg,
99 const bool changed_to_open_this_step)
101 this->gravity_ = gravity_arg;
103 this->changed_to_open_this_step_ = changed_to_open_this_step;
109 template<
typename TypeTag>
114 if constexpr (has_polymer) {
115 return this->wpolymer_();
125 template<
typename TypeTag>
130 if constexpr (has_foam) {
131 return this->wfoam_();
139 template<
typename TypeTag>
144 if constexpr (has_brine) {
145 return this->wsalt_();
151 template<
typename TypeTag>
156 if constexpr (has_micp) {
157 return this->wmicrobes_();
163 template<
typename TypeTag>
168 if constexpr (has_micp) {
169 return this->woxygen_();
175 template<
typename TypeTag>
180 if constexpr (has_micp) {
181 return this->wurea_();
187 template<
typename TypeTag>
197 if (stoppedOrZeroRateTarget(groupStateHelper)) {
201 const auto& summaryState = simulator.vanguard().summaryState();
202 const auto& schedule = simulator.vanguard().schedule();
203 const auto& well = this->well_ecl_;
204 auto& ws = well_state.
well(this->index_of_well_);
206 bool is_grup =
false;
207 if (well.isInjector()) {
208 from = WellInjectorCMode2String(ws.injection_cmode);
209 is_grup = ws.injection_cmode == Well::InjectorCMode::GRUP;
211 from = WellProducerCMode2String(ws.production_cmode);
212 is_grup = ws.production_cmode == Well::ProducerCMode::GRUP;
215 const int episodeIdx = simulator.episodeIndex();
216 const auto& iterCtx = simulator.problem().iterationContext();
217 const int nupcol = schedule[episodeIdx].nupcol();
218 const bool oscillating =
219 std::ranges::count(this->well_control_log_, from) >= this->param_.max_number_of_well_switches_;
220 if (oscillating && !is_grup) {
223 std::ranges::count(this->well_control_log_, from) == this->param_.max_number_of_well_switches_;
225 const auto msg = fmt::format(
" The control mode for well {} is oscillating. \n"
226 "We don't allow for more than {} switches after NUPCOL iterations. (NUPCOL = {}) \n"
227 "The control is kept at {}.",
228 this->name(), this->param_.max_number_of_well_switches_, nupcol, from);
229 deferred_logger.info(msg);
231 this->well_control_log_.push_back(from);
235 bool changed =
false;
236 if (iog == IndividualOrGroup::Individual) {
237 changed = this->checkIndividualConstraints(ws, summaryState, deferred_logger);
238 }
else if (iog == IndividualOrGroup::Group) {
239 changed = this->checkGroupConstraints(
240 groupStateHelper, schedule, summaryState,
true, well_state
243 assert(iog == IndividualOrGroup::Both);
244 changed = this->checkConstraints(groupStateHelper, schedule, summaryState, well_state);
250 if (well.isInjector()) {
251 to = WellInjectorCMode2String(ws.injection_cmode);
253 to = WellProducerCMode2String(ws.production_cmode);
255 std::ostringstream ss;
256 ss <<
" Switching control mode for well " << this->name()
259 if (iterCtx.inLocalSolve()) {
260 ss <<
" (NLDD domain solve)";
263 ss <<
" on rank " << cc.rank();
265 deferred_logger.debug(ss.str());
272 if (!iterCtx.inLocalSolve()) {
273 if (!iterCtx.withinNupcol(nupcol) || this->well_control_log_.empty()) {
274 this->well_control_log_.push_back(from);
277 updateWellStateWithTarget(simulator, groupStateHelper, well_state);
278 updatePrimaryVariables(groupStateHelper);
284 template<
typename TypeTag>
289 const Well::InjectionControls& inj_controls,
290 const Well::ProductionControls& prod_controls,
293 const bool fixed_control,
294 const bool fixed_status,
295 const bool solving_with_zero_rate)
299 const auto& summary_state = simulator.vanguard().summaryState();
300 const auto& schedule = simulator.vanguard().schedule();
301 auto& ws = well_state.
well(this->index_of_well_);
303 if (this->isInjector()) {
304 from = WellInjectorCMode2String(ws.injection_cmode);
306 from = WellProducerCMode2String(ws.production_cmode);
308 const bool oscillating =
309 std::ranges::count(this->well_control_log_, from) >= this->param_.max_number_of_well_switches_;
311 if (oscillating || this->wellUnderZeroRateTarget(groupStateHelper) || !(well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
315 const Scalar sgn = this->isInjector() ? 1.0 : -1.0;
316 if (!this->wellIsStopped()){
317 if (wqTotal*sgn <= 0.0 && !fixed_status){
321 bool changed =
false;
322 if (!fixed_control) {
325 if (solving_with_zero_rate) {
327 "Well {}: solving_with_zero_rate should not be true when fixed_control is false",
328 this->name()), deferred_logger);
334 const bool hasGroupControl = this->isInjector() ? inj_controls.hasControl(Well::InjectorCMode::GRUP) :
335 prod_controls.hasControl(Well::ProducerCMode::GRUP);
336 bool isGroupControl = ws.production_cmode == Well::ProducerCMode::GRUP || ws.injection_cmode == Well::InjectorCMode::GRUP;
337 if (! (isGroupControl && !this->param_.check_group_constraints_inner_well_iterations_)) {
338 changed = this->checkIndividualConstraints(ws, summary_state, deferred_logger, inj_controls, prod_controls);
340 if (hasGroupControl && this->param_.check_group_constraints_inner_well_iterations_) {
341 changed = changed || this->checkGroupConstraints(
342 groupStateHelper, schedule, summary_state,
false, well_state
347 const bool thp_controlled = this->isInjector() ? ws.injection_cmode == Well::InjectorCMode::THP :
348 ws.production_cmode == Well::ProducerCMode::THP;
350 ws.thp = this->getTHPConstraint(summary_state);
353 updateWellStateWithTarget(simulator, groupStateHelper, well_state);
355 updatePrimaryVariables(groupStateHelper);
360 }
else if (!fixed_status){
362 const Scalar bhp = well_state.
well(this->index_of_well_).bhp;
363 Scalar prod_limit = prod_controls.bhp_limit;
364 Scalar inj_limit = inj_controls.bhp_limit;
365 const bool has_thp = this->wellHasTHPConstraints(summary_state);
367 std::vector<Scalar> rates(this->num_conservation_quantities_);
368 if (this->isInjector()){
370 calculateBhpFromThp(well_state, rates,
373 this->getRefDensity(),
375 inj_limit = std::min(bhp_thp,
static_cast<Scalar>(inj_controls.bhp_limit));
380 calculateMinimumBhpFromThp(well_state,
383 this->getRefDensity());
384 prod_limit = std::max(bhp_min,
static_cast<Scalar>(prod_controls.bhp_limit));
387 const Scalar bhp_diff = (this->isInjector())? inj_limit - bhp: bhp - prod_limit;
390 well_state.
well(this->index_of_well_).bhp = (this->isInjector())? inj_limit : prod_limit;
392 well_state.
well(this->index_of_well_).thp = this->getTHPConstraint(summary_state);
403 template<
typename TypeTag>
407 const double simulation_time,
410 WellTestState& well_test_state,
412 std::map<std::string, double>& open_times)
416 const auto& group_state = groupStateHelper.
groupState();
417 deferred_logger.info(
" well " + this->name() +
" is being tested");
424 auto guard = groupStateHelper_copy.
pushWellState(well_state_copy);
425 auto& ws = well_state_copy.
well(this->indexOfWell());
427 const auto& summary_state = simulator.vanguard().summaryState();
428 const bool has_thp_limit = this->wellHasTHPConstraints(summary_state);
429 if (this->isProducer()) {
430 ws.production_cmode = has_thp_limit ? Well::ProducerCMode::THP : Well::ProducerCMode::BHP;
432 ws.injection_cmode = has_thp_limit ? Well::InjectorCMode::THP : Well::InjectorCMode::BHP;
437 scaleSegmentRatesAndPressure(well_state_copy);
438 calculateExplicitQuantities(simulator, groupStateHelper_copy);
439 updatePrimaryVariables(groupStateHelper_copy);
441 if (this->isProducer()) {
442 const auto& schedule = simulator.vanguard().schedule();
443 const auto report_step = simulator.episodeIndex();
444 const auto& glo = schedule.glo(report_step);
446 gliftBeginTimeStepWellTestUpdateALQ(simulator,
454 WellTestState welltest_state_temp;
456 bool testWell =
true;
461 const std::size_t original_number_closed_completions = welltest_state_temp.num_closed_completions();
462 bool converged = solveWellForTesting(simulator, groupStateHelper_copy, well_state_copy);
464 const auto msg = fmt::format(
"WTEST: Well {} is not solvable (physical)", this->name());
465 deferred_logger.debug(msg);
470 updateWellOperability(simulator, well_state_copy, groupStateHelper_copy);
471 if ( !this->isOperableAndSolvable() ) {
472 const auto msg = fmt::format(
"WTEST: Well {} is not operable (physical)", this->name());
473 deferred_logger.debug(msg);
476 std::vector<Scalar> potentials;
478 computeWellPotentials(simulator, well_state_copy, groupStateHelper_copy, potentials);
479 }
catch (
const std::exception& e) {
480 const std::string msg = fmt::format(
"well {}: computeWellPotentials() "
481 "failed during testing for re-opening: ",
482 this->name(), e.what());
483 deferred_logger.info(msg);
486 const int np = well_state_copy.
numPhases();
487 for (
int p = 0; p < np; ++p) {
488 ws.well_potentials[p] = std::max(
Scalar{0.0}, potentials[p]);
490 const bool under_zero_target = this->wellUnderZeroGroupRateTarget(groupStateHelper_copy);
491 this->updateWellTestState(well_state_copy.
well(this->indexOfWell()),
497 this->closeCompletions(welltest_state_temp);
503 if ( welltest_state_temp.num_closed_wells() > 0 ||
504 (original_number_closed_completions == welltest_state_temp.num_closed_completions()) ) {
510 if (!welltest_state_temp.well_is_closed(this->name())) {
511 well_test_state.open_well(this->name());
513 std::string msg = std::string(
"well ") + this->name() + std::string(
" is re-opened");
514 deferred_logger.info(msg);
517 for (
const auto& completion : this->well_ecl_.getCompletions()) {
518 if (!welltest_state_temp.completion_is_closed(this->name(), completion.first))
519 well_test_state.open_completion(this->name(), completion.first);
521 well_state = well_state_copy;
522 open_times.try_emplace(this->name(), well_test_state.lastTestTime(this->name()));
529 template<
typename TypeTag>
540 const auto& summary_state = simulator.vanguard().summaryState();
541 const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
542 const auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
543 const auto& ws = well_state.
well(this->indexOfWell());
544 const auto pmode_orig = ws.production_cmode;
545 const auto imode_orig = ws.injection_cmode;
546 bool converged =
false;
549 if (!this->param_.local_well_solver_control_switching_){
550 converged = this->iterateWellEqWithControl(simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state);
552 if (this->param_.use_implicit_ipr_ && this->well_ecl_.isProducer() && (well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
553 converged = solveWellWithOperabilityCheck(
554 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state
557 converged = this->iterateWellEqWithSwitching(
558 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
564 }
catch (NumericalProblem& e ) {
565 const std::string msg =
"Inner well iterations failed for well " + this->name() +
" Treat the well as unconverged. ";
566 deferred_logger.warning(
"INNER_ITERATION_FAILED", msg);
571 if (ws.production_cmode != pmode_orig || ws.injection_cmode != imode_orig) {
573 if (this->isInjector()) {
574 from = WellInjectorCMode2String(imode_orig);
575 to = WellInjectorCMode2String(ws.injection_cmode);
577 from = WellProducerCMode2String(pmode_orig);
578 to = WellProducerCMode2String(ws.production_cmode);
580 const auto msg = fmt::format(
" Well {} switched from {} to {} during local solve", this->name(), from, to);
581 deferred_logger.debug(msg);
582 const int episodeIdx = simulator.episodeIndex();
583 const auto& iterCtx = simulator.problem().iterationContext();
584 const auto& schedule = simulator.vanguard().schedule();
585 const int nupcol = schedule[episodeIdx].nupcol();
589 if (!iterCtx.withinNupcol(nupcol) || this->well_control_log_.empty()) {
590 this->well_control_log_.push_back(from);
595 if (this->isProducer() && ws.production_cmode == Well::ProducerCMode::GRUP && ws.use_group_target_fallback) {
596 assert(ws.group_target && ws.group_target_fallback);
597 const std::string cmode = Group::ProductionCMode2String(ws.group_target->production_cmode);
598 const std::string cmode_fallback = Group::ProductionCMode2String(ws.group_target_fallback->production_cmode);
599 const auto msg = fmt::format(
" Well {} was solved using group target fallback mode {} as current group mode {} was not feasible.",
600 this->name(), cmode_fallback, cmode);
601 deferred_logger.debug(msg);
607 template<
typename TypeTag>
612 const Well::InjectionControls& inj_controls,
613 const Well::ProductionControls& prod_controls,
620 const auto& summary_state = simulator.vanguard().summaryState();
621 bool converged =
true;
622 auto& ws = well_state.
well(this->index_of_well_);
624 if (this->wellIsStopped()) {
626 const bool use_vfpexplicit = this->operability_status_.use_vfpexplicit;
627 this->operability_status_.use_vfpexplicit =
true;
628 auto bhp_target = estimateOperableBhp(simulator, dt, groupStateHelper, summary_state, well_state);
629 if (!bhp_target.has_value()) {
631 const auto msg = fmt::format(
"estimateOperableBhp: Did not find operable BHP for well {}", this->name());
632 deferred_logger.debug(msg);
635 converged = solveWellWithZeroRate(simulator, dt, groupStateHelper, well_state);
637 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
638 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
642 ws.thp = this->getTHPConstraint(summary_state);
643 const Scalar bhp = std::max(bhp_target.value(),
644 static_cast<Scalar>(prod_controls.bhp_limit));
645 solveWellWithBhp(simulator, dt, bhp, groupStateHelper, well_state);
646 this->operability_status_.use_vfpexplicit = use_vfpexplicit;
650 converged = this->iterateWellEqWithSwitching(
651 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
656 const bool isThp = ws.production_cmode == Well::ProducerCMode::THP;
658 if (converged && !stoppedOrZeroRateTarget(groupStateHelper) && isThp) {
659 auto rates = well_state.
well(this->index_of_well_).surface_rates;
660 this->adaptRatesForVFP(rates);
661 this->updateIPRImplicit(simulator, groupStateHelper, well_state);
665 this->operability_status_.use_vfpexplicit =
true;
668 const Scalar reltol = 1e-3;
669 const Scalar cur_bhp = ws.bhp;
670 if (bhp_stable.has_value() && cur_bhp - bhp_stable.value() > cur_bhp*reltol){
671 const auto msg = fmt::format(
"Well {} converged to an unstable solution, re-solving", this->name());
672 deferred_logger.debug(msg);
674 simulator, dt, bhp_stable.value(), groupStateHelper, well_state
677 ws.thp = this->getTHPConstraint(summary_state);
678 converged = this->iterateWellEqWithSwitching(
679 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
688 this->operability_status_.use_vfpexplicit =
true;
690 auto bhp_target = estimateOperableBhp(
691 simulator, dt, groupStateHelper, summary_state, well_state
693 if (!bhp_target.has_value()) {
696 converged = solveWellWithZeroRate(simulator, dt, groupStateHelper, well_state);
698 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
699 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
703 const Scalar bhp = std::max(bhp_target.value(),
704 static_cast<Scalar>(prod_controls.bhp_limit));
706 simulator, dt, bhp, groupStateHelper, well_state
708 ws.thp = this->getTHPConstraint(summary_state);
709 const auto msg = fmt::format(
"Well {} did not converge, re-solving with explicit fractions for VFP caculations.", this->name());
710 deferred_logger.debug(msg);
711 converged = this->iterateWellEqWithSwitching(simulator, dt,
722 this->operability_status_.can_obtain_bhp_with_thp_limit = !this->wellIsStopped();
723 this->operability_status_.obey_thp_limit_under_bhp_limit = !this->wellIsStopped();
727 template<
typename TypeTag>
728 std::optional<typename WellInterface<TypeTag>::Scalar>
733 const SummaryState& summary_state,
736 if (!this->wellHasTHPConstraints(summary_state)) {
738 const bool converged = solveWellWithBhp(
739 simulator, dt, bhp_limit, groupStateHelper, well_state
741 if (!converged || this->wellIsStopped()) {
752 const bool converged = solveWellWithBhp(
753 simulator, dt, bhp_min, groupStateHelper, well_state
755 if (!converged || this->wellIsStopped()) {
758 this->updateIPRImplicit(simulator, groupStateHelper, well_state);
759 auto rates = well_state.
well(this->index_of_well_).surface_rates;
760 this->adaptRatesForVFP(rates);
764 template<
typename TypeTag>
781 auto group_guard = groupStateHelper_copy.
pushGroupState(group_state);
783 auto inj_controls = Well::InjectionControls(0);
784 auto prod_controls = Well::ProductionControls(0);
785 auto& ws = well_state.
well(this->index_of_well_);
786 auto cmode_inj = ws.injection_cmode;
787 auto cmode_prod = ws.production_cmode;
788 if (this->isInjector()) {
789 inj_controls.addControl(Well::InjectorCMode::BHP);
790 inj_controls.bhp_limit = bhp;
791 inj_controls.cmode = Well::InjectorCMode::BHP;
792 ws.injection_cmode = Well::InjectorCMode::BHP;
794 prod_controls.addControl(Well::ProducerCMode::BHP);
795 prod_controls.bhp_limit = bhp;
796 prod_controls.cmode = Well::ProducerCMode::BHP;
797 ws.production_cmode = Well::ProducerCMode::BHP;
802 const bool converged = this->iterateWellEqWithSwitching(
803 simulator, dt, inj_controls, prod_controls, groupStateHelper_copy,
809 ws.injection_cmode = cmode_inj;
810 ws.production_cmode = cmode_prod;
814 template<
typename TypeTag>
825 const auto well_status_orig = this->wellStatus_;
828 auto inj_controls = Well::InjectionControls(0);
829 auto prod_controls = Well::ProductionControls(0);
834 const bool converged = this->iterateWellEqWithSwitching(
835 simulator, dt, inj_controls, prod_controls,
842 this->wellStatus_ = well_status_orig;
846 template<
typename TypeTag>
856 const double dt = simulator.timeStepSize();
858 const auto& summary_state = simulator.vanguard().summaryState();
859 auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
860 auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
861 this->onlyKeepBHPandTHPcontrols(summary_state, well_state, inj_controls, prod_controls);
863 bool converged =
false;
866 if (!this->param_.local_well_solver_control_switching_){
867 converged = this->iterateWellEqWithControl(
868 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state
871 if (this->param_.use_implicit_ipr_ && this->well_ecl_.isProducer() && (well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
872 converged = this->solveWellWithOperabilityCheck(
873 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state
876 converged = this->iterateWellEqWithSwitching(
877 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
885 }
catch (NumericalProblem& e ) {
886 const std::string msg =
"Inner well iterations failed for well " + this->name() +
" Treat the well as unconverged. ";
887 deferred_logger.warning(
"INNER_ITERATION_FAILED", msg);
892 deferred_logger.debug(
"WellTest: Well equation for well " + this->name() +
" converged");
895 const int max_iter = this->param_.max_welleq_iter_;
896 deferred_logger.debug(
"WellTest: Well equation for well " + this->name() +
" failed converging in "
902 template<
typename TypeTag>
911 if (!this->isOperableAndSolvable() && !this->wellIsStopped())
916 const double dt = simulator.timeStepSize();
917 bool converged = iterateWellEquations(simulator, dt, groupStateHelper, well_state);
927 auto& ws = well_state.
well(this->indexOfWell());
928 bool thp_control =
false;
929 if (this->well_ecl_.isInjector()) {
930 thp_control = ws.injection_cmode == Well::InjectorCMode::THP;
932 ws.injection_cmode = Well::InjectorCMode::BHP;
933 if (this->well_control_log_.empty()) {
934 this->well_control_log_.push_back(WellInjectorCMode2String(Well::InjectorCMode::THP));
938 thp_control = ws.production_cmode == Well::ProducerCMode::THP;
940 ws.production_cmode = Well::ProducerCMode::BHP;
941 if (this->well_control_log_.empty()) {
942 this->well_control_log_.push_back(WellProducerCMode2String(Well::ProducerCMode::THP));
947 const std::string msg = std::string(
"The newly opened well ") + this->name()
948 + std::string(
" with THP control did not converge during inner iterations, we try again with bhp control");
949 deferred_logger.debug(msg);
950 converged = this->iterateWellEquations(simulator, dt, groupStateHelper, well_state);
955 const int max_iter = this->param_.max_welleq_iter_;
956 deferred_logger.debug(
"Compute initial well solution for well " + this->name() +
". Failed to converge in "
958 well_state = well_state0;
964 template <
typename TypeTag>
973 prepareWellBeforeAssembling(simulator, dt, groupStateHelper, well_state);
974 assembleWellEqWithoutIteration(simulator, groupStateHelper, dt, well_state,
980 template <
typename TypeTag>
987 const bool solving_with_zero_rate)
990 const auto& summary_state = simulator.vanguard().summaryState();
991 const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
992 const auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
995 assembleWellEqWithoutIteration(simulator, groupStateHelper, dt, inj_controls, prod_controls, well_state, solving_with_zero_rate);
1000 template<
typename TypeTag>
1007 std::vector<Scalar> scaled_well_fractions(FluidSystem::numPhases, 0.0);
1008 this->getScaledWellFractions(scaled_well_fractions, deferred_logger);
1010 this->Base::updateGroupTargetFallbackFlag(well_state, scaled_well_fractions, deferred_logger);
1015 template<
typename TypeTag>
1025 const bool old_well_operable = this->operability_status_.isOperableAndSolvable();
1027 if (this->param_.check_well_operability_iter_)
1028 checkWellOperability(simulator, well_state, groupStateHelper);
1031 const auto& iterCtx = simulator.problem().iterationContext();
1032 if (iterCtx.shouldRunInnerWellIterations(this->param_.max_niter_inner_well_iter_)) {
1033 const auto& ws = well_state.
well(this->indexOfWell());
1034 const bool nonzero_rate_original =
1035 std::any_of(ws.surface_rates.begin(),
1036 ws.surface_rates.begin() + well_state.
numPhases(),
1037 [](
Scalar rate) { return rate != Scalar(0.0); });
1039 this->operability_status_.solvable =
true;
1040 if (number_of_well_reopenings_ >= this->param_.max_well_status_switch_) {
1042 if (number_of_well_reopenings_ == this->param_.max_well_status_switch_) {
1043 const std::string msg = fmt::format(
"well {} is oscillating between open and stop. \n"
1044 "We don't allow for more than {} re-openings "
1045 "and the well is therefore kept stopped.",
1046 this->name(), number_of_well_reopenings_);
1047 deferred_logger.debug(msg);
1048 changed_to_stopped_this_step_ = old_well_operable;
1050 changed_to_stopped_this_step_ =
false;
1053 bool converged_zero_rate = this->solveWellWithZeroRate(
1054 simulator, dt, groupStateHelper, well_state
1056 if (this->param_.shut_unsolvable_wells_ && !converged_zero_rate ) {
1057 this->operability_status_.solvable =
false;
1059 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
1060 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
1063 number_of_well_reopenings_++;
1066 bool converged = this->iterateWellEquations(
1067 simulator, dt, groupStateHelper, well_state
1071 const bool zero_target = this->wellUnderZeroRateTarget(groupStateHelper);
1072 if (this->wellIsStopped() && !zero_target && nonzero_rate_original) {
1076 this->operability_status_.resetOperability();
1078 deferred_logger.debug(
" " + this->name() +
" is re-opened after being stopped during local solve");
1079 number_of_well_reopenings_++;
1083 if (this->param_.shut_unsolvable_wells_) {
1084 this->operability_status_.solvable =
false;
1088 if (this->operability_status_.has_negative_potentials) {
1089 auto well_state_copy = well_state;
1090 std::vector<Scalar> potentials;
1092 computeWellPotentials(simulator, well_state_copy, groupStateHelper, potentials);
1093 }
catch (
const std::exception& e) {
1094 const std::string msg = fmt::format(
"well {}: computeWellPotentials() failed "
1095 "during attempt to recompute potentials for well: ",
1096 this->name(), e.what());
1097 deferred_logger.info(msg);
1098 this->operability_status_.has_negative_potentials =
true;
1100 auto& ws = well_state.
well(this->indexOfWell());
1102 for (
int p = 0; p < np; ++p) {
1103 ws.well_potentials[p] = std::max(
Scalar{0.0}, potentials[p]);
1106 this->changed_to_open_this_step_ =
false;
1107 changed_to_stopped_this_step_ =
false;
1109 const bool well_operable = this->operability_status_.isOperableAndSolvable();
1110 if (!well_operable) {
1113 this->solveWellWithZeroRate(
1114 simulator, dt, groupStateHelper, well_state
1116 }
catch (
const std::exception& e) {
1117 const std::string msg = fmt::format(
"well {}: solveWellWithZeroRate() failed "
1118 "during attempt to solve with zero rate for well: ",
1119 this->name(), e.what());
1120 deferred_logger.info(msg);
1122 auto& ws = well_state.
well(this->indexOfWell());
1124 for (
int p = 0; p < np; ++p) {
1125 ws.surface_rates[p] =
Scalar{0.0};
1128 if (old_well_operable) {
1129 const std::string ctx = iterCtx.inLocalSolve() ?
" (NLDD domain solve)" :
"";
1130 deferred_logger.debug(
" well " + this->name() +
" gets STOPPED during iteration" + ctx);
1131 changed_to_stopped_this_step_ =
true;
1133 }
else if (well_state.
isOpen(this->name())) {
1135 if (!old_well_operable) {
1136 const std::string ctx = iterCtx.inLocalSolve() ?
" (NLDD domain solve)" :
"";
1137 deferred_logger.debug(
" well " + this->name() +
" gets REVIVED during iteration" + ctx);
1138 this->changed_to_open_this_step_ =
true;
1143 template<
typename TypeTag>
1147 if(!this->operability_status_.solvable)
1150 for (
int perfIdx = 0; perfIdx < this->number_of_local_perforations_; ++perfIdx) {
1151 const auto cellIdx = this->cells()[perfIdx];
1152 const auto it = cellRates_.find(cellIdx);
1153 RateVector rates = (it == cellRates_.end()) ? 0.0 : it->second;
1154 for (
auto i=0*RateVector::dimension; i < RateVector::dimension; ++i)
1156 rates[i] += connectionRates_[perfIdx][i];
1158 cellRates_.insert_or_assign(cellIdx, rates);
1162 template<
typename TypeTag>
1166 for (
int perfIdx = 0; perfIdx < this->number_of_local_perforations_; ++perfIdx) {
1167 if (this->cells()[perfIdx] == cellIdx) {
1168 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
1169 return connectionRates_[perfIdx][activeCompIdx].value();
1173 OPM_THROW(std::invalid_argument,
"The well with name " + this->name()
1181 template<
typename TypeTag>
1190 if (!this->param_.check_well_operability_) {
1194 if (this->wellIsStopped() && !changed_to_stopped_this_step_) {
1198 updateWellOperability(simulator, well_state, groupStateHelper);
1199 if (!this->operability_status_.isOperableAndSolvable()) {
1200 this->operability_status_.use_vfpexplicit =
true;
1201 deferred_logger.debug(
"EXPLICIT_LOOKUP_VFP",
1202 "well not operable, trying with explicit vfp lookup: " + this->name());
1203 updateWellOperability(simulator, well_state, groupStateHelper);
1209 template<
typename TypeTag>
1219 const auto& summary_state = simulator.vanguard().summaryState();
1220 const auto& well_name = this->name();
1221 if (!this->wellHasTHPConstraints(summary_state)) {
1222 const std::string msg = fmt::format(
"GLIFT WTEST: Well {} does not have THP constraints", well_name);
1223 deferred_logger.
info(msg);
1226 const auto& schedule = simulator.vanguard().schedule();
1227 const auto report_step_idx = simulator.episodeIndex();
1228 const auto& glo = schedule.glo(report_step_idx);
1229 if (!glo.has_well(well_name)) {
1230 const std::string msg = fmt::format(
1231 "GLIFT WTEST: Well {} : Gas lift not activated: "
1232 "WLIFTOPT is probably missing. Skipping.", well_name);
1233 deferred_logger.
info(msg);
1236 const auto& gl_well = glo.well(well_name);
1239 std::unique_ptr<GasLiftSingleWell> glift =
1240 initializeGliftWellTest_<GasLiftSingleWell>(simulator,
1245 auto [wtest_alq, success] = glift->wellTestALQ();
1247 const auto& unit_system = schedule.getUnits();
1249 well_state.
well(well_name).alq_state.set(wtest_alq);
1251 "GLIFT WTEST: Well {} : Setting ALQ to optimized value = {}",
1252 well_name, unit_system.from_si(UnitSystem::measure::gas_surface_rate, wtest_alq));
1255 if (!gl_well.use_glo()) {
1257 "GLIFT WTEST: Well {} : Gas lift optimization deactivated. Setting ALQ to WLIFTOPT item 3 = {}",
1259 unit_system.from_si(UnitSystem::measure::gas_surface_rate, well_state.
well(well_name).alq_state.get()));
1264 "GLIFT WTEST: Well {} : Gas lift optimization failed, no ALQ set.",
1268 deferred_logger.
info(msg);
1271 template<
typename TypeTag>
1280 if (this->param_.local_well_solver_control_switching_) {
1281 const bool success = updateWellOperabilityFromWellEq(simulator, groupStateHelper);
1283 this->operability_status_.solvable =
false;
1284 deferred_logger.debug(
"Operability check using well equations did not converge for well "
1285 + this->name() +
". Mark the well as unsolvable." );
1289 this->operability_status_.resetOperability();
1291 bool thp_controlled = this->isInjector() ? well_state.
well(this->index_of_well_).injection_cmode == Well::InjectorCMode::THP:
1292 well_state.
well(this->index_of_well_).production_cmode == Well::ProducerCMode::THP;
1293 bool bhp_controlled = this->isInjector() ? well_state.
well(this->index_of_well_).injection_cmode == Well::InjectorCMode::BHP:
1294 well_state.
well(this->index_of_well_).production_cmode == Well::ProducerCMode::BHP;
1298 bool check_thp = thp_controlled || this->operability_status_.thp_limit_violated_but_not_switched;
1299 if (check_thp || bhp_controlled) {
1300 updateIPR(simulator, deferred_logger);
1301 checkOperabilityUnderBHPLimit(well_state, simulator, deferred_logger);
1305 checkOperabilityUnderTHPLimit(simulator, well_state, groupStateHelper);
1309 template<
typename TypeTag>
1317 assert(this->param_.local_well_solver_control_switching_);
1318 this->operability_status_.resetOperability();
1321 const double dt = simulator.timeStepSize();
1325 auto guard = groupStateHelper_copy.
pushWellState(well_state_copy);
1327 bool converged = iterateWellEquations(simulator, dt, groupStateHelper_copy, well_state_copy);
1331 template<
typename TypeTag>
1339 template<
typename TypeTag>
1349 const auto& well = this->well_ecl_;
1350 const int well_index = this->index_of_well_;
1351 auto& ws = well_state.
well(well_index);
1353 const auto& summaryState = simulator.vanguard().summaryState();
1354 const auto& schedule = simulator.vanguard().schedule();
1358 ws.primaryvar.resize(0);
1360 if (this->wellIsStopped()) {
1361 for (
int p = 0; p<np; ++p) {
1362 ws.surface_rates[p] = 0;
1368 if (this->isInjector() )
1370 const auto& controls = well.injectionControls(summaryState);
1372 InjectorType injectorType = controls.injector_type;
1374 switch (injectorType) {
1375 case InjectorType::WATER:
1377 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1380 case InjectorType::OIL:
1382 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1385 case InjectorType::GAS:
1387 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1391 OPM_DEFLOG_THROW(std::runtime_error,
"Expected WATER, OIL or GAS as type for injectors " + this->name(), deferred_logger );
1394 const auto current = ws.injection_cmode;
1397 case Well::InjectorCMode::RATE:
1399 ws.surface_rates[phasePos] = (1.0 - this->rsRvInj()) * controls.surface_rate;
1400 if(this->rsRvInj() > 0) {
1401 if (injectorType == InjectorType::OIL && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1402 const int gas_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1403 ws.surface_rates[gas_pos] = controls.surface_rate * this->rsRvInj();
1404 }
else if (injectorType == InjectorType::GAS && FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1405 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1406 ws.surface_rates[oil_pos] = controls.surface_rate * this->rsRvInj();
1408 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 );
1414 case Well::InjectorCMode::RESV:
1416 std::vector<Scalar> convert_coeff(this->number_of_phases_, 1.0);
1417 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, convert_coeff);
1418 const Scalar coeff = convert_coeff[phasePos];
1419 ws.surface_rates[phasePos] = controls.reservoir_rate/coeff;
1423 case Well::InjectorCMode::THP:
1425 auto rates = ws.surface_rates;
1430 this->getRefDensity(),
1433 ws.thp = this->getTHPConstraint(summaryState);
1438 Scalar total_rate = std::accumulate(rates.begin(), rates.end(), 0.0);
1439 if (total_rate <= 0.0)
1440 ws.surface_rates = ws.well_potentials;
1444 case Well::InjectorCMode::BHP:
1446 ws.bhp = controls.bhp_limit;
1448 for (
int p = 0; p<np; ++p) {
1449 total_rate += ws.surface_rates[p];
1454 if (total_rate <= 0.0)
1455 ws.surface_rates = ws.well_potentials;
1459 case Well::InjectorCMode::GRUP:
1461 assert(well.isAvailableForGroupControl());
1462 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
1463 const Scalar efficiencyFactor = well.getEfficiencyFactor() *
1464 well_state[well.name()].efficiency_scaling_factor;
1465 std::optional<Scalar> target =
1466 this->getGroupInjectionTargetRate(group,
1471 ws.surface_rates[phasePos] = *target;
1474 case Well::InjectorCMode::CMODE_UNDEFINED:
1476 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name(), deferred_logger );
1486 ws.surface_rates[phasePos] = std::max(
Scalar{1.e-7}, ws.surface_rates[phasePos]);
1489 ws.bhp = controls.bhp_limit;
1495 const auto current = ws.production_cmode;
1496 const auto& controls = well.productionControls(summaryState);
1498 case Well::ProducerCMode::ORAT:
1500 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1501 Scalar current_rate = -ws.surface_rates[oil_pos];
1504 if (current_rate > 0.0) {
1505 for (
int p = 0; p<np; ++p) {
1506 ws.surface_rates[p] *= controls.oil_rate/current_rate;
1509 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1510 double control_fraction = fractions[oil_pos];
1511 if (control_fraction != 0.0) {
1512 for (
int p = 0; p<np; ++p) {
1513 ws.surface_rates[p] = - fractions[p] * controls.oil_rate/control_fraction;
1519 case Well::ProducerCMode::WRAT:
1521 const int water_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1522 Scalar current_rate = -ws.surface_rates[water_pos];
1525 if (current_rate > 0.0) {
1526 for (
int p = 0; p<np; ++p) {
1527 ws.surface_rates[p] *= controls.water_rate/current_rate;
1530 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1531 const Scalar control_fraction = fractions[water_pos];
1532 if (control_fraction != 0.0) {
1533 for (
int p = 0; p<np; ++p) {
1534 ws.surface_rates[p] = - fractions[p] * controls.water_rate / control_fraction;
1540 case Well::ProducerCMode::GRAT:
1542 const int gas_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1543 Scalar current_rate = -ws.surface_rates[gas_pos];
1546 if (current_rate > 0.0) {
1547 for (
int p = 0; p<np; ++p) {
1548 ws.surface_rates[p] *= controls.gas_rate/current_rate;
1551 const std::vector<Scalar > fractions = initialWellRateFractions(simulator, well_state);
1552 const Scalar control_fraction = fractions[gas_pos];
1553 if (control_fraction != 0.0) {
1554 for (
int p = 0; p<np; ++p) {
1555 ws.surface_rates[p] = - fractions[p] * controls.gas_rate / control_fraction;
1563 case Well::ProducerCMode::LRAT:
1565 const int water_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1566 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1567 Scalar current_rate = - ws.surface_rates[water_pos]
1568 - ws.surface_rates[oil_pos];
1571 if (current_rate > 0.0) {
1572 for (
int p = 0; p<np; ++p) {
1573 ws.surface_rates[p] *= controls.liquid_rate/current_rate;
1576 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1577 const Scalar control_fraction = fractions[water_pos] + fractions[oil_pos];
1578 if (control_fraction != 0.0) {
1579 for (
int p = 0; p<np; ++p) {
1580 ws.surface_rates[p] = - fractions[p] * controls.liquid_rate / control_fraction;
1586 case Well::ProducerCMode::CRAT:
1589 fmt::format(
"CRAT control not supported, well {}", this->name()),
1592 case Well::ProducerCMode::RESV:
1594 std::vector<Scalar> convert_coeff(this->number_of_phases_, 1.0);
1595 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, ws.surface_rates, convert_coeff);
1596 Scalar total_res_rate = 0.0;
1597 for (
int p = 0; p<np; ++p) {
1598 total_res_rate -= ws.surface_rates[p] * convert_coeff[p];
1600 if (controls.prediction_mode) {
1603 if (total_res_rate > 0.0) {
1604 for (
int p = 0; p<np; ++p) {
1605 ws.surface_rates[p] *= controls.resv_rate/total_res_rate;
1608 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1609 for (
int p = 0; p<np; ++p) {
1610 ws.surface_rates[p] = - fractions[p] * controls.resv_rate / convert_coeff[p];
1614 std::vector<Scalar> hrates(this->number_of_phases_,0.);
1615 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
1616 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1617 hrates[phase_pos] = controls.water_rate;
1619 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1620 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1621 hrates[phase_pos] = controls.oil_rate;
1623 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1624 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1625 hrates[phase_pos] = controls.gas_rate;
1627 std::vector<Scalar> hrates_resv(this->number_of_phases_,0.);
1628 this->rateConverter_.calcReservoirVoidageRates( 0, this->pvtRegionIdx_, hrates, hrates_resv);
1629 Scalar target = std::accumulate(hrates_resv.begin(), hrates_resv.end(), 0.0);
1632 if (total_res_rate > 0.0) {
1633 for (
int p = 0; p<np; ++p) {
1634 ws.surface_rates[p] *= target/total_res_rate;
1637 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1638 for (
int p = 0; p<np; ++p) {
1639 ws.surface_rates[p] = - fractions[p] * target / convert_coeff[p];
1645 case Well::ProducerCMode::BHP:
1647 ws.bhp = controls.bhp_limit;
1649 for (
int p = 0; p<np; ++p) {
1650 total_rate -= ws.surface_rates[p];
1655 if (total_rate <= 0.0){
1656 for (
int p = 0; p<np; ++p) {
1657 ws.surface_rates[p] = -ws.well_potentials[p];
1662 case Well::ProducerCMode::THP:
1664 const bool update_success = updateWellStateWithTHPTargetProd(simulator, well_state, groupStateHelper);
1666 if (!update_success) {
1670 auto rates = ws.surface_rates;
1671 this->adaptRatesForVFP(rates);
1673 well_state, rates, well, summaryState, this->getRefDensity(), deferred_logger);
1675 ws.thp = this->getTHPConstraint(summaryState);
1679 const Scalar total_rate = -std::accumulate(rates.begin(), rates.end(), 0.0);
1680 if (total_rate <= 0.0) {
1681 for (
int p = 0; p < this->number_of_phases_; ++p) {
1682 ws.surface_rates[p] = -ws.well_potentials[p];
1688 case Well::ProducerCMode::GRUP:
1690 assert(well.isAvailableForGroupControl());
1691 this->updateGroupTargetFallbackFlag(well_state, deferred_logger);
1692 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
1693 const Scalar efficiencyFactor = well.getEfficiencyFactor() *
1694 well_state[well.name()].efficiency_scaling_factor;
1695 Scalar scale = this->getGroupProductionTargetRate(group,
1701 for (
int p = 0; p<np; ++p) {
1702 ws.surface_rates[p] *= scale;
1704 ws.trivial_group_target =
false;
1708 ws.trivial_group_target =
true;
1712 case Well::ProducerCMode::CMODE_UNDEFINED:
1715 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name() , deferred_logger);
1721 ws.bhp = controls.bhp_limit;
1726 template<
typename TypeTag>
1732 const auto& well_state = groupStateHelper.
wellState();
1734 const bool isGroupControlled = this->wellUnderGroupControl(well_state.well(this->index_of_well_));
1735 if (!isGroupControlled) {
1737 const auto& summaryState = groupStateHelper.
summaryState();
1738 return this->wellUnderZeroRateTargetIndividual(summaryState, well_state);
1740 return this->wellUnderZeroGroupRateTarget(groupStateHelper, isGroupControlled);
1744 template <
typename TypeTag>
1747 const std::optional<bool> group_control)
const
1749 const auto& well_state = groupStateHelper.
wellState();
1751 const bool isGroupControlled = group_control.value_or(this->wellUnderGroupControl(well_state.well(this->index_of_well_)));
1752 if (isGroupControlled) {
1753 return this->zeroGroupRateTarget(groupStateHelper);
1758 template<
typename TypeTag>
1765 return this->wellIsStopped()
1766 || this->wellUnderZeroRateTarget(groupStateHelper);
1769 template<
typename TypeTag>
1770 std::vector<typename WellInterface<TypeTag>::Scalar>
1776 const int np = this->number_of_phases_;
1777 std::vector<Scalar> scaling_factor(np);
1778 const auto& ws = well_state.
well(this->index_of_well_);
1780 Scalar total_potentials = 0.0;
1781 for (
int p = 0; p<np; ++p) {
1782 total_potentials += ws.well_potentials[p];
1784 if (total_potentials > 0) {
1785 for (
int p = 0; p<np; ++p) {
1786 scaling_factor[p] = ws.well_potentials[p] / total_potentials;
1788 return scaling_factor;
1793 const int nperf = this->number_of_local_perforations_;
1794 for (
int perf = 0; perf < nperf; ++perf) {
1795 total_tw += this->well_index_[perf];
1797 total_tw = this->parallelWellInfo().communication().sum(total_tw);
1799 for (
int perf = 0; perf < nperf; ++perf) {
1800 const int cell_idx = this->well_cells_[perf];
1801 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
1802 const auto& fs = intQuants.fluidState();
1803 const Scalar well_tw_fraction = this->well_index_[perf] / total_tw;
1804 Scalar total_mobility = 0.0;
1805 for (
int p = 0; p < np; ++p) {
1806 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
1807 total_mobility += fs.invB(canonical_phase_idx).value() * intQuants.mobility(canonical_phase_idx).value();
1809 for (
int p = 0; p < np; ++p) {
1810 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
1811 scaling_factor[p] += well_tw_fraction * fs.invB(canonical_phase_idx).value() * intQuants.mobility(canonical_phase_idx).value() / total_mobility;
1814 return scaling_factor;
1819 template <
typename TypeTag>
1826 assert(this->isProducer());
1830 auto& ws = well_state.
well(this->index_of_well_);
1831 int nonzero_rate_index = -1;
1832 const Scalar floating_point_error_epsilon = 1e-14;
1833 for (
int p = 0; p < this->number_of_phases_; ++p) {
1834 if (std::abs(ws.surface_rates[p]) > floating_point_error_epsilon) {
1835 if (nonzero_rate_index == -1) {
1836 nonzero_rate_index = p;
1845 std::vector<Scalar> well_q_s(this->number_of_phases_, 0.0);
1846 bool rates_evaluated_at_1bar =
false;
1848 const auto& summary_state = simulator.vanguard().summaryState();
1849 const auto& prod_controls = this->well_ecl_.productionControls(summary_state);
1850 const double bhp_limit = std::max(prod_controls.bhp_limit, 1.0 * unit::barsa);
1851 this->computeWellRatesWithBhp(simulator, bhp_limit, well_q_s, deferred_logger);
1853 rates_evaluated_at_1bar = (bhp_limit < 1.1 * unit::barsa);
1855 if (std::ranges::any_of(well_q_s, [](
Scalar q) {
return q > 0.0; })) {
1857 if (!rates_evaluated_at_1bar) {
1858 this->computeWellRatesWithBhp(simulator, 1.0 * unit::barsa, well_q_s, deferred_logger);
1859 rates_evaluated_at_1bar =
true;
1862 for (
auto& q : well_q_s) {
1863 q = std::min(q,
Scalar{0.0});
1868 if (nonzero_rate_index == -1) {
1872 const Scalar factor = rates_evaluated_at_1bar ? 0.5 : 1.0;
1873 for (
int p = 0; p < this->number_of_phases_; ++p) {
1874 ws.surface_rates[p] = factor * well_q_s[p];
1883 const Scalar initial_nonzero_rate = ws.surface_rates[nonzero_rate_index];
1884 const Scalar computed_rate = well_q_s[nonzero_rate_index];
1885 if (std::abs(initial_nonzero_rate) < std::abs(computed_rate)) {
1887 const Scalar factor = initial_nonzero_rate / computed_rate;
1888 assert(factor < 1.0);
1889 for (
int p = 0; p < this->number_of_phases_; ++p) {
1891 if (p != nonzero_rate_index) {
1892 ws.surface_rates[p] = factor * well_q_s[p];
1901 for (
int p = 0; p < this->number_of_phases_; ++p) {
1902 ws.surface_rates[p] = well_q_s[p];
1906 template <
typename TypeTag>
1907 template<
class Value>
1910 getTw(std::vector<Value>& Tw,
1913 const Value& trans_mult,
1916 OPM_TIMEFUNCTION_LOCAL(Subsystem::Wells);
1919 if (
static_cast<std::size_t
>(perf) >= this->well_cells_.size()) {
1920 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!");
1923 if constexpr (! Indices::gasEnabled) {
1927 const auto& wdfac = this->well_ecl_.getWDFAC();
1929 if (! wdfac.useDFactor() || (this->well_index_[perf] == 0.0)) {
1933 const Scalar d = this->computeConnectionDFactor(perf, intQuants, ws);
1940 const auto& connection = this->well_ecl_.getConnections()[ws.
perf_data.ecl_index[perf]];
1941 const Scalar Kh = connection.Kh();
1942 const Scalar scaling = std::numbers::pi * Kh * connection.wpimult();
1943 const unsigned gas_comp_idx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
1946 const Scalar cell_pressure = getValue(intQuants.fluidState().pressure(FluidSystem::gasPhaseIdx));
1947 const Scalar drawdown = cell_pressure - connection_pressure;
1948 const Scalar invB = getValue(intQuants.fluidState().invB(FluidSystem::gasPhaseIdx));
1949 const Scalar mob_g = getValue(intQuants.mobility(FluidSystem::gasPhaseIdx)) * invB;
1951 const Scalar b = 2 * scaling / getValue(Tw[gas_comp_idx]);
1952 const Scalar c = -2 * scaling * mob_g * drawdown;
1954 Scalar consistent_Q = -1.0e20;
1956 const Scalar r2n = b*b + 4*a*c;
1958 const Scalar rn = std::sqrt(r2n);
1959 const Scalar xn1 = (b-rn)*0.5/a;
1963 const Scalar xn2 = (b+rn)*0.5/a;
1964 if (xn2 <= 0 && xn2 > consistent_Q) {
1970 const Scalar r2p = b*b - 4*a*c;
1972 const Scalar rp = std::sqrt(r2p);
1973 const Scalar xp1 = (rp-b)*0.5/a;
1974 if (xp1 > 0 && xp1 < consistent_Q) {
1977 const Scalar xp2 = -(rp+b)*0.5/a;
1978 if (xp2 > 0 && xp2 < consistent_Q) {
1982 Tw[gas_comp_idx] = 1.0 / (1.0 / (trans_mult * this->well_index_[perf]) + (consistent_Q/2 * d / scaling));
1985 template <
typename TypeTag>
1991 if (! this->well_ecl_.getWDFAC().useDFactor()) {
1995 auto& d_factor = ws.
perf_data.connection_d_factor;
1997 for (
int perf = 0; perf < this->number_of_local_perforations_; ++perf) {
1998 const int cell_idx = this->well_cells_[perf];
1999 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2001 d_factor[perf] = this->computeConnectionDFactor(perf, intQuants, ws);
2005 template <
typename TypeTag>
2012 auto rhoGS = [regIdx = this->pvtRegionIdx()]() {
2013 return FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, regIdx);
2017 auto gas_visc = [connection_pressure = ws.
perf_data.pressure[perf],
2019 regIdx = this->pvtRegionIdx(), &intQuants]()
2021 const auto rv = getValue(intQuants.fluidState().Rv());
2023 const auto& gasPvt = FluidSystem::gasPvt();
2028 const Scalar rv_sat = gasPvt.saturatedOilVaporizationFactor
2029 (regIdx, temperature, connection_pressure);
2031 if (! (rv < rv_sat)) {
2032 return gasPvt.saturatedViscosity(regIdx, temperature,
2033 connection_pressure);
2036 return gasPvt.viscosity(regIdx, temperature, connection_pressure,
2037 rv, getValue(intQuants.fluidState().Rvw()));
2040 const auto& connection = this->well_ecl_.getConnections()
2043 return this->well_ecl_.getWDFAC().getDFactor(rhoGS, gas_visc, connection);
2047 template <
typename TypeTag>
2053 auto connCF = [&connIx = std::as_const(ws.
perf_data.ecl_index),
2054 &conns = this->well_ecl_.getConnections()]
2057 return conns[connIx[perf]].CF();
2060 auto obtain = [](
const Eval& value)
2062 return getValue(value);
2065 auto& tmult = ws.
perf_data.connection_compaction_tmult;
2066 auto& ctf = ws.
perf_data.connection_transmissibility_factor;
2068 for (
int perf = 0; perf < this->number_of_local_perforations_; ++perf) {
2069 const int cell_idx = this->well_cells_[perf];
2071 getTransMult(trans_mult, simulator, cell_idx, obtain);
2072 tmult[perf] = trans_mult;
2074 ctf[perf] = connCF(perf) * tmult[perf];
2079 template<
typename TypeTag>
2083 if constexpr (Indices::oilEnabled) {
2084 return fs.pressure(FluidSystem::oilPhaseIdx);
2085 }
else if constexpr (Indices::gasEnabled) {
2086 return fs.pressure(FluidSystem::gasPhaseIdx);
2088 return fs.pressure(FluidSystem::waterPhaseIdx);
2092 template <
typename TypeTag>
2093 template<
class Value,
class Callback>
2099 Callback& extendEval)
const
2101 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2102 trans_mult = simulator.problem().template wellTransMultiplier<Value>(intQuants, cell_idx, extendEval);
2105 template <
typename TypeTag>
2106 template<
class Value,
class Callback>
2110 const int local_perf_index,
2111 std::vector<Value>& mob,
2112 Callback& extendEval,
2115 auto relpermArray = []()
2117 if constexpr (std::is_same_v<Value, Scalar>) {
2118 return std::array<Scalar,3>{};
2120 return std::array<Eval,3>{};
2123 if (
static_cast<std::size_t
>(local_perf_index) >= this->well_cells_.size()) {
2124 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!");
2126 const int cell_idx = this->well_cells_[local_perf_index];
2127 assert (
int(mob.size()) == this->num_conservation_quantities_);
2128 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2129 const auto& materialLawManager = simulator.problem().materialLawManager();
2133 const int satid = this->saturation_table_number_[local_perf_index] - 1;
2134 const int satid_elem = materialLawManager->satnumRegionIdx(cell_idx);
2135 if (satid == satid_elem) {
2136 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2137 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2141 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2142 mob[activeCompIdx] = extendEval(intQuants.mobility(phaseIdx));
2144 if constexpr (has_solvent) {
2145 mob[Indices::contiSolventEqIdx] = extendEval(intQuants.solventMobility());
2148 const auto& paramsCell = materialLawManager->connectionMaterialLawParams(satid, cell_idx);
2149 auto relativePerms = relpermArray();
2150 MaterialLaw::relativePermeabilities(relativePerms, paramsCell, intQuants.fluidState());
2153 materialLawManager->connectionMaterialLawParams(satid_elem, cell_idx);
2156 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2157 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2161 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2162 mob[activeCompIdx] = extendEval(relativePerms[phaseIdx] / intQuants.fluidState().viscosity(phaseIdx));
2165 if constexpr (has_solvent) {
2166 const auto Fsolgas = intQuants.solventSaturation() / (intQuants.solventSaturation() + intQuants.fluidState().saturation(FluidSystem::gasPhaseIdx));
2168 if (Fsolgas > SolventModule::cutOff) {
2169 const unsigned activeGasCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(FluidSystem::gasPhaseIdx));
2170 const auto& ssfnKrg = SolventModule::ssfnKrg(satid);
2171 const auto& ssfnKrs = SolventModule::ssfnKrs(satid);
2172 mob[activeGasCompIdx] *= extendEval(ssfnKrg.eval(1-Fsolgas,
true));
2173 mob[Indices::contiSolventEqIdx] = extendEval(ssfnKrs.eval(Fsolgas,
true) * relativePerms[activeGasCompIdx] / intQuants.solventViscosity());
2178 if (this->isInjector() && !this->inj_fc_multiplier_.empty()) {
2179 const auto perf_ecl_index = this->perforationData()[local_perf_index].ecl_index;
2180 const auto& connections = this->well_ecl_.getConnections();
2181 const auto& connection = connections[perf_ecl_index];
2182 if (connection.filterCakeActive()) {
2183 std::ranges::transform(mob, mob.begin(),
2184 [mult = this->inj_fc_multiplier_[local_perf_index]]
2186 { return val * mult; });
2192 template<
typename TypeTag>
2201 const auto& summary_state = simulator.vanguard().summaryState();
2203 auto bhp_at_thp_limit = computeBhpAtThpLimitProdWithAlq(
2204 simulator, groupStateHelper, summary_state, this->getALQ(well_state),
false);
2205 if (bhp_at_thp_limit) {
2206 std::vector<Scalar> rates(this->number_of_phases_, 0.0);
2207 if (thp_update_iterations) {
2208 computeWellRatesWithBhpIterations(simulator, *bhp_at_thp_limit,
2209 groupStateHelper, rates);
2211 computeWellRatesWithBhp(simulator, *bhp_at_thp_limit,
2212 rates, deferred_logger);
2214 auto& ws = well_state.
well(this->name());
2215 ws.surface_rates = rates;
2216 ws.bhp = *bhp_at_thp_limit;
2217 ws.thp = this->getTHPConstraint(summary_state);
2224 template<
typename TypeTag>
2225 std::optional<typename WellInterface<TypeTag>::Scalar>
2230 const SummaryState& summary_state,
2235 const auto& groupStateHelper = simulator.problem().wellModel().groupStateHelper();
2237 auto well_guard = groupStateHelper_copy.
pushWellState(well_state_copy);
2238 const double dt = simulator.timeStepSize();
2239 const bool converged = this->solveWellWithBhp(
2240 simulator, dt, bhp, groupStateHelper_copy, well_state_copy
2244 auto rates = well_state_copy.
well(this->index_of_well_).surface_rates;
2246 for (std::size_t p = 0; p < rates.size(); ++p) {
2247 zero_rates &= rates[p] == 0.0;
2251 if (zero_rates || !converged) {
2252 return this->computeBhpAtThpLimitProdWithAlq(simulator, groupStateHelper_copy, summary_state, alq_value,
false);
2254 this->updateIPRImplicit(simulator, groupStateHelper_copy, well_state_copy);
2255 this->adaptRatesForVFP(rates);
2259 template <
typename TypeTag>
2264 const std::vector<Scalar>& mobility,
2267 const int np = this->number_of_phases_;
2268 for (
int p = 0; p < np; ++p) {
2271 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
2272 const auto connMob =
2273 mobility[FluidSystem::activePhaseToActiveCompIdx(p)] * fs.invB(canonical_phase_idx).value();
2275 connPI[p] = connPICalc(connMob);
2278 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) &&
2279 FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx))
2281 const auto io = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
2282 const auto ig = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
2284 const auto vapoil = connPI[ig] * fs.Rv().value();
2285 const auto disgas = connPI[io] * fs.Rs().value();
2287 connPI[io] += vapoil;
2288 connPI[ig] += disgas;
2293 template <
typename TypeTag>
2297 const Phase preferred_phase,
2299 const std::vector<Scalar>& mobility,
2304 if (preferred_phase == Phase::GAS) {
2305 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
2307 else if (preferred_phase == Phase::OIL) {
2308 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
2310 else if (preferred_phase == Phase::WATER) {
2311 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
2315 fmt::format(
"Unsupported Injector Type ({}) "
2316 "for well {} during connection I.I. calculation",
2317 static_cast<int>(preferred_phase), this->name()),
2321 const auto mt = std::accumulate(mobility.begin(), mobility.end(), 0.0);
2322 const int canonicalPhaseIdx = FluidSystem::activeToCanonicalPhaseIdx(phase_pos);
2323 connII[phase_pos] = connIICalc(mt * fs.invB(canonicalPhaseIdx).value());
2326 template<
typename TypeTag>
2327 template<
class GasLiftSingleWell>
2328 std::unique_ptr<GasLiftSingleWell>
2337 auto& comm = simulator.vanguard().grid().comm();
2338 ecl_well_map.try_emplace(this->name(), &(this->wellEcl()), this->indexOfWell());
2339 const auto& iterCtx = simulator.problem().iterationContext();
2342 simulator.vanguard().schedule(),
2343 simulator.vanguard().summaryState(),
2344 simulator.episodeIndex(),
2354 std::set<int> sync_groups;
2355 const auto& summary_state = simulator.vanguard().summaryState();
2356 return std::make_unique<GasLiftSingleWell>(*
this,
#define OPM_DEFLOG_THROW(Exception, message, deferred_logger)
Definition: DeferredLoggingErrorHelpers.hpp:45
Contains the high level supplements required to extend the black oil model by solvents.
Definition: blackoilsolventmodules.hh:69
Definition: DeferredLogger.hpp:57
void info(const std::string &tag, const std::string &message)
Definition: GasLiftGroupInfo.hpp:47
Definition: GroupStateHelper.hpp:56
GroupState< Scalar > & groupState() const
Definition: GroupStateHelper.hpp:301
const SummaryState & summaryState() const
Definition: GroupStateHelper.hpp:418
const WellState< Scalar, IndexTraits > & wellState() const
Definition: GroupStateHelper.hpp:499
DeferredLogger & deferredLogger() const
Get the deferred logger.
Definition: GroupStateHelper.hpp:233
WellStateGuard pushWellState(WellState< Scalar, IndexTraits > &well_state)
Definition: GroupStateHelper.hpp:357
GroupStateGuard pushGroupState(GroupState< Scalar > &group_state)
Definition: GroupStateHelper.hpp:334
Definition: GroupState.hpp:41
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:198
Definition: SingleWellState.hpp:44
Scalar temperature
Definition: SingleWellState.hpp:108
PerfData< Scalar > perf_data
Definition: SingleWellState.hpp:156
Class for computing BHP limits.
Definition: WellBhpThpCalculator.hpp:41
Scalar calculateMinimumBhpFromThp(const WellState< Scalar, IndexTraits > &well_state, const Well &well, const SummaryState &summaryState, const Scalar rho) const
Scalar mostStrictBhpFromBhpLimits(const SummaryState &summaryState) const
Obtain the most strict BHP from BHP limits.
bool isStableSolution(const WellState< Scalar, IndexTraits > &well_state, const Well &well, const std::vector< Scalar > &rates, const SummaryState &summaryState) const
EvalWell calculateBhpFromThp(const WellState< Scalar, IndexTraits > &well_state, const std::vector< EvalWell > &rates, const Well &well, const SummaryState &summaryState, const Scalar rho, DeferredLogger &deferred_logger) const
std::optional< Scalar > estimateStableBhp(const WellState< Scalar, IndexTraits > &well_state, const Well &well, const std::vector< Scalar > &rates, const Scalar rho, const SummaryState &summaryState) const
Well well_ecl_
Definition: WellInterfaceGeneric.hpp:309
int number_of_local_perforations_
Definition: WellInterfaceGeneric.hpp:345
FluidSystem::Scalar wsolvent_
Definition: WellInterfaceGeneric.hpp:385
Definition: WellInterfaceIndices.hpp:34
bool stoppedOrZeroRateTarget(const GroupStateHelperType &groupStateHelper) const
Definition: WellInterface_impl.hpp:1761
bool updateWellOperabilityFromWellEq(const Simulator &simulator, const GroupStateHelperType &groupStateHelper)
Definition: WellInterface_impl.hpp:1312
void checkWellOperability(const Simulator &simulator, const WellStateType &well_state, const GroupStateHelperType &groupStateHelper)
Definition: WellInterface_impl.hpp:1184
void updateWellOperability(const Simulator &simulator, const WellStateType &well_state, const GroupStateHelperType &groupStateHelper)
Definition: WellInterface_impl.hpp:1274
bool solveWellWithOperabilityCheck(const Simulator &simulator, const double dt, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:610
Scalar woxygen() const
Definition: WellInterface_impl.hpp:166
IndividualOrGroup
Definition: WellInterface.hpp:249
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: WellInterface.hpp:82
void assembleWellEqWithoutIteration(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, const double dt, WellStateType &well_state, const bool solving_with_zero_rate)
Definition: WellInterface_impl.hpp:983
Scalar computeConnectionDFactor(const int perf, const IntensiveQuantities &intQuants, const SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:2008
typename WellInterfaceFluidSystem< FluidSystem >::RateConverterType RateConverterType
Definition: WellInterface.hpp:105
Scalar wfoam() const
Definition: WellInterface_impl.hpp:128
bool updateWellControlAndStatusLocalIteration(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, const Scalar WQTotal, WellStateType &well_state, const bool fixed_control, const bool fixed_status, const bool solving_with_zero_rate)
Definition: WellInterface_impl.hpp:287
void getTransMult(Value &trans_mult, const Simulator &simulator, const int cell_idx, Callback &extendEval) const
Definition: WellInterface_impl.hpp:2096
std::vector< RateVector > connectionRates_
Definition: WellInterface.hpp:372
bool solveWellForTesting(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:849
void computeConnLevelProdInd(const FluidState &fs, const std::function< Scalar(const Scalar)> &connPICalc, const std::vector< Scalar > &mobility, Scalar *connPI) const
Definition: WellInterface_impl.hpp:2262
void gliftBeginTimeStepWellTestUpdateALQ(const Simulator &simulator, WellStateType &well_state, const GroupState< Scalar > &group_state, GLiftEclWells &ecl_well_map, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:1212
Scalar volumetricSurfaceRateForConnection(int cellIdx, int phaseIdx) const
Definition: WellInterface_impl.hpp:1164
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:96
std::optional< Scalar > computeBhpAtThpLimitProdWithAlqUsingIPR(const Simulator &simulator, const WellStateType &well_state, Scalar bhp, const SummaryState &summary_state, const Scalar alq_value)
Definition: WellInterface_impl.hpp:2227
void getTw(std::vector< Value > &wi, const int perf, const IntensiveQuantities &intQuants, const Value &trans_mult, const SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:1910
void getMobility(const Simulator &simulator, const int local_perf_index, std::vector< Value > &mob, Callback &extendEval, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:2109
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:1772
void solveWellEquation(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:905
void updateConnectionDFactor(const Simulator &simulator, SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:1988
Eval getPerfCellPressure(const FluidState &fs) const
Definition: WellInterface_impl.hpp:2081
void initializeProducerWellState(const Simulator &simulator, WellStateType &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1822
virtual void updateWellStateWithTarget(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state) const
Definition: WellInterface_impl.hpp:1342
void addCellRates(std::map< int, RateVector > &cellRates_) const
Definition: WellInterface_impl.hpp:1145
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
bool wellUnderZeroRateTarget(const GroupStateHelperType &groupStateHelper) const
Definition: WellInterface_impl.hpp:1729
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: WellInterface.hpp:90
void updateConnectionTransmissibilityFactor(const Simulator &simulator, SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:2050
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:2296
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:2330
std::optional< Scalar > estimateOperableBhp(const Simulator &ebos_simulator, const double dt, const GroupStateHelperType &groupStateHelper, const SummaryState &summary_state, WellStateType &well_state)
Definition: WellInterface_impl.hpp:730
Scalar wsalt() const
Definition: WellInterface_impl.hpp:142
bool solveWellWithZeroRate(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:817
bool wellUnderZeroGroupRateTarget(const GroupStateHelperType &groupStateHelper, const std::optional< bool > group_control=std::nullopt) const
Definition: WellInterface_impl.hpp:1746
bool solveWellWithBhp(const Simulator &simulator, const double dt, const Scalar bhp, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:767
void prepareWellBeforeAssembling(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:1018
void wellTesting(const Simulator &simulator, const double simulation_time, const GroupStateHelperType &groupStateHelper, WellStateType &well_state, WellTestState &welltest_state, GLiftEclWells &ecl_well_map, std::map< std::string, double > &open_times)
Definition: WellInterface_impl.hpp:406
typename Base::Eval Eval
Definition: WellInterface.hpp:96
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:59
bool updateWellStateWithTHPTargetProd(const Simulator &simulator, WellStateType &well_state, const GroupStateHelperType &groupStateHelper) const
Definition: WellInterface_impl.hpp:2195
bool iterateWellEquations(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:532
Scalar wpolymer() const
Definition: WellInterface_impl.hpp:112
GetPropType< TypeTag, Properties::Indices > Indices
Definition: WellInterface.hpp:86
bool updateWellControl(const Simulator &simulator, const IndividualOrGroup iog, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:190
Scalar wurea() const
Definition: WellInterface_impl.hpp:178
void updateGroupTargetFallbackFlag(WellStateType &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1003
void assembleWellEq(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:967
BlackOilFluidState< Eval, FluidSystem, energyModuleType !=EnergyModules::NoTemperature, energyModuleType==EnergyModules::FullyImplicitThermal, Indices::compositionSwitchIdx >=0, has_watVapor, has_brine, has_saltPrecip, has_disgas_in_water, has_solvent, Indices::numPhases > FluidState
Definition: WellInterface.hpp:140
Scalar wmicrobes() const
Definition: WellInterface_impl.hpp:154
virtual void scaleSegmentRatesAndPressure(WellStateType &well_state) const
Definition: WellInterface_impl.hpp:1334
static constexpr bool has_zFraction
Definition: WellInterface.hpp:114
Definition: WellState.hpp:66
constexpr int numPhases() const
The number of phases present.
Definition: WellState.hpp:265
const SingleWellState< Scalar, IndexTraits > & well(std::size_t well_index) const
Definition: WellState.hpp:306
bool isOpen(const std::string &name) const
Definition: WellState.hpp:213
@ 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:156
Definition: blackoilbioeffectsmodules.hh:45
std::string to_string(const ConvergenceReport::ReservoirFailure::Type t)
Static data associated with a well perforation.
Definition: PerforationData.hpp:30