22 #include <opm/parser/eclipse/EclipseState/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);
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::abs(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 bool converged = iterateWellEquations(ebosSimulator, dt, well_state, group_state, deferred_logger);
423 deferred_logger.debug(
"WellTest: Well equation for well " + this->name() +
" converged");
426 const int max_iter = param_.max_welleq_iter_;
427 deferred_logger.debug(
"WellTest: Well equation for well " + this->name() +
" failed converging in "
428 + std::to_string(max_iter) +
" iterations");
429 well_state = well_state0;
434 template<
typename TypeTag>
436 WellInterface<TypeTag>::
437 solveWellEquation(
const Simulator& ebosSimulator,
438 WellState& well_state,
439 const GroupState& group_state,
440 DeferredLogger& deferred_logger)
442 if (!this->isOperableAndSolvable())
446 const WellState well_state0 = well_state;
447 const double dt = ebosSimulator.timeStepSize();
448 const bool converged = iterateWellEquations(ebosSimulator, dt, well_state, group_state, deferred_logger);
450 const int max_iter = param_.max_welleq_iter_;
451 deferred_logger.debug(
"Compute initial well solution for well " + this->name() +
". Failed to converge in "
452 + std::to_string(max_iter) +
" iterations");
453 well_state = well_state0;
459 template <
typename TypeTag>
461 WellInterface<TypeTag>::
462 assembleWellEq(
const Simulator& ebosSimulator,
464 WellState& well_state,
465 const GroupState& group_state,
466 DeferredLogger& deferred_logger)
468 const bool old_well_operable = this->operability_status_.isOperableAndSolvable();
470 if (param_.check_well_operability_iter_)
471 checkWellOperability(ebosSimulator, well_state, deferred_logger);
474 const int iteration_idx = ebosSimulator.model().newtonMethod().numIterations();
475 if (iteration_idx < param_.max_niter_inner_well_iter_) {
476 this->operability_status_.solvable =
true;
477 bool converged = this->iterateWellEquations(ebosSimulator, dt, well_state, group_state, deferred_logger);
481 if (this->shutUnsolvableWells())
482 this->operability_status_.solvable =
false;
486 const bool well_operable = this->operability_status_.isOperableAndSolvable();
487 if (!well_operable && old_well_operable) {
488 if (this->well_ecl_.getAutomaticShutIn()) {
489 deferred_logger.info(
" well " + this->name() +
" gets SHUT during iteration ");
491 if (!this->wellIsStopped()) {
492 deferred_logger.info(
" well " + this->name() +
" gets STOPPED during iteration ");
494 changed_to_stopped_this_step_ =
true;
497 }
else if (well_operable && !old_well_operable) {
498 deferred_logger.info(
" well " + this->name() +
" gets REVIVED during iteration ");
500 changed_to_stopped_this_step_ =
false;
503 const auto& summary_state = ebosSimulator.vanguard().summaryState();
504 const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
505 const auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
506 assembleWellEqWithoutIteration(ebosSimulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
511 template<
typename TypeTag>
513 WellInterface<TypeTag>::addCellRates(RateVector& rates,
int cellIdx)
const
515 for (
int perfIdx = 0; perfIdx < this->number_of_perforations_; ++perfIdx) {
516 if (this->cells()[perfIdx] == cellIdx) {
517 for (
int i = 0; i < RateVector::dimension; ++i) {
518 rates[i] += connectionRates_[perfIdx][i];
524 template<
typename TypeTag>
525 typename WellInterface<TypeTag>::Scalar
526 WellInterface<TypeTag>::volumetricSurfaceRateForConnection(
int cellIdx,
int phaseIdx)
const {
527 for (
int perfIdx = 0; perfIdx < this->number_of_perforations_; ++perfIdx) {
528 if (this->cells()[perfIdx] == cellIdx) {
529 const unsigned activeCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::solventComponentIndex(phaseIdx));
530 return connectionRates_[perfIdx][activeCompIdx].value();
534 OPM_THROW(std::invalid_argument,
"The well with name " + this->name()
535 +
" does not perforate cell " + std::to_string(cellIdx));
542 template<
typename TypeTag>
544 WellInterface<TypeTag>::
545 checkWellOperability(
const Simulator& ebos_simulator,
546 const WellState& well_state,
547 DeferredLogger& deferred_logger)
550 if (!param_.check_well_operability_) {
555 if (this->isInjector()) {
559 if (!this->underPredictionMode() ) {
563 if (this->wellIsStopped() && !changed_to_stopped_this_step_) {
567 updateWellOperability(ebos_simulator, well_state, deferred_logger);
571 template<
typename TypeTag>
573 WellInterface<TypeTag>::
574 shutUnsolvableWells()
const
576 bool shut_unsolvable_wells = param_.shut_unsolvable_wells_;
578 return shut_unsolvable_wells && !this->isInjector() && this->underPredictionMode();
585 template<
typename TypeTag>
587 WellInterface<TypeTag>::
588 updateWellOperability(
const Simulator& ebos_simulator,
589 const WellState& well_state,
590 DeferredLogger& deferred_logger)
592 this->operability_status_.resetOperability();
594 auto current_control = well_state.well(this->index_of_well_).production_cmode;
597 if(current_control == Well::ProducerCMode::BHP || current_control == Well::ProducerCMode::THP) {
598 updateIPR(ebos_simulator, deferred_logger);
599 checkOperabilityUnderBHPLimitProducer(well_state, ebos_simulator, deferred_logger);
602 if (current_control == Well::ProducerCMode::THP) {
603 checkOperabilityUnderTHPLimitProducer(ebos_simulator, well_state, deferred_logger);
608 template<
typename TypeTag>
610 WellInterface<TypeTag>::
611 updateWellStateWithTarget(
const Simulator& ebos_simulator,
612 const GroupState& group_state,
613 WellState& well_state,
614 DeferredLogger& deferred_logger)
const
618 const auto& well = this->well_ecl_;
619 const int well_index = this->index_of_well_;
620 auto& ws = well_state.well(well_index);
622 const int np = well_state.numPhases();
623 const auto& summaryState = ebos_simulator.vanguard().summaryState();
624 const auto& schedule = ebos_simulator.vanguard().schedule();
626 if (this->wellIsStopped()) {
627 for (
int p = 0; p<np; ++p) {
628 ws.surface_rates[p] = 0;
634 if (this->isInjector() )
636 const auto& controls = well.injectionControls(summaryState);
638 InjectorType injectorType = controls.injector_type;
640 switch (injectorType) {
641 case InjectorType::WATER:
643 phasePos = pu.phase_pos[BlackoilPhases::Aqua];
646 case InjectorType::OIL:
648 phasePos = pu.phase_pos[BlackoilPhases::Liquid];
651 case InjectorType::GAS:
653 phasePos = pu.phase_pos[BlackoilPhases::Vapour];
657 OPM_DEFLOG_THROW(std::runtime_error,
"Expected WATER, OIL or GAS as type for injectors " + this->name(), deferred_logger );
660 const auto current = ws.injection_cmode;
663 case Well::InjectorCMode::RATE:
665 ws.surface_rates[phasePos] = controls.surface_rate;
669 case Well::InjectorCMode::RESV:
671 std::vector<double> convert_coeff(this->number_of_phases_, 1.0);
672 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, convert_coeff);
673 const double coeff = convert_coeff[phasePos];
674 ws.surface_rates[phasePos] = controls.reservoir_rate/coeff;
678 case Well::InjectorCMode::THP:
680 auto rates = ws.surface_rates;
681 double bhp = this->calculateBhpFromThp(well_state, rates, well, summaryState, this->getRefDensity(), deferred_logger);
687 double total_rate = std::accumulate(rates.begin(), rates.end(), 0.0);
688 if (total_rate <= 0.0)
689 ws.surface_rates = ws.well_potentials;
693 case Well::InjectorCMode::BHP:
695 ws.bhp = controls.bhp_limit;
696 double total_rate = 0.0;
697 for (
int p = 0; p<np; ++p) {
698 total_rate += ws.surface_rates[p];
703 if (total_rate <= 0.0)
704 ws.surface_rates = ws.well_potentials;
708 case Well::InjectorCMode::GRUP:
710 assert(well.isAvailableForGroupControl());
711 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
712 const double efficiencyFactor = well.getEfficiencyFactor();
713 std::optional<double> target =
714 this->getGroupInjectionTargetRate(group,
723 ws.surface_rates[phasePos] = *target;
726 case Well::InjectorCMode::CMODE_UNDEFINED:
728 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name(), deferred_logger );
736 const auto current = ws.production_cmode;
737 const auto& controls = well.productionControls(summaryState);
739 case Well::ProducerCMode::ORAT:
741 double current_rate = -ws.surface_rates[ pu.phase_pos[Oil] ];
744 if (current_rate > 0.0) {
745 for (
int p = 0; p<np; ++p) {
746 ws.surface_rates[p] *= controls.oil_rate/current_rate;
749 const std::vector<double> fractions = initialWellRateFractions(ebos_simulator, well_state);
750 double control_fraction = fractions[pu.phase_pos[Oil]];
751 if (control_fraction != 0.0) {
752 for (
int p = 0; p<np; ++p) {
753 ws.surface_rates[p] = - fractions[p] * controls.oil_rate/control_fraction;
759 case Well::ProducerCMode::WRAT:
761 double current_rate = -ws.surface_rates[ pu.phase_pos[Water] ];
764 if (current_rate > 0.0) {
765 for (
int p = 0; p<np; ++p) {
766 ws.surface_rates[p] *= controls.water_rate/current_rate;
769 const std::vector<double> fractions = initialWellRateFractions(ebos_simulator, well_state);
770 double control_fraction = fractions[pu.phase_pos[Water]];
771 if (control_fraction != 0.0) {
772 for (
int p = 0; p<np; ++p) {
773 ws.surface_rates[p] = - fractions[p] * controls.water_rate/control_fraction;
779 case Well::ProducerCMode::GRAT:
781 double current_rate = -ws.surface_rates[pu.phase_pos[Gas] ];
784 if (current_rate > 0.0) {
785 for (
int p = 0; p<np; ++p) {
786 ws.surface_rates[p] *= controls.gas_rate/current_rate;
789 const std::vector<double> fractions = initialWellRateFractions(ebos_simulator, well_state);
790 double control_fraction = fractions[pu.phase_pos[Gas]];
791 if (control_fraction != 0.0) {
792 for (
int p = 0; p<np; ++p) {
793 ws.surface_rates[p] = - fractions[p] * controls.gas_rate/control_fraction;
801 case Well::ProducerCMode::LRAT:
803 double current_rate = -ws.surface_rates[ pu.phase_pos[Water] ]
804 - ws.surface_rates[ pu.phase_pos[Oil] ];
807 if (current_rate > 0.0) {
808 for (
int p = 0; p<np; ++p) {
809 ws.surface_rates[p] *= controls.liquid_rate/current_rate;
812 const std::vector<double> fractions = initialWellRateFractions(ebos_simulator, well_state);
813 double control_fraction = fractions[pu.phase_pos[Water]] + fractions[pu.phase_pos[Oil]];
814 if (control_fraction != 0.0) {
815 for (
int p = 0; p<np; ++p) {
816 ws.surface_rates[p] = - fractions[p] * controls.liquid_rate / control_fraction;
822 case Well::ProducerCMode::CRAT:
824 OPM_DEFLOG_THROW(std::runtime_error,
"CRAT control not supported " << this->name(), deferred_logger);
826 case Well::ProducerCMode::RESV:
828 std::vector<double> convert_coeff(this->number_of_phases_, 1.0);
829 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, convert_coeff);
830 double total_res_rate = 0.0;
831 for (
int p = 0; p<np; ++p) {
832 total_res_rate -= ws.surface_rates[p] * convert_coeff[p];
834 if (controls.prediction_mode) {
837 if (total_res_rate > 0.0) {
838 for (
int p = 0; p<np; ++p) {
839 ws.surface_rates[p] *= controls.resv_rate/total_res_rate;
842 const std::vector<double> fractions = initialWellRateFractions(ebos_simulator, well_state);
843 for (
int p = 0; p<np; ++p) {
844 ws.surface_rates[p] = - fractions[p] * controls.resv_rate / convert_coeff[p];
848 std::vector<double> hrates(this->number_of_phases_,0.);
849 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
850 hrates[pu.phase_pos[Water]] = controls.water_rate;
852 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
853 hrates[pu.phase_pos[Oil]] = controls.oil_rate;
855 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
856 hrates[pu.phase_pos[Gas]] = controls.gas_rate;
858 std::vector<double> hrates_resv(this->number_of_phases_,0.);
859 this->rateConverter_.calcReservoirVoidageRates( 0, this->pvtRegionIdx_, hrates, hrates_resv);
860 double target = std::accumulate(hrates_resv.begin(), hrates_resv.end(), 0.0);
863 if (total_res_rate > 0.0) {
864 for (
int p = 0; p<np; ++p) {
865 ws.surface_rates[p] *= target/total_res_rate;
868 const std::vector<double> fractions = initialWellRateFractions(ebos_simulator, well_state);
869 for (
int p = 0; p<np; ++p) {
870 ws.surface_rates[p] = - fractions[p] * target / convert_coeff[p];
877 case Well::ProducerCMode::BHP:
879 ws.bhp = controls.bhp_limit;
880 double total_rate = 0.0;
881 for (
int p = 0; p<np; ++p) {
882 total_rate -= ws.surface_rates[p];
887 if (total_rate <= 0.0){
888 for (
int p = 0; p<np; ++p) {
889 ws.surface_rates[p] = -ws.well_potentials[p];
894 case Well::ProducerCMode::THP:
896 auto rates = ws.surface_rates;
897 double bhp = this->calculateBhpFromThp(well_state, rates, well, summaryState, this->getRefDensity(), deferred_logger);
903 double total_rate = -std::accumulate(rates.begin(), rates.end(), 0.0);
904 if (total_rate <= 0.0){
905 for (
int p = 0; p<np; ++p) {
906 ws.surface_rates[p] = -ws.well_potentials[p];
911 case Well::ProducerCMode::GRUP:
913 assert(well.isAvailableForGroupControl());
914 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
915 const double efficiencyFactor = well.getEfficiencyFactor();
916 double scale = this->getGroupProductionTargetRate(group,
925 for (
int p = 0; p<np; ++p) {
926 ws.surface_rates[p] *= scale;
931 case Well::ProducerCMode::CMODE_UNDEFINED:
932 case Well::ProducerCMode::NONE:
934 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name() , deferred_logger);
942 template<
typename TypeTag>
944 WellInterface<TypeTag>::
945 initialWellRateFractions(
const Simulator& ebosSimulator,
const WellState& well_state)
const
947 const int np = this->number_of_phases_;
948 std::vector<double> scaling_factor(np);
949 const auto& ws = well_state.well(this->index_of_well_);
951 double total_potentials = 0.0;
952 for (
int p = 0; p<np; ++p) {
953 total_potentials += ws.well_potentials[p];
955 if (total_potentials > 0) {
956 for (
int p = 0; p<np; ++p) {
957 scaling_factor[p] = ws.well_potentials[p] / total_potentials;
959 return scaling_factor;
964 const int nperf = this->number_of_perforations_;
965 for (
int perf = 0; perf < nperf; ++perf) {
966 total_tw += this->well_index_[perf];
968 for (
int perf = 0; perf < nperf; ++perf) {
969 const int cell_idx = this->well_cells_[perf];
970 const auto& intQuants = *(ebosSimulator.model().cachedIntensiveQuantities(cell_idx, 0));
971 const auto& fs = intQuants.fluidState();
972 const double well_tw_fraction = this->well_index_[perf] / total_tw;
973 double total_mobility = 0.0;
974 for (
int p = 0; p < np; ++p) {
975 int ebosPhaseIdx = this->flowPhaseToEbosPhaseIdx(p);
976 total_mobility += fs.invB(ebosPhaseIdx).value() * intQuants.mobility(ebosPhaseIdx).value();
978 for (
int p = 0; p < np; ++p) {
979 int ebosPhaseIdx = this->flowPhaseToEbosPhaseIdx(p);
980 scaling_factor[p] += well_tw_fraction * fs.invB(ebosPhaseIdx).value() * intQuants.mobility(ebosPhaseIdx).value() / total_mobility;
983 return scaling_factor;
988 template <
typename TypeTag>
997 auto& ws = well_state.well(this->index_of_well_);
998 int nonzero_rate_index = -1;
999 for (
int p = 0; p < this->number_of_phases_; ++p) {
1000 if (ws.surface_rates[p] != 0.0) {
1001 if (nonzero_rate_index == -1) {
1002 nonzero_rate_index = p;
1009 if (nonzero_rate_index == -1) {
1015 std::vector<double> well_q_s = computeCurrentWellRates(ebosSimulator, deferred_logger);
1018 const double initial_nonzero_rate = ws.surface_rates[nonzero_rate_index];
1019 const int comp_idx_nz = this->flowPhaseToEbosCompIdx(nonzero_rate_index);
1020 for (
int p = 0; p < this->number_of_phases_; ++p) {
1021 if (p != nonzero_rate_index) {
1022 const int comp_idx = this->flowPhaseToEbosCompIdx(p);
1023 double& rate = ws.surface_rates[p];
1024 rate = (initial_nonzero_rate/well_q_s[comp_idx_nz]) * (well_q_s[comp_idx]);
Definition: DeferredLogger.hpp:57
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:252
Definition: WellInterfaceIndices.hpp:35
Definition: WellInterface.hpp:71
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:991
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:26
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:45