22#ifndef OPM_WELLINTERFACE_IMPL_HEADER_INCLUDED
23#define OPM_WELLINTERFACE_IMPL_HEADER_INCLUDED
26#ifndef OPM_WELLINTERFACE_HEADER_INCLUDED
31#include <opm/common/Exceptions.hpp>
33#include <opm/input/eclipse/Schedule/ScheduleTypes.hpp>
34#include <opm/input/eclipse/Schedule/Well/WDFAC.hpp>
43#include <dune/common/version.hh>
50#include <fmt/format.h>
56 template<
typename TypeTag>
63 const int pvtRegionIdx,
64 const int num_conservation_quantities,
66 const int index_of_well,
74 num_conservation_quantities,
82 if (well.isInjector()) {
83 auto injectorType = this->
well_ecl_.injectorType();
84 if (injectorType == InjectorType::GAS) {
92 template<
typename TypeTag>
95 init(
const std::vector<Scalar>& ,
97 const std::vector<Scalar>& B_avg,
98 const bool changed_to_open_this_step)
100 this->gravity_ = gravity_arg;
102 this->changed_to_open_this_step_ = changed_to_open_this_step;
108 template<
typename TypeTag>
113 if constexpr (has_polymer) {
114 return this->wpolymer_();
124 template<
typename TypeTag>
129 if constexpr (has_foam) {
130 return this->wfoam_();
138 template<
typename TypeTag>
143 if constexpr (has_brine) {
144 return this->wsalt_();
150 template<
typename TypeTag>
155 if constexpr (has_micp) {
156 return this->wmicrobes_();
162 template<
typename TypeTag>
167 if constexpr (has_micp) {
168 return this->woxygen_();
174 template<
typename TypeTag>
179 if constexpr (has_micp) {
180 return this->wurea_();
186 template<
typename TypeTag>
196 if (stoppedOrZeroRateTarget(groupStateHelper)) {
200 const auto& summaryState = simulator.vanguard().summaryState();
201 const auto& schedule = simulator.vanguard().schedule();
202 const auto& well = this->well_ecl_;
203 auto& ws = well_state.
well(this->index_of_well_);
205 bool is_grup =
false;
206 if (well.isInjector()) {
207 from = WellInjectorCMode2String(ws.injection_cmode);
208 is_grup = ws.injection_cmode == Well::InjectorCMode::GRUP;
210 from = WellProducerCMode2String(ws.production_cmode);
211 is_grup = ws.production_cmode == Well::ProducerCMode::GRUP;
214 const int episodeIdx = simulator.episodeIndex();
215 const auto& iterCtx = simulator.problem().iterationContext();
216 const int nupcol = schedule[episodeIdx].nupcol();
217 const bool oscillating =
218 std::ranges::count(this->well_control_log_, from) >= this->param_.max_number_of_well_switches_;
219 if (oscillating && !is_grup) {
222 std::ranges::count(this->well_control_log_, from) == this->param_.max_number_of_well_switches_;
224 const auto msg = fmt::format(
" The control mode for well {} is oscillating. \n"
225 "We don't allow for more than {} switches after NUPCOL iterations. (NUPCOL = {}) \n"
226 "The control is kept at {}.",
227 this->name(), this->param_.max_number_of_well_switches_, nupcol, from);
228 deferred_logger.info(msg);
230 this->well_control_log_.push_back(from);
234 bool changed =
false;
235 if (iog == IndividualOrGroup::Individual) {
236 changed = this->checkIndividualConstraints(ws, summaryState, deferred_logger);
237 }
else if (iog == IndividualOrGroup::Group) {
238 changed = this->checkGroupConstraints(
239 groupStateHelper, schedule, summaryState,
true, well_state
242 assert(iog == IndividualOrGroup::Both);
243 changed = this->checkConstraints(groupStateHelper, schedule, summaryState, well_state);
249 if (well.isInjector()) {
250 to = WellInjectorCMode2String(ws.injection_cmode);
252 to = WellProducerCMode2String(ws.production_cmode);
254 std::ostringstream ss;
255 ss <<
" Switching control mode for well " << this->name()
258 if (iterCtx.inLocalSolve()) {
259 ss <<
" (NLDD domain solve)";
262 ss <<
" on rank " << cc.rank();
264 deferred_logger.debug(ss.str());
271 if (!iterCtx.inLocalSolve()) {
272 if (!iterCtx.withinNupcol(nupcol) || this->well_control_log_.empty()) {
273 this->well_control_log_.push_back(from);
276 updateWellStateWithTarget(simulator, groupStateHelper, well_state);
277 updatePrimaryVariables(groupStateHelper);
283 template<
typename TypeTag>
288 const Well::InjectionControls& inj_controls,
289 const Well::ProductionControls& prod_controls,
292 const bool fixed_control,
293 const bool fixed_status,
294 const bool solving_with_zero_rate)
298 const auto& summary_state = simulator.vanguard().summaryState();
299 const auto& schedule = simulator.vanguard().schedule();
300 auto& ws = well_state.
well(this->index_of_well_);
302 if (this->isInjector()) {
303 from = WellInjectorCMode2String(ws.injection_cmode);
305 from = WellProducerCMode2String(ws.production_cmode);
307 const bool oscillating =
308 std::ranges::count(this->well_control_log_, from) >= this->param_.max_number_of_well_switches_;
310 if (oscillating || this->wellUnderZeroRateTarget(groupStateHelper) || !(well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
314 const Scalar sgn = this->isInjector() ? 1.0 : -1.0;
315 if (!this->wellIsStopped()){
316 if (wqTotal*sgn <= 0.0 && !fixed_status){
320 bool changed =
false;
321 if (!fixed_control) {
324 if (solving_with_zero_rate) {
326 "Well {}: solving_with_zero_rate should not be true when fixed_control is false",
327 this->name()), deferred_logger);
333 const bool hasGroupControl = this->isInjector() ? inj_controls.hasControl(Well::InjectorCMode::GRUP) :
334 prod_controls.hasControl(Well::ProducerCMode::GRUP);
335 bool isGroupControl = ws.production_cmode == Well::ProducerCMode::GRUP || ws.injection_cmode == Well::InjectorCMode::GRUP;
336 if (! (isGroupControl && !this->param_.check_group_constraints_inner_well_iterations_)) {
337 changed = this->checkIndividualConstraints(ws, summary_state, deferred_logger, inj_controls, prod_controls);
339 if (hasGroupControl && this->param_.check_group_constraints_inner_well_iterations_) {
340 changed = changed || this->checkGroupConstraints(
341 groupStateHelper, schedule, summary_state,
false, well_state
346 const bool thp_controlled = this->isInjector() ? ws.injection_cmode == Well::InjectorCMode::THP :
347 ws.production_cmode == Well::ProducerCMode::THP;
349 ws.thp = this->getTHPConstraint(summary_state);
352 updateWellStateWithTarget(simulator, groupStateHelper, well_state);
354 updatePrimaryVariables(groupStateHelper);
359 }
else if (!fixed_status){
361 const Scalar bhp = well_state.
well(this->index_of_well_).bhp;
362 Scalar prod_limit = prod_controls.bhp_limit;
363 Scalar inj_limit = inj_controls.bhp_limit;
364 const bool has_thp = this->wellHasTHPConstraints(summary_state);
366 std::vector<Scalar> rates(this->num_conservation_quantities_);
367 if (this->isInjector()){
369 calculateBhpFromThp(well_state, rates,
372 this->getRefDensity(),
374 inj_limit = std::min(bhp_thp,
static_cast<Scalar>(inj_controls.bhp_limit));
379 calculateMinimumBhpFromThp(well_state,
382 this->getRefDensity());
383 prod_limit = std::max(bhp_min,
static_cast<Scalar>(prod_controls.bhp_limit));
386 const Scalar bhp_diff = (this->isInjector())? inj_limit - bhp: bhp - prod_limit;
389 well_state.
well(this->index_of_well_).bhp = (this->isInjector())? inj_limit : prod_limit;
391 well_state.
well(this->index_of_well_).thp = this->getTHPConstraint(summary_state);
402 template<
typename TypeTag>
406 const double simulation_time,
409 WellTestState& well_test_state,
411 std::map<std::string, double>& open_times)
415 const auto& group_state = groupStateHelper.
groupState();
416 deferred_logger.info(
" well " + this->name() +
" is being tested");
423 auto guard = groupStateHelper_copy.
pushWellState(well_state_copy);
424 auto& ws = well_state_copy.
well(this->indexOfWell());
426 const auto& summary_state = simulator.vanguard().summaryState();
427 const bool has_thp_limit = this->wellHasTHPConstraints(summary_state);
428 if (this->isProducer()) {
429 ws.production_cmode = has_thp_limit ? Well::ProducerCMode::THP : Well::ProducerCMode::BHP;
431 ws.injection_cmode = has_thp_limit ? Well::InjectorCMode::THP : Well::InjectorCMode::BHP;
436 scaleSegmentRatesAndPressure(well_state_copy);
437 calculateExplicitQuantities(simulator, groupStateHelper_copy);
438 updatePrimaryVariables(groupStateHelper_copy);
440 if (this->isProducer()) {
441 const auto& schedule = simulator.vanguard().schedule();
442 const auto report_step = simulator.episodeIndex();
443 const auto& glo = schedule.glo(report_step);
445 gliftBeginTimeStepWellTestUpdateALQ(simulator,
453 WellTestState welltest_state_temp;
455 bool testWell =
true;
460 const std::size_t original_number_closed_completions = welltest_state_temp.num_closed_completions();
461 bool converged = solveWellForTesting(simulator, groupStateHelper_copy, well_state_copy);
463 const auto msg = fmt::format(
"WTEST: Well {} is not solvable (physical)", this->name());
464 deferred_logger.debug(msg);
469 updateWellOperability(simulator, well_state_copy, groupStateHelper_copy);
470 if ( !this->isOperableAndSolvable() ) {
471 const auto msg = fmt::format(
"WTEST: Well {} is not operable (physical)", this->name());
472 deferred_logger.debug(msg);
475 std::vector<Scalar> potentials;
477 computeWellPotentials(simulator, well_state_copy, groupStateHelper_copy, potentials);
478 }
catch (
const std::exception& e) {
479 const std::string msg = fmt::format(
"well {}: computeWellPotentials() "
480 "failed during testing for re-opening: ",
481 this->name(), e.what());
482 deferred_logger.info(msg);
485 const int np = well_state_copy.
numPhases();
486 for (
int p = 0; p < np; ++p) {
487 ws.well_potentials[p] = std::max(
Scalar{0.0}, potentials[p]);
489 const bool under_zero_target = this->wellUnderZeroGroupRateTarget(groupStateHelper_copy);
490 this->updateWellTestState(well_state_copy.
well(this->indexOfWell()),
496 this->closeCompletions(welltest_state_temp);
502 if ( welltest_state_temp.num_closed_wells() > 0 ||
503 (original_number_closed_completions == welltest_state_temp.num_closed_completions()) ) {
509 if (!welltest_state_temp.well_is_closed(this->name())) {
510 well_test_state.open_well(this->name());
512 std::string msg = std::string(
"well ") + this->name() + std::string(
" is re-opened");
513 deferred_logger.info(msg);
516 for (
const auto& completion : this->well_ecl_.getCompletions()) {
517 if (!welltest_state_temp.completion_is_closed(this->name(), completion.first))
518 well_test_state.open_completion(this->name(), completion.first);
520 well_state = well_state_copy;
521 open_times.try_emplace(this->name(), well_test_state.lastTestTime(this->name()));
528 template<
typename TypeTag>
539 const auto& summary_state = simulator.vanguard().summaryState();
540 const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
541 const auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
542 const auto& ws = well_state.
well(this->indexOfWell());
543 const auto pmode_orig = ws.production_cmode;
544 const auto imode_orig = ws.injection_cmode;
545 bool converged =
false;
548 if (!this->param_.local_well_solver_control_switching_){
549 converged = this->iterateWellEqWithControl(simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state);
551 if (this->param_.use_implicit_ipr_ && this->well_ecl_.isProducer() && (well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
552 converged = solveWellWithOperabilityCheck(
553 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state
556 converged = this->iterateWellEqWithSwitching(
557 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
563 }
catch (NumericalProblem& e ) {
564 const std::string msg =
"Inner well iterations failed for well " + this->name() +
" Treat the well as unconverged. ";
565 deferred_logger.warning(
"INNER_ITERATION_FAILED", msg);
570 if (ws.production_cmode != pmode_orig || ws.injection_cmode != imode_orig) {
572 if (this->isInjector()) {
573 from = WellInjectorCMode2String(imode_orig);
574 to = WellInjectorCMode2String(ws.injection_cmode);
576 from = WellProducerCMode2String(pmode_orig);
577 to = WellProducerCMode2String(ws.production_cmode);
579 const auto msg = fmt::format(
" Well {} switched from {} to {} during local solve", this->name(), from, to);
580 deferred_logger.debug(msg);
581 const int episodeIdx = simulator.episodeIndex();
582 const auto& iterCtx = simulator.problem().iterationContext();
583 const auto& schedule = simulator.vanguard().schedule();
584 const int nupcol = schedule[episodeIdx].nupcol();
588 if (!iterCtx.withinNupcol(nupcol) || this->well_control_log_.empty()) {
589 this->well_control_log_.push_back(from);
597 template<
typename TypeTag>
602 const Well::InjectionControls& inj_controls,
603 const Well::ProductionControls& prod_controls,
610 const auto& summary_state = simulator.vanguard().summaryState();
611 bool converged =
true;
612 auto& ws = well_state.
well(this->index_of_well_);
614 if (this->wellIsStopped()) {
616 const bool use_vfpexplicit = this->operability_status_.use_vfpexplicit;
617 this->operability_status_.use_vfpexplicit =
true;
618 auto bhp_target = estimateOperableBhp(simulator, dt, groupStateHelper, summary_state, well_state);
619 if (!bhp_target.has_value()) {
621 const auto msg = fmt::format(
"estimateOperableBhp: Did not find operable BHP for well {}", this->name());
622 deferred_logger.debug(msg);
625 converged = solveWellWithZeroRate(simulator, dt, groupStateHelper, well_state);
627 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
628 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
632 ws.thp = this->getTHPConstraint(summary_state);
633 const Scalar bhp = std::max(bhp_target.value(),
634 static_cast<Scalar>(prod_controls.bhp_limit));
635 solveWellWithBhp(simulator, dt, bhp, groupStateHelper, well_state);
636 this->operability_status_.use_vfpexplicit = use_vfpexplicit;
640 converged = this->iterateWellEqWithSwitching(
641 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
646 const bool isThp = ws.production_cmode == Well::ProducerCMode::THP;
648 if (converged && !stoppedOrZeroRateTarget(groupStateHelper) && isThp) {
649 auto rates = well_state.
well(this->index_of_well_).surface_rates;
650 this->adaptRatesForVFP(rates);
651 this->updateIPRImplicit(simulator, groupStateHelper, well_state);
655 this->operability_status_.use_vfpexplicit =
true;
658 const Scalar reltol = 1e-3;
659 const Scalar cur_bhp = ws.bhp;
660 if (bhp_stable.has_value() && cur_bhp - bhp_stable.value() > cur_bhp*reltol){
661 const auto msg = fmt::format(
"Well {} converged to an unstable solution, re-solving", this->name());
662 deferred_logger.debug(msg);
664 simulator, dt, bhp_stable.value(), groupStateHelper, well_state
667 ws.thp = this->getTHPConstraint(summary_state);
668 converged = this->iterateWellEqWithSwitching(
669 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
678 this->operability_status_.use_vfpexplicit =
true;
680 auto bhp_target = estimateOperableBhp(
681 simulator, dt, groupStateHelper, summary_state, well_state
683 if (!bhp_target.has_value()) {
686 converged = solveWellWithZeroRate(simulator, dt, groupStateHelper, well_state);
688 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
689 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
693 const Scalar bhp = std::max(bhp_target.value(),
694 static_cast<Scalar>(prod_controls.bhp_limit));
696 simulator, dt, bhp, groupStateHelper, well_state
698 ws.thp = this->getTHPConstraint(summary_state);
699 const auto msg = fmt::format(
"Well {} did not converge, re-solving with explicit fractions for VFP caculations.", this->name());
700 deferred_logger.debug(msg);
701 converged = this->iterateWellEqWithSwitching(simulator, dt,
712 this->operability_status_.can_obtain_bhp_with_thp_limit = !this->wellIsStopped();
713 this->operability_status_.obey_thp_limit_under_bhp_limit = !this->wellIsStopped();
717 template<
typename TypeTag>
718 std::optional<typename WellInterface<TypeTag>::Scalar>
723 const SummaryState& summary_state,
726 if (!this->wellHasTHPConstraints(summary_state)) {
728 const bool converged = solveWellWithBhp(
729 simulator, dt, bhp_limit, groupStateHelper, well_state
731 if (!converged || this->wellIsStopped()) {
742 const bool converged = solveWellWithBhp(
743 simulator, dt, bhp_min, groupStateHelper, well_state
745 if (!converged || this->wellIsStopped()) {
748 this->updateIPRImplicit(simulator, groupStateHelper, well_state);
749 auto rates = well_state.
well(this->index_of_well_).surface_rates;
750 this->adaptRatesForVFP(rates);
754 template<
typename TypeTag>
771 auto group_guard = groupStateHelper_copy.
pushGroupState(group_state);
773 auto inj_controls = Well::InjectionControls(0);
774 auto prod_controls = Well::ProductionControls(0);
775 auto& ws = well_state.
well(this->index_of_well_);
776 auto cmode_inj = ws.injection_cmode;
777 auto cmode_prod = ws.production_cmode;
778 if (this->isInjector()) {
779 inj_controls.addControl(Well::InjectorCMode::BHP);
780 inj_controls.bhp_limit = bhp;
781 inj_controls.cmode = Well::InjectorCMode::BHP;
782 ws.injection_cmode = Well::InjectorCMode::BHP;
784 prod_controls.addControl(Well::ProducerCMode::BHP);
785 prod_controls.bhp_limit = bhp;
786 prod_controls.cmode = Well::ProducerCMode::BHP;
787 ws.production_cmode = Well::ProducerCMode::BHP;
792 const bool converged = this->iterateWellEqWithSwitching(
793 simulator, dt, inj_controls, prod_controls, groupStateHelper_copy,
799 ws.injection_cmode = cmode_inj;
800 ws.production_cmode = cmode_prod;
804 template<
typename TypeTag>
815 const auto well_status_orig = this->wellStatus_;
818 auto inj_controls = Well::InjectionControls(0);
819 auto prod_controls = Well::ProductionControls(0);
824 const bool converged = this->iterateWellEqWithSwitching(
825 simulator, dt, inj_controls, prod_controls,
832 this->wellStatus_ = well_status_orig;
836 template<
typename TypeTag>
846 const double dt = simulator.timeStepSize();
848 const auto& summary_state = simulator.vanguard().summaryState();
849 auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
850 auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
851 this->onlyKeepBHPandTHPcontrols(summary_state, well_state, inj_controls, prod_controls);
853 bool converged =
false;
856 if (!this->param_.local_well_solver_control_switching_){
857 converged = this->iterateWellEqWithControl(
858 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state
861 if (this->param_.use_implicit_ipr_ && this->well_ecl_.isProducer() && (well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
862 converged = this->solveWellWithOperabilityCheck(
863 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state
866 converged = this->iterateWellEqWithSwitching(
867 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
875 }
catch (NumericalProblem& e ) {
876 const std::string msg =
"Inner well iterations failed for well " + this->name() +
" Treat the well as unconverged. ";
877 deferred_logger.warning(
"INNER_ITERATION_FAILED", msg);
882 deferred_logger.debug(
"WellTest: Well equation for well " + this->name() +
" converged");
885 const int max_iter = this->param_.max_welleq_iter_;
886 deferred_logger.debug(
"WellTest: Well equation for well " + this->name() +
" failed converging in "
892 template<
typename TypeTag>
901 if (!this->isOperableAndSolvable() && !this->wellIsStopped())
906 const double dt = simulator.timeStepSize();
907 bool converged = iterateWellEquations(simulator, dt, groupStateHelper, well_state);
917 auto& ws = well_state.
well(this->indexOfWell());
918 bool thp_control =
false;
919 if (this->well_ecl_.isInjector()) {
920 thp_control = ws.injection_cmode == Well::InjectorCMode::THP;
922 ws.injection_cmode = Well::InjectorCMode::BHP;
923 if (this->well_control_log_.empty()) {
924 this->well_control_log_.push_back(WellInjectorCMode2String(Well::InjectorCMode::THP));
928 thp_control = ws.production_cmode == Well::ProducerCMode::THP;
930 ws.production_cmode = Well::ProducerCMode::BHP;
931 if (this->well_control_log_.empty()) {
932 this->well_control_log_.push_back(WellProducerCMode2String(Well::ProducerCMode::THP));
937 const std::string msg = std::string(
"The newly opened well ") + this->name()
938 + std::string(
" with THP control did not converge during inner iterations, we try again with bhp control");
939 deferred_logger.debug(msg);
940 converged = this->iterateWellEquations(simulator, dt, groupStateHelper, well_state);
945 const int max_iter = this->param_.max_welleq_iter_;
946 deferred_logger.debug(
"Compute initial well solution for well " + this->name() +
". Failed to converge in "
948 well_state = well_state0;
954 template <
typename TypeTag>
963 prepareWellBeforeAssembling(simulator, dt, groupStateHelper, well_state);
964 assembleWellEqWithoutIteration(simulator, groupStateHelper, dt, well_state,
970 template <
typename TypeTag>
977 const bool solving_with_zero_rate)
980 const auto& summary_state = simulator.vanguard().summaryState();
981 const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
982 const auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
985 assembleWellEqWithoutIteration(simulator, groupStateHelper, dt, inj_controls, prod_controls, well_state, solving_with_zero_rate);
990 template<
typename TypeTag>
1000 const bool old_well_operable = this->operability_status_.isOperableAndSolvable();
1002 if (this->param_.check_well_operability_iter_)
1003 checkWellOperability(simulator, well_state, groupStateHelper);
1006 const auto& iterCtx = simulator.problem().iterationContext();
1007 if (iterCtx.shouldRunInnerWellIterations(this->param_.max_niter_inner_well_iter_)) {
1008 const auto& ws = well_state.
well(this->indexOfWell());
1009 const bool nonzero_rate_original =
1010 std::any_of(ws.surface_rates.begin(),
1011 ws.surface_rates.begin() + well_state.
numPhases(),
1012 [](
Scalar rate) { return rate != Scalar(0.0); });
1014 this->operability_status_.solvable =
true;
1015 if (number_of_well_reopenings_ >= this->param_.max_well_status_switch_) {
1017 if (number_of_well_reopenings_ == this->param_.max_well_status_switch_) {
1018 const std::string msg = fmt::format(
"well {} is oscillating between open and stop. \n"
1019 "We don't allow for more than {} re-openings "
1020 "and the well is therefore kept stopped.",
1021 this->name(), number_of_well_reopenings_);
1022 deferred_logger.debug(msg);
1025 changed_to_stopped_this_step_ =
true;
1026 bool converged_zero_rate = this->solveWellWithZeroRate(
1027 simulator, dt, groupStateHelper, well_state
1029 if (this->param_.shut_unsolvable_wells_ && !converged_zero_rate ) {
1030 this->operability_status_.solvable =
false;
1033 number_of_well_reopenings_++;
1036 bool converged = this->iterateWellEquations(
1037 simulator, dt, groupStateHelper, well_state
1041 const bool zero_target = this->wellUnderZeroRateTarget(groupStateHelper);
1042 if (this->wellIsStopped() && !zero_target && nonzero_rate_original) {
1046 this->operability_status_.resetOperability();
1048 deferred_logger.debug(
" " + this->name() +
" is re-opened after being stopped during local solve");
1049 number_of_well_reopenings_++;
1053 if (this->param_.shut_unsolvable_wells_) {
1054 this->operability_status_.solvable =
false;
1058 if (this->operability_status_.has_negative_potentials) {
1059 auto well_state_copy = well_state;
1060 std::vector<Scalar> potentials;
1062 computeWellPotentials(simulator, well_state_copy, groupStateHelper, potentials);
1063 }
catch (
const std::exception& e) {
1064 const std::string msg = fmt::format(
"well {}: computeWellPotentials() failed "
1065 "during attempt to recompute potentials for well: ",
1066 this->name(), e.what());
1067 deferred_logger.info(msg);
1068 this->operability_status_.has_negative_potentials =
true;
1070 auto& ws = well_state.
well(this->indexOfWell());
1072 for (
int p = 0; p < np; ++p) {
1073 ws.well_potentials[p] = std::max(
Scalar{0.0}, potentials[p]);
1076 this->changed_to_open_this_step_ =
false;
1077 changed_to_stopped_this_step_ =
false;
1079 const bool well_operable = this->operability_status_.isOperableAndSolvable();
1080 if (!well_operable) {
1083 this->solveWellWithZeroRate(
1084 simulator, dt, groupStateHelper, well_state
1086 }
catch (
const std::exception& e) {
1087 const std::string msg = fmt::format(
"well {}: solveWellWithZeroRate() failed "
1088 "during attempt to solve with zero rate for well: ",
1089 this->name(), e.what());
1090 deferred_logger.info(msg);
1092 auto& ws = well_state.
well(this->indexOfWell());
1094 for (
int p = 0; p < np; ++p) {
1095 ws.surface_rates[p] =
Scalar{0.0};
1098 if (old_well_operable) {
1099 const std::string ctx = iterCtx.inLocalSolve() ?
" (NLDD domain solve)" :
"";
1100 deferred_logger.debug(
" well " + this->name() +
" gets STOPPED during iteration" + ctx);
1101 changed_to_stopped_this_step_ =
true;
1103 }
else if (well_state.
isOpen(this->name())) {
1105 if (!old_well_operable) {
1106 const std::string ctx = iterCtx.inLocalSolve() ?
" (NLDD domain solve)" :
"";
1107 deferred_logger.debug(
" well " + this->name() +
" gets REVIVED during iteration" + ctx);
1108 this->changed_to_open_this_step_ =
true;
1113 template<
typename TypeTag>
1117 if(!this->operability_status_.solvable)
1120 for (
int perfIdx = 0; perfIdx < this->number_of_local_perforations_; ++perfIdx) {
1121 const auto cellIdx = this->cells()[perfIdx];
1122 const auto it = cellRates_.find(cellIdx);
1123 RateVector rates = (it == cellRates_.end()) ? 0.0 : it->second;
1124 for (
auto i=0*RateVector::dimension; i < RateVector::dimension; ++i)
1126 rates[i] += connectionRates_[perfIdx][i];
1128 cellRates_.insert_or_assign(cellIdx, rates);
1132 template<
typename TypeTag>
1136 for (
int perfIdx = 0; perfIdx < this->number_of_local_perforations_; ++perfIdx) {
1137 if (this->cells()[perfIdx] == cellIdx) {
1138 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
1139 return connectionRates_[perfIdx][activeCompIdx].value();
1143 OPM_THROW(std::invalid_argument,
"The well with name " + this->name()
1151 template<
typename TypeTag>
1160 if (!this->param_.check_well_operability_) {
1164 if (this->wellIsStopped() && !changed_to_stopped_this_step_) {
1168 updateWellOperability(simulator, well_state, groupStateHelper);
1169 if (!this->operability_status_.isOperableAndSolvable()) {
1170 this->operability_status_.use_vfpexplicit =
true;
1171 deferred_logger.debug(
"EXPLICIT_LOOKUP_VFP",
1172 "well not operable, trying with explicit vfp lookup: " + this->name());
1173 updateWellOperability(simulator, well_state, groupStateHelper);
1179 template<
typename TypeTag>
1189 const auto& summary_state = simulator.vanguard().summaryState();
1190 const auto& well_name = this->name();
1191 if (!this->wellHasTHPConstraints(summary_state)) {
1192 const std::string msg = fmt::format(
"GLIFT WTEST: Well {} does not have THP constraints", well_name);
1193 deferred_logger.
info(msg);
1196 const auto& schedule = simulator.vanguard().schedule();
1197 const auto report_step_idx = simulator.episodeIndex();
1198 const auto& glo = schedule.glo(report_step_idx);
1199 if (!glo.has_well(well_name)) {
1200 const std::string msg = fmt::format(
1201 "GLIFT WTEST: Well {} : Gas lift not activated: "
1202 "WLIFTOPT is probably missing. Skipping.", well_name);
1203 deferred_logger.
info(msg);
1206 const auto& gl_well = glo.well(well_name);
1209 std::unique_ptr<GasLiftSingleWell> glift =
1210 initializeGliftWellTest_<GasLiftSingleWell>(simulator,
1215 auto [wtest_alq, success] = glift->wellTestALQ();
1217 const auto& unit_system = schedule.getUnits();
1219 well_state.
well(well_name).alq_state.set(wtest_alq);
1221 "GLIFT WTEST: Well {} : Setting ALQ to optimized value = {}",
1222 well_name, unit_system.from_si(UnitSystem::measure::gas_surface_rate, wtest_alq));
1225 if (!gl_well.use_glo()) {
1227 "GLIFT WTEST: Well {} : Gas lift optimization deactivated. Setting ALQ to WLIFTOPT item 3 = {}",
1229 unit_system.from_si(UnitSystem::measure::gas_surface_rate, well_state.
well(well_name).alq_state.get()));
1234 "GLIFT WTEST: Well {} : Gas lift optimization failed, no ALQ set.",
1238 deferred_logger.
info(msg);
1241 template<
typename TypeTag>
1250 if (this->param_.local_well_solver_control_switching_) {
1251 const bool success = updateWellOperabilityFromWellEq(simulator, groupStateHelper);
1253 this->operability_status_.solvable =
false;
1254 deferred_logger.debug(
"Operability check using well equations did not converge for well "
1255 + this->name() +
". Mark the well as unsolvable." );
1259 this->operability_status_.resetOperability();
1261 bool thp_controlled = this->isInjector() ? well_state.
well(this->index_of_well_).injection_cmode == Well::InjectorCMode::THP:
1262 well_state.
well(this->index_of_well_).production_cmode == Well::ProducerCMode::THP;
1263 bool bhp_controlled = this->isInjector() ? well_state.
well(this->index_of_well_).injection_cmode == Well::InjectorCMode::BHP:
1264 well_state.
well(this->index_of_well_).production_cmode == Well::ProducerCMode::BHP;
1268 bool check_thp = thp_controlled || this->operability_status_.thp_limit_violated_but_not_switched;
1269 if (check_thp || bhp_controlled) {
1270 updateIPR(simulator, deferred_logger);
1271 checkOperabilityUnderBHPLimit(well_state, simulator, deferred_logger);
1275 checkOperabilityUnderTHPLimit(simulator, well_state, groupStateHelper);
1279 template<
typename TypeTag>
1287 assert(this->param_.local_well_solver_control_switching_);
1288 this->operability_status_.resetOperability();
1291 const double dt = simulator.timeStepSize();
1295 auto guard = groupStateHelper_copy.
pushWellState(well_state_copy);
1297 bool converged = iterateWellEquations(simulator, dt, groupStateHelper_copy, well_state_copy);
1301 template<
typename TypeTag>
1309 template<
typename TypeTag>
1319 const auto& well = this->well_ecl_;
1320 const int well_index = this->index_of_well_;
1321 auto& ws = well_state.
well(well_index);
1323 const auto& summaryState = simulator.vanguard().summaryState();
1324 const auto& schedule = simulator.vanguard().schedule();
1328 ws.primaryvar.resize(0);
1330 if (this->wellIsStopped()) {
1331 for (
int p = 0; p<np; ++p) {
1332 ws.surface_rates[p] = 0;
1338 if (this->isInjector() )
1340 const auto& controls = well.injectionControls(summaryState);
1342 InjectorType injectorType = controls.injector_type;
1344 switch (injectorType) {
1345 case InjectorType::WATER:
1347 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1350 case InjectorType::OIL:
1352 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1355 case InjectorType::GAS:
1357 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1361 OPM_DEFLOG_THROW(std::runtime_error,
"Expected WATER, OIL or GAS as type for injectors " + this->name(), deferred_logger );
1364 const auto current = ws.injection_cmode;
1367 case Well::InjectorCMode::RATE:
1369 ws.surface_rates[phasePos] = (1.0 - this->rsRvInj()) * controls.surface_rate;
1370 if(this->rsRvInj() > 0) {
1371 if (injectorType == InjectorType::OIL && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1372 const int gas_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1373 ws.surface_rates[gas_pos] = controls.surface_rate * this->rsRvInj();
1374 }
else if (injectorType == InjectorType::GAS && FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1375 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1376 ws.surface_rates[oil_pos] = controls.surface_rate * this->rsRvInj();
1378 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 );
1384 case Well::InjectorCMode::RESV:
1386 std::vector<Scalar> convert_coeff(this->number_of_phases_, 1.0);
1387 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, convert_coeff);
1388 const Scalar coeff = convert_coeff[phasePos];
1389 ws.surface_rates[phasePos] = controls.reservoir_rate/coeff;
1393 case Well::InjectorCMode::THP:
1395 auto rates = ws.surface_rates;
1400 this->getRefDensity(),
1403 ws.thp = this->getTHPConstraint(summaryState);
1408 Scalar total_rate = std::accumulate(rates.begin(), rates.end(), 0.0);
1409 if (total_rate <= 0.0)
1410 ws.surface_rates = ws.well_potentials;
1414 case Well::InjectorCMode::BHP:
1416 ws.bhp = controls.bhp_limit;
1418 for (
int p = 0; p<np; ++p) {
1419 total_rate += ws.surface_rates[p];
1424 if (total_rate <= 0.0)
1425 ws.surface_rates = ws.well_potentials;
1429 case Well::InjectorCMode::GRUP:
1431 assert(well.isAvailableForGroupControl());
1432 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
1433 const Scalar efficiencyFactor = well.getEfficiencyFactor() *
1434 well_state[well.name()].efficiency_scaling_factor;
1435 std::optional<Scalar> target =
1436 this->getGroupInjectionTargetRate(group,
1441 ws.surface_rates[phasePos] = *target;
1444 case Well::InjectorCMode::CMODE_UNDEFINED:
1446 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name(), deferred_logger );
1456 ws.surface_rates[phasePos] = std::max(
Scalar{1.e-7}, ws.surface_rates[phasePos]);
1459 ws.bhp = controls.bhp_limit;
1465 const auto current = ws.production_cmode;
1466 const auto& controls = well.productionControls(summaryState);
1468 case Well::ProducerCMode::ORAT:
1470 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1471 Scalar current_rate = -ws.surface_rates[oil_pos];
1474 if (current_rate > 0.0) {
1475 for (
int p = 0; p<np; ++p) {
1476 ws.surface_rates[p] *= controls.oil_rate/current_rate;
1479 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1480 double control_fraction = fractions[oil_pos];
1481 if (control_fraction != 0.0) {
1482 for (
int p = 0; p<np; ++p) {
1483 ws.surface_rates[p] = - fractions[p] * controls.oil_rate/control_fraction;
1489 case Well::ProducerCMode::WRAT:
1491 const int water_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1492 Scalar current_rate = -ws.surface_rates[water_pos];
1495 if (current_rate > 0.0) {
1496 for (
int p = 0; p<np; ++p) {
1497 ws.surface_rates[p] *= controls.water_rate/current_rate;
1500 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1501 const Scalar control_fraction = fractions[water_pos];
1502 if (control_fraction != 0.0) {
1503 for (
int p = 0; p<np; ++p) {
1504 ws.surface_rates[p] = - fractions[p] * controls.water_rate / control_fraction;
1510 case Well::ProducerCMode::GRAT:
1512 const int gas_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1513 Scalar current_rate = -ws.surface_rates[gas_pos];
1516 if (current_rate > 0.0) {
1517 for (
int p = 0; p<np; ++p) {
1518 ws.surface_rates[p] *= controls.gas_rate/current_rate;
1521 const std::vector<Scalar > fractions = initialWellRateFractions(simulator, well_state);
1522 const Scalar control_fraction = fractions[gas_pos];
1523 if (control_fraction != 0.0) {
1524 for (
int p = 0; p<np; ++p) {
1525 ws.surface_rates[p] = - fractions[p] * controls.gas_rate / control_fraction;
1533 case Well::ProducerCMode::LRAT:
1535 const int water_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1536 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1537 Scalar current_rate = - ws.surface_rates[water_pos]
1538 - ws.surface_rates[oil_pos];
1541 if (current_rate > 0.0) {
1542 for (
int p = 0; p<np; ++p) {
1543 ws.surface_rates[p] *= controls.liquid_rate/current_rate;
1546 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1547 const Scalar control_fraction = fractions[water_pos] + fractions[oil_pos];
1548 if (control_fraction != 0.0) {
1549 for (
int p = 0; p<np; ++p) {
1550 ws.surface_rates[p] = - fractions[p] * controls.liquid_rate / control_fraction;
1556 case Well::ProducerCMode::CRAT:
1559 fmt::format(
"CRAT control not supported, well {}", this->name()),
1562 case Well::ProducerCMode::RESV:
1564 std::vector<Scalar> convert_coeff(this->number_of_phases_, 1.0);
1565 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, ws.surface_rates, convert_coeff);
1566 Scalar total_res_rate = 0.0;
1567 for (
int p = 0; p<np; ++p) {
1568 total_res_rate -= ws.surface_rates[p] * convert_coeff[p];
1570 if (controls.prediction_mode) {
1573 if (total_res_rate > 0.0) {
1574 for (
int p = 0; p<np; ++p) {
1575 ws.surface_rates[p] *= controls.resv_rate/total_res_rate;
1578 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1579 for (
int p = 0; p<np; ++p) {
1580 ws.surface_rates[p] = - fractions[p] * controls.resv_rate / convert_coeff[p];
1584 std::vector<Scalar> hrates(this->number_of_phases_,0.);
1585 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
1586 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1587 hrates[phase_pos] = controls.water_rate;
1589 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1590 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1591 hrates[phase_pos] = controls.oil_rate;
1593 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1594 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1595 hrates[phase_pos] = controls.gas_rate;
1597 std::vector<Scalar> hrates_resv(this->number_of_phases_,0.);
1598 this->rateConverter_.calcReservoirVoidageRates( 0, this->pvtRegionIdx_, hrates, hrates_resv);
1599 Scalar target = std::accumulate(hrates_resv.begin(), hrates_resv.end(), 0.0);
1602 if (total_res_rate > 0.0) {
1603 for (
int p = 0; p<np; ++p) {
1604 ws.surface_rates[p] *= target/total_res_rate;
1607 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1608 for (
int p = 0; p<np; ++p) {
1609 ws.surface_rates[p] = - fractions[p] * target / convert_coeff[p];
1615 case Well::ProducerCMode::BHP:
1617 ws.bhp = controls.bhp_limit;
1619 for (
int p = 0; p<np; ++p) {
1620 total_rate -= ws.surface_rates[p];
1625 if (total_rate <= 0.0){
1626 for (
int p = 0; p<np; ++p) {
1627 ws.surface_rates[p] = -ws.well_potentials[p];
1632 case Well::ProducerCMode::THP:
1634 const bool update_success = updateWellStateWithTHPTargetProd(simulator, well_state, groupStateHelper);
1636 if (!update_success) {
1640 auto rates = ws.surface_rates;
1641 this->adaptRatesForVFP(rates);
1643 well_state, rates, well, summaryState, this->getRefDensity(), deferred_logger);
1645 ws.thp = this->getTHPConstraint(summaryState);
1649 const Scalar total_rate = -std::accumulate(rates.begin(), rates.end(), 0.0);
1650 if (total_rate <= 0.0) {
1651 for (
int p = 0; p < this->number_of_phases_; ++p) {
1652 ws.surface_rates[p] = -ws.well_potentials[p];
1658 case Well::ProducerCMode::GRUP:
1660 assert(well.isAvailableForGroupControl());
1661 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
1662 const Scalar efficiencyFactor = well.getEfficiencyFactor() *
1663 well_state[well.name()].efficiency_scaling_factor;
1664 Scalar scale = this->getGroupProductionTargetRate(group,
1670 for (
int p = 0; p<np; ++p) {
1671 ws.surface_rates[p] *= scale;
1673 ws.trivial_group_target =
false;
1677 ws.trivial_group_target =
true;
1681 case Well::ProducerCMode::CMODE_UNDEFINED:
1684 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name() , deferred_logger);
1690 ws.bhp = controls.bhp_limit;
1695 template<
typename TypeTag>
1701 const auto& well_state = groupStateHelper.
wellState();
1703 const bool isGroupControlled = this->wellUnderGroupControl(well_state.well(this->index_of_well_));
1704 if (!isGroupControlled) {
1706 const auto& summaryState = groupStateHelper.
summaryState();
1707 return this->wellUnderZeroRateTargetIndividual(summaryState, well_state);
1709 return this->wellUnderZeroGroupRateTarget(groupStateHelper, isGroupControlled);
1713 template <
typename TypeTag>
1716 const std::optional<bool> group_control)
const
1718 const auto& well_state = groupStateHelper.
wellState();
1720 const bool isGroupControlled = group_control.value_or(this->wellUnderGroupControl(well_state.well(this->index_of_well_)));
1721 if (isGroupControlled) {
1722 return this->zeroGroupRateTarget(groupStateHelper);
1727 template<
typename TypeTag>
1734 return this->wellIsStopped()
1735 || this->wellUnderZeroRateTarget(groupStateHelper);
1738 template<
typename TypeTag>
1739 std::vector<typename WellInterface<TypeTag>::Scalar>
1745 const int np = this->number_of_phases_;
1746 std::vector<Scalar> scaling_factor(np);
1747 const auto& ws = well_state.
well(this->index_of_well_);
1749 Scalar total_potentials = 0.0;
1750 for (
int p = 0; p<np; ++p) {
1751 total_potentials += ws.well_potentials[p];
1753 if (total_potentials > 0) {
1754 for (
int p = 0; p<np; ++p) {
1755 scaling_factor[p] = ws.well_potentials[p] / total_potentials;
1757 return scaling_factor;
1762 const int nperf = this->number_of_local_perforations_;
1763 for (
int perf = 0; perf < nperf; ++perf) {
1764 total_tw += this->well_index_[perf];
1766 total_tw = this->parallelWellInfo().communication().sum(total_tw);
1768 for (
int perf = 0; perf < nperf; ++perf) {
1769 const int cell_idx = this->well_cells_[perf];
1770 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
1771 const auto& fs = intQuants.fluidState();
1772 const Scalar well_tw_fraction = this->well_index_[perf] / total_tw;
1773 Scalar total_mobility = 0.0;
1774 for (
int p = 0; p < np; ++p) {
1775 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
1776 total_mobility += fs.invB(canonical_phase_idx).value() * intQuants.mobility(canonical_phase_idx).value();
1778 for (
int p = 0; p < np; ++p) {
1779 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
1780 scaling_factor[p] += well_tw_fraction * fs.invB(canonical_phase_idx).value() * intQuants.mobility(canonical_phase_idx).value() / total_mobility;
1783 return scaling_factor;
1788 template <
typename TypeTag>
1795 assert(this->isProducer());
1799 auto& ws = well_state.
well(this->index_of_well_);
1800 int nonzero_rate_index = -1;
1801 const Scalar floating_point_error_epsilon = 1e-14;
1802 for (
int p = 0; p < this->number_of_phases_; ++p) {
1803 if (std::abs(ws.surface_rates[p]) > floating_point_error_epsilon) {
1804 if (nonzero_rate_index == -1) {
1805 nonzero_rate_index = p;
1814 std::vector<Scalar> well_q_s(this->number_of_phases_, 0.0);
1815 bool rates_evaluated_at_1bar =
false;
1817 const auto& summary_state = simulator.vanguard().summaryState();
1818 const auto& prod_controls = this->well_ecl_.productionControls(summary_state);
1819 const double bhp_limit = std::max(prod_controls.bhp_limit, 1.0 * unit::barsa);
1820 this->computeWellRatesWithBhp(simulator, bhp_limit, well_q_s, deferred_logger);
1822 rates_evaluated_at_1bar = (bhp_limit < 1.1 * unit::barsa);
1824 if (std::ranges::any_of(well_q_s, [](
Scalar q) {
return q > 0.0; })) {
1826 if (!rates_evaluated_at_1bar) {
1827 this->computeWellRatesWithBhp(simulator, 1.0 * unit::barsa, well_q_s, deferred_logger);
1828 rates_evaluated_at_1bar =
true;
1831 for (
auto& q : well_q_s) {
1832 q = std::min(q,
Scalar{0.0});
1837 if (nonzero_rate_index == -1) {
1841 const Scalar factor = rates_evaluated_at_1bar ? 0.5 : 1.0;
1842 for (
int p = 0; p < this->number_of_phases_; ++p) {
1843 ws.surface_rates[p] = factor * well_q_s[p];
1852 const Scalar initial_nonzero_rate = ws.surface_rates[nonzero_rate_index];
1853 const Scalar computed_rate = well_q_s[nonzero_rate_index];
1854 if (std::abs(initial_nonzero_rate) < std::abs(computed_rate)) {
1856 const Scalar factor = initial_nonzero_rate / computed_rate;
1857 assert(factor < 1.0);
1858 for (
int p = 0; p < this->number_of_phases_; ++p) {
1860 if (p != nonzero_rate_index) {
1861 ws.surface_rates[p] = factor * well_q_s[p];
1870 for (
int p = 0; p < this->number_of_phases_; ++p) {
1871 ws.surface_rates[p] = well_q_s[p];
1875 template <
typename TypeTag>
1876 template<
class Value>
1879 getTw(std::vector<Value>& Tw,
1882 const Value& trans_mult,
1885 OPM_TIMEFUNCTION_LOCAL(Subsystem::Wells);
1888 if (
static_cast<std::size_t
>(perf) >= this->well_cells_.size()) {
1889 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!");
1892 if constexpr (! Indices::gasEnabled) {
1896 const auto& wdfac = this->well_ecl_.getWDFAC();
1898 if (! wdfac.useDFactor() || (this->well_index_[perf] == 0.0)) {
1902 const Scalar d = this->computeConnectionDFactor(perf, intQuants, ws);
1909 const auto& connection = this->well_ecl_.getConnections()[ws.
perf_data.ecl_index[perf]];
1910 const Scalar Kh = connection.Kh();
1911 const Scalar scaling = 3.141592653589 * Kh * connection.wpimult();
1912 const unsigned gas_comp_idx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
1915 const Scalar cell_pressure = getValue(intQuants.fluidState().pressure(FluidSystem::gasPhaseIdx));
1916 const Scalar drawdown = cell_pressure - connection_pressure;
1917 const Scalar invB = getValue(intQuants.fluidState().invB(FluidSystem::gasPhaseIdx));
1918 const Scalar mob_g = getValue(intQuants.mobility(FluidSystem::gasPhaseIdx)) * invB;
1920 const Scalar b = 2 * scaling / getValue(Tw[gas_comp_idx]);
1921 const Scalar c = -2 * scaling * mob_g * drawdown;
1923 Scalar consistent_Q = -1.0e20;
1925 const Scalar r2n = b*b + 4*a*c;
1927 const Scalar rn = std::sqrt(r2n);
1928 const Scalar xn1 = (b-rn)*0.5/a;
1932 const Scalar xn2 = (b+rn)*0.5/a;
1933 if (xn2 <= 0 && xn2 > consistent_Q) {
1939 const Scalar r2p = b*b - 4*a*c;
1941 const Scalar rp = std::sqrt(r2p);
1942 const Scalar xp1 = (rp-b)*0.5/a;
1943 if (xp1 > 0 && xp1 < consistent_Q) {
1946 const Scalar xp2 = -(rp+b)*0.5/a;
1947 if (xp2 > 0 && xp2 < consistent_Q) {
1951 Tw[gas_comp_idx] = 1.0 / (1.0 / (trans_mult * this->well_index_[perf]) + (consistent_Q/2 * d / scaling));
1954 template <
typename TypeTag>
1960 if (! this->well_ecl_.getWDFAC().useDFactor()) {
1964 auto& d_factor = ws.
perf_data.connection_d_factor;
1966 for (
int perf = 0; perf < this->number_of_local_perforations_; ++perf) {
1967 const int cell_idx = this->well_cells_[perf];
1968 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
1970 d_factor[perf] = this->computeConnectionDFactor(perf, intQuants, ws);
1974 template <
typename TypeTag>
1981 auto rhoGS = [regIdx = this->pvtRegionIdx()]() {
1982 return FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, regIdx);
1986 auto gas_visc = [connection_pressure = ws.
perf_data.pressure[perf],
1988 regIdx = this->pvtRegionIdx(), &intQuants]()
1990 const auto rv = getValue(intQuants.fluidState().Rv());
1992 const auto& gasPvt = FluidSystem::gasPvt();
1997 const Scalar rv_sat = gasPvt.saturatedOilVaporizationFactor
1998 (regIdx, temperature, connection_pressure);
2000 if (! (rv < rv_sat)) {
2001 return gasPvt.saturatedViscosity(regIdx, temperature,
2002 connection_pressure);
2005 return gasPvt.viscosity(regIdx, temperature, connection_pressure,
2006 rv, getValue(intQuants.fluidState().Rvw()));
2009 const auto& connection = this->well_ecl_.getConnections()
2012 return this->well_ecl_.getWDFAC().getDFactor(rhoGS, gas_visc, connection);
2016 template <
typename TypeTag>
2022 auto connCF = [&connIx = std::as_const(ws.
perf_data.ecl_index),
2023 &conns = this->well_ecl_.getConnections()]
2026 return conns[connIx[perf]].CF();
2029 auto obtain = [](
const Eval& value)
2031 return getValue(value);
2034 auto& tmult = ws.
perf_data.connection_compaction_tmult;
2035 auto& ctf = ws.
perf_data.connection_transmissibility_factor;
2037 for (
int perf = 0; perf < this->number_of_local_perforations_; ++perf) {
2038 const int cell_idx = this->well_cells_[perf];
2040 getTransMult(trans_mult, simulator, cell_idx, obtain);
2041 tmult[perf] = trans_mult;
2043 ctf[perf] = connCF(perf) * tmult[perf];
2048 template<
typename TypeTag>
2052 if constexpr (Indices::oilEnabled) {
2053 return fs.pressure(FluidSystem::oilPhaseIdx);
2054 }
else if constexpr (Indices::gasEnabled) {
2055 return fs.pressure(FluidSystem::gasPhaseIdx);
2057 return fs.pressure(FluidSystem::waterPhaseIdx);
2061 template <
typename TypeTag>
2062 template<
class Value,
class Callback>
2068 Callback& extendEval)
const
2070 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2071 trans_mult = simulator.problem().template wellTransMultiplier<Value>(intQuants, cell_idx, extendEval);
2074 template <
typename TypeTag>
2075 template<
class Value,
class Callback>
2079 const int local_perf_index,
2080 std::vector<Value>& mob,
2081 Callback& extendEval,
2084 auto relpermArray = []()
2086 if constexpr (std::is_same_v<Value, Scalar>) {
2087 return std::array<Scalar,3>{};
2089 return std::array<Eval,3>{};
2092 if (
static_cast<std::size_t
>(local_perf_index) >= this->well_cells_.size()) {
2093 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!");
2095 const int cell_idx = this->well_cells_[local_perf_index];
2096 assert (
int(mob.size()) == this->num_conservation_quantities_);
2097 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2098 const auto& materialLawManager = simulator.problem().materialLawManager();
2102 const int satid = this->saturation_table_number_[local_perf_index] - 1;
2103 const int satid_elem = materialLawManager->satnumRegionIdx(cell_idx);
2104 if (satid == satid_elem) {
2105 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2106 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2110 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2111 mob[activeCompIdx] = extendEval(intQuants.mobility(phaseIdx));
2113 if constexpr (has_solvent) {
2114 mob[Indices::contiSolventEqIdx] = extendEval(intQuants.solventMobility());
2117 const auto& paramsCell = materialLawManager->connectionMaterialLawParams(satid, cell_idx);
2118 auto relativePerms = relpermArray();
2119 MaterialLaw::relativePermeabilities(relativePerms, paramsCell, intQuants.fluidState());
2122 materialLawManager->connectionMaterialLawParams(satid_elem, cell_idx);
2125 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2126 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2130 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2131 mob[activeCompIdx] = extendEval(relativePerms[phaseIdx] / intQuants.fluidState().viscosity(phaseIdx));
2134 if constexpr (has_solvent) {
2135 const auto Fsolgas = intQuants.solventSaturation() / (intQuants.solventSaturation() + intQuants.fluidState().saturation(FluidSystem::gasPhaseIdx));
2137 if (Fsolgas > SolventModule::cutOff) {
2138 const unsigned activeGasCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(FluidSystem::gasPhaseIdx));
2139 const auto& ssfnKrg = SolventModule::ssfnKrg(satid);
2140 const auto& ssfnKrs = SolventModule::ssfnKrs(satid);
2141 mob[activeGasCompIdx] *= extendEval(ssfnKrg.eval(1-Fsolgas,
true));
2142 mob[Indices::contiSolventEqIdx] = extendEval(ssfnKrs.eval(Fsolgas,
true) * relativePerms[activeGasCompIdx] / intQuants.solventViscosity());
2147 if (this->isInjector() && !this->inj_fc_multiplier_.empty()) {
2148 const auto perf_ecl_index = this->perforationData()[local_perf_index].ecl_index;
2149 const auto& connections = this->well_ecl_.getConnections();
2150 const auto& connection = connections[perf_ecl_index];
2151 if (connection.filterCakeActive()) {
2152 std::ranges::transform(mob, mob.begin(),
2153 [mult = this->inj_fc_multiplier_[local_perf_index]]
2155 { return val * mult; });
2161 template<
typename TypeTag>
2170 const auto& summary_state = simulator.vanguard().summaryState();
2172 auto bhp_at_thp_limit = computeBhpAtThpLimitProdWithAlq(
2173 simulator, groupStateHelper, summary_state, this->getALQ(well_state),
false);
2174 if (bhp_at_thp_limit) {
2175 std::vector<Scalar> rates(this->number_of_phases_, 0.0);
2176 if (thp_update_iterations) {
2177 computeWellRatesWithBhpIterations(simulator, *bhp_at_thp_limit,
2178 groupStateHelper, rates);
2180 computeWellRatesWithBhp(simulator, *bhp_at_thp_limit,
2181 rates, deferred_logger);
2183 auto& ws = well_state.
well(this->name());
2184 ws.surface_rates = rates;
2185 ws.bhp = *bhp_at_thp_limit;
2186 ws.thp = this->getTHPConstraint(summary_state);
2193 template<
typename TypeTag>
2194 std::optional<typename WellInterface<TypeTag>::Scalar>
2199 const SummaryState& summary_state,
2204 const auto& groupStateHelper = simulator.problem().wellModel().groupStateHelper();
2206 auto well_guard = groupStateHelper_copy.
pushWellState(well_state_copy);
2207 const double dt = simulator.timeStepSize();
2208 const bool converged = this->solveWellWithBhp(
2209 simulator, dt, bhp, groupStateHelper_copy, well_state_copy
2213 auto rates = well_state_copy.
well(this->index_of_well_).surface_rates;
2215 for (std::size_t p = 0; p < rates.size(); ++p) {
2216 zero_rates &= rates[p] == 0.0;
2220 if (zero_rates || !converged) {
2221 return this->computeBhpAtThpLimitProdWithAlq(simulator, groupStateHelper_copy, summary_state, alq_value,
false);
2223 this->updateIPRImplicit(simulator, groupStateHelper_copy, well_state_copy);
2224 this->adaptRatesForVFP(rates);
2228 template <
typename TypeTag>
2233 const std::vector<Scalar>& mobility,
2236 const int np = this->number_of_phases_;
2237 for (
int p = 0; p < np; ++p) {
2240 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
2241 const auto connMob =
2242 mobility[FluidSystem::activePhaseToActiveCompIdx(p)] * fs.invB(canonical_phase_idx).value();
2244 connPI[p] = connPICalc(connMob);
2247 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) &&
2248 FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx))
2250 const auto io = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
2251 const auto ig = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
2253 const auto vapoil = connPI[ig] * fs.Rv().value();
2254 const auto disgas = connPI[io] * fs.Rs().value();
2256 connPI[io] += vapoil;
2257 connPI[ig] += disgas;
2262 template <
typename TypeTag>
2266 const Phase preferred_phase,
2268 const std::vector<Scalar>& mobility,
2273 if (preferred_phase == Phase::GAS) {
2274 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
2276 else if (preferred_phase == Phase::OIL) {
2277 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
2279 else if (preferred_phase == Phase::WATER) {
2280 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
2284 fmt::format(
"Unsupported Injector Type ({}) "
2285 "for well {} during connection I.I. calculation",
2286 static_cast<int>(preferred_phase), this->name()),
2290 const auto mt = std::accumulate(mobility.begin(), mobility.end(), 0.0);
2291 const int canonicalPhaseIdx = FluidSystem::activeToCanonicalPhaseIdx(phase_pos);
2292 connII[phase_pos] = connIICalc(mt * fs.invB(canonicalPhaseIdx).value());
2295 template<
typename TypeTag>
2296 template<
class GasLiftSingleWell>
2297 std::unique_ptr<GasLiftSingleWell>
2306 auto& comm = simulator.vanguard().grid().comm();
2307 ecl_well_map.try_emplace(this->name(), &(this->wellEcl()), this->indexOfWell());
2308 const auto& iterCtx = simulator.problem().iterationContext();
2311 simulator.vanguard().schedule(),
2312 simulator.vanguard().summaryState(),
2313 simulator.episodeIndex(),
2323 std::set<int> sync_groups;
2324 const auto& summary_state = simulator.vanguard().summaryState();
2325 return std::make_unique<GasLiftSingleWell>(*
this,
#define OPM_DEFLOG_THROW(Exception, message, deferred_logger)
Definition: DeferredLoggingErrorHelpers.hpp:45
Contains the high level supplements required to extend the black oil model by solvents.
Definition: blackoilsolventmodules.hh:69
Definition: DeferredLogger.hpp:57
void info(const std::string &tag, const std::string &message)
Definition: GasLiftGroupInfo.hpp:47
Definition: GroupStateHelper.hpp:57
GroupState< Scalar > & groupState() const
Definition: GroupStateHelper.hpp:298
const SummaryState & summaryState() const
Definition: GroupStateHelper.hpp:415
const WellState< Scalar, IndexTraits > & wellState() const
Definition: GroupStateHelper.hpp:494
DeferredLogger & deferredLogger() const
Get the deferred logger.
Definition: GroupStateHelper.hpp:234
WellStateGuard pushWellState(WellState< Scalar, IndexTraits > &well_state)
Definition: GroupStateHelper.hpp:354
GroupStateGuard pushGroupState(GroupState< Scalar > &group_state)
Definition: GroupStateHelper.hpp:331
Definition: GroupState.hpp:41
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:198
Definition: SingleWellState.hpp:43
Scalar temperature
Definition: SingleWellState.hpp:105
PerfData< Scalar > perf_data
Definition: SingleWellState.hpp:143
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:305
int number_of_local_perforations_
Definition: WellInterfaceGeneric.hpp:341
FluidSystem::Scalar wsolvent_
Definition: WellInterfaceGeneric.hpp:381
Definition: WellInterfaceIndices.hpp:34
bool stoppedOrZeroRateTarget(const GroupStateHelperType &groupStateHelper) const
Definition: WellInterface_impl.hpp:1730
bool updateWellOperabilityFromWellEq(const Simulator &simulator, const GroupStateHelperType &groupStateHelper)
Definition: WellInterface_impl.hpp:1282
void checkWellOperability(const Simulator &simulator, const WellStateType &well_state, const GroupStateHelperType &groupStateHelper)
Definition: WellInterface_impl.hpp:1154
void updateWellOperability(const Simulator &simulator, const WellStateType &well_state, const GroupStateHelperType &groupStateHelper)
Definition: WellInterface_impl.hpp:1244
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:600
Scalar woxygen() const
Definition: WellInterface_impl.hpp:165
IndividualOrGroup
Definition: WellInterface.hpp:244
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: WellInterface.hpp:82
void assembleWellEqWithoutIteration(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, const double dt, WellStateType &well_state, const bool solving_with_zero_rate)
Definition: WellInterface_impl.hpp:973
Scalar computeConnectionDFactor(const int perf, const IntensiveQuantities &intQuants, const SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:1977
typename WellInterfaceFluidSystem< FluidSystem >::RateConverterType RateConverterType
Definition: WellInterface.hpp:105
Scalar wfoam() const
Definition: WellInterface_impl.hpp:127
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:286
void getTransMult(Value &trans_mult, const Simulator &simulator, const int cell_idx, Callback &extendEval) const
Definition: WellInterface_impl.hpp:2065
std::vector< RateVector > connectionRates_
Definition: WellInterface.hpp:362
bool solveWellForTesting(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:839
void computeConnLevelProdInd(const FluidState &fs, const std::function< Scalar(const Scalar)> &connPICalc, const std::vector< Scalar > &mobility, Scalar *connPI) const
Definition: WellInterface_impl.hpp:2231
void gliftBeginTimeStepWellTestUpdateALQ(const Simulator &simulator, WellStateType &well_state, const GroupState< Scalar > &group_state, GLiftEclWells &ecl_well_map, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:1182
Scalar volumetricSurfaceRateForConnection(int cellIdx, int phaseIdx) const
Definition: WellInterface_impl.hpp:1134
virtual void init(const std::vector< Scalar > &depth_arg, const Scalar gravity_arg, const std::vector< Scalar > &B_avg, const bool changed_to_open_this_step)
Definition: WellInterface_impl.hpp:95
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:2196
void getTw(std::vector< Value > &wi, const int perf, const IntensiveQuantities &intQuants, const Value &trans_mult, const SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:1879
void getMobility(const Simulator &simulator, const int local_perf_index, std::vector< Value > &mob, Callback &extendEval, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:2078
GetPropType< TypeTag, Properties::IntensiveQuantities > IntensiveQuantities
Definition: WellInterface.hpp:87
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: WellInterface.hpp:83
std::vector< Scalar > initialWellRateFractions(const Simulator &ebosSimulator, const WellStateType &well_state) const
Definition: WellInterface_impl.hpp:1741
void solveWellEquation(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:895
void updateConnectionDFactor(const Simulator &simulator, SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:1957
Eval getPerfCellPressure(const FluidState &fs) const
Definition: WellInterface_impl.hpp:2050
void initializeProducerWellState(const Simulator &simulator, WellStateType &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1791
virtual void updateWellStateWithTarget(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state) const
Definition: WellInterface_impl.hpp:1312
void addCellRates(std::map< int, RateVector > &cellRates_) const
Definition: WellInterface_impl.hpp:1115
BlackOilFluidState< Eval, FluidSystem, energyModuleType !=EnergyModules::NoTemperature, energyModuleType==EnergyModules::FullyImplicitThermal, Indices::compositionSwitchIdx >=0, has_watVapor, has_brine, has_saltPrecip, has_disgas_in_water, Indices::numPhases > FluidState
Definition: WellInterface.hpp:139
typename Base::ModelParameters ModelParameters
Definition: WellInterface.hpp:111
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: WellInterface.hpp:84
static constexpr bool has_solvent
Definition: WellInterface.hpp:113
bool wellUnderZeroRateTarget(const GroupStateHelperType &groupStateHelper) const
Definition: WellInterface_impl.hpp:1698
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: WellInterface.hpp:90
void updateConnectionTransmissibilityFactor(const Simulator &simulator, SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:2019
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:2265
typename GasLiftGroupInfo< Scalar, IndexTraits >::GLiftEclWells GLiftEclWells
Definition: WellInterface.hpp:92
std::unique_ptr< GasLiftSingleWell > initializeGliftWellTest_(const Simulator &simulator, WellStateType &well_state, const GroupState< Scalar > &group_state, GLiftEclWells &ecl_well_map, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:2299
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:720
Scalar wsalt() const
Definition: WellInterface_impl.hpp:141
bool solveWellWithZeroRate(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:807
bool wellUnderZeroGroupRateTarget(const GroupStateHelperType &groupStateHelper, const std::optional< bool > group_control=std::nullopt) const
Definition: WellInterface_impl.hpp:1715
bool solveWellWithBhp(const Simulator &simulator, const double dt, const Scalar bhp, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:757
void prepareWellBeforeAssembling(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:993
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:405
typename Base::Eval Eval
Definition: WellInterface.hpp:96
WellInterface(const Well &well, const ParallelWellInfo< Scalar > &pw_info, const int time_step, const ModelParameters ¶m, const RateConverterType &rate_converter, const int pvtRegionIdx, const int num_conservation_quantities, const int num_phases, const int index_of_well, const std::vector< PerforationData< Scalar > > &perf_data)
Constructor.
Definition: WellInterface_impl.hpp:58
bool updateWellStateWithTHPTargetProd(const Simulator &simulator, WellStateType &well_state, const GroupStateHelperType &groupStateHelper) const
Definition: WellInterface_impl.hpp:2164
bool iterateWellEquations(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:531
Scalar wpolymer() const
Definition: WellInterface_impl.hpp:111
GetPropType< TypeTag, Properties::Indices > Indices
Definition: WellInterface.hpp:86
bool updateWellControl(const Simulator &simulator, const IndividualOrGroup iog, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:189
Scalar wurea() const
Definition: WellInterface_impl.hpp:177
void assembleWellEq(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:957
Scalar wmicrobes() const
Definition: WellInterface_impl.hpp:153
virtual void scaleSegmentRatesAndPressure(WellStateType &well_state) const
Definition: WellInterface_impl.hpp:1304
static constexpr bool has_zFraction
Definition: WellInterface.hpp:114
Definition: WellState.hpp:66
constexpr int numPhases() const
The number of phases present.
Definition: WellState.hpp:249
const SingleWellState< Scalar, IndexTraits > & well(std::size_t well_index) const
Definition: WellState.hpp:290
bool isOpen(const std::string &name) const
Definition: WellState.hpp:197
@ NONE
Definition: DeferredLogger.hpp:46
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Phase
Phase indices for reservoir coupling, we currently only support black-oil phases (oil,...
Definition: ReservoirCoupling.hpp:156
Definition: blackoilbioeffectsmodules.hh:45
std::string to_string(const ConvergenceReport::ReservoirFailure::Type t)
Static data associated with a well perforation.
Definition: PerforationData.hpp:30