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)
81 if constexpr (has_solvent) {
82 OPM_THROW(std::runtime_error,
"solvent is not supported by multisegment well yet");
85 if constexpr (has_polymer) {
86 OPM_THROW(std::runtime_error,
"polymer is not supported by multisegment well yet");
89 if constexpr (Base::has_foam) {
90 OPM_THROW(std::runtime_error,
"foam is not supported by multisegment well yet");
93 if constexpr (Base::has_brine) {
94 OPM_THROW(std::runtime_error,
"brine is not supported by multisegment well yet");
97 if constexpr (Base::has_watVapor) {
98 OPM_THROW(std::runtime_error,
"water evaporation is not supported by multisegment well yet");
101 if constexpr (Base::has_micp) {
102 OPM_THROW(std::runtime_error,
"MICP is not supported by multisegment well yet");
105 if(this->rsRvInj() > 0) {
106 OPM_THROW(std::runtime_error,
107 "dissolved gas/ vapporized oil in injected oil/gas not supported by multisegment well yet."
108 " \n See (WCONINJE item 10 / WCONHIST item 8)");
111 this->thp_update_iterations =
true;
118 template <
typename TypeTag>
121 init(
const std::vector<Scalar>& depth_arg,
123 const std::vector< Scalar >& B_avg,
124 const bool changed_to_open_this_step)
126 Base::init(depth_arg, gravity_arg, B_avg, changed_to_open_this_step);
138 this->initMatrixAndVectors(this->parallel_well_info_);
141 for (
int local_perf_index = 0; local_perf_index < this->number_of_local_perforations_; ++local_perf_index) {
143 const int cell_idx = this->well_cells_[local_perf_index];
145 this->cell_perforation_depth_diffs_[local_perf_index] = depth_arg[cell_idx] - this->perf_depth_[this->parallel_well_info_.localPerfToActivePerf(local_perf_index)];
153 template <
typename TypeTag>
158 const auto& well_state = groupStateHelper.
wellState();
159 const bool stop_or_zero_rate_target = this->stoppedOrZeroRateTarget(groupStateHelper);
160 this->primary_variables_.update(well_state, stop_or_zero_rate_target);
168 template <
typename TypeTag>
173 this->scaleSegmentRatesWithWellRates(this->segments_.inlets(),
174 this->segments_.perforations(),
176 this->scaleSegmentPressuresWithBhp(well_state);
179 template <
typename TypeTag>
186 Base::updateWellStateWithTarget(simulator, groupStateHelper, well_state);
189 this->scaleSegmentRatesWithWellRates(this->segments_.inlets(),
190 this->segments_.perforations(),
192 this->scaleSegmentPressuresWithBhp(well_state);
198 template <
typename TypeTag>
202 const std::vector<Scalar>& B_avg,
203 const bool relax_tolerance)
const
205 const auto& well_state = groupStateHelper.
wellState();
207 return this->MSWEval::getWellConvergence(well_state,
210 this->param_.max_residual_allowed_,
211 this->param_.tolerance_wells_,
212 this->param_.relaxed_tolerance_flow_well_,
213 this->param_.tolerance_pressure_ms_wells_,
214 this->param_.relaxed_tolerance_pressure_ms_well_,
216 this->wellIsStopped());
224 template <
typename TypeTag>
229 if (!this->isOperableAndSolvable() && !this->wellIsStopped()) {
233 if (this->param_.matrix_add_well_contributions_) {
238 this->linSys_.apply(x, Ax);
245 template <
typename TypeTag>
250 if (!this->isOperableAndSolvable() && !this->wellIsStopped()) {
254 this->linSys_.apply(r);
259 template <
typename TypeTag>
267 if (!this->isOperableAndSolvable() && !this->wellIsStopped()) {
274 this->linSys_.recoverSolutionWell(x, xw);
276 updateWellState(simulator, xw, groupStateHelper, well_state);
277 if constexpr (has_energy) {
278 const FSInfo info = this->getFirstPerforationFluidStateInfo(simulator);
279 updateSegmentFluidState(info, deferred_logger);
282 catch (
const NumericalProblem& exp) {
286 deferred_logger.problem(
"In MultisegmentWell::recoverWellSolutionAndUpdateWellState for well "
287 + this->name() +
": "+exp.what());
296 template <
typename TypeTag>
302 std::vector<Scalar>& well_potentials)
305 const auto [compute_potential, bhp_controlled_well] =
308 if (!compute_potential) {
312 debug_cost_counter_ = 0;
313 bool converged_implicit =
false;
314 if (this->param_.local_well_solver_control_switching_) {
315 converged_implicit = computeWellPotentialsImplicit(simulator, groupStateHelper, well_potentials);
316 if (!converged_implicit) {
317 deferred_logger.debug(
"Implicit potential calculations failed for well "
318 + this->name() +
", reverting to original aproach.");
321 if (!converged_implicit) {
323 const auto& summaryState = simulator.vanguard().summaryState();
324 if (!Base::wellHasTHPConstraints(summaryState) || bhp_controlled_well) {
325 computeWellRatesAtBhpLimit(simulator, groupStateHelper, well_potentials);
327 well_potentials = computeWellPotentialWithTHP(
328 well_state, simulator, groupStateHelper);
331 deferred_logger.debug(
"Cost in iterations of finding well potential for well "
334 this->checkNegativeWellPotentials(well_potentials,
335 this->param_.check_well_operability_,
342 template<
typename TypeTag>
347 std::vector<Scalar>& well_flux)
const
349 if (this->well_ecl_.isInjector()) {
350 const auto controls = this->well_ecl_.injectionControls(simulator.vanguard().summaryState());
351 computeWellRatesWithBhpIterations(simulator, controls.bhp_limit, groupStateHelper, well_flux);
353 const auto controls = this->well_ecl_.productionControls(simulator.vanguard().summaryState());
354 computeWellRatesWithBhpIterations(simulator, controls.bhp_limit, groupStateHelper, well_flux);
358 template<
typename TypeTag>
363 std::vector<Scalar>& well_flux,
366 const int np = this->number_of_phases_;
368 well_flux.resize(np, 0.0);
369 const bool allow_cf = this->getAllowCrossFlow();
370 const int nseg = this->numberOfSegments();
371 const WellStateType& well_state = simulator.problem().wellModel().wellState();
372 const auto& ws = well_state.
well(this->indexOfWell());
373 auto segments_copy = ws.segments;
374 segments_copy.scale_pressure(bhp);
375 const auto& segment_pressure = segments_copy.pressure;
376 for (
int seg = 0; seg < nseg; ++seg) {
377 for (
const int perf : this->segments_.perforations()[seg]) {
378 const int local_perf_index = this->parallel_well_info_.activePerfToLocalPerf(perf);
379 if (local_perf_index < 0)
381 const int cell_idx = this->well_cells_[local_perf_index];
382 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
384 std::vector<Scalar> mob(this->num_conservation_quantities_, 0.);
385 getMobility(simulator, local_perf_index, mob, deferred_logger);
387 getTransMult(trans_mult, simulator, cell_idx);
388 const auto& wellstate_nupcol = simulator.problem().wellModel().nupcolWellState().well(this->index_of_well_);
389 std::vector<Scalar> Tw(this->num_conservation_quantities_,
390 this->well_index_[local_perf_index] * trans_mult);
391 this->getTw(Tw, local_perf_index, intQuants, trans_mult, wellstate_nupcol);
392 const Scalar seg_pressure = segment_pressure[seg];
393 std::vector<Scalar> cq_s(this->num_conservation_quantities_, 0.);
396 computePerfRate(intQuants, mob, Tw, seg, perf, seg_pressure,
397 allow_cf, cq_s, perf_press, perf_rates, deferred_logger);
399 for(
int p = 0; p < np; ++p) {
400 well_flux[FluidSystem::activeCompToActivePhaseIdx(p)] += cq_s[p];
404 this->parallel_well_info_.communication().sum(well_flux.data(), well_flux.size());
408 template<
typename TypeTag>
414 std::vector<Scalar>& well_flux)
const
427 auto guard = groupStateHelper_copy.
pushWellState(well_state_copy);
428 auto& ws = well_state_copy.
well(this->index_of_well_);
431 const auto& summary_state = simulator.vanguard().summaryState();
432 auto inj_controls = well_copy.
well_ecl_.isInjector()
433 ? well_copy.
well_ecl_.injectionControls(summary_state)
434 : Well::InjectionControls(0);
435 auto prod_controls = well_copy.
well_ecl_.isProducer()
436 ? well_copy.
well_ecl_.productionControls(summary_state) :
437 Well::ProductionControls(0);
441 inj_controls.bhp_limit = bhp;
442 ws.injection_cmode = Well::InjectorCMode::BHP;
444 prod_controls.bhp_limit = bhp;
445 ws.production_cmode = Well::ProducerCMode::BHP;
451 const int np = this->number_of_phases_;
453 for (
int phase = 0; phase < np; ++phase){
454 trivial = trivial && (ws.well_potentials[phase] == 0.0) ;
458 for (
int phase = 0; phase < np; ++phase) {
459 ws.surface_rates[phase] = sign * ws.well_potentials[phase];
463 this->segments_.perforations(),
467 const double dt = simulator.timeStepSize();
474 well_flux.resize(np, 0.0);
475 for (
int compIdx = 0; compIdx < this->num_conservation_quantities_; ++compIdx) {
477 well_flux[FluidSystem::activeCompToActivePhaseIdx(compIdx)] = rate.value();
484 template<
typename TypeTag>
485 std::vector<typename MultisegmentWell<TypeTag>::Scalar>
492 std::vector<Scalar> potentials(this->number_of_phases_, 0.0);
493 const auto& summary_state = simulator.vanguard().summaryState();
495 const auto& well = this->well_ecl_;
496 if (well.isInjector()) {
497 auto bhp_at_thp_limit = computeBhpAtThpLimitInj(simulator, groupStateHelper, summary_state);
498 if (bhp_at_thp_limit) {
499 const auto& controls = well.injectionControls(summary_state);
500 const Scalar bhp = std::min(*bhp_at_thp_limit,
501 static_cast<Scalar>(controls.bhp_limit));
502 computeWellRatesWithBhpIterations(simulator, bhp, groupStateHelper, potentials);
503 deferred_logger.debug(
"Converged thp based potential calculation for well "
506 deferred_logger.warning(
"FAILURE_GETTING_CONVERGED_POTENTIAL",
507 "Failed in getting converged thp based potential calculation for well "
508 + this->name() +
". Instead the bhp based value is used");
509 const auto& controls = well.injectionControls(summary_state);
510 const Scalar bhp = controls.bhp_limit;
511 computeWellRatesWithBhpIterations(simulator, bhp, groupStateHelper, potentials);
514 auto bhp_at_thp_limit = computeBhpAtThpLimitProd(
515 well_state, simulator, groupStateHelper, summary_state);
516 if (bhp_at_thp_limit) {
517 const auto& controls = well.productionControls(summary_state);
518 const Scalar bhp = std::max(*bhp_at_thp_limit,
519 static_cast<Scalar>(controls.bhp_limit));
520 computeWellRatesWithBhpIterations(simulator, bhp, groupStateHelper, potentials);
521 deferred_logger.debug(
"Converged thp based potential calculation for well "
524 deferred_logger.warning(
"FAILURE_GETTING_CONVERGED_POTENTIAL",
525 "Failed in getting converged thp based potential calculation for well "
526 + this->name() +
". Instead the bhp based value is used");
527 const auto& controls = well.productionControls(summary_state);
528 const Scalar bhp = controls.bhp_limit;
529 computeWellRatesWithBhpIterations(simulator, bhp, groupStateHelper, potentials);
536 template<
typename TypeTag>
541 std::vector<Scalar>& well_potentials)
const
552 auto guard = groupStateHelper_copy.
pushWellState(well_state_copy);
553 auto& ws = well_state_copy.
well(this->index_of_well_);
556 const auto& summary_state = simulator.vanguard().summaryState();
557 auto inj_controls = well_copy.
well_ecl_.isInjector()
558 ? well_copy.
well_ecl_.injectionControls(summary_state)
559 : Well::InjectionControls(0);
560 auto prod_controls = well_copy.
well_ecl_.isProducer()
561 ? well_copy.
well_ecl_.productionControls(summary_state)
562 : Well::ProductionControls(0);
570 const int np = this->number_of_phases_;
572 for (
int phase = 0; phase < np; ++phase){
573 trivial = trivial && (ws.well_potentials[phase] == 0.0) ;
577 for (
int phase = 0; phase < np; ++phase) {
578 ws.surface_rates[phase] = sign * ws.well_potentials[phase];
582 this->segments_.perforations(),
586 const double dt = simulator.timeStepSize();
588 bool converged =
false;
589 if (this->well_ecl_.isProducer()) {
591 simulator, dt, inj_controls, prod_controls, groupStateHelper_copy, well_state_copy
595 simulator, dt, inj_controls, prod_controls, groupStateHelper_copy, well_state_copy,
603 well_potentials.clear();
604 well_potentials.resize(np, 0.0);
605 for (
int compIdx = 0; compIdx < this->num_conservation_quantities_; ++compIdx) {
607 well_potentials[FluidSystem::activeCompToActivePhaseIdx(compIdx)] = rate.value();
613 template <
typename TypeTag>
620 if (!this->isOperableAndSolvable() && !this->wellIsStopped())
return;
625 const BVectorWell dx_well = this->linSys_.solve();
626 updateWellState(simulator, dx_well, groupStateHelper, well_state);
628 catch(
const NumericalProblem& exp) {
633 deferred_logger.
problem(
"In MultisegmentWell::solveEqAndUpdateWellState for well "
634 + this->name() +
": "+exp.what());
643 template <
typename TypeTag>
650 for (
int local_perf_index = 0; local_perf_index < this->number_of_local_perforations_; ++local_perf_index) {
653 std::vector<Scalar> kr(this->number_of_phases_, 0.0);
654 std::vector<Scalar> density(this->number_of_phases_, 0.0);
656 const int cell_idx = this->well_cells_[local_perf_index];
657 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
658 const auto& fs = intQuants.fluidState();
662 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
663 const int water_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::waterPhaseIdx);
664 kr[water_pos] = intQuants.relativePermeability(FluidSystem::waterPhaseIdx).value();
665 sum_kr += kr[water_pos];
666 density[water_pos] = fs.density(FluidSystem::waterPhaseIdx).value();
669 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
670 const int oil_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::oilPhaseIdx);
671 kr[oil_pos] = intQuants.relativePermeability(FluidSystem::oilPhaseIdx).value();
672 sum_kr += kr[oil_pos];
673 density[oil_pos] = fs.density(FluidSystem::oilPhaseIdx).value();
676 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
677 const int gas_pos = FluidSystem::canonicalToActivePhaseIdx(FluidSystem::gasPhaseIdx);
678 kr[gas_pos] = intQuants.relativePermeability(FluidSystem::gasPhaseIdx).value();
679 sum_kr += kr[gas_pos];
680 density[gas_pos] = fs.density(FluidSystem::gasPhaseIdx).value();
683 assert(sum_kr != 0.);
686 Scalar average_density = 0.;
687 for (
int p = 0; p < this->number_of_phases_; ++p) {
688 average_density += kr[p] * density[p];
690 average_density /= sum_kr;
692 this->cell_perforation_pressure_diffs_[local_perf_index] = this->gravity_ * average_density * this->cell_perforation_depth_diffs_[local_perf_index];
700 template <
typename TypeTag>
706 for (
int seg = 0; seg < this->numberOfSegments(); ++seg) {
707 const Scalar surface_volume = getSegmentSurfaceVolume(seg, info, deferred_logger).value();
708 for (
int comp_idx = 0; comp_idx < this->num_conservation_quantities_; ++comp_idx) {
709 segment_fluid_initial_[seg][comp_idx] = surface_volume * this->primary_variables_.surfaceVolumeFraction(seg, comp_idx).value();
718 template <
typename TypeTag>
722 const BVectorWell& dwells,
725 const Scalar relaxation_factor)
727 if (!this->isOperableAndSolvable() && !this->wellIsStopped())
return;
731 const Scalar dFLimit = this->param_.dwell_fraction_max_;
732 const Scalar max_pressure_change = this->param_.max_pressure_change_ms_wells_;
733 const bool stop_or_zero_rate_target =
734 this->stoppedOrZeroRateTarget(groupStateHelper);
735 this->primary_variables_.updateNewton(dwells,
738 stop_or_zero_rate_target,
739 max_pressure_change);
741 const auto& summary_state = simulator.vanguard().summaryState();
742 this->primary_variables_.copyToWellState(*
this, getRefDensity(),
748 auto& ws = well_state.
well(this->index_of_well_);
749 this->segments_.copyPhaseDensities(ws.segments);
753 const bool isThermal = simulator.vanguard().eclState().getSimulationConfig().isThermal();
754 const bool co2store = simulator.vanguard().eclState().runspec().co2Storage();
755 Base::calculateReservoirRates( (isThermal || co2store), well_state.
well(this->index_of_well_));
762 template <
typename TypeTag>
769 updatePrimaryVariables(groupStateHelper);
770 computePerfCellPressDiffs(simulator);
772 const auto info = this->getFirstPerforationFluidStateInfo(simulator);
774 computeInitialSegmentFluids(info, deferred_logger);
775 if constexpr (has_energy) {
778 updateSegmentFluidState(info, deferred_logger);
779 computeInitialSegmentEnergy();
787 template<
typename TypeTag>
795 auto fluidState = [&simulator,
this](
const int local_perf_index)
797 const auto cell_idx = this->well_cells_[local_perf_index];
798 return simulator.model()
799 .intensiveQuantities(cell_idx, 0).fluidState();
802 const int np = this->number_of_phases_;
803 auto setToZero = [np](
Scalar* x) ->
void
805 std::fill_n(x, np, 0.0);
808 auto addVector = [np](
const Scalar* src,
Scalar* dest) ->
void
810 std::transform(src, src + np, dest, dest, std::plus<>{});
813 auto& ws = well_state.
well(this->index_of_well_);
814 auto& perf_data = ws.perf_data;
815 auto* connPI = perf_data.prod_index.data();
816 auto* wellPI = ws.productivity_index.data();
820 const auto preferred_phase = this->well_ecl_.getPreferredPhase();
821 auto subsetPerfID = 0;
823 for (
const auto& perf : *this->perf_data_){
824 auto allPerfID = perf.ecl_index;
826 auto connPICalc = [&wellPICalc, allPerfID](
const Scalar mobility) ->
Scalar
831 std::vector<Scalar> mob(this->num_conservation_quantities_, 0.0);
836 getMobility(simulator,
static_cast<int>(subsetPerfID), mob, deferred_logger);
838 const auto& fs = fluidState(subsetPerfID);
841 if (this->isInjector()) {
842 this->computeConnLevelInjInd(fs, preferred_phase, connPICalc,
843 mob, connPI, deferred_logger);
846 this->computeConnLevelProdInd(fs, connPICalc, mob, connPI);
849 addVector(connPI, wellPI);
856 const auto& comm = this->parallel_well_info_.communication();
857 if (comm.size() > 1) {
858 comm.sum(wellPI, np);
861 assert (
static_cast<int>(subsetPerfID) == this->number_of_local_perforations_ &&
862 "Internal logic error in processing connections for PI/II");
869 template<
typename TypeTag>
873 [[maybe_unused]]
const int openConnIdx)
const
878 const auto segNum = this->wellEcl()
879 .getConnections()[globalConnIdx].segment();
881 const auto segIdx = this->wellEcl()
882 .getSegments().segmentNumberToIndex(segNum);
884 return this->segments_.density(segIdx).value();
891 template<
typename TypeTag>
896 if (this->number_of_local_perforations_ == 0) {
900 this->linSys_.extract(jacobian);
904 template<
typename TypeTag>
909 const int pressureVarIndex,
910 const bool use_well_weights,
913 if (this->number_of_local_perforations_ == 0) {
918 this->linSys_.extractCPRPressureMatrix(jacobian,
928 template<
typename TypeTag>
929 template<
class Value>
935 const std::vector<Value>& b_perfcells,
936 const std::vector<Value>& mob_perfcells,
937 const std::vector<Value>& Tw,
939 const Value& segment_pressure,
940 const Value& segment_density,
941 const bool& allow_cf,
942 const std::vector<Value>& cmix_s,
943 std::vector<Value>& cq_s,
948 const int local_perf_index = this->parallel_well_info_.activePerfToLocalPerf(perf);
949 if (local_perf_index < 0)
953 const Value perf_seg_press_diff = this->gravity() * segment_density *
954 this->segments_.local_perforation_depth_diff(local_perf_index);
956 const Scalar cell_perf_press_diff = this->cell_perforation_pressure_diffs_[local_perf_index];
960 perf_press = segment_pressure + perf_seg_press_diff;
963 const Value cell_press_at_perf = pressure_cell - cell_perf_press_diff;
966 const Value drawdown = cell_press_at_perf - perf_press;
969 if (drawdown > 0.0) {
971 if (!allow_cf && this->isInjector()) {
976 for (
int comp_idx = 0; comp_idx < this->numConservationQuantities(); ++comp_idx) {
977 const Value cq_p = - Tw[comp_idx] * (mob_perfcells[comp_idx] * drawdown);
978 cq_s[comp_idx] = b_perfcells[comp_idx] * cq_p;
981 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
982 const unsigned oilCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::oilCompIdx);
983 const unsigned gasCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
984 const Value cq_s_oil = cq_s[oilCompIdx];
985 const Value cq_s_gas = cq_s[gasCompIdx];
986 cq_s[gasCompIdx] += rs * cq_s_oil;
987 cq_s[oilCompIdx] += rv * cq_s_gas;
991 if (!allow_cf && this->isProducer()) {
996 Value total_mob = mob_perfcells[0];
997 for (
int comp_idx = 1; comp_idx < this->numConservationQuantities(); ++comp_idx) {
998 total_mob += mob_perfcells[comp_idx];
1002 Value volume_ratio = 0.0;
1003 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
1004 const unsigned waterCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::waterCompIdx);
1005 volume_ratio += cmix_s[waterCompIdx] / b_perfcells[waterCompIdx];
1008 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1009 const unsigned oilCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::oilCompIdx);
1010 const unsigned gasCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
1015 const Value d = 1.0 - rv * rs;
1017 if (getValue(d) == 0.0) {
1019 fmt::format(
"Zero d value obtained for well {} "
1020 "during flux calculation with rs {} and rv {}",
1021 this->name(), rs, rv),
1025 const Value tmp_oil = (cmix_s[oilCompIdx] - rv * cmix_s[gasCompIdx]) / d;
1026 volume_ratio += tmp_oil / b_perfcells[oilCompIdx];
1028 const Value tmp_gas = (cmix_s[gasCompIdx] - rs * cmix_s[oilCompIdx]) / d;
1029 volume_ratio += tmp_gas / b_perfcells[gasCompIdx];
1031 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1032 const unsigned oilCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::oilCompIdx);
1033 volume_ratio += cmix_s[oilCompIdx] / b_perfcells[oilCompIdx];
1035 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1036 const unsigned gasCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
1037 volume_ratio += cmix_s[gasCompIdx] / b_perfcells[gasCompIdx];
1041 for (
int componentIdx = 0; componentIdx < this->numConservationQuantities(); ++componentIdx) {
1042 const Value cqt_i = - Tw[componentIdx] * (total_mob * drawdown);
1043 Value cqt_is = cqt_i / volume_ratio;
1044 cq_s[componentIdx] = cmix_s[componentIdx] * cqt_is;
1049 if (this->isProducer()) {
1050 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1051 const unsigned oilCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::oilCompIdx);
1052 const unsigned gasCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
1061 const Scalar d = 1.0 - getValue(rv) * getValue(rs);
1064 perf_rates.
vap_oil = getValue(rv) * (getValue(cq_s[gasCompIdx]) - getValue(rs) * getValue(cq_s[oilCompIdx])) / d;
1067 perf_rates.
dis_gas = getValue(rs) * (getValue(cq_s[oilCompIdx]) - getValue(rv) * getValue(cq_s[gasCompIdx])) / d;
1072 template <
typename TypeTag>
1073 template<
class Value>
1077 const std::vector<Value>& mob_perfcells,
1078 const std::vector<Value>& Tw,
1081 const Value& segment_pressure,
1082 const bool& allow_cf,
1083 std::vector<Value>& cq_s,
1089 auto obtain = [
this](
const Eval& value)
1091 if constexpr (std::is_same_v<Value, Scalar>) {
1092 static_cast<void>(
this);
1093 return getValue(value);
1095 return this->extendEval(value);
1098 auto obtainN = [](
const auto& value)
1100 if constexpr (std::is_same_v<Value, Scalar>) {
1101 return getValue(value);
1106 const auto& fs = int_quants.fluidState();
1108 const Value pressure_cell = obtain(this->getPerfCellPressure(fs));
1109 const Value rs = obtain(fs.Rs());
1110 const Value rv = obtain(fs.Rv());
1113 std::vector<Value> b_perfcells(this->num_conservation_quantities_, 0.0);
1115 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
1116 if (!FluidSystem::phaseIsActive(phaseIdx)) {
1120 const unsigned compIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
1121 b_perfcells[compIdx] = obtain(fs.invB(phaseIdx));
1124 std::vector<Value> cmix_s(this->numConservationQuantities(), 0.0);
1125 for (
int comp_idx = 0; comp_idx < this->numConservationQuantities(); ++comp_idx) {
1126 cmix_s[comp_idx] = obtainN(this->primary_variables_.surfaceVolumeFraction(seg, comp_idx));
1129 this->computePerfRate(pressure_cell,
1137 obtainN(this->segments_.density(seg)),
1146 template <
typename TypeTag>
1163 auto info = this->getFirstPerforationFluidStateInfo(simulator);
1164 const Scalar firstPerfTemperature = std::get<0>(info);
1165 const Scalar firstPerfSaltConcentration = std::get<1>(info);
1167 this->segments_.computeFluidProperties(firstPerfTemperature,
1168 firstPerfSaltConcentration,
1169 this->primary_variables_,
1173 template<
typename TypeTag>
1174 template<
class Value>
1179 const int cell_idx)
const
1181 auto obtain = [
this](
const Eval& value)
1183 if constexpr (std::is_same_v<Value, Scalar>) {
1184 static_cast<void>(
this);
1185 return getValue(value);
1187 return this->extendEval(value);
1193 template <
typename TypeTag>
1194 template<
class Value>
1198 const int local_perf_index,
1199 std::vector<Value>& mob,
1202 auto obtain = [
this](
const Eval& value)
1204 if constexpr (std::is_same_v<Value, Scalar>) {
1205 static_cast<void>(
this);
1206 return getValue(value);
1208 return this->extendEval(value);
1215 const auto perf_ecl_index = this->perforationData()[local_perf_index].ecl_index;
1216 const Connection& con = this->well_ecl_.getConnections()[perf_ecl_index];
1217 const int seg = this->segmentNumberToIndex(con.segment());
1221 const Scalar segment_pres = this->primary_variables_.getSegmentPressure(seg).value();
1222 const Scalar perf_seg_press_diff = this->gravity() * this->segments_.density(seg).value()
1223 * this->segments_.local_perforation_depth_diff(local_perf_index);
1224 const Scalar perf_press = segment_pres + perf_seg_press_diff;
1225 const Scalar multiplier = this->getInjMult(local_perf_index, segment_pres, perf_press, deferred_logger);
1226 for (std::size_t i = 0; i < mob.size(); ++i) {
1227 mob[i] *= multiplier;
1234 template<
typename TypeTag>
1239 return this->segments_.getRefDensity();
1242 template<
typename TypeTag>
1249 const auto& summaryState = simulator.vanguard().summaryState();
1253 const bool bhp_limit_not_defaulted = bhp_limit > 1.5 * unit::barsa;
1254 if ( bhp_limit_not_defaulted || !this->wellHasTHPConstraints(summaryState) ) {
1257 Scalar total_ipr_mass_rate = 0.0;
1258 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
1260 if (!FluidSystem::phaseIsActive(phaseIdx)) {
1264 const unsigned compIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
1265 const Scalar ipr_rate = this->ipr_a_[compIdx] - this->ipr_b_[compIdx] * bhp_limit;
1267 const Scalar rho = FluidSystem::referenceDensity( phaseIdx, Base::pvtRegionIdx() );
1268 total_ipr_mass_rate += ipr_rate * rho;
1270 if ( (this->isProducer() && total_ipr_mass_rate < 0.) || (this->isInjector() && total_ipr_mass_rate > 0.) ) {
1271 this->operability_status_.operable_under_only_bhp_limit =
false;
1275 if (this->operability_status_.operable_under_only_bhp_limit && this->wellHasTHPConstraints(summaryState)) {
1279 std::vector<Scalar> well_rates_bhp_limit;
1280 computeWellRatesWithBhp(simulator, bhp_limit, well_rates_bhp_limit, deferred_logger);
1282 const Scalar thp_limit = this->getTHPConstraint(summaryState);
1285 this->getRefDensity(),
1286 this->wellEcl().alq_value(summaryState),
1289 if ( (this->isProducer() && thp < thp_limit) || (this->isInjector() && thp > thp_limit) ) {
1290 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
1301 this->operability_status_.operable_under_only_bhp_limit =
true;
1302 this->operability_status_.obey_thp_limit_under_bhp_limit =
false;
1308 template<
typename TypeTag>
1316 std::ranges::fill(this->ipr_a_, 0.0);
1317 std::ranges::fill(this->ipr_b_, 0.0);
1319 const int nseg = this->numberOfSegments();
1320 std::vector<Scalar> seg_dp(nseg, 0.0);
1321 for (
int seg = 0; seg < nseg; ++seg) {
1323 const Scalar dp = this->getSegmentDp(seg,
1324 this->segments_.density(seg).value(),
1327 for (
const int perf : this->segments_.perforations()[seg]) {
1328 const int local_perf_index = this->parallel_well_info_.activePerfToLocalPerf(perf);
1329 if (local_perf_index < 0)
1331 std::vector<Scalar> mob(this->num_conservation_quantities_, 0.0);
1334 getMobility(simulator, local_perf_index, mob, deferred_logger);
1336 const int cell_idx = this->well_cells_[local_perf_index];
1337 const auto& int_quantities = simulator.model().intensiveQuantities(cell_idx, 0);
1338 const auto& fs = int_quantities.fluidState();
1340 const Scalar perf_seg_press_diff = this->segments_.getPressureDiffSegLocalPerf(seg, local_perf_index);
1342 const Scalar cell_perf_press_diff = this->cell_perforation_pressure_diffs_[local_perf_index];
1343 const Scalar pressure_cell = this->getPerfCellPressure(fs).value();
1346 std::vector<Scalar> b_perf(this->num_conservation_quantities_);
1347 for (std::size_t phase = 0; phase < FluidSystem::numPhases; ++phase) {
1348 if (!FluidSystem::phaseIsActive(phase)) {
1351 const unsigned comp_idx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phase));
1352 b_perf[comp_idx] = fs.invB(phase).value();
1356 const Scalar h_perf = cell_perf_press_diff + perf_seg_press_diff + dp;
1357 const Scalar pressure_diff = pressure_cell - h_perf;
1360 if ( (this->isProducer() && pressure_diff < 0.) || (this->isInjector() && pressure_diff > 0.) ) {
1361 deferred_logger.
debug(
"CROSSFLOW_IPR",
1362 "cross flow found when updateIPR for well " + this->name());
1367 getTransMult(trans_mult, simulator, cell_idx);
1368 const auto& wellstate_nupcol = simulator.problem().wellModel().nupcolWellState().well(this->index_of_well_);
1369 std::vector<Scalar> tw_perf(this->num_conservation_quantities_, this->well_index_[perf] * trans_mult);
1370 this->getTw(tw_perf, local_perf_index, int_quantities, trans_mult, wellstate_nupcol);
1371 std::vector<Scalar> ipr_a_perf(this->ipr_a_.size());
1372 std::vector<Scalar> ipr_b_perf(this->ipr_b_.size());
1373 for (
int comp_idx = 0; comp_idx < this->num_conservation_quantities_; ++comp_idx) {
1374 const Scalar tw_mob = tw_perf[comp_idx] * mob[comp_idx] * b_perf[comp_idx];
1375 ipr_a_perf[comp_idx] += tw_mob * pressure_diff;
1376 ipr_b_perf[comp_idx] += tw_mob;
1380 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1381 const unsigned oil_comp_idx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::oilCompIdx);
1382 const unsigned gas_comp_idx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
1383 const Scalar rs = (fs.Rs()).value();
1384 const Scalar rv = (fs.Rv()).value();
1386 const Scalar dis_gas_a = rs * ipr_a_perf[oil_comp_idx];
1387 const Scalar vap_oil_a = rv * ipr_a_perf[gas_comp_idx];
1389 ipr_a_perf[gas_comp_idx] += dis_gas_a;
1390 ipr_a_perf[oil_comp_idx] += vap_oil_a;
1392 const Scalar dis_gas_b = rs * ipr_b_perf[oil_comp_idx];
1393 const Scalar vap_oil_b = rv * ipr_b_perf[gas_comp_idx];
1395 ipr_b_perf[gas_comp_idx] += dis_gas_b;
1396 ipr_b_perf[oil_comp_idx] += vap_oil_b;
1399 for (std::size_t comp_idx = 0; comp_idx < ipr_a_perf.size(); ++comp_idx) {
1400 this->ipr_a_[comp_idx] += ipr_a_perf[comp_idx];
1401 this->ipr_b_[comp_idx] += ipr_b_perf[comp_idx];
1405 this->parallel_well_info_.communication().sum(this->ipr_a_.data(), this->ipr_a_.size());
1406 this->parallel_well_info_.communication().sum(this->ipr_b_.data(), this->ipr_b_.size());
1409 template<
typename TypeTag>
1424 auto rates = well_state.
well(this->index_of_well_).surface_rates;
1426 for (std::size_t p = 0; p < rates.size(); ++p) {
1427 zero_rates &= rates[p] == 0.0;
1429 auto& ws = well_state.
well(this->index_of_well_);
1431 const auto msg = fmt::format(
"updateIPRImplicit: Well {} has zero rate, IPRs might be problematic", this->name());
1432 deferred_logger.debug(msg);
1445 std::ranges::fill(ws.implicit_ipr_a, 0.0);
1446 std::ranges::fill(ws.implicit_ipr_b, 0.0);
1448 auto inj_controls = Well::InjectionControls(0);
1449 auto prod_controls = Well::ProductionControls(0);
1450 prod_controls.addControl(Well::ProducerCMode::BHP);
1451 prod_controls.bhp_limit = well_state.
well(this->index_of_well_).bhp;
1454 const auto cmode = ws.production_cmode;
1455 ws.production_cmode = Well::ProducerCMode::BHP;
1456 const double dt = simulator.timeStepSize();
1457 assembleWellEqWithoutIteration(simulator, groupStateHelper, dt, inj_controls, prod_controls, well_state,
1460 BVectorWell rhs(this->numberOfSegments());
1462 rhs[0][SPres] = -1.0;
1464 const BVectorWell x_well = this->linSys_.solve(rhs);
1465 constexpr int num_eq = MSWEval::numWellEq;
1466 for (
int comp_idx = 0; comp_idx < this->num_conservation_quantities_; ++comp_idx){
1467 const EvalWell comp_rate = this->primary_variables_.getQs(comp_idx);
1468 const int idx = FluidSystem::activeCompToActivePhaseIdx(comp_idx);
1469 for (
size_t pvIdx = 0; pvIdx < num_eq; ++pvIdx) {
1471 ws.implicit_ipr_b[idx] -= x_well[0][pvIdx]*comp_rate.derivative(pvIdx+Indices::numEq);
1473 ws.implicit_ipr_a[idx] = ws.implicit_ipr_b[idx]*ws.bhp - comp_rate.value();
1476 ws.production_cmode = cmode;
1479 template<
typename TypeTag>
1487 const auto& summaryState = simulator.vanguard().summaryState();
1488 const auto obtain_bhp = this->isProducer()
1489 ? computeBhpAtThpLimitProd(
1490 well_state, simulator, groupStateHelper, summaryState)
1491 : computeBhpAtThpLimitInj(simulator, groupStateHelper, summaryState);
1494 this->operability_status_.can_obtain_bhp_with_thp_limit =
true;
1497 this->operability_status_.obey_bhp_limit_with_thp_limit = (*obtain_bhp >= bhp_limit);
1499 const Scalar thp_limit = this->getTHPConstraint(summaryState);
1500 if (this->isProducer() && *obtain_bhp < thp_limit) {
1501 const std::string msg =
" obtained bhp " +
std::to_string(unit::convert::to(*obtain_bhp, unit::barsa))
1502 +
" bars is SMALLER than thp limit "
1504 +
" bars as a producer for well " + this->name();
1505 deferred_logger.debug(msg);
1507 else if (this->isInjector() && *obtain_bhp > thp_limit) {
1508 const std::string msg =
" obtained bhp " +
std::to_string(unit::convert::to(*obtain_bhp, unit::barsa))
1509 +
" bars is LARGER than thp limit "
1511 +
" bars as a injector for well " + this->name();
1512 deferred_logger.debug(msg);
1517 this->operability_status_.can_obtain_bhp_with_thp_limit =
false;
1518 this->operability_status_.obey_bhp_limit_with_thp_limit =
false;
1519 if (!this->wellIsStopped()) {
1520 const Scalar thp_limit = this->getTHPConstraint(summaryState);
1521 deferred_logger.debug(
" could not find bhp value at thp limit "
1523 +
" bar for well " + this->name() +
", the well might need to be closed ");
1532 template<
typename TypeTag>
1537 const Well::InjectionControls& inj_controls,
1538 const Well::ProductionControls& prod_controls,
1542 if (!this->isOperableAndSolvable() && !this->wellIsStopped())
return true;
1546 const int max_iter_number = this->param_.max_inner_iter_ms_wells_;
1550 const auto& [isFinite, residuals] = this->getFiniteWellResiduals(Base::B_avg_, deferred_logger);
1555 updatePrimaryVariables(groupStateHelper);
1557 std::vector<std::vector<Scalar> > residual_history;
1558 std::vector<Scalar> measure_history;
1561 Scalar relaxation_factor = 1.;
1562 bool converged =
false;
1563 bool relax_convergence =
false;
1564 this->regularize_ =
false;
1568 [[maybe_unused]]
FSInfo info{};
1569 if constexpr (has_energy) {
1570 info = this->getFirstPerforationFluidStateInfo(simulator);
1572 for (; it < max_iter_number; ++it, ++debug_cost_counter_) {
1574 if (it > this->param_.strict_inner_iter_wells_) {
1575 relax_convergence =
true;
1576 this->regularize_ =
true;
1579 assembleWellEqWithoutIteration(simulator, groupStateHelper, dt, inj_controls, prod_controls,
1583 const auto report = getWellConvergence(groupStateHelper, Base::B_avg_, relax_convergence);
1584 if (report.converged()) {
1591 const auto& [isFinite, residuals] = this->getFiniteWellResiduals(Base::B_avg_, deferred_logger);
1595 residual_history.push_back(residuals);
1596 measure_history.push_back(this->getResidualMeasureValue(well_state,
1597 residual_history[it],
1598 this->param_.tolerance_wells_,
1599 this->param_.tolerance_pressure_ms_wells_,
1602 bool min_relaxation_reached = this->update_relaxation_factor(measure_history, relaxation_factor, this->regularize_, deferred_logger);
1603 if (min_relaxation_reached || this->repeatedStagnation(measure_history, this->regularize_, deferred_logger)) {
1605 const auto reportStag = getWellConvergence(groupStateHelper, Base::B_avg_,
true);
1606 if (reportStag.converged()) {
1608 std::string message = fmt::format(
"Well stagnates/oscillates but {} manages to get converged with relaxed tolerances in {} inner iterations."
1610 deferred_logger.debug(message);
1617 BVectorWell dx_well;
1619 dx_well = this->linSys_.solve();
1620 updateWellState(simulator, dx_well, groupStateHelper, well_state, relaxation_factor);
1621 if constexpr (has_energy) {
1623 updateSegmentFluidState(info, deferred_logger);
1626 catch(
const NumericalProblem& exp) {
1630 deferred_logger.problem(
"In MultisegmentWell::iterateWellEqWithControl for well "
1631 + this->name() +
": "+exp.what());
1638 std::ostringstream sstr;
1639 sstr <<
" Well " << this->name() <<
" converged in " << it <<
" inner iterations.";
1640 if (relax_convergence)
1641 sstr <<
" (A relaxed tolerance was used after "<< this->param_.strict_inner_iter_wells_ <<
" iterations)";
1645 deferred_logger.debug(sstr.str(), OpmLog::defaultDebugVerbosityLevel + (it == 0));
1647 std::ostringstream sstr;
1648 sstr <<
" Well " << this->name() <<
" did not converge in " << it <<
" inner iterations.";
1649#define EXTRA_DEBUG_MSW 0
1651 sstr <<
"***** Outputting the residual history for well " << this->name() <<
" during inner iterations:";
1652 for (
int i = 0; i < it; ++i) {
1653 const auto& residual = residual_history[i];
1654 sstr <<
" residual at " << i <<
"th iteration ";
1655 for (
const auto& res : residual) {
1658 sstr <<
" " << measure_history[i] <<
" \n";
1661#undef EXTRA_DEBUG_MSW
1662 deferred_logger.debug(sstr.str());
1669 template<
typename TypeTag>
1674 const Well::InjectionControls& inj_controls,
1675 const Well::ProductionControls& prod_controls,
1678 const bool fixed_control ,
1679 const bool fixed_status ,
1680 const bool solving_with_zero_rate )
1684 const int max_iter_number = this->param_.max_inner_iter_ms_wells_;
1688 const auto& [isFinite, residuals] = this->getFiniteWellResiduals(Base::B_avg_, deferred_logger);
1693 updatePrimaryVariables(groupStateHelper);
1695 std::vector<std::vector<Scalar> > residual_history;
1696 std::vector<Scalar> measure_history;
1699 Scalar relaxation_factor = 1.;
1700 bool converged =
false;
1701 bool relax_convergence =
false;
1702 this->regularize_ =
false;
1703 const auto& summary_state = groupStateHelper.
summaryState();
1708 const int min_its_after_switch = 3;
1710 const int max_status_switch = this->param_.max_well_status_switch_inner_iter_;
1711 int its_since_last_switch = min_its_after_switch;
1712 int switch_count= 0;
1713 int status_switch_count = 0;
1715 const auto well_status_orig = this->wellStatus_;
1716 const auto operability_orig = this->operability_status_;
1717 auto well_status_cur = well_status_orig;
1719 const bool allow_open = well_state.
well(this->index_of_well_).status == WellStatus::OPEN;
1721 const bool allow_switching = !this->wellUnderZeroRateTarget(groupStateHelper) &&
1722 (!fixed_control || !fixed_status) && allow_open;
1723 bool final_check =
false;
1725 this->operability_status_.resetOperability();
1726 this->operability_status_.solvable =
true;
1731 [[maybe_unused]]
FSInfo info{};
1732 if constexpr (has_energy) {
1733 info = this->getFirstPerforationFluidStateInfo(simulator);
1735 for (; it < max_iter_number; ++it, ++debug_cost_counter_) {
1736 ++its_since_last_switch;
1737 if (allow_switching && its_since_last_switch >= min_its_after_switch && status_switch_count < max_status_switch){
1738 const Scalar wqTotal = this->primary_variables_.getWQTotal().value();
1739 bool changed = this->updateWellControlAndStatusLocalIteration(
1740 simulator, groupStateHelper, inj_controls, prod_controls, wqTotal,
1741 well_state, fixed_control, fixed_status,
1742 solving_with_zero_rate
1745 its_since_last_switch = 0;
1747 if (well_status_cur != this->wellStatus_) {
1748 well_status_cur = this->wellStatus_;
1749 status_switch_count++;
1752 if (!changed && final_check) {
1755 final_check =
false;
1757 if (status_switch_count == max_status_switch) {
1758 this->wellStatus_ = well_status_orig;
1762 if (it > this->param_.strict_inner_iter_wells_) {
1763 relax_convergence =
true;
1764 this->regularize_ =
true;
1767 assembleWellEqWithoutIteration(simulator, groupStateHelper, dt, inj_controls, prod_controls,
1768 well_state, solving_with_zero_rate);
1771 const auto report = getWellConvergence(groupStateHelper, Base::B_avg_, relax_convergence);
1772 converged = report.converged();
1773 if (this->parallel_well_info_.communication().size() > 1 &&
1774 this->parallel_well_info_.communication().max(converged) != this->parallel_well_info_.communication().min(converged)) {
1775 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()));
1780 if (switch_count > 0 && its_since_last_switch < min_its_after_switch) {
1782 its_since_last_switch = min_its_after_switch;
1790 const auto& [isFinite, residuals] = this->getFiniteWellResiduals(Base::B_avg_, deferred_logger);
1796 residual_history.push_back(residuals);
1800 measure_history.push_back(this->getResidualMeasureValue(well_state,
1801 residual_history[it],
1802 this->param_.tolerance_wells_,
1803 this->param_.tolerance_pressure_ms_wells_,
1805 bool min_relaxation_reached = this->update_relaxation_factor(measure_history, relaxation_factor, this->regularize_, deferred_logger);
1806 if (min_relaxation_reached || this->repeatedStagnation(measure_history, this->regularize_, deferred_logger)) {
1812 const BVectorWell dx_well = this->linSys_.solve();
1813 updateWellState(simulator, dx_well, groupStateHelper, well_state, relaxation_factor);
1814 if constexpr (has_energy) {
1816 updateSegmentFluidState(info, deferred_logger);
1819 catch(
const NumericalProblem& exp) {
1823 deferred_logger.problem(
"In MultisegmentWell::iterateWellEqWithSwitching for well "
1824 + this->name() +
": "+exp.what());
1830 if (allow_switching){
1832 const bool is_stopped = this->wellIsStopped();
1833 if (this->wellHasTHPConstraints(summary_state)){
1834 this->operability_status_.can_obtain_bhp_with_thp_limit = !is_stopped;
1835 this->operability_status_.obey_thp_limit_under_bhp_limit = !is_stopped;
1837 this->operability_status_.operable_under_only_bhp_limit = !is_stopped;
1840 std::string message = fmt::format(
" Well {} converged in {} inner iterations ("
1841 "{} control/status switches).", this->name(), it, switch_count);
1842 if (relax_convergence) {
1843 message.append(fmt::format(
" (A relaxed tolerance was used after {} iterations)",
1844 this->param_.strict_inner_iter_wells_));
1846 deferred_logger.debug(message, OpmLog::defaultDebugVerbosityLevel + ((it == 0) && (switch_count == 0)));
1848 this->wellStatus_ = well_status_orig;
1849 this->operability_status_ = operability_orig;
1850 const std::string message = fmt::format(
" Well {} did not converge in {} inner iterations ("
1851 "{} switches, {} status changes).", this->name(), it, switch_count, status_switch_count);
1852 deferred_logger.debug(message);
1853 this->primary_variables_.outputLowLimitPressureSegments(deferred_logger);
1860 template<
typename TypeTag>
1866 const Well::InjectionControls& inj_controls,
1867 const Well::ProductionControls& prod_controls,
1869 const bool solving_with_zero_rate)
1871 if (!this->isOperableAndSolvable() && !this->wellIsStopped())
return;
1876 this->segments_.updateUpwindingSegments(this->primary_variables_);
1879 computeSegmentFluidProperties(simulator, deferred_logger);
1882 this->linSys_.clear();
1884 auto& ws = well_state.
well(this->index_of_well_);
1885 ws.phase_mixing_rates.fill(0.0);
1886 if constexpr (has_energy) {
1887 ws.energy_rate = 0.0;
1895 const bool allow_cf = this->getAllowCrossFlow() || openCrossFlowAvoidSingularity(simulator);
1897 const int nseg = this->numberOfSegments();
1899 const Scalar rhow = FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx) ?
1900 FluidSystem::referenceDensity( FluidSystem::waterPhaseIdx, Base::pvtRegionIdx() ) : 0.0;
1901 const unsigned watCompIdx = FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx) ?
1902 FluidSystem::canonicalToActiveCompIdx(FluidSystem::waterCompIdx) : 0;
1904 for (
int seg = 0; seg < nseg; ++seg) {
1906 const EvalWell seg_pressure = this->primary_variables_.getSegmentPressure(seg);
1907 auto& perf_data = ws.perf_data;
1908 auto& perf_rates = perf_data.phase_rates;
1909 auto& perf_press_state = perf_data.pressure;
1910 for (
const int perf : this->segments_.perforations()[seg]) {
1911 const int local_perf_index = this->parallel_well_info_.activePerfToLocalPerf(perf);
1912 if (local_perf_index < 0)
1914 const int cell_idx = this->well_cells_[local_perf_index];
1915 const auto& int_quants = simulator.model().intensiveQuantities(cell_idx, 0);
1916 std::vector<EvalWell> mob(this->num_conservation_quantities_, 0.0);
1917 getMobility(simulator, local_perf_index, mob, deferred_logger);
1918 EvalWell trans_mult(0.0);
1919 getTransMult(trans_mult, simulator, cell_idx);
1920 const auto& wellstate_nupcol = simulator.problem().wellModel().nupcolWellState().well(this->index_of_well_);
1921 std::vector<EvalWell> Tw(this->num_conservation_quantities_, this->well_index_[local_perf_index] * trans_mult);
1922 this->getTw(Tw, local_perf_index, int_quants, trans_mult, wellstate_nupcol);
1923 std::vector<EvalWell> cq_s(this->num_conservation_quantities_, 0.0);
1924 EvalWell perf_press;
1926 computePerfRate(int_quants, mob, Tw, seg, perf, seg_pressure,
1927 allow_cf, cq_s, perf_press, perfRates, deferred_logger);
1930 if (this->isProducer()) {
1931 ws.phase_mixing_rates[ws.dissolved_gas] += perfRates.
dis_gas;
1932 ws.phase_mixing_rates[ws.vaporized_oil] += perfRates.
vap_oil;
1933 perf_data.phase_mixing_rates[local_perf_index][ws.dissolved_gas] = perfRates.
dis_gas;
1934 perf_data.phase_mixing_rates[local_perf_index][ws.vaporized_oil] = perfRates.
vap_oil;
1938 for (
int comp_idx = 0; comp_idx < this->num_conservation_quantities_; ++comp_idx) {
1939 perf_rates[local_perf_index*this->number_of_phases_ + FluidSystem::activeCompToActivePhaseIdx(comp_idx)] = cq_s[comp_idx].value();
1941 perf_press_state[local_perf_index] = perf_press.value();
1944 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
1945 perf_data.wat_mass_rates[local_perf_index] = cq_s[watCompIdx].value() * rhow;
1948 for (
int comp_idx = 0; comp_idx < this->num_conservation_quantities_; ++comp_idx) {
1950 const EvalWell cq_s_effective = cq_s[comp_idx] * this->well_efficiency_factor_;
1952 this->connectionRates_[local_perf_index][comp_idx] = Base::restrictEval(cq_s_effective);
1955 assemblePerforationEq(seg, local_perf_index, comp_idx, cq_s_effective, this->linSys_);
1959 if constexpr (has_energy) {
1960 assemblePerforationEnergyEq(int_quants, cq_s, seg, local_perf_index, deferred_logger);
1964 ws.energy_rate += getValue(this->connectionRates_[local_perf_index][Indices::contiEnergyEqIdx]);
1970 const auto& comm = this->parallel_well_info_.communication();
1971 comm.sum(ws.phase_mixing_rates.data(), ws.phase_mixing_rates.size());
1972 if constexpr (has_energy) {
1973 ws.energy_rate = comm.sum(ws.energy_rate);
1977 if (this->parallel_well_info_.communication().size() > 1) {
1979 this->linSys_.sumDistributed(this->parallel_well_info_.communication());
1982 const FSInfo info = this->getFirstPerforationFluidStateInfo(simulator);
1984 for (
int seg = 0; seg < nseg; ++seg) {
1987 const EvalWell segment_surface_volume = getSegmentSurfaceVolume(seg, info, deferred_logger);
1992 const Scalar regularization_factor = this->regularize_? this->param_.regularization_factor_wells_ : 1.0;
1994 for (
int comp_idx = 0; comp_idx < this->num_conservation_quantities_; ++comp_idx) {
1995 const EvalWell accumulation_term = regularization_factor * (segment_surface_volume * this->primary_variables_.surfaceVolumeFraction(seg, comp_idx)
1996 - segment_fluid_initial_[seg][comp_idx]) / dt;
1998 assembleAccumulationTerm(seg, comp_idx, accumulation_term, this->linSys_);
2001 if constexpr (has_energy) {
2002 const EvalWell segment_energy = this->computeSegmentEnergy(seg);
2004 const EvalWell accumulation_term_energy =
2005 energy_scaling_factor_ * regularization_factor * (segment_energy - segment_initial_energy_[seg]) / dt;
2007 assembleAccumulationTerm(seg, MSWEval::PrimaryVariables::Temperature, accumulation_term_energy, this->linSys_);
2012 const int seg_upwind = this->segments_.upwinding_segment(seg);
2013 for (
int comp_idx = 0; comp_idx < this->num_conservation_quantities_; ++comp_idx) {
2014 const EvalWell segment_rate =
2015 this->primary_variables_.getSegmentRateUpwinding(seg,
2018 this->well_efficiency_factor_;
2020 assembleOutflowTerm(seg, seg_upwind, comp_idx, segment_rate, this->linSys_);
2022 if constexpr (has_energy) {
2023 const bool top_injecting_segment = (seg == 0) && this->isInjector();
2024 if (top_injecting_segment) {
2025 this->updateWellHeadCondition(simulator, std::get<0>(info),
2026 std::get<1>(info), deferred_logger);
2031 const auto& upwind_fs = top_injecting_segment ? this->wellhead_fluid_state_
2032 : this->segment_fluid_state_[seg_upwind];
2033 assert((top_injecting_segment && seg_upwind == 0) || !top_injecting_segment);
2035 const EvalWell energy_rate =
2036 this->computeSegmentEnergyRate(seg, seg_upwind, upwind_fs,
2037 "energy outflow assembly", deferred_logger);
2039 assembleOutflowTerm(seg, seg_upwind, MSWEval::PrimaryVariables::Temperature, energy_rate, this->linSys_);
2045 for (
const int inlet : this->segments_.inlets()[seg]) {
2046 const int inlet_upwind = this->segments_.upwinding_segment(inlet);
2047 for (
int comp_idx = 0; comp_idx < this->num_conservation_quantities_; ++comp_idx) {
2048 const EvalWell inlet_rate =
2049 this->primary_variables_.getSegmentRateUpwinding(inlet,
2052 this->well_efficiency_factor_;
2054 assembleInflowTerm(seg, inlet, inlet_upwind, comp_idx, inlet_rate, this->linSys_);
2057 if constexpr (has_energy) {
2058 for (
const int inlet : this->segments_.inlets()[seg]) {
2059 const int inlet_upwind = this->segments_.upwinding_segment(inlet);
2061 const auto& upwind_fs = this->segment_fluid_state_[inlet_upwind];
2062 const EvalWell energy_rate =
2063 this->computeSegmentEnergyRate(inlet, inlet_upwind, upwind_fs,
2064 "energy inflow assembly", deferred_logger);
2066 assembleInflowTerm(seg, inlet, inlet_upwind, MSWEval::PrimaryVariables::Temperature, energy_rate, this->linSys_);
2073 const bool stopped_or_zero_target = this->stoppedOrZeroRateTarget(groupStateHelper);
2081 auto& group_state = solving_with_zero_rate
2085 auto group_guard = groupStateHelper_copy.
pushGroupState(group_state);
2087 if (this->wellUnderGroupControl(ws) && this->isProducer() && !stopped_or_zero_target) {
2088 this->updateGroupTargetFallbackFlag(well_state, deferred_logger);
2091 assembleControlEq(groupStateHelper_copy,
2094 this->getRefDensity(),
2095 this->primary_variables_,
2097 stopped_or_zero_target);
2099 const UnitSystem& unit_system = simulator.vanguard().eclState().getDeckUnitSystem();
2100 const auto& summary_state = simulator.vanguard().summaryState();
2101 this->assemblePressureEq(seg, unit_system, well_state, summary_state, this->param_.use_average_density_ms_wells_, deferred_logger);
2105 this->parallel_well_info_.communication().sum(this->ipr_a_.data(), this->ipr_a_.size());
2106 this->linSys_.createSolver();
2112 template<
typename TypeTag>
2117 return !this->getAllowCrossFlow() && allDrawDownWrongDirection(simulator);
2121 template<
typename TypeTag>
2126 bool all_drawdown_wrong_direction =
true;
2127 const int nseg = this->numberOfSegments();
2129 for (
int seg = 0; seg < nseg; ++seg) {
2130 const EvalWell segment_pressure = this->primary_variables_.getSegmentPressure(seg);
2131 for (
const int perf : this->segments_.perforations()[seg]) {
2132 const int local_perf_index = this->parallel_well_info_.activePerfToLocalPerf(perf);
2133 if (local_perf_index < 0)
2136 const int cell_idx = this->well_cells_[local_perf_index];
2137 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2138 const auto& fs = intQuants.fluidState();
2141 const EvalWell perf_seg_press_diff = this->segments_.getPressureDiffSegLocalPerf(seg, local_perf_index);
2143 const Scalar cell_perf_press_diff = this->cell_perforation_pressure_diffs_[local_perf_index];
2145 const Scalar pressure_cell = this->getPerfCellPressure(fs).value();
2146 const Scalar perf_press = pressure_cell - cell_perf_press_diff;
2149 const EvalWell drawdown = perf_press - (segment_pressure + perf_seg_press_diff);
2154 if ( (drawdown < 0. && this->isInjector()) ||
2155 (drawdown > 0. && this->isProducer()) ) {
2156 all_drawdown_wrong_direction =
false;
2161 const auto& comm = this->parallel_well_info_.communication();
2162 if (comm.size() > 1)
2164 all_drawdown_wrong_direction =
2165 (comm.min(all_drawdown_wrong_direction ? 1 : 0) == 1);
2168 return all_drawdown_wrong_direction;
2174 template<
typename TypeTag>
2185 template<
typename TypeTag>
2192 const Scalar firstPerfTemperature = std::get<0>(info);
2193 const Scalar firstPerfSaltConcentration = std::get<1>(info);
2195 return this->segments_.getSurfaceVolume(firstPerfTemperature,
2196 firstPerfSaltConcentration,
2197 this->primary_variables_,
2203 template<
typename TypeTag>
2204 std::optional<typename MultisegmentWell<TypeTag>::Scalar>
2209 const SummaryState& summary_state)
const
2215 this->getALQ(well_state),
2221 template<
typename TypeTag>
2222 std::optional<typename MultisegmentWell<TypeTag>::Scalar>
2226 const SummaryState& summary_state,
2228 bool iterate_if_no_solution)
const
2233 auto frates = [
this, &simulator, &deferred_logger](
const Scalar bhp) {
2239 std::vector<Scalar> rates(3);
2240 computeWellRatesWithBhp(simulator, bhp, rates, deferred_logger);
2245 computeBhpAtThpLimitProd(frates,
2247 maxPerfPress(simulator),
2248 this->getRefDensity(),
2250 this->getTHPConstraint(summary_state),
2256 if (!iterate_if_no_solution)
2257 return std::nullopt;
2259 auto fratesIter = [
this, &simulator, &groupStateHelper](
const Scalar bhp) {
2263 std::vector<Scalar> rates(3);
2264 computeWellRatesWithBhpIterations(simulator, bhp, groupStateHelper, rates);
2269 computeBhpAtThpLimitProd(fratesIter,
2271 maxPerfPress(simulator),
2272 this->getRefDensity(),
2274 this->getTHPConstraint(summary_state),
2278 template<
typename TypeTag>
2279 std::optional<typename MultisegmentWell<TypeTag>::Scalar>
2283 const SummaryState& summary_state)
const
2287 auto frates = [
this, &simulator, &deferred_logger](
const Scalar bhp) {
2293 std::vector<Scalar> rates(3);
2294 computeWellRatesWithBhp(simulator, bhp, rates, deferred_logger);
2299 computeBhpAtThpLimitInj(frates,
2301 this->getRefDensity(),
2310 auto fratesIter = [
this, &simulator, &groupStateHelper](
const Scalar bhp) {
2314 std::vector<Scalar> rates(3);
2315 computeWellRatesWithBhpIterations(simulator, bhp, groupStateHelper, rates);
2320 computeBhpAtThpLimitInj(fratesIter,
2322 this->getRefDensity(),
2333 template<
typename TypeTag>
2338 Scalar max_pressure = 0.0;
2339 const int nseg = this->numberOfSegments();
2340 for (
int seg = 0; seg < nseg; ++seg) {
2341 for (
const int perf : this->segments_.perforations()[seg]) {
2342 const int local_perf_index = this->parallel_well_info_.activePerfToLocalPerf(perf);
2343 if (local_perf_index < 0)
2346 const int cell_idx = this->well_cells_[local_perf_index];
2347 const auto& int_quants = simulator.model().intensiveQuantities(cell_idx, 0);
2348 const auto& fs = int_quants.fluidState();
2349 Scalar pressure_cell = this->getPerfCellPressure(fs).value();
2350 max_pressure = std::max(max_pressure, pressure_cell);
2353 max_pressure = this->parallel_well_info_.communication().max(max_pressure);
2354 return max_pressure;
2361 template<
typename TypeTag>
2362 std::vector<typename MultisegmentWell<TypeTag>::Scalar>
2368 std::vector<Scalar> well_q_s(this->num_conservation_quantities_, 0.0);
2369 const bool allow_cf = this->getAllowCrossFlow() || openCrossFlowAvoidSingularity(simulator);
2370 const int nseg = this->numberOfSegments();
2371 for (
int seg = 0; seg < nseg; ++seg) {
2373 const Scalar seg_pressure = getValue(this->primary_variables_.getSegmentPressure(seg));
2374 for (
const int perf : this->segments_.perforations()[seg]) {
2375 const int local_perf_index = this->parallel_well_info_.activePerfToLocalPerf(perf);
2376 if (local_perf_index < 0)
2379 const int cell_idx = this->well_cells_[local_perf_index];
2380 const auto& int_quants = simulator.model().intensiveQuantities(cell_idx, 0);
2381 std::vector<Scalar> mob(this->num_conservation_quantities_, 0.0);
2382 getMobility(simulator, local_perf_index, mob, deferred_logger);
2384 getTransMult(trans_mult, simulator, cell_idx);
2385 const auto& wellstate_nupcol = simulator.problem().wellModel().nupcolWellState().well(this->index_of_well_);
2386 std::vector<Scalar> Tw(this->num_conservation_quantities_, this->well_index_[local_perf_index] * trans_mult);
2387 this->getTw(Tw, local_perf_index, int_quants, trans_mult, wellstate_nupcol);
2388 std::vector<Scalar> cq_s(this->num_conservation_quantities_, 0.0);
2391 computePerfRate(int_quants, mob, Tw, seg, perf, seg_pressure,
2392 allow_cf, cq_s, perf_press, perf_rates, deferred_logger);
2393 for (
int comp = 0; comp < this->num_conservation_quantities_; ++comp) {
2394 well_q_s[comp] += cq_s[comp];
2398 const auto& comm = this->parallel_well_info_.communication();
2399 if (comm.size() > 1)
2401 comm.sum(well_q_s.data(), well_q_s.size());
2407 template <
typename TypeTag>
2408 std::vector<typename MultisegmentWell<TypeTag>::Scalar>
2412 const int num_seg = this->numberOfSegments();
2413 constexpr int num_eq = MSWEval::numWellEq;
2414 std::vector<Scalar> retval(num_seg * num_eq);
2415 for (
int ii = 0; ii < num_seg; ++ii) {
2416 const auto& pv = this->primary_variables_.value(ii);
2417 std::ranges::copy(pv, retval.begin() + ii * num_eq);
2425 template <
typename TypeTag>
2430 const int num_seg = this->numberOfSegments();
2431 constexpr int num_eq = MSWEval::numWellEq;
2432 std::array<Scalar, num_eq> tmp;
2433 for (
int ii = 0; ii < num_seg; ++ii) {
2434 const auto start = it + ii * num_eq;
2435 std::copy_n(start, num_eq, tmp.begin());
2436 this->primary_variables_.setValue(ii, tmp);
2438 return num_seg * num_eq;
2442 template <
typename TypeTag>
2448 this->primary_variables_.scaledWellFractions(scaled_fractions, deferred_logger);
2451 template <
typename TypeTag>
2456 Scalar fsTemperature = 0.0;
2457 Scalar fsSaltConcentration = 0.0;
2460 if (this->well_cells_.size() > 0) {
2463 const int cell_idx = this->well_cells_[0];
2464 const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, 0);
2465 const auto& fs = intQuants.fluidState();
2467 fsTemperature = getValue(fs.temperature(FluidSystem::oilPhaseIdx));
2468 fsSaltConcentration = getValue(fs.saltConcentration());
2471 auto info = std::make_tuple(fsTemperature, fsSaltConcentration);
2475 return this->parallel_well_info_.communication().size() == 1 ? info : this->parallel_well_info_.broadcastFirstPerforationValue(info);
2478 template <
typename TypeTag>
2479 template <
typename ValueType>
2483 const ValueType& pressure,
2484 const ValueType& temperature,
2485 const ValueType& saltConcentration,
2489 if constexpr (has_energy) {
2490 fluid_state.setTemperature(temperature);
2492 if constexpr (has_brine) {
2494 fluid_state.setSaltConcentration(saltConcentration);
2496 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2497 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2501 fluid_state.setPressure(phaseIdx, pressure);
2503 fluid_state.setPvtRegionIndex(this->pvtRegionIdx());
2505 const bool both_oil_gas = FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx);
2507 const ValueType zero_value {0.};
2509 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2510 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2514 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2515 constexpr Scalar epsilon = std::numeric_limits<Scalar>::epsilon();
2518 case FluidSystem::oilPhaseIdx: {
2519 if constexpr (compositionSwitchEnabled) {
2522 ValueType rs = FluidSystem::saturatedDissolutionFactor(fluid_state, phaseIdx, fluid_state.pvtRegionIndex());
2523 if (fluid_composition[activeCompIdx] > epsilon) {
2524 const unsigned gasCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
2525 const ValueType max_possible_rs = fluid_composition[gasCompIdx] / fluid_composition[activeCompIdx];
2526 rs = std::min(rs, max_possible_rs);
2528 fluid_state.setRs(rs);
2530 fluid_state.setRs(zero_value);
2535 case FluidSystem::gasPhaseIdx: {
2536 if constexpr (compositionSwitchEnabled) {
2539 ValueType rv = FluidSystem::saturatedVaporizationFactor(fluid_state, phaseIdx, fluid_state.pvtRegionIndex());
2540 const unsigned oilCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::oilCompIdx);
2541 if (fluid_composition[activeCompIdx] > epsilon) {
2542 const ValueType max_possible_rv = fluid_composition[oilCompIdx] / fluid_composition[activeCompIdx];
2543 rv = std::min(rv, max_possible_rv);
2545 fluid_state.setRv(rv);
2547 fluid_state.setRv(zero_value);
2552 case FluidSystem::waterPhaseIdx: {
2557 throw std::logic_error(
"Unhandled phase index " +
std::to_string(phaseIdx));
2560 const auto& inv_b = FluidSystem::inverseFormationVolumeFactor(fluid_state, phaseIdx, fluid_state.pvtRegionIndex());
2561 fluid_state.setInvB(phaseIdx, inv_b);
2564 std::vector<ValueType> saturations (FluidSystem::numPhases, zero_value);
2565 ValueType sum_saturation {0.0};
2567 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2568 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2571 if (!both_oil_gas || FluidSystem::waterPhaseIdx == phaseIdx) {
2572 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2573 saturations[phaseIdx] = fluid_composition[activeCompIdx] / fluid_state.invB(phaseIdx);
2574 sum_saturation += saturations[phaseIdx];
2581 const ValueType d = 1.0 - fluid_state.Rv() * fluid_state.Rs();
2583 deferred_logger.
debug(
2584 fmt::format(
"Problematic d value {} obtained for well {}"
2585 " during createFluidState with rs {}"
2586 ", rv {}. Continue as if no dissolution (rs = 0) and"
2587 " vaporization (rv = 0)",
2588 d, this->name(), fluid_state.Rs(), fluid_state.Rv()) );
2592 if constexpr (compositionSwitchEnabled) {
2593 fluid_state.setRs(zero_value);
2594 fluid_state.setRv(zero_value);
2596 fluid_state.setInvB(FluidSystem::oilPhaseIdx,
2597 FluidSystem::inverseFormationVolumeFactor(fluid_state, FluidSystem::oilPhaseIdx, fluid_state.pvtRegionIndex()));
2598 fluid_state.setInvB(FluidSystem::gasPhaseIdx,
2599 FluidSystem::inverseFormationVolumeFactor(fluid_state, FluidSystem::gasPhaseIdx, fluid_state.pvtRegionIndex()));
2600 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2601 saturations[phaseIdx] = fluid_composition[activeCompIdx] / fluid_state.invB(phaseIdx);
2603 const unsigned oilCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::oilCompIdx);
2604 const unsigned gasCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
2605 if (FluidSystem::gasPhaseIdx == phaseIdx) {
2606 saturations[phaseIdx] = (fluid_composition[gasCompIdx] -
2607 fluid_state.Rs() * fluid_composition[oilCompIdx]) /
2608 (d * fluid_state.invB(phaseIdx));
2609 }
else if (FluidSystem::oilPhaseIdx == phaseIdx) {
2610 saturations[phaseIdx] = (fluid_composition[oilCompIdx] -
2611 fluid_state.Rv() * fluid_composition[gasCompIdx]) /
2612 (d * fluid_state.invB(phaseIdx));
2615 sum_saturation += saturations[phaseIdx];
2619 typename FluidSystem::template ParameterCache<ValueType> paramCache;
2620 paramCache.setRegionIndex(fluid_state.pvtRegionIndex());
2621 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2622 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2625 fluid_state.setSaturation(phaseIdx, saturations[phaseIdx] / sum_saturation);
2627 paramCache.updatePhase(fluid_state, phaseIdx);
2628 fluid_state.setDensity(phaseIdx, FluidSystem::density(fluid_state, paramCache, phaseIdx));
2629 if constexpr (has_energy) {
2630 fluid_state.setEnthalpy(phaseIdx, FluidSystem::enthalpy(fluid_state, paramCache, phaseIdx));
2637 template <
typename TypeTag>
2642 const EvalWell seg_pressure = this->primary_variables_.getSegmentPressure(seg);
2643 const Scalar firstPerfTemperature = std::get<0>(info);
2645 const EvalWell seg_salt_concentration = std::get<1>(info);
2646 const EvalWell seg_temperature = has_energy ? this->primary_variables_.getSegmentTemperature(seg) : firstPerfTemperature;
2649 std::vector<EvalWell> fluid_composition(this->numConservationQuantities(), 0.0);
2650 for (
int idx = 0; idx < this->numConservationQuantities(); ++idx) {
2651 fluid_composition[idx] = this->primary_variables_.surfaceVolumeFraction(seg, idx);
2654 return createFluidState(fluid_composition, seg_pressure, seg_temperature,
2655 seg_salt_concentration, deferred_logger);
2658 template <
typename TypeTag>
2659 template <
typename Flu
idStateT>
2663 const FluidStateT& fs,
2664 const std::vector<EvalWell>& surface_rates,
2666 const std::string_view context,
2671 auto asEvalWell = [
this](
const auto& v) -> EvalWell {
2672 if constexpr (std::is_same_v<std::decay_t<
decltype(v)>, EvalWell>) {
2675 return this->extendEval(v);
2679 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2680 const EvalWell invB = asEvalWell(fs.invB(phaseIdx));
2681 const bool both_oil_gas = FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)
2682 && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx);
2683 if (!both_oil_gas || FluidSystem::waterPhaseIdx == phaseIdx) {
2684 return surface_rates[activeCompIdx] / invB;
2688 const EvalWell rs = asEvalWell(fs.Rs());
2689 const EvalWell rv = asEvalWell(fs.Rv());
2690 const EvalWell d = 1. - rs * rv;
2692 deferred_logger.
debug(
2693 fmt::format(
"Problematic d value {} obtained for well {}, segment {}"
2694 " during {} with rs {}, rv {}. Continue as if no dissolution"
2695 " (rs = 0) and vaporization (rv = 0) for this connection.",
2696 d, this->name(), seg, context, rs, rv));
2697 return surface_rates[activeCompIdx] / invB;
2699 const unsigned oilCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::oilCompIdx);
2700 const unsigned gasCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
2701 if (FluidSystem::gasPhaseIdx == phaseIdx) {
2702 return (surface_rates[gasCompIdx] - rs * surface_rates[oilCompIdx]) / (d * invB);
2704 if (FluidSystem::oilPhaseIdx == phaseIdx) {
2705 return (surface_rates[oilCompIdx] - rv * surface_rates[gasCompIdx]) / (d * invB);
2707 return EvalWell{0.0};
2710 template <
typename TypeTag>
2714 const int upwind_seg,
2716 const std::string_view context,
2720 std::vector<EvalWell> surface_rates(this->num_conservation_quantities_, 0.0);
2721 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2722 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2725 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2726 surface_rates[activeCompIdx] =
2727 this->primary_variables_.getSegmentRateUpwinding(seg,
2730 this->well_efficiency_factor_;
2733 EvalWell energy_rate(0.0);
2734 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2735 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2738 const EvalWell reservoir_rate =
2739 this->surfaceToReservoirRate(phaseIdx, upwind_fs, surface_rates,
2740 seg, context, deferred_logger);
2741 energy_rate += reservoir_rate * upwind_fs.enthalpy(phaseIdx) * upwind_fs.density(phaseIdx);
2744 return energy_scaling_factor_ * energy_rate;
2747 template <
typename TypeTag>
2751 const std::vector<EvalWell>& cq_s,
2753 const int local_perf_index,
2756 const auto& fs = int_quants.fluidState();
2758 const auto& seg_fs = this->segment_fluid_state_[seg];
2761 EvalWell energy_flux(0.0);
2762 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2763 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2767 const unsigned activeCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2769 const bool injecting = cq_s[activeCompIdx] > 0.0;
2771 EvalWell cq_r_thermal(0.0);
2774 cq_r_thermal = this->surfaceToReservoirRate(phaseIdx, seg_fs, cq_s,
2775 seg,
"energy assembly (injecting)",
2780 energy_flux += cq_r_thermal * seg_fs.enthalpy(phaseIdx) * seg_fs.density(phaseIdx);
2783 cq_r_thermal = this->surfaceToReservoirRate(phaseIdx, fs, cq_s,
2784 seg,
"energy assembly (producing)",
2786 energy_flux += cq_r_thermal * this->extendEval(fs.enthalpy(phaseIdx)) * this->extendEval(fs.density(phaseIdx));
2789 energy_flux *= this->well_efficiency_factor_;
2792 this->connectionRates_[local_perf_index][Indices::contiEnergyEqIdx] = Base::restrictEval(energy_flux);
2797 assemblePerforationEq(seg, local_perf_index,
2798 MSWEval::PrimaryVariables::Temperature,
2799 energy_scaling_factor_ * energy_flux,
2803 template <
typename TypeTag>
2807 for (
int seg = 0; seg < this->numberOfSegments(); ++seg) {
2808 segment_initial_energy_[seg] = computeSegmentEnergy<Scalar>(seg);
2812 template <
typename TypeTag>
2815 const Scalar first_perf_temperature,
2816 const Scalar first_perf_salt_concentration,
2819 if (!this->well_ecl_.isInjector())
return;
2821 std::vector<EvalWell> fluid_composition(FluidSystem::numPhases, 0.0);
2825 const EvalWell bhp = this->primary_variables_.getSegmentPressure(0);
2829 const EvalWell inj_temperature = this->well_ecl_.hasInjTemperature()
2830 ? EvalWell{this->well_ecl_.inj_temperature()}
2831 : EvalWell{first_perf_temperature};
2833 const auto controls = this->well_ecl_.injectionControls(simulator.vanguard().summaryState());
2834 switch (controls.injector_type) {
2835 case InjectorType::OIL: {
2836 const unsigned oilActiveCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::oilCompIdx);
2837 fluid_composition[oilActiveCompIdx] = 1.0;
2840 case InjectorType::GAS: {
2841 const unsigned gasActiveCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::gasCompIdx);
2842 fluid_composition[gasActiveCompIdx] = 1.0;
2845 case InjectorType::WATER: {
2846 const unsigned waterActiveCompIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::waterCompIdx);
2847 fluid_composition[waterActiveCompIdx] = 1.0;
2851 throw std::logic_error(
"Unsupported injection type " +
std::to_string(
static_cast<int>(controls.injector_type)));
2856 const EvalWell inj_salt_concentration{first_perf_salt_concentration};
2858 this->wellhead_fluid_state_ = createFluidState(fluid_composition, bhp, inj_temperature,
2859 inj_salt_concentration, deferred_logger);
2863 template <
typename TypeTag>
2864 template <
typename ValueType>
2868 auto obtain = [](
const auto& val) {
2869 if constexpr (std::is_same_v<ValueType, Scalar>) {
2870 return getValue(val);
2876 ValueType result {0.};
2877 const auto& segment_fluid_state = this->segment_fluid_state_[seg];
2878 const Scalar segment_volume = this->wellEcl().getSegments()[seg].volume();
2879 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
2880 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2883 const auto u = obtain(segment_fluid_state.internalEnergy(phaseIdx));
2884 const auto s = obtain(segment_fluid_state.saturation(phaseIdx));
2885 const auto rho = obtain(segment_fluid_state.density(phaseIdx));
2886 result += segment_volume * u * s * rho;
2892 template <
typename TypeTag>
2897 for (
int seg = 0; seg < this->numberOfSegments(); ++seg) {
2898 segment_fluid_state_[seg] = this->createSegmentFluidState(seg, info, deferred_logger);
#define OPM_DEFLOG_PROBLEM(Exception, message, deferred_logger)
Definition: DeferredLoggingErrorHelpers.hpp:61
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:429
const WellState< Scalar, IndexTraits > & wellState() const
Definition: GroupStateHelper.hpp:510
DeferredLogger & deferredLogger() const
Get the deferred logger.
Definition: GroupStateHelper.hpp:233
WellStateGuard pushWellState(WellState< Scalar, IndexTraits > &well_state)
Definition: GroupStateHelper.hpp:368
GroupStateGuard pushGroupState(GroupState< Scalar > &group_state)
Definition: GroupStateHelper.hpp:345
Definition: GroupState.hpp:41
Class 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:157
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:539
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:1672
std::tuple< Scalar, Scalar > FSInfo
Definition: MultisegmentWell.hpp:91
void computeInitialSegmentEnergy()
Definition: MultisegmentWell_impl.hpp:2805
void updateWellState(const Simulator &simulator, const BVectorWell &dwells, const GroupStateHelperType &groupStateHelper, WellStateType &well_state, const Scalar relaxation_factor=1.0)
Definition: MultisegmentWell_impl.hpp:721
void updateWaterThroughput(const double dt, WellStateType &well_state) const override
Definition: MultisegmentWell_impl.hpp:2177
void addWellPressureEquations(PressureMatrix &mat, const BVector &x, const int pressureVarIndex, const bool use_well_weights, const WellStateType &well_state) const override
Definition: MultisegmentWell_impl.hpp:907
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:1863
Scalar connectionDensity(const int globalConnIdx, const int openConnIdx) const override
Definition: MultisegmentWell_impl.hpp:872
void addWellContributions(SparseMatrixAdapter &jacobian) const override
Definition: MultisegmentWell_impl.hpp:894
void getTransMult(Value &trans_mult, const Simulator &simulator, const int cell_indx) const
Definition: MultisegmentWell_impl.hpp:1177
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:2662
EvalWell getSegmentSurfaceVolume(const int seg_idx, const FSInfo &info, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:2188
std::vector< Scalar > computeWellPotentialWithTHP(const WellStateType &well_state, const Simulator &simulator, const GroupStateHelperType &groupStateHelper) const
Definition: MultisegmentWell_impl.hpp:487
Scalar getRefDensity() const override
Definition: MultisegmentWell_impl.hpp:1237
EvalWell computeSegmentEnergyRate(int seg, int upwind_seg, const SegmentFluidState< EvalWell > &upwind_fs, std::string_view context, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:2713
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:182
std::vector< Scalar > getPrimaryVars() const override
Definition: MultisegmentWell_impl.hpp:2410
void computeWellRatesWithBhpIterations(const Simulator &simulator, const Scalar &bhp, const GroupStateHelperType &groupStateHelper, std::vector< Scalar > &well_flux) const override
Definition: MultisegmentWell_impl.hpp:411
void checkOperabilityUnderTHPLimit(const Simulator &ebos_simulator, const WellStateType &well_state, const GroupStateHelperType &groupStateHelper) override
Definition: MultisegmentWell_impl.hpp:1482
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:1535
ValueType computeSegmentEnergy(int seg) const
Definition: MultisegmentWell_impl.hpp:2866
std::vector< Scalar > computeCurrentWellRates(const Simulator &simulator, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:2364
void apply(const BVector &x, BVector &Ax) const override
Ax = Ax - C D^-1 B x.
Definition: MultisegmentWell_impl.hpp:227
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:84
void checkOperabilityUnderBHPLimit(const WellStateType &well_state, const Simulator &ebos_simulator, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:1245
void getMobility(const Simulator &simulator, const int local_perf_index, std::vector< Value > &mob, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:1197
void recoverWellSolutionAndUpdateWellState(const Simulator &simulator, const BVector &x, const GroupStateHelperType &groupStateHelper, WellStateType &well_state) override
Definition: MultisegmentWell_impl.hpp:262
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:2750
bool openCrossFlowAvoidSingularity(const Simulator &simulator) const
Definition: MultisegmentWell_impl.hpp:2115
void computeSegmentFluidProperties(const Simulator &simulator, DeferredLogger &deferred_logger)
Definition: MultisegmentWell_impl.hpp:1149
int setPrimaryVars(typename std::vector< Scalar >::const_iterator it) override
Definition: MultisegmentWell_impl.hpp:2428
void computeWellRatesWithBhp(const Simulator &simulator, const Scalar &bhp, std::vector< Scalar > &well_flux, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:361
void updateSegmentFluidState(const FSInfo &info, DeferredLogger &deferred_logger)
Definition: MultisegmentWell_impl.hpp:2894
Base::template BlackOilFluidStateType< ValueType > SegmentFluidState
Definition: MultisegmentWell.hpp:102
void scaleSegmentRatesAndPressure(WellStateType &well_state) const override
updating the segment pressure and rates based the current bhp and well rates
Definition: MultisegmentWell_impl.hpp:171
bool allDrawDownWrongDirection(const Simulator &simulator) const
Definition: MultisegmentWell_impl.hpp:2124
int debug_cost_counter_
Definition: MultisegmentWell.hpp:230
void updateProductivityIndex(const Simulator &simulator, const WellProdIndexCalculator< Scalar > &wellPICalc, WellStateType &well_state, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:790
std::optional< Scalar > computeBhpAtThpLimitProd(const WellStateType &well_state, const Simulator &ebos_simulator, const GroupStateHelperType &groupStateHelper, const SummaryState &summary_state) const
Definition: MultisegmentWell_impl.hpp:2206
Scalar maxPerfPress(const Simulator &simulator) const override
Definition: MultisegmentWell_impl.hpp:2336
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:1076
SegmentFluidState< EvalWell > createSegmentFluidState(int seg, const FSInfo &info, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:2639
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:2482
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:299
void calculateExplicitQuantities(const Simulator &simulator, const GroupStateHelperType &groupStateHelper) override
Definition: MultisegmentWell_impl.hpp:765
void computePerfCellPressDiffs(const Simulator &simulator)
Definition: MultisegmentWell_impl.hpp:646
void solveEqAndUpdateWellState(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state) override
Definition: MultisegmentWell_impl.hpp:616
void updateWellHeadCondition(const Simulator &simulator, const Scalar first_perf_temperature, const Scalar first_perf_salt_concentration, DeferredLogger &deferred_logger)
Definition: MultisegmentWell_impl.hpp:2814
std::optional< Scalar > computeBhpAtThpLimitInj(const Simulator &ebos_simulator, const GroupStateHelperType &groupStateHelper, const SummaryState &summary_state) const
Definition: MultisegmentWell_impl.hpp:2281
void updateIPR(const Simulator &ebos_simulator, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:1311
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:201
void updatePrimaryVariables(const GroupStateHelperType &groupStateHelper) override
Definition: MultisegmentWell_impl.hpp:156
void updateIPRImplicit(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, WellStateType &well_state) override
Definition: MultisegmentWell_impl.hpp:1412
void computeWellRatesAtBhpLimit(const Simulator &simulator, const GroupStateHelperType &groupStateHelper, std::vector< Scalar > &well_flux) const
Definition: MultisegmentWell_impl.hpp:345
FSInfo getFirstPerforationFluidStateInfo(const Simulator &simulator) const
Definition: MultisegmentWell_impl.hpp:2454
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:121
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:2224
void computeInitialSegmentFluids(const FSInfo &info, DeferredLogger &deferred_logger)
Definition: MultisegmentWell_impl.hpp:703
void getScaledWellFractions(std::vector< Scalar > &scaled_fractions, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:2445
EvalWell getQs(const int comp_idx) const
Returns scaled rate for a component.
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:198
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:318
void onlyKeepBHPandTHPcontrols(const SummaryState &summary_state, WellStateType &well_state, Well::InjectionControls &inj_controls, Well::ProductionControls &prod_controls) const
void resetDampening()
Definition: WellInterfaceGeneric.hpp:256
std::pair< bool, bool > computeWellPotentials(std::vector< Scalar > &well_potentials, const WellStateType &well_state)
Definition: WellInterfaceIndices.hpp:34
Definition: WellInterface.hpp:78
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:613
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: WellInterface.hpp:83
typename WellInterfaceFluidSystem< FluidSystem >::RateConverterType RateConverterType
Definition: WellInterface.hpp:106
void getTransMult(Value &trans_mult, const Simulator &simulator, const int cell_idx, Callback &extendEval) const
Definition: WellInterface_impl.hpp:2099
Dune::BCRSMatrix< Opm::MatrixBlock< Scalar, 1, 1 > > PressureMatrix
Definition: WellInterface.hpp:99
void getMobility(const Simulator &simulator, const int local_perf_index, std::vector< Value > &mob, Callback &extendEval, DeferredLogger &deferred_logger) const
Definition: WellInterface_impl.hpp:2112
GetPropType< TypeTag, Properties::IntensiveQuantities > IntensiveQuantities
Definition: WellInterface.hpp:88
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: WellInterface.hpp:84
Dune::BlockVector< VectorBlockType > BVector
Definition: WellInterface.hpp:98
typename Base::ModelParameters ModelParameters
Definition: WellInterface.hpp:112
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: WellInterface.hpp:85
typename Base::Eval Eval
Definition: WellInterface.hpp:97
GetPropType< TypeTag, Properties::Indices > Indices
Definition: WellInterface.hpp:87
GetPropType< TypeTag, Properties::SparseMatrixAdapter > SparseMatrixAdapter
Definition: WellInterface.hpp:90
Definition: WellProdIndexCalculator.hpp:37
Scalar connectionProdIndStandard(const std::size_t connIdx, const Scalar connMobility) const
Definition: WellState.hpp:66
const SingleWellState< Scalar, IndexTraits > & well(std::size_t well_index) const
Definition: WellState.hpp:310
@ 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:56
Scalar dis_gas
Definition: PerforationData.hpp:57
Scalar vap_oil
Definition: PerforationData.hpp:59