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>
44#include <dune/common/version.hh>
52#include <fmt/format.h>
58 template<
typename TypeTag>
65 const int pvtRegionIdx,
66 const int num_conservation_quantities,
68 const int index_of_well,
76 num_conservation_quantities,
84 if (well.isInjector()) {
85 auto injectorType = this->
well_ecl_.injectorType();
86 if (injectorType == InjectorType::GAS) {
94 template<
typename TypeTag>
97 init(
const std::vector<Scalar>& ,
99 const std::vector<Scalar>& B_avg,
100 const bool changed_to_open_this_step)
102 this->gravity_ = gravity_arg;
104 this->changed_to_open_this_step_ = changed_to_open_this_step;
110 template<
typename TypeTag>
115 if constexpr (has_polymer) {
116 return this->wpolymer_();
126 template<
typename TypeTag>
131 if constexpr (has_foam) {
132 return this->wfoam_();
140 template<
typename TypeTag>
145 if constexpr (has_brine) {
146 return this->wsalt_();
152 template<
typename TypeTag>
157 if constexpr (has_micp) {
158 return this->wmicrobes_();
164 template<
typename TypeTag>
169 if constexpr (has_micp) {
170 return this->woxygen_();
176 template<
typename TypeTag>
181 if constexpr (has_micp) {
182 return this->wurea_();
188 template<
typename TypeTag>
198 if (stoppedOrZeroRateTarget(groupStateHelper)) {
202 const auto& summaryState = simulator.vanguard().summaryState();
203 const auto& schedule = simulator.vanguard().schedule();
204 const auto& well = this->well_ecl_;
205 auto& ws = well_state.
well(this->index_of_well_);
207 bool is_grup =
false;
208 if (well.isInjector()) {
209 from = WellInjectorCMode2String(ws.injection_cmode);
210 is_grup = ws.injection_cmode == Well::InjectorCMode::GRUP;
212 from = WellProducerCMode2String(ws.production_cmode);
213 is_grup = ws.production_cmode == Well::ProducerCMode::GRUP;
216 const int episodeIdx = simulator.episodeIndex();
217 const auto& iterCtx = simulator.problem().iterationContext();
218 const int nupcol = schedule[episodeIdx].nupcol();
219 const bool oscillating =
220 std::ranges::count(this->well_control_log_, from) >= this->param_.max_number_of_well_switches_;
221 if (oscillating && !is_grup) {
224 std::ranges::count(this->well_control_log_, from) == this->param_.max_number_of_well_switches_;
226 const auto msg = fmt::format(
" The control mode for well {} is oscillating. \n"
227 "We don't allow for more than {} switches after NUPCOL iterations. (NUPCOL = {}) \n"
228 "The control is kept at {}.",
229 this->name(), this->param_.max_number_of_well_switches_, nupcol, from);
230 deferred_logger.info(msg);
232 this->well_control_log_.push_back(from);
236 bool changed =
false;
237 if (iog == IndividualOrGroup::Individual) {
238 changed = this->checkIndividualConstraints(ws, summaryState, deferred_logger);
239 }
else if (iog == IndividualOrGroup::Group) {
240 changed = this->checkGroupConstraints(
241 groupStateHelper, schedule, summaryState,
true, well_state
244 assert(iog == IndividualOrGroup::Both);
245 changed = this->checkConstraints(groupStateHelper, schedule, summaryState, well_state);
251 if (well.isInjector()) {
252 to = WellInjectorCMode2String(ws.injection_cmode);
254 to = WellProducerCMode2String(ws.production_cmode);
256 std::ostringstream ss;
257 ss <<
" Switching control mode for well " << this->name()
260 if (iterCtx.inLocalSolve()) {
261 ss <<
" (NLDD domain solve)";
264 ss <<
" on rank " << cc.rank();
266 deferred_logger.debug(ss.str());
273 if (!iterCtx.inLocalSolve()) {
274 if (!iterCtx.withinNupcol(nupcol) || this->well_control_log_.empty()) {
275 this->well_control_log_.push_back(from);
278 updateWellStateWithTarget(simulator, groupStateHelper, well_state);
279 updatePrimaryVariables(groupStateHelper);
285 template<
typename TypeTag>
290 const Well::InjectionControls& inj_controls,
291 const Well::ProductionControls& prod_controls,
294 const bool fixed_control,
295 const bool fixed_status,
296 const bool solving_with_zero_rate)
300 const auto& summary_state = simulator.vanguard().summaryState();
301 const auto& schedule = simulator.vanguard().schedule();
302 auto& ws = well_state.
well(this->index_of_well_);
304 if (this->isInjector()) {
305 from = WellInjectorCMode2String(ws.injection_cmode);
307 from = WellProducerCMode2String(ws.production_cmode);
309 const bool oscillating =
310 std::ranges::count(this->well_control_log_, from) >= this->param_.max_number_of_well_switches_;
312 if (oscillating || this->wellUnderZeroRateTarget(groupStateHelper) || !(well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
316 const Scalar sgn = this->isInjector() ? 1.0 : -1.0;
317 if (!this->wellIsStopped()){
318 if (wqTotal*sgn <= 0.0 && !fixed_status){
322 bool changed =
false;
323 if (!fixed_control) {
326 if (solving_with_zero_rate) {
328 "Well {}: solving_with_zero_rate should not be true when fixed_control is false",
329 this->name()), deferred_logger);
335 const bool hasGroupControl = this->isInjector() ? inj_controls.hasControl(Well::InjectorCMode::GRUP) :
336 prod_controls.hasControl(Well::ProducerCMode::GRUP);
337 bool isGroupControl = ws.production_cmode == Well::ProducerCMode::GRUP || ws.injection_cmode == Well::InjectorCMode::GRUP;
338 if (! (isGroupControl && !this->param_.check_group_constraints_inner_well_iterations_)) {
339 changed = this->checkIndividualConstraints(ws, summary_state, deferred_logger, inj_controls, prod_controls);
341 if (hasGroupControl && this->param_.check_group_constraints_inner_well_iterations_) {
342 changed = changed || this->checkGroupConstraints(
343 groupStateHelper, schedule, summary_state,
false, well_state
348 const bool thp_controlled = this->isInjector() ? ws.injection_cmode == Well::InjectorCMode::THP :
349 ws.production_cmode == Well::ProducerCMode::THP;
351 ws.thp = this->getTHPConstraint(summary_state);
354 updateWellStateWithTarget(simulator, groupStateHelper, well_state);
356 updatePrimaryVariables(groupStateHelper);
361 }
else if (!fixed_status){
363 const Scalar bhp = well_state.
well(this->index_of_well_).bhp;
364 Scalar prod_limit = prod_controls.bhp_limit;
365 Scalar inj_limit = inj_controls.bhp_limit;
366 const bool has_thp = this->wellHasTHPConstraints(summary_state);
368 std::vector<Scalar> rates(this->num_conservation_quantities_);
369 if (this->isInjector()){
371 calculateBhpFromThp(well_state, rates,
374 this->getRefDensity(),
376 inj_limit = std::min(bhp_thp,
static_cast<Scalar>(inj_controls.bhp_limit));
381 calculateMinimumBhpFromThp(well_state,
384 this->getRefDensity());
385 prod_limit = std::max(bhp_min,
static_cast<Scalar>(prod_controls.bhp_limit));
388 const Scalar bhp_diff = (this->isInjector())? inj_limit - bhp: bhp - prod_limit;
391 well_state.
well(this->index_of_well_).bhp = (this->isInjector())? inj_limit : prod_limit;
393 well_state.
well(this->index_of_well_).thp = this->getTHPConstraint(summary_state);
404 template<
typename TypeTag>
408 const double simulation_time,
411 WellTestState& well_test_state,
413 std::map<std::string, double>& open_times)
417 const auto& group_state = groupStateHelper.
groupState();
421 const auto& unit_system = simulator.vanguard().eclState().getUnits();
422 const auto start_time = simulator.vanguard().schedule().getStartTime();
424 fmt::format(
"at time {:.2f} {} (date = {})",
425 unit_system.from_si(UnitSystem::measure::time, simulation_time),
426 unit_system.name(UnitSystem::measure::time),
429 deferred_logger.info(fmt::format(
" well {} is being tested {}", this->name(), when));
436 auto guard = groupStateHelper_copy.
pushWellState(well_state_copy);
437 auto& ws = well_state_copy.
well(this->indexOfWell());
439 const auto& summary_state = simulator.vanguard().summaryState();
440 const bool has_thp_limit = this->wellHasTHPConstraints(summary_state);
441 if (this->isProducer()) {
442 ws.production_cmode = has_thp_limit ? Well::ProducerCMode::THP : Well::ProducerCMode::BHP;
444 ws.injection_cmode = has_thp_limit ? Well::InjectorCMode::THP : Well::InjectorCMode::BHP;
449 scaleSegmentRatesAndPressure(well_state_copy);
450 calculateExplicitQuantities(simulator, groupStateHelper_copy);
451 updatePrimaryVariables(groupStateHelper_copy);
453 if (this->isProducer()) {
454 const auto& schedule = simulator.vanguard().schedule();
455 const auto report_step = simulator.episodeIndex();
456 const auto& glo = schedule.glo(report_step);
458 gliftBeginTimeStepWellTestUpdateALQ(simulator,
466 WellTestState welltest_state_temp;
468 bool testWell =
true;
473 const std::size_t original_number_closed_completions = welltest_state_temp.num_closed_completions();
474 bool converged = solveWellForTesting(simulator, groupStateHelper_copy, well_state_copy);
476 const auto msg = fmt::format(
"WTEST: Well {} is not solvable (physical)", this->name());
477 deferred_logger.debug(msg);
482 updateWellOperability(simulator, well_state_copy, groupStateHelper_copy);
483 if ( !this->isOperableAndSolvable() ) {
484 const auto msg = fmt::format(
"WTEST: Well {} is not operable (physical)", this->name());
485 deferred_logger.debug(msg);
488 std::vector<Scalar> potentials;
490 computeWellPotentials(simulator, well_state_copy, groupStateHelper_copy, potentials);
491 }
catch (
const std::exception& e) {
492 const std::string msg = fmt::format(
"well {}: computeWellPotentials() "
493 "failed during testing for re-opening: ",
494 this->name(), e.what());
495 deferred_logger.info(msg);
498 const int np = well_state_copy.
numPhases();
499 for (
int p = 0; p < np; ++p) {
500 ws.well_potentials[p] = std::max(
Scalar{0.0}, potentials[p]);
502 const bool under_zero_target = this->wellUnderZeroGroupRateTarget(groupStateHelper_copy);
503 this->updateWellTestState(well_state_copy.
well(this->indexOfWell()),
509 simulator.vanguard().eclState().getUnits(),
510 simulator.vanguard().schedule().getStartTime(),
512 this->closeCompletions(welltest_state_temp);
518 if ( welltest_state_temp.num_closed_wells() > 0 ||
519 (original_number_closed_completions == welltest_state_temp.num_closed_completions()) ) {
525 if (!welltest_state_temp.well_is_closed(this->name())) {
526 well_test_state.open_well(this->name());
528 deferred_logger.info(
529 fmt::format(
"well {} is re-opened {}", this->name(), when));
532 for (
const auto& completion : this->well_ecl_.getCompletions()) {
533 if (!welltest_state_temp.completion_is_closed(this->name(), completion.first))
534 well_test_state.open_completion(this->name(), completion.first);
536 well_state = well_state_copy;
537 open_times.try_emplace(this->name(), well_test_state.lastTestTime(this->name()));
544 template<
typename TypeTag>
555 const auto& summary_state = simulator.vanguard().summaryState();
556 const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
557 const auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
558 const auto& ws = well_state.
well(this->indexOfWell());
559 const auto pmode_orig = ws.production_cmode;
560 const auto imode_orig = ws.injection_cmode;
561 bool converged =
false;
564 if (!this->param_.local_well_solver_control_switching_){
565 converged = this->iterateWellEqWithControl(simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state);
567 if (this->param_.use_implicit_ipr_ && this->well_ecl_.isProducer() && (well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
568 converged = solveWellWithOperabilityCheck(
569 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state
572 converged = this->iterateWellEqWithSwitching(
573 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
579 }
catch (NumericalProblem& e ) {
580 const std::string msg =
"Inner well iterations failed for well " + this->name() +
" Treat the well as unconverged. ";
581 deferred_logger.warning(
"INNER_ITERATION_FAILED", msg);
586 if (ws.production_cmode != pmode_orig || ws.injection_cmode != imode_orig) {
588 if (this->isInjector()) {
589 from = WellInjectorCMode2String(imode_orig);
590 to = WellInjectorCMode2String(ws.injection_cmode);
592 from = WellProducerCMode2String(pmode_orig);
593 to = WellProducerCMode2String(ws.production_cmode);
595 const auto msg = fmt::format(
" Well {} switched from {} to {} during local solve", this->name(), from, to);
596 deferred_logger.debug(msg);
597 const int episodeIdx = simulator.episodeIndex();
598 const auto& iterCtx = simulator.problem().iterationContext();
599 const auto& schedule = simulator.vanguard().schedule();
600 const int nupcol = schedule[episodeIdx].nupcol();
604 if (!iterCtx.withinNupcol(nupcol) || this->well_control_log_.empty()) {
605 this->well_control_log_.push_back(from);
610 if (this->isProducer() && ws.production_cmode == Well::ProducerCMode::GRUP && ws.use_group_target_fallback) {
611 assert(ws.group_target && ws.group_target_fallback);
612 const std::string cmode = Group::ProductionCMode2String(ws.group_target->production_cmode);
613 const std::string cmode_fallback = Group::ProductionCMode2String(ws.group_target_fallback->production_cmode);
614 const auto msg = fmt::format(
" Well {} was solved using group target fallback mode {} as current group mode {} was not feasible.",
615 this->name(), cmode_fallback, cmode);
616 deferred_logger.debug(msg);
622 template<
typename TypeTag>
627 const Well::InjectionControls& inj_controls,
628 const Well::ProductionControls& prod_controls,
635 const auto& summary_state = simulator.vanguard().summaryState();
636 bool converged =
true;
637 auto& ws = well_state.
well(this->index_of_well_);
639 if (this->wellIsStopped()) {
641 const bool use_vfpexplicit = this->operability_status_.use_vfpexplicit;
642 this->operability_status_.use_vfpexplicit =
true;
643 auto bhp_target = estimateOperableBhp(simulator, dt, groupStateHelper, summary_state, well_state);
644 if (!bhp_target.has_value()) {
646 const auto msg = fmt::format(
"estimateOperableBhp: Did not find operable BHP for well {}", this->name());
647 deferred_logger.debug(msg);
650 converged = solveWellWithZeroRate(simulator, dt, groupStateHelper, well_state);
652 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
653 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
657 ws.thp = this->getTHPConstraint(summary_state);
658 const Scalar bhp = std::max(bhp_target.value(),
659 static_cast<Scalar>(prod_controls.bhp_limit));
660 solveWellWithBhp(simulator, dt, bhp, groupStateHelper, well_state);
661 this->operability_status_.use_vfpexplicit = use_vfpexplicit;
665 converged = this->iterateWellEqWithSwitching(
666 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
671 const bool isThp = ws.production_cmode == Well::ProducerCMode::THP;
673 if (converged && !stoppedOrZeroRateTarget(groupStateHelper) && isThp) {
674 auto rates = well_state.
well(this->index_of_well_).surface_rates;
675 this->adaptRatesForVFP(rates);
676 this->updateIPRImplicit(simulator, groupStateHelper, well_state);
680 this->operability_status_.use_vfpexplicit =
true;
683 const Scalar reltol = 1e-3;
684 const Scalar cur_bhp = ws.bhp;
685 if (bhp_stable.has_value() && cur_bhp - bhp_stable.value() > cur_bhp*reltol){
686 const auto msg = fmt::format(
"Well {} converged to an unstable solution, re-solving", this->name());
687 deferred_logger.debug(msg);
689 simulator, dt, bhp_stable.value(), groupStateHelper, well_state
692 ws.thp = this->getTHPConstraint(summary_state);
693 converged = this->iterateWellEqWithSwitching(
694 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
703 this->operability_status_.use_vfpexplicit =
true;
705 auto bhp_target = estimateOperableBhp(
706 simulator, dt, groupStateHelper, summary_state, well_state
708 if (!bhp_target.has_value()) {
711 converged = solveWellWithZeroRate(simulator, dt, groupStateHelper, well_state);
713 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
714 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
718 const Scalar bhp = std::max(bhp_target.value(),
719 static_cast<Scalar>(prod_controls.bhp_limit));
721 simulator, dt, bhp, groupStateHelper, well_state
723 ws.thp = this->getTHPConstraint(summary_state);
724 const auto msg = fmt::format(
"Well {} did not converge, re-solving with explicit fractions for VFP caculations.", this->name());
725 deferred_logger.debug(msg);
726 converged = this->iterateWellEqWithSwitching(simulator, dt,
737 this->operability_status_.can_obtain_bhp_with_thp_limit = !this->wellIsStopped();
738 this->operability_status_.obey_thp_limit_under_bhp_limit = !this->wellIsStopped();
742 template<
typename TypeTag>
743 std::optional<typename WellInterface<TypeTag>::Scalar>
748 const SummaryState& summary_state,
751 if (!this->wellHasTHPConstraints(summary_state)) {
753 const bool converged = solveWellWithBhp(
754 simulator, dt, bhp_limit, groupStateHelper, well_state
756 if (!converged || this->wellIsStopped()) {
767 const bool converged = solveWellWithBhp(
768 simulator, dt, bhp_min, groupStateHelper, well_state
770 if (!converged || this->wellIsStopped()) {
773 this->updateIPRImplicit(simulator, groupStateHelper, well_state);
774 auto rates = well_state.
well(this->index_of_well_).surface_rates;
775 this->adaptRatesForVFP(rates);
779 template<
typename TypeTag>
796 auto group_guard = groupStateHelper_copy.
pushGroupState(group_state);
798 auto inj_controls = Well::InjectionControls(0);
799 auto prod_controls = Well::ProductionControls(0);
800 auto& ws = well_state.
well(this->index_of_well_);
801 auto cmode_inj = ws.injection_cmode;
802 auto cmode_prod = ws.production_cmode;
803 if (this->isInjector()) {
804 inj_controls.addControl(Well::InjectorCMode::BHP);
805 inj_controls.bhp_limit = bhp;
806 inj_controls.cmode = Well::InjectorCMode::BHP;
807 ws.injection_cmode = Well::InjectorCMode::BHP;
809 prod_controls.addControl(Well::ProducerCMode::BHP);
810 prod_controls.bhp_limit = bhp;
811 prod_controls.cmode = Well::ProducerCMode::BHP;
812 ws.production_cmode = Well::ProducerCMode::BHP;
817 const bool converged = this->iterateWellEqWithSwitching(
818 simulator, dt, inj_controls, prod_controls, groupStateHelper_copy,
824 ws.injection_cmode = cmode_inj;
825 ws.production_cmode = cmode_prod;
829 template<
typename TypeTag>
840 const auto well_status_orig = this->wellStatus_;
843 auto inj_controls = Well::InjectionControls(0);
844 auto prod_controls = Well::ProductionControls(0);
849 const bool converged = this->iterateWellEqWithSwitching(
850 simulator, dt, inj_controls, prod_controls,
857 this->wellStatus_ = well_status_orig;
861 template<
typename TypeTag>
871 const double dt = simulator.timeStepSize();
873 const auto& summary_state = simulator.vanguard().summaryState();
874 auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
875 auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
876 this->onlyKeepBHPandTHPcontrols(summary_state, well_state, inj_controls, prod_controls);
878 bool converged =
false;
881 if (!this->param_.local_well_solver_control_switching_){
882 converged = this->iterateWellEqWithControl(
883 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state
886 if (this->param_.use_implicit_ipr_ && this->well_ecl_.isProducer() && (well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
887 converged = this->solveWellWithOperabilityCheck(
888 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state
891 converged = this->iterateWellEqWithSwitching(
892 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
900 }
catch (NumericalProblem& e ) {
901 const std::string msg =
"Inner well iterations failed for well " + this->name() +
" Treat the well as unconverged. ";
902 deferred_logger.warning(
"INNER_ITERATION_FAILED", msg);
907 deferred_logger.debug(
"WellTest: Well equation for well " + this->name() +
" converged");
910 const int max_iter = this->param_.max_welleq_iter_;
911 deferred_logger.debug(
"WellTest: Well equation for well " + this->name() +
" failed converging in "
917 template<
typename TypeTag>
926 if (!this->isOperableAndSolvable() && !this->wellIsStopped())
931 const double dt = simulator.timeStepSize();
932 bool converged = iterateWellEquations(simulator, dt, groupStateHelper, well_state);
942 auto& ws = well_state.
well(this->indexOfWell());
943 bool thp_control =
false;
944 if (this->well_ecl_.isInjector()) {
945 thp_control = ws.injection_cmode == Well::InjectorCMode::THP;
947 ws.injection_cmode = Well::InjectorCMode::BHP;
948 if (this->well_control_log_.empty()) {
949 this->well_control_log_.push_back(WellInjectorCMode2String(Well::InjectorCMode::THP));
953 thp_control = ws.production_cmode == Well::ProducerCMode::THP;
955 ws.production_cmode = Well::ProducerCMode::BHP;
956 if (this->well_control_log_.empty()) {
957 this->well_control_log_.push_back(WellProducerCMode2String(Well::ProducerCMode::THP));
962 const std::string msg = std::string(
"The newly opened well ") + this->name()
963 + std::string(
" with THP control did not converge during inner iterations, we try again with bhp control");
964 deferred_logger.debug(msg);
965 converged = this->iterateWellEquations(simulator, dt, groupStateHelper, well_state);
970 const int max_iter = this->param_.max_welleq_iter_;
971 deferred_logger.debug(
"Compute initial well solution for well " + this->name() +
". Failed to converge in "
973 well_state = well_state0;
979 template <
typename TypeTag>
988 prepareWellBeforeAssembling(simulator, dt, groupStateHelper, well_state);
989 assembleWellEqWithoutIteration(simulator, groupStateHelper, dt, well_state,
995 template <
typename TypeTag>
1002 const bool solving_with_zero_rate)
1005 const auto& summary_state = simulator.vanguard().summaryState();
1006 const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
1007 const auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
1010 assembleWellEqWithoutIteration(simulator, groupStateHelper, dt, inj_controls, prod_controls, well_state, solving_with_zero_rate);
1015 template<
typename TypeTag>
1022 std::vector<Scalar> scaled_well_fractions(FluidSystem::numPhases, 0.0);
1023 this->getScaledWellFractions(scaled_well_fractions, deferred_logger);
1025 this->Base::updateGroupTargetFallbackFlag(well_state, scaled_well_fractions, deferred_logger);
1030 template<
typename TypeTag>
1040 const bool old_well_operable = this->operability_status_.isOperableAndSolvable();
1042 if (this->param_.check_well_operability_iter_)
1043 checkWellOperability(simulator, well_state, groupStateHelper);
1046 const auto& iterCtx = simulator.problem().iterationContext();
1047 if (iterCtx.shouldRunInnerWellIterations(this->param_.max_niter_inner_well_iter_)) {
1048 const auto& ws = well_state.
well(this->indexOfWell());
1049 const bool nonzero_rate_original =
1050 std::any_of(ws.surface_rates.begin(),
1051 ws.surface_rates.begin() + well_state.
numPhases(),
1052 [](
Scalar rate) { return rate != Scalar(0.0); });
1054 this->operability_status_.solvable =
true;
1055 if (number_of_well_reopenings_ >= this->param_.max_well_status_switch_) {
1057 if (number_of_well_reopenings_ == this->param_.max_well_status_switch_) {
1058 const std::string msg = fmt::format(
"well {} is oscillating between open and stop. \n"
1059 "We don't allow for more than {} re-openings "
1060 "and the well is therefore kept stopped.",
1061 this->name(), number_of_well_reopenings_);
1062 deferred_logger.debug(msg);
1063 changed_to_stopped_this_step_ = old_well_operable;
1065 changed_to_stopped_this_step_ =
false;
1068 bool converged_zero_rate = this->solveWellWithZeroRate(
1069 simulator, dt, groupStateHelper, well_state
1071 if (this->param_.shut_unsolvable_wells_ && !converged_zero_rate ) {
1072 this->operability_status_.solvable =
false;
1074 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
1075 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
1078 number_of_well_reopenings_++;
1081 bool converged = this->iterateWellEquations(
1082 simulator, dt, groupStateHelper, well_state
1086 const bool zero_target = this->wellUnderZeroRateTarget(groupStateHelper);
1087 if (this->wellIsStopped() && !zero_target && nonzero_rate_original) {
1091 this->operability_status_.resetOperability();
1093 deferred_logger.debug(
" " + this->name() +
" is re-opened after being stopped during local solve");
1094 number_of_well_reopenings_++;
1098 if (this->param_.shut_unsolvable_wells_) {
1099 this->operability_status_.solvable =
false;
1103 if (this->operability_status_.has_negative_potentials) {
1104 auto well_state_copy = well_state;
1105 std::vector<Scalar> potentials;
1107 computeWellPotentials(simulator, well_state_copy, groupStateHelper, potentials);
1108 }
catch (
const std::exception& e) {
1109 const std::string msg = fmt::format(
"well {}: computeWellPotentials() failed "
1110 "during attempt to recompute potentials for well: ",
1111 this->name(), e.what());
1112 deferred_logger.info(msg);
1113 this->operability_status_.has_negative_potentials =
true;
1115 auto& ws = well_state.
well(this->indexOfWell());
1117 for (
int p = 0; p < np; ++p) {
1118 ws.well_potentials[p] = std::max(
Scalar{0.0}, potentials[p]);
1121 this->changed_to_open_this_step_ =
false;
1122 changed_to_stopped_this_step_ =
false;
1124 const bool well_operable = this->operability_status_.isOperableAndSolvable();
1125 if (!well_operable) {
1128 this->solveWellWithZeroRate(
1129 simulator, dt, groupStateHelper, well_state
1131 }
catch (
const std::exception& e) {
1132 const std::string msg = fmt::format(
"well {}: solveWellWithZeroRate() failed "
1133 "during attempt to solve with zero rate for well: ",
1134 this->name(), e.what());
1135 deferred_logger.info(msg);
1137 auto& ws = well_state.
well(this->indexOfWell());
1139 for (
int p = 0; p < np; ++p) {
1140 ws.surface_rates[p] =
Scalar{0.0};
1143 if (old_well_operable) {
1144 const std::string ctx = iterCtx.inLocalSolve() ?
" (NLDD domain solve)" :
"";
1145 deferred_logger.debug(
" well " + this->name() +
" gets STOPPED during iteration" + ctx);
1146 changed_to_stopped_this_step_ =
true;
1148 }
else if (well_state.
isOpen(this->name())) {
1150 if (!old_well_operable) {
1151 const std::string ctx = iterCtx.inLocalSolve() ?
" (NLDD domain solve)" :
"";
1152 deferred_logger.debug(
" well " + this->name() +
" gets REVIVED during iteration" + ctx);
1153 this->changed_to_open_this_step_ =
true;
1158 template<
typename TypeTag>
1162 if(!this->operability_status_.solvable)
1165 for (
int perfIdx = 0; perfIdx < this->number_of_local_perforations_; ++perfIdx) {
1166 const auto cellIdx = this->cells()[perfIdx];
1167 const auto it = cellRates_.find(cellIdx);
1168 RateVector rates = (it == cellRates_.end()) ? 0.0 : it->second;
1169 for (
auto i=0*RateVector::dimension; i < RateVector::dimension; ++i)
1171 rates[i] += connectionRates_[perfIdx][i];
1173 cellRates_.insert_or_assign(cellIdx, rates);
1177 template<
typename TypeTag>
1181 for (
int perfIdx = 0; perfIdx < this->number_of_local_perforations_; ++perfIdx) {
1182 if (this->cells()[perfIdx] == cellIdx) {
1183 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
1184 return connectionRates_[perfIdx][activeCompIdx].value();
1188 OPM_THROW(std::invalid_argument,
"The well with name " + this->name()
1196 template<
typename TypeTag>
1205 if (!this->param_.check_well_operability_) {
1209 if (this->wellIsStopped() && !changed_to_stopped_this_step_) {
1213 updateWellOperability(simulator, well_state, groupStateHelper);
1214 if (!this->operability_status_.isOperableAndSolvable()) {
1215 this->operability_status_.use_vfpexplicit =
true;
1216 deferred_logger.debug(
"EXPLICIT_LOOKUP_VFP",
1217 "well not operable, trying with explicit vfp lookup: " + this->name());
1218 updateWellOperability(simulator, well_state, groupStateHelper);
1224 template<
typename TypeTag>
1234 const auto& summary_state = simulator.vanguard().summaryState();
1235 const auto& well_name = this->name();
1236 if (!this->wellHasTHPConstraints(summary_state)) {
1237 const std::string msg = fmt::format(
"GLIFT WTEST: Well {} does not have THP constraints", well_name);
1238 deferred_logger.
info(msg);
1241 const auto& schedule = simulator.vanguard().schedule();
1242 const auto report_step_idx = simulator.episodeIndex();
1243 const auto& glo = schedule.glo(report_step_idx);
1244 if (!glo.has_well(well_name)) {
1245 const std::string msg = fmt::format(
1246 "GLIFT WTEST: Well {} : Gas lift not activated: "
1247 "WLIFTOPT is probably missing. Skipping.", well_name);
1248 deferred_logger.
info(msg);
1251 const auto& gl_well = glo.well(well_name);
1254 std::unique_ptr<GasLiftSingleWell> glift =
1255 initializeGliftWellTest_<GasLiftSingleWell>(simulator,
1260 auto [wtest_alq, success] = glift->wellTestALQ();
1262 const auto& unit_system = schedule.getUnits();
1264 well_state.
well(well_name).alq_state.set(wtest_alq);
1266 "GLIFT WTEST: Well {} : Setting ALQ to optimized value = {}",
1267 well_name, unit_system.from_si(UnitSystem::measure::gas_surface_rate, wtest_alq));
1270 if (!gl_well.use_glo()) {
1272 "GLIFT WTEST: Well {} : Gas lift optimization deactivated. Setting ALQ to WLIFTOPT item 3 = {}",
1274 unit_system.from_si(UnitSystem::measure::gas_surface_rate, well_state.
well(well_name).alq_state.get()));
1279 "GLIFT WTEST: Well {} : Gas lift optimization failed, no ALQ set.",
1283 deferred_logger.
info(msg);
1286 template<
typename TypeTag>
1295 if (this->param_.local_well_solver_control_switching_) {
1296 const bool success = updateWellOperabilityFromWellEq(simulator, groupStateHelper);
1298 this->operability_status_.solvable =
false;
1299 deferred_logger.debug(
"Operability check using well equations did not converge for well "
1300 + this->name() +
". Mark the well as unsolvable." );
1304 this->operability_status_.resetOperability();
1306 bool thp_controlled = this->isInjector() ? well_state.
well(this->index_of_well_).injection_cmode == Well::InjectorCMode::THP:
1307 well_state.
well(this->index_of_well_).production_cmode == Well::ProducerCMode::THP;
1308 bool bhp_controlled = this->isInjector() ? well_state.
well(this->index_of_well_).injection_cmode == Well::InjectorCMode::BHP:
1309 well_state.
well(this->index_of_well_).production_cmode == Well::ProducerCMode::BHP;
1313 bool check_thp = thp_controlled || this->operability_status_.thp_limit_violated_but_not_switched;
1314 if (check_thp || bhp_controlled) {
1315 updateIPR(simulator, deferred_logger);
1316 checkOperabilityUnderBHPLimit(well_state, simulator, deferred_logger);
1320 checkOperabilityUnderTHPLimit(simulator, well_state, groupStateHelper);
1324 template<
typename TypeTag>
1332 assert(this->param_.local_well_solver_control_switching_);
1333 this->operability_status_.resetOperability();
1336 const double dt = simulator.timeStepSize();
1340 auto guard = groupStateHelper_copy.
pushWellState(well_state_copy);
1342 bool converged = iterateWellEquations(simulator, dt, groupStateHelper_copy, well_state_copy);
1346 template<
typename TypeTag>
1354 template<
typename TypeTag>
1364 const auto& well = this->well_ecl_;
1365 const int well_index = this->index_of_well_;
1366 auto& ws = well_state.
well(well_index);
1368 const auto& summaryState = simulator.vanguard().summaryState();
1369 const auto& schedule = simulator.vanguard().schedule();
1373 ws.primaryvar.resize(0);
1375 if (this->wellIsStopped()) {
1376 for (
int p = 0; p<np; ++p) {
1377 ws.surface_rates[p] = 0;
1383 if (this->isInjector() )
1385 const auto& controls = well.injectionControls(summaryState);
1387 InjectorType injectorType = controls.injector_type;
1389 switch (injectorType) {
1390 case InjectorType::WATER:
1392 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1395 case InjectorType::OIL:
1397 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1400 case InjectorType::GAS:
1402 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1406 OPM_DEFLOG_THROW(std::runtime_error,
"Expected WATER, OIL or GAS as type for injectors " + this->name(), deferred_logger );
1409 const auto current = ws.injection_cmode;
1412 case Well::InjectorCMode::RATE:
1414 ws.surface_rates[phasePos] = (1.0 - this->rsRvInj()) * controls.surface_rate;
1415 if(this->rsRvInj() > 0) {
1416 if (injectorType == InjectorType::OIL && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1417 const int gas_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1418 ws.surface_rates[gas_pos] = controls.surface_rate * this->rsRvInj();
1419 }
else if (injectorType == InjectorType::GAS && FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1420 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1421 ws.surface_rates[oil_pos] = controls.surface_rate * this->rsRvInj();
1423 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 );
1429 case Well::InjectorCMode::RESV:
1431 std::vector<Scalar> convert_coeff(this->number_of_phases_, 1.0);
1432 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, convert_coeff);
1433 const Scalar coeff = convert_coeff[phasePos];
1434 ws.surface_rates[phasePos] = controls.reservoir_rate/coeff;
1438 case Well::InjectorCMode::THP:
1440 auto rates = ws.surface_rates;
1445 this->getRefDensity(),
1448 ws.thp = this->getTHPConstraint(summaryState);
1453 Scalar total_rate = std::accumulate(rates.begin(), rates.end(), 0.0);
1454 if (total_rate <= 0.0)
1455 ws.surface_rates = ws.well_potentials;
1459 case Well::InjectorCMode::BHP:
1461 ws.bhp = controls.bhp_limit;
1463 for (
int p = 0; p<np; ++p) {
1464 total_rate += ws.surface_rates[p];
1469 if (total_rate <= 0.0)
1470 ws.surface_rates = ws.well_potentials;
1474 case Well::InjectorCMode::GRUP:
1476 assert(well.isAvailableForGroupControl());
1477 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
1478 const Scalar efficiencyFactor = well.getEfficiencyFactor() *
1479 well_state[well.name()].efficiency_scaling_factor;
1480 std::optional<Scalar> target =
1481 this->getGroupInjectionTargetRate(group,
1486 ws.surface_rates[phasePos] = *target;
1489 case Well::InjectorCMode::CMODE_UNDEFINED:
1491 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name(), deferred_logger );
1501 ws.surface_rates[phasePos] = std::max(
Scalar{1.e-7}, ws.surface_rates[phasePos]);
1504 ws.bhp = controls.bhp_limit;
1510 const auto current = ws.production_cmode;
1511 const auto& controls = well.productionControls(summaryState);
1513 case Well::ProducerCMode::ORAT:
1515 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1516 Scalar current_rate = -ws.surface_rates[oil_pos];
1519 if (current_rate > 0.0) {
1520 for (
int p = 0; p<np; ++p) {
1521 ws.surface_rates[p] *= controls.oil_rate/current_rate;
1524 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1525 double control_fraction = fractions[oil_pos];
1526 if (control_fraction != 0.0) {
1527 for (
int p = 0; p<np; ++p) {
1528 ws.surface_rates[p] = - fractions[p] * controls.oil_rate/control_fraction;
1534 case Well::ProducerCMode::WRAT:
1536 const int water_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1537 Scalar current_rate = -ws.surface_rates[water_pos];
1540 if (current_rate > 0.0) {
1541 for (
int p = 0; p<np; ++p) {
1542 ws.surface_rates[p] *= controls.water_rate/current_rate;
1545 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1546 const Scalar control_fraction = fractions[water_pos];
1547 if (control_fraction != 0.0) {
1548 for (
int p = 0; p<np; ++p) {
1549 ws.surface_rates[p] = - fractions[p] * controls.water_rate / control_fraction;
1555 case Well::ProducerCMode::GRAT:
1557 const int gas_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1558 Scalar current_rate = -ws.surface_rates[gas_pos];
1561 if (current_rate > 0.0) {
1562 for (
int p = 0; p<np; ++p) {
1563 ws.surface_rates[p] *= controls.gas_rate/current_rate;
1566 const std::vector<Scalar > fractions = initialWellRateFractions(simulator, well_state);
1567 const Scalar control_fraction = fractions[gas_pos];
1568 if (control_fraction != 0.0) {
1569 for (
int p = 0; p<np; ++p) {
1570 ws.surface_rates[p] = - fractions[p] * controls.gas_rate / control_fraction;
1578 case Well::ProducerCMode::LRAT:
1580 const int water_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1581 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1582 Scalar current_rate = - ws.surface_rates[water_pos]
1583 - ws.surface_rates[oil_pos];
1586 if (current_rate > 0.0) {
1587 for (
int p = 0; p<np; ++p) {
1588 ws.surface_rates[p] *= controls.liquid_rate/current_rate;
1591 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1592 const Scalar control_fraction = fractions[water_pos] + fractions[oil_pos];
1593 if (control_fraction != 0.0) {
1594 for (
int p = 0; p<np; ++p) {
1595 ws.surface_rates[p] = - fractions[p] * controls.liquid_rate / control_fraction;
1601 case Well::ProducerCMode::CRAT:
1604 fmt::format(
"CRAT control not supported, well {}", this->name()),
1607 case Well::ProducerCMode::RESV:
1609 std::vector<Scalar> convert_coeff(this->number_of_phases_, 1.0);
1610 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, ws.surface_rates, convert_coeff);
1611 Scalar total_res_rate = 0.0;
1612 for (
int p = 0; p<np; ++p) {
1613 total_res_rate -= ws.surface_rates[p] * convert_coeff[p];
1615 if (controls.prediction_mode) {
1618 if (total_res_rate > 0.0) {
1619 for (
int p = 0; p<np; ++p) {
1620 ws.surface_rates[p] *= controls.resv_rate/total_res_rate;
1623 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1624 for (
int p = 0; p<np; ++p) {
1625 ws.surface_rates[p] = - fractions[p] * controls.resv_rate / convert_coeff[p];
1629 std::vector<Scalar> hrates(this->number_of_phases_,0.);
1630 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
1631 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1632 hrates[phase_pos] = controls.water_rate;
1634 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1635 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1636 hrates[phase_pos] = controls.oil_rate;
1638 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1639 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1640 hrates[phase_pos] = controls.gas_rate;
1642 std::vector<Scalar> hrates_resv(this->number_of_phases_,0.);
1643 this->rateConverter_.calcReservoirVoidageRates( 0, this->pvtRegionIdx_, hrates, hrates_resv);
1644 Scalar target = std::accumulate(hrates_resv.begin(), hrates_resv.end(), 0.0);
1647 if (total_res_rate > 0.0) {
1648 for (
int p = 0; p<np; ++p) {
1649 ws.surface_rates[p] *= target/total_res_rate;
1652 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1653 for (
int p = 0; p<np; ++p) {
1654 ws.surface_rates[p] = - fractions[p] * target / convert_coeff[p];
1660 case Well::ProducerCMode::BHP:
1662 ws.bhp = controls.bhp_limit;
1664 for (
int p = 0; p<np; ++p) {
1665 total_rate -= ws.surface_rates[p];
1670 if (total_rate <= 0.0){
1671 for (
int p = 0; p<np; ++p) {
1672 ws.surface_rates[p] = -ws.well_potentials[p];
1677 case Well::ProducerCMode::THP:
1679 const bool update_success = updateWellStateWithTHPTargetProd(simulator, well_state, groupStateHelper);
1681 if (!update_success) {
1685 auto rates = ws.surface_rates;
1686 this->adaptRatesForVFP(rates);
1688 well_state, rates, well, summaryState, this->getRefDensity(), deferred_logger);
1690 ws.thp = this->getTHPConstraint(summaryState);
1694 const Scalar total_rate = -std::accumulate(rates.begin(), rates.end(), 0.0);
1695 if (total_rate <= 0.0) {
1696 for (
int p = 0; p < this->number_of_phases_; ++p) {
1697 ws.surface_rates[p] = -ws.well_potentials[p];
1703 case Well::ProducerCMode::GRUP:
1705 assert(well.isAvailableForGroupControl());
1706 this->updateGroupTargetFallbackFlag(well_state, deferred_logger);
1707 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
1708 const Scalar efficiencyFactor = well.getEfficiencyFactor() *
1709 well_state[well.name()].efficiency_scaling_factor;
1710 Scalar scale = this->getGroupProductionTargetRate(group,
1716 for (
int p = 0; p<np; ++p) {
1717 ws.surface_rates[p] *= scale;
1719 ws.trivial_group_target =
false;
1723 ws.trivial_group_target =
true;
1727 case Well::ProducerCMode::CMODE_UNDEFINED:
1730 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name() , deferred_logger);
1736 ws.bhp = controls.bhp_limit;
1741 template<
typename TypeTag>
1747 const auto& well_state = groupStateHelper.
wellState();
1749 const bool isGroupControlled = this->wellUnderGroupControl(well_state.well(this->index_of_well_));
1750 if (!isGroupControlled) {
1752 const auto& summaryState = groupStateHelper.
summaryState();
1753 return this->wellUnderZeroRateTargetIndividual(summaryState, well_state);
1755 return this->wellUnderZeroGroupRateTarget(groupStateHelper, isGroupControlled);
1759 template <
typename TypeTag>
1762 const std::optional<bool> group_control)
const
1764 const auto& well_state = groupStateHelper.
wellState();
1766 const bool isGroupControlled = group_control.value_or(this->wellUnderGroupControl(well_state.well(this->index_of_well_)));
1767 if (isGroupControlled) {
1768 return this->zeroGroupRateTarget(groupStateHelper);
1773 template<
typename TypeTag>
1780 return this->wellIsStopped()
1781 || this->wellUnderZeroRateTarget(groupStateHelper);
1784 template<
typename TypeTag>
1785 std::vector<typename WellInterface<TypeTag>::Scalar>
1791 const int np = this->number_of_phases_;
1792 std::vector<Scalar> scaling_factor(np);
1793 const auto& ws = well_state.
well(this->index_of_well_);
1795 Scalar total_potentials = 0.0;
1796 for (
int p = 0; p<np; ++p) {
1797 total_potentials += ws.well_potentials[p];
1799 if (total_potentials > 0) {
1800 for (
int p = 0; p<np; ++p) {
1801 scaling_factor[p] = ws.well_potentials[p] / total_potentials;
1803 return scaling_factor;
1808 const int nperf = this->number_of_local_perforations_;
1809 for (
int perf = 0; perf < nperf; ++perf) {
1810 total_tw += this->well_index_[perf];
1812 total_tw = this->parallelWellInfo().communication().sum(total_tw);
1814 for (
int perf = 0; perf < nperf; ++perf) {
1815 const int cell_idx = this->well_cells_[perf];
1816 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
1817 const auto& fs = intQuants.fluidState();
1818 const Scalar well_tw_fraction = this->well_index_[perf] / total_tw;
1819 Scalar total_mobility = 0.0;
1820 for (
int p = 0; p < np; ++p) {
1821 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
1822 total_mobility += fs.invB(canonical_phase_idx).value() * intQuants.mobility(canonical_phase_idx).value();
1824 for (
int p = 0; p < np; ++p) {
1825 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
1826 scaling_factor[p] += well_tw_fraction * fs.invB(canonical_phase_idx).value() * intQuants.mobility(canonical_phase_idx).value() / total_mobility;
1829 return scaling_factor;
1834 template <
typename TypeTag>
1841 assert(this->isProducer());
1845 auto& ws = well_state.
well(this->index_of_well_);
1846 int nonzero_rate_index = -1;
1847 const Scalar floating_point_error_epsilon = 1e-14;
1848 for (
int p = 0; p < this->number_of_phases_; ++p) {
1849 if (std::abs(ws.surface_rates[p]) > floating_point_error_epsilon) {
1850 if (nonzero_rate_index == -1) {
1851 nonzero_rate_index = p;
1860 std::vector<Scalar> well_q_s(this->number_of_phases_, 0.0);
1861 bool rates_evaluated_at_1bar =
false;
1863 const auto& summary_state = simulator.vanguard().summaryState();
1864 const auto& prod_controls = this->well_ecl_.productionControls(summary_state);
1865 const double bhp_limit = std::max(prod_controls.bhp_limit, 1.0 * unit::barsa);
1866 this->computeWellRatesWithBhp(simulator, bhp_limit, well_q_s, deferred_logger);
1868 rates_evaluated_at_1bar = (bhp_limit < 1.1 * unit::barsa);
1870 if (std::ranges::any_of(well_q_s, [](
Scalar q) {
return q > 0.0; })) {
1872 if (!rates_evaluated_at_1bar) {
1873 this->computeWellRatesWithBhp(simulator, 1.0 * unit::barsa, well_q_s, deferred_logger);
1874 rates_evaluated_at_1bar =
true;
1877 for (
auto& q : well_q_s) {
1878 q = std::min(q,
Scalar{0.0});
1883 if (nonzero_rate_index == -1) {
1887 const Scalar factor = rates_evaluated_at_1bar ? 0.5 : 1.0;
1888 for (
int p = 0; p < this->number_of_phases_; ++p) {
1889 ws.surface_rates[p] = factor * well_q_s[p];
1898 const Scalar initial_nonzero_rate = ws.surface_rates[nonzero_rate_index];
1899 const Scalar computed_rate = well_q_s[nonzero_rate_index];
1900 if (std::abs(initial_nonzero_rate) < std::abs(computed_rate)) {
1902 const Scalar factor = initial_nonzero_rate / computed_rate;
1903 assert(factor < 1.0);
1904 for (
int p = 0; p < this->number_of_phases_; ++p) {
1906 if (p != nonzero_rate_index) {
1907 ws.surface_rates[p] = factor * well_q_s[p];
1916 for (
int p = 0; p < this->number_of_phases_; ++p) {
1917 ws.surface_rates[p] = well_q_s[p];
1921 template <
typename TypeTag>
1922 template<
class Value>
1925 getTw(std::vector<Value>& Tw,
1928 const Value& trans_mult,
1931 OPM_TIMEFUNCTION_LOCAL(Subsystem::Wells);
1934 if (
static_cast<std::size_t
>(perf) >= this->well_cells_.size()) {
1935 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!");
1938 if constexpr (! Indices::gasEnabled) {
1942 const auto& wdfac = this->well_ecl_.getWDFAC();
1944 if (! wdfac.useDFactor() || (this->well_index_[perf] == 0.0)) {
1948 const Scalar d = this->computeConnectionDFactor(perf, intQuants, ws);
1955 const auto& connection = this->well_ecl_.getConnections()[ws.
perf_data.ecl_index[perf]];
1956 const Scalar Kh = connection.Kh();
1957 const Scalar scaling = std::numbers::pi * Kh * connection.wpimult();
1958 const unsigned gas_comp_idx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
1961 const Scalar cell_pressure = getValue(intQuants.fluidState().pressure(FluidSystem::gasPhaseIdx));
1962 const Scalar drawdown = cell_pressure - connection_pressure;
1963 const Scalar invB = getValue(intQuants.fluidState().invB(FluidSystem::gasPhaseIdx));
1964 const Scalar mob_g = getValue(intQuants.mobility(FluidSystem::gasPhaseIdx)) * invB;
1966 const Scalar b = 2 * scaling / getValue(Tw[gas_comp_idx]);
1967 const Scalar c = -2 * scaling * mob_g * drawdown;
1969 Scalar consistent_Q = -1.0e20;
1971 const Scalar r2n = b*b + 4*a*c;
1973 const Scalar rn = std::sqrt(r2n);
1974 const Scalar xn1 = (b-rn)*0.5/a;
1978 const Scalar xn2 = (b+rn)*0.5/a;
1979 if (xn2 <= 0 && xn2 > consistent_Q) {
1985 const Scalar r2p = b*b - 4*a*c;
1987 const Scalar rp = std::sqrt(r2p);
1988 const Scalar xp1 = (rp-b)*0.5/a;
1989 if (xp1 > 0 && xp1 < consistent_Q) {
1992 const Scalar xp2 = -(rp+b)*0.5/a;
1993 if (xp2 > 0 && xp2 < consistent_Q) {
1997 Tw[gas_comp_idx] = 1.0 / (1.0 / (trans_mult * this->well_index_[perf]) + (consistent_Q/2 * d / scaling));
2000 template <
typename TypeTag>
2006 if (! this->well_ecl_.getWDFAC().useDFactor()) {
2010 auto& d_factor = ws.
perf_data.connection_d_factor;
2012 for (
int perf = 0; perf < this->number_of_local_perforations_; ++perf) {
2013 const int cell_idx = this->well_cells_[perf];
2014 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2016 d_factor[perf] = this->computeConnectionDFactor(perf, intQuants, ws);
2020 template <
typename TypeTag>
2027 auto rhoGS = [regIdx = this->pvtRegionIdx()]() {
2028 return FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, regIdx);
2032 auto gas_visc = [connection_pressure = ws.
perf_data.pressure[perf],
2034 regIdx = this->pvtRegionIdx(), &intQuants]()
2036 const auto rv = getValue(intQuants.fluidState().Rv());
2038 const auto& gasPvt = FluidSystem::gasPvt();
2043 const Scalar rv_sat = gasPvt.saturatedOilVaporizationFactor
2044 (regIdx, temperature, connection_pressure);
2046 if (! (rv < rv_sat)) {
2047 return gasPvt.saturatedViscosity(regIdx, temperature,
2048 connection_pressure);
2051 return gasPvt.viscosity(regIdx, temperature, connection_pressure,
2052 rv, getValue(intQuants.fluidState().Rvw()));
2055 const auto& connection = this->well_ecl_.getConnections()
2058 return this->well_ecl_.getWDFAC().getDFactor(rhoGS, gas_visc, connection);
2062 template <
typename TypeTag>
2068 auto connCF = [&connIx = std::as_const(ws.
perf_data.ecl_index),
2069 &conns = this->well_ecl_.getConnections()]
2072 return conns[connIx[perf]].CF();
2075 auto obtain = [](
const Eval& value)
2077 return getValue(value);
2080 auto& tmult = ws.
perf_data.connection_compaction_tmult;
2081 auto& ctf = ws.
perf_data.connection_transmissibility_factor;
2083 for (
int perf = 0; perf < this->number_of_local_perforations_; ++perf) {
2084 const int cell_idx = this->well_cells_[perf];
2086 getTransMult(trans_mult, simulator, cell_idx, obtain);
2087 tmult[perf] = trans_mult;
2089 ctf[perf] = connCF(perf) * tmult[perf];
2094 template<
typename TypeTag>
2098 if constexpr (Indices::oilEnabled) {
2099 return fs.pressure(FluidSystem::oilPhaseIdx);
2100 }
else if constexpr (Indices::gasEnabled) {
2101 return fs.pressure(FluidSystem::gasPhaseIdx);
2103 return fs.pressure(FluidSystem::waterPhaseIdx);
2107 template <
typename TypeTag>
2108 template<
class Value,
class Callback>
2114 Callback& extendEval)
const
2116 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2117 trans_mult = simulator.problem().template wellTransMultiplier<Value>(intQuants, cell_idx, extendEval);
2120 template <
typename TypeTag>
2121 template<
class Value,
class Callback>
2125 const int local_perf_index,
2126 std::vector<Value>& mob,
2127 Callback& extendEval,
2130 auto relpermArray = []()
2132 if constexpr (std::is_same_v<Value, Scalar>) {
2133 return std::array<Scalar,3>{};
2135 return std::array<Eval,3>{};
2138 if (
static_cast<std::size_t
>(local_perf_index) >= this->well_cells_.size()) {
2139 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!");
2141 const int cell_idx = this->well_cells_[local_perf_index];
2142 assert (
int(mob.size()) == this->num_conservation_quantities_);
2143 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2144 const auto& materialLawManager = simulator.problem().materialLawManager();
2148 const int satid = this->saturation_table_number_[local_perf_index] - 1;
2149 const int satid_elem = materialLawManager->satnumRegionIdx(cell_idx);
2150 if (satid == satid_elem) {
2151 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2152 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2156 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2157 mob[activeCompIdx] = extendEval(intQuants.mobility(phaseIdx));
2159 if constexpr (has_solvent) {
2160 mob[Indices::contiSolventEqIdx] = extendEval(intQuants.solventMobility());
2163 const auto& paramsCell = materialLawManager->connectionMaterialLawParams(satid, cell_idx);
2164 auto relativePerms = relpermArray();
2165 MaterialLaw::relativePermeabilities(relativePerms, paramsCell, intQuants.fluidState());
2168 materialLawManager->connectionMaterialLawParams(satid_elem, cell_idx);
2171 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2172 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2176 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2177 mob[activeCompIdx] = extendEval(relativePerms[phaseIdx] / intQuants.fluidState().viscosity(phaseIdx));
2180 if constexpr (has_solvent) {
2181 const auto Fsolgas = intQuants.solventSaturation() / (intQuants.solventSaturation() + intQuants.fluidState().saturation(FluidSystem::gasPhaseIdx));
2183 if (Fsolgas > SolventModule::cutOff) {
2184 const unsigned activeGasCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(FluidSystem::gasPhaseIdx));
2185 const auto& ssfnKrg = SolventModule::ssfnKrg(satid);
2186 const auto& ssfnKrs = SolventModule::ssfnKrs(satid);
2187 mob[activeGasCompIdx] *= extendEval(ssfnKrg.eval(1-Fsolgas,
true));
2188 mob[Indices::contiSolventEqIdx] = extendEval(ssfnKrs.eval(Fsolgas,
true) * relativePerms[activeGasCompIdx] / intQuants.solventViscosity());
2193 if (this->isInjector() && !this->inj_fc_multiplier_.empty()) {
2194 const auto perf_ecl_index = this->perforationData()[local_perf_index].ecl_index;
2195 const auto& connections = this->well_ecl_.getConnections();
2196 const auto& connection = connections[perf_ecl_index];
2197 if (connection.filterCakeActive()) {
2198 std::ranges::transform(mob, mob.begin(),
2199 [mult = this->inj_fc_multiplier_[local_perf_index]]
2201 { return val * mult; });
2207 template<
typename TypeTag>
2216 const auto& summary_state = simulator.vanguard().summaryState();
2218 auto bhp_at_thp_limit = computeBhpAtThpLimitProdWithAlq(
2219 simulator, groupStateHelper, summary_state, this->getALQ(well_state),
false);
2220 if (bhp_at_thp_limit) {
2221 std::vector<Scalar> rates(this->number_of_phases_, 0.0);
2222 if (thp_update_iterations) {
2223 computeWellRatesWithBhpIterations(simulator, *bhp_at_thp_limit,
2224 groupStateHelper, rates);
2226 computeWellRatesWithBhp(simulator, *bhp_at_thp_limit,
2227 rates, deferred_logger);
2229 auto& ws = well_state.
well(this->name());
2230 ws.surface_rates = rates;
2231 ws.bhp = *bhp_at_thp_limit;
2232 ws.thp = this->getTHPConstraint(summary_state);
2239 template<
typename TypeTag>
2240 std::optional<typename WellInterface<TypeTag>::Scalar>
2245 const SummaryState& summary_state,
2250 const auto& groupStateHelper = simulator.problem().wellModel().groupStateHelper();
2252 auto well_guard = groupStateHelper_copy.
pushWellState(well_state_copy);
2253 const double dt = simulator.timeStepSize();
2254 const bool converged = this->solveWellWithBhp(
2255 simulator, dt, bhp, groupStateHelper_copy, well_state_copy
2259 auto rates = well_state_copy.
well(this->index_of_well_).surface_rates;
2261 for (std::size_t p = 0; p < rates.size(); ++p) {
2262 zero_rates &= rates[p] == 0.0;
2266 if (zero_rates || !converged) {
2267 return this->computeBhpAtThpLimitProdWithAlq(simulator, groupStateHelper_copy, summary_state, alq_value,
false);
2269 this->updateIPRImplicit(simulator, groupStateHelper_copy, well_state_copy);
2270 this->adaptRatesForVFP(rates);
2274 template <
typename TypeTag>
2279 const std::vector<Scalar>& mobility,
2282 const int np = this->number_of_phases_;
2283 for (
int p = 0; p < np; ++p) {
2286 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
2287 const auto connMob =
2288 mobility[FluidSystem::activePhaseToActiveCompIdx(p)] * fs.invB(canonical_phase_idx).value();
2290 connPI[p] = connPICalc(connMob);
2293 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) &&
2294 FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx))
2296 const auto io = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
2297 const auto ig = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
2299 const auto vapoil = connPI[ig] * fs.Rv().value();
2300 const auto disgas = connPI[io] * fs.Rs().value();
2302 connPI[io] += vapoil;
2303 connPI[ig] += disgas;
2308 template <
typename TypeTag>
2312 const Phase preferred_phase,
2314 const std::vector<Scalar>& mobility,
2319 if (preferred_phase == Phase::GAS) {
2320 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
2322 else if (preferred_phase == Phase::OIL) {
2323 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
2325 else if (preferred_phase == Phase::WATER) {
2326 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
2330 fmt::format(
"Unsupported Injector Type ({}) "
2331 "for well {} during connection I.I. calculation",
2332 static_cast<int>(preferred_phase), this->name()),
2336 const auto mt = std::accumulate(mobility.begin(), mobility.end(), 0.0);
2337 const int canonicalPhaseIdx = FluidSystem::activeToCanonicalPhaseIdx(phase_pos);
2338 connII[phase_pos] = connIICalc(mt * fs.invB(canonicalPhaseIdx).value());
2341 template<
typename TypeTag>
2342 template<
class GasLiftSingleWell>
2343 std::unique_ptr<GasLiftSingleWell>
2352 auto& comm = simulator.vanguard().grid().comm();
2353 ecl_well_map.try_emplace(this->name(), &(this->wellEcl()), this->indexOfWell());
2354 const auto& iterCtx = simulator.problem().iterationContext();
2357 simulator.vanguard().schedule(),
2358 simulator.vanguard().summaryState(),
2359 simulator.episodeIndex(),
2369 std::set<int> sync_groups;
2370 const auto& summary_state = simulator.vanguard().summaryState();
2371 return std::make_unique<GasLiftSingleWell>(*
this,
#define OPM_DEFLOG_THROW(Exception, message, deferred_logger)
Definition: DeferredLoggingErrorHelpers.hpp:47
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:429
const WellState< Scalar, IndexTraits > & wellState() const
Definition: GroupStateHelper.hpp:510
DeferredLogger & deferredLogger() const
Get the deferred logger.
Definition: GroupStateHelper.hpp:233
WellStateGuard pushWellState(WellState< Scalar, IndexTraits > &well_state)
Definition: GroupStateHelper.hpp:368
GroupStateGuard pushGroupState(GroupState< Scalar > &group_state)
Definition: GroupStateHelper.hpp:345
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:324
int number_of_local_perforations_
Definition: WellInterfaceGeneric.hpp:362
FluidSystem::Scalar wsolvent_
Definition: WellInterfaceGeneric.hpp:402
Definition: WellInterfaceIndices.hpp:34
bool stoppedOrZeroRateTarget(const GroupStateHelperType &groupStateHelper) const
Definition: WellInterface_impl.hpp:1776
bool updateWellOperabilityFromWellEq(const Simulator &simulator, const GroupStateHelperType &groupStateHelper)
Definition: WellInterface_impl.hpp:1327
void checkWellOperability(const Simulator &simulator, const WellStateType &well_state, const GroupStateHelperType &groupStateHelper)
Definition: WellInterface_impl.hpp:1199
void updateWellOperability(const Simulator &simulator, const WellStateType &well_state, const GroupStateHelperType &groupStateHelper)
Definition: WellInterface_impl.hpp:1289
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:625
Scalar woxygen() const
Definition: WellInterface_impl.hpp:167
IndividualOrGroup
Definition: WellInterface.hpp:254
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: WellInterface.hpp:83
void assembleWellEqWithoutIteration(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, const double dt, WellStateType &well_state, const bool solving_with_zero_rate)
Definition: WellInterface_impl.hpp:998
Scalar computeConnectionDFactor(const int perf, const IntensiveQuantities &intQuants, const SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:2023
typename WellInterfaceFluidSystem< FluidSystem >::RateConverterType RateConverterType
Definition: WellInterface.hpp:106
Scalar wfoam() const
Definition: WellInterface_impl.hpp:129
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:288
void getTransMult(Value &trans_mult, const Simulator &simulator, const int cell_idx, Callback &extendEval) const
Definition: WellInterface_impl.hpp:2111
std::vector< RateVector > connectionRates_
Definition: WellInterface.hpp:389
bool solveWellForTesting(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:864
void computeConnLevelProdInd(const FluidState &fs, const std::function< Scalar(const Scalar)> &connPICalc, const std::vector< Scalar > &mobility, Scalar *connPI) const
Definition: WellInterface_impl.hpp:2277
void gliftBeginTimeStepWellTestUpdateALQ(const Simulator &simulator, WellStateType &well_state, const GroupState< Scalar > &group_state, GLiftEclWells &ecl_well_map, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:1227
Scalar volumetricSurfaceRateForConnection(int cellIdx, int phaseIdx) const
Definition: WellInterface_impl.hpp:1179
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:97
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:2242
void getTw(std::vector< Value > &wi, const int perf, const IntensiveQuantities &intQuants, const Value &trans_mult, const SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:1925
void getMobility(const Simulator &simulator, const int local_perf_index, std::vector< Value > &mob, Callback &extendEval, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:2124
GetPropType< TypeTag, Properties::IntensiveQuantities > IntensiveQuantities
Definition: WellInterface.hpp:88
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: WellInterface.hpp:84
std::vector< Scalar > initialWellRateFractions(const Simulator &ebosSimulator, const WellStateType &well_state) const
Definition: WellInterface_impl.hpp:1787
void solveWellEquation(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:920
void updateConnectionDFactor(const Simulator &simulator, SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:2003
Eval getPerfCellPressure(const FluidState &fs) const
Definition: WellInterface_impl.hpp:2096
void initializeProducerWellState(const Simulator &simulator, WellStateType &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1837
virtual void updateWellStateWithTarget(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state) const
Definition: WellInterface_impl.hpp:1357
void addCellRates(std::map< int, RateVector > &cellRates_) const
Definition: WellInterface_impl.hpp:1160
typename Base::ModelParameters ModelParameters
Definition: WellInterface.hpp:112
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: WellInterface.hpp:85
static constexpr bool has_solvent
Definition: WellInterface.hpp:114
bool wellUnderZeroRateTarget(const GroupStateHelperType &groupStateHelper) const
Definition: WellInterface_impl.hpp:1744
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: WellInterface.hpp:91
void updateConnectionTransmissibilityFactor(const Simulator &simulator, SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:2065
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:2311
typename GasLiftGroupInfo< Scalar, IndexTraits >::GLiftEclWells GLiftEclWells
Definition: WellInterface.hpp:93
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:2345
BlackOilFluidStateType< Eval > FluidState
Definition: WellInterface.hpp:144
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:745
Scalar wsalt() const
Definition: WellInterface_impl.hpp:143
bool solveWellWithZeroRate(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:832
bool wellUnderZeroGroupRateTarget(const GroupStateHelperType &groupStateHelper, const std::optional< bool > group_control=std::nullopt) const
Definition: WellInterface_impl.hpp:1761
bool solveWellWithBhp(const Simulator &simulator, const double dt, const Scalar bhp, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:782
void prepareWellBeforeAssembling(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:1033
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:407
typename Base::Eval Eval
Definition: WellInterface.hpp:97
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:60
bool updateWellStateWithTHPTargetProd(const Simulator &simulator, WellStateType &well_state, const GroupStateHelperType &groupStateHelper) const
Definition: WellInterface_impl.hpp:2210
bool iterateWellEquations(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:547
Scalar wpolymer() const
Definition: WellInterface_impl.hpp:113
GetPropType< TypeTag, Properties::Indices > Indices
Definition: WellInterface.hpp:87
bool updateWellControl(const Simulator &simulator, const IndividualOrGroup iog, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:191
Scalar wurea() const
Definition: WellInterface_impl.hpp:179
void updateGroupTargetFallbackFlag(WellStateType &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1018
void assembleWellEq(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:982
Scalar wmicrobes() const
Definition: WellInterface_impl.hpp:155
virtual void scaleSegmentRatesAndPressure(WellStateType &well_state) const
Definition: WellInterface_impl.hpp:1349
static constexpr bool has_zFraction
Definition: WellInterface.hpp:115
Definition: WellState.hpp:68
constexpr int numPhases() const
The number of phases present.
Definition: WellState.hpp:268
const SingleWellState< Scalar, IndexTraits > & well(std::size_t well_index) const
Definition: WellState.hpp:309
bool isOpen(const std::string &name) const
Definition: WellState.hpp:216
@ 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:165
Definition: blackoilbioeffectsmodules.hh:45
std::string economicLimitDateString(const std::time_t start_time, const double sim_time)
Calendar date (DD-Mon-YYYY, UTC) reached at start_time plus sim_time seconds.
Definition: EconomicLimitsMessage.hpp:39
std::string to_string(const ConvergenceReport::ReservoirFailure::Type t)
Static data associated with a well perforation.
Definition: PerforationData.hpp:30