23#ifndef OPM_WELLINTERFACE_HEADER_INCLUDED
25#define OPM_WELLINTERFACE_IMPL_HEADER_INCLUDED
29#include <opm/common/Exceptions.hpp>
31#include <opm/input/eclipse/Schedule/ScheduleTypes.hpp>
32#include <opm/input/eclipse/Schedule/Well/WDFAC.hpp>
41#include <dune/common/version.hh>
46#include <fmt/format.h>
52 template<
typename TypeTag>
59 const int pvtRegionIdx,
60 const int num_components,
62 const int index_of_well,
63 const std::vector<PerforationData>& perf_data)
78 if (well.isInjector()) {
79 auto injectorType = this->
well_ecl_.injectorType();
80 if (injectorType == InjectorType::GAS) {
88 template<
typename TypeTag>
92 const std::vector<double>& ,
93 const double gravity_arg,
95 const std::vector< Scalar >& B_avg,
96 const bool changed_to_open_this_step)
98 this->phase_usage_ = phase_usage_arg;
99 this->gravity_ = gravity_arg;
101 this->changed_to_open_this_step_ = changed_to_open_this_step;
107 template<
typename TypeTag>
112 if constexpr (has_polymer) {
113 return this->wpolymer_();
123 template<
typename TypeTag>
128 if constexpr (has_foam) {
129 return this->wfoam_();
137 template<
typename TypeTag>
142 if constexpr (has_brine) {
143 return this->wsalt_();
149 template<
typename TypeTag>
154 if constexpr (has_micp) {
155 return this->wmicrobes_();
161 template<
typename TypeTag>
166 if constexpr (has_micp) {
167 return this->woxygen_();
179 template<
typename TypeTag>
184 if constexpr (has_micp) {
185 return this->wurea_();
191 template<
typename TypeTag>
200 const auto& summary_state = simulator.vanguard().summaryState();
201 if (this->stopppedOrZeroRateTarget(summary_state, well_state)) {
205 const auto& summaryState = simulator.vanguard().summaryState();
206 const auto& schedule = simulator.vanguard().schedule();
207 const auto& well = this->well_ecl_;
208 auto& ws = well_state.
well(this->index_of_well_);
210 if (well.isInjector()) {
211 from = WellInjectorCMode2String(ws.injection_cmode);
213 from = WellProducerCMode2String(ws.production_cmode);
215 bool oscillating = std::count(this->well_control_log_.begin(), this->well_control_log_.end(), from) >= param_.max_number_of_well_switches_;
219 bool output = std::count(this->well_control_log_.begin(), this->well_control_log_.end(), from) == param_.max_number_of_well_switches_;
221 std::ostringstream ss;
222 ss <<
" The control mode for well " << this->name()
223 <<
" is oscillating\n"
224 <<
" We don't allow for more than "
225 << param_.max_number_of_well_switches_
226 <<
" switches. The control is kept at " << from;
227 deferred_logger.
info(ss.str());
229 this->well_control_log_.push_back(from);
233 bool changed =
false;
234 if (iog == IndividualOrGroup::Individual) {
235 changed = this->checkIndividualConstraints(ws, summaryState, deferred_logger);
236 }
else if (iog == IndividualOrGroup::Group) {
237 changed = this->checkGroupConstraints(well_state, group_state, schedule, summaryState, deferred_logger);
239 assert(iog == IndividualOrGroup::Both);
240 changed = this->checkConstraints(well_state, group_state, schedule, summaryState, deferred_logger);
246 if (well.isInjector()) {
247 to = WellInjectorCMode2String(ws.injection_cmode);
249 to = WellProducerCMode2String(ws.production_cmode);
251 std::ostringstream ss;
252 ss <<
" Switching control mode for well " << this->name()
256 ss <<
" on rank " << cc.rank();
258 deferred_logger.
debug(ss.str());
260 this->well_control_log_.push_back(from);
261 updateWellStateWithTarget(simulator, group_state, well_state, deferred_logger);
262 updatePrimaryVariables(summaryState, well_state, deferred_logger);
268 template<
typename TypeTag>
274 const Well::InjectionControls& inj_controls,
275 const Well::ProductionControls& prod_controls,
276 const double wqTotal,
278 const bool fixed_control,
279 const bool fixed_status)
281 const auto& summary_state = simulator.vanguard().summaryState();
282 const auto& schedule = simulator.vanguard().schedule();
284 if (this->wellUnderZeroRateTarget(summary_state, well_state) || !(this->well_ecl_.getStatus() == WellStatus::OPEN)) {
288 const double sgn = this->isInjector() ? 1.0 : -1.0;
289 if (!this->wellIsStopped()){
290 if (wqTotal*sgn <= 0.0 && !fixed_status){
294 bool changed =
false;
295 if (!fixed_control) {
296 auto& ws = well_state.
well(this->index_of_well_);
297 const bool hasGroupControl = this->isInjector() ? inj_controls.hasControl(Well::InjectorCMode::GRUP) :
298 prod_controls.hasControl(Well::ProducerCMode::GRUP);
300 changed = this->checkIndividualConstraints(ws, summary_state, deferred_logger, inj_controls, prod_controls);
301 if (hasGroupControl) {
302 changed = changed || this->checkGroupConstraints(well_state, group_state, schedule, summary_state,deferred_logger);
306 const bool thp_controlled = this->isInjector() ? ws.injection_cmode == Well::InjectorCMode::THP :
307 ws.production_cmode == Well::ProducerCMode::THP;
308 if (!thp_controlled){
310 updateWellStateWithTarget(simulator, group_state, well_state, deferred_logger);
312 ws.thp = this->getTHPConstraint(summary_state);
314 updatePrimaryVariables(summary_state, well_state, deferred_logger);
319 }
else if (!fixed_status){
321 const double bhp = well_state.
well(this->index_of_well_).bhp;
322 double prod_limit = prod_controls.bhp_limit;
323 double inj_limit = inj_controls.bhp_limit;
324 const bool has_thp = this->wellHasTHPConstraints(summary_state);
326 std::vector<double> rates(this->num_components_);
327 if (this->isInjector()){
329 inj_limit = std::min(bhp_thp, inj_controls.bhp_limit);
333 prod_limit = std::max(bhp_min, prod_controls.bhp_limit);
336 const double bhp_diff = (this->isInjector())? inj_limit -
bhp:
bhp - prod_limit;
339 well_state.
well(this->index_of_well_).bhp = (this->isInjector())? inj_limit : prod_limit;
341 well_state.
well(this->index_of_well_).thp = this->getTHPConstraint(summary_state);
352 template<
typename TypeTag>
356 const double simulation_time,
359 WellTestState& well_test_state,
362 deferred_logger.
info(
" well " + this->name() +
" is being tested");
365 auto& ws = well_state_copy.
well(this->indexOfWell());
367 updateWellStateWithTarget(simulator, group_state, well_state_copy, deferred_logger);
368 calculateExplicitQuantities(simulator, well_state_copy, deferred_logger);
369 const auto& summary_state = simulator.vanguard().summaryState();
370 updatePrimaryVariables(summary_state, well_state_copy, deferred_logger);
371 initPrimaryVariablesEvaluation();
373 if (this->isProducer()) {
374 const auto& schedule = simulator.vanguard().schedule();
375 const auto report_step = simulator.episodeIndex();
376 const auto& glo = schedule.glo(report_step);
378 gliftBeginTimeStepWellTestUpdateALQ(simulator, well_state_copy, deferred_logger);
382 WellTestState welltest_state_temp;
384 bool testWell =
true;
389 const std::size_t original_number_closed_completions = welltest_state_temp.num_closed_completions();
390 bool converged = solveWellForTesting(simulator, well_state_copy, group_state, deferred_logger);
392 const auto msg = fmt::format(
"WTEST: Well {} is not solvable (physical)", this->name());
393 deferred_logger.
debug(msg);
398 updateWellOperability(simulator, well_state_copy, deferred_logger);
399 if ( !this->isOperableAndSolvable() ) {
400 const auto msg = fmt::format(
"WTEST: Well {} is not operable (physical)", this->name());
401 deferred_logger.
debug(msg);
404 std::vector<double> potentials;
406 computeWellPotentials(simulator, well_state_copy, potentials, deferred_logger);
407 }
catch (
const std::exception& e) {
408 const std::string msg = std::string(
"well ") + this->name() + std::string(
": computeWellPotentials() failed during testing for re-opening: ") + e.what();
409 deferred_logger.
info(msg);
412 const int np = well_state_copy.
numPhases();
413 for (
int p = 0; p < np; ++p) {
414 ws.well_potentials[p] = std::max(0.0, potentials[p]);
416 this->updateWellTestState(well_state_copy.
well(this->indexOfWell()), simulation_time,
false, welltest_state_temp, deferred_logger);
417 this->closeCompletions(welltest_state_temp);
423 if ( welltest_state_temp.num_closed_wells() > 0 ||
424 (original_number_closed_completions == welltest_state_temp.num_closed_completions()) ) {
430 if (!welltest_state_temp.well_is_closed(this->name())) {
431 well_test_state.open_well(this->name());
433 std::string msg = std::string(
"well ") + this->name() + std::string(
" is re-opened");
434 deferred_logger.
info(msg);
437 for (
auto& completion : this->well_ecl_.getCompletions()) {
438 if (!welltest_state_temp.completion_is_closed(this->name(), completion.first))
439 well_test_state.open_completion(this->name(), completion.first);
443 well_state = well_state_copy;
450 template<
typename TypeTag>
459 const auto& summary_state = simulator.vanguard().summaryState();
460 const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
461 const auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
462 bool converged =
false;
465 if (!this->param_.local_well_solver_control_switching_){
466 converged = this->iterateWellEqWithControl(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
468 if (this->param_.use_implicit_ipr_ && this->well_ecl_.isProducer() && this->wellHasTHPConstraints(summary_state) && (this->well_ecl_.getStatus() == WellStatus::OPEN)) {
469 converged = solveWellWithTHPConstraint(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
471 converged = this->iterateWellEqWithSwitching(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
475 }
catch (NumericalProblem& e ) {
476 const std::string msg =
"Inner well iterations failed for well " + this->name() +
" Treat the well as unconverged. ";
477 deferred_logger.
warning(
"INNER_ITERATION_FAILED", msg);
483 template<
typename TypeTag>
488 const Well::InjectionControls& inj_controls,
489 const Well::ProductionControls& prod_controls,
494 const auto& summary_state = simulator.vanguard().summaryState();
495 bool is_operable =
true;
496 bool converged =
true;
497 auto& ws = well_state.
well(this->index_of_well_);
499 if (this->wellIsStopped()) {
501 auto bhp_target = estimateOperableBhp(simulator, dt, well_state, summary_state, deferred_logger);
502 if (!bhp_target.has_value()) {
504 const auto msg = fmt::format(
"estimateOperableBhp: Did not find operable BHP for well {}", this->name());
505 deferred_logger.
debug(msg);
508 solveWellWithZeroRate(simulator, dt, well_state, deferred_logger);
512 ws.thp = this->getTHPConstraint(summary_state);
513 const double bhp = std::max(bhp_target.value(), prod_controls.bhp_limit);
514 solveWellWithBhp(simulator, dt,
bhp, well_state, deferred_logger);
519 converged = this->iterateWellEqWithSwitching(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
522 const bool isThp = ws.production_cmode == Well::ProducerCMode::THP;
524 if (converged && !this->stopppedOrZeroRateTarget(summary_state, well_state) && isThp) {
525 auto rates = well_state.
well(this->index_of_well_).surface_rates;
526 this->adaptRatesForVFP(rates);
527 this->updateIPRImplicit(simulator, well_state, deferred_logger);
531 this->operability_status_.use_vfpexplicit =
true;
534 const double reltol = 1e-3;
535 const double cur_bhp = ws.bhp;
536 if (bhp_stable.has_value() && cur_bhp - bhp_stable.value() > cur_bhp*reltol){
537 const auto msg = fmt::format(
"Well {} converged to an unstable solution, re-solving", this->name());
538 deferred_logger.
debug(msg);
539 solveWellWithBhp(simulator, dt, bhp_stable.value(), well_state, deferred_logger);
541 ws.thp = this->getTHPConstraint(summary_state);
542 converged = this->iterateWellEqWithSwitching(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
549 this->operability_status_.use_vfpexplicit =
true;
551 auto bhp_target = estimateOperableBhp(simulator, dt, well_state, summary_state, deferred_logger);
552 if (!bhp_target.has_value()) {
556 converged = solveWellWithZeroRate(simulator, dt, well_state, deferred_logger);
560 const double bhp = std::max(bhp_target.value(), prod_controls.bhp_limit);
561 solveWellWithBhp(simulator, dt,
bhp, well_state, deferred_logger);
562 ws.thp = this->getTHPConstraint(summary_state);
563 converged = this->iterateWellEqWithSwitching(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
567 is_operable = is_operable && !this->wellIsStopped();
568 this->operability_status_.can_obtain_bhp_with_thp_limit = is_operable;
569 this->operability_status_.obey_thp_limit_under_bhp_limit = is_operable;
573 template<
typename TypeTag>
574 std::optional<double>
579 const SummaryState& summary_state,
586 const bool converged = solveWellWithBhp(simulator, dt, bhp_min, well_state, deferred_logger);
587 if (!converged || this->wellIsStopped()) {
590 this->updateIPRImplicit(simulator, well_state, deferred_logger);
591 auto rates = well_state.
well(this->index_of_well_).surface_rates;
592 this->adaptRatesForVFP(rates);
596 template<
typename TypeTag>
607 auto inj_controls = Well::InjectionControls(0);
608 auto prod_controls = Well::ProductionControls(0);
609 auto& ws = well_state.
well(this->index_of_well_);
610 auto cmode_inj = ws.injection_cmode;
611 auto cmode_prod = ws.production_cmode;
612 if (this->isInjector()) {
613 inj_controls.addControl(Well::InjectorCMode::BHP);
614 inj_controls.bhp_limit =
bhp;
615 inj_controls.cmode = Well::InjectorCMode::BHP;
616 ws.injection_cmode = Well::InjectorCMode::BHP;
618 prod_controls.addControl(Well::ProducerCMode::BHP);
619 prod_controls.bhp_limit =
bhp;
620 prod_controls.cmode = Well::ProducerCMode::BHP;
621 ws.production_cmode = Well::ProducerCMode::BHP;
626 const bool converged = this->iterateWellEqWithSwitching(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger,
true);
627 ws.injection_cmode = cmode_inj;
628 ws.production_cmode = cmode_prod;
632 template<
typename TypeTag>
641 const auto well_status_orig = this->wellStatus_;
645 auto inj_controls = Well::InjectionControls(0);
646 auto prod_controls = Well::ProductionControls(0);
647 const bool converged = this->iterateWellEqWithSwitching(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger,
true,
true);
648 this->wellStatus_ = well_status_orig;
652 template<
typename TypeTag>
662 const double dt = simulator.timeStepSize();
663 const auto& summary_state = simulator.vanguard().summaryState();
664 const bool has_thp_limit = this->wellHasTHPConstraints(summary_state);
667 well_state.
well(this->indexOfWell()).production_cmode = Well::ProducerCMode::THP;
668 converged = gliftBeginTimeStepWellTestIterateWellEquations(
669 simulator, dt, well_state, group_state, deferred_logger);
672 well_state.
well(this->indexOfWell()).production_cmode = Well::ProducerCMode::BHP;
673 converged = iterateWellEquations(simulator, dt, well_state, group_state, deferred_logger);
676 deferred_logger.
debug(
"WellTest: Well equation for well " + this->name() +
" converged");
679 const int max_iter = param_.max_welleq_iter_;
680 deferred_logger.
debug(
"WellTest: Well equation for well " + this->name() +
" failed converging in "
682 well_state = well_state0;
687 template<
typename TypeTag>
695 if (!this->isOperableAndSolvable() && !this->wellIsStopped())
700 const double dt = simulator.timeStepSize();
701 bool converged = iterateWellEquations(simulator, dt, well_state, group_state, deferred_logger);
711 auto& ws = well_state.
well(this->indexOfWell());
712 bool thp_control =
false;
713 if (this->well_ecl_.isInjector()) {
714 thp_control = ws.injection_cmode == Well::InjectorCMode::THP;
716 ws.injection_cmode = Well::InjectorCMode::BHP;
717 this->well_control_log_.push_back(WellInjectorCMode2String(Well::InjectorCMode::THP));
720 thp_control = ws.production_cmode == Well::ProducerCMode::THP;
722 ws.production_cmode = Well::ProducerCMode::BHP;
723 this->well_control_log_.push_back(WellProducerCMode2String(Well::ProducerCMode::THP));
727 const std::string msg = std::string(
"The newly opened well ") + this->name()
728 + std::string(
" with THP control did not converge during inner iterations, we try again with bhp control");
729 deferred_logger.
debug(msg);
730 converged = this->iterateWellEquations(simulator, dt, well_state, group_state, deferred_logger);
735 const int max_iter = param_.max_welleq_iter_;
736 deferred_logger.
debug(
"Compute initial well solution for well " + this->name() +
". Failed to converge in "
738 well_state = well_state0;
744 template <
typename TypeTag>
754 prepareWellBeforeAssembling(simulator, dt, well_state, group_state, deferred_logger);
756 assembleWellEqWithoutIteration(simulator, dt, well_state, group_state, deferred_logger);
761 template <
typename TypeTag>
770 const auto& summary_state = simulator.vanguard().summaryState();
771 const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
772 const auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
775 assembleWellEqWithoutIteration(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
780 template<
typename TypeTag>
789 const bool old_well_operable = this->operability_status_.isOperableAndSolvable();
791 if (param_.check_well_operability_iter_)
792 checkWellOperability(simulator, well_state, deferred_logger);
795 const int iteration_idx = simulator.model().newtonMethod().numIterations();
796 if (iteration_idx < param_.max_niter_inner_well_iter_ || this->well_ecl_.isMultiSegment()) {
797 this->operability_status_.solvable =
true;
798 bool converged = this->iterateWellEquations(simulator, dt, well_state, group_state, deferred_logger);
802 if (param_.shut_unsolvable_wells_)
803 this->operability_status_.solvable =
false;
806 if (this->operability_status_.has_negative_potentials) {
807 auto well_state_copy = well_state;
808 std::vector<double> potentials;
810 computeWellPotentials(simulator, well_state_copy, potentials, deferred_logger);
811 }
catch (
const std::exception& e) {
812 const std::string msg = std::string(
"well ") + this->name() + std::string(
": computeWellPotentials() failed during attempt to recompute potentials for well : ") + e.what();
813 deferred_logger.
info(msg);
814 this->operability_status_.has_negative_potentials =
true;
816 auto& ws = well_state.
well(this->indexOfWell());
818 for (
int p = 0; p < np; ++p) {
819 ws.well_potentials[p] = std::max(0.0, potentials[p]);
822 this->changed_to_open_this_step_ =
false;
823 const bool well_operable = this->operability_status_.isOperableAndSolvable();
825 if (!well_operable && old_well_operable) {
826 deferred_logger.
info(
" well " + this->name() +
" gets STOPPED during iteration ");
828 changed_to_stopped_this_step_ =
true;
829 }
else if (well_operable && !old_well_operable) {
830 deferred_logger.
info(
" well " + this->name() +
" gets REVIVED during iteration ");
832 changed_to_stopped_this_step_ =
false;
833 this->changed_to_open_this_step_ =
true;
837 template<
typename TypeTag>
841 if(!this->isOperableAndSolvable() && !this->wellIsStopped())
844 for (
int perfIdx = 0; perfIdx < this->number_of_perforations_; ++perfIdx) {
845 if (this->cells()[perfIdx] == cellIdx) {
846 for (
int i = 0; i < RateVector::dimension; ++i) {
847 rates[i] += connectionRates_[perfIdx][i];
853 template<
typename TypeTag>
856 for (
int perfIdx = 0; perfIdx < this->number_of_perforations_; ++perfIdx) {
857 if (this->cells()[perfIdx] == cellIdx) {
858 const unsigned activeCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::solventComponentIndex(phaseIdx));
859 return connectionRates_[perfIdx][activeCompIdx].value();
863 OPM_THROW(std::invalid_argument,
"The well with name " + this->name()
871 template<
typename TypeTag>
879 if (!param_.check_well_operability_) {
883 if (this->wellIsStopped() && !changed_to_stopped_this_step_) {
887 updateWellOperability(simulator, well_state, deferred_logger);
888 if (!this->operability_status_.isOperableAndSolvable()) {
889 this->operability_status_.use_vfpexplicit =
true;
890 deferred_logger.
debug(
"EXPLICIT_LOOKUP_VFP",
891 "well not operable, trying with explicit vfp lookup: " + this->name());
892 updateWellOperability(simulator, well_state, deferred_logger);
896 template<
typename TypeTag>
906 const auto& well_name = this->name();
907 assert(this->wellHasTHPConstraints(simulator.vanguard().summaryState()));
908 const auto& schedule = simulator.vanguard().schedule();
909 auto report_step_idx = simulator.episodeIndex();
910 const auto& glo = schedule.glo(report_step_idx);
911 if(glo.active() && glo.has_well(well_name)) {
912 const auto increment = glo.gaslift_increment();
913 auto alq = well_state.
getALQ(well_name);
916 well_state.
setALQ(well_name, alq);
918 iterateWellEquations(simulator, dt, well_state, group_state, deferred_logger)))
927 return iterateWellEquations(simulator, dt, well_state, group_state, deferred_logger);
931 template<
typename TypeTag>
938 const auto& summary_state = simulator.vanguard().summaryState();
939 const auto& well_name = this->name();
940 if (!this->wellHasTHPConstraints(summary_state)) {
941 const std::string msg = fmt::format(
"GLIFT WTEST: Well {} does not have THP constraints", well_name);
942 deferred_logger.
info(msg);
945 const auto& schedule = simulator.vanguard().schedule();
946 const auto report_step_idx = simulator.episodeIndex();
947 const auto& glo = schedule.glo(report_step_idx);
948 if (!glo.has_well(well_name)) {
949 const std::string msg = fmt::format(
950 "GLIFT WTEST: Well {} : Gas Lift not activated: "
951 "WLIFTOPT is probably missing. Skipping.", well_name);
952 deferred_logger.
info(msg);
955 const auto& gl_well = glo.well(well_name);
956 auto& max_alq_optional = gl_well.max_rate();
958 if (max_alq_optional) {
959 max_alq = *max_alq_optional;
962 const auto& well_ecl = this->wellEcl();
963 const auto& controls = well_ecl.productionControls(summary_state);
964 const auto& table = this->vfpProperties()->getProd()->getTable(controls.vfp_table_number);
965 const auto& alq_values = table.getALQAxis();
966 max_alq = alq_values.back();
968 well_state.
setALQ(well_name, max_alq);
969 const std::string msg = fmt::format(
970 "GLIFT WTEST: Well {} : Setting ALQ to max value: {}",
972 deferred_logger.
info(msg);
975 template<
typename TypeTag>
982 if (this->param_.local_well_solver_control_switching_) {
983 const bool success = updateWellOperabilityFromWellEq(simulator, well_state, deferred_logger);
987 deferred_logger.
debug(
"Operability check using well equations did not converge for well "
988 + this->name() +
", reverting to classical approach." );
991 this->operability_status_.resetOperability();
993 bool thp_controlled = this->isInjector() ? well_state.
well(this->index_of_well_).injection_cmode == Well::InjectorCMode::THP:
994 well_state.
well(this->index_of_well_).production_cmode == Well::ProducerCMode::THP;
995 bool bhp_controlled = this->isInjector() ? well_state.
well(this->index_of_well_).injection_cmode == Well::InjectorCMode::BHP:
996 well_state.
well(this->index_of_well_).production_cmode == Well::ProducerCMode::BHP;
1000 bool check_thp = thp_controlled || this->operability_status_.thp_limit_violated_but_not_switched;
1001 if (check_thp || bhp_controlled) {
1002 updateIPR(simulator, deferred_logger);
1003 checkOperabilityUnderBHPLimit(well_state, simulator, deferred_logger);
1007 checkOperabilityUnderTHPLimit(simulator, well_state, deferred_logger);
1011 template<
typename TypeTag>
1019 assert(this->param_.local_well_solver_control_switching_);
1020 this->operability_status_.resetOperability();
1022 const auto& group_state = simulator.problem().wellModel().groupState();
1023 const double dt = simulator.timeStepSize();
1025 bool converged = iterateWellEquations(simulator, dt, well_state_copy, group_state, deferred_logger);
1029 template<
typename TypeTag>
1039 const auto& well = this->well_ecl_;
1040 const int well_index = this->index_of_well_;
1041 auto& ws = well_state.
well(well_index);
1044 const auto& summaryState = simulator.vanguard().summaryState();
1045 const auto& schedule = simulator.vanguard().schedule();
1047 if (this->wellIsStopped()) {
1048 for (
int p = 0; p<np; ++p) {
1049 ws.surface_rates[p] = 0;
1055 if (this->isInjector() )
1057 const auto& controls = well.injectionControls(summaryState);
1059 InjectorType injectorType = controls.injector_type;
1061 switch (injectorType) {
1062 case InjectorType::WATER:
1067 case InjectorType::OIL:
1072 case InjectorType::GAS:
1078 OPM_DEFLOG_THROW(std::runtime_error,
"Expected WATER, OIL or GAS as type for injectors " + this->name(), deferred_logger );
1081 const auto current = ws.injection_cmode;
1084 case Well::InjectorCMode::RATE:
1086 ws.surface_rates[phasePos] = (1.0 - this->rsRvInj()) * controls.surface_rate;
1087 if(this->rsRvInj() > 0) {
1088 if (injectorType == InjectorType::OIL && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1090 }
else if (injectorType == InjectorType::GAS && FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1093 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 );
1099 case Well::InjectorCMode::RESV:
1101 std::vector<double> convert_coeff(this->number_of_phases_, 1.0);
1102 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, convert_coeff);
1103 const double coeff = convert_coeff[phasePos];
1104 ws.surface_rates[phasePos] = controls.reservoir_rate/coeff;
1108 case Well::InjectorCMode::THP:
1110 auto rates = ws.surface_rates;
1115 this->getRefDensity(),
1118 ws.thp = this->getTHPConstraint(summaryState);
1123 double total_rate = std::accumulate(rates.begin(), rates.end(), 0.0);
1124 if (total_rate <= 0.0)
1125 ws.surface_rates = ws.well_potentials;
1129 case Well::InjectorCMode::BHP:
1131 ws.bhp = controls.bhp_limit;
1132 double total_rate = 0.0;
1133 for (
int p = 0; p<np; ++p) {
1134 total_rate += ws.surface_rates[p];
1139 if (total_rate <= 0.0)
1140 ws.surface_rates = ws.well_potentials;
1144 case Well::InjectorCMode::GRUP:
1146 assert(well.isAvailableForGroupControl());
1147 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
1148 const double efficiencyFactor = well.getEfficiencyFactor();
1149 std::optional<double> target =
1150 this->getGroupInjectionTargetRate(group,
1159 ws.surface_rates[phasePos] = *target;
1162 case Well::InjectorCMode::CMODE_UNDEFINED:
1164 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name(), deferred_logger );
1174 ws.surface_rates[phasePos] = std::max(1.e-7, ws.surface_rates[phasePos]);
1177 ws.bhp = controls.bhp_limit;
1183 const auto current = ws.production_cmode;
1184 const auto& controls = well.productionControls(summaryState);
1186 case Well::ProducerCMode::ORAT:
1188 double current_rate = -ws.surface_rates[ pu.phase_pos[Oil] ];
1191 if (current_rate > 0.0) {
1192 for (
int p = 0; p<np; ++p) {
1193 ws.surface_rates[p] *= controls.oil_rate/current_rate;
1196 const std::vector<double> fractions = initialWellRateFractions(simulator, well_state);
1197 double control_fraction = fractions[pu.phase_pos[Oil]];
1198 if (control_fraction != 0.0) {
1199 for (
int p = 0; p<np; ++p) {
1200 ws.surface_rates[p] = - fractions[p] * controls.oil_rate/control_fraction;
1206 case Well::ProducerCMode::WRAT:
1208 double current_rate = -ws.surface_rates[ pu.phase_pos[Water] ];
1211 if (current_rate > 0.0) {
1212 for (
int p = 0; p<np; ++p) {
1213 ws.surface_rates[p] *= controls.water_rate/current_rate;
1216 const std::vector<double> fractions = initialWellRateFractions(simulator, well_state);
1217 double control_fraction = fractions[pu.phase_pos[Water]];
1218 if (control_fraction != 0.0) {
1219 for (
int p = 0; p<np; ++p) {
1220 ws.surface_rates[p] = - fractions[p] * controls.water_rate/control_fraction;
1226 case Well::ProducerCMode::GRAT:
1228 double current_rate = -ws.surface_rates[pu.phase_pos[Gas] ];
1231 if (current_rate > 0.0) {
1232 for (
int p = 0; p<np; ++p) {
1233 ws.surface_rates[p] *= controls.gas_rate/current_rate;
1236 const std::vector<double> fractions = initialWellRateFractions(simulator, well_state);
1237 double control_fraction = fractions[pu.phase_pos[Gas]];
1238 if (control_fraction != 0.0) {
1239 for (
int p = 0; p<np; ++p) {
1240 ws.surface_rates[p] = - fractions[p] * controls.gas_rate/control_fraction;
1248 case Well::ProducerCMode::LRAT:
1250 double current_rate = -ws.surface_rates[ pu.phase_pos[Water] ]
1251 - ws.surface_rates[ pu.phase_pos[Oil] ];
1254 if (current_rate > 0.0) {
1255 for (
int p = 0; p<np; ++p) {
1256 ws.surface_rates[p] *= controls.liquid_rate/current_rate;
1259 const std::vector<double> fractions = initialWellRateFractions(simulator, well_state);
1260 double control_fraction = fractions[pu.phase_pos[Water]] + fractions[pu.phase_pos[Oil]];
1261 if (control_fraction != 0.0) {
1262 for (
int p = 0; p<np; ++p) {
1263 ws.surface_rates[p] = - fractions[p] * controls.liquid_rate / control_fraction;
1269 case Well::ProducerCMode::CRAT:
1272 fmt::format(
"CRAT control not supported, well {}", this->name()),
1275 case Well::ProducerCMode::RESV:
1277 std::vector<double> convert_coeff(this->number_of_phases_, 1.0);
1278 this->rateConverter_.calcCoeff( 0, this->pvtRegionIdx_, ws.surface_rates, convert_coeff);
1279 double total_res_rate = 0.0;
1280 for (
int p = 0; p<np; ++p) {
1281 total_res_rate -= ws.surface_rates[p] * convert_coeff[p];
1283 if (controls.prediction_mode) {
1286 if (total_res_rate > 0.0) {
1287 for (
int p = 0; p<np; ++p) {
1288 ws.surface_rates[p] *= controls.resv_rate/total_res_rate;
1291 const std::vector<double> fractions = initialWellRateFractions(simulator, well_state);
1292 for (
int p = 0; p<np; ++p) {
1293 ws.surface_rates[p] = - fractions[p] * controls.resv_rate / convert_coeff[p];
1297 std::vector<double> hrates(this->number_of_phases_,0.);
1298 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
1299 hrates[pu.phase_pos[Water]] = controls.water_rate;
1301 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1302 hrates[pu.phase_pos[Oil]] = controls.oil_rate;
1304 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1305 hrates[pu.phase_pos[Gas]] = controls.gas_rate;
1307 std::vector<double> hrates_resv(this->number_of_phases_,0.);
1308 this->rateConverter_.calcReservoirVoidageRates( 0, this->pvtRegionIdx_, hrates, hrates_resv);
1309 double target = std::accumulate(hrates_resv.begin(), hrates_resv.end(), 0.0);
1312 if (total_res_rate > 0.0) {
1313 for (
int p = 0; p<np; ++p) {
1314 ws.surface_rates[p] *= target/total_res_rate;
1317 const std::vector<double> fractions = initialWellRateFractions(simulator, well_state);
1318 for (
int p = 0; p<np; ++p) {
1319 ws.surface_rates[p] = - fractions[p] * target / convert_coeff[p];
1326 case Well::ProducerCMode::BHP:
1328 ws.bhp = controls.bhp_limit;
1329 double total_rate = 0.0;
1330 for (
int p = 0; p<np; ++p) {
1331 total_rate -= ws.surface_rates[p];
1336 if (total_rate <= 0.0){
1337 for (
int p = 0; p<np; ++p) {
1338 ws.surface_rates[p] = -ws.well_potentials[p];
1343 case Well::ProducerCMode::THP:
1345 const bool update_success = updateWellStateWithTHPTargetProd(simulator, well_state, deferred_logger);
1347 if (!update_success) {
1351 auto rates = ws.surface_rates;
1352 this->adaptRatesForVFP(rates);
1354 well_state, rates, well, summaryState, this->getRefDensity(), deferred_logger);
1356 ws.thp = this->getTHPConstraint(summaryState);
1360 const double total_rate = -std::accumulate(rates.begin(), rates.end(), 0.0);
1361 if (total_rate <= 0.0) {
1362 for (
int p = 0; p < this->number_of_phases_; ++p) {
1363 ws.surface_rates[p] = -ws.well_potentials[p];
1369 case Well::ProducerCMode::GRUP:
1371 assert(well.isAvailableForGroupControl());
1372 const auto& group = schedule.getGroup(well.groupName(), this->currentStep());
1373 const double efficiencyFactor = well.getEfficiencyFactor();
1374 double scale = this->getGroupProductionTargetRate(group,
1384 for (
int p = 0; p<np; ++p) {
1385 ws.surface_rates[p] *= scale;
1387 ws.trivial_target =
false;
1389 ws.trivial_target =
true;
1393 case Well::ProducerCMode::CMODE_UNDEFINED:
1396 OPM_DEFLOG_THROW(std::runtime_error,
"Well control must be specified for well " + this->name() , deferred_logger);
1403 ws.bhp = controls.bhp_limit;
1408 template<
typename TypeTag>
1414 const int np = this->number_of_phases_;
1415 std::vector<double> scaling_factor(np);
1416 const auto& ws = well_state.
well(this->index_of_well_);
1418 double total_potentials = 0.0;
1419 for (
int p = 0; p<np; ++p) {
1420 total_potentials += ws.well_potentials[p];
1422 if (total_potentials > 0) {
1423 for (
int p = 0; p<np; ++p) {
1424 scaling_factor[p] = ws.well_potentials[p] / total_potentials;
1426 return scaling_factor;
1430 double total_tw = 0;
1431 const int nperf = this->number_of_perforations_;
1432 for (
int perf = 0; perf < nperf; ++perf) {
1433 total_tw += this->well_index_[perf];
1435 for (
int perf = 0; perf < nperf; ++perf) {
1436 const int cell_idx = this->well_cells_[perf];
1437 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
1438 const auto& fs = intQuants.fluidState();
1439 const double well_tw_fraction = this->well_index_[perf] / total_tw;
1440 double total_mobility = 0.0;
1441 for (
int p = 0; p < np; ++p) {
1442 int modelPhaseIdx = this->flowPhaseToModelPhaseIdx(p);
1443 total_mobility += fs.invB(modelPhaseIdx).value() * intQuants.mobility(modelPhaseIdx).value();
1445 for (
int p = 0; p < np; ++p) {
1446 int modelPhaseIdx = this->flowPhaseToModelPhaseIdx(p);
1447 scaling_factor[p] += well_tw_fraction * fs.invB(modelPhaseIdx).value() * intQuants.mobility(modelPhaseIdx).value() / total_mobility;
1450 return scaling_factor;
1455 template <
typename TypeTag>
1464 auto& ws = well_state.
well(this->index_of_well_);
1465 int nonzero_rate_index = -1;
1466 const double floating_point_error_epsilon = 1e-14;
1467 for (
int p = 0; p < this->number_of_phases_; ++p) {
1468 if (std::abs(ws.surface_rates[p]) > floating_point_error_epsilon) {
1469 if (nonzero_rate_index == -1) {
1470 nonzero_rate_index = p;
1479 std::vector<double> well_q_s = computeCurrentWellRates(simulator, deferred_logger);
1481 if (nonzero_rate_index == -1) {
1484 for (
int p = 0; p < this->number_of_phases_; ++p) {
1485 ws.surface_rates[p] = well_q_s[this->flowPhaseToModelCompIdx(p)];
1491 const double initial_nonzero_rate = ws.surface_rates[nonzero_rate_index];
1492 const int comp_idx_nz = this->flowPhaseToModelCompIdx(nonzero_rate_index);
1493 if (std::abs(well_q_s[comp_idx_nz]) > floating_point_error_epsilon) {
1494 for (
int p = 0; p < this->number_of_phases_; ++p) {
1495 if (p != nonzero_rate_index) {
1496 const int comp_idx = this->flowPhaseToModelCompIdx(p);
1497 double& rate = ws.surface_rates[p];
1498 rate = (initial_nonzero_rate / well_q_s[comp_idx_nz]) * (well_q_s[comp_idx]);
1504 template <
typename TypeTag>
1509 const double trans_mult,
1515 auto wi = std::vector<Scalar>
1516 (this->num_components_, this->well_index_[perf] * trans_mult);
1518 if constexpr (! Indices::gasEnabled) {
1522 const auto& wdfac = this->well_ecl_.getWDFAC();
1524 if (! wdfac.useDFactor() || (this->well_index_[perf] == 0.0)) {
1528 const double d = this->computeConnectionDFactor(perf, intQuants, ws);
1535 const auto& connection = this->well_ecl_.getConnections()[ws.
perf_data.
ecl_index[perf]];
1536 const double Kh = connection.Kh();
1537 const double scaling = 3.141592653589 * Kh * connection.wpimult();
1538 const unsigned gas_comp_idx = Indices::canonicalToActiveComponentIndex(FluidSystem::gasCompIdx);
1541 const double cell_pressure = getValue(intQuants.fluidState().pressure(FluidSystem::gasPhaseIdx));
1542 const double drawdown = cell_pressure - connection_pressure;
1543 const double invB = getValue(intQuants.fluidState().invB(FluidSystem::gasPhaseIdx));
1544 const double mob_g = getValue(intQuants.mobility(FluidSystem::gasPhaseIdx)) * invB;
1546 const double b = 2*scaling/wi[gas_comp_idx];
1547 const double c = -2*scaling*mob_g*drawdown;
1549 double consistent_Q = -1.0e20;
1551 const double r2n = b*b + 4*a*c;
1553 const double rn = std::sqrt(r2n);
1554 const double xn1 = (b-rn)*0.5/a;
1558 const double xn2 = (b+rn)*0.5/a;
1559 if (xn2 <= 0 && xn2 > consistent_Q) {
1565 const double r2p = b*b - 4*a*c;
1567 const double rp = std::sqrt(r2p);
1568 const double xp1 = (rp-b)*0.5/a;
1569 if (xp1 > 0 && xp1 < consistent_Q) {
1572 const double xp2 = -(rp+b)*0.5/a;
1573 if (xp2 > 0 && xp2 < consistent_Q) {
1577 wi[gas_comp_idx] = 1.0/(1.0/(trans_mult * this->well_index_[perf]) + (consistent_Q/2 * d / scaling));
1582 template <
typename TypeTag>
1588 if (! this->well_ecl_.getWDFAC().useDFactor()) {
1594 for (
int perf = 0; perf < this->number_of_perforations_; ++perf) {
1595 const int cell_idx = this->well_cells_[perf];
1596 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
1598 d_factor[perf] = this->computeConnectionDFactor(perf, intQuants, ws);
1602 template <
typename TypeTag>
1609 auto rhoGS = [regIdx = this->pvtRegionIdx()]() {
1610 return FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, regIdx);
1616 regIdx = this->pvtRegionIdx(), &intQuants]()
1618 const auto rv = getValue(intQuants.fluidState().Rv());
1620 const auto& gasPvt = FluidSystem::gasPvt();
1625 const double rv_sat = gasPvt.saturatedOilVaporizationFactor
1626 (regIdx, temperature, connection_pressure);
1628 if (! (rv < rv_sat)) {
1629 return gasPvt.saturatedViscosity(regIdx, temperature,
1630 connection_pressure);
1633 return gasPvt.viscosity(regIdx, temperature, connection_pressure,
1634 rv, getValue(intQuants.fluidState().Rvw()));
1637 const auto& connection = this->well_ecl_.getConnections()
1640 return this->well_ecl_.getWDFAC().getDFactor(rhoGS, gas_visc, connection);
1644 template <
typename TypeTag>
1651 &conns = this->well_ecl_.getConnections()]
1654 return conns[connIx[perf]].CF();
1660 for (
int perf = 0; perf < this->number_of_perforations_; ++perf) {
1661 const int cell_idx = this->well_cells_[perf];
1663 const auto& intQuants = simulator.model()
1664 .intensiveQuantities(cell_idx, 0);
1666 tmult[perf] = simulator.problem()
1667 .template wellTransMultiplier<double>(intQuants, cell_idx);
1669 ctf[perf] = connCF(perf) * tmult[perf];
1674 template<
typename TypeTag>
1678 if constexpr (Indices::oilEnabled) {
1679 return fs.pressure(FluidSystem::oilPhaseIdx);
1680 }
else if constexpr (Indices::gasEnabled) {
1681 return fs.pressure(FluidSystem::gasPhaseIdx);
1683 return fs.pressure(FluidSystem::waterPhaseIdx);
1687 template <
typename TypeTag>
1688 template<
class Value,
class Callback>
1693 std::vector<Value>& mob,
1694 Callback& extendEval,
1697 auto relpermArray = []()
1699 if constexpr (std::is_same_v<Value, Scalar>) {
1700 return std::array<Scalar,3>{};
1702 return std::array<Eval,3>{};
1705 const int cell_idx = this->well_cells_[perf];
1706 assert (
int(mob.size()) == this->num_components_);
1707 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
1708 const auto& materialLawManager = simulator.problem().materialLawManager();
1712 const int satid = this->saturation_table_number_[perf] - 1;
1713 const int satid_elem = materialLawManager->satnumRegionIdx(cell_idx);
1714 if (satid == satid_elem) {
1715 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
1716 if (!FluidSystem::phaseIsActive(phaseIdx)) {
1720 const unsigned activeCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::solventComponentIndex(phaseIdx));
1721 mob[activeCompIdx] = extendEval(intQuants.mobility(phaseIdx));
1723 if constexpr (has_solvent) {
1724 mob[Indices::contiSolventEqIdx] = extendEval(intQuants.solventMobility());
1727 const auto& paramsCell = materialLawManager->connectionMaterialLawParams(satid, cell_idx);
1728 auto relativePerms = relpermArray();
1729 MaterialLaw::relativePermeabilities(relativePerms, paramsCell, intQuants.fluidState());
1732 materialLawManager->connectionMaterialLawParams(satid_elem, cell_idx);
1735 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
1736 if (!FluidSystem::phaseIsActive(phaseIdx)) {
1740 const unsigned activeCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::solventComponentIndex(phaseIdx));
1741 mob[activeCompIdx] = extendEval(relativePerms[phaseIdx] / intQuants.fluidState().viscosity(phaseIdx));
1745 if constexpr (has_solvent) {
1746 OPM_DEFLOG_THROW(std::runtime_error,
"individual mobility for wells does not work in combination with solvent", deferred_logger);
1750 if (this->isInjector() && !this->inj_fc_multiplier_.empty()) {
1751 const auto perf_ecl_index = this->perforationData()[perf].ecl_index;
1752 const auto& connections = this->well_ecl_.getConnections();
1753 const auto& connection = connections[perf_ecl_index];
1754 if (connection.filterCakeActive()) {
1755 for (
auto& val : mob) {
1756 val *= this->inj_fc_multiplier_[perf];
1763 template<
typename TypeTag>
1770 const auto& summary_state = simulator.vanguard().summaryState();
1772 auto bhp_at_thp_limit = computeBhpAtThpLimitProdWithAlq(
1773 simulator, summary_state, this->getALQ(well_state), deferred_logger);
1774 if (bhp_at_thp_limit) {
1775 std::vector<double> rates(this->number_of_phases_, 0.0);
1776 if (thp_update_iterations) {
1777 computeWellRatesWithBhpIterations(simulator, *bhp_at_thp_limit,
1778 rates, deferred_logger);
1780 computeWellRatesWithBhp(simulator, *bhp_at_thp_limit,
1781 rates, deferred_logger);
1783 auto& ws = well_state.
well(this->name());
1784 ws.surface_rates = rates;
1785 ws.bhp = *bhp_at_thp_limit;
1786 ws.thp = this->getTHPConstraint(summary_state);
1793 template <
typename TypeTag>
1797 const std::function<
double(
const double)>& connPICalc,
1798 const std::vector<Scalar>& mobility,
1799 double* connPI)
const
1802 const int np = this->number_of_phases_;
1803 for (
int p = 0; p < np; ++p) {
1806 const auto connMob =
1807 mobility[this->flowPhaseToModelCompIdx(p)]
1808 * fs.invB(this->flowPhaseToModelPhaseIdx(p)).value();
1810 connPI[p] = connPICalc(connMob);
1813 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) &&
1814 FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx))
1816 const auto io = pu.phase_pos[Oil];
1817 const auto ig = pu.phase_pos[Gas];
1819 const auto vapoil = connPI[ig] * fs.Rv().value();
1820 const auto disgas = connPI[io] * fs.Rs().value();
1822 connPI[io] += vapoil;
1823 connPI[ig] += disgas;
1828 template <
typename TypeTag>
1832 const Phase preferred_phase,
1833 const std::function<
double(
const double)>& connIICalc,
1834 const std::vector<Scalar>& mobility,
1842 if (preferred_phase == Phase::GAS) {
1843 phase_pos = pu.phase_pos[Gas];
1845 else if (preferred_phase == Phase::OIL) {
1846 phase_pos = pu.phase_pos[Oil];
1848 else if (preferred_phase == Phase::WATER) {
1849 phase_pos = pu.phase_pos[Water];
1853 fmt::format(
"Unsupported Injector Type ({}) "
1854 "for well {} during connection I.I. calculation",
1855 static_cast<int>(preferred_phase), this->name()),
1859 const auto mt = std::accumulate(mobility.begin(), mobility.end(), 0.0);
1860 connII[phase_pos] = connIICalc(mt * fs.invB(this->flowPhaseToModelPhaseIdx(phase_pos)).value());
#define OPM_DEFLOG_THROW(Exception, message, deferred_logger)
Definition: DeferredLoggingErrorHelpers.hpp:45
@ Liquid
Definition: BlackoilPhases.hpp:42
@ Aqua
Definition: BlackoilPhases.hpp:42
@ Vapour
Definition: BlackoilPhases.hpp:42
Definition: DeferredLogger.hpp:57
void info(const std::string &tag, const std::string &message)
void warning(const std::string &tag, const std::string &message)
void debug(const std::string &tag, const std::string &message)
Definition: GroupState.hpp:35
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:184
std::vector< std::size_t > ecl_index
Definition: PerfData.hpp:98
std::vector< Scalar > connection_d_factor
Definition: PerfData.hpp:95
std::vector< Scalar > connection_compaction_tmult
Definition: PerfData.hpp:96
std::vector< Scalar > connection_transmissibility_factor
Definition: PerfData.hpp:94
std::vector< Scalar > pressure
Definition: PerfData.hpp:84
PerfData< Scalar > perf_data
Definition: SingleWellState.hpp:109
Scalar temperature
Definition: SingleWellState.hpp:89
Class for computing BHP limits.
Definition: WellBhpThpCalculator.hpp:42
double calculateMinimumBhpFromThp(const WellState< double > &well_state, const Well &well, const SummaryState &summaryState, const double rho) const
bool isStableSolution(const WellState< double > &well_state, const Well &well, const std::vector< double > &rates, const SummaryState &summaryState) const
std::optional< double > estimateStableBhp(const WellState< double > &well_state, const Well &well, const std::vector< double > &rates, const double rho, const SummaryState &summaryState) const
EvalWell calculateBhpFromThp(const WellState< double > &well_state, const std::vector< EvalWell > &rates, const Well &well, const SummaryState &summaryState, const double rho, DeferredLogger &deferred_logger) const
double wsolvent_
Definition: WellInterfaceGeneric.hpp:377
int number_of_perforations_
Definition: WellInterfaceGeneric.hpp:335
const std::vector< double > & wellIndex() const
Definition: WellInterfaceGeneric.hpp:170
Well well_ecl_
Definition: WellInterfaceGeneric.hpp:302
Definition: WellInterfaceIndices.hpp:35
bool updateWellControl(const Simulator &simulator, const IndividualOrGroup iog, WellState< Scalar > &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:194
std::optional< double > estimateOperableBhp(const Simulator &simulator, const double dt, WellState< Scalar > &well_state, const SummaryState &summary_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:576
bool solveWellWithBhp(const Simulator &simulator, const double dt, const double bhp, WellState< Scalar > &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:599
IndividualOrGroup
Definition: WellInterface.hpp:237
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: WellInterface.hpp:82
void getMobility(const Simulator &simulator, const int perf, std::vector< Value > &mob, Callback &extendEval, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1691
void assembleWellEq(const Simulator &simulator, const double dt, WellState< Scalar > &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:747
typename WellInterfaceFluidSystem< FluidSystem >::RateConverterType RateConverterType
Definition: WellInterface.hpp:105
BlackOilFluidState< Eval, FluidSystem, has_temperature, has_energy, Indices::compositionSwitchIdx >=0, has_watVapor, has_brine, has_saltPrecip, has_disgas_in_water, Indices::numPhases > FluidState
Definition: WellInterface.hpp:135
std::vector< RateVector > connectionRates_
Definition: WellInterface.hpp:374
bool updateWellStateWithTHPTargetProd(const Simulator &simulator, WellState< Scalar > &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1766
void addCellRates(RateVector &rates, int cellIdx) const
Definition: WellInterface_impl.hpp:839
Scalar volumetricSurfaceRateForConnection(int cellIdx, int phaseIdx) const
Definition: WellInterface_impl.hpp:855
void computeConnLevelInjInd(const FluidState &fs, const Phase preferred_phase, const std::function< double(const double)> &connIICalc, const std::vector< Scalar > &mobility, double *connII, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1831
bool iterateWellEquations(const Simulator &simulator, const double dt, WellState< Scalar > &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:453
void computeConnLevelProdInd(const FluidState &fs, const std::function< double(const double)> &connPICalc, const std::vector< Scalar > &mobility, double *connPI) const
Definition: WellInterface_impl.hpp:1796
GetPropType< TypeTag, Properties::IntensiveQuantities > IntensiveQuantities
Definition: WellInterface.hpp:85
void updateConnectionDFactor(const Simulator &simulator, SingleWellState< double > &ws) const
Definition: WellInterface_impl.hpp:1585
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: WellInterface.hpp:96
void checkWellOperability(const Simulator &simulator, const WellState< Scalar > &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:874
void updateWellOperability(const Simulator &simulator, const WellState< Scalar > &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:978
void updateWellStateRates(const Simulator &simulator, WellState< Scalar > &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1458
virtual void updateWellStateWithTarget(const Simulator &simulator, const GroupState< Scalar > &group_state, WellState< Scalar > &well_state, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:1032
double wfoam() const
Definition: WellInterface_impl.hpp:126
double wsalt() const
Definition: WellInterface_impl.hpp:140
Eval getPerfCellPressure(const FluidState &fs) const
Definition: WellInterface_impl.hpp:1676
bool gliftBeginTimeStepWellTestIterateWellEquations(const Simulator &simulator, const double dt, WellState< Scalar > &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:899
void updateConnectionTransmissibilityFactor(const Simulator &simulator, SingleWellState< double > &ws) const
Definition: WellInterface_impl.hpp:1647
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:54
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: WellInterface.hpp:83
static constexpr bool has_solvent
Definition: WellInterface.hpp:111
void prepareWellBeforeAssembling(const Simulator &simulator, const double dt, WellState< Scalar > &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:783
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: WellInterface.hpp:88
void solveWellEquation(const Simulator &simulator, WellState< Scalar > &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:690
double woxygen() const
Definition: WellInterface_impl.hpp:164
bool updateWellOperabilityFromWellEq(const Simulator &simulator, const WellState< Scalar > &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:1014
double wurea() const
Definition: WellInterface_impl.hpp:182
void gliftBeginTimeStepWellTestUpdateALQ(const Simulator &simulator, WellState< Scalar > &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:934
std::vector< double > initialWellRateFractions(const Simulator &simulator, const WellState< Scalar > &well_state) const
Definition: WellInterface_impl.hpp:1411
typename Base::Eval Eval
Definition: WellInterface.hpp:100
double computeConnectionDFactor(const int perf, const IntensiveQuantities &intQuants, const SingleWellState< double > &ws) const
Definition: WellInterface_impl.hpp:1605
virtual void init(const PhaseUsage *phase_usage_arg, const std::vector< double > &depth_arg, const double gravity_arg, const int num_cells, const std::vector< Scalar > &B_avg, const bool changed_to_open_this_step)
Definition: WellInterface_impl.hpp:91
void wellTesting(const Simulator &simulator, const double simulation_time, WellState< Scalar > &well_state, const GroupState< Scalar > &group_state, WellTestState &welltest_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:355
double wpolymer() const
Definition: WellInterface_impl.hpp:110
bool solveWellWithZeroRate(const Simulator &simulator, const double dt, WellState< Scalar > &well_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:635
bool solveWellForTesting(const Simulator &simulator, WellState< Scalar > &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:655
GetPropType< TypeTag, Properties::Indices > Indices
Definition: WellInterface.hpp:84
bool solveWellWithTHPConstraint(const Simulator &simulator, const double dt, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, WellState< Scalar > &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:486
bool updateWellControlAndStatusLocalIteration(const Simulator &simulator, WellState< Scalar > &well_state, const GroupState< Scalar > &group_state, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, const double WQTotal, DeferredLogger &deferred_logger, const bool fixed_control=false, const bool fixed_status=false)
Definition: WellInterface_impl.hpp:271
double wmicrobes() const
Definition: WellInterface_impl.hpp:152
void assembleWellEqWithoutIteration(const Simulator &simulator, const double dt, WellState< Scalar > &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:764
static constexpr bool has_zFraction
Definition: WellInterface.hpp:112
Definition: WellState.hpp:62
const SingleWellState< Scalar > & well(std::size_t well_index) const
Definition: WellState.hpp:300
void setALQ(const std::string &name, Scalar value)
Definition: WellState.hpp:180
int numPhases() const
The number of phases present.
Definition: WellState.hpp:254
Scalar getALQ(const std::string &name) const
Definition: WellState.hpp:175
@ NONE
Definition: DeferredLogger.hpp:46
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
VFPEvaluation bhp(const VFPProdTable &table, const double aqua, const double liquid, const double vapour, const double thp, const double alq, const double explicit_wfr, const double explicit_gfr, const bool use_vfpexplicit)
Definition: BlackoilPhases.hpp:27
PhaseUsage phaseUsage(const Phases &phases)
Determine the active phases.
std::string to_string(const ConvergenceReport::ReservoirFailure::Type t)
Solver parameters for the BlackoilModel.
Definition: BlackoilModelParameters.hpp:484
Definition: BlackoilPhases.hpp:46