22 #include <opm/input/eclipse/Schedule/ScheduleTypes.hpp>
23 #include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
24 #include <opm/simulators/wells/GroupState.hpp>
25 #include <opm/simulators/wells/TargetCalculator.hpp>
27 #include <dune/common/version.hh>
33 template<
typename TypeTag>
39 const RateConverterType& rate_converter,
40 const int pvtRegionIdx,
41 const int num_components,
43 const int index_of_well,
44 const std::vector<PerforationData>& perf_data)
56 connectionRates_.resize(this->number_of_perforations_);
58 if constexpr (has_solvent || has_zFraction) {
59 if (well.isInjector()) {
60 auto injectorType = this->well_ecl_.injectorType();
61 if (injectorType == InjectorType::GAS) {
62 this->wsolvent_ = this->well_ecl_.getSolventFraction();
69 template<
typename TypeTag>
73 const std::vector<double>& ,
74 const double gravity_arg,
76 const std::vector< Scalar >& B_avg)
78 this->phase_usage_ = phase_usage_arg;
79 this->gravity_ = gravity_arg;
86 template<
typename TypeTag>
88 WellInterface<TypeTag>::
91 if constexpr (has_polymer) {
92 auto injectorType = this->well_ecl_.injectorType();
94 if (injectorType == InjectorType::WATER) {
95 WellPolymerProperties polymer = this->well_ecl_.getPolymerProperties();
96 const double polymer_injection_concentration = polymer.m_polymerConcentration;
97 return polymer_injection_concentration;
111 template<
typename TypeTag>
113 WellInterface<TypeTag>::
116 if constexpr (has_foam) {
117 auto injectorType = this->well_ecl_.injectorType();
119 if (injectorType == InjectorType::GAS) {
120 WellFoamProperties fprop = this->well_ecl_.getFoamProperties();
121 return fprop.m_foamConcentration;
133 template<
typename TypeTag>
135 WellInterface<TypeTag>::
138 if constexpr (has_brine) {
139 auto injectorType = this->well_ecl_.injectorType();
141 if (injectorType == InjectorType::WATER) {
142 WellBrineProperties fprop = this->well_ecl_.getBrineProperties();
143 return fprop.m_saltConcentration;
153 template<
typename TypeTag>
155 WellInterface<TypeTag>::
158 if constexpr (has_micp) {
159 auto injectorType = this->well_ecl_.injectorType();
161 if (injectorType == InjectorType::WATER) {
162 WellMICPProperties microbes = this->well_ecl_.getMICPProperties();
163 const double microbial_injection_concentration = microbes.m_microbialConcentration;
164 return microbial_injection_concentration;
174 template<
typename TypeTag>
176 WellInterface<TypeTag>::
179 if constexpr (has_micp) {
180 auto injectorType = this->well_ecl_.injectorType();
182 if (injectorType == InjectorType::WATER) {
183 WellMICPProperties oxygen = this->well_ecl_.getMICPProperties();
184 const double oxygen_injection_concentration = oxygen.m_oxygenConcentration;
185 return oxygen_injection_concentration;
201 template<
typename TypeTag>
203 WellInterface<TypeTag>::
206 if constexpr (has_micp) {
207 auto injectorType = this->well_ecl_.injectorType();
209 if (injectorType == InjectorType::WATER) {
210 WellMICPProperties urea = this->well_ecl_.getMICPProperties();
211 const double urea_injection_concentration = urea.m_ureaConcentration / 10.;
212 return urea_injection_concentration;
222 template<
typename TypeTag>
224 WellInterface<TypeTag>::
225 updateWellControl(
const Simulator& ebos_simulator,
226 const IndividualOrGroup iog,
227 WellState& well_state,
228 const GroupState& group_state,
229 DeferredLogger& deferred_logger)
231 if (this->wellIsStopped()) {
235 const auto& summaryState = ebos_simulator.vanguard().summaryState();
236 const auto& schedule = ebos_simulator.vanguard().schedule();
237 const auto& well = this->well_ecl_;
238 auto& ws = well_state.well(this->index_of_well_);
240 if (well.isInjector()) {
241 from = Well::InjectorCMode2String(ws.injection_cmode);
243 from = Well::ProducerCMode2String(ws.production_cmode);
245 bool oscillating = std::count(this->well_control_log_.begin(), this->well_control_log_.end(), from) >= param_.max_number_of_well_switches_;
249 bool output = std::count(this->well_control_log_.begin(), this->well_control_log_.end(), from) == param_.max_number_of_well_switches_;
251 std::ostringstream ss;
252 ss <<
" The control model for well " << this->name()
253 <<
" is oscillating\n"
254 <<
" We don't allow for more than "
255 << param_.max_number_of_well_switches_
256 <<
" switches. The control is kept at " << from;
257 deferred_logger.info(ss.str());
259 this->well_control_log_.push_back(from);
263 bool changed =
false;
264 if (iog == IndividualOrGroup::Individual) {
265 changed = this->checkIndividualConstraints(ws, summaryState, deferred_logger);
266 }
else if (iog == IndividualOrGroup::Group) {
267 changed = this->checkGroupConstraints(well_state, group_state, schedule, summaryState, deferred_logger);
269 assert(iog == IndividualOrGroup::Both);
270 changed = this->checkConstraints(well_state, group_state, schedule, summaryState, deferred_logger);
272 Parallel::Communication cc = ebos_simulator.vanguard().grid().comm();
276 if (well.isInjector()) {
277 to = Well::InjectorCMode2String(ws.injection_cmode);
279 to = Well::ProducerCMode2String(ws.production_cmode);
281 std::ostringstream ss;
282 ss <<
" Switching control mode for well " << this->name()
286 ss <<
" on rank " << cc.rank();
288 deferred_logger.debug(ss.str());
290 this->well_control_log_.push_back(from);
291 updateWellStateWithTarget(ebos_simulator, group_state, well_state, deferred_logger);
292 updatePrimaryVariables(well_state, deferred_logger);
300 template<
typename TypeTag>
302 WellInterface<TypeTag>::
303 wellTesting(
const Simulator& simulator,
304 const double simulation_time,
305 WellState& well_state,
306 const GroupState& group_state,
307 WellTestState& well_test_state,
308 DeferredLogger& deferred_logger)
310 deferred_logger.info(
" well " + this->name() +
" is being tested");
312 WellState well_state_copy = well_state;
313 auto& ws = well_state_copy.well(this->indexOfWell());
315 updateWellStateWithTarget(simulator, group_state, well_state_copy, deferred_logger);
316 calculateExplicitQuantities(simulator, well_state_copy, deferred_logger);
317 updatePrimaryVariables(well_state_copy, deferred_logger);
318 initPrimaryVariablesEvaluation();
320 WellTestState welltest_state_temp;
322 bool testWell =
true;
327 const size_t original_number_closed_completions = welltest_state_temp.num_closed_completions();
328 bool converged = solveWellForTesting(simulator, well_state_copy, group_state, deferred_logger);
330 const auto msg = fmt::format(
"WTEST: Well {} is not solvable (physical)", this->name());
331 deferred_logger.debug(msg);
335 updateWellOperability(simulator, well_state_copy, deferred_logger);
336 if ( !this->isOperableAndSolvable() ) {
337 const auto msg = fmt::format(
"WTEST: Well {} is not operable (physical)", this->name());
338 deferred_logger.debug(msg);
342 std::vector<double> potentials;
344 computeWellPotentials(simulator, well_state_copy, potentials, deferred_logger);
345 }
catch (
const std::exception& e) {
346 const std::string msg = std::string(
"well ") + this->name() + std::string(
": computeWellPotentials() failed during testing for re-opening: ") + e.what();
347 deferred_logger.info(msg);
350 const int np = well_state_copy.numPhases();
351 for (
int p = 0; p < np; ++p) {
352 ws.well_potentials[p] = std::max(0.0, potentials[p]);
354 this->updateWellTestState(well_state_copy.well(this->indexOfWell()), simulation_time,
false, welltest_state_temp, deferred_logger);
355 this->closeCompletions(welltest_state_temp);
361 if ( welltest_state_temp.num_closed_wells() > 0 ||
362 (original_number_closed_completions == welltest_state_temp.num_closed_completions()) ) {
368 if (!welltest_state_temp.well_is_closed(this->name())) {
369 well_test_state.open_well(this->name());
371 std::string msg = std::string(
"well ") + this->name() + std::string(
" is re-opened");
372 deferred_logger.info(msg);
375 for (
auto& completion : this->well_ecl_.getCompletions()) {
376 if (!welltest_state_temp.completion_is_closed(this->name(), completion.first))
377 well_test_state.open_completion(this->name(), completion.first);
381 well_state = well_state_copy;
388 template<
typename TypeTag>
390 WellInterface<TypeTag>::
391 iterateWellEquations(
const Simulator& ebosSimulator,
393 WellState& well_state,
394 const GroupState& group_state,
395 DeferredLogger& deferred_logger)
397 const auto& summary_state = ebosSimulator.vanguard().summaryState();
398 const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
399 const auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
400 bool converged =
false;
402 converged = this->iterateWellEqWithControl(ebosSimulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
403 }
catch (NumericalIssue& e ) {
404 const std::string msg =
"Inner well iterations failed for well " + this->name() +
" Treat the well as unconverged. ";
405 deferred_logger.warning(
"INNER_ITERATION_FAILED", msg);
412 template<
typename TypeTag>
414 WellInterface<TypeTag>::
415 solveWellForTesting(
const Simulator& ebosSimulator, WellState& well_state,
const GroupState& group_state,
416 DeferredLogger& deferred_logger)
419 const WellState well_state0 = well_state;
420 const double dt = ebosSimulator.timeStepSize();
421 const auto& summary_state = ebosSimulator.vanguard().summaryState();
422 const bool has_thp_limit = this->wellHasTHPConstraints(summary_state);
424 well_state.well(this->indexOfWell()).production_cmode = Well::ProducerCMode::THP;
426 well_state.well(this->indexOfWell()).production_cmode = Well::ProducerCMode::BHP;
428 const bool converged = iterateWellEquations(ebosSimulator, dt, well_state, group_state, deferred_logger);
430 deferred_logger.debug(
"WellTest: Well equation for well " + this->name() +
" converged");
433 const int max_iter = param_.max_welleq_iter_;
434 deferred_logger.debug(
"WellTest: Well equation for well " + this->name() +
" failed converging in "
435 + std::to_string(max_iter) +
" iterations");
436 well_state = well_state0;
441 template<
typename TypeTag>
443 WellInterface<TypeTag>::
444 solveWellEquation(
const Simulator& ebosSimulator,
445 WellState& well_state,
446 const GroupState& group_state,
447 DeferredLogger& deferred_logger)
449 if (!this->isOperableAndSolvable() && !this->wellIsStopped())
453 const WellState well_state0 = well_state;
454 const double dt = ebosSimulator.timeStepSize();
455 const bool converged = iterateWellEquations(ebosSimulator, dt, well_state, group_state, deferred_logger);
457 const int max_iter = param_.max_welleq_iter_;
458 deferred_logger.debug(
"Compute initial well solution for well " + this->name() +
". Failed to converge in "
459 + std::to_string(max_iter) +
" iterations");
460 well_state = well_state0;
466 template <
typename TypeTag>
468 WellInterface<TypeTag>::
469 assembleWellEq(
const Simulator& ebosSimulator,
471 WellState& well_state,
472 const GroupState& group_state,
473 DeferredLogger& deferred_logger)
475 const bool old_well_operable = this->operability_status_.isOperableAndSolvable();
477 if (param_.check_well_operability_iter_)
478 checkWellOperability(ebosSimulator, well_state, deferred_logger);
481 const int iteration_idx = ebosSimulator.model().newtonMethod().numIterations();
482 if (iteration_idx < param_.max_niter_inner_well_iter_ || this->well_ecl_.isMultiSegment()) {
483 this->operability_status_.solvable =
true;
484 bool converged = this->iterateWellEquations(ebosSimulator, dt, well_state, group_state, deferred_logger);
488 if (param_.shut_unsolvable_wells_)
489 this->operability_status_.solvable =
false;
492 if (this->operability_status_.has_negative_potentials) {
493 auto well_state_copy = well_state;
494 std::vector<double> potentials;
496 computeWellPotentials(ebosSimulator, well_state_copy, potentials, deferred_logger);
497 }
catch (
const std::exception& e) {
498 const std::string msg = std::string(
"well ") + this->name() + std::string(
": computeWellPotentials() failed during attempt to recompute potentials for well : ") + e.what();
499 deferred_logger.info(msg);
500 this->operability_status_.has_negative_potentials =
true;
502 auto& ws = well_state.well(this->indexOfWell());
503 const int np = well_state.numPhases();
504 for (
int p = 0; p < np; ++p) {
505 ws.well_potentials[p] = std::max(0.0, potentials[p]);
508 this->changed_to_open_this_step_ =
false;
509 const bool well_operable = this->operability_status_.isOperableAndSolvable();
511 if (!well_operable && old_well_operable) {
512 if (this->well_ecl_.getAutomaticShutIn()) {
513 deferred_logger.info(
" well " + this->name() +
" gets SHUT during iteration ");
515 if (!this->wellIsStopped()) {
516 deferred_logger.info(
" well " + this->name() +
" gets STOPPED during iteration ");
518 changed_to_stopped_this_step_ =
true;
521 }
else if (well_operable && !old_well_operable) {
522 deferred_logger.info(
" well " + this->name() +
" gets REVIVED during iteration ");
524 changed_to_stopped_this_step_ =
false;
525 this->changed_to_open_this_step_ =
true;
528 const auto& summary_state = ebosSimulator.vanguard().summaryState();
529 const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
530 const auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
531 assembleWellEqWithoutIteration(ebosSimulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
536 template<
typename TypeTag>
538 WellInterface<TypeTag>::addCellRates(RateVector& rates,
int cellIdx)
const
540 if(!this->isOperableAndSolvable() && !this->wellIsStopped())
543 for (
int perfIdx = 0; perfIdx < this->number_of_perforations_; ++perfIdx) {
544 if (this->cells()[perfIdx] == cellIdx) {
545 for (
int i = 0; i < RateVector::dimension; ++i) {
546 rates[i] += connectionRates_[perfIdx][i];
552 template<
typename TypeTag>
553 typename WellInterface<TypeTag>::Scalar
554 WellInterface<TypeTag>::volumetricSurfaceRateForConnection(
int cellIdx,
int phaseIdx)
const {
555 for (
int perfIdx = 0; perfIdx < this->number_of_perforations_; ++perfIdx) {
556 if (this->cells()[perfIdx] == cellIdx) {
557 const unsigned activeCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::solventComponentIndex(phaseIdx));
558 return connectionRates_[perfIdx][activeCompIdx].value();
562 OPM_THROW(std::invalid_argument,
"The well with name " + this->name()
563 +
" does not perforate cell " + std::to_string(cellIdx));
570 template<
typename TypeTag>
572 WellInterface<TypeTag>::
573 checkWellOperability(
const Simulator& ebos_simulator,
574 const WellState& well_state,
575 DeferredLogger& deferred_logger)
578 if (!param_.check_well_operability_) {
582 if (this->wellIsStopped() && !changed_to_stopped_this_step_) {
586 updateWellOperability(ebos_simulator, well_state, deferred_logger);
591 template<
typename TypeTag>
593 WellInterface<TypeTag>::
594 updateWellOperability(
const Simulator& ebos_simulator,
595 const WellState& well_state,
596 DeferredLogger& deferred_logger)
598 this->operability_status_.resetOperability();
600 bool thp_controled = this->isInjector() ? well_state.well(this->index_of_well_).injection_cmode == Well::InjectorCMode::THP:
601 well_state.well(this->index_of_well_).production_cmode == Well::ProducerCMode::THP;
602 bool bhp_controled = this->isInjector() ? well_state.well(this->index_of_well_).injection_cmode == Well::InjectorCMode::BHP:
603 well_state.well(this->index_of_well_).production_cmode == Well::ProducerCMode::BHP;
607 bool check_thp = thp_controled || this->operability_status_.thp_limit_violated_but_not_switched;
608 if (check_thp || bhp_controled) {
609 updateIPR(ebos_simulator, deferred_logger);
610 checkOperabilityUnderBHPLimit(well_state, ebos_simulator, deferred_logger);
614 checkOperabilityUnderTHPLimit(ebos_simulator, well_state, deferred_logger);
619 template<
typename TypeTag>
621 WellInterface<TypeTag>::
622 updateWellStateWithTarget(
const Simulator& ebos_simulator,
623 const GroupState& group_state,
624 WellState& well_state,
625 DeferredLogger& deferred_logger)
const
629 const auto& well = this->well_ecl_;
630 const int well_index = this->index_of_well_;
631 auto& ws = well_state.well(well_index);
633 const int np = well_state.numPhases();
634 const auto& summaryState = ebos_simulator.vanguard().summaryState();
635 const auto& schedule = ebos_simulator.vanguard().schedule();
637 if (this->wellIsStopped()) {
638 for (
int p = 0; p<np; ++p) {
639 ws.surface_rates[p] = 0;
645 if (this->isInjector() )
647 const auto& controls = well.injectionControls(summaryState);
649 InjectorType injectorType = controls.injector_type;
651 switch (injectorType) {
652 case InjectorType::WATER:
654 phasePos = pu.phase_pos[BlackoilPhases::Aqua];
657 case InjectorType::OIL:
659 phasePos = pu.phase_pos[BlackoilPhases::Liquid];
662 case InjectorType::GAS:
664 phasePos = pu.phase_pos[BlackoilPhases::Vapour];
668 OPM_DEFLOG_THROW(std::runtime_error,
"Expected WATER, OIL or GAS as type for injectors " + this->name(), deferred_logger );
671 const auto current = ws.injection_cmode;
674 case Well::InjectorCMode::RATE:
676 ws.surface_rates[phasePos] = controls.surface_rate;
680 case Well::InjectorCMode::RESV:
682 std::vector<double> convert_coeff(this->number_of_phases_, 1.0);
683 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, convert_coeff);
684 const double coeff = convert_coeff[phasePos];
685 ws.surface_rates[phasePos] = controls.reservoir_rate/coeff;
689 case Well::InjectorCMode::THP:
691 auto rates = ws.surface_rates;
692 double bhp = this->calculateBhpFromThp(well_state, rates, well, summaryState, this->getRefDensity(), deferred_logger);
698 double total_rate = std::accumulate(rates.begin(), rates.end(), 0.0);
699 if (total_rate <= 0.0)
700 ws.surface_rates = ws.well_potentials;
704 case Well::InjectorCMode::BHP:
706 ws.bhp = controls.bhp_limit;
707 double total_rate = 0.0;
708 for (
int p = 0; p<np; ++p) {
709 total_rate += ws.surface_rates[p];
714 if (total_rate <= 0.0)
715 ws.surface_rates = ws.well_potentials;
719 case Well::InjectorCMode::GRUP:
721 assert(well.isAvailableForGroupControl());
722 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
723 const double efficiencyFactor = well.getEfficiencyFactor();
724 std::optional<double> target =
725 this->getGroupInjectionTargetRate(group,
734 ws.surface_rates[phasePos] = *target;
737 case Well::InjectorCMode::CMODE_UNDEFINED:
739 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name(), deferred_logger );
747 const auto current = ws.production_cmode;
748 const auto& controls = well.productionControls(summaryState);
750 case Well::ProducerCMode::ORAT:
752 double current_rate = -ws.surface_rates[ pu.phase_pos[Oil] ];
755 if (current_rate > 0.0) {
756 for (
int p = 0; p<np; ++p) {
757 ws.surface_rates[p] *= controls.oil_rate/current_rate;
760 const std::vector<double> fractions = initialWellRateFractions(ebos_simulator, well_state);
761 double control_fraction = fractions[pu.phase_pos[Oil]];
762 if (control_fraction != 0.0) {
763 for (
int p = 0; p<np; ++p) {
764 ws.surface_rates[p] = - fractions[p] * controls.oil_rate/control_fraction;
770 case Well::ProducerCMode::WRAT:
772 double current_rate = -ws.surface_rates[ pu.phase_pos[Water] ];
775 if (current_rate > 0.0) {
776 for (
int p = 0; p<np; ++p) {
777 ws.surface_rates[p] *= controls.water_rate/current_rate;
780 const std::vector<double> fractions = initialWellRateFractions(ebos_simulator, well_state);
781 double control_fraction = fractions[pu.phase_pos[Water]];
782 if (control_fraction != 0.0) {
783 for (
int p = 0; p<np; ++p) {
784 ws.surface_rates[p] = - fractions[p] * controls.water_rate/control_fraction;
790 case Well::ProducerCMode::GRAT:
792 double current_rate = -ws.surface_rates[pu.phase_pos[Gas] ];
795 if (current_rate > 0.0) {
796 for (
int p = 0; p<np; ++p) {
797 ws.surface_rates[p] *= controls.gas_rate/current_rate;
800 const std::vector<double> fractions = initialWellRateFractions(ebos_simulator, well_state);
801 double control_fraction = fractions[pu.phase_pos[Gas]];
802 if (control_fraction != 0.0) {
803 for (
int p = 0; p<np; ++p) {
804 ws.surface_rates[p] = - fractions[p] * controls.gas_rate/control_fraction;
812 case Well::ProducerCMode::LRAT:
814 double current_rate = -ws.surface_rates[ pu.phase_pos[Water] ]
815 - ws.surface_rates[ pu.phase_pos[Oil] ];
818 if (current_rate > 0.0) {
819 for (
int p = 0; p<np; ++p) {
820 ws.surface_rates[p] *= controls.liquid_rate/current_rate;
823 const std::vector<double> fractions = initialWellRateFractions(ebos_simulator, well_state);
824 double control_fraction = fractions[pu.phase_pos[Water]] + fractions[pu.phase_pos[Oil]];
825 if (control_fraction != 0.0) {
826 for (
int p = 0; p<np; ++p) {
827 ws.surface_rates[p] = - fractions[p] * controls.liquid_rate / control_fraction;
833 case Well::ProducerCMode::CRAT:
835 OPM_DEFLOG_THROW(std::runtime_error,
"CRAT control not supported " << this->name(), deferred_logger);
837 case Well::ProducerCMode::RESV:
839 std::vector<double> convert_coeff(this->number_of_phases_, 1.0);
840 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, convert_coeff);
841 double total_res_rate = 0.0;
842 for (
int p = 0; p<np; ++p) {
843 total_res_rate -= ws.surface_rates[p] * convert_coeff[p];
845 if (controls.prediction_mode) {
848 if (total_res_rate > 0.0) {
849 for (
int p = 0; p<np; ++p) {
850 ws.surface_rates[p] *= controls.resv_rate/total_res_rate;
853 const std::vector<double> fractions = initialWellRateFractions(ebos_simulator, well_state);
854 for (
int p = 0; p<np; ++p) {
855 ws.surface_rates[p] = - fractions[p] * controls.resv_rate / convert_coeff[p];
859 std::vector<double> hrates(this->number_of_phases_,0.);
860 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
861 hrates[pu.phase_pos[Water]] = controls.water_rate;
863 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
864 hrates[pu.phase_pos[Oil]] = controls.oil_rate;
866 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
867 hrates[pu.phase_pos[Gas]] = controls.gas_rate;
869 std::vector<double> hrates_resv(this->number_of_phases_,0.);
870 this->rateConverter_.calcReservoirVoidageRates( 0, this->pvtRegionIdx_, hrates, hrates_resv);
871 double target = std::accumulate(hrates_resv.begin(), hrates_resv.end(), 0.0);
874 if (total_res_rate > 0.0) {
875 for (
int p = 0; p<np; ++p) {
876 ws.surface_rates[p] *= target/total_res_rate;
879 const std::vector<double> fractions = initialWellRateFractions(ebos_simulator, well_state);
880 for (
int p = 0; p<np; ++p) {
881 ws.surface_rates[p] = - fractions[p] * target / convert_coeff[p];
888 case Well::ProducerCMode::BHP:
890 ws.bhp = controls.bhp_limit;
891 double total_rate = 0.0;
892 for (
int p = 0; p<np; ++p) {
893 total_rate -= ws.surface_rates[p];
898 if (total_rate <= 0.0){
899 for (
int p = 0; p<np; ++p) {
900 ws.surface_rates[p] = -ws.well_potentials[p];
905 case Well::ProducerCMode::THP:
907 auto rates = ws.surface_rates;
908 this->adaptRatesForVFP(rates);
909 double bhp = this->calculateBhpFromThp(well_state, rates, well, summaryState, this->getRefDensity(), deferred_logger);
915 double total_rate = -std::accumulate(rates.begin(), rates.end(), 0.0);
916 if (total_rate <= 0.0){
917 for (
int p = 0; p<np; ++p) {
918 ws.surface_rates[p] = -ws.well_potentials[p];
923 case Well::ProducerCMode::GRUP:
925 assert(well.isAvailableForGroupControl());
926 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
927 const double efficiencyFactor = well.getEfficiencyFactor();
928 double scale = this->getGroupProductionTargetRate(group,
937 for (
int p = 0; p<np; ++p) {
938 ws.surface_rates[p] *= scale;
943 case Well::ProducerCMode::CMODE_UNDEFINED:
944 case Well::ProducerCMode::NONE:
946 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name() , deferred_logger);
954 template<
typename TypeTag>
956 WellInterface<TypeTag>::
957 initialWellRateFractions(
const Simulator& ebosSimulator,
const WellState& well_state)
const
959 const int np = this->number_of_phases_;
960 std::vector<double> scaling_factor(np);
961 const auto& ws = well_state.well(this->index_of_well_);
963 double total_potentials = 0.0;
964 for (
int p = 0; p<np; ++p) {
965 total_potentials += ws.well_potentials[p];
967 if (total_potentials > 0) {
968 for (
int p = 0; p<np; ++p) {
969 scaling_factor[p] = ws.well_potentials[p] / total_potentials;
971 return scaling_factor;
976 const int nperf = this->number_of_perforations_;
977 for (
int perf = 0; perf < nperf; ++perf) {
978 total_tw += this->well_index_[perf];
980 for (
int perf = 0; perf < nperf; ++perf) {
981 const int cell_idx = this->well_cells_[perf];
982 const auto& intQuants = *(ebosSimulator.model().cachedIntensiveQuantities(cell_idx, 0));
983 const auto& fs = intQuants.fluidState();
984 const double well_tw_fraction = this->well_index_[perf] / total_tw;
985 double total_mobility = 0.0;
986 for (
int p = 0; p < np; ++p) {
987 int ebosPhaseIdx = this->flowPhaseToEbosPhaseIdx(p);
988 total_mobility += fs.invB(ebosPhaseIdx).value() * intQuants.mobility(ebosPhaseIdx).value();
990 for (
int p = 0; p < np; ++p) {
991 int ebosPhaseIdx = this->flowPhaseToEbosPhaseIdx(p);
992 scaling_factor[p] += well_tw_fraction * fs.invB(ebosPhaseIdx).value() * intQuants.mobility(ebosPhaseIdx).value() / total_mobility;
995 return scaling_factor;
1000 template <
typename TypeTag>
1009 auto& ws = well_state.well(this->index_of_well_);
1010 int nonzero_rate_index = -1;
1011 for (
int p = 0; p < this->number_of_phases_; ++p) {
1012 if (ws.surface_rates[p] != 0.0) {
1013 if (nonzero_rate_index == -1) {
1014 nonzero_rate_index = p;
1023 std::vector<double> well_q_s = computeCurrentWellRates(ebosSimulator, deferred_logger);
1025 if (nonzero_rate_index == -1) {
1028 for (
int p = 0; p < this->number_of_phases_; ++p) {
1029 ws.surface_rates[p] = well_q_s[this->flowPhaseToEbosCompIdx(p)];
1035 const double initial_nonzero_rate = ws.surface_rates[nonzero_rate_index];
1036 const int comp_idx_nz = this->flowPhaseToEbosCompIdx(nonzero_rate_index);
1037 for (
int p = 0; p < this->number_of_phases_; ++p) {
1038 if (p != nonzero_rate_index) {
1039 const int comp_idx = this->flowPhaseToEbosCompIdx(p);
1040 double& rate = ws.surface_rates[p];
1041 rate = (initial_nonzero_rate/well_q_s[comp_idx_nz]) * (well_q_s[comp_idx]);
1045 template<
typename TypeTag>
1046 typename WellInterface<TypeTag>::Eval
1050 if (Indices::oilEnabled) {
1051 pressure = fs.pressure(FluidSystem::oilPhaseIdx);
1053 if (Indices::waterEnabled) {
1054 pressure = fs.pressure(FluidSystem::waterPhaseIdx);
1056 pressure = fs.pressure(FluidSystem::gasPhaseIdx);
Definition: DeferredLogger.hpp:57
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:252
Definition: WellInterfaceIndices.hpp:35
Definition: WellInterface.hpp:72
void updateWellStateRates(const Simulator &ebosSimulator, WellState &well_state, DeferredLogger &deferred_logger) const
Modify the well_state's rates if there is only one nonzero rate.
Definition: WellInterface_impl.hpp:1003
WellInterface(const Well &well, const ParallelWellInfo &pw_info, const int time_step, const ModelParameters ¶m, const RateConverterType &rate_converter, const int pvtRegionIdx, const int num_components, const int num_phases, const int index_of_well, const std::vector< PerforationData > &perf_data)
Constructor.
Definition: WellInterface_impl.hpp:35
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition: WellState.hpp:56
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27
PhaseUsage phaseUsage(const Phases &phases)
Determine the active phases.
Definition: phaseUsageFromDeck.cpp:33
Solver parameters for the BlackoilModel.
Definition: BlackoilModelParametersEbos.hpp:327
Definition: BlackoilPhases.hpp:46