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 std::string closure_reason;
474 auto notReopened = [
this, &when, &deferred_logger](
const std::string_view reason)
476 deferred_logger.info(
477 fmt::format(
"Well {} is not re-opened {}.", this->name(), when));
478 if (!reason.empty()) {
479 deferred_logger.debug(fmt::format(
"Because {}.", reason));
483 bool testWell =
true;
488 const std::size_t original_number_closed_completions = welltest_state_temp.num_closed_completions();
489 bool converged = solveWellForTesting(simulator, groupStateHelper_copy, well_state_copy);
491 notReopened(
"the well equations could not be solved");
496 updateWellOperability(simulator, well_state_copy, groupStateHelper_copy);
497 if ( !this->isOperableAndSolvable() ) {
498 notReopened(
"the well is not operable");
501 std::vector<Scalar> potentials;
503 computeWellPotentials(simulator, well_state_copy, groupStateHelper_copy, potentials);
504 }
catch (
const std::exception& e) {
505 notReopened(fmt::format(
"computing the well potentials failed: {}", e.what()));
508 const int np = well_state_copy.
numPhases();
509 for (
int p = 0; p < np; ++p) {
510 ws.well_potentials[p] = std::max(
Scalar{0.0}, potentials[p]);
512 const bool under_zero_target = this->wellUnderZeroGroupRateTarget(groupStateHelper_copy);
513 this->updateWellTestState(well_state_copy.
well(this->indexOfWell()),
519 simulator.vanguard().eclState().getUnits(),
520 simulator.vanguard().schedule().getStartTime(),
523 this->closeCompletions(welltest_state_temp);
529 if ( welltest_state_temp.num_closed_wells() > 0 ||
530 (original_number_closed_completions == welltest_state_temp.num_closed_completions()) ) {
536 if (!welltest_state_temp.well_is_closed(this->name())) {
537 well_test_state.open_well(this->name());
540 deferred_logger.info(
541 fmt::format(
"{}\nWell {} is re-opened {}.\n{}",
542 sep, this->name(), when, sep));
545 for (
const auto& completion : this->well_ecl_.getCompletions()) {
546 if (!welltest_state_temp.completion_is_closed(this->name(), completion.first))
547 well_test_state.open_completion(this->name(), completion.first);
549 well_state = well_state_copy;
550 open_times.try_emplace(this->name(), well_test_state.lastTestTime(this->name()));
554 notReopened(closure_reason);
561 template<
typename TypeTag>
572 const auto& summary_state = simulator.vanguard().summaryState();
573 const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
574 const auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
575 const auto& ws = well_state.
well(this->indexOfWell());
576 const auto pmode_orig = ws.production_cmode;
577 const auto imode_orig = ws.injection_cmode;
578 bool converged =
false;
581 if (!this->param_.local_well_solver_control_switching_){
582 converged = this->iterateWellEqWithControl(simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state);
584 if (this->param_.use_implicit_ipr_ && this->well_ecl_.isProducer() && (well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
585 converged = solveWellWithOperabilityCheck(
586 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state
589 converged = this->iterateWellEqWithSwitching(
590 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
596 }
catch (NumericalProblem& e ) {
597 const std::string msg =
"Inner well iterations failed for well " + this->name() +
" Treat the well as unconverged. ";
598 deferred_logger.warning(
"INNER_ITERATION_FAILED", msg);
603 if (ws.production_cmode != pmode_orig || ws.injection_cmode != imode_orig) {
605 if (this->isInjector()) {
606 from = WellInjectorCMode2String(imode_orig);
607 to = WellInjectorCMode2String(ws.injection_cmode);
609 from = WellProducerCMode2String(pmode_orig);
610 to = WellProducerCMode2String(ws.production_cmode);
612 const auto msg = fmt::format(
" Well {} switched from {} to {} during local solve", this->name(), from, to);
613 deferred_logger.debug(msg);
614 const int episodeIdx = simulator.episodeIndex();
615 const auto& iterCtx = simulator.problem().iterationContext();
616 const auto& schedule = simulator.vanguard().schedule();
617 const int nupcol = schedule[episodeIdx].nupcol();
621 if (!iterCtx.withinNupcol(nupcol) || this->well_control_log_.empty()) {
622 this->well_control_log_.push_back(from);
627 if (this->isProducer() && ws.production_cmode == Well::ProducerCMode::GRUP && ws.use_group_target_fallback) {
628 assert(ws.group_target && ws.group_target_fallback);
629 const std::string cmode = Group::ProductionCMode2String(ws.group_target->production_cmode);
630 const std::string cmode_fallback = Group::ProductionCMode2String(ws.group_target_fallback->production_cmode);
631 const auto msg = fmt::format(
" Well {} was solved using group target fallback mode {} as current group mode {} was not feasible.",
632 this->name(), cmode_fallback, cmode);
633 deferred_logger.debug(msg);
639 template<
typename TypeTag>
644 const Well::InjectionControls& inj_controls,
645 const Well::ProductionControls& prod_controls,
652 const auto& summary_state = simulator.vanguard().summaryState();
653 bool converged =
true;
654 auto& ws = well_state.
well(this->index_of_well_);
656 if (this->wellIsStopped()) {
658 const bool use_vfpexplicit = this->operability_status_.use_vfpexplicit;
659 this->operability_status_.use_vfpexplicit =
true;
660 auto bhp_target = estimateOperableBhp(simulator, dt, groupStateHelper, summary_state, well_state);
661 if (!bhp_target.has_value()) {
663 const auto msg = fmt::format(
"estimateOperableBhp: Did not find operable BHP for well {}", this->name());
664 deferred_logger.debug(msg);
667 converged = solveWellWithZeroRate(simulator, dt, groupStateHelper, well_state);
669 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
670 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
674 ws.thp = this->getTHPConstraint(summary_state);
675 const Scalar bhp = std::max(bhp_target.value(),
676 static_cast<Scalar>(prod_controls.bhp_limit));
677 solveWellWithBhp(simulator, dt, bhp, groupStateHelper, well_state);
678 this->operability_status_.use_vfpexplicit = use_vfpexplicit;
682 converged = this->iterateWellEqWithSwitching(
683 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
688 const bool isThp = ws.production_cmode == Well::ProducerCMode::THP;
690 if (converged && !stoppedOrZeroRateTarget(groupStateHelper) && isThp) {
691 auto rates = well_state.
well(this->index_of_well_).surface_rates;
692 this->adaptRatesForVFP(rates);
693 this->updateIPRImplicit(simulator, groupStateHelper, well_state);
697 this->operability_status_.use_vfpexplicit =
true;
700 const Scalar reltol = 1e-3;
701 const Scalar cur_bhp = ws.bhp;
702 if (bhp_stable.has_value() && cur_bhp - bhp_stable.value() > cur_bhp*reltol){
703 const auto msg = fmt::format(
"Well {} converged to an unstable solution, re-solving", this->name());
704 deferred_logger.debug(msg);
706 simulator, dt, bhp_stable.value(), groupStateHelper, well_state
709 ws.thp = this->getTHPConstraint(summary_state);
710 converged = this->iterateWellEqWithSwitching(
711 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
720 this->operability_status_.use_vfpexplicit =
true;
722 auto bhp_target = estimateOperableBhp(
723 simulator, dt, groupStateHelper, summary_state, well_state
725 if (!bhp_target.has_value()) {
728 converged = solveWellWithZeroRate(simulator, dt, groupStateHelper, well_state);
730 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
731 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
735 const Scalar bhp = std::max(bhp_target.value(),
736 static_cast<Scalar>(prod_controls.bhp_limit));
738 simulator, dt, bhp, groupStateHelper, well_state
740 ws.thp = this->getTHPConstraint(summary_state);
741 const auto msg = fmt::format(
"Well {} did not converge, re-solving with explicit fractions for VFP caculations.", this->name());
742 deferred_logger.debug(msg);
743 converged = this->iterateWellEqWithSwitching(simulator, dt,
754 this->operability_status_.can_obtain_bhp_with_thp_limit = !this->wellIsStopped();
755 this->operability_status_.obey_thp_limit_under_bhp_limit = !this->wellIsStopped();
759 template<
typename TypeTag>
760 std::optional<typename WellInterface<TypeTag>::Scalar>
765 const SummaryState& summary_state,
768 if (!this->wellHasTHPConstraints(summary_state)) {
770 const bool converged = solveWellWithBhp(
771 simulator, dt, bhp_limit, groupStateHelper, well_state
773 if (!converged || this->wellIsStopped()) {
784 const bool converged = solveWellWithBhp(
785 simulator, dt, bhp_min, groupStateHelper, well_state
787 if (!converged || this->wellIsStopped()) {
790 this->updateIPRImplicit(simulator, groupStateHelper, well_state);
791 auto rates = well_state.
well(this->index_of_well_).surface_rates;
792 this->adaptRatesForVFP(rates);
796 template<
typename TypeTag>
813 auto group_guard = groupStateHelper_copy.
pushGroupState(group_state);
815 auto inj_controls = Well::InjectionControls(0);
816 auto prod_controls = Well::ProductionControls(0);
817 auto& ws = well_state.
well(this->index_of_well_);
818 auto cmode_inj = ws.injection_cmode;
819 auto cmode_prod = ws.production_cmode;
820 if (this->isInjector()) {
821 inj_controls.addControl(Well::InjectorCMode::BHP);
822 inj_controls.bhp_limit = bhp;
823 inj_controls.cmode = Well::InjectorCMode::BHP;
824 ws.injection_cmode = Well::InjectorCMode::BHP;
826 prod_controls.addControl(Well::ProducerCMode::BHP);
827 prod_controls.bhp_limit = bhp;
828 prod_controls.cmode = Well::ProducerCMode::BHP;
829 ws.production_cmode = Well::ProducerCMode::BHP;
834 const bool converged = this->iterateWellEqWithSwitching(
835 simulator, dt, inj_controls, prod_controls, groupStateHelper_copy,
841 ws.injection_cmode = cmode_inj;
842 ws.production_cmode = cmode_prod;
846 template<
typename TypeTag>
857 const auto well_status_orig = this->wellStatus_;
860 auto inj_controls = Well::InjectionControls(0);
861 auto prod_controls = Well::ProductionControls(0);
866 const bool converged = this->iterateWellEqWithSwitching(
867 simulator, dt, inj_controls, prod_controls,
874 this->wellStatus_ = well_status_orig;
878 template<
typename TypeTag>
888 const double dt = simulator.timeStepSize();
890 const auto& summary_state = simulator.vanguard().summaryState();
891 auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
892 auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
893 this->onlyKeepBHPandTHPcontrols(summary_state, well_state, inj_controls, prod_controls);
895 bool converged =
false;
898 if (!this->param_.local_well_solver_control_switching_){
899 converged = this->iterateWellEqWithControl(
900 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state
903 if (this->param_.use_implicit_ipr_ && this->well_ecl_.isProducer() && (well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
904 converged = this->solveWellWithOperabilityCheck(
905 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state
908 converged = this->iterateWellEqWithSwitching(
909 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
917 }
catch (NumericalProblem& e ) {
918 const std::string msg =
"Inner well iterations failed for well " + this->name() +
" Treat the well as unconverged. ";
919 deferred_logger.warning(
"INNER_ITERATION_FAILED", msg);
924 deferred_logger.debug(
"WellTest: Well equation for well " + this->name() +
" converged");
927 const int max_iter = this->param_.max_welleq_iter_;
928 deferred_logger.debug(
"WellTest: Well equation for well " + this->name() +
" failed converging in "
934 template<
typename TypeTag>
943 if (!this->isOperableAndSolvable() && !this->wellIsStopped())
948 const double dt = simulator.timeStepSize();
949 bool converged = iterateWellEquations(simulator, dt, groupStateHelper, well_state);
959 auto& ws = well_state.
well(this->indexOfWell());
960 bool thp_control =
false;
961 if (this->well_ecl_.isInjector()) {
962 thp_control = ws.injection_cmode == Well::InjectorCMode::THP;
964 ws.injection_cmode = Well::InjectorCMode::BHP;
965 if (this->well_control_log_.empty()) {
966 this->well_control_log_.push_back(WellInjectorCMode2String(Well::InjectorCMode::THP));
970 thp_control = ws.production_cmode == Well::ProducerCMode::THP;
972 ws.production_cmode = Well::ProducerCMode::BHP;
973 if (this->well_control_log_.empty()) {
974 this->well_control_log_.push_back(WellProducerCMode2String(Well::ProducerCMode::THP));
979 const std::string msg = std::string(
"The newly opened well ") + this->name()
980 + std::string(
" with THP control did not converge during inner iterations, we try again with bhp control");
981 deferred_logger.debug(msg);
982 converged = this->iterateWellEquations(simulator, dt, groupStateHelper, well_state);
987 const int max_iter = this->param_.max_welleq_iter_;
988 deferred_logger.debug(
"Compute initial well solution for well " + this->name() +
". Failed to converge in "
990 well_state = well_state0;
996 template <
typename TypeTag>
1005 prepareWellBeforeAssembling(simulator, dt, groupStateHelper, well_state);
1006 assembleWellEqWithoutIteration(simulator, groupStateHelper, dt, well_state,
1012 template <
typename TypeTag>
1019 const bool solving_with_zero_rate)
1022 const auto& summary_state = simulator.vanguard().summaryState();
1023 const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
1024 const auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
1027 assembleWellEqWithoutIteration(simulator, groupStateHelper, dt, inj_controls, prod_controls, well_state, solving_with_zero_rate);
1032 template<
typename TypeTag>
1039 std::vector<Scalar> scaled_well_fractions(FluidSystem::numPhases, 0.0);
1040 this->getScaledWellFractions(scaled_well_fractions, deferred_logger);
1042 this->Base::updateGroupTargetFallbackFlag(well_state, scaled_well_fractions, deferred_logger);
1047 template<
typename TypeTag>
1057 const bool old_well_operable = this->operability_status_.isOperableAndSolvable();
1059 if (this->param_.check_well_operability_iter_)
1060 checkWellOperability(simulator, well_state, groupStateHelper);
1063 const auto& iterCtx = simulator.problem().iterationContext();
1064 if (iterCtx.shouldRunInnerWellIterations(this->param_.max_niter_inner_well_iter_)) {
1065 const auto& ws = well_state.
well(this->indexOfWell());
1066 const bool nonzero_rate_original =
1067 std::any_of(ws.surface_rates.begin(),
1068 ws.surface_rates.begin() + well_state.
numPhases(),
1069 [](
Scalar rate) { return rate != Scalar(0.0); });
1071 this->operability_status_.solvable =
true;
1072 if (number_of_well_reopenings_ >= this->param_.max_well_status_switch_) {
1074 if (number_of_well_reopenings_ == this->param_.max_well_status_switch_) {
1075 const std::string msg = fmt::format(
"well {} is oscillating between open and stop. \n"
1076 "We don't allow for more than {} re-openings "
1077 "and the well is therefore kept stopped.",
1078 this->name(), number_of_well_reopenings_);
1079 deferred_logger.debug(msg);
1080 changed_to_stopped_this_step_ = old_well_operable;
1082 changed_to_stopped_this_step_ =
false;
1085 bool converged_zero_rate = this->solveWellWithZeroRate(
1086 simulator, dt, groupStateHelper, well_state
1088 if (this->param_.shut_unsolvable_wells_ && !converged_zero_rate ) {
1089 this->operability_status_.solvable =
false;
1091 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
1092 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
1095 number_of_well_reopenings_++;
1098 bool converged = this->iterateWellEquations(
1099 simulator, dt, groupStateHelper, well_state
1103 const bool zero_target = this->wellUnderZeroRateTarget(groupStateHelper);
1104 if (this->wellIsStopped() && !zero_target && nonzero_rate_original) {
1108 this->operability_status_.resetOperability();
1110 deferred_logger.debug(
" " + this->name() +
" is re-opened after being stopped during local solve");
1111 number_of_well_reopenings_++;
1115 if (this->param_.shut_unsolvable_wells_) {
1116 this->operability_status_.solvable =
false;
1120 if (this->operability_status_.has_negative_potentials) {
1121 auto well_state_copy = well_state;
1122 std::vector<Scalar> potentials;
1124 computeWellPotentials(simulator, well_state_copy, groupStateHelper, potentials);
1125 }
catch (
const std::exception& e) {
1126 const std::string msg = fmt::format(
"well {}: computeWellPotentials() failed "
1127 "during attempt to recompute potentials for well: ",
1128 this->name(), e.what());
1129 deferred_logger.info(msg);
1130 this->operability_status_.has_negative_potentials =
true;
1132 auto& ws = well_state.
well(this->indexOfWell());
1134 for (
int p = 0; p < np; ++p) {
1135 ws.well_potentials[p] = std::max(
Scalar{0.0}, potentials[p]);
1138 this->changed_to_open_this_step_ =
false;
1139 changed_to_stopped_this_step_ =
false;
1141 const bool well_operable = this->operability_status_.isOperableAndSolvable();
1142 if (!well_operable) {
1145 this->solveWellWithZeroRate(
1146 simulator, dt, groupStateHelper, well_state
1148 }
catch (
const std::exception& e) {
1149 const std::string msg = fmt::format(
"well {}: solveWellWithZeroRate() failed "
1150 "during attempt to solve with zero rate for well: ",
1151 this->name(), e.what());
1152 deferred_logger.info(msg);
1154 auto& ws = well_state.
well(this->indexOfWell());
1156 for (
int p = 0; p < np; ++p) {
1157 ws.surface_rates[p] =
Scalar{0.0};
1160 if (old_well_operable) {
1161 const std::string ctx = iterCtx.inLocalSolve() ?
" (NLDD domain solve)" :
"";
1162 deferred_logger.debug(
" well " + this->name() +
" gets STOPPED during iteration" + ctx);
1163 changed_to_stopped_this_step_ =
true;
1165 }
else if (well_state.
isOpen(this->name())) {
1167 if (!old_well_operable) {
1168 const std::string ctx = iterCtx.inLocalSolve() ?
" (NLDD domain solve)" :
"";
1169 deferred_logger.debug(
" well " + this->name() +
" gets REVIVED during iteration" + ctx);
1170 this->changed_to_open_this_step_ =
true;
1175 template<
typename TypeTag>
1179 if(!this->operability_status_.solvable)
1182 for (
int perfIdx = 0; perfIdx < this->number_of_local_perforations_; ++perfIdx) {
1183 const auto cellIdx = this->cells()[perfIdx];
1184 const auto it = cellRates_.find(cellIdx);
1185 RateVector rates = (it == cellRates_.end()) ? 0.0 : it->second;
1186 for (
auto i=0*RateVector::dimension; i < RateVector::dimension; ++i)
1188 rates[i] += connectionRates_[perfIdx][i];
1190 cellRates_.insert_or_assign(cellIdx, rates);
1194 template<
typename TypeTag>
1198 for (
int perfIdx = 0; perfIdx < this->number_of_local_perforations_; ++perfIdx) {
1199 if (this->cells()[perfIdx] == cellIdx) {
1200 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
1201 return connectionRates_[perfIdx][activeCompIdx].value();
1205 OPM_THROW(std::invalid_argument,
"The well with name " + this->name()
1213 template<
typename TypeTag>
1222 if (!this->param_.check_well_operability_) {
1226 if (this->wellIsStopped() && !changed_to_stopped_this_step_) {
1230 updateWellOperability(simulator, well_state, groupStateHelper);
1231 if (!this->operability_status_.isOperableAndSolvable()) {
1232 this->operability_status_.use_vfpexplicit =
true;
1233 deferred_logger.debug(
"EXPLICIT_LOOKUP_VFP",
1234 "well not operable, trying with explicit vfp lookup: " + this->name());
1235 updateWellOperability(simulator, well_state, groupStateHelper);
1241 template<
typename TypeTag>
1251 const auto& summary_state = simulator.vanguard().summaryState();
1252 const auto& well_name = this->name();
1253 if (!this->wellHasTHPConstraints(summary_state)) {
1254 const std::string msg = fmt::format(
"GLIFT WTEST: Well {} does not have THP constraints", well_name);
1255 deferred_logger.
info(msg);
1258 const auto& schedule = simulator.vanguard().schedule();
1259 const auto report_step_idx = simulator.episodeIndex();
1260 const auto& glo = schedule.glo(report_step_idx);
1261 if (!glo.has_well(well_name)) {
1262 const std::string msg = fmt::format(
1263 "GLIFT WTEST: Well {} : Gas lift not activated: "
1264 "WLIFTOPT is probably missing. Skipping.", well_name);
1265 deferred_logger.
info(msg);
1268 const auto& gl_well = glo.well(well_name);
1271 std::unique_ptr<GasLiftSingleWell> glift =
1272 initializeGliftWellTest_<GasLiftSingleWell>(simulator,
1277 auto [wtest_alq, success] = glift->wellTestALQ();
1279 const auto& unit_system = schedule.getUnits();
1281 well_state.
well(well_name).alq_state.set(wtest_alq);
1283 "GLIFT WTEST: Well {} : Setting ALQ to optimized value = {}",
1284 well_name, unit_system.from_si(UnitSystem::measure::gas_surface_rate, wtest_alq));
1287 if (!gl_well.use_glo()) {
1289 "GLIFT WTEST: Well {} : Gas lift optimization deactivated. Setting ALQ to WLIFTOPT item 3 = {}",
1291 unit_system.from_si(UnitSystem::measure::gas_surface_rate, well_state.
well(well_name).alq_state.get()));
1296 "GLIFT WTEST: Well {} : Gas lift optimization failed, no ALQ set.",
1300 deferred_logger.
info(msg);
1303 template<
typename TypeTag>
1312 if (this->param_.local_well_solver_control_switching_) {
1313 const bool success = updateWellOperabilityFromWellEq(simulator, groupStateHelper);
1315 this->operability_status_.solvable =
false;
1316 deferred_logger.debug(
"Operability check using well equations did not converge for well "
1317 + this->name() +
". Mark the well as unsolvable." );
1321 this->operability_status_.resetOperability();
1323 bool thp_controlled = this->isInjector() ? well_state.
well(this->index_of_well_).injection_cmode == Well::InjectorCMode::THP:
1324 well_state.
well(this->index_of_well_).production_cmode == Well::ProducerCMode::THP;
1325 bool bhp_controlled = this->isInjector() ? well_state.
well(this->index_of_well_).injection_cmode == Well::InjectorCMode::BHP:
1326 well_state.
well(this->index_of_well_).production_cmode == Well::ProducerCMode::BHP;
1330 bool check_thp = thp_controlled || this->operability_status_.thp_limit_violated_but_not_switched;
1331 if (check_thp || bhp_controlled) {
1332 updateIPR(simulator, deferred_logger);
1333 checkOperabilityUnderBHPLimit(well_state, simulator, deferred_logger);
1337 checkOperabilityUnderTHPLimit(simulator, well_state, groupStateHelper);
1341 template<
typename TypeTag>
1349 assert(this->param_.local_well_solver_control_switching_);
1350 this->operability_status_.resetOperability();
1353 const double dt = simulator.timeStepSize();
1357 auto guard = groupStateHelper_copy.
pushWellState(well_state_copy);
1359 bool converged = iterateWellEquations(simulator, dt, groupStateHelper_copy, well_state_copy);
1363 template<
typename TypeTag>
1371 template<
typename TypeTag>
1381 const auto& well = this->well_ecl_;
1382 const int well_index = this->index_of_well_;
1383 auto& ws = well_state.
well(well_index);
1385 const auto& summaryState = simulator.vanguard().summaryState();
1386 const auto& schedule = simulator.vanguard().schedule();
1390 ws.primaryvar.resize(0);
1392 if (this->wellIsStopped()) {
1393 for (
int p = 0; p<np; ++p) {
1394 ws.surface_rates[p] = 0;
1400 if (this->isInjector() )
1402 const auto& controls = well.injectionControls(summaryState);
1404 InjectorType injectorType = controls.injector_type;
1406 switch (injectorType) {
1407 case InjectorType::WATER:
1409 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1412 case InjectorType::OIL:
1414 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1417 case InjectorType::GAS:
1419 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1423 OPM_DEFLOG_THROW(std::runtime_error,
"Expected WATER, OIL or GAS as type for injectors " + this->name(), deferred_logger );
1426 const auto current = ws.injection_cmode;
1429 case Well::InjectorCMode::RATE:
1431 ws.surface_rates[phasePos] = (1.0 - this->rsRvInj()) * controls.surface_rate;
1432 if(this->rsRvInj() > 0) {
1433 if (injectorType == InjectorType::OIL && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1434 const int gas_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1435 ws.surface_rates[gas_pos] = controls.surface_rate * this->rsRvInj();
1436 }
else if (injectorType == InjectorType::GAS && FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1437 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1438 ws.surface_rates[oil_pos] = controls.surface_rate * this->rsRvInj();
1440 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 );
1446 case Well::InjectorCMode::RESV:
1448 std::vector<Scalar> convert_coeff(this->number_of_phases_, 1.0);
1449 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, convert_coeff);
1450 const Scalar coeff = convert_coeff[phasePos];
1451 ws.surface_rates[phasePos] = controls.reservoir_rate/coeff;
1455 case Well::InjectorCMode::THP:
1457 auto rates = ws.surface_rates;
1462 this->getRefDensity(),
1465 ws.thp = this->getTHPConstraint(summaryState);
1470 Scalar total_rate = std::accumulate(rates.begin(), rates.end(), 0.0);
1471 if (total_rate <= 0.0)
1472 ws.surface_rates = ws.well_potentials;
1476 case Well::InjectorCMode::BHP:
1478 ws.bhp = controls.bhp_limit;
1480 for (
int p = 0; p<np; ++p) {
1481 total_rate += ws.surface_rates[p];
1486 if (total_rate <= 0.0)
1487 ws.surface_rates = ws.well_potentials;
1491 case Well::InjectorCMode::GRUP:
1493 assert(well.isAvailableForGroupControl());
1494 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
1495 const Scalar efficiencyFactor = well.getEfficiencyFactor() *
1496 well_state[well.name()].efficiency_scaling_factor;
1497 std::optional<Scalar> target =
1498 this->getGroupInjectionTargetRate(group,
1503 ws.surface_rates[phasePos] = *target;
1506 case Well::InjectorCMode::CMODE_UNDEFINED:
1508 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name(), deferred_logger );
1518 ws.surface_rates[phasePos] = std::max(
Scalar{1.e-7}, ws.surface_rates[phasePos]);
1521 ws.bhp = controls.bhp_limit;
1527 const auto current = ws.production_cmode;
1528 const auto& controls = well.productionControls(summaryState);
1530 case Well::ProducerCMode::ORAT:
1532 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1533 Scalar current_rate = -ws.surface_rates[oil_pos];
1536 if (current_rate > 0.0) {
1537 for (
int p = 0; p<np; ++p) {
1538 ws.surface_rates[p] *= controls.oil_rate/current_rate;
1541 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1542 double control_fraction = fractions[oil_pos];
1543 if (control_fraction != 0.0) {
1544 for (
int p = 0; p<np; ++p) {
1545 ws.surface_rates[p] = - fractions[p] * controls.oil_rate/control_fraction;
1551 case Well::ProducerCMode::WRAT:
1553 const int water_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1554 Scalar current_rate = -ws.surface_rates[water_pos];
1557 if (current_rate > 0.0) {
1558 for (
int p = 0; p<np; ++p) {
1559 ws.surface_rates[p] *= controls.water_rate/current_rate;
1562 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1563 const Scalar control_fraction = fractions[water_pos];
1564 if (control_fraction != 0.0) {
1565 for (
int p = 0; p<np; ++p) {
1566 ws.surface_rates[p] = - fractions[p] * controls.water_rate / control_fraction;
1572 case Well::ProducerCMode::GRAT:
1574 const int gas_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1575 Scalar current_rate = -ws.surface_rates[gas_pos];
1578 if (current_rate > 0.0) {
1579 for (
int p = 0; p<np; ++p) {
1580 ws.surface_rates[p] *= controls.gas_rate/current_rate;
1583 const std::vector<Scalar > fractions = initialWellRateFractions(simulator, well_state);
1584 const Scalar control_fraction = fractions[gas_pos];
1585 if (control_fraction != 0.0) {
1586 for (
int p = 0; p<np; ++p) {
1587 ws.surface_rates[p] = - fractions[p] * controls.gas_rate / control_fraction;
1595 case Well::ProducerCMode::LRAT:
1597 const int water_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1598 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1599 Scalar current_rate = - ws.surface_rates[water_pos]
1600 - ws.surface_rates[oil_pos];
1603 if (current_rate > 0.0) {
1604 for (
int p = 0; p<np; ++p) {
1605 ws.surface_rates[p] *= controls.liquid_rate/current_rate;
1608 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1609 const Scalar control_fraction = fractions[water_pos] + fractions[oil_pos];
1610 if (control_fraction != 0.0) {
1611 for (
int p = 0; p<np; ++p) {
1612 ws.surface_rates[p] = - fractions[p] * controls.liquid_rate / control_fraction;
1618 case Well::ProducerCMode::CRAT:
1621 fmt::format(
"CRAT control not supported, well {}", this->name()),
1624 case Well::ProducerCMode::RESV:
1626 std::vector<Scalar> convert_coeff(this->number_of_phases_, 1.0);
1627 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, ws.surface_rates, convert_coeff);
1628 Scalar total_res_rate = 0.0;
1629 for (
int p = 0; p<np; ++p) {
1630 total_res_rate -= ws.surface_rates[p] * convert_coeff[p];
1632 if (controls.prediction_mode) {
1635 if (total_res_rate > 0.0) {
1636 for (
int p = 0; p<np; ++p) {
1637 ws.surface_rates[p] *= controls.resv_rate/total_res_rate;
1640 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1641 for (
int p = 0; p<np; ++p) {
1642 ws.surface_rates[p] = - fractions[p] * controls.resv_rate / convert_coeff[p];
1646 std::vector<Scalar> hrates(this->number_of_phases_,0.);
1647 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
1648 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1649 hrates[phase_pos] = controls.water_rate;
1651 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1652 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1653 hrates[phase_pos] = controls.oil_rate;
1655 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1656 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1657 hrates[phase_pos] = controls.gas_rate;
1659 std::vector<Scalar> hrates_resv(this->number_of_phases_,0.);
1660 this->rateConverter_.calcReservoirVoidageRates( 0, this->pvtRegionIdx_, hrates, hrates_resv);
1661 Scalar target = std::accumulate(hrates_resv.begin(), hrates_resv.end(), 0.0);
1664 if (total_res_rate > 0.0) {
1665 for (
int p = 0; p<np; ++p) {
1666 ws.surface_rates[p] *= target/total_res_rate;
1669 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1670 for (
int p = 0; p<np; ++p) {
1671 ws.surface_rates[p] = - fractions[p] * target / convert_coeff[p];
1677 case Well::ProducerCMode::BHP:
1679 ws.bhp = controls.bhp_limit;
1681 for (
int p = 0; p<np; ++p) {
1682 total_rate -= ws.surface_rates[p];
1687 if (total_rate <= 0.0){
1688 for (
int p = 0; p<np; ++p) {
1689 ws.surface_rates[p] = -ws.well_potentials[p];
1694 case Well::ProducerCMode::THP:
1696 const bool update_success = updateWellStateWithTHPTargetProd(simulator, well_state, groupStateHelper);
1698 if (!update_success) {
1702 auto rates = ws.surface_rates;
1703 this->adaptRatesForVFP(rates);
1705 well_state, rates, well, summaryState, this->getRefDensity(), deferred_logger);
1707 ws.thp = this->getTHPConstraint(summaryState);
1711 const Scalar total_rate = -std::accumulate(rates.begin(), rates.end(), 0.0);
1712 if (total_rate <= 0.0) {
1713 for (
int p = 0; p < this->number_of_phases_; ++p) {
1714 ws.surface_rates[p] = -ws.well_potentials[p];
1720 case Well::ProducerCMode::GRUP:
1722 assert(well.isAvailableForGroupControl());
1723 this->updateGroupTargetFallbackFlag(well_state, deferred_logger);
1724 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
1725 const Scalar efficiencyFactor = well.getEfficiencyFactor() *
1726 well_state[well.name()].efficiency_scaling_factor;
1727 Scalar scale = this->getGroupProductionTargetRate(group,
1733 for (
int p = 0; p<np; ++p) {
1734 ws.surface_rates[p] *= scale;
1736 ws.trivial_group_target =
false;
1740 ws.trivial_group_target =
true;
1744 case Well::ProducerCMode::CMODE_UNDEFINED:
1747 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name() , deferred_logger);
1753 ws.bhp = controls.bhp_limit;
1758 template<
typename TypeTag>
1764 const auto& well_state = groupStateHelper.
wellState();
1766 const bool isGroupControlled = this->wellUnderGroupControl(well_state.well(this->index_of_well_));
1767 if (!isGroupControlled) {
1769 const auto& summaryState = groupStateHelper.
summaryState();
1770 return this->wellUnderZeroRateTargetIndividual(summaryState, well_state);
1772 return this->wellUnderZeroGroupRateTarget(groupStateHelper, isGroupControlled);
1776 template <
typename TypeTag>
1779 const std::optional<bool> group_control)
const
1781 const auto& well_state = groupStateHelper.
wellState();
1783 const bool isGroupControlled = group_control.value_or(this->wellUnderGroupControl(well_state.well(this->index_of_well_)));
1784 if (isGroupControlled) {
1785 return this->zeroGroupRateTarget(groupStateHelper);
1790 template<
typename TypeTag>
1797 return this->wellIsStopped()
1798 || this->wellUnderZeroRateTarget(groupStateHelper);
1801 template<
typename TypeTag>
1802 std::vector<typename WellInterface<TypeTag>::Scalar>
1808 const int np = this->number_of_phases_;
1809 std::vector<Scalar> scaling_factor(np);
1810 const auto& ws = well_state.
well(this->index_of_well_);
1812 Scalar total_potentials = 0.0;
1813 for (
int p = 0; p<np; ++p) {
1814 total_potentials += ws.well_potentials[p];
1816 if (total_potentials > 0) {
1817 for (
int p = 0; p<np; ++p) {
1818 scaling_factor[p] = ws.well_potentials[p] / total_potentials;
1820 return scaling_factor;
1825 const int nperf = this->number_of_local_perforations_;
1826 for (
int perf = 0; perf < nperf; ++perf) {
1827 total_tw += this->well_index_[perf];
1829 total_tw = this->parallelWellInfo().communication().sum(total_tw);
1831 for (
int perf = 0; perf < nperf; ++perf) {
1832 const int cell_idx = this->well_cells_[perf];
1833 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
1834 const auto& fs = intQuants.fluidState();
1835 const Scalar well_tw_fraction = this->well_index_[perf] / total_tw;
1836 Scalar total_mobility = 0.0;
1837 for (
int p = 0; p < np; ++p) {
1838 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
1839 total_mobility += fs.invB(canonical_phase_idx).value() * intQuants.mobility(canonical_phase_idx).value();
1841 for (
int p = 0; p < np; ++p) {
1842 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
1843 scaling_factor[p] += well_tw_fraction * fs.invB(canonical_phase_idx).value() * intQuants.mobility(canonical_phase_idx).value() / total_mobility;
1846 return scaling_factor;
1851 template <
typename TypeTag>
1858 assert(this->isProducer());
1862 auto& ws = well_state.
well(this->index_of_well_);
1863 int nonzero_rate_index = -1;
1864 const Scalar floating_point_error_epsilon = 1e-14;
1865 for (
int p = 0; p < this->number_of_phases_; ++p) {
1866 if (std::abs(ws.surface_rates[p]) > floating_point_error_epsilon) {
1867 if (nonzero_rate_index == -1) {
1868 nonzero_rate_index = p;
1877 std::vector<Scalar> well_q_s(this->number_of_phases_, 0.0);
1878 bool rates_evaluated_at_1bar =
false;
1880 const auto& summary_state = simulator.vanguard().summaryState();
1881 const auto& prod_controls = this->well_ecl_.productionControls(summary_state);
1882 const double bhp_limit = std::max(prod_controls.bhp_limit, 1.0 * unit::barsa);
1883 this->computeWellRatesWithBhp(simulator, bhp_limit, well_q_s, deferred_logger);
1885 rates_evaluated_at_1bar = (bhp_limit < 1.1 * unit::barsa);
1887 if (std::ranges::any_of(well_q_s, [](
Scalar q) {
return q > 0.0; })) {
1889 if (!rates_evaluated_at_1bar) {
1890 this->computeWellRatesWithBhp(simulator, 1.0 * unit::barsa, well_q_s, deferred_logger);
1891 rates_evaluated_at_1bar =
true;
1894 for (
auto& q : well_q_s) {
1895 q = std::min(q,
Scalar{0.0});
1900 if (nonzero_rate_index == -1) {
1904 const Scalar factor = rates_evaluated_at_1bar ? 0.5 : 1.0;
1905 for (
int p = 0; p < this->number_of_phases_; ++p) {
1906 ws.surface_rates[p] = factor * well_q_s[p];
1915 const Scalar initial_nonzero_rate = ws.surface_rates[nonzero_rate_index];
1916 const Scalar computed_rate = well_q_s[nonzero_rate_index];
1917 if (std::abs(initial_nonzero_rate) < std::abs(computed_rate)) {
1919 const Scalar factor = initial_nonzero_rate / computed_rate;
1920 assert(factor < 1.0);
1921 for (
int p = 0; p < this->number_of_phases_; ++p) {
1923 if (p != nonzero_rate_index) {
1924 ws.surface_rates[p] = factor * well_q_s[p];
1933 for (
int p = 0; p < this->number_of_phases_; ++p) {
1934 ws.surface_rates[p] = well_q_s[p];
1938 template <
typename TypeTag>
1939 template<
class Value>
1942 getTw(std::vector<Value>& Tw,
1945 const Value& trans_mult,
1948 OPM_TIMEFUNCTION_LOCAL(Subsystem::Wells);
1951 if (
static_cast<std::size_t
>(perf) >= this->well_cells_.size()) {
1952 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!");
1955 if constexpr (! Indices::gasEnabled) {
1959 const auto& wdfac = this->well_ecl_.getWDFAC();
1961 if (! wdfac.useDFactor() || (this->well_index_[perf] == 0.0)) {
1965 const Scalar d = this->computeConnectionDFactor(perf, intQuants, ws);
1972 const auto& connection = this->well_ecl_.getConnections()[ws.
perf_data.ecl_index[perf]];
1973 const Scalar Kh = connection.Kh();
1974 const Scalar scaling = std::numbers::pi * Kh * connection.wpimult();
1975 const unsigned gas_comp_idx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
1978 const Scalar cell_pressure = getValue(intQuants.fluidState().pressure(FluidSystem::gasPhaseIdx));
1979 const Scalar drawdown = cell_pressure - connection_pressure;
1980 const Scalar invB = getValue(intQuants.fluidState().invB(FluidSystem::gasPhaseIdx));
1981 const Scalar mob_g = getValue(intQuants.mobility(FluidSystem::gasPhaseIdx)) * invB;
1983 const Scalar b = 2 * scaling / getValue(Tw[gas_comp_idx]);
1984 const Scalar c = -2 * scaling * mob_g * drawdown;
1986 Scalar consistent_Q = -1.0e20;
1988 const Scalar r2n = b*b + 4*a*c;
1990 const Scalar rn = std::sqrt(r2n);
1991 const Scalar xn1 = (b-rn)*0.5/a;
1995 const Scalar xn2 = (b+rn)*0.5/a;
1996 if (xn2 <= 0 && xn2 > consistent_Q) {
2002 const Scalar r2p = b*b - 4*a*c;
2004 const Scalar rp = std::sqrt(r2p);
2005 const Scalar xp1 = (rp-b)*0.5/a;
2006 if (xp1 > 0 && xp1 < consistent_Q) {
2009 const Scalar xp2 = -(rp+b)*0.5/a;
2010 if (xp2 > 0 && xp2 < consistent_Q) {
2014 Tw[gas_comp_idx] = 1.0 / (1.0 / (trans_mult * this->well_index_[perf]) + (consistent_Q/2 * d / scaling));
2017 template <
typename TypeTag>
2023 if (! this->well_ecl_.getWDFAC().useDFactor()) {
2027 auto& d_factor = ws.
perf_data.connection_d_factor;
2029 for (
int perf = 0; perf < this->number_of_local_perforations_; ++perf) {
2030 const int cell_idx = this->well_cells_[perf];
2031 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2033 d_factor[perf] = this->computeConnectionDFactor(perf, intQuants, ws);
2037 template <
typename TypeTag>
2044 auto rhoGS = [regIdx = this->pvtRegionIdx()]() {
2045 return FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, regIdx);
2049 auto gas_visc = [connection_pressure = ws.
perf_data.pressure[perf],
2051 regIdx = this->pvtRegionIdx(), &intQuants]()
2053 const auto rv = getValue(intQuants.fluidState().Rv());
2055 const auto& gasPvt = FluidSystem::gasPvt();
2060 const Scalar rv_sat = gasPvt.saturatedOilVaporizationFactor
2061 (regIdx, temperature, connection_pressure);
2063 if (! (rv < rv_sat)) {
2064 return gasPvt.saturatedViscosity(regIdx, temperature,
2065 connection_pressure);
2068 return gasPvt.viscosity(regIdx, temperature, connection_pressure,
2069 rv, getValue(intQuants.fluidState().Rvw()));
2072 const auto& connection = this->well_ecl_.getConnections()
2075 return this->well_ecl_.getWDFAC().getDFactor(rhoGS, gas_visc, connection);
2079 template <
typename TypeTag>
2085 auto connCF = [&connIx = std::as_const(ws.
perf_data.ecl_index),
2086 &conns = this->well_ecl_.getConnections()]
2089 return conns[connIx[perf]].CF();
2092 auto obtain = [](
const Eval& value)
2094 return getValue(value);
2097 auto& tmult = ws.
perf_data.connection_compaction_tmult;
2098 auto& ctf = ws.
perf_data.connection_transmissibility_factor;
2100 for (
int perf = 0; perf < this->number_of_local_perforations_; ++perf) {
2101 const int cell_idx = this->well_cells_[perf];
2103 getTransMult(trans_mult, simulator, cell_idx, obtain);
2104 tmult[perf] = trans_mult;
2106 ctf[perf] = connCF(perf) * tmult[perf];
2111 template<
typename TypeTag>
2115 if constexpr (Indices::oilEnabled) {
2116 return fs.pressure(FluidSystem::oilPhaseIdx);
2117 }
else if constexpr (Indices::gasEnabled) {
2118 return fs.pressure(FluidSystem::gasPhaseIdx);
2120 return fs.pressure(FluidSystem::waterPhaseIdx);
2124 template <
typename TypeTag>
2125 template<
class Value,
class Callback>
2131 Callback& extendEval)
const
2133 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2134 trans_mult = simulator.problem().template wellTransMultiplier<Value>(intQuants, cell_idx, extendEval);
2137 template <
typename TypeTag>
2138 template<
class Value,
class Callback>
2142 const int local_perf_index,
2143 std::vector<Value>& mob,
2144 Callback& extendEval,
2147 auto relpermArray = []()
2149 if constexpr (std::is_same_v<Value, Scalar>) {
2150 return std::array<Scalar,3>{};
2152 return std::array<Eval,3>{};
2155 if (
static_cast<std::size_t
>(local_perf_index) >= this->well_cells_.size()) {
2156 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!");
2158 const int cell_idx = this->well_cells_[local_perf_index];
2159 assert (
int(mob.size()) == this->num_conservation_quantities_);
2160 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2161 const auto& materialLawManager = simulator.problem().materialLawManager();
2165 const int satid = this->saturation_table_number_[local_perf_index] - 1;
2166 const int satid_elem = materialLawManager->satnumRegionIdx(cell_idx);
2167 if (satid == satid_elem) {
2168 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2169 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2173 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2174 mob[activeCompIdx] = extendEval(intQuants.mobility(phaseIdx));
2176 if constexpr (has_solvent) {
2177 mob[Indices::contiSolventEqIdx] = extendEval(intQuants.solventMobility());
2180 const auto& paramsCell = materialLawManager->connectionMaterialLawParams(satid, cell_idx);
2181 auto relativePerms = relpermArray();
2182 MaterialLaw::relativePermeabilities(relativePerms, paramsCell, intQuants.fluidState());
2185 materialLawManager->connectionMaterialLawParams(satid_elem, cell_idx);
2188 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2189 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2193 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2194 mob[activeCompIdx] = extendEval(relativePerms[phaseIdx] / intQuants.fluidState().viscosity(phaseIdx));
2197 if constexpr (has_solvent) {
2198 const auto Fsolgas = intQuants.solventSaturation() / (intQuants.solventSaturation() + intQuants.fluidState().saturation(FluidSystem::gasPhaseIdx));
2200 if (Fsolgas > SolventModule::cutOff) {
2201 const unsigned activeGasCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(FluidSystem::gasPhaseIdx));
2202 const auto& ssfnKrg = SolventModule::ssfnKrg(satid);
2203 const auto& ssfnKrs = SolventModule::ssfnKrs(satid);
2204 mob[activeGasCompIdx] *= extendEval(ssfnKrg.eval(1-Fsolgas,
true));
2205 mob[Indices::contiSolventEqIdx] = extendEval(ssfnKrs.eval(Fsolgas,
true) * relativePerms[activeGasCompIdx] / intQuants.solventViscosity());
2210 if (this->isInjector() && !this->inj_fc_multiplier_.empty()) {
2211 const auto perf_ecl_index = this->perforationData()[local_perf_index].ecl_index;
2212 const auto& connections = this->well_ecl_.getConnections();
2213 const auto& connection = connections[perf_ecl_index];
2214 if (connection.filterCakeActive()) {
2215 std::ranges::transform(mob, mob.begin(),
2216 [mult = this->inj_fc_multiplier_[local_perf_index]]
2218 { return val * mult; });
2224 template<
typename TypeTag>
2233 const auto& summary_state = simulator.vanguard().summaryState();
2235 auto bhp_at_thp_limit = computeBhpAtThpLimitProdWithAlq(
2236 simulator, groupStateHelper, summary_state, this->getALQ(well_state),
false);
2237 if (bhp_at_thp_limit) {
2238 std::vector<Scalar> rates(this->number_of_phases_, 0.0);
2239 if (thp_update_iterations) {
2240 computeWellRatesWithBhpIterations(simulator, *bhp_at_thp_limit,
2241 groupStateHelper, rates);
2243 computeWellRatesWithBhp(simulator, *bhp_at_thp_limit,
2244 rates, deferred_logger);
2246 auto& ws = well_state.
well(this->name());
2247 ws.surface_rates = rates;
2248 ws.bhp = *bhp_at_thp_limit;
2249 ws.thp = this->getTHPConstraint(summary_state);
2256 template<
typename TypeTag>
2257 std::optional<typename WellInterface<TypeTag>::Scalar>
2262 const SummaryState& summary_state,
2267 const auto& groupStateHelper = simulator.problem().wellModel().groupStateHelper();
2269 auto well_guard = groupStateHelper_copy.
pushWellState(well_state_copy);
2270 const double dt = simulator.timeStepSize();
2271 const bool converged = this->solveWellWithBhp(
2272 simulator, dt, bhp, groupStateHelper_copy, well_state_copy
2276 auto rates = well_state_copy.
well(this->index_of_well_).surface_rates;
2278 for (std::size_t p = 0; p < rates.size(); ++p) {
2279 zero_rates &= rates[p] == 0.0;
2283 if (zero_rates || !converged) {
2284 return this->computeBhpAtThpLimitProdWithAlq(simulator, groupStateHelper_copy, summary_state, alq_value,
false);
2286 this->updateIPRImplicit(simulator, groupStateHelper_copy, well_state_copy);
2287 this->adaptRatesForVFP(rates);
2291 template <
typename TypeTag>
2296 const std::vector<Scalar>& mobility,
2299 const int np = this->number_of_phases_;
2300 for (
int p = 0; p < np; ++p) {
2303 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
2304 const auto connMob =
2305 mobility[FluidSystem::activePhaseToActiveCompIdx(p)] * fs.invB(canonical_phase_idx).value();
2307 connPI[p] = connPICalc(connMob);
2310 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) &&
2311 FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx))
2313 const auto io = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
2314 const auto ig = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
2316 const auto vapoil = connPI[ig] * fs.Rv().value();
2317 const auto disgas = connPI[io] * fs.Rs().value();
2319 connPI[io] += vapoil;
2320 connPI[ig] += disgas;
2325 template <
typename TypeTag>
2329 const Phase preferred_phase,
2331 const std::vector<Scalar>& mobility,
2336 if (preferred_phase == Phase::GAS) {
2337 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
2339 else if (preferred_phase == Phase::OIL) {
2340 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
2342 else if (preferred_phase == Phase::WATER) {
2343 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
2347 fmt::format(
"Unsupported Injector Type ({}) "
2348 "for well {} during connection I.I. calculation",
2349 static_cast<int>(preferred_phase), this->name()),
2353 const auto mt = std::accumulate(mobility.begin(), mobility.end(), 0.0);
2354 const int canonicalPhaseIdx = FluidSystem::activeToCanonicalPhaseIdx(phase_pos);
2355 connII[phase_pos] = connIICalc(mt * fs.invB(canonicalPhaseIdx).value());
2358 template<
typename TypeTag>
2359 template<
class GasLiftSingleWell>
2360 std::unique_ptr<GasLiftSingleWell>
2369 auto& comm = simulator.vanguard().grid().comm();
2370 ecl_well_map.try_emplace(this->name(), &(this->wellEcl()), this->indexOfWell());
2371 const auto& iterCtx = simulator.problem().iterationContext();
2374 simulator.vanguard().schedule(),
2375 simulator.vanguard().summaryState(),
2376 simulator.episodeIndex(),
2386 std::set<int> sync_groups;
2387 const auto& summary_state = simulator.vanguard().summaryState();
2388 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:109
PerfData< Scalar > perf_data
Definition: SingleWellState.hpp:158
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:341
int number_of_local_perforations_
Definition: WellInterfaceGeneric.hpp:379
FluidSystem::Scalar wsolvent_
Definition: WellInterfaceGeneric.hpp:419
Definition: WellInterfaceIndices.hpp:34
bool stoppedOrZeroRateTarget(const GroupStateHelperType &groupStateHelper) const
Definition: WellInterface_impl.hpp:1793
bool updateWellOperabilityFromWellEq(const Simulator &simulator, const GroupStateHelperType &groupStateHelper)
Definition: WellInterface_impl.hpp:1344
void checkWellOperability(const Simulator &simulator, const WellStateType &well_state, const GroupStateHelperType &groupStateHelper)
Definition: WellInterface_impl.hpp:1216
void updateWellOperability(const Simulator &simulator, const WellStateType &well_state, const GroupStateHelperType &groupStateHelper)
Definition: WellInterface_impl.hpp:1306
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:642
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:1015
Scalar computeConnectionDFactor(const int perf, const IntensiveQuantities &intQuants, const SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:2040
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:2128
std::vector< RateVector > connectionRates_
Definition: WellInterface.hpp:389
bool solveWellForTesting(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:881
void computeConnLevelProdInd(const FluidState &fs, const std::function< Scalar(const Scalar)> &connPICalc, const std::vector< Scalar > &mobility, Scalar *connPI) const
Definition: WellInterface_impl.hpp:2294
void gliftBeginTimeStepWellTestUpdateALQ(const Simulator &simulator, WellStateType &well_state, const GroupState< Scalar > &group_state, GLiftEclWells &ecl_well_map, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:1244
Scalar volumetricSurfaceRateForConnection(int cellIdx, int phaseIdx) const
Definition: WellInterface_impl.hpp:1196
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:2259
void getTw(std::vector< Value > &wi, const int perf, const IntensiveQuantities &intQuants, const Value &trans_mult, const SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:1942
void getMobility(const Simulator &simulator, const int local_perf_index, std::vector< Value > &mob, Callback &extendEval, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:2141
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:1804
void solveWellEquation(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:937
void updateConnectionDFactor(const Simulator &simulator, SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:2020
Eval getPerfCellPressure(const FluidState &fs) const
Definition: WellInterface_impl.hpp:2113
void initializeProducerWellState(const Simulator &simulator, WellStateType &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1854
virtual void updateWellStateWithTarget(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state) const
Definition: WellInterface_impl.hpp:1374
void addCellRates(std::map< int, RateVector > &cellRates_) const
Definition: WellInterface_impl.hpp:1177
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:1761
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: WellInterface.hpp:91
void updateConnectionTransmissibilityFactor(const Simulator &simulator, SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:2082
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:2328
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:2362
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:762
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:849
bool wellUnderZeroGroupRateTarget(const GroupStateHelperType &groupStateHelper, const std::optional< bool > group_control=std::nullopt) const
Definition: WellInterface_impl.hpp:1778
bool solveWellWithBhp(const Simulator &simulator, const double dt, const Scalar bhp, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:799
void prepareWellBeforeAssembling(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:1050
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:2227
bool iterateWellEquations(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:564
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:1035
void assembleWellEq(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:999
Scalar wmicrobes() const
Definition: WellInterface_impl.hpp:155
virtual void scaleSegmentRatesAndPressure(WellStateType &well_state) const
Definition: WellInterface_impl.hpp:1366
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:270
const SingleWellState< Scalar, IndexTraits > & well(std::size_t well_index) const
Definition: WellState.hpp:311
bool isOpen(const std::string &name) const
Definition: WellState.hpp:218
@ 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
const std::string & economicLimitMessageSeparator()
Separator line used to frame economic-limit workover messages. Built once and returned by reference (...
Definition: EconomicLimitsMessage.hpp:61
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:41
std::string to_string(const ConvergenceReport::ReservoirFailure::Type t)
Static data associated with a well perforation.
Definition: PerforationData.hpp:30