22#ifndef OPM_MULTISEGMENTWELL_IMPL_HEADER_INCLUDED
23#define OPM_MULTISEGMENTWELL_IMPL_HEADER_INCLUDED
25#ifndef OPM_MULTISEGMENTWELL_HEADER_INCLUDED
30#include <opm/common/Exceptions.hpp>
31#include <opm/common/OpmLog/OpmLog.hpp>
33#include <opm/input/eclipse/Schedule/MSW/Segment.hpp>
34#include <opm/input/eclipse/Schedule/MSW/Valve.hpp>
35#include <opm/input/eclipse/Schedule/MSW/WellSegments.hpp>
36#include <opm/input/eclipse/Schedule/Well/Connection.hpp>
37#include <opm/input/eclipse/Schedule/Well/WellConnections.hpp>
39#include <opm/input/eclipse/Units/Units.hpp>
41#include <opm/material/densead/EvaluationFormat.hpp>
53#if COMPILE_GPU_BRIDGE && (HAVE_CUDA || HAVE_OPENCL)
61 template <
typename TypeTag>
68 const int pvtRegionIdx,
69 const int num_conservation_quantities,
71 const int index_of_well,
73 :
Base(well, pw_info, time_step, param, rate_converter, pvtRegionIdx, num_conservation_quantities, num_phases, index_of_well, perf_data)
76 , segment_fluid_initial_(this->numberOfSegments(), std::vector<
Scalar>(this->num_conservation_quantities_, 0.0))
77 , segment_initial_energy_(this->numberOfSegments(), 0.0)
79 , segment_pvt_(this->numberOfSegments())
82 if constexpr (has_solvent) {
83 OPM_THROW(std::runtime_error,
"solvent is not supported by multisegment well yet");
86 if constexpr (has_polymer) {
87 OPM_THROW(std::runtime_error,
"polymer is not supported by multisegment well yet");
90 if constexpr (Base::has_foam) {
91 OPM_THROW(std::runtime_error,
"foam is not supported by multisegment well yet");
94 if constexpr (Base::has_brine) {
95 OPM_THROW(std::runtime_error,
"brine is not supported by multisegment well yet");
98 if constexpr (Base::has_watVapor) {
99 OPM_THROW(std::runtime_error,
"water evaporation is not supported by multisegment well yet");
102 if constexpr (Base::has_micp) {
103 OPM_THROW(std::runtime_error,
"MICP is not supported by multisegment well yet");
106 if(this->rsRvInj() > 0) {
107 OPM_THROW(std::runtime_error,
108 "dissolved gas/ vapporized oil in injected oil/gas not supported by multisegment well yet."
109 " \n See (WCONINJE item 10 / WCONHIST item 8)");
112 this->thp_update_iterations =
true;
119 template <
typename TypeTag>
122 init(
const std::vector<Scalar>& depth_arg,
124 const std::vector< Scalar >& B_avg,
125 const bool changed_to_open_this_step)
127 Base::init(depth_arg, gravity_arg, B_avg, changed_to_open_this_step);
139 this->initMatrixAndVectors(this->parallel_well_info_);
142 for (
int local_perf_index = 0; local_perf_index < this->number_of_local_perforations_; ++local_perf_index) {
144 const int cell_idx = this->well_cells_[local_perf_index];
146 this->cell_perforation_depth_diffs_[local_perf_index] = depth_arg[cell_idx] - this->perf_depth_[this->parallel_well_info_.localPerfToActivePerf(local_perf_index)];
154 template <
typename TypeTag>
159 const auto& well_state = groupStateHelper.
wellState();
160 const bool stop_or_zero_rate_target = this->stoppedOrZeroRateTarget(groupStateHelper);
161 this->primary_variables_.update(well_state, stop_or_zero_rate_target);
169 template <
typename TypeTag>
174 this->scaleSegmentRatesWithWellRates(this->segments_.inlets(),
175 this->segments_.perforations(),
177 this->scaleSegmentPressuresWithBhp(well_state);
180 template <
typename TypeTag>
187 Base::updateWellStateWithTarget(simulator, groupStateHelper, well_state);
190 this->scaleSegmentRatesWithWellRates(this->segments_.inlets(),
191 this->segments_.perforations(),
193 this->scaleSegmentPressuresWithBhp(well_state);
199 template <
typename TypeTag>
203 const std::vector<Scalar>& B_avg,
204 const bool relax_tolerance)
const
206 const auto& well_state = groupStateHelper.
wellState();
208 return this->MSWEval::getWellConvergence(well_state,
211 this->param_.max_residual_allowed_,
212 this->param_.tolerance_wells_,
213 this->param_.relaxed_tolerance_flow_well_,
214 this->param_.tolerance_pressure_ms_wells_,
215 this->param_.relaxed_tolerance_pressure_ms_well_,
217 this->wellIsStopped());
225 template <
typename TypeTag>
230 if (!this->isOperableAndSolvable() && !this->wellIsStopped()) {
234 if (this->param_.matrix_add_well_contributions_) {
239 this->linSys_.apply(x, Ax);
246 template <
typename TypeTag>
251 if (!this->isOperableAndSolvable() && !this->wellIsStopped()) {
255 this->linSys_.apply(r);
260 template <
typename TypeTag>
268 if (!this->isOperableAndSolvable() && !this->wellIsStopped()) {
275 this->linSys_.recoverSolutionWell(x, xw);
277 updateWellState(simulator, xw, groupStateHelper, well_state);
279 catch (
const NumericalProblem& exp) {
283 deferred_logger.problem(
"In MultisegmentWell::recoverWellSolutionAndUpdateWellState for well "
284 + this->name() +
": "+exp.what());
293 template <
typename TypeTag>
299 std::vector<Scalar>& well_potentials)
302 const auto [compute_potential, bhp_controlled_well] =
305 if (!compute_potential) {
311 const auto potential_scope = this->potentialCalculationScope();
313 debug_cost_counter_ = 0;
314 bool converged_implicit =
false;
315 if (this->param_.local_well_solver_control_switching_) {
316 converged_implicit = computeWellPotentialsImplicit(simulator, groupStateHelper, well_potentials);
317 if (!converged_implicit) {
318 deferred_logger.debug(
"Implicit potential calculations failed for well "
319 + this->name() +
", reverting to original aproach.");
322 if (!converged_implicit) {
324 const auto& summaryState = simulator.vanguard().summaryState();
325 if (!Base::wellHasTHPConstraints(summaryState) || bhp_controlled_well) {
326 computeWellRatesAtBhpLimit(simulator, groupStateHelper, well_potentials);
328 well_potentials = computeWellPotentialWithTHP(
329 well_state, simulator, groupStateHelper);
332 deferred_logger.debug(
"Cost in iterations of finding well potential for well "
335 this->checkNegativeWellPotentials(well_potentials,
336 this->param_.check_well_operability_,
343 template<
typename TypeTag>
348 std::vector<Scalar>& well_flux)
const
350 if (this->well_ecl_.isInjector()) {
351 const auto controls = this->well_ecl_.injectionControls(simulator.vanguard().summaryState());
352 computeWellRatesWithBhpIterations(simulator, controls.bhp_limit, groupStateHelper, well_flux);
354 const auto controls = this->well_ecl_.productionControls(simulator.vanguard().summaryState());
355 computeWellRatesWithBhpIterations(simulator, controls.bhp_limit, groupStateHelper, well_flux);
359 template<
typename TypeTag>
364 std::vector<Scalar>& well_flux,
367 const int np = this->number_of_phases_;
369 well_flux.resize(np, 0.0);
370 const bool allow_cf = this->getAllowCrossFlow();
371 const int nseg = this->numberOfSegments();
372 const WellStateType& well_state = simulator.problem().wellModel().wellState();
373 const auto& ws = well_state.
well(this->indexOfWell());
374 auto segments_copy = ws.segments;
375 segments_copy.scale_pressure(bhp);
376 const auto& segment_pressure = segments_copy.pressure;
377 for (
int seg = 0; seg < nseg; ++seg) {
378 for (
const int perf : this->segments_.perforations()[seg]) {
379 const int local_perf_index = this->parallel_well_info_.activePerfToLocalPerf(perf);
380 if (local_perf_index < 0)
382 const int cell_idx = this->well_cells_[local_perf_index];
383 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
385 std::vector<Scalar> mob(this->num_conservation_quantities_, 0.);
386 getMobility(simulator, local_perf_index, mob, deferred_logger);
388 getTransMult(trans_mult, simulator, cell_idx);
389 const auto& wellstate_nupcol = simulator.problem().wellModel().nupcolWellState().well(this->index_of_well_);
390 std::vector<Scalar> Tw(this->num_conservation_quantities_,
391 this->well_index_[local_perf_index] * trans_mult);
392 this->getTw(Tw, local_perf_index, intQuants, trans_mult, wellstate_nupcol);
393 const Scalar seg_pressure = segment_pressure[seg];
394 std::vector<Scalar> cq_s(this->num_conservation_quantities_, 0.);
397 computePerfRate(intQuants, mob, Tw, seg, perf, seg_pressure,
398 allow_cf, cq_s, perf_press, perf_rates, deferred_logger);
400 for(
int p = 0; p < np; ++p) {
401 well_flux[FluidSystem::activeCompToActivePhaseIdx(p)] += cq_s[p];
405 this->parallel_well_info_.communication().sum(well_flux.data(), well_flux.size());
409 template<
typename TypeTag>
415 std::vector<Scalar>& well_flux)
const
428 auto guard = groupStateHelper_copy.
pushWellState(well_state_copy);
429 auto& ws = well_state_copy.
well(this->index_of_well_);
432 const auto& summary_state = simulator.vanguard().summaryState();
433 auto inj_controls = well_copy.
well_ecl_.isInjector()
434 ? well_copy.
well_ecl_.injectionControls(summary_state)
435 : Well::InjectionControls(0);
436 auto prod_controls = well_copy.
well_ecl_.isProducer()
437 ? well_copy.
well_ecl_.productionControls(summary_state) :
438 Well::ProductionControls(0);
442 inj_controls.bhp_limit = bhp;
443 ws.injection_cmode = Well::InjectorCMode::BHP;
445 prod_controls.bhp_limit = bhp;
446 ws.production_cmode = Well::ProducerCMode::BHP;
452 const int np = this->number_of_phases_;
454 for (
int phase = 0; phase < np; ++phase){
455 trivial = trivial && (ws.well_potentials[phase] == 0.0) ;
459 for (
int phase = 0; phase < np; ++phase) {
460 ws.surface_rates[phase] = sign * ws.well_potentials[phase];
464 this->segments_.perforations(),
468 const double dt = simulator.timeStepSize();
475 well_flux.resize(np, 0.0);
476 for (
int compIdx = 0; compIdx < this->num_conservation_quantities_; ++compIdx) {
478 well_flux[FluidSystem::activeCompToActivePhaseIdx(compIdx)] = rate.value();
485 template<
typename TypeTag>
486 std::vector<typename MultisegmentWell<TypeTag>::Scalar>
493 std::vector<Scalar> potentials(this->number_of_phases_, 0.0);
494 const auto& summary_state = simulator.vanguard().summaryState();
496 const auto& well = this->well_ecl_;
497 if (well.isInjector()) {
498 auto bhp_at_thp_limit = computeBhpAtThpLimitInj(simulator, groupStateHelper, summary_state);
499 if (bhp_at_thp_limit) {
500 const auto& controls = well.injectionControls(summary_state);
501 const Scalar bhp = std::min(*bhp_at_thp_limit,
502 static_cast<Scalar>(controls.bhp_limit));
503 computeWellRatesWithBhpIterations(simulator, bhp, groupStateHelper, potentials);
504 deferred_logger.debug(
"Converged thp based potential calculation for well "
507 deferred_logger.warning(
"FAILURE_GETTING_CONVERGED_POTENTIAL",
508 "Failed in getting converged thp based potential calculation for well "
509 + this->name() +
". Instead the bhp based value is used");
510 const auto& controls = well.injectionControls(summary_state);
511 const Scalar bhp = controls.bhp_limit;
512 computeWellRatesWithBhpIterations(simulator, bhp, groupStateHelper, potentials);
515 auto bhp_at_thp_limit = computeBhpAtThpLimitProd(
516 well_state, simulator, groupStateHelper, summary_state);
517 if (bhp_at_thp_limit) {
518 const auto& controls = well.productionControls(summary_state);
519 const Scalar bhp = std::max(*bhp_at_thp_limit,
520 static_cast<Scalar>(controls.bhp_limit));
521 computeWellRatesWithBhpIterations(simulator, bhp, groupStateHelper, potentials);
522 deferred_logger.debug(
"Converged thp based potential calculation for well "
525 deferred_logger.warning(
"FAILURE_GETTING_CONVERGED_POTENTIAL",
526 "Failed in getting converged thp based potential calculation for well "
527 + this->name() +
". Instead the bhp based value is used");
528 const auto& controls = well.productionControls(summary_state);
529 const Scalar bhp = controls.bhp_limit;
530 computeWellRatesWithBhpIterations(simulator, bhp, groupStateHelper, potentials);
537 template<
typename TypeTag>
542 std::vector<Scalar>& well_potentials)
const
553 auto guard = groupStateHelper_copy.
pushWellState(well_state_copy);
554 auto& ws = well_state_copy.
well(this->index_of_well_);
557 const auto& summary_state = simulator.vanguard().summaryState();
558 auto inj_controls = well_copy.
well_ecl_.isInjector()
559 ? well_copy.
well_ecl_.injectionControls(summary_state)
560 : Well::InjectionControls(0);
561 auto prod_controls = well_copy.
well_ecl_.isProducer()
562 ? well_copy.
well_ecl_.productionControls(summary_state)
563 : Well::ProductionControls(0);
571 const int np = this->number_of_phases_;
573 for (
int phase = 0; phase < np; ++phase){
574 trivial = trivial && (ws.well_potentials[phase] == 0.0) ;
578 for (
int phase = 0; phase < np; ++phase) {
579 ws.surface_rates[phase] = sign * ws.well_potentials[phase];
583 this->segments_.perforations(),
587 const double dt = simulator.timeStepSize();
589 bool converged =
false;
590 if (this->well_ecl_.isProducer()) {
592 simulator, dt, inj_controls, prod_controls, groupStateHelper_copy, well_state_copy
596 simulator, dt, inj_controls, prod_controls, groupStateHelper_copy, well_state_copy,
604 well_potentials.clear();
605 well_potentials.resize(np, 0.0);
606 for (
int compIdx = 0; compIdx < this->num_conservation_quantities_; ++compIdx) {
608 well_potentials[FluidSystem::activeCompToActivePhaseIdx(compIdx)] = rate.value();
614 template <
typename TypeTag>
621 if (!this->isOperableAndSolvable() && !this->wellIsStopped())
return;
628 const auto linear_solve_timer = this->solveLinearSolveTimer();
629 dx_well = this->linSys_.solve();
631 updateWellState(simulator, dx_well, groupStateHelper, well_state);
633 catch(
const NumericalProblem& exp) {
638 deferred_logger.
problem(
"In MultisegmentWell::solveEqAndUpdateWellState for well "
639 + this->name() +
": "+exp.what());
648 template <
typename TypeTag>
655 for (
int local_perf_index = 0; local_perf_index < this->number_of_local_perforations_; ++local_perf_index) {
658 std::vector<Scalar> kr(this->number_of_phases_, 0.0);
659 std::vector<Scalar> density(this->number_of_phases_, 0.0);
661 const int cell_idx = this->well_cells_[local_perf_index];
662 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
663 const auto& fs = intQuants.fluidState();
667 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
668 const int water_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
669 kr[water_pos] = intQuants.relativePermeability(FluidSystem::waterPhaseIdx).value();
670 sum_kr += kr[water_pos];
671 density[water_pos] = fs.density(FluidSystem::waterPhaseIdx).value();
674 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
675 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
676 kr[oil_pos] = intQuants.relativePermeability(FluidSystem::oilPhaseIdx).value();
677 sum_kr += kr[oil_pos];
678 density[oil_pos] = fs.density(FluidSystem::oilPhaseIdx).value();
681 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
682 const int gas_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
683 kr[gas_pos] = intQuants.relativePermeability(FluidSystem::gasPhaseIdx).value();
684 sum_kr += kr[gas_pos];
685 density[gas_pos] = fs.density(FluidSystem::gasPhaseIdx).value();
688 assert(sum_kr != 0.);
691 Scalar average_density = 0.;
692 for (
int p = 0; p < this->number_of_phases_; ++p) {
693 average_density += kr[p] * density[p];
695 average_density /= sum_kr;
697 this->cell_perforation_pressure_diffs_[local_perf_index] = this->gravity_ * average_density * this->cell_perforation_depth_diffs_[local_perf_index];
705 template <
typename TypeTag>
710 for (
int seg = 0; seg < this->numberOfSegments(); ++seg) {
711 const EvalWell volume_ratio =
712 this->segments_.computeVolumeRatio(seg, segmentPvt(segment_fluid_state_[seg]),
713 this->primary_variables_, deferred_logger);
714 const Scalar surface_volume = getSegmentSurfaceVolume(seg, volume_ratio).value();
715 for (
int comp_idx = 0; comp_idx < this->num_conservation_quantities_; ++comp_idx) {
716 segment_fluid_initial_[seg][comp_idx] = surface_volume * this->primary_variables_.surfaceVolumeFraction(seg, comp_idx).value();
718 if constexpr (has_energy) {
719 segment_initial_energy_[seg] = computeSegmentEnergy<Scalar>(seg);
728 template <
typename TypeTag>
732 const BVectorWell& dwells,
735 const Scalar relaxation_factor)
737 if (!this->isOperableAndSolvable() && !this->wellIsStopped())
return;
741 const Scalar dFLimit = this->param_.dwell_fraction_max_;
742 const Scalar max_pressure_change = this->param_.max_pressure_change_ms_wells_;
743 const bool stop_or_zero_rate_target =
744 this->stoppedOrZeroRateTarget(groupStateHelper);
745 this->primary_variables_.updateNewton(dwells,
748 stop_or_zero_rate_target,
749 max_pressure_change);
751 const auto& summary_state = simulator.vanguard().summaryState();
752 this->primary_variables_.copyToWellState(*
this, getRefDensity(),
758 auto& ws = well_state.
well(this->index_of_well_);
759 this->segments_.copyPhaseDensities(ws.segments);
763 const bool isThermal = simulator.vanguard().eclState().getSimulationConfig().isThermal();
764 const bool co2store = simulator.vanguard().eclState().runspec().co2Storage();
765 Base::calculateReservoirRates( (isThermal || co2store), well_state.
well(this->index_of_well_));
772 template <
typename TypeTag>
779 updatePrimaryVariables(groupStateHelper);
780 computePerfCellPressDiffs(simulator);
783 const auto info = this->getFirstPerfCellConditions(simulator);
784 updateSegmentFluidState(info, deferred_logger);
785 computeInitialSegmentInventory(deferred_logger);
792 template<
typename TypeTag>
800 auto fluidState = [&simulator,
this](
const int local_perf_index)
802 const auto cell_idx = this->well_cells_[local_perf_index];
803 return simulator.model()
804 .intensiveQuantities(cell_idx, 0).fluidState();
807 const int np = this->number_of_phases_;
808 auto setToZero = [np](
Scalar* x) ->
void
810 std::fill_n(x, np, 0.0);
813 auto addVector = [np](
const Scalar* src,
Scalar* dest) ->
void
815 std::transform(src, src + np, dest, dest, std::plus<>{});
818 auto& ws = well_state.
well(this->index_of_well_);
819 auto& perf_data = ws.perf_data;
820 auto* connPI = perf_data.prod_index.data();
821 auto* wellPI = ws.productivity_index.data();
825 const auto preferred_phase = this->well_ecl_.getPreferredPhase();
826 auto subsetPerfID = 0;
828 for (
const auto& perf : *this->perf_data_){
829 auto allPerfID = perf.ecl_index;
831 auto connPICalc = [&wellPICalc, allPerfID](
const Scalar mobility) ->
Scalar
836 std::vector<Scalar> mob(this->num_conservation_quantities_, 0.0);
841 getMobility(simulator,
static_cast<int>(subsetPerfID), mob, deferred_logger);
843 const auto& fs = fluidState(subsetPerfID);
846 if (this->isInjector()) {
847 this->computeConnLevelInjInd(fs, preferred_phase, connPICalc,
848 mob, connPI, deferred_logger);
851 this->computeConnLevelProdInd(fs, connPICalc, mob, connPI);
854 addVector(connPI, wellPI);
861 const auto& comm = this->parallel_well_info_.communication();
862 if (comm.size() > 1) {
863 comm.sum(wellPI, np);
866 assert (
static_cast<int>(subsetPerfID) == this->number_of_local_perforations_ &&
867 "Internal logic error in processing connections for PI/II");
874 template<
typename TypeTag>
878 [[maybe_unused]]
const int openConnIdx)
const
883 const auto segNum = this->wellEcl()
884 .getConnections()[globalConnIdx].segment();
886 const auto segIdx = this->wellEcl()
887 .getSegments().segmentNumberToIndex(segNum);
889 return this->segments_.density(segIdx).value();
896 template<
typename TypeTag>
901 if (this->number_of_local_perforations_ == 0) {
905 this->linSys_.extract(jacobian);
909 template<
typename TypeTag>
914 const int pressureVarIndex,
915 const bool use_well_weights,
916 const bool contract_d_diagonal,
919 if (this->number_of_local_perforations_ == 0) {
924 this->linSys_.extractCPRPressureMatrix(jacobian,
935 template<
typename TypeTag>
936 template<
class Value>
942 const std::vector<Value>& b_perfcells,
943 const std::vector<Value>& mob_perfcells,
944 const std::vector<Value>& Tw,
946 const Value& segment_pressure,
947 const Value& segment_density,
948 const bool& allow_cf,
949 const std::vector<Value>& cmix_s,
950 std::vector<Value>& cq_s,
955 const int local_perf_index = this->parallel_well_info_.activePerfToLocalPerf(perf);
956 if (local_perf_index < 0)
960 const Value perf_seg_press_diff = this->gravity() * segment_density *
961 this->segments_.local_perforation_depth_diff(local_perf_index);
963 const Scalar cell_perf_press_diff = this->cell_perforation_pressure_diffs_[local_perf_index];
967 perf_press = segment_pressure + perf_seg_press_diff;
970 const Value cell_press_at_perf = pressure_cell - cell_perf_press_diff;
973 const Value drawdown = cell_press_at_perf - perf_press;
976 if (drawdown > 0.0) {
978 if (!allow_cf && this->isInjector()) {
983 for (
int comp_idx = 0; comp_idx < this->numConservationQuantities(); ++comp_idx) {
984 const Value cq_p = - Tw[comp_idx] * (mob_perfcells[comp_idx] * drawdown);
985 cq_s[comp_idx] = b_perfcells[comp_idx] * cq_p;
988 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
989 const unsigned oilCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::oilCompIdx);
990 const unsigned gasCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
991 const Value cq_s_oil = cq_s[oilCompIdx];
992 const Value cq_s_gas = cq_s[gasCompIdx];
993 cq_s[gasCompIdx] += rs * cq_s_oil;
994 cq_s[oilCompIdx] += rv * cq_s_gas;
998 if (!allow_cf && this->isProducer()) {
1003 Value total_mob = mob_perfcells[0];
1004 for (
int comp_idx = 1; comp_idx < this->numConservationQuantities(); ++comp_idx) {
1005 total_mob += mob_perfcells[comp_idx];
1009 Value volume_ratio = 0.0;
1010 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
1011 const unsigned waterCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::waterCompIdx);
1012 volume_ratio += cmix_s[waterCompIdx] / b_perfcells[waterCompIdx];
1015 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1016 const unsigned oilCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::oilCompIdx);
1017 const unsigned gasCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
1022 const Value d = 1.0 - rv * rs;
1024 if (getValue(d) == 0.0) {
1026 fmt::format(
"Zero d value obtained for well {} "
1027 "during flux calculation with rs {} and rv {}",
1028 this->name(), rs, rv),
1032 const Value tmp_oil = (cmix_s[oilCompIdx] - rv * cmix_s[gasCompIdx]) / d;
1033 volume_ratio += tmp_oil / b_perfcells[oilCompIdx];
1035 const Value tmp_gas = (cmix_s[gasCompIdx] - rs * cmix_s[oilCompIdx]) / d;
1036 volume_ratio += tmp_gas / b_perfcells[gasCompIdx];
1038 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1039 const unsigned oilCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::oilCompIdx);
1040 volume_ratio += cmix_s[oilCompIdx] / b_perfcells[oilCompIdx];
1042 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1043 const unsigned gasCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
1044 volume_ratio += cmix_s[gasCompIdx] / b_perfcells[gasCompIdx];
1048 for (
int componentIdx = 0; componentIdx < this->numConservationQuantities(); ++componentIdx) {
1049 const Value cqt_i = - Tw[componentIdx] * (total_mob * drawdown);
1050 Value cqt_is = cqt_i / volume_ratio;
1051 cq_s[componentIdx] = cmix_s[componentIdx] * cqt_is;
1056 if (this->isProducer()) {
1057 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1058 const unsigned oilCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::oilCompIdx);
1059 const unsigned gasCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
1068 const Scalar d = 1.0 - getValue(rv) * getValue(rs);
1071 perf_rates.
vap_oil = getValue(rv) * (getValue(cq_s[gasCompIdx]) - getValue(rs) * getValue(cq_s[oilCompIdx])) / d;
1074 perf_rates.
dis_gas = getValue(rs) * (getValue(cq_s[oilCompIdx]) - getValue(rv) * getValue(cq_s[gasCompIdx])) / d;
1079 template <
typename TypeTag>
1080 template<
class Value>
1084 const std::vector<Value>& mob_perfcells,
1085 const std::vector<Value>& Tw,
1088 const Value& segment_pressure,
1089 const bool& allow_cf,
1090 std::vector<Value>& cq_s,
1096 auto obtain = [
this](
const Eval& value)
1098 if constexpr (std::is_same_v<Value, Scalar>) {
1099 static_cast<void>(
this);
1100 return getValue(value);
1102 return this->extendEval(value);
1105 auto obtainN = [](
const auto& value)
1107 if constexpr (std::is_same_v<Value, Scalar>) {
1108 return getValue(value);
1113 const auto& fs = int_quants.fluidState();
1115 const Value pressure_cell = obtain(this->getPerfCellPressure(fs));
1116 const Value rs = obtain(fs.Rs());
1117 const Value rv = obtain(fs.Rv());
1120 std::vector<Value> b_perfcells(this->num_conservation_quantities_, 0.0);
1122 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
1123 if (!FluidSystem::phaseIsActive(phaseIdx)) {
1127 const unsigned compIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
1128 b_perfcells[compIdx] = obtain(fs.invB(phaseIdx));
1131 std::vector<Value> cmix_s(this->numConservationQuantities(), 0.0);
1132 for (
int comp_idx = 0; comp_idx < this->numConservationQuantities(); ++comp_idx) {
1133 cmix_s[comp_idx] = obtainN(this->primary_variables_.surfaceVolumeFraction(seg, comp_idx));
1136 this->computePerfRate(pressure_cell,
1144 obtainN(this->segments_.density(seg)),
1153 template <
typename TypeTag>
1160 const FSInfo info = this->getFirstPerfCellConditions(simulator);
1161 updateSegmentFluidState(info, deferred_logger);
1163 for (
int seg = 0; seg < this->numberOfSegments(); ++seg) {
1164 segment_pvt_[seg] = segmentPvt(segment_fluid_state_[seg]);
1166 this->segments_.computeFluidProperties(segment_pvt_,
1167 this->primary_variables_,
1171 template <
typename TypeTag>
1178 const bool waterActive = FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx);
1179 const bool oilActive = FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx);
1180 const unsigned pressure_phase = waterActive ? FluidSystem::waterPhaseIdx
1181 : oilActive ? FluidSystem::oilPhaseIdx
1182 : FluidSystem::gasPhaseIdx;
1185 pvt.pressure = fluid_state.pressure(pressure_phase);
1186 pvt.temperature = fluid_state.temperature(pressure_phase);
1187 pvt.saltConcentration = fluid_state.saltConcentration();
1188 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
1189 if (FluidSystem::phaseIsActive(phaseIdx)) {
1190 pvt.invB[phaseIdx] = fluid_state.invB(phaseIdx);
1193 if constexpr (compositionSwitchEnabled) {
1194 pvt.Rs = fluid_state.Rs();
1195 pvt.Rv = fluid_state.Rv();
1200 template<
typename TypeTag>
1201 template<
class Value>
1206 const int cell_idx)
const
1208 auto obtain = [
this](
const Eval& value)
1210 if constexpr (std::is_same_v<Value, Scalar>) {
1211 static_cast<void>(
this);
1212 return getValue(value);
1214 return this->extendEval(value);
1220 template <
typename TypeTag>
1221 template<
class Value>
1225 const int local_perf_index,
1226 std::vector<Value>& mob,
1229 auto obtain = [
this](
const Eval& value)
1231 if constexpr (std::is_same_v<Value, Scalar>) {
1232 static_cast<void>(
this);
1233 return getValue(value);
1235 return this->extendEval(value);
1242 const auto perf_ecl_index = this->perforationData()[local_perf_index].ecl_index;
1243 const Connection& con = this->well_ecl_.getConnections()[perf_ecl_index];
1244 const int seg = this->segmentNumberToIndex(con.segment());
1248 const Scalar segment_pres = this->primary_variables_.getSegmentPressure(seg).value();
1249 const Scalar perf_seg_press_diff = this->gravity() * this->segments_.density(seg).value()
1250 * this->segments_.local_perforation_depth_diff(local_perf_index);
1251 const Scalar perf_press = segment_pres + perf_seg_press_diff;
1252 const Scalar multiplier = this->getInjMult(local_perf_index, segment_pres, perf_press, deferred_logger);
1253 for (std::size_t i = 0; i < mob.size(); ++i) {
1254 mob[i] *= multiplier;
1261 template<
typename TypeTag>
1266 return this->segments_.getRefDensity();
1269 template<
typename TypeTag>
1276 const auto& summaryState = simulator.vanguard().summaryState();
1280 const bool bhp_limit_not_defaulted = bhp_limit > 1.5 * unit::barsa;
1281 if ( bhp_limit_not_defaulted || !this->wellHasTHPConstraints(summaryState) ) {
1284 Scalar total_ipr_mass_rate = 0.0;
1285 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
1287 if (!FluidSystem::phaseIsActive(phaseIdx)) {
1291 const unsigned compIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
1292 const Scalar ipr_rate = this->ipr_a_[compIdx] - this->ipr_b_[compIdx] * bhp_limit;
1294 const Scalar rho = FluidSystem::referenceDensity( phaseIdx, Base::pvtRegionIdx() );
1295 total_ipr_mass_rate += ipr_rate * rho;
1297 if ( (this->isProducer() && total_ipr_mass_rate < 0.) || (this->isInjector() && total_ipr_mass_rate > 0.) ) {
1298 this->operability_status_.operable_under_only_bhp_limit =
false;
1302 if (this->operability_status_.operable_under_only_bhp_limit && this->wellHasTHPConstraints(summaryState)) {
1306 std::vector<Scalar> well_rates_bhp_limit;
1307 computeWellRatesWithBhp(simulator, bhp_limit, well_rates_bhp_limit, deferred_logger);
1309 const Scalar thp_limit = this->getTHPConstraint(summaryState);
1312 this->getRefDensity(),
1313 this->wellEcl().alq_value(summaryState),
1316 if ( (this->isProducer() && thp < thp_limit) || (this->isInjector() && thp > thp_limit) ) {
1317 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
1328 this->operability_status_.operable_under_only_bhp_limit =
true;
1329 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
1335 template<
typename TypeTag>
1343 std::ranges::fill(this->ipr_a_, 0.0);
1344 std::ranges::fill(this->ipr_b_, 0.0);
1346 const int nseg = this->numberOfSegments();
1347 std::vector<Scalar> seg_dp(nseg, 0.0);
1348 for (
int seg = 0; seg < nseg; ++seg) {
1350 const Scalar dp = this->getSegmentDp(seg,
1351 this->segments_.density(seg).value(),
1354 for (
const int perf : this->segments_.perforations()[seg]) {
1355 const int local_perf_index = this->parallel_well_info_.activePerfToLocalPerf(perf);
1356 if (local_perf_index < 0)
1358 std::vector<Scalar> mob(this->num_conservation_quantities_, 0.0);
1361 getMobility(simulator, local_perf_index, mob, deferred_logger);
1363 const int cell_idx = this->well_cells_[local_perf_index];
1364 const auto& int_quantities = simulator.model().intensiveQuantities(cell_idx, 0);
1365 const auto& fs = int_quantities.fluidState();
1367 const Scalar perf_seg_press_diff = this->segments_.getPressureDiffSegLocalPerf(seg, local_perf_index);
1369 const Scalar cell_perf_press_diff = this->cell_perforation_pressure_diffs_[local_perf_index];
1370 const Scalar pressure_cell = this->getPerfCellPressure(fs).value();
1373 std::vector<Scalar> b_perf(this->num_conservation_quantities_);
1374 for (std::size_t phase = 0; phase < FluidSystem::numPhases; ++phase) {
1375 if (!FluidSystem::phaseIsActive(phase)) {
1378 const unsigned comp_idx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phase));
1379 b_perf[comp_idx] = fs.invB(phase).value();
1383 const Scalar h_perf = cell_perf_press_diff + perf_seg_press_diff + dp;
1384 const Scalar pressure_diff = pressure_cell - h_perf;
1387 if ( (this->isProducer() && pressure_diff < 0.) || (this->isInjector() && pressure_diff > 0.) ) {
1388 deferred_logger.
debug(
"CROSSFLOW_IPR",
1389 "cross flow found when updateIPR for well " + this->name());
1394 getTransMult(trans_mult, simulator, cell_idx);
1395 const auto& wellstate_nupcol = simulator.problem().wellModel().nupcolWellState().well(this->index_of_well_);
1396 std::vector<Scalar> tw_perf(this->num_conservation_quantities_, this->well_index_[perf] * trans_mult);
1397 this->getTw(tw_perf, local_perf_index, int_quantities, trans_mult, wellstate_nupcol);
1398 std::vector<Scalar> ipr_a_perf(this->ipr_a_.size());
1399 std::vector<Scalar> ipr_b_perf(this->ipr_b_.size());
1400 for (
int comp_idx = 0; comp_idx < this->num_conservation_quantities_; ++comp_idx) {
1401 const Scalar tw_mob = tw_perf[comp_idx] * mob[comp_idx] * b_perf[comp_idx];
1402 ipr_a_perf[comp_idx] += tw_mob * pressure_diff;
1403 ipr_b_perf[comp_idx] += tw_mob;
1407 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1408 const unsigned oil_comp_idx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::oilCompIdx);
1409 const unsigned gas_comp_idx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
1410 const Scalar rs = (fs.Rs()).value();
1411 const Scalar rv = (fs.Rv()).value();
1413 const Scalar dis_gas_a = rs * ipr_a_perf[oil_comp_idx];
1414 const Scalar vap_oil_a = rv * ipr_a_perf[gas_comp_idx];
1416 ipr_a_perf[gas_comp_idx] += dis_gas_a;
1417 ipr_a_perf[oil_comp_idx] += vap_oil_a;
1419 const Scalar dis_gas_b = rs * ipr_b_perf[oil_comp_idx];
1420 const Scalar vap_oil_b = rv * ipr_b_perf[gas_comp_idx];
1422 ipr_b_perf[gas_comp_idx] += dis_gas_b;
1423 ipr_b_perf[oil_comp_idx] += vap_oil_b;
1426 for (std::size_t comp_idx = 0; comp_idx < ipr_a_perf.size(); ++comp_idx) {
1427 this->ipr_a_[comp_idx] += ipr_a_perf[comp_idx];
1428 this->ipr_b_[comp_idx] += ipr_b_perf[comp_idx];
1432 this->parallel_well_info_.communication().sum(this->ipr_a_.data(), this->ipr_a_.size());
1433 this->parallel_well_info_.communication().sum(this->ipr_b_.data(), this->ipr_b_.size());
1436 template<
typename TypeTag>
1451 auto rates = well_state.
well(this->index_of_well_).surface_rates;
1453 for (std::size_t p = 0; p < rates.size(); ++p) {
1454 zero_rates &= rates[p] == 0.0;
1456 auto& ws = well_state.
well(this->index_of_well_);
1458 const auto msg = fmt::format(
"updateIPRImplicit: Well {} has zero rate, IPRs might be problematic", this->name());
1459 deferred_logger.debug(msg);
1472 std::ranges::fill(ws.implicit_ipr_a, 0.0);
1473 std::ranges::fill(ws.implicit_ipr_b, 0.0);
1475 auto inj_controls = Well::InjectionControls(0);
1476 auto prod_controls = Well::ProductionControls(0);
1477 prod_controls.addControl(Well::ProducerCMode::BHP);
1478 prod_controls.bhp_limit = well_state.
well(this->index_of_well_).bhp;
1481 const auto cmode = ws.production_cmode;
1482 ws.production_cmode = Well::ProducerCMode::BHP;
1483 const double dt = simulator.timeStepSize();
1484 assembleWellEqWithoutIteration(simulator, groupStateHelper, dt, inj_controls, prod_controls, well_state,
1487 BVectorWell rhs(this->numberOfSegments());
1489 rhs[0][SPres] = -1.0;
1491 const BVectorWell x_well = this->linSys_.solve(rhs);
1492 constexpr int num_eq = MSWEval::numWellEq;
1493 for (
int comp_idx = 0; comp_idx < this->num_conservation_quantities_; ++comp_idx){
1494 const EvalWell comp_rate = this->primary_variables_.getQs(comp_idx);
1495 const int idx = FluidSystem::activeCompToActivePhaseIdx(comp_idx);
1496 for (
size_t pvIdx = 0; pvIdx < num_eq; ++pvIdx) {
1498 ws.implicit_ipr_b[idx] -= x_well[0][pvIdx]*comp_rate.derivative(pvIdx+Indices::numEq);
1500 ws.implicit_ipr_a[idx] = ws.implicit_ipr_b[idx]*ws.bhp - comp_rate.value();
1503 ws.production_cmode = cmode;
1506 template<
typename TypeTag>
1514 const auto& summaryState = simulator.vanguard().summaryState();
1515 const auto obtain_bhp = this->isProducer()
1516 ? computeBhpAtThpLimitProd(
1517 well_state, simulator, groupStateHelper, summaryState)
1518 : computeBhpAtThpLimitInj(simulator, groupStateHelper, summaryState);
1521 this->operability_status_.can_obtain_bhp_with_thp_limit =
true;
1524 this->operability_status_.obey_bhp_limit_with_thp_limit = (*obtain_bhp >= bhp_limit);
1526 const Scalar thp_limit = this->getTHPConstraint(summaryState);
1527 if (this->isProducer() && *obtain_bhp < thp_limit) {
1528 const std::string msg =
" obtained bhp " +
std::to_string(unit::convert::to(*obtain_bhp, unit::barsa))
1529 +
" bars is SMALLER than thp limit "
1531 +
" bars as a producer for well " + this->name();
1532 deferred_logger.debug(msg);
1534 else if (this->isInjector() && *obtain_bhp > thp_limit) {
1535 const std::string msg =
" obtained bhp " +
std::to_string(unit::convert::to(*obtain_bhp, unit::barsa))
1536 +
" bars is LARGER than thp limit "
1538 +
" bars as a injector for well " + this->name();
1539 deferred_logger.debug(msg);
1544 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
1545 this->operability_status_.obey_bhp_limit_with_thp_limit =
false;
1546 if (!this->wellIsStopped()) {
1547 const Scalar thp_limit = this->getTHPConstraint(summaryState);
1548 deferred_logger.debug(
" could not find bhp value at thp limit "
1550 +
" bar for well " + this->name() +
", the well might need to be closed ");
1559 template<
typename TypeTag>
1564 const Well::InjectionControls& inj_controls,
1565 const Well::ProductionControls& prod_controls,
1569 if (!this->isOperableAndSolvable() && !this->wellIsStopped())
return true;
1573 const int max_iter_number = this->param_.max_inner_iter_ms_wells_;
1577 const auto& [isFinite, residuals] = this->getFiniteWellResiduals(Base::B_avg_, deferred_logger);
1582 updatePrimaryVariables(groupStateHelper);
1584 std::vector<std::vector<Scalar> > residual_history;
1585 std::vector<Scalar> measure_history;
1587 const auto solve_scope = this->solveScope(it);
1589 Scalar relaxation_factor = 1.;
1590 bool converged =
false;
1591 bool relax_convergence =
false;
1592 this->regularize_ =
false;
1593 for (; it < max_iter_number; ++it, ++debug_cost_counter_) {
1595 if (it > this->param_.strict_inner_iter_wells_) {
1596 relax_convergence =
true;
1597 this->regularize_ =
true;
1600 assembleWellEqWithoutIteration(simulator, groupStateHelper, dt, inj_controls, prod_controls,
1604 const auto report = getWellConvergence(groupStateHelper, Base::B_avg_, relax_convergence);
1605 if (report.converged()) {
1612 const auto& [isFinite, residuals] = this->getFiniteWellResiduals(Base::B_avg_, deferred_logger);
1616 residual_history.push_back(residuals);
1617 measure_history.push_back(this->getResidualMeasureValue(well_state,
1618 residual_history[it],
1619 this->param_.tolerance_wells_,
1620 this->param_.tolerance_pressure_ms_wells_,
1623 bool min_relaxation_reached = this->update_relaxation_factor(measure_history, relaxation_factor, this->regularize_, deferred_logger);
1624 if (min_relaxation_reached || this->repeatedStagnation(measure_history, this->regularize_, deferred_logger)) {
1626 const auto reportStag = getWellConvergence(groupStateHelper, Base::B_avg_,
true);
1627 if (reportStag.converged()) {
1629 std::string message = fmt::format(
"Well stagnates/oscillates but {} manages to get converged with relaxed tolerances in {} inner iterations."
1631 deferred_logger.debug(message);
1638 BVectorWell dx_well;
1641 const auto linear_solve_timer = this->solveLinearSolveTimer();
1642 dx_well = this->linSys_.solve();
1644 updateWellState(simulator, dx_well, groupStateHelper, well_state, relaxation_factor);
1646 catch(
const NumericalProblem& exp) {
1650 deferred_logger.problem(
"In MultisegmentWell::iterateWellEqWithControl for well "
1651 + this->name() +
": "+exp.what());
1658 std::ostringstream sstr;
1659 sstr <<
" Well " << this->name() <<
" converged in " << it <<
" inner iterations.";
1660 if (relax_convergence)
1661 sstr <<
" (A relaxed tolerance was used after "<< this->param_.strict_inner_iter_wells_ <<
" iterations)";
1665 deferred_logger.debug(sstr.str(), OpmLog::defaultDebugVerbosityLevel + (it == 0));
1667 std::ostringstream sstr;
1668 sstr <<
" Well " << this->name() <<
" did not converge in " << it <<
" inner iterations.";
1669#define EXTRA_DEBUG_MSW 0
1671 sstr <<
"***** Outputting the residual history for well " << this->name() <<
" during inner iterations:";
1672 for (
int i = 0; i < it; ++i) {
1673 const auto& residual = residual_history[i];
1674 sstr <<
" residual at " << i <<
"th iteration ";
1675 for (
const auto& res : residual) {
1678 sstr <<
" " << measure_history[i] <<
" \n";
1681#undef EXTRA_DEBUG_MSW
1682 deferred_logger.debug(sstr.str());
1689 template<
typename TypeTag>
1694 const Well::InjectionControls& inj_controls,
1695 const Well::ProductionControls& prod_controls,
1698 const bool fixed_control ,
1699 const bool fixed_status ,
1700 const bool solving_with_zero_rate )
1704 const int max_iter_number = this->param_.max_inner_iter_ms_wells_;
1708 const auto& [isFinite, residuals] = this->getFiniteWellResiduals(Base::B_avg_, deferred_logger);
1713 updatePrimaryVariables(groupStateHelper);
1715 std::vector<std::vector<Scalar> > residual_history;
1716 std::vector<Scalar> measure_history;
1718 const auto solve_scope = this->solveScope(it);
1720 Scalar relaxation_factor = 1.;
1721 bool converged =
false;
1722 bool relax_convergence =
false;
1723 this->regularize_ =
false;
1724 const auto& summary_state = groupStateHelper.
summaryState();
1729 const int min_its_after_switch = 3;
1731 const int max_status_switch = this->param_.max_well_status_switch_inner_iter_;
1732 int its_since_last_switch = min_its_after_switch;
1733 int switch_count= 0;
1734 int status_switch_count = 0;
1736 const auto well_status_orig = this->wellStatus_;
1737 const auto operability_orig = this->operability_status_;
1738 auto well_status_cur = well_status_orig;
1740 const bool allow_open = well_state.
well(this->index_of_well_).status == WellStatus::OPEN;
1742 const bool allow_switching = !this->wellUnderZeroRateTarget(groupStateHelper) &&
1743 (!fixed_control || !fixed_status) && allow_open;
1744 bool final_check =
false;
1746 this->operability_status_.resetOperability();
1747 this->operability_status_.solvable =
true;
1749 for (; it < max_iter_number; ++it, ++debug_cost_counter_) {
1750 ++its_since_last_switch;
1751 if (allow_switching && its_since_last_switch >= min_its_after_switch && status_switch_count < max_status_switch){
1752 const Scalar wqTotal = this->primary_variables_.getWQTotal().value();
1753 bool changed = this->updateWellControlAndStatusLocalIteration(
1754 simulator, groupStateHelper, inj_controls, prod_controls, wqTotal,
1755 well_state, fixed_control, fixed_status,
1756 solving_with_zero_rate
1759 its_since_last_switch = 0;
1761 if (well_status_cur != this->wellStatus_) {
1762 well_status_cur = this->wellStatus_;
1763 status_switch_count++;
1766 if (!changed && final_check) {
1769 final_check =
false;
1771 if (status_switch_count == max_status_switch) {
1772 this->wellStatus_ = well_status_orig;
1776 if (it > this->param_.strict_inner_iter_wells_) {
1777 relax_convergence =
true;
1778 this->regularize_ =
true;
1781 assembleWellEqWithoutIteration(simulator, groupStateHelper, dt, inj_controls, prod_controls,
1782 well_state, solving_with_zero_rate);
1785 const auto report = getWellConvergence(groupStateHelper, Base::B_avg_, relax_convergence);
1786 converged = report.converged();
1787 if (this->parallel_well_info_.communication().size() > 1 &&
1788 this->parallel_well_info_.communication().max(converged) != this->parallel_well_info_.communication().min(converged)) {
1789 OPM_THROW(std::runtime_error, fmt::format(
"Misalignment of the parallel simulation run in iterateWellEqWithSwitching - the well calculation for well {} succeeded some ranks but failed on other ranks.", this->name()));
1794 if (switch_count > 0 && its_since_last_switch < min_its_after_switch) {
1796 its_since_last_switch = min_its_after_switch;
1804 const auto& [isFinite, residuals] = this->getFiniteWellResiduals(Base::B_avg_, deferred_logger);
1810 residual_history.push_back(residuals);
1814 measure_history.push_back(this->getResidualMeasureValue(well_state,
1815 residual_history[it],
1816 this->param_.tolerance_wells_,
1817 this->param_.tolerance_pressure_ms_wells_,
1819 bool min_relaxation_reached = this->update_relaxation_factor(measure_history, relaxation_factor, this->regularize_, deferred_logger);
1820 if (min_relaxation_reached || this->repeatedStagnation(measure_history, this->regularize_, deferred_logger)) {
1826 BVectorWell dx_well;
1828 const auto linear_solve_timer = this->solveLinearSolveTimer();
1829 dx_well = this->linSys_.solve();
1831 updateWellState(simulator, dx_well, groupStateHelper, well_state, relaxation_factor);
1833 catch(
const NumericalProblem& exp) {
1837 deferred_logger.problem(
"In MultisegmentWell::iterateWellEqWithSwitching for well "
1838 + this->name() +
": "+exp.what());
1844 if (allow_switching){
1846 const bool is_stopped = this->wellIsStopped();
1847 if (this->wellHasTHPConstraints(summary_state)){
1848 this->operability_status_.can_obtain_bhp_with_thp_limit = !is_stopped;
1849 this->operability_status_.obey_thp_limit_under_bhp_limit = !is_stopped;
1851 this->operability_status_.operable_under_only_bhp_limit = !is_stopped;
1854 std::string message = fmt::format(
" Well {} converged in {} inner iterations ("
1855 "{} control/status switches).", this->name(), it, switch_count);
1856 if (relax_convergence) {
1857 message.append(fmt::format(
" (A relaxed tolerance was used after {} iterations)",
1858 this->param_.strict_inner_iter_wells_));
1860 deferred_logger.debug(message, OpmLog::defaultDebugVerbosityLevel + ((it == 0) && (switch_count == 0)));
1862 this->wellStatus_ = well_status_orig;
1863 this->operability_status_ = operability_orig;
1864 const std::string message = fmt::format(
" Well {} did not converge in {} inner iterations ("
1865 "{} switches, {} status changes).", this->name(), it, switch_count, status_switch_count);
1866 deferred_logger.debug(message);
1867 this->primary_variables_.outputLowLimitPressureSegments(deferred_logger);
1874 template<
typename TypeTag>
1880 const Well::InjectionControls& inj_controls,
1881 const Well::ProductionControls& prod_controls,
1883 const bool solving_with_zero_rate)
1885 if (!this->isOperableAndSolvable() && !this->wellIsStopped())
return;
1887 const auto assemble_timer = this->solveAssembleTimer();
1892 this->segments_.updateUpwindingSegments(this->primary_variables_);
1895 computeSegmentFluidProperties(simulator, deferred_logger);
1898 this->linSys_.clear();
1900 auto& ws = well_state.
well(this->index_of_well_);
1901 if constexpr (has_energy) {
1902 ws.energy_rate = 0.0;
1910 const bool allow_cf = this->getAllowCrossFlow() || openCrossFlowAvoidSingularity(simulator);
1912 const int nseg = this->numberOfSegments();
1914 const Scalar rhow = FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx) ?
1915 FluidSystem::referenceDensity( FluidSystem::waterPhaseIdx, Base::pvtRegionIdx() ) : 0.0;
1916 const unsigned watCompIdx = FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx) ?
1917 FluidSystem::canonicalToActiveCompIdx(FluidSystem::waterCompIdx) : 0;
1919 for (
int seg = 0; seg < nseg; ++seg) {
1921 const EvalWell seg_pressure = this->primary_variables_.getSegmentPressure(seg);
1922 auto& perf_data = ws.perf_data;
1923 auto& perf_rates = perf_data.phase_rates;
1924 auto& perf_press_state = perf_data.pressure;
1925 for (
const int perf : this->segments_.perforations()[seg]) {
1926 const int local_perf_index = this->parallel_well_info_.activePerfToLocalPerf(perf);
1927 if (local_perf_index < 0)
1929 const int cell_idx = this->well_cells_[local_perf_index];
1930 const auto& int_quants = simulator.model().intensiveQuantities(cell_idx, 0);
1931 std::vector<EvalWell> mob(this->num_conservation_quantities_, 0.0);
1932 getMobility(simulator, local_perf_index, mob, deferred_logger);
1933 EvalWell trans_mult(0.0);
1934 getTransMult(trans_mult, simulator, cell_idx);
1935 const auto& wellstate_nupcol = simulator.problem().wellModel().nupcolWellState().well(this->index_of_well_);
1936 std::vector<EvalWell> Tw(this->num_conservation_quantities_, this->well_index_[local_perf_index] * trans_mult);
1937 this->getTw(Tw, local_perf_index, int_quants, trans_mult, wellstate_nupcol);
1938 std::vector<EvalWell> cq_s(this->num_conservation_quantities_, 0.0);
1939 EvalWell perf_press;
1941 computePerfRate(int_quants, mob, Tw, seg, perf, seg_pressure,
1942 allow_cf, cq_s, perf_press, perfRates, deferred_logger);
1945 if (this->isProducer()) {
1946 perf_data.phase_mixing_rates[local_perf_index][ws.dissolved_gas] = perfRates.
dis_gas;
1947 perf_data.phase_mixing_rates[local_perf_index][ws.vaporized_oil] = perfRates.
vap_oil;
1951 for (
int comp_idx = 0; comp_idx < this->num_conservation_quantities_; ++comp_idx) {
1952 perf_rates[local_perf_index*this->number_of_phases_ + FluidSystem::activeCompToActivePhaseIdx(comp_idx)] = cq_s[comp_idx].value();
1954 perf_press_state[local_perf_index] = perf_press.value();
1957 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
1958 perf_data.wat_mass_rates[local_perf_index] = cq_s[watCompIdx].value() * rhow;
1961 for (
int comp_idx = 0; comp_idx < this->num_conservation_quantities_; ++comp_idx) {
1963 const EvalWell cq_s_effective = cq_s[comp_idx] * this->well_efficiency_factor_;
1965 this->connectionRates_[local_perf_index][comp_idx] = Base::restrictEval(cq_s_effective);
1968 assemblePerforationEq(seg, local_perf_index, comp_idx, comp_idx, cq_s_effective, this->linSys_);
1972 if constexpr (has_energy) {
1973 assemblePerforationEnergyEq(int_quants, cq_s, seg, local_perf_index, deferred_logger);
1977 ws.energy_rate += getValue(this->connectionRates_[local_perf_index][Indices::contiEnergyEqIdx]);
1981 if constexpr (has_energy) {
1982 ws.energy_rate = this->parallel_well_info_.communication().sum(ws.energy_rate);
1985 if (this->parallel_well_info_.communication().size() > 1) {
1987 this->linSys_.sumDistributed(this->parallel_well_info_.communication());
1991 [[maybe_unused]]
FSInfo info{};
1992 if constexpr (has_energy) {
1993 info = this->getFirstPerfCellConditions(simulator);
1996 for (
int seg = 0; seg < nseg; ++seg) {
2000 const EvalWell segment_surface_volume =
2001 getSegmentSurfaceVolume(seg, this->segments_.volumeRatio(seg));
2006 const Scalar regularization_factor = this->regularize_? this->param_.regularization_factor_wells_ : 1.0;
2008 for (
int comp_idx = 0; comp_idx < this->num_conservation_quantities_; ++comp_idx) {
2009 const EvalWell accumulation_term = regularization_factor * (segment_surface_volume * this->primary_variables_.surfaceVolumeFraction(seg, comp_idx)
2010 - segment_fluid_initial_[seg][comp_idx]) / dt;
2012 assembleAccumulationTerm(seg, comp_idx, accumulation_term, this->linSys_);
2015 if constexpr (has_energy) {
2016 const EvalWell segment_energy = this->computeSegmentEnergy(seg);
2018 const EvalWell accumulation_term_energy =
2019 energy_scaling_factor_ * regularization_factor * (segment_energy - segment_initial_energy_[seg]) / dt;
2021 assembleAccumulationTerm(seg, MSWEval::PrimaryVariables::Temperature, accumulation_term_energy, this->linSys_);
2026 const int seg_upwind = this->segments_.upwinding_segment(seg);
2027 for (
int comp_idx = 0; comp_idx < this->num_conservation_quantities_; ++comp_idx) {
2028 const EvalWell segment_rate =
2029 this->primary_variables_.getSegmentRateUpwinding(seg,
2032 this->well_efficiency_factor_;
2034 assembleOutflowTerm(seg, seg_upwind, comp_idx, segment_rate, this->linSys_);
2036 if constexpr (has_energy) {
2037 const bool top_injecting_segment = (seg == 0) && this->isInjector();
2038 if (top_injecting_segment) {
2039 this->updateWellHeadCondition(simulator, info.temperature,
2040 info.saltConcentration, deferred_logger);
2045 const auto& upwind_fs = top_injecting_segment ? this->wellhead_fluid_state_
2046 : this->segment_fluid_state_[seg_upwind];
2047 assert((top_injecting_segment && seg_upwind == 0) || !top_injecting_segment);
2049 const EvalWell energy_rate =
2050 this->computeSegmentEnergyRate(seg, seg_upwind, upwind_fs,
2051 "energy outflow assembly", deferred_logger);
2053 assembleOutflowTerm(seg, seg_upwind, MSWEval::PrimaryVariables::Temperature, energy_rate, this->linSys_);
2059 for (
const int inlet : this->segments_.inlets()[seg]) {
2060 const int inlet_upwind = this->segments_.upwinding_segment(inlet);
2061 for (
int comp_idx = 0; comp_idx < this->num_conservation_quantities_; ++comp_idx) {
2062 const EvalWell inlet_rate =
2063 this->primary_variables_.getSegmentRateUpwinding(inlet,
2066 this->well_efficiency_factor_;
2068 assembleInflowTerm(seg, inlet, inlet_upwind, comp_idx, inlet_rate, this->linSys_);
2071 if constexpr (has_energy) {
2072 for (
const int inlet : this->segments_.inlets()[seg]) {
2073 const int inlet_upwind = this->segments_.upwinding_segment(inlet);
2075 const auto& upwind_fs = this->segment_fluid_state_[inlet_upwind];
2076 const EvalWell energy_rate =
2077 this->computeSegmentEnergyRate(inlet, inlet_upwind, upwind_fs,
2078 "energy inflow assembly", deferred_logger);
2080 assembleInflowTerm(seg, inlet, inlet_upwind, MSWEval::PrimaryVariables::Temperature, energy_rate, this->linSys_);
2087 const bool stopped_or_zero_target = this->stoppedOrZeroRateTarget(groupStateHelper);
2095 auto& group_state = solving_with_zero_rate
2099 auto group_guard = groupStateHelper_copy.
pushGroupState(group_state);
2101 if (this->wellUnderGroupControl(ws) && this->isProducer() && !stopped_or_zero_target) {
2102 this->updateGroupTargetFallbackFlag(well_state, deferred_logger);
2105 assembleControlEq(groupStateHelper_copy,
2108 this->getRefDensity(),
2109 this->primary_variables_,
2111 stopped_or_zero_target);
2113 const UnitSystem& unit_system = simulator.vanguard().eclState().getDeckUnitSystem();
2114 const auto& summary_state = simulator.vanguard().summaryState();
2115 this->assemblePressureEq(seg, unit_system, well_state, summary_state, this->param_.use_average_density_ms_wells_, deferred_logger);
2119 this->parallel_well_info_.communication().sum(this->ipr_a_.data(), this->ipr_a_.size());
2120 this->linSys_.createSolver();
2126 template<
typename TypeTag>
2131 return !this->getAllowCrossFlow() && allDrawDownWrongDirection(simulator);
2135 template<
typename TypeTag>
2140 bool all_drawdown_wrong_direction =
true;
2141 const int nseg = this->numberOfSegments();
2143 for (
int seg = 0; seg < nseg; ++seg) {
2144 const EvalWell segment_pressure = this->primary_variables_.getSegmentPressure(seg);
2145 for (
const int perf : this->segments_.perforations()[seg]) {
2146 const int local_perf_index = this->parallel_well_info_.activePerfToLocalPerf(perf);
2147 if (local_perf_index < 0)
2150 const int cell_idx = this->well_cells_[local_perf_index];
2151 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2152 const auto& fs = intQuants.fluidState();
2155 const EvalWell perf_seg_press_diff = this->segments_.getPressureDiffSegLocalPerf(seg, local_perf_index);
2157 const Scalar cell_perf_press_diff = this->cell_perforation_pressure_diffs_[local_perf_index];
2159 const Scalar pressure_cell = this->getPerfCellPressure(fs).value();
2160 const Scalar perf_press = pressure_cell - cell_perf_press_diff;
2163 const EvalWell drawdown = perf_press - (segment_pressure + perf_seg_press_diff);
2168 if ( (drawdown < 0. && this->isInjector()) ||
2169 (drawdown > 0. && this->isProducer()) ) {
2170 all_drawdown_wrong_direction =
false;
2175 const auto& comm = this->parallel_well_info_.communication();
2176 if (comm.size() > 1)
2178 all_drawdown_wrong_direction =
2179 (comm.min(all_drawdown_wrong_direction ? 1 : 0) == 1);
2182 return all_drawdown_wrong_direction;
2188 template<
typename TypeTag>
2199 template<
typename TypeTag>
2203 const EvalWell& volume_ratio)
const
2205 const Scalar volume = this->wellEcl().getSegments()[seg_idx].volume();
2206 return volume / volume_ratio;
2210 template<
typename TypeTag>
2211 std::optional<typename MultisegmentWell<TypeTag>::Scalar>
2216 const SummaryState& summary_state)
const
2222 this->getALQ(well_state),
2228 template<
typename TypeTag>
2229 std::optional<typename MultisegmentWell<TypeTag>::Scalar>
2233 const SummaryState& summary_state,
2235 bool iterate_if_no_solution)
const
2240 auto frates = [
this, &simulator, &deferred_logger](
const Scalar bhp) {
2246 std::vector<Scalar> rates(3);
2247 computeWellRatesWithBhp(simulator, bhp, rates, deferred_logger);
2252 computeBhpAtThpLimitProd(frates,
2254 maxPerfPress(simulator),
2255 this->getRefDensity(),
2257 this->getTHPConstraint(summary_state),
2263 if (!iterate_if_no_solution)
2264 return std::nullopt;
2266 auto fratesIter = [
this, &simulator, &groupStateHelper](
const Scalar bhp) {
2270 std::vector<Scalar> rates(3);
2271 computeWellRatesWithBhpIterations(simulator, bhp, groupStateHelper, rates);
2276 computeBhpAtThpLimitProd(fratesIter,
2278 maxPerfPress(simulator),
2279 this->getRefDensity(),
2281 this->getTHPConstraint(summary_state),
2285 template<
typename TypeTag>
2286 std::optional<typename MultisegmentWell<TypeTag>::Scalar>
2290 const SummaryState& summary_state)
const
2294 auto frates = [
this, &simulator, &deferred_logger](
const Scalar bhp) {
2300 std::vector<Scalar> rates(3);
2301 computeWellRatesWithBhp(simulator, bhp, rates, deferred_logger);
2306 computeBhpAtThpLimitInj(frates,
2308 this->getRefDensity(),
2317 auto fratesIter = [
this, &simulator, &groupStateHelper](
const Scalar bhp) {
2321 std::vector<Scalar> rates(3);
2322 computeWellRatesWithBhpIterations(simulator, bhp, groupStateHelper, rates);
2327 computeBhpAtThpLimitInj(fratesIter,
2329 this->getRefDensity(),
2340 template<
typename TypeTag>
2345 Scalar max_pressure = 0.0;
2346 const int nseg = this->numberOfSegments();
2347 for (
int seg = 0; seg < nseg; ++seg) {
2348 for (
const int perf : this->segments_.perforations()[seg]) {
2349 const int local_perf_index = this->parallel_well_info_.activePerfToLocalPerf(perf);
2350 if (local_perf_index < 0)
2353 const int cell_idx = this->well_cells_[local_perf_index];
2354 const auto& int_quants = simulator.model().intensiveQuantities(cell_idx, 0);
2355 const auto& fs = int_quants.fluidState();
2356 Scalar pressure_cell = this->getPerfCellPressure(fs).value();
2357 max_pressure = std::max(max_pressure, pressure_cell);
2360 max_pressure = this->parallel_well_info_.communication().max(max_pressure);
2361 return max_pressure;
2368 template<
typename TypeTag>
2369 std::vector<typename MultisegmentWell<TypeTag>::Scalar>
2375 std::vector<Scalar> well_q_s(this->num_conservation_quantities_, 0.0);
2376 const bool allow_cf = this->getAllowCrossFlow() || openCrossFlowAvoidSingularity(simulator);
2377 const int nseg = this->numberOfSegments();
2378 for (
int seg = 0; seg < nseg; ++seg) {
2380 const Scalar seg_pressure = getValue(this->primary_variables_.getSegmentPressure(seg));
2381 for (
const int perf : this->segments_.perforations()[seg]) {
2382 const int local_perf_index = this->parallel_well_info_.activePerfToLocalPerf(perf);
2383 if (local_perf_index < 0)
2386 const int cell_idx = this->well_cells_[local_perf_index];
2387 const auto& int_quants = simulator.model().intensiveQuantities(cell_idx, 0);
2388 std::vector<Scalar> mob(this->num_conservation_quantities_, 0.0);
2389 getMobility(simulator, local_perf_index, mob, deferred_logger);
2391 getTransMult(trans_mult, simulator, cell_idx);
2392 const auto& wellstate_nupcol = simulator.problem().wellModel().nupcolWellState().well(this->index_of_well_);
2393 std::vector<Scalar> Tw(this->num_conservation_quantities_, this->well_index_[local_perf_index] * trans_mult);
2394 this->getTw(Tw, local_perf_index, int_quants, trans_mult, wellstate_nupcol);
2395 std::vector<Scalar> cq_s(this->num_conservation_quantities_, 0.0);
2398 computePerfRate(int_quants, mob, Tw, seg, perf, seg_pressure,
2399 allow_cf, cq_s, perf_press, perf_rates, deferred_logger);
2400 for (
int comp = 0; comp < this->num_conservation_quantities_; ++comp) {
2401 well_q_s[comp] += cq_s[comp];
2405 const auto& comm = this->parallel_well_info_.communication();
2406 if (comm.size() > 1)
2408 comm.sum(well_q_s.data(), well_q_s.size());
2414 template <
typename TypeTag>
2415 std::vector<typename MultisegmentWell<TypeTag>::Scalar>
2419 const int num_seg = this->numberOfSegments();
2420 constexpr int num_eq = MSWEval::numWellEq;
2421 std::vector<Scalar> retval(num_seg * num_eq);
2422 for (
int ii = 0; ii < num_seg; ++ii) {
2423 const auto& pv = this->primary_variables_.value(ii);
2424 std::ranges::copy(pv, retval.begin() + ii * num_eq);
2432 template <
typename TypeTag>
2437 const int num_seg = this->numberOfSegments();
2438 constexpr int num_eq = MSWEval::numWellEq;
2439 std::array<Scalar, num_eq> tmp;
2440 for (
int ii = 0; ii < num_seg; ++ii) {
2441 const auto start = it + ii * num_eq;
2442 std::copy_n(start, num_eq, tmp.begin());
2443 this->primary_variables_.setValue(ii, tmp);
2445 return num_seg * num_eq;
2449 template <
typename TypeTag>
2455 this->primary_variables_.scaledWellFractions(scaled_fractions, deferred_logger);
2459 template <
typename TypeTag>
2460 template <
typename ValueType>
2464 const ValueType& pressure,
2465 const ValueType& temperature,
2466 const ValueType& saltConcentration,
2470 if constexpr (enable_temperature) {
2473 fluid_state.setTemperature(temperature);
2475 if constexpr (has_brine) {
2477 fluid_state.setSaltConcentration(saltConcentration);
2479 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2480 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2484 fluid_state.setPressure(phaseIdx, pressure);
2486 fluid_state.setPvtRegionIndex(this->pvtRegionIdx());
2488 const bool both_oil_gas = FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx);
2490 const ValueType zero_value {0.};
2492 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2493 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2497 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2500 case FluidSystem::oilPhaseIdx: {
2501 if constexpr (compositionSwitchEnabled) {
2504 ValueType rs = FluidSystem::saturatedDissolutionFactor(fluid_state, phaseIdx, fluid_state.pvtRegionIndex());
2505 if (fluid_composition[activeCompIdx] > 0.0) {
2506 const unsigned gasCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
2507 const ValueType max_possible_rs = fluid_composition[gasCompIdx] / fluid_composition[activeCompIdx];
2508 rs = std::min(rs, max_possible_rs);
2510 fluid_state.setRs(rs);
2512 fluid_state.setRs(zero_value);
2517 case FluidSystem::gasPhaseIdx: {
2518 if constexpr (compositionSwitchEnabled) {
2525 ValueType rv = FluidSystem::saturatedDissolutionFactor(fluid_state, phaseIdx, fluid_state.pvtRegionIndex());
2526 const unsigned oilCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::oilCompIdx);
2527 if (fluid_composition[activeCompIdx] > 0.0) {
2528 const ValueType max_possible_rv = fluid_composition[oilCompIdx] / fluid_composition[activeCompIdx];
2529 rv = std::min(rv, max_possible_rv);
2531 fluid_state.setRv(rv);
2533 fluid_state.setRv(zero_value);
2538 case FluidSystem::waterPhaseIdx: {
2543 throw std::logic_error(
"Unhandled phase index " +
std::to_string(phaseIdx));
2546 const auto& inv_b = FluidSystem::inverseFormationVolumeFactor(fluid_state, phaseIdx, fluid_state.pvtRegionIndex());
2547 fluid_state.setInvB(phaseIdx, inv_b);
2550 std::vector<ValueType> saturations (FluidSystem::numPhases, zero_value);
2551 ValueType sum_saturation {0.0};
2553 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2554 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2557 if (!both_oil_gas || FluidSystem::waterPhaseIdx == phaseIdx) {
2558 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2559 saturations[phaseIdx] = fluid_composition[activeCompIdx] / fluid_state.invB(phaseIdx);
2560 sum_saturation += saturations[phaseIdx];
2567 const ValueType d = 1.0 - fluid_state.Rv() * fluid_state.Rs();
2569 deferred_logger.
debug(
2570 fmt::format(
"Problematic d value {} obtained for well {}"
2571 " during createFluidState with rs {}"
2572 ", rv {}. Continue as if no dissolution (rs = 0) and"
2573 " vaporization (rv = 0)",
2574 d, this->name(), fluid_state.Rs(), fluid_state.Rv()) );
2578 if constexpr (compositionSwitchEnabled) {
2579 fluid_state.setRs(zero_value);
2580 fluid_state.setRv(zero_value);
2582 fluid_state.setInvB(FluidSystem::oilPhaseIdx,
2583 FluidSystem::inverseFormationVolumeFactor(fluid_state, FluidSystem::oilPhaseIdx, fluid_state.pvtRegionIndex()));
2584 fluid_state.setInvB(FluidSystem::gasPhaseIdx,
2585 FluidSystem::inverseFormationVolumeFactor(fluid_state, FluidSystem::gasPhaseIdx, fluid_state.pvtRegionIndex()));
2586 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2587 saturations[phaseIdx] = fluid_composition[activeCompIdx] / fluid_state.invB(phaseIdx);
2589 const unsigned oilCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::oilCompIdx);
2590 const unsigned gasCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
2591 if (FluidSystem::gasPhaseIdx == phaseIdx) {
2592 saturations[phaseIdx] = (fluid_composition[gasCompIdx] -
2593 fluid_state.Rs() * fluid_composition[oilCompIdx]) /
2594 (d * fluid_state.invB(phaseIdx));
2595 }
else if (FluidSystem::oilPhaseIdx == phaseIdx) {
2596 saturations[phaseIdx] = (fluid_composition[oilCompIdx] -
2597 fluid_state.Rv() * fluid_composition[gasCompIdx]) /
2598 (d * fluid_state.invB(phaseIdx));
2601 sum_saturation += saturations[phaseIdx];
2605 typename FluidSystem::template ParameterCache<ValueType> paramCache;
2606 paramCache.setRegionIndex(fluid_state.pvtRegionIndex());
2607 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2608 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2611 fluid_state.setSaturation(phaseIdx, saturations[phaseIdx] / sum_saturation);
2613 paramCache.updatePhase(fluid_state, phaseIdx);
2614 fluid_state.setDensity(phaseIdx, FluidSystem::density(fluid_state, paramCache, phaseIdx));
2615 if constexpr (has_energy) {
2616 fluid_state.setEnthalpy(phaseIdx, FluidSystem::enthalpy(fluid_state, paramCache, phaseIdx));
2623 template <
typename TypeTag>
2628 const EvalWell seg_pressure = this->primary_variables_.getSegmentPressure(seg);
2629 const Scalar firstPerfTemperature = info.temperature;
2631 const EvalWell seg_salt_concentration = info.saltConcentration;
2632 const EvalWell seg_temperature = has_energy ? this->primary_variables_.getSegmentTemperature(seg) : firstPerfTemperature;
2635 std::vector<EvalWell> fluid_composition(this->numConservationQuantities(), 0.0);
2636 for (
int idx = 0; idx < this->numConservationQuantities(); ++idx) {
2637 fluid_composition[idx] = this->primary_variables_.surfaceVolumeFraction(seg, idx);
2640 return createFluidState(fluid_composition, seg_pressure, seg_temperature,
2641 seg_salt_concentration, deferred_logger);
2644 template <
typename TypeTag>
2645 template <
typename Flu
idStateT>
2649 const FluidStateT& fs,
2650 const std::vector<EvalWell>& surface_rates,
2652 const std::string_view context,
2657 auto asEvalWell = [
this](
const auto& v) -> EvalWell {
2658 if constexpr (std::is_same_v<std::decay_t<
decltype(v)>, EvalWell>) {
2661 return this->extendEval(v);
2665 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2666 const EvalWell invB = asEvalWell(fs.invB(phaseIdx));
2667 const bool both_oil_gas = FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)
2668 && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx);
2669 if (!both_oil_gas || FluidSystem::waterPhaseIdx == phaseIdx) {
2670 return surface_rates[activeCompIdx] / invB;
2674 const EvalWell rs = asEvalWell(fs.Rs());
2675 const EvalWell rv = asEvalWell(fs.Rv());
2676 const EvalWell d = 1. - rs * rv;
2678 deferred_logger.
debug(
2679 fmt::format(
"Problematic d value {} obtained for well {}, segment {}"
2680 " during {} with rs {}, rv {}. Continue as if no dissolution"
2681 " (rs = 0) and vaporization (rv = 0) for this connection.",
2682 d, this->name(), seg, context, rs, rv));
2683 return surface_rates[activeCompIdx] / invB;
2685 const unsigned oilCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::oilCompIdx);
2686 const unsigned gasCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
2687 if (FluidSystem::gasPhaseIdx == phaseIdx) {
2688 return (surface_rates[gasCompIdx] - rs * surface_rates[oilCompIdx]) / (d * invB);
2690 if (FluidSystem::oilPhaseIdx == phaseIdx) {
2691 return (surface_rates[oilCompIdx] - rv * surface_rates[gasCompIdx]) / (d * invB);
2693 return EvalWell{0.0};
2696 template <
typename TypeTag>
2700 const int upwind_seg,
2702 const std::string_view context,
2706 std::vector<EvalWell> surface_rates(this->num_conservation_quantities_, 0.0);
2707 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2708 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2711 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2712 surface_rates[activeCompIdx] =
2713 this->primary_variables_.getSegmentRateUpwinding(seg,
2716 this->well_efficiency_factor_;
2719 EvalWell energy_rate(0.0);
2720 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2721 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2724 const EvalWell reservoir_rate =
2725 this->surfaceToReservoirRate(phaseIdx, upwind_fs, surface_rates,
2726 seg, context, deferred_logger);
2727 energy_rate += reservoir_rate * upwind_fs.enthalpy(phaseIdx) * upwind_fs.density(phaseIdx);
2730 return energy_scaling_factor_ * energy_rate;
2733 template <
typename TypeTag>
2737 const std::vector<EvalWell>& cq_s,
2739 const int local_perf_index,
2742 const auto& fs = int_quants.fluidState();
2744 const auto& seg_fs = this->segment_fluid_state_[seg];
2747 EvalWell energy_flux(0.0);
2748 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2749 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2753 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2755 const bool injecting = cq_s[activeCompIdx] > 0.0;
2757 EvalWell cq_r_thermal(0.0);
2760 cq_r_thermal = this->surfaceToReservoirRate(phaseIdx, seg_fs, cq_s,
2761 seg,
"energy assembly (injecting)",
2766 energy_flux += cq_r_thermal * seg_fs.enthalpy(phaseIdx) * seg_fs.density(phaseIdx);
2769 cq_r_thermal = this->surfaceToReservoirRate(phaseIdx, fs, cq_s,
2770 seg,
"energy assembly (producing)",
2772 energy_flux += cq_r_thermal * this->extendEval(fs.enthalpy(phaseIdx)) * this->extendEval(fs.density(phaseIdx));
2775 energy_flux *= this->well_efficiency_factor_;
2778 this->connectionRates_[local_perf_index][Indices::contiEnergyEqIdx] = Base::restrictEval(energy_flux);
2783 assemblePerforationEq(seg, local_perf_index,
2784 MSWEval::PrimaryVariables::Temperature,
2785 Indices::contiEnergyEqIdx,
2786 energy_scaling_factor_ * energy_flux,
2790 template <
typename TypeTag>
2793 const Scalar first_perf_temperature,
2794 const Scalar first_perf_salt_concentration,
2797 if (!this->well_ecl_.isInjector())
return;
2799 std::vector<EvalWell> fluid_composition(FluidSystem::numPhases, 0.0);
2803 const EvalWell bhp = this->primary_variables_.getSegmentPressure(0);
2807 const EvalWell inj_temperature = this->well_ecl_.hasInjTemperature()
2808 ? EvalWell{this->well_ecl_.inj_temperature()}
2809 : EvalWell{first_perf_temperature};
2811 const auto controls = this->well_ecl_.injectionControls(simulator.vanguard().summaryState());
2812 switch (controls.injector_type) {
2813 case InjectorType::OIL: {
2814 const unsigned oilActiveCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::oilCompIdx);
2815 fluid_composition[oilActiveCompIdx] = 1.0;
2818 case InjectorType::GAS: {
2819 const unsigned gasActiveCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
2820 fluid_composition[gasActiveCompIdx] = 1.0;
2823 case InjectorType::WATER: {
2824 const unsigned waterActiveCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::waterCompIdx);
2825 fluid_composition[waterActiveCompIdx] = 1.0;
2829 throw std::logic_error(
"Unsupported injection type " +
std::to_string(
static_cast<int>(controls.injector_type)));
2834 const EvalWell inj_salt_concentration{first_perf_salt_concentration};
2836 this->wellhead_fluid_state_ = createFluidState(fluid_composition, bhp, inj_temperature,
2837 inj_salt_concentration, deferred_logger);
2841 template <
typename TypeTag>
2842 template <
typename ValueType>
2846 auto obtain = [](
const auto& val) {
2847 if constexpr (std::is_same_v<ValueType, Scalar>) {
2848 return getValue(val);
2854 ValueType result {0.};
2855 const auto& segment_fluid_state = this->segment_fluid_state_[seg];
2856 const Scalar segment_volume = this->wellEcl().getSegments()[seg].volume();
2857 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2858 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2861 const auto u = obtain(segment_fluid_state.internalEnergy(phaseIdx));
2862 const auto s = obtain(segment_fluid_state.saturation(phaseIdx));
2863 const auto rho = obtain(segment_fluid_state.density(phaseIdx));
2864 result += segment_volume * u * s * rho;
2870 template <
typename TypeTag>
2875 for (
int seg = 0; seg < this->numberOfSegments(); ++seg) {
2876 segment_fluid_state_[seg] = this->createSegmentFluidState(seg, info, deferred_logger);
#define OPM_DEFLOG_PROBLEM(Exception, message, deferred_logger)
Definition: DeferredLoggingErrorHelpers.hpp:63
Definition: ConvergenceReport.hpp:38
Definition: DeferredLogger.hpp:57
void problem(const std::string &tag, const std::string &message)
void debug(const std::string &tag, const std::string &message)
Definition: GroupStateHelper.hpp:56
GroupState< Scalar > & groupState() const
Definition: GroupStateHelper.hpp:301
const SummaryState & summaryState() const
Definition: GroupStateHelper.hpp:441
const WellState< Scalar, IndexTraits > & wellState() const
Definition: GroupStateHelper.hpp:522
DeferredLogger & deferredLogger() const
Get the deferred logger.
Definition: GroupStateHelper.hpp:233
WellStateGuard pushWellState(WellState< Scalar, IndexTraits > &well_state)
Definition: GroupStateHelper.hpp:380
GroupStateGuard pushGroupState(GroupState< Scalar > &group_state)
Definition: GroupStateHelper.hpp:357
Definition: GroupState.hpp:42
Class handling assemble of the equation system for MultisegmentWell.
Definition: MultisegmentWellAssemble.hpp:45
typename PrimaryVariables::EvalWell EvalWell
Definition: MultisegmentWellEval.hpp:73
PrimaryVariables primary_variables_
The primary variables.
Definition: MultisegmentWellEval.hpp:163
void scaleSegmentRatesWithWellRates(const std::vector< std::vector< int > > &segment_inlets, const std::vector< std::vector< int > > &segment_perforations, WellState< Scalar, IndexTraits > &well_state) const
void scaleSegmentPressuresWithBhp(WellState< Scalar, IndexTraits > &well_state) const
Definition: MultisegmentWell.hpp:42
bool computeWellPotentialsImplicit(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, std::vector< Scalar > &well_potentials) const
Definition: MultisegmentWell_impl.hpp:540
bool iterateWellEqWithSwitching(const Simulator &simulator, const double dt, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, const GroupStateHelperType &groupStateHelper, WellStateType &well_state, const bool fixed_control, const bool fixed_status, const bool solving_with_zero_rate) override
Definition: MultisegmentWell_impl.hpp:1692
void updateWellState(const Simulator &simulator, const BVectorWell &dwells, const GroupStateHelperType &groupStateHelper, WellStateType &well_state, const Scalar relaxation_factor=1.0)
Definition: MultisegmentWell_impl.hpp:731
void updateWaterThroughput(const double dt, WellStateType &well_state) const override
Definition: MultisegmentWell_impl.hpp:2191
void assembleWellEqWithoutIteration(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, const double dt, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, WellStateType &well_state, const bool solving_with_zero_rate) override
Definition: MultisegmentWell_impl.hpp:1877
Scalar connectionDensity(const int globalConnIdx, const int openConnIdx) const override
Definition: MultisegmentWell_impl.hpp:877
void addWellContributions(SparseMatrixAdapter &jacobian) const override
Definition: MultisegmentWell_impl.hpp:899
void getTransMult(Value &trans_mult, const Simulator &simulator, const int cell_indx) const
Definition: MultisegmentWell_impl.hpp:1204
typename Base::FSInfo FSInfo
Definition: MultisegmentWell.hpp:96
EvalWell surfaceToReservoirRate(unsigned phaseIdx, const FluidStateT &fs, const std::vector< EvalWell > &surface_rates, int seg, std::string_view context, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:2648
std::vector< Scalar > computeWellPotentialWithTHP(const WellStateType &well_state, const Simulator &simulator, const GroupStateHelperType &groupStateHelper) const
Definition: MultisegmentWell_impl.hpp:488
Scalar getRefDensity() const override
Definition: MultisegmentWell_impl.hpp:1264
EvalWell getSegmentSurfaceVolume(const int seg_idx, const EvalWell &volume_ratio) const
Definition: MultisegmentWell_impl.hpp:2202
EvalWell computeSegmentEnergyRate(int seg, int upwind_seg, const SegmentFluidState< EvalWell > &upwind_fs, std::string_view context, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:2699
void updateWellStateWithTarget(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state) const override
updating the well state based the current control mode
Definition: MultisegmentWell_impl.hpp:183
std::vector< Scalar > getPrimaryVars() const override
Definition: MultisegmentWell_impl.hpp:2417
void computeWellRatesWithBhpIterations(const Simulator &simulator, const Scalar &bhp, const GroupStateHelperType &groupStateHelper, std::vector< Scalar > &well_flux) const override
Definition: MultisegmentWell_impl.hpp:412
void checkOperabilityUnderTHPLimit(const Simulator &ebos_simulator, const WellStateType &well_state, const GroupStateHelperType &groupStateHelper) override
Definition: MultisegmentWell_impl.hpp:1509
bool iterateWellEqWithControl(const Simulator &simulator, const double dt, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, const GroupStateHelperType &groupStateHelper, WellStateType &well_state) override
Definition: MultisegmentWell_impl.hpp:1562
ValueType computeSegmentEnergy(int seg) const
Definition: MultisegmentWell_impl.hpp:2844
std::vector< Scalar > computeCurrentWellRates(const Simulator &simulator, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:2371
void apply(const BVector &x, BVector &Ax) const override
Ax = Ax - C D^-1 B x.
Definition: MultisegmentWell_impl.hpp:228
MultisegmentWell(const Well &well, const ParallelWellInfo< Scalar > &pw_info, const int time_step, const ModelParameters ¶m, const RateConverterType &rate_converter, const int pvtRegionIdx, const int num_conservation_quantities, const int num_phases, const int index_of_well, const std::vector< PerforationData< Scalar > > &perf_data)
Definition: MultisegmentWell_impl.hpp:63
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: WellInterface.hpp:85
void checkOperabilityUnderBHPLimit(const WellStateType &well_state, const Simulator &ebos_simulator, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:1272
void getMobility(const Simulator &simulator, const int local_perf_index, std::vector< Value > &mob, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:1224
SegmentPvt segmentPvt(const SegmentFluidState< EvalWell > &fluid_state) const
Definition: MultisegmentWell_impl.hpp:1174
void recoverWellSolutionAndUpdateWellState(const Simulator &simulator, const BVector &x, const GroupStateHelperType &groupStateHelper, WellStateType &well_state) override
Definition: MultisegmentWell_impl.hpp:263
void addWellPressureEquations(PressureMatrix &mat, const BVector &x, const int pressureVarIndex, const bool use_well_weights, const bool contract_d_diagonal, const WellStateType &well_state) const override
Definition: MultisegmentWell_impl.hpp:912
void assemblePerforationEnergyEq(const IntensiveQuantities &int_quants, const std::vector< EvalWell > &cq_s, const int seg, const int local_perf_index, DeferredLogger &deferred_logger)
Definition: MultisegmentWell_impl.hpp:2736
bool openCrossFlowAvoidSingularity(const Simulator &simulator) const
Definition: MultisegmentWell_impl.hpp:2129
void computeSegmentFluidProperties(const Simulator &simulator, DeferredLogger &deferred_logger)
Definition: MultisegmentWell_impl.hpp:1156
int setPrimaryVars(typename std::vector< Scalar >::const_iterator it) override
Definition: MultisegmentWell_impl.hpp:2435
void computeWellRatesWithBhp(const Simulator &simulator, const Scalar &bhp, std::vector< Scalar > &well_flux, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:362
void updateSegmentFluidState(const FSInfo &info, DeferredLogger &deferred_logger)
Definition: MultisegmentWell_impl.hpp:2872
Base::template BlackOilFluidStateType< ValueType > SegmentFluidState
Definition: MultisegmentWell.hpp:107
void scaleSegmentRatesAndPressure(WellStateType &well_state) const override
updating the segment pressure and rates based the current bhp and well rates
Definition: MultisegmentWell_impl.hpp:172
bool allDrawDownWrongDirection(const Simulator &simulator) const
Definition: MultisegmentWell_impl.hpp:2138
int debug_cost_counter_
Definition: MultisegmentWell.hpp:245
void updateProductivityIndex(const Simulator &simulator, const WellProdIndexCalculator< Scalar > &wellPICalc, WellStateType &well_state, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:795
typename MultisegmentWellSegments< FluidSystem, Indices >::SegmentPvt SegmentPvt
Definition: MultisegmentWell.hpp:112
std::optional< Scalar > computeBhpAtThpLimitProd(const WellStateType &well_state, const Simulator &ebos_simulator, const GroupStateHelperType &groupStateHelper, const SummaryState &summary_state) const
Definition: MultisegmentWell_impl.hpp:2213
Scalar maxPerfPress(const Simulator &simulator) const override
Definition: MultisegmentWell_impl.hpp:2343
void computePerfRate(const IntensiveQuantities &int_quants, const std::vector< Value > &mob_perfcells, const std::vector< Value > &Tw, const int seg, const int perf, const Value &segment_pressure, const bool &allow_cf, std::vector< Value > &cq_s, Value &perf_press, PerforationRates< Scalar > &perf_rates, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:1083
SegmentFluidState< EvalWell > createSegmentFluidState(int seg, const FSInfo &info, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:2625
SegmentFluidState< ValueType > createFluidState(const std::vector< ValueType > &fluid_composition, const ValueType &pressure, const ValueType &temperature, const ValueType &saltConcentration, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:2463
void computeWellPotentials(const Simulator &simulator, const WellStateType &well_state, const GroupStateHelperType &groupStateHelper, std::vector< Scalar > &well_potentials) override
computing the well potentials for group control
Definition: MultisegmentWell_impl.hpp:296
void calculateExplicitQuantities(const Simulator &simulator, const GroupStateHelperType &groupStateHelper) override
Definition: MultisegmentWell_impl.hpp:775
void computePerfCellPressDiffs(const Simulator &simulator)
Definition: MultisegmentWell_impl.hpp:651
void solveEqAndUpdateWellState(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state) override
Definition: MultisegmentWell_impl.hpp:617
void updateWellHeadCondition(const Simulator &simulator, const Scalar first_perf_temperature, const Scalar first_perf_salt_concentration, DeferredLogger &deferred_logger)
Definition: MultisegmentWell_impl.hpp:2792
std::optional< Scalar > computeBhpAtThpLimitInj(const Simulator &ebos_simulator, const GroupStateHelperType &groupStateHelper, const SummaryState &summary_state) const
Definition: MultisegmentWell_impl.hpp:2288
void updateIPR(const Simulator &ebos_simulator, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:1338
void computeInitialSegmentInventory(DeferredLogger &deferred_logger)
Definition: MultisegmentWell_impl.hpp:708
ConvergenceReport getWellConvergence(const GroupStateHelperType &groupStateHelper, const std::vector< Scalar > &B_avg, const bool relax_tolerance) const override
check whether the well equations get converged for this well
Definition: MultisegmentWell_impl.hpp:202
void updatePrimaryVariables(const GroupStateHelperType &groupStateHelper) override
Definition: MultisegmentWell_impl.hpp:157
void updateIPRImplicit(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state) override
Definition: MultisegmentWell_impl.hpp:1439
void computeWellRatesAtBhpLimit(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, std::vector< Scalar > &well_flux) const
Definition: MultisegmentWell_impl.hpp:346
void init(const std::vector< Scalar > &depth_arg, const Scalar gravity_arg, const std::vector< Scalar > &B_avg, const bool changed_to_open_this_step) override
Definition: MultisegmentWell_impl.hpp:122
std::optional< Scalar > computeBhpAtThpLimitProdWithAlq(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, const SummaryState &summary_state, const Scalar alq_value, bool iterate_if_no_solution) const override
Definition: MultisegmentWell_impl.hpp:2231
void getScaledWellFractions(std::vector< Scalar > &scaled_fractions, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:2452
EvalWell getQs(const int comp_idx) const
Returns scaled rate for a component.
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:217
Class for computing BHP limits.
Definition: WellBhpThpCalculator.hpp:41
Scalar calculateThpFromBhp(const std::vector< Scalar > &rates, const Scalar bhp, const Scalar rho, const std::optional< Scalar > &alq, const Scalar thp_limit, DeferredLogger &deferred_logger) const
Calculates THP from BHP.
Scalar mostStrictBhpFromBhpLimits(const SummaryState &summaryState) const
Obtain the most strict BHP from BHP limits.
Well well_ecl_
Definition: WellInterfaceGeneric.hpp:478
void onlyKeepBHPandTHPcontrols(const SummaryState &summary_state, WellStateType &well_state, Well::InjectionControls &inj_controls, Well::ProductionControls &prod_controls) const
void resetDampening()
Definition: WellInterfaceGeneric.hpp:416
std::pair< bool, bool > computeWellPotentials(std::vector< Scalar > &well_potentials, const WellStateType &well_state)
Definition: WellInterfaceIndices.hpp:34
Definition: WellInterface.hpp:79
bool solveWellWithOperabilityCheck(const Simulator &simulator, const double dt, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:855
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: WellInterface.hpp:84
typename WellInterfaceFluidSystem< FluidSystem >::RateConverterType RateConverterType
Definition: WellInterface.hpp:110
void getTransMult(Value &trans_mult, const Simulator &simulator, const int cell_idx, Callback &extendEval) const
Definition: WellInterface_impl.hpp:2351
Dune::BCRSMatrix< Opm::MatrixBlock< Scalar, 1, 1 > > PressureMatrix
Definition: WellInterface.hpp:100
void getMobility(const Simulator &simulator, const int local_perf_index, std::vector< Value > &mob, Callback &extendEval, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:2364
GetPropType< TypeTag, Properties::IntensiveQuantities > IntensiveQuantities
Definition: WellInterface.hpp:89
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: WellInterface.hpp:85
Dune::BlockVector< VectorBlockType > BVector
Definition: WellInterface.hpp:99
typename Base::ModelParameters ModelParameters
Definition: WellInterface.hpp:116
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: WellInterface.hpp:86
typename Base::Eval Eval
Definition: WellInterface.hpp:98
GetPropType< TypeTag, Properties::Indices > Indices
Definition: WellInterface.hpp:88
GetPropType< TypeTag, Properties::SparseMatrixAdapter > SparseMatrixAdapter
Definition: WellInterface.hpp:91
Definition: WellProdIndexCalculator.hpp:37
Scalar connectionProdIndStandard(const std::size_t connIdx, const Scalar connMobility) const
Definition: WellState.hpp:68
const SingleWellState< Scalar, IndexTraits > & well(std::size_t well_index) const
Definition: WellState.hpp:315
@ NONE
Definition: DeferredLogger.hpp:46
Definition: blackoilbioeffectsmodules.hh:45
std::string to_string(const ConvergenceReport::ReservoirFailure::Type t)
Static data associated with a well perforation.
Definition: PerforationData.hpp:30
Definition: PerforationData.hpp:72
Scalar dis_gas
Definition: PerforationData.hpp:73
Scalar vap_oil
Definition: PerforationData.hpp:75