22 #ifndef OPM_MULTISEGMENTWELL_HEADER_INCLUDED 23 #define OPM_MULTISEGMENTWELL_HEADER_INCLUDED 27 #include <opm/common/Exceptions.hpp> 28 #include <opm/simulators/wells/WellInterface.hpp> 29 #include <opm/simulators/wells/MultisegmentWellEval.hpp> 32 #include <string_view> 38 template<
typename TypeTag>
41 GetPropType<TypeTag, Properties::Indices>>
48 using typename Base::Simulator;
49 using typename Base::IntensiveQuantities;
50 using typename Base::FluidSystem;
51 using typename Base::IndexTraits;
52 using typename Base::ModelParameters;
53 using typename Base::MaterialLaw;
54 using typename Base::Indices;
55 using typename Base::RateConverterType;
56 using typename Base::SparseMatrixAdapter;
57 using typename Base::FluidState;
61 using Base::has_solvent;
62 using Base::has_polymer;
63 using Base::has_energy;
64 using Base::has_brine;
69 using typename Base::Scalar;
74 static constexpr
bool compositionSwitchEnabled =
75 Indices::compositionSwitchIdx != std::numeric_limits<unsigned>::max();
79 static constexpr Scalar energy_scaling_factor_ =
80 getPropValue<TypeTag, Properties::BlackOilEnergyScalingFactor>();
83 using typename Base::BVector;
84 using typename Base::Eval;
87 using typename MSWEval::EvalWell;
88 using typename MSWEval::BVectorWell;
90 using typename Base::PressureMatrix;
91 using FSInfo = std::tuple<Scalar, Scalar>;
93 using BMatrix =
typename Base::BMatrix;
94 using CMatrix =
typename Base::CMatrix;
95 using DMatrix =
typename Base::DMatrix;
96 using WVector =
typename Base::WVector;
101 template <
typename ValueType>
102 using SegmentFluidState = Base::template BlackOilFluidStateType<ValueType>;
107 const ModelParameters& param,
108 const RateConverterType& rate_converter,
109 const int pvtRegionIdx,
110 const int num_conservation_quantities,
111 const int num_phases,
112 const int index_of_well,
115 void init(
const std::vector<Scalar>& depth_arg,
116 const Scalar gravity_arg,
117 const std::vector<Scalar>& B_avg,
118 const bool changed_to_open_this_step)
override;
130 const std::vector<Scalar>& B_avg,
131 const bool relax_tolerance)
const override;
134 void apply(
const BVector& x, BVector& Ax)
const override;
136 void apply(BVector& r)
const override;
149 std::vector<Scalar>& well_potentials)
override;
153 void solveEqAndUpdateWellState(
const Simulator& simulator,
157 void calculateExplicitQuantities(
const Simulator& simulator,
160 void updateIPRImplicit(
const Simulator& simulator,
164 void updateProductivityIndex(
const Simulator& simulator,
169 Scalar connectionDensity(
const int globalConnIdx,
170 const int openConnIdx)
const override;
172 void addWellContributions(SparseMatrixAdapter& jacobian)
const override;
174 void addWellPressureEquations(PressureMatrix& mat,
176 const int pressureVarIndex,
177 const bool use_well_weights,
184 std::optional<Scalar>
185 computeBhpAtThpLimitProdWithAlq(
const Simulator& simulator,
187 const SummaryState& summary_state,
188 const Scalar alq_value,
189 bool iterate_if_no_solution)
const override;
191 std::vector<Scalar> getPrimaryVars()
const override;
193 int setPrimaryVars(
typename std::vector<Scalar>::const_iterator it)
override;
194 void addBCDMatrix(std::vector<typename Base::BMatrix>& b_matrices,
195 std::vector<typename Base::CMatrix>& c_matrices,
196 std::vector<typename Base::DMatrix>& d_matrices,
201 if constexpr (Base::numWellDofs == MSWEval::numWellDofs) {
202 MSWEval::addBCDMatrix(b_matrices, c_matrices, d_matrices, wcells);
204 OPM_THROW(std::runtime_error,
205 "system_cpr preconditioner with multisegment wells is only supported for standard " 206 "3-phase blackoil (Indices::numEq == 3). This model has different equation count.");
218 std::vector<std::vector<Scalar> > segment_fluid_initial_;
220 std::vector<Scalar> segment_initial_energy_;
223 std::vector<SegmentFluidState<EvalWell>> segment_fluid_state_;
228 SegmentFluidState<EvalWell> wellhead_fluid_state_;
230 mutable int debug_cost_counter_ = 0;
233 void updateWellState(
const Simulator& simulator,
234 const BVectorWell& dwells,
237 const Scalar relaxation_factor = 1.0);
240 void computeInitialSegmentFluids(
const FSInfo& info,
DeferredLogger& deferred_logger);
243 void computePerfCellPressDiffs(
const Simulator& simulator);
245 template<
class Value>
246 void computePerfRate(
const IntensiveQuantities& int_quants,
247 const std::vector<Value>& mob_perfcells,
248 const std::vector<Value>& Tw,
251 const Value& segment_pressure,
252 const bool& allow_cf,
253 std::vector<Value>& cq_s,
258 template<
class Value>
259 void computePerfRate(
const Value& pressure_cell,
262 const std::vector<Value>& b_perfcells,
263 const std::vector<Value>& mob_perfcells,
264 const std::vector<Value>& Tw,
266 const Value& segment_pressure,
267 const Value& segment_density,
268 const bool& allow_cf,
269 const std::vector<Value>& cmix_s,
270 std::vector<Value>& cq_s,
277 void computeSegmentFluidProperties(
const Simulator& simulator,
281 template<
class Value>
282 void getTransMult(Value& trans_mult,
283 const Simulator& simulator,
284 const int cell_indx)
const;
287 template<
class Value>
288 void getMobility(
const Simulator& simulator,
289 const int local_perf_index,
290 std::vector<Value>& mob,
293 void computeWellRatesAtBhpLimit(
const Simulator& simulator,
295 std::vector<Scalar>& well_flux)
const;
297 void computeWellRatesWithBhp(
const Simulator& simulator,
299 std::vector<Scalar>& well_flux,
302 void computeWellRatesWithBhpIterations(
const Simulator& simulator,
305 std::vector<Scalar>& well_flux)
const override;
309 const Simulator& simulator,
312 bool computeWellPotentialsImplicit(
const Simulator& simulator,
314 std::vector<Scalar>& well_potentials)
const;
316 Scalar getRefDensity()
const override;
318 bool iterateWellEqWithControl(
const Simulator& simulator,
320 const Well::InjectionControls& inj_controls,
321 const Well::ProductionControls& prod_controls,
325 bool iterateWellEqWithSwitching(
const Simulator& simulator,
327 const Well::InjectionControls& inj_controls,
328 const Well::ProductionControls& prod_controls,
331 const bool fixed_control,
332 const bool fixed_status,
333 const bool solving_with_zero_rate)
override;
335 void assembleWellEqWithoutIteration(
const Simulator& simulator,
338 const Well::InjectionControls& inj_controls,
339 const Well::ProductionControls& prod_controls,
341 const bool solving_with_zero_rate)
override;
343 void updateWaterThroughput(
const double dt,
WellStateType& well_state)
const override;
345 EvalWell getSegmentSurfaceVolume(
const int seg_idx,
354 bool openCrossFlowAvoidSingularity(
const Simulator& simulator)
const;
358 bool allDrawDownWrongDirection(
const Simulator& simulator)
const;
360 std::optional<Scalar>
362 const Simulator& ebos_simulator,
364 const SummaryState& summary_state)
const;
366 std::optional<Scalar>
367 computeBhpAtThpLimitInj(
const Simulator& ebos_simulator,
369 const SummaryState& summary_state)
const;
371 Scalar maxPerfPress(
const Simulator& simulator)
const override;
374 void checkOperabilityUnderBHPLimit(
const WellStateType& well_state,
375 const Simulator& ebos_simulator,
379 void checkOperabilityUnderTHPLimit(
const Simulator& ebos_simulator,
384 void updateIPR(
const Simulator& ebos_simulator,
387 FSInfo getFirstPerforationFluidStateInfo(
const Simulator& simulator)
const;
391 template <
typename ValueType = EvalWell>
392 SegmentFluidState<ValueType>
393 createFluidState(
const std::vector<ValueType>& fluid_composition,
394 const ValueType& pressure,
395 const ValueType& temperature,
396 const ValueType& saltConcentration,
399 SegmentFluidState<EvalWell>
400 createSegmentFluidState(
int seg,
const FSInfo& info,
DeferredLogger& deferred_logger)
const;
402 void computeInitialSegmentEnergy();
405 void assemblePerforationEnergyEq(
const IntensiveQuantities& int_quants,
406 const std::vector<EvalWell>& cq_s,
408 const int local_perf_index,
411 void updateWellHeadCondition(
const Simulator& simulator,
412 const Scalar first_perf_temperature,
413 const Scalar first_perf_salt_concentration,
416 void updateSegmentFluidState(
const FSInfo& info,
DeferredLogger& deferred_logger);
418 template <
typename ValueType = EvalWell>
419 ValueType computeSegmentEnergy(
int seg)
const;
428 template <
typename Flu
idStateT>
429 EvalWell surfaceToReservoirRate(
unsigned phaseIdx,
430 const FluidStateT& fs,
431 const std::vector<EvalWell>& surface_rates,
433 std::string_view context,
440 EvalWell computeSegmentEnergyRate(
int seg,
442 const SegmentFluidState<EvalWell>& upwind_fs,
443 std::string_view context,
449 #include "MultisegmentWell_impl.hpp" 451 #endif // OPM_MULTISEGMENTWELL_HEADER_INCLUDED 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
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(...))
Definition: propertysystem.hh:233
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
Defines the common properties required by the porous medium multi-phase models.
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
Definition: BlackoilWellModelConstraints.hpp:37
void getScaledWellFractions(std::vector< Scalar > &scaled_fractions, DeferredLogger &deferred_logger) const override
Get scaled well fractions from primary variables Implemented by derived classes that have access to p...
Definition: MultisegmentWell_impl.hpp:2445
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
Definition: BlackoilWellModelGasLift.hpp:38
Definition: PerforationData.hpp:55
void apply(const BVector &x, BVector &Ax) const override
Ax = Ax - C D^-1 B x.
Definition: MultisegmentWell_impl.hpp:227
Definition: MultisegmentWellEval.hpp:48
Class encapsulating some information about parallel wells.
Definition: MSWellHelpers.hpp:34
std::vector< Scalar > computeCurrentWellRates(const Simulator &simulator, DeferredLogger &deferred_logger) const override
Compute well rates based on current reservoir conditions and well variables.
Definition: MultisegmentWell_impl.hpp:2364
Definition: DeferredLogger.hpp:56
Collect per-connection static information to enable calculating connection-level or well-level produc...
Definition: WellProdIndexCalculator.hpp:36
Static data associated with a well perforation.
Definition: BlackoilWellModelRestart.hpp:41
void recoverWellSolutionAndUpdateWellState(const Simulator &simulator, const BVector &x, const GroupStateHelperType &groupStateHelper, WellStateType &well_state) override
using the solution x to recover the solution xw for wells and applying xw to update Well State ...
Definition: MultisegmentWell_impl.hpp:262
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
Represents the convergence status of the whole simulator, to make it possible to query and store the ...
Definition: ConvergenceReport.hpp:37
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition: TemperatureModel.hpp:65
Definition: MultisegmentWell.hpp:39