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>
35#include <opm/input/eclipse/Schedule/Well/WELDRAW.hpp>
45#include <dune/common/version.hh>
53#include <fmt/format.h>
59 template<
typename TypeTag>
66 const int pvtRegionIdx,
67 const int num_conservation_quantities,
69 const int index_of_well,
77 num_conservation_quantities,
85 if (well.isInjector()) {
86 auto injectorType = this->
well_ecl_.injectorType();
87 if (injectorType == InjectorType::GAS) {
95 template<
typename TypeTag>
98 init(
const std::vector<Scalar>& ,
100 const std::vector<Scalar>& B_avg,
101 const bool changed_to_open_this_step)
103 this->gravity_ = gravity_arg;
105 this->changed_to_open_this_step_ = changed_to_open_this_step;
111 template<
typename TypeTag>
116 if constexpr (has_polymer) {
117 return this->wpolymer_();
127 template<
typename TypeTag>
132 if constexpr (has_foam) {
133 return this->wfoam_();
141 template<
typename TypeTag>
146 if constexpr (has_brine) {
147 return this->wsalt_();
153 template<
typename TypeTag>
158 if constexpr (has_micp) {
159 return this->wmicrobes_();
165 template<
typename TypeTag>
170 if constexpr (has_micp) {
171 return this->woxygen_();
177 template<
typename TypeTag>
182 if constexpr (has_micp) {
183 return this->wurea_();
189 template<
typename TypeTag>
199 if (stoppedOrZeroRateTarget(groupStateHelper)) {
203 const auto& summaryState = simulator.vanguard().summaryState();
204 const auto& schedule = simulator.vanguard().schedule();
205 const auto& well = this->well_ecl_;
206 auto& ws = well_state.
well(this->index_of_well_);
208 bool is_grup =
false;
209 if (well.isInjector()) {
210 from = WellInjectorCMode2String(ws.injection_cmode);
211 is_grup = ws.injection_cmode == Well::InjectorCMode::GRUP;
213 from = WellProducerCMode2String(ws.production_cmode);
214 is_grup = ws.production_cmode == Well::ProducerCMode::GRUP;
217 const int episodeIdx = simulator.episodeIndex();
218 const auto& iterCtx = simulator.problem().iterationContext();
219 const int nupcol = schedule[episodeIdx].nupcol();
220 const bool oscillating =
221 std::ranges::count(this->well_control_log_, from) >= this->param_.max_number_of_well_switches_;
222 if (oscillating && !is_grup) {
225 std::ranges::count(this->well_control_log_, from) == this->param_.max_number_of_well_switches_;
227 const auto msg = fmt::format(
" The control mode for well {} is oscillating. \n"
228 "We don't allow for more than {} switches after NUPCOL iterations. (NUPCOL = {}) \n"
229 "The control is kept at {}.",
230 this->name(), this->param_.max_number_of_well_switches_, nupcol, from);
231 deferred_logger.info(msg);
233 this->well_control_log_.push_back(from);
237 bool changed =
false;
238 if (iog == IndividualOrGroup::Individual) {
239 changed = this->checkIndividualConstraints(ws, summaryState, deferred_logger);
240 }
else if (iog == IndividualOrGroup::Group) {
241 changed = this->checkGroupConstraints(
242 groupStateHelper, schedule, summaryState,
true, well_state
245 assert(iog == IndividualOrGroup::Both);
246 changed = this->checkConstraints(groupStateHelper, schedule, summaryState, well_state);
252 if (well.isInjector()) {
253 to = WellInjectorCMode2String(ws.injection_cmode);
255 to = WellProducerCMode2String(ws.production_cmode);
257 std::ostringstream ss;
258 ss <<
" Switching control mode for well " << this->name()
261 if (iterCtx.inLocalSolve()) {
262 ss <<
" (NLDD domain solve)";
265 ss <<
" on rank " << cc.rank();
267 deferred_logger.debug(ss.str());
274 if (!iterCtx.inLocalSolve()) {
275 if (!iterCtx.withinNupcol(nupcol) || this->well_control_log_.empty()) {
276 this->well_control_log_.push_back(from);
279 updateWellStateWithTarget(simulator, groupStateHelper, well_state);
280 updatePrimaryVariables(groupStateHelper);
286 template<
typename TypeTag>
293 if (!this->isProducer()) {
297 auto& ws = well_state.
well(this->index_of_well_);
298 const auto& weldraw = this->well_ecl_.getWELDRAW();
299 if (!weldraw.active()) {
300 ws.weldraw_max_rate.reset();
301 ws.weldraw_cmode.reset();
305 const auto& summary_state = simulator.vanguard().summaryState();
306 const Scalar max_draw = this->well_ecl_.weldrawMaxDrawdown(summary_state);
307 if (!(max_draw > 0.0)) {
308 ws.weldraw_max_rate.reset();
309 ws.weldraw_cmode.reset();
320 this->updateIPR(simulator, deferred_logger);
322 auto phase_coeff = [
this](
const unsigned phase_idx) ->
Scalar {
323 const unsigned comp_idx = FluidSystem::canonicalToActiveCompIdx(
324 FluidSystem::solventComponentIndex(phase_idx));
325 return this->ipr_b_[comp_idx];
329 const bool gas_target = (weldraw.targetPhase() == WELDRAW::TargetPhase::GAS);
331 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
332 coeff += phase_coeff(FluidSystem::gasPhaseIdx);
336 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
337 coeff += phase_coeff(FluidSystem::oilPhaseIdx);
339 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
340 coeff += phase_coeff(FluidSystem::waterPhaseIdx);
344 if (!(coeff > 0.0)) {
350 deferred_logger.
warning(
"WELDRAW_NO_TARGET_PHASE_MOBILITY",
351 fmt::format(
"Well {}: the WELDRAW target phase ({}) has no "
352 "producible mobility; the drawdown limit is ignored.",
353 this->name(), gas_target ?
"GAS" :
"LIQ"));
354 ws.weldraw_max_rate.reset();
355 ws.weldraw_cmode.reset();
359 const Scalar max_rate = max_draw * coeff;
360 ws.weldraw_max_rate = max_rate;
365 const auto controls = this->well_ecl_.productionControls(summary_state);
366 const auto cmode = gas_target ? Well::ProducerCMode::GRAT
367 : Well::ProducerCMode::LRAT;
368 const Scalar own_target = gas_target ? controls.gas_rate
369 : controls.liquid_rate;
370 if (!controls.hasControl(cmode) || (max_rate <= own_target)) {
371 ws.weldraw_cmode = cmode;
374 ws.weldraw_cmode.reset();
378 template<
typename TypeTag>
383 const Well::InjectionControls& inj_controls,
384 const Well::ProductionControls& prod_controls,
387 const bool fixed_control,
388 const bool fixed_status,
389 const bool solving_with_zero_rate)
393 const auto& summary_state = simulator.vanguard().summaryState();
394 const auto& schedule = simulator.vanguard().schedule();
395 auto& ws = well_state.
well(this->index_of_well_);
397 if (this->isInjector()) {
398 from = WellInjectorCMode2String(ws.injection_cmode);
400 from = WellProducerCMode2String(ws.production_cmode);
402 const bool oscillating =
403 std::ranges::count(this->well_control_log_, from) >= this->param_.max_number_of_well_switches_;
405 if (oscillating || this->wellUnderZeroRateTarget(groupStateHelper) || !(well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
409 const Scalar sgn = this->isInjector() ? 1.0 : -1.0;
410 if (!this->wellIsStopped()){
411 if (wqTotal*sgn <= 0.0 && !fixed_status){
415 bool changed =
false;
416 if (!fixed_control) {
419 if (solving_with_zero_rate) {
421 "Well {}: solving_with_zero_rate should not be true when fixed_control is false",
422 this->name()), deferred_logger);
428 const bool hasGroupControl = this->isInjector() ? inj_controls.hasControl(Well::InjectorCMode::GRUP) :
429 prod_controls.hasControl(Well::ProducerCMode::GRUP);
430 bool isGroupControl = ws.production_cmode == Well::ProducerCMode::GRUP || ws.injection_cmode == Well::InjectorCMode::GRUP;
431 if (! (isGroupControl && !this->param_.check_group_constraints_inner_well_iterations_)) {
432 changed = this->checkIndividualConstraints(ws, summary_state, deferred_logger, inj_controls, prod_controls);
434 if (hasGroupControl && this->param_.check_group_constraints_inner_well_iterations_) {
435 changed = changed || this->checkGroupConstraints(
436 groupStateHelper, schedule, summary_state,
false, well_state
441 const bool thp_controlled = this->isInjector() ? ws.injection_cmode == Well::InjectorCMode::THP :
442 ws.production_cmode == Well::ProducerCMode::THP;
444 ws.thp = this->getTHPConstraint(summary_state);
447 updateWellStateWithTarget(simulator, groupStateHelper, well_state);
449 updatePrimaryVariables(groupStateHelper);
454 }
else if (!fixed_status){
456 const Scalar bhp = well_state.
well(this->index_of_well_).bhp;
457 Scalar prod_limit = prod_controls.bhp_limit;
458 Scalar inj_limit = inj_controls.bhp_limit;
459 const bool has_thp = this->wellHasTHPConstraints(summary_state);
461 std::vector<Scalar> rates(this->num_conservation_quantities_);
462 if (this->isInjector()){
464 calculateBhpFromThp(well_state, rates,
467 this->getRefDensity(),
469 inj_limit = std::min(bhp_thp,
static_cast<Scalar>(inj_controls.bhp_limit));
474 calculateMinimumBhpFromThp(well_state,
477 this->getRefDensity());
478 prod_limit = std::max(bhp_min,
static_cast<Scalar>(prod_controls.bhp_limit));
481 const Scalar bhp_diff = (this->isInjector())? inj_limit - bhp: bhp - prod_limit;
484 well_state.
well(this->index_of_well_).bhp = (this->isInjector())? inj_limit : prod_limit;
486 well_state.
well(this->index_of_well_).thp = this->getTHPConstraint(summary_state);
497 template<
typename TypeTag>
501 const double simulation_time,
504 WellTestState& well_test_state,
506 std::map<std::string, double>& open_times)
510 const auto& group_state = groupStateHelper.
groupState();
514 const auto& unit_system = simulator.vanguard().eclState().getUnits();
515 const auto start_time = simulator.vanguard().schedule().getStartTime();
517 fmt::format(
"at time {:.2f} {} (date = {})",
518 unit_system.from_si(UnitSystem::measure::time, simulation_time),
519 unit_system.name(UnitSystem::measure::time),
522 deferred_logger.info(fmt::format(
"Well {} is being tested {}.", this->name(), when));
529 auto guard = groupStateHelper_copy.
pushWellState(well_state_copy);
530 auto& ws = well_state_copy.
well(this->indexOfWell());
532 const auto& summary_state = simulator.vanguard().summaryState();
533 const bool has_thp_limit = this->wellHasTHPConstraints(summary_state);
534 if (this->isProducer()) {
535 ws.production_cmode = has_thp_limit ? Well::ProducerCMode::THP : Well::ProducerCMode::BHP;
537 ws.injection_cmode = has_thp_limit ? Well::InjectorCMode::THP : Well::InjectorCMode::BHP;
542 scaleSegmentRatesAndPressure(well_state_copy);
543 calculateExplicitQuantities(simulator, groupStateHelper_copy);
544 updatePrimaryVariables(groupStateHelper_copy);
546 if (this->isProducer()) {
547 const auto& schedule = simulator.vanguard().schedule();
548 const auto report_step = simulator.episodeIndex();
549 const auto& glo = schedule.glo(report_step);
551 gliftBeginTimeStepWellTestUpdateALQ(simulator,
559 WellTestState welltest_state_temp;
561 std::string closure_reason;
567 auto notReopened = [
this, &when, &deferred_logger](
const std::string_view reason)
569 deferred_logger.info(
570 fmt::format(
"Well {} is not re-opened {}.", this->name(), when));
571 if (!reason.empty()) {
572 deferred_logger.debug(fmt::format(
"Because {}.", reason));
576 bool testWell =
true;
581 const std::size_t original_number_closed_completions = welltest_state_temp.num_closed_completions();
582 bool converged = solveWellForTesting(simulator, groupStateHelper_copy, well_state_copy);
584 notReopened(
"the well equations could not be solved");
589 updateWellOperability(simulator, well_state_copy, groupStateHelper_copy);
590 if ( !this->isOperableAndSolvable() ) {
591 notReopened(
"the well is not operable");
594 std::vector<Scalar> potentials;
596 computeWellPotentials(simulator, well_state_copy, groupStateHelper_copy, potentials);
597 }
catch (
const std::exception& e) {
598 notReopened(fmt::format(
"computing the well potentials failed: {}", e.what()));
601 const int np = well_state_copy.
numPhases();
602 for (
int p = 0; p < np; ++p) {
603 ws.well_potentials[p] = std::max(
Scalar{0.0}, potentials[p]);
605 const bool under_zero_target = this->wellUnderZeroGroupRateTarget(groupStateHelper_copy);
606 this->updateWellTestState(well_state_copy.
well(this->indexOfWell()),
612 simulator.vanguard().eclState().getUnits(),
613 simulator.vanguard().schedule().getStartTime(),
616 this->closeCompletions(welltest_state_temp);
622 if ( welltest_state_temp.num_closed_wells() > 0 ||
623 (original_number_closed_completions == welltest_state_temp.num_closed_completions()) ) {
629 if (!welltest_state_temp.well_is_closed(this->name())) {
630 well_test_state.open_well(this->name());
633 deferred_logger.info(
634 fmt::format(
"{}\nWell {} is re-opened {}.\n{}",
635 sep, this->name(), when, sep));
638 for (
const auto& completion : this->well_ecl_.getCompletions()) {
639 if (!welltest_state_temp.completion_is_closed(this->name(), completion.first))
640 well_test_state.open_completion(this->name(), completion.first);
642 well_state = well_state_copy;
643 open_times.try_emplace(this->name(), well_test_state.lastTestTime(this->name()));
647 notReopened(closure_reason);
654 template<
typename TypeTag>
665 const auto& summary_state = simulator.vanguard().summaryState();
666 const auto& ws = well_state.
well(this->indexOfWell());
667 const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
668 const auto prod_controls = this->well_ecl_.isProducer() ? this->productionControlsWithWeldraw(summary_state, ws) : Well::ProductionControls(0);
669 const auto pmode_orig = ws.production_cmode;
670 const auto imode_orig = ws.injection_cmode;
671 bool converged =
false;
674 if (!this->param_.local_well_solver_control_switching_){
675 converged = this->iterateWellEqWithControl(simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state);
677 if (this->param_.use_implicit_ipr_ && this->well_ecl_.isProducer() && (well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
678 converged = solveWellWithOperabilityCheck(
679 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state
682 converged = this->iterateWellEqWithSwitching(
683 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
689 }
catch (NumericalProblem& e ) {
690 const std::string msg =
"Inner well iterations failed for well " + this->name() +
" Treat the well as unconverged. ";
691 deferred_logger.warning(
"INNER_ITERATION_FAILED", msg);
696 if (ws.production_cmode != pmode_orig || ws.injection_cmode != imode_orig) {
698 if (this->isInjector()) {
699 from = WellInjectorCMode2String(imode_orig);
700 to = WellInjectorCMode2String(ws.injection_cmode);
702 from = WellProducerCMode2String(pmode_orig);
703 to = WellProducerCMode2String(ws.production_cmode);
705 const auto msg = fmt::format(
" Well {} switched from {} to {} during local solve", this->name(), from, to);
706 deferred_logger.debug(msg);
707 const int episodeIdx = simulator.episodeIndex();
708 const auto& iterCtx = simulator.problem().iterationContext();
709 const auto& schedule = simulator.vanguard().schedule();
710 const int nupcol = schedule[episodeIdx].nupcol();
714 if (!iterCtx.withinNupcol(nupcol) || this->well_control_log_.empty()) {
715 this->well_control_log_.push_back(from);
720 if (this->isProducer() && ws.production_cmode == Well::ProducerCMode::GRUP && ws.use_group_target_fallback) {
721 assert(ws.group_target && ws.group_target_fallback);
722 const std::string cmode = Group::ProductionCMode2String(ws.group_target->production_cmode);
723 const std::string cmode_fallback = Group::ProductionCMode2String(ws.group_target_fallback->production_cmode);
724 const auto msg = fmt::format(
" Well {} was solved using group target fallback mode {} as current group mode {} was not feasible.",
725 this->name(), cmode_fallback, cmode);
726 deferred_logger.debug(msg);
732 template<
typename TypeTag>
737 const Well::InjectionControls& inj_controls,
738 const Well::ProductionControls& prod_controls,
745 const auto& summary_state = simulator.vanguard().summaryState();
746 bool converged =
true;
747 auto& ws = well_state.
well(this->index_of_well_);
749 if (this->wellIsStopped()) {
751 const bool use_vfpexplicit = this->operability_status_.use_vfpexplicit;
752 this->operability_status_.use_vfpexplicit =
true;
753 auto bhp_target = estimateOperableBhp(simulator, dt, groupStateHelper, summary_state, well_state);
754 if (!bhp_target.has_value()) {
756 const auto msg = fmt::format(
"estimateOperableBhp: Did not find operable BHP for well {}", this->name());
757 deferred_logger.debug(msg);
760 converged = solveWellWithZeroRate(simulator, dt, groupStateHelper, well_state);
762 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
763 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
767 ws.thp = this->getTHPConstraint(summary_state);
768 const Scalar bhp = std::max(bhp_target.value(),
769 static_cast<Scalar>(prod_controls.bhp_limit));
770 solveWellWithBhp(simulator, dt, bhp, groupStateHelper, well_state);
771 this->operability_status_.use_vfpexplicit = use_vfpexplicit;
775 converged = this->iterateWellEqWithSwitching(
776 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
781 const bool isThp = ws.production_cmode == Well::ProducerCMode::THP;
783 if (converged && !stoppedOrZeroRateTarget(groupStateHelper) && isThp) {
784 auto rates = well_state.
well(this->index_of_well_).surface_rates;
785 this->adaptRatesForVFP(rates);
786 this->updateIPRImplicit(simulator, groupStateHelper, well_state);
790 this->operability_status_.use_vfpexplicit =
true;
793 const Scalar reltol = 1e-3;
794 const Scalar cur_bhp = ws.bhp;
795 if (bhp_stable.has_value() && cur_bhp - bhp_stable.value() > cur_bhp*reltol){
796 const auto msg = fmt::format(
"Well {} converged to an unstable solution, re-solving", this->name());
797 deferred_logger.debug(msg);
799 simulator, dt, bhp_stable.value(), groupStateHelper, well_state
802 ws.thp = this->getTHPConstraint(summary_state);
803 converged = this->iterateWellEqWithSwitching(
804 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
813 this->operability_status_.use_vfpexplicit =
true;
815 auto bhp_target = estimateOperableBhp(
816 simulator, dt, groupStateHelper, summary_state, well_state
818 if (!bhp_target.has_value()) {
821 converged = solveWellWithZeroRate(simulator, dt, groupStateHelper, well_state);
823 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
824 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
828 const Scalar bhp = std::max(bhp_target.value(),
829 static_cast<Scalar>(prod_controls.bhp_limit));
831 simulator, dt, bhp, groupStateHelper, well_state
833 ws.thp = this->getTHPConstraint(summary_state);
834 const auto msg = fmt::format(
"Well {} did not converge, re-solving with explicit fractions for VFP caculations.", this->name());
835 deferred_logger.debug(msg);
836 converged = this->iterateWellEqWithSwitching(simulator, dt,
847 this->operability_status_.can_obtain_bhp_with_thp_limit = !this->wellIsStopped();
848 this->operability_status_.obey_thp_limit_under_bhp_limit = !this->wellIsStopped();
852 template<
typename TypeTag>
853 std::optional<typename WellInterface<TypeTag>::Scalar>
858 const SummaryState& summary_state,
861 if (!this->wellHasTHPConstraints(summary_state)) {
863 const bool converged = solveWellWithBhp(
864 simulator, dt, bhp_limit, groupStateHelper, well_state
866 if (!converged || this->wellIsStopped()) {
877 const bool converged = solveWellWithBhp(
878 simulator, dt, bhp_min, groupStateHelper, well_state
880 if (!converged || this->wellIsStopped()) {
883 this->updateIPRImplicit(simulator, groupStateHelper, well_state);
884 auto rates = well_state.
well(this->index_of_well_).surface_rates;
885 this->adaptRatesForVFP(rates);
889 template<
typename TypeTag>
906 auto group_guard = groupStateHelper_copy.
pushGroupState(group_state);
908 auto inj_controls = Well::InjectionControls(0);
909 auto prod_controls = Well::ProductionControls(0);
910 auto& ws = well_state.
well(this->index_of_well_);
911 auto cmode_inj = ws.injection_cmode;
912 auto cmode_prod = ws.production_cmode;
913 if (this->isInjector()) {
914 inj_controls.addControl(Well::InjectorCMode::BHP);
915 inj_controls.bhp_limit = bhp;
916 inj_controls.cmode = Well::InjectorCMode::BHP;
917 ws.injection_cmode = Well::InjectorCMode::BHP;
919 prod_controls.addControl(Well::ProducerCMode::BHP);
920 prod_controls.bhp_limit = bhp;
921 prod_controls.cmode = Well::ProducerCMode::BHP;
922 ws.production_cmode = Well::ProducerCMode::BHP;
927 const bool converged = this->iterateWellEqWithSwitching(
928 simulator, dt, inj_controls, prod_controls, groupStateHelper_copy,
934 ws.injection_cmode = cmode_inj;
935 ws.production_cmode = cmode_prod;
939 template<
typename TypeTag>
950 const auto well_status_orig = this->wellStatus_;
953 auto inj_controls = Well::InjectionControls(0);
954 auto prod_controls = Well::ProductionControls(0);
959 const bool converged = this->iterateWellEqWithSwitching(
960 simulator, dt, inj_controls, prod_controls,
967 this->wellStatus_ = well_status_orig;
971 template<
typename TypeTag>
981 const double dt = simulator.timeStepSize();
983 const auto& summary_state = simulator.vanguard().summaryState();
984 auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
985 auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
986 this->onlyKeepBHPandTHPcontrols(summary_state, well_state, inj_controls, prod_controls);
988 bool converged =
false;
991 if (!this->param_.local_well_solver_control_switching_){
992 converged = this->iterateWellEqWithControl(
993 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state
996 if (this->param_.use_implicit_ipr_ && this->well_ecl_.isProducer() && (well_state.
well(this->index_of_well_).status == WellStatus::OPEN)) {
997 converged = this->solveWellWithOperabilityCheck(
998 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state
1001 converged = this->iterateWellEqWithSwitching(
1002 simulator, dt, inj_controls, prod_controls, groupStateHelper, well_state,
1010 }
catch (NumericalProblem& e ) {
1011 const std::string msg =
"Inner well iterations failed for well " + this->name() +
" Treat the well as unconverged. ";
1012 deferred_logger.warning(
"INNER_ITERATION_FAILED", msg);
1017 deferred_logger.debug(
"WellTest: Well equation for well " + this->name() +
" converged");
1020 const int max_iter = this->param_.max_welleq_iter_;
1021 deferred_logger.debug(
"WellTest: Well equation for well " + this->name() +
" failed converging in "
1027 template<
typename TypeTag>
1036 if (!this->isOperableAndSolvable() && !this->wellIsStopped())
1041 const double dt = simulator.timeStepSize();
1042 bool converged = iterateWellEquations(simulator, dt, groupStateHelper, well_state);
1052 auto& ws = well_state.
well(this->indexOfWell());
1053 bool thp_control =
false;
1054 if (this->well_ecl_.isInjector()) {
1055 thp_control = ws.injection_cmode == Well::InjectorCMode::THP;
1057 ws.injection_cmode = Well::InjectorCMode::BHP;
1058 if (this->well_control_log_.empty()) {
1059 this->well_control_log_.push_back(WellInjectorCMode2String(Well::InjectorCMode::THP));
1063 thp_control = ws.production_cmode == Well::ProducerCMode::THP;
1065 ws.production_cmode = Well::ProducerCMode::BHP;
1066 if (this->well_control_log_.empty()) {
1067 this->well_control_log_.push_back(WellProducerCMode2String(Well::ProducerCMode::THP));
1072 const std::string msg = std::string(
"The newly opened well ") + this->name()
1073 + std::string(
" with THP control did not converge during inner iterations, we try again with bhp control");
1074 deferred_logger.debug(msg);
1075 converged = this->iterateWellEquations(simulator, dt, groupStateHelper, well_state);
1080 const int max_iter = this->param_.max_welleq_iter_;
1081 deferred_logger.debug(
"Compute initial well solution for well " + this->name() +
". Failed to converge in "
1083 well_state = well_state0;
1089 template <
typename TypeTag>
1098 prepareWellBeforeAssembling(simulator, dt, groupStateHelper, well_state);
1099 assembleWellEqWithoutIteration(simulator, groupStateHelper, dt, well_state,
1105 template <
typename TypeTag>
1112 const bool solving_with_zero_rate)
1115 const auto& summary_state = simulator.vanguard().summaryState();
1116 const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
1117 const auto prod_controls = this->well_ecl_.isProducer()
1118 ? this->productionControlsWithWeldraw(summary_state, well_state.
well(this->index_of_well_))
1119 : Well::ProductionControls(0);
1122 assembleWellEqWithoutIteration(simulator, groupStateHelper, dt, inj_controls, prod_controls, well_state, solving_with_zero_rate);
1127 template<
typename TypeTag>
1134 std::vector<Scalar> scaled_well_fractions(FluidSystem::numPhases, 0.0);
1135 this->getScaledWellFractions(scaled_well_fractions, deferred_logger);
1137 this->Base::updateGroupTargetFallbackFlag(well_state, scaled_well_fractions, deferred_logger);
1142 template<
typename TypeTag>
1152 const bool old_well_operable = this->operability_status_.isOperableAndSolvable();
1154 if (this->param_.check_well_operability_iter_)
1155 checkWellOperability(simulator, well_state, groupStateHelper);
1158 const auto& iterCtx = simulator.problem().iterationContext();
1159 if (iterCtx.shouldRunInnerWellIterations(this->param_.max_niter_inner_well_iter_)) {
1160 const auto& ws = well_state.
well(this->indexOfWell());
1161 const bool nonzero_rate_original =
1162 std::any_of(ws.surface_rates.begin(),
1163 ws.surface_rates.begin() + well_state.
numPhases(),
1164 [](
Scalar rate) { return rate != Scalar(0.0); });
1166 this->operability_status_.solvable =
true;
1167 if (number_of_well_reopenings_ >= this->param_.max_well_status_switch_) {
1169 if (number_of_well_reopenings_ == this->param_.max_well_status_switch_) {
1170 const std::string msg = fmt::format(
"well {} is oscillating between open and stop. \n"
1171 "We don't allow for more than {} re-openings "
1172 "and the well is therefore kept stopped.",
1173 this->name(), number_of_well_reopenings_);
1174 deferred_logger.debug(msg);
1175 changed_to_stopped_this_step_ = old_well_operable;
1177 changed_to_stopped_this_step_ =
false;
1180 bool converged_zero_rate = this->solveWellWithZeroRate(
1181 simulator, dt, groupStateHelper, well_state
1183 if (this->param_.shut_unsolvable_wells_ && !converged_zero_rate ) {
1184 this->operability_status_.solvable =
false;
1186 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
1187 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
1190 number_of_well_reopenings_++;
1193 bool converged = this->iterateWellEquations(
1194 simulator, dt, groupStateHelper, well_state
1198 const bool zero_target = this->wellUnderZeroRateTarget(groupStateHelper);
1199 if (this->wellIsStopped() && !zero_target && nonzero_rate_original) {
1203 this->operability_status_.resetOperability();
1205 deferred_logger.debug(
" " + this->name() +
" is re-opened after being stopped during local solve");
1206 number_of_well_reopenings_++;
1210 if (this->param_.shut_unsolvable_wells_) {
1211 this->operability_status_.solvable =
false;
1215 if (this->operability_status_.has_negative_potentials) {
1216 auto well_state_copy = well_state;
1217 std::vector<Scalar> potentials;
1219 computeWellPotentials(simulator, well_state_copy, groupStateHelper, potentials);
1220 }
catch (
const std::exception& e) {
1221 const std::string msg = fmt::format(
"well {}: computeWellPotentials() failed "
1222 "during attempt to recompute potentials for well: ",
1223 this->name(), e.what());
1224 deferred_logger.info(msg);
1225 this->operability_status_.has_negative_potentials =
true;
1227 auto& ws = well_state.
well(this->indexOfWell());
1229 for (
int p = 0; p < np; ++p) {
1230 ws.well_potentials[p] = std::max(
Scalar{0.0}, potentials[p]);
1233 this->changed_to_open_this_step_ =
false;
1234 changed_to_stopped_this_step_ =
false;
1236 const bool well_operable = this->operability_status_.isOperableAndSolvable();
1237 if (!well_operable) {
1240 this->solveWellWithZeroRate(
1241 simulator, dt, groupStateHelper, well_state
1243 }
catch (
const std::exception& e) {
1244 const std::string msg = fmt::format(
"well {}: solveWellWithZeroRate() failed "
1245 "during attempt to solve with zero rate for well: ",
1246 this->name(), e.what());
1247 deferred_logger.info(msg);
1249 auto& ws = well_state.
well(this->indexOfWell());
1251 for (
int p = 0; p < np; ++p) {
1252 ws.surface_rates[p] =
Scalar{0.0};
1255 if (old_well_operable) {
1256 const std::string ctx = iterCtx.inLocalSolve() ?
" (NLDD domain solve)" :
"";
1257 deferred_logger.debug(
" well " + this->name() +
" gets STOPPED during iteration" + ctx);
1258 changed_to_stopped_this_step_ =
true;
1260 }
else if (well_state.
isOpen(this->name())) {
1262 if (!old_well_operable) {
1263 const std::string ctx = iterCtx.inLocalSolve() ?
" (NLDD domain solve)" :
"";
1264 deferred_logger.debug(
" well " + this->name() +
" gets REVIVED during iteration" + ctx);
1265 this->changed_to_open_this_step_ =
true;
1270 template<
typename TypeTag>
1274 if(!this->operability_status_.solvable)
1277 for (
int perfIdx = 0; perfIdx < this->number_of_local_perforations_; ++perfIdx) {
1278 const auto cellIdx = this->cells()[perfIdx];
1279 const auto it = cellRates_.find(cellIdx);
1280 RateVector rates = (it == cellRates_.end()) ? 0.0 : it->second;
1281 for (
auto i=0*RateVector::dimension; i < RateVector::dimension; ++i)
1283 rates[i] += connectionRates_[perfIdx][i];
1285 cellRates_.insert_or_assign(cellIdx, rates);
1289 template<
typename TypeTag>
1293 for (
int perfIdx = 0; perfIdx < this->number_of_local_perforations_; ++perfIdx) {
1294 if (this->cells()[perfIdx] == cellIdx) {
1295 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
1296 return connectionRates_[perfIdx][activeCompIdx].value();
1300 OPM_THROW(std::invalid_argument,
"The well with name " + this->name()
1308 template<
typename TypeTag>
1317 if (!this->param_.check_well_operability_) {
1321 if (this->wellIsStopped() && !changed_to_stopped_this_step_) {
1325 updateWellOperability(simulator, well_state, groupStateHelper);
1326 if (!this->operability_status_.isOperableAndSolvable()) {
1327 this->operability_status_.use_vfpexplicit =
true;
1328 deferred_logger.debug(
"EXPLICIT_LOOKUP_VFP",
1329 "well not operable, trying with explicit vfp lookup: " + this->name());
1330 updateWellOperability(simulator, well_state, groupStateHelper);
1336 template<
typename TypeTag>
1346 const auto& summary_state = simulator.vanguard().summaryState();
1347 const auto& well_name = this->name();
1348 if (!this->wellHasTHPConstraints(summary_state)) {
1349 const std::string msg = fmt::format(
"GLIFT WTEST: Well {} does not have THP constraints", well_name);
1350 deferred_logger.
info(msg);
1353 const auto& schedule = simulator.vanguard().schedule();
1354 const auto report_step_idx = simulator.episodeIndex();
1355 const auto& glo = schedule.glo(report_step_idx);
1356 if (!glo.has_well(well_name)) {
1357 const std::string msg = fmt::format(
1358 "GLIFT WTEST: Well {} : Gas lift not activated: "
1359 "WLIFTOPT is probably missing. Skipping.", well_name);
1360 deferred_logger.
info(msg);
1363 const auto& gl_well = glo.well(well_name);
1366 std::unique_ptr<GasLiftSingleWell> glift =
1367 initializeGliftWellTest_<GasLiftSingleWell>(simulator,
1372 auto [wtest_alq, success] = glift->wellTestALQ();
1374 const auto& unit_system = schedule.getUnits();
1376 well_state.
well(well_name).alq_state.set(wtest_alq);
1378 "GLIFT WTEST: Well {} : Setting ALQ to optimized value = {}",
1379 well_name, unit_system.from_si(UnitSystem::measure::gas_surface_rate, wtest_alq));
1382 if (!gl_well.use_glo()) {
1384 "GLIFT WTEST: Well {} : Gas lift optimization deactivated. Setting ALQ to WLIFTOPT item 3 = {}",
1386 unit_system.from_si(UnitSystem::measure::gas_surface_rate, well_state.
well(well_name).alq_state.get()));
1391 "GLIFT WTEST: Well {} : Gas lift optimization failed, no ALQ set.",
1395 deferred_logger.
info(msg);
1398 template<
typename TypeTag>
1407 if (this->param_.local_well_solver_control_switching_) {
1408 const bool success = updateWellOperabilityFromWellEq(simulator, groupStateHelper);
1410 this->operability_status_.solvable =
false;
1411 deferred_logger.debug(
"Operability check using well equations did not converge for well "
1412 + this->name() +
". Mark the well as unsolvable." );
1416 this->operability_status_.resetOperability();
1418 bool thp_controlled = this->isInjector() ? well_state.
well(this->index_of_well_).injection_cmode == Well::InjectorCMode::THP:
1419 well_state.
well(this->index_of_well_).production_cmode == Well::ProducerCMode::THP;
1420 bool bhp_controlled = this->isInjector() ? well_state.
well(this->index_of_well_).injection_cmode == Well::InjectorCMode::BHP:
1421 well_state.
well(this->index_of_well_).production_cmode == Well::ProducerCMode::BHP;
1425 bool check_thp = thp_controlled || this->operability_status_.thp_limit_violated_but_not_switched;
1426 if (check_thp || bhp_controlled) {
1427 updateIPR(simulator, deferred_logger);
1428 checkOperabilityUnderBHPLimit(well_state, simulator, deferred_logger);
1432 checkOperabilityUnderTHPLimit(simulator, well_state, groupStateHelper);
1436 template<
typename TypeTag>
1444 assert(this->param_.local_well_solver_control_switching_);
1445 this->operability_status_.resetOperability();
1448 const double dt = simulator.timeStepSize();
1452 auto guard = groupStateHelper_copy.
pushWellState(well_state_copy);
1454 bool converged = iterateWellEquations(simulator, dt, groupStateHelper_copy, well_state_copy);
1458 template<
typename TypeTag>
1466 template<
typename TypeTag>
1476 const auto& well = this->well_ecl_;
1477 const int well_index = this->index_of_well_;
1478 auto& ws = well_state.
well(well_index);
1480 const auto& summaryState = simulator.vanguard().summaryState();
1481 const auto& schedule = simulator.vanguard().schedule();
1485 ws.primaryvar.resize(0);
1487 if (this->wellIsStopped()) {
1488 for (
int p = 0; p<np; ++p) {
1489 ws.surface_rates[p] = 0;
1495 if (this->isInjector() )
1497 const auto& controls = well.injectionControls(summaryState);
1499 InjectorType injectorType = controls.injector_type;
1501 switch (injectorType) {
1502 case InjectorType::WATER:
1504 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1507 case InjectorType::OIL:
1509 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1512 case InjectorType::GAS:
1514 phasePos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1518 OPM_DEFLOG_THROW(std::runtime_error,
"Expected WATER, OIL or GAS as type for injectors " + this->name(), deferred_logger );
1521 const auto current = ws.injection_cmode;
1524 case Well::InjectorCMode::RATE:
1526 ws.surface_rates[phasePos] = (1.0 - this->rsRvInj()) * controls.surface_rate;
1527 if(this->rsRvInj() > 0) {
1528 if (injectorType == InjectorType::OIL && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1529 const int gas_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1530 ws.surface_rates[gas_pos] = controls.surface_rate * this->rsRvInj();
1531 }
else if (injectorType == InjectorType::GAS && FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1532 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1533 ws.surface_rates[oil_pos] = controls.surface_rate * this->rsRvInj();
1535 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 );
1541 case Well::InjectorCMode::RESV:
1543 std::vector<Scalar> convert_coeff(this->number_of_phases_, 1.0);
1544 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, convert_coeff);
1545 const Scalar coeff = convert_coeff[phasePos];
1546 ws.surface_rates[phasePos] = controls.reservoir_rate/coeff;
1550 case Well::InjectorCMode::THP:
1552 auto rates = ws.surface_rates;
1557 this->getRefDensity(),
1560 ws.thp = this->getTHPConstraint(summaryState);
1565 Scalar total_rate = std::accumulate(rates.begin(), rates.end(), 0.0);
1566 if (total_rate <= 0.0)
1567 ws.surface_rates = ws.well_potentials;
1571 case Well::InjectorCMode::BHP:
1573 ws.bhp = controls.bhp_limit;
1575 for (
int p = 0; p<np; ++p) {
1576 total_rate += ws.surface_rates[p];
1581 if (total_rate <= 0.0)
1582 ws.surface_rates = ws.well_potentials;
1586 case Well::InjectorCMode::GRUP:
1588 assert(well.isAvailableForGroupControl());
1589 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
1590 const Scalar efficiencyFactor = well.getEfficiencyFactor() *
1591 well_state[well.name()].efficiency_scaling_factor;
1592 std::optional<Scalar> target =
1593 this->getGroupInjectionTargetRate(group,
1598 ws.surface_rates[phasePos] = *target;
1601 case Well::InjectorCMode::CMODE_UNDEFINED:
1603 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name(), deferred_logger );
1613 ws.surface_rates[phasePos] = std::max(
Scalar{1.e-7}, ws.surface_rates[phasePos]);
1616 ws.bhp = controls.bhp_limit;
1622 const auto current = ws.production_cmode;
1623 const auto controls = this->productionControlsWithWeldraw(summaryState, ws);
1625 case Well::ProducerCMode::ORAT:
1627 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1628 Scalar current_rate = -ws.surface_rates[oil_pos];
1631 if (current_rate > 0.0) {
1632 for (
int p = 0; p<np; ++p) {
1633 ws.surface_rates[p] *= controls.oil_rate/current_rate;
1636 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1637 double control_fraction = fractions[oil_pos];
1638 if (control_fraction != 0.0) {
1639 for (
int p = 0; p<np; ++p) {
1640 ws.surface_rates[p] = - fractions[p] * controls.oil_rate/control_fraction;
1646 case Well::ProducerCMode::WRAT:
1648 const int water_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1649 Scalar current_rate = -ws.surface_rates[water_pos];
1652 if (current_rate > 0.0) {
1653 for (
int p = 0; p<np; ++p) {
1654 ws.surface_rates[p] *= controls.water_rate/current_rate;
1657 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1658 const Scalar control_fraction = fractions[water_pos];
1659 if (control_fraction != 0.0) {
1660 for (
int p = 0; p<np; ++p) {
1661 ws.surface_rates[p] = - fractions[p] * controls.water_rate / control_fraction;
1667 case Well::ProducerCMode::GRAT:
1669 const int gas_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1670 Scalar current_rate = -ws.surface_rates[gas_pos];
1673 if (current_rate > 0.0) {
1674 for (
int p = 0; p<np; ++p) {
1675 ws.surface_rates[p] *= controls.gas_rate/current_rate;
1678 const std::vector<Scalar > fractions = initialWellRateFractions(simulator, well_state);
1679 const Scalar control_fraction = fractions[gas_pos];
1680 if (control_fraction != 0.0) {
1681 for (
int p = 0; p<np; ++p) {
1682 ws.surface_rates[p] = - fractions[p] * controls.gas_rate / control_fraction;
1690 case Well::ProducerCMode::LRAT:
1692 const int water_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1693 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1694 Scalar current_rate = - ws.surface_rates[water_pos]
1695 - ws.surface_rates[oil_pos];
1698 if (current_rate > 0.0) {
1699 for (
int p = 0; p<np; ++p) {
1700 ws.surface_rates[p] *= controls.liquid_rate/current_rate;
1703 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1704 const Scalar control_fraction = fractions[water_pos] + fractions[oil_pos];
1705 if (control_fraction != 0.0) {
1706 for (
int p = 0; p<np; ++p) {
1707 ws.surface_rates[p] = - fractions[p] * controls.liquid_rate / control_fraction;
1713 case Well::ProducerCMode::CRAT:
1716 fmt::format(
"CRAT control not supported, well {}", this->name()),
1719 case Well::ProducerCMode::RESV:
1721 std::vector<Scalar> convert_coeff(this->number_of_phases_, 1.0);
1722 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, ws.surface_rates, convert_coeff);
1723 Scalar total_res_rate = 0.0;
1724 for (
int p = 0; p<np; ++p) {
1725 total_res_rate -= ws.surface_rates[p] * convert_coeff[p];
1727 if (controls.prediction_mode) {
1730 if (total_res_rate > 0.0) {
1731 for (
int p = 0; p<np; ++p) {
1732 ws.surface_rates[p] *= controls.resv_rate/total_res_rate;
1735 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1736 for (
int p = 0; p<np; ++p) {
1737 ws.surface_rates[p] = - fractions[p] * controls.resv_rate / convert_coeff[p];
1741 std::vector<Scalar> hrates(this->number_of_phases_,0.);
1742 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
1743 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
1744 hrates[phase_pos] = controls.water_rate;
1746 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1747 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
1748 hrates[phase_pos] = controls.oil_rate;
1750 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1751 const int phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
1752 hrates[phase_pos] = controls.gas_rate;
1754 std::vector<Scalar> hrates_resv(this->number_of_phases_,0.);
1755 this->rateConverter_.calcReservoirVoidageRates( 0, this->pvtRegionIdx_, hrates, hrates_resv);
1756 Scalar target = std::accumulate(hrates_resv.begin(), hrates_resv.end(), 0.0);
1759 if (total_res_rate > 0.0) {
1760 for (
int p = 0; p<np; ++p) {
1761 ws.surface_rates[p] *= target/total_res_rate;
1764 const std::vector<Scalar> fractions = initialWellRateFractions(simulator, well_state);
1765 for (
int p = 0; p<np; ++p) {
1766 ws.surface_rates[p] = - fractions[p] * target / convert_coeff[p];
1772 case Well::ProducerCMode::BHP:
1774 ws.bhp = controls.bhp_limit;
1776 for (
int p = 0; p<np; ++p) {
1777 total_rate -= ws.surface_rates[p];
1782 if (total_rate <= 0.0){
1783 for (
int p = 0; p<np; ++p) {
1784 ws.surface_rates[p] = -ws.well_potentials[p];
1789 case Well::ProducerCMode::THP:
1791 const bool update_success = updateWellStateWithTHPTargetProd(simulator, well_state, groupStateHelper);
1793 if (!update_success) {
1797 auto rates = ws.surface_rates;
1798 this->adaptRatesForVFP(rates);
1800 well_state, rates, well, summaryState, this->getRefDensity(), deferred_logger);
1802 ws.thp = this->getTHPConstraint(summaryState);
1806 const Scalar total_rate = -std::accumulate(rates.begin(), rates.end(), 0.0);
1807 if (total_rate <= 0.0) {
1808 for (
int p = 0; p < this->number_of_phases_; ++p) {
1809 ws.surface_rates[p] = -ws.well_potentials[p];
1815 case Well::ProducerCMode::GRUP:
1817 assert(well.isAvailableForGroupControl());
1818 this->updateGroupTargetFallbackFlag(well_state, deferred_logger);
1819 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
1820 const Scalar efficiencyFactor = well.getEfficiencyFactor() *
1821 well_state[well.name()].efficiency_scaling_factor;
1822 Scalar scale = this->getGroupProductionTargetRate(group,
1828 for (
int p = 0; p<np; ++p) {
1829 ws.surface_rates[p] *= scale;
1831 ws.trivial_group_target =
false;
1835 ws.trivial_group_target =
true;
1839 case Well::ProducerCMode::CMODE_UNDEFINED:
1842 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name() , deferred_logger);
1848 ws.bhp = controls.bhp_limit;
1853 template<
typename TypeTag>
1859 const auto& well_state = groupStateHelper.
wellState();
1861 const bool isGroupControlled = this->wellUnderGroupControl(well_state.well(this->index_of_well_));
1862 if (!isGroupControlled) {
1864 const auto& summaryState = groupStateHelper.
summaryState();
1865 return this->wellUnderZeroRateTargetIndividual(summaryState, well_state);
1867 return this->wellUnderZeroGroupRateTarget(groupStateHelper, isGroupControlled);
1871 template <
typename TypeTag>
1874 const std::optional<bool> group_control)
const
1876 const auto& well_state = groupStateHelper.
wellState();
1878 const bool isGroupControlled = group_control.value_or(this->wellUnderGroupControl(well_state.well(this->index_of_well_)));
1879 if (isGroupControlled) {
1880 return this->zeroGroupRateTarget(groupStateHelper);
1885 template<
typename TypeTag>
1892 return this->wellIsStopped()
1893 || this->wellUnderZeroRateTarget(groupStateHelper);
1896 template<
typename TypeTag>
1897 std::vector<typename WellInterface<TypeTag>::Scalar>
1903 const int np = this->number_of_phases_;
1904 std::vector<Scalar> scaling_factor(np);
1905 const auto& ws = well_state.
well(this->index_of_well_);
1907 Scalar total_potentials = 0.0;
1908 for (
int p = 0; p<np; ++p) {
1909 total_potentials += ws.well_potentials[p];
1911 if (total_potentials > 0) {
1912 for (
int p = 0; p<np; ++p) {
1913 scaling_factor[p] = ws.well_potentials[p] / total_potentials;
1915 return scaling_factor;
1920 const int nperf = this->number_of_local_perforations_;
1921 for (
int perf = 0; perf < nperf; ++perf) {
1922 total_tw += this->well_index_[perf];
1924 total_tw = this->parallelWellInfo().communication().sum(total_tw);
1926 for (
int perf = 0; perf < nperf; ++perf) {
1927 const int cell_idx = this->well_cells_[perf];
1928 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
1929 const auto& fs = intQuants.fluidState();
1930 const Scalar well_tw_fraction = this->well_index_[perf] / total_tw;
1931 Scalar total_mobility = 0.0;
1932 for (
int p = 0; p < np; ++p) {
1933 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
1934 total_mobility += fs.invB(canonical_phase_idx).value() * intQuants.mobility(canonical_phase_idx).value();
1936 for (
int p = 0; p < np; ++p) {
1937 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
1938 scaling_factor[p] += well_tw_fraction * fs.invB(canonical_phase_idx).value() * intQuants.mobility(canonical_phase_idx).value() / total_mobility;
1941 return scaling_factor;
1946 template <
typename TypeTag>
1953 assert(this->isProducer());
1957 auto& ws = well_state.
well(this->index_of_well_);
1958 int nonzero_rate_index = -1;
1959 const Scalar floating_point_error_epsilon = 1e-14;
1960 for (
int p = 0; p < this->number_of_phases_; ++p) {
1961 if (std::abs(ws.surface_rates[p]) > floating_point_error_epsilon) {
1962 if (nonzero_rate_index == -1) {
1963 nonzero_rate_index = p;
1972 std::vector<Scalar> well_q_s(this->number_of_phases_, 0.0);
1973 bool rates_evaluated_at_1bar =
false;
1975 const auto& summary_state = simulator.vanguard().summaryState();
1976 const auto& prod_controls = this->well_ecl_.productionControls(summary_state);
1977 const double bhp_limit = std::max(prod_controls.bhp_limit, 1.0 * unit::barsa);
1978 this->computeWellRatesWithBhp(simulator, bhp_limit, well_q_s, deferred_logger);
1980 rates_evaluated_at_1bar = (bhp_limit < 1.1 * unit::barsa);
1982 if (std::ranges::any_of(well_q_s, [](
Scalar q) {
return q > 0.0; })) {
1984 if (!rates_evaluated_at_1bar) {
1985 this->computeWellRatesWithBhp(simulator, 1.0 * unit::barsa, well_q_s, deferred_logger);
1986 rates_evaluated_at_1bar =
true;
1989 for (
auto& q : well_q_s) {
1990 q = std::min(q,
Scalar{0.0});
1995 if (nonzero_rate_index == -1) {
1999 const Scalar factor = rates_evaluated_at_1bar ? 0.5 : 1.0;
2000 for (
int p = 0; p < this->number_of_phases_; ++p) {
2001 ws.surface_rates[p] = factor * well_q_s[p];
2010 const Scalar initial_nonzero_rate = ws.surface_rates[nonzero_rate_index];
2011 const Scalar computed_rate = well_q_s[nonzero_rate_index];
2012 if (std::abs(initial_nonzero_rate) < std::abs(computed_rate)) {
2014 const Scalar factor = initial_nonzero_rate / computed_rate;
2015 assert(factor < 1.0);
2016 for (
int p = 0; p < this->number_of_phases_; ++p) {
2018 if (p != nonzero_rate_index) {
2019 ws.surface_rates[p] = factor * well_q_s[p];
2028 for (
int p = 0; p < this->number_of_phases_; ++p) {
2029 ws.surface_rates[p] = well_q_s[p];
2033 template <
typename TypeTag>
2034 template<
class Value>
2037 getTw(std::vector<Value>& Tw,
2040 const Value& trans_mult,
2043 OPM_TIMEFUNCTION_LOCAL(Subsystem::Wells);
2046 if (
static_cast<std::size_t
>(perf) >= this->well_cells_.size()) {
2047 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!");
2050 if constexpr (! Indices::gasEnabled) {
2054 const auto& wdfac = this->well_ecl_.getWDFAC();
2056 if (! wdfac.useDFactor() || (this->well_index_[perf] == 0.0)) {
2060 const Scalar d = this->computeConnectionDFactor(perf, intQuants, ws);
2067 const auto& connection = this->well_ecl_.getConnections()[ws.
perf_data.ecl_index[perf]];
2068 const Scalar Kh = connection.Kh();
2069 const Scalar scaling = std::numbers::pi * Kh * connection.wpimult();
2070 const unsigned gas_comp_idx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
2073 const Scalar cell_pressure = getValue(intQuants.fluidState().pressure(FluidSystem::gasPhaseIdx));
2074 const Scalar drawdown = cell_pressure - connection_pressure;
2075 const Scalar invB = getValue(intQuants.fluidState().invB(FluidSystem::gasPhaseIdx));
2076 const Scalar mob_g = getValue(intQuants.mobility(FluidSystem::gasPhaseIdx)) * invB;
2078 const Scalar b = 2 * scaling / getValue(Tw[gas_comp_idx]);
2079 const Scalar c = -2 * scaling * mob_g * drawdown;
2081 Scalar consistent_Q = -1.0e20;
2083 const Scalar r2n = b*b + 4*a*c;
2085 const Scalar rn = std::sqrt(r2n);
2086 const Scalar xn1 = (b-rn)*0.5/a;
2090 const Scalar xn2 = (b+rn)*0.5/a;
2091 if (xn2 <= 0 && xn2 > consistent_Q) {
2097 const Scalar r2p = b*b - 4*a*c;
2099 const Scalar rp = std::sqrt(r2p);
2100 const Scalar xp1 = (rp-b)*0.5/a;
2101 if (xp1 > 0 && xp1 < consistent_Q) {
2104 const Scalar xp2 = -(rp+b)*0.5/a;
2105 if (xp2 > 0 && xp2 < consistent_Q) {
2109 Tw[gas_comp_idx] = 1.0 / (1.0 / (trans_mult * this->well_index_[perf]) + (consistent_Q/2 * d / scaling));
2112 template <
typename TypeTag>
2118 if (! this->well_ecl_.getWDFAC().useDFactor()) {
2122 auto& d_factor = ws.
perf_data.connection_d_factor;
2124 for (
int perf = 0; perf < this->number_of_local_perforations_; ++perf) {
2125 const int cell_idx = this->well_cells_[perf];
2126 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2128 d_factor[perf] = this->computeConnectionDFactor(perf, intQuants, ws);
2132 template <
typename TypeTag>
2139 auto rhoGS = [regIdx = this->pvtRegionIdx()]() {
2140 return FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, regIdx);
2144 auto gas_visc = [connection_pressure = ws.
perf_data.pressure[perf],
2146 regIdx = this->pvtRegionIdx(), &intQuants]()
2148 const auto rv = getValue(intQuants.fluidState().Rv());
2150 const auto& gasPvt = FluidSystem::gasPvt();
2155 const Scalar rv_sat = gasPvt.saturatedOilVaporizationFactor
2156 (regIdx, temperature, connection_pressure);
2158 if (! (rv < rv_sat)) {
2159 return gasPvt.saturatedViscosity(regIdx, temperature,
2160 connection_pressure);
2163 return gasPvt.viscosity(regIdx, temperature, connection_pressure,
2164 rv, getValue(intQuants.fluidState().Rvw()));
2167 const auto& connection = this->well_ecl_.getConnections()
2170 return this->well_ecl_.getWDFAC().getDFactor(rhoGS, gas_visc, connection);
2174 template <
typename TypeTag>
2180 auto connCF = [&connIx = std::as_const(ws.
perf_data.ecl_index),
2181 &conns = this->well_ecl_.getConnections()]
2184 return conns[connIx[perf]].CF();
2187 auto obtain = [](
const Eval& value)
2189 return getValue(value);
2192 auto& tmult = ws.
perf_data.connection_compaction_tmult;
2193 auto& ctf = ws.
perf_data.connection_transmissibility_factor;
2195 for (
int perf = 0; perf < this->number_of_local_perforations_; ++perf) {
2196 const int cell_idx = this->well_cells_[perf];
2198 getTransMult(trans_mult, simulator, cell_idx, obtain);
2199 tmult[perf] = trans_mult;
2201 ctf[perf] = connCF(perf) * tmult[perf];
2206 template<
typename TypeTag>
2210 if constexpr (Indices::oilEnabled) {
2211 return fs.pressure(FluidSystem::oilPhaseIdx);
2212 }
else if constexpr (Indices::gasEnabled) {
2213 return fs.pressure(FluidSystem::gasPhaseIdx);
2215 return fs.pressure(FluidSystem::waterPhaseIdx);
2219 template <
typename TypeTag>
2220 template<
class Value,
class Callback>
2226 Callback& extendEval)
const
2228 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2229 trans_mult = simulator.problem().template wellTransMultiplier<Value>(intQuants, cell_idx, extendEval);
2232 template <
typename TypeTag>
2233 template<
class Value,
class Callback>
2237 const int local_perf_index,
2238 std::vector<Value>& mob,
2239 Callback& extendEval,
2242 auto relpermArray = []()
2244 if constexpr (std::is_same_v<Value, Scalar>) {
2245 return std::array<Scalar,3>{};
2247 return std::array<Eval,3>{};
2250 if (
static_cast<std::size_t
>(local_perf_index) >= this->well_cells_.size()) {
2251 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!");
2253 const int cell_idx = this->well_cells_[local_perf_index];
2254 assert (
int(mob.size()) == this->num_conservation_quantities_);
2255 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2256 const auto& materialLawManager = simulator.problem().materialLawManager();
2260 const int satid = this->saturation_table_number_[local_perf_index] - 1;
2261 const int satid_elem = materialLawManager->satnumRegionIdx(cell_idx);
2262 if (satid == satid_elem) {
2263 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2264 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2268 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2269 mob[activeCompIdx] = extendEval(intQuants.mobility(phaseIdx));
2271 if constexpr (has_solvent) {
2272 mob[Indices::contiSolventEqIdx] = extendEval(intQuants.solventMobility());
2275 const auto& paramsCell = materialLawManager->connectionMaterialLawParams(satid, cell_idx);
2276 auto relativePerms = relpermArray();
2277 MaterialLaw::relativePermeabilities(relativePerms, paramsCell, intQuants.fluidState());
2280 materialLawManager->connectionMaterialLawParams(satid_elem, cell_idx);
2283 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2284 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2288 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2289 mob[activeCompIdx] = extendEval(relativePerms[phaseIdx] / intQuants.fluidState().viscosity(phaseIdx));
2292 if constexpr (has_solvent) {
2293 const auto Fsolgas = intQuants.solventSaturation() / (intQuants.solventSaturation() + intQuants.fluidState().saturation(FluidSystem::gasPhaseIdx));
2295 if (Fsolgas > SolventModule::cutOff) {
2296 const unsigned activeGasCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(FluidSystem::gasPhaseIdx));
2297 const auto& ssfnKrg = SolventModule::ssfnKrg(satid);
2298 const auto& ssfnKrs = SolventModule::ssfnKrs(satid);
2299 mob[activeGasCompIdx] *= extendEval(ssfnKrg.eval(1-Fsolgas,
true));
2300 mob[Indices::contiSolventEqIdx] = extendEval(ssfnKrs.eval(Fsolgas,
true) * relativePerms[activeGasCompIdx] / intQuants.solventViscosity());
2305 if (this->isInjector() && !this->inj_fc_multiplier_.empty()) {
2306 const auto perf_ecl_index = this->perforationData()[local_perf_index].ecl_index;
2307 const auto& connections = this->well_ecl_.getConnections();
2308 const auto& connection = connections[perf_ecl_index];
2309 if (connection.filterCakeActive()) {
2310 std::ranges::transform(mob, mob.begin(),
2311 [mult = this->inj_fc_multiplier_[local_perf_index]]
2313 { return val * mult; });
2319 template<
typename TypeTag>
2328 const auto& summary_state = simulator.vanguard().summaryState();
2330 auto bhp_at_thp_limit = computeBhpAtThpLimitProdWithAlq(
2331 simulator, groupStateHelper, summary_state, this->getALQ(well_state),
false);
2332 if (bhp_at_thp_limit) {
2333 std::vector<Scalar> rates(this->number_of_phases_, 0.0);
2334 if (thp_update_iterations) {
2335 computeWellRatesWithBhpIterations(simulator, *bhp_at_thp_limit,
2336 groupStateHelper, rates);
2338 computeWellRatesWithBhp(simulator, *bhp_at_thp_limit,
2339 rates, deferred_logger);
2341 auto& ws = well_state.
well(this->name());
2342 ws.surface_rates = rates;
2343 ws.bhp = *bhp_at_thp_limit;
2344 ws.thp = this->getTHPConstraint(summary_state);
2351 template<
typename TypeTag>
2352 std::optional<typename WellInterface<TypeTag>::Scalar>
2357 const SummaryState& summary_state,
2362 const auto& groupStateHelper = simulator.problem().wellModel().groupStateHelper();
2364 auto well_guard = groupStateHelper_copy.
pushWellState(well_state_copy);
2365 const double dt = simulator.timeStepSize();
2366 const bool converged = this->solveWellWithBhp(
2367 simulator, dt, bhp, groupStateHelper_copy, well_state_copy
2371 auto rates = well_state_copy.
well(this->index_of_well_).surface_rates;
2373 for (std::size_t p = 0; p < rates.size(); ++p) {
2374 zero_rates &= rates[p] == 0.0;
2378 if (zero_rates || !converged) {
2379 return this->computeBhpAtThpLimitProdWithAlq(simulator, groupStateHelper_copy, summary_state, alq_value,
false);
2381 this->updateIPRImplicit(simulator, groupStateHelper_copy, well_state_copy);
2382 this->adaptRatesForVFP(rates);
2386 template <
typename TypeTag>
2391 const std::vector<Scalar>& mobility,
2394 const int np = this->number_of_phases_;
2395 for (
int p = 0; p < np; ++p) {
2398 const int canonical_phase_idx = FluidSystem::activeToCanonicalPhaseIdx(p);
2399 const auto connMob =
2400 mobility[FluidSystem::activePhaseToActiveCompIdx(p)] * fs.invB(canonical_phase_idx).value();
2402 connPI[p] = connPICalc(connMob);
2405 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) &&
2406 FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx))
2408 const auto io = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
2409 const auto ig = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
2411 const auto vapoil = connPI[ig] * fs.Rv().value();
2412 const auto disgas = connPI[io] * fs.Rs().value();
2414 connPI[io] += vapoil;
2415 connPI[ig] += disgas;
2420 template <
typename TypeTag>
2424 const Phase preferred_phase,
2426 const std::vector<Scalar>& mobility,
2431 if (preferred_phase == Phase::GAS) {
2432 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
2434 else if (preferred_phase == Phase::OIL) {
2435 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
2437 else if (preferred_phase == Phase::WATER) {
2438 phase_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
2442 fmt::format(
"Unsupported Injector Type ({}) "
2443 "for well {} during connection I.I. calculation",
2444 static_cast<int>(preferred_phase), this->name()),
2448 const auto mt = std::accumulate(mobility.begin(), mobility.end(), 0.0);
2449 const int canonicalPhaseIdx = FluidSystem::activeToCanonicalPhaseIdx(phase_pos);
2450 connII[phase_pos] = connIICalc(mt * fs.invB(canonicalPhaseIdx).value());
2453 template<
typename TypeTag>
2454 template<
class GasLiftSingleWell>
2455 std::unique_ptr<GasLiftSingleWell>
2464 auto& comm = simulator.vanguard().grid().comm();
2465 ecl_well_map.try_emplace(this->name(), &(this->wellEcl()), this->indexOfWell());
2466 const auto& iterCtx = simulator.problem().iterationContext();
2469 simulator.vanguard().schedule(),
2470 simulator.vanguard().summaryState(),
2471 simulator.episodeIndex(),
2481 std::set<int> sync_groups;
2482 const auto& summary_state = simulator.vanguard().summaryState();
2483 return std::make_unique<GasLiftSingleWell>(*
this,
2497 template <
typename TypeTag>
2504 if (this->well_cells_.size() > 0) {
2508 const int cell_idx = this->well_cells_[0];
2509 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2510 const auto& fs = intQuants.fluidState();
2512 info.
temperature = getValue(fs.temperature(FluidSystem::oilPhaseIdx));
2513 info.saltConcentration = getValue(fs.saltConcentration());
2519 return this->parallel_well_info_.communication().size() == 1
2521 : this->parallel_well_info_.broadcastFirstPerforationValue(info);
#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)
void warning(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:217
Definition: SingleWellState.hpp:44
Scalar temperature
Definition: SingleWellState.hpp:111
PerfData< Scalar > perf_data
Definition: SingleWellState.hpp:160
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:358
int number_of_local_perforations_
Definition: WellInterfaceGeneric.hpp:396
FluidSystem::Scalar wsolvent_
Definition: WellInterfaceGeneric.hpp:436
Definition: WellInterfaceIndices.hpp:34
bool stoppedOrZeroRateTarget(const GroupStateHelperType &groupStateHelper) const
Definition: WellInterface_impl.hpp:1888
bool updateWellOperabilityFromWellEq(const Simulator &simulator, const GroupStateHelperType &groupStateHelper)
Definition: WellInterface_impl.hpp:1439
void checkWellOperability(const Simulator &simulator, const WellStateType &well_state, const GroupStateHelperType &groupStateHelper)
Definition: WellInterface_impl.hpp:1311
void updateWellOperability(const Simulator &simulator, const WellStateType &well_state, const GroupStateHelperType &groupStateHelper)
Definition: WellInterface_impl.hpp:1401
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:735
Scalar woxygen() const
Definition: WellInterface_impl.hpp:168
IndividualOrGroup
Definition: WellInterface.hpp:258
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: WellInterface.hpp:84
void assembleWellEqWithoutIteration(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, const double dt, WellStateType &well_state, const bool solving_with_zero_rate)
Definition: WellInterface_impl.hpp:1108
Scalar computeConnectionDFactor(const int perf, const IntensiveQuantities &intQuants, const SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:2135
void updateWeldrawMaxRate(const Simulator &simulator, WellStateType &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:289
typename WellInterfaceFluidSystem< FluidSystem >::RateConverterType RateConverterType
Definition: WellInterface.hpp:110
Scalar wfoam() const
Definition: WellInterface_impl.hpp:130
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:381
void getTransMult(Value &trans_mult, const Simulator &simulator, const int cell_idx, Callback &extendEval) const
Definition: WellInterface_impl.hpp:2223
std::vector< RateVector > connectionRates_
Definition: WellInterface.hpp:403
bool solveWellForTesting(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:974
void computeConnLevelProdInd(const FluidState &fs, const std::function< Scalar(const Scalar)> &connPICalc, const std::vector< Scalar > &mobility, Scalar *connPI) const
Definition: WellInterface_impl.hpp:2389
void gliftBeginTimeStepWellTestUpdateALQ(const Simulator &simulator, WellStateType &well_state, const GroupState< Scalar > &group_state, GLiftEclWells &ecl_well_map, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:1339
Scalar volumetricSurfaceRateForConnection(int cellIdx, int phaseIdx) const
Definition: WellInterface_impl.hpp:1291
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:98
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:2354
void getTw(std::vector< Value > &wi, const int perf, const IntensiveQuantities &intQuants, const Value &trans_mult, const SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:2037
void getMobility(const Simulator &simulator, const int local_perf_index, std::vector< Value > &mob, Callback &extendEval, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:2236
GetPropType< TypeTag, Properties::IntensiveQuantities > IntensiveQuantities
Definition: WellInterface.hpp:89
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: WellInterface.hpp:85
std::vector< Scalar > initialWellRateFractions(const Simulator &ebosSimulator, const WellStateType &well_state) const
Definition: WellInterface_impl.hpp:1899
void solveWellEquation(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:1030
void updateConnectionDFactor(const Simulator &simulator, SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:2115
Eval getPerfCellPressure(const FluidState &fs) const
Definition: WellInterface_impl.hpp:2208
void initializeProducerWellState(const Simulator &simulator, WellStateType &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1949
virtual void updateWellStateWithTarget(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state) const
Definition: WellInterface_impl.hpp:1469
void addCellRates(std::map< int, RateVector > &cellRates_) const
Definition: WellInterface_impl.hpp:1272
typename Base::ModelParameters ModelParameters
Definition: WellInterface.hpp:116
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: WellInterface.hpp:86
static constexpr bool has_solvent
Definition: WellInterface.hpp:118
bool wellUnderZeroRateTarget(const GroupStateHelperType &groupStateHelper) const
Definition: WellInterface_impl.hpp:1856
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: WellInterface.hpp:92
void updateConnectionTransmissibilityFactor(const Simulator &simulator, SingleWellStateType &ws) const
Definition: WellInterface_impl.hpp:2177
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:2423
typename GasLiftGroupInfo< Scalar, IndexTraits >::GLiftEclWells GLiftEclWells
Definition: WellInterface.hpp:94
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:2457
BlackOilFluidStateType< Eval > FluidState
Definition: WellInterface.hpp:148
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:855
Scalar wsalt() const
Definition: WellInterface_impl.hpp:144
bool solveWellWithZeroRate(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:942
bool wellUnderZeroGroupRateTarget(const GroupStateHelperType &groupStateHelper, const std::optional< bool > group_control=std::nullopt) const
Definition: WellInterface_impl.hpp:1873
bool solveWellWithBhp(const Simulator &simulator, const double dt, const Scalar bhp, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:892
void prepareWellBeforeAssembling(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:1145
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:500
typename Base::Eval Eval
Definition: WellInterface.hpp:98
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:61
bool updateWellStateWithTHPTargetProd(const Simulator &simulator, WellStateType &well_state, const GroupStateHelperType &groupStateHelper) const
Definition: WellInterface_impl.hpp:2322
bool iterateWellEquations(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:657
Scalar wpolymer() const
Definition: WellInterface_impl.hpp:114
GetPropType< TypeTag, Properties::Indices > Indices
Definition: WellInterface.hpp:88
bool updateWellControl(const Simulator &simulator, const IndividualOrGroup iog, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:192
Scalar wurea() const
Definition: WellInterface_impl.hpp:180
void updateGroupTargetFallbackFlag(WellStateType &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1130
FSInfo getFirstPerfCellConditions(const Simulator &simulator) const
Temperature and salt concentration of the first perforated cell, broadcast so that all processes of a...
Definition: WellInterface_impl.hpp:2499
void assembleWellEq(const Simulator &simulator, const double dt, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:1092
Scalar wmicrobes() const
Definition: WellInterface_impl.hpp:156
virtual void scaleSegmentRatesAndPressure(WellStateType &well_state) const
Definition: WellInterface_impl.hpp:1461
static constexpr bool has_zFraction
Definition: WellInterface.hpp:119
Definition: WellState.hpp:68
constexpr int numPhases() const
The number of phases present.
Definition: WellState.hpp:274
const SingleWellState< Scalar, IndexTraits > & well(std::size_t well_index) const
Definition: WellState.hpp:315
bool isOpen(const std::string &name) const
Definition: WellState.hpp:222
@ 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)
Reservoir temperature and salt concentration of the first perforated cell.
Definition: ParallelWellInfo.hpp:44
Scalar temperature
Definition: ParallelWellInfo.hpp:45
Static data associated with a well perforation.
Definition: PerforationData.hpp:30