MultisegmentWell.hpp
Go to the documentation of this file.
1/*
2 Copyright 2017 SINTEF Digital, Mathematics and Cybernetics.
3 Copyright 2017 Statoil ASA.
4
5 This file is part of the Open Porous Media project (OPM).
6
7 OPM is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 OPM is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with OPM. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21
22#ifndef OPM_MULTISEGMENTWELL_HEADER_INCLUDED
23#define OPM_MULTISEGMENTWELL_HEADER_INCLUDED
24
26
29
30namespace Opm {
31
32 class DeferredLogger;
33
34 template<typename TypeTag>
35 class MultisegmentWell : public WellInterface<TypeTag>
36 , public MultisegmentWellEval<GetPropType<TypeTag, Properties::FluidSystem>,
37 GetPropType<TypeTag, Properties::Indices>>
38 {
39 public:
43
44 using typename Base::Simulator;
45 using typename Base::IntensiveQuantities;
46 using typename Base::FluidSystem;
47 using typename Base::IndexTraits;
48 using typename Base::ModelParameters;
49 using typename Base::MaterialLaw;
50 using typename Base::Indices;
51 using typename Base::RateConverterType;
52 using typename Base::SparseMatrixAdapter;
53 using typename Base::FluidState;
54 using typename Base::WellStateType;
55
58 using Base::Water;
59 using Base::Oil;
60 using Base::Gas;
61
62 using typename Base::Scalar;
63
65 using typename Base::BVector;
66 using typename Base::Eval;
67
68 using typename MSWEval::Equations;
69 using typename MSWEval::EvalWell;
70 using typename MSWEval::BVectorWell;
71 using MSWEval::SPres;
72 using typename Base::PressureMatrix;
73 using FSInfo = std::tuple<Scalar,typename std::decay<decltype(std::declval<decltype(std::declval<const Simulator&>().model().intensiveQuantities(0, 0).fluidState())>().saltConcentration())>::type,int>;
74
75 MultisegmentWell(const Well& well,
76 const ParallelWellInfo<Scalar>& pw_info,
77 const int time_step,
78 const ModelParameters& param,
79 const RateConverterType& rate_converter,
80 const int pvtRegionIdx,
81 const int num_conservation_quantities,
82 const int num_phases,
83 const int index_of_well,
84 const std::vector<PerforationData<Scalar>>& perf_data);
85
86 void init(const std::vector<Scalar>& depth_arg,
87 const Scalar gravity_arg,
88 const std::vector<Scalar>& B_avg,
89 const bool changed_to_open_this_step) override;
90
92 void updateWellStateWithTarget(const Simulator& simulator,
93 const GroupState<Scalar>& group_state,
94 WellStateType& well_state,
95 DeferredLogger& deferred_logger) const override;
96
99 const WellStateType& well_state,
100 const std::vector<Scalar>& B_avg,
101 DeferredLogger& deferred_logger,
102 const bool relax_tolerance) const override;
103
105 void apply(const BVector& x, BVector& Ax) const override;
107 void apply(BVector& r) const override;
108
112 const BVector& x,
113 WellStateType& well_state,
114 DeferredLogger& deferred_logger) override;
115
117 void computeWellPotentials(const Simulator& simulator,
118 const WellStateType& well_state,
119 std::vector<Scalar>& well_potentials,
120 DeferredLogger& deferred_logger) override;
121
122 void updatePrimaryVariables(const Simulator& simulator,
123 const WellStateType& well_state,
124 DeferredLogger& deferred_logger) override;
125
126 void solveEqAndUpdateWellState(const Simulator& simulator,
127 WellStateType& well_state,
128 DeferredLogger& deferred_logger) override; // const?
129
130 void calculateExplicitQuantities(const Simulator& simulator,
131 const WellStateType& well_state,
132 DeferredLogger& deferred_logger) override; // should be const?
133
134 void updateIPRImplicit(const Simulator& simulator,
135 WellStateType& well_state,
136 DeferredLogger& deferred_logger) override;
137
138 void updateProductivityIndex(const Simulator& simulator,
139 const WellProdIndexCalculator<Scalar>& wellPICalc,
140 WellStateType& well_state,
141 DeferredLogger& deferred_logger) const override;
142
143 Scalar connectionDensity(const int globalConnIdx,
144 const int openConnIdx) const override;
145
146 void addWellContributions(SparseMatrixAdapter& jacobian) const override;
147
149 const BVector& x,
150 const int pressureVarIndex,
151 const bool use_well_weights,
152 const WellStateType& well_state) const override;
153
154 std::vector<Scalar>
155 computeCurrentWellRates(const Simulator& simulator,
156 DeferredLogger& deferred_logger) const override;
157
158 std::optional<Scalar>
160 const SummaryState& summary_state,
161 const Scalar alq_value,
162 DeferredLogger& deferred_logger,
163 bool iterate_if_no_solution) const override;
164
165 std::vector<Scalar> getPrimaryVars() const override;
166
167 int setPrimaryVars(typename std::vector<Scalar>::const_iterator it) override;
168
169 protected:
170 // regularize msw equation
172
173 // the intial amount of fluids in each segment under surface condition
174 std::vector<std::vector<Scalar> > segment_fluid_initial_;
175
176 mutable int debug_cost_counter_ = 0;
177
178 // updating the well_state based on well solution dwells
179 void updateWellState(const Simulator& simulator,
180 const BVectorWell& dwells,
181 WellStateType& well_state,
182 DeferredLogger& deferred_logger,
183 const Scalar relaxation_factor = 1.0);
184
185 // computing the accumulation term for later use in well mass equations
186 void computeInitialSegmentFluids(const Simulator& simulator);
187
188 // compute the pressure difference between the perforation and cell center
189 void computePerfCellPressDiffs(const Simulator& simulator);
190
191 template<class Value>
192 void computePerfRate(const IntensiveQuantities& int_quants,
193 const std::vector<Value>& mob_perfcells,
194 const std::vector<Scalar>& Tw,
195 const int seg,
196 const int perf,
197 const Value& segment_pressure,
198 const bool& allow_cf,
199 std::vector<Value>& cq_s,
200 Value& perf_press,
201 PerforationRates<Scalar>& perf_rates,
202 DeferredLogger& deferred_logger) const;
203
204 template<class Value>
205 void computePerfRate(const Value& pressure_cell,
206 const Value& rs,
207 const Value& rv,
208 const std::vector<Value>& b_perfcells,
209 const std::vector<Value>& mob_perfcells,
210 const std::vector<Scalar>& Tw,
211 const int perf,
212 const Value& segment_pressure,
213 const Value& segment_density,
214 const bool& allow_cf,
215 const std::vector<Value>& cmix_s,
216 std::vector<Value>& cq_s,
217 Value& perf_press,
218 PerforationRates<Scalar>& perf_rates,
219 DeferredLogger& deferred_logger) const;
220
221 // compute the fluid properties, such as densities, viscosities, and so on, in the segments
222 // They will be treated implicitly, so they need to be of Evaluation type
223 void computeSegmentFluidProperties(const Simulator& simulator,
224 DeferredLogger& deferred_logger);
225
226 // get the mobility for specific perforation
227 template<class Value>
228 void getMobility(const Simulator& simulator,
229 const int local_perf_index,
230 std::vector<Value>& mob,
231 DeferredLogger& deferred_logger) const;
232
233 void computeWellRatesAtBhpLimit(const Simulator& simulator,
234 std::vector<Scalar>& well_flux,
235 DeferredLogger& deferred_logger) const;
236
237 void computeWellRatesWithBhp(const Simulator& simulator,
238 const Scalar& bhp,
239 std::vector<Scalar>& well_flux,
240 DeferredLogger& deferred_logger) const override;
241
242 void computeWellRatesWithBhpIterations(const Simulator& simulator,
243 const Scalar& bhp,
244 std::vector<Scalar>& well_flux,
245 DeferredLogger& deferred_logger) const override;
246
247 std::vector<Scalar>
249 const Simulator& simulator,
250 DeferredLogger& deferred_logger) const;
251
252 bool computeWellPotentialsImplicit(const Simulator& simulator,
253 const WellStateType& well_state,
254 std::vector<Scalar>& well_potentials,
255 DeferredLogger& deferred_logger) const;
256
257 Scalar getRefDensity() const override;
258
259 bool iterateWellEqWithControl(const Simulator& simulator,
260 const double dt,
261 const Well::InjectionControls& inj_controls,
262 const Well::ProductionControls& prod_controls,
263 WellStateType& well_state,
264 const GroupState<Scalar>& group_state,
265 DeferredLogger& deferred_logger) override;
266
267 bool iterateWellEqWithSwitching(const Simulator& simulator,
268 const double dt,
269 const Well::InjectionControls& inj_controls,
270 const Well::ProductionControls& prod_controls,
271 WellStateType& well_state,
272 const GroupState<Scalar>& group_state,
273 DeferredLogger& deferred_logger,
274 const bool fixed_control = false,
275 const bool fixed_status = false) override;
276
277 void assembleWellEqWithoutIteration(const Simulator& simulator,
278 const double dt,
279 const Well::InjectionControls& inj_controls,
280 const Well::ProductionControls& prod_controls,
281 WellStateType& well_state,
282 const GroupState<Scalar>& group_state,
283 DeferredLogger& deferred_logger) override;
284
285 void updateWaterThroughput(const double dt, WellStateType& well_state) const override;
286
287 EvalWell getSegmentSurfaceVolume(const Simulator& simulator, const int seg_idx) const;
288
289 // turn on crossflow to avoid singular well equations
290 // when the well is banned from cross-flow and the BHP is not properly initialized,
291 // we turn on crossflow to avoid singular well equations. It can result in wrong-signed
292 // well rates, it can cause problem for THP calculation
293 // TODO: looking for better alternative to avoid wrong-signed well rates
294 bool openCrossFlowAvoidSingularity(const Simulator& simulator) const;
295
296 // for a well, when all drawdown are in the wrong direction, then this well will not
297 // be able to produce/inject .
298 bool allDrawDownWrongDirection(const Simulator& simulator) const;
299
300 std::optional<Scalar>
301 computeBhpAtThpLimitProd(const WellStateType& well_state,
302 const Simulator& ebos_simulator,
303 const SummaryState& summary_state,
304 DeferredLogger& deferred_logger) const;
305
306 std::optional<Scalar>
307 computeBhpAtThpLimitInj(const Simulator& ebos_simulator,
308 const SummaryState& summary_state,
309 DeferredLogger& deferred_logger) const;
310
311 Scalar maxPerfPress(const Simulator& simulator) const;
312
313 // check whether the well is operable under BHP limit with current reservoir condition
314 void checkOperabilityUnderBHPLimit(const WellStateType& well_state,
315 const Simulator& ebos_simulator,
316 DeferredLogger& deferred_logger) override;
317
318 // check whether the well is operable under THP limit with current reservoir condition
319 void checkOperabilityUnderTHPLimit(const Simulator& ebos_simulator,
320 const WellStateType& well_state,
321 DeferredLogger& deferred_logger) override;
322
323 // updating the inflow based on the current reservoir condition
324 void updateIPR(const Simulator& ebos_simulator,
325 DeferredLogger& deferred_logger) const override;
326
327 FSInfo getFirstPerforationFluidStateInfo(const Simulator& simulator) const;
328 };
329
330}
331
333
334#endif // OPM_MULTISEGMENTWELL_HEADER_INCLUDED
Definition: ConvergenceReport.hpp:38
Definition: DeferredLogger.hpp:57
Definition: GroupState.hpp:41
Definition: MultisegmentWellEval.hpp:48
MultisegmentWellEquations< Scalar, IndexTraits, numWellEq, Indices::numEq > Equations
Definition: MultisegmentWellEval.hpp:57
Definition: MultisegmentWell.hpp:38
bool computeWellPotentialsImplicit(const Simulator &simulator, const WellStateType &well_state, std::vector< Scalar > &well_potentials, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:521
void updateWellState(const Simulator &simulator, const BVectorWell &dwells, WellStateType &well_state, DeferredLogger &deferred_logger, const Scalar relaxation_factor=1.0)
Definition: MultisegmentWell_impl.hpp:695
void updateWaterThroughput(const double dt, WellStateType &well_state) const override
Definition: MultisegmentWell_impl.hpp:2017
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:867
std::optional< Scalar > computeBhpAtThpLimitProdWithAlq(const Simulator &simulator, const SummaryState &summary_state, const Scalar alq_value, DeferredLogger &deferred_logger, bool iterate_if_no_solution) const override
Definition: MultisegmentWell_impl.hpp:2066
Scalar connectionDensity(const int globalConnIdx, const int openConnIdx) const override
Definition: MultisegmentWell_impl.hpp:832
void addWellContributions(SparseMatrixAdapter &jacobian) const override
Definition: MultisegmentWell_impl.hpp:854
bool iterateWellEqWithSwitching(const Simulator &simulator, const double dt, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, WellStateType &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger, const bool fixed_control=false, const bool fixed_status=false) override
Definition: MultisegmentWell_impl.hpp:1599
void solveEqAndUpdateWellState(const Simulator &simulator, WellStateType &well_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:591
Scalar getRefDensity() const override
Definition: MultisegmentWell_impl.hpp:1181
std::vector< Scalar > getPrimaryVars() const override
Definition: MultisegmentWell_impl.hpp:2248
void computeWellRatesWithBhpIterations(const Simulator &simulator, const Scalar &bhp, std::vector< Scalar > &well_flux, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:395
std::vector< Scalar > computeCurrentWellRates(const Simulator &simulator, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:2204
void apply(const BVector &x, BVector &Ax) const override
Ax = Ax - C D^-1 B x.
Definition: MultisegmentWell_impl.hpp:220
MultisegmentWell(const Well &well, const ParallelWellInfo< Scalar > &pw_info, const int time_step, const ModelParameters &param, 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:62
void checkOperabilityUnderBHPLimit(const WellStateType &well_state, const Simulator &ebos_simulator, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:1189
void getMobility(const Simulator &simulator, const int local_perf_index, std::vector< Value > &mob, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:1141
void computePerfRate(const IntensiveQuantities &int_quants, const std::vector< Value > &mob_perfcells, const std::vector< Scalar > &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:1036
void updateIPRImplicit(const Simulator &simulator, WellStateType &well_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:1354
std::optional< Scalar > computeBhpAtThpLimitProd(const WellStateType &well_state, const Simulator &ebos_simulator, const SummaryState &summary_state, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:2048
bool openCrossFlowAvoidSingularity(const Simulator &simulator) const
Definition: MultisegmentWell_impl.hpp:1955
void computeSegmentFluidProperties(const Simulator &simulator, DeferredLogger &deferred_logger)
Definition: MultisegmentWell_impl.hpp:1109
void checkOperabilityUnderTHPLimit(const Simulator &ebos_simulator, const WellStateType &well_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:1423
bool iterateWellEqWithControl(const Simulator &simulator, const double dt, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, WellStateType &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:1475
int setPrimaryVars(typename std::vector< Scalar >::const_iterator it) override
Definition: MultisegmentWell_impl.hpp:2266
void computeWellRatesWithBhp(const Simulator &simulator, const Scalar &bhp, std::vector< Scalar > &well_flux, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:348
EvalWell getSegmentSurfaceVolume(const Simulator &simulator, const int seg_idx) const
Definition: MultisegmentWell_impl.hpp:2028
bool allDrawDownWrongDirection(const Simulator &simulator) const
Definition: MultisegmentWell_impl.hpp:1964
int debug_cost_counter_
Definition: MultisegmentWell.hpp:176
ConvergenceReport getWellConvergence(const Simulator &simulator, const WellStateType &well_state, const std::vector< Scalar > &B_avg, DeferredLogger &deferred_logger, const bool relax_tolerance) const override
check whether the well equations get converged for this well
Definition: MultisegmentWell_impl.hpp:194
void updateProductivityIndex(const Simulator &simulator, const WellProdIndexCalculator< Scalar > &wellPICalc, WellStateType &well_state, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:750
void computePerfCellPressDiffs(const Simulator &simulator)
Definition: MultisegmentWell_impl.hpp:620
void computeWellPotentials(const Simulator &simulator, const WellStateType &well_state, std::vector< Scalar > &well_potentials, DeferredLogger &deferred_logger) override
computing the well potentials for group control
Definition: MultisegmentWell_impl.hpp:287
void recoverWellSolutionAndUpdateWellState(const Simulator &simulator, const BVector &x, WellStateType &well_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:255
void updateWellStateWithTarget(const Simulator &simulator, const GroupState< Scalar > &group_state, WellStateType &well_state, DeferredLogger &deferred_logger) const override
updating the well state based the current control mode
Definition: MultisegmentWell_impl.hpp:173
void updateIPR(const Simulator &ebos_simulator, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:1255
std::tuple< Scalar, typename std::decay< decltype(std::declval< decltype(std::declval< const Simulator & >().model().intensiveQuantities(0, 0).fluidState())>().saltConcentration())>::type, int > FSInfo
Definition: MultisegmentWell.hpp:73
FSInfo getFirstPerforationFluidStateInfo(const Simulator &simulator) const
Definition: MultisegmentWell_impl.hpp:2281
void computeWellRatesAtBhpLimit(const Simulator &simulator, std::vector< Scalar > &well_flux, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:332
void init(const std::vector< Scalar > &depth_arg, const Scalar gravity_arg, const std::vector< Scalar > &B_avg, const bool changed_to_open_this_step) override
Definition: MultisegmentWell_impl.hpp:122
void assembleWellEqWithoutIteration(const Simulator &simulator, const double dt, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, WellStateType &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:1774
bool regularize_
Definition: MultisegmentWell.hpp:171
Scalar maxPerfPress(const Simulator &simulator) const
Definition: MultisegmentWell_impl.hpp:2176
std::vector< std::vector< Scalar > > segment_fluid_initial_
Definition: MultisegmentWell.hpp:174
void updatePrimaryVariables(const Simulator &simulator, const WellStateType &well_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:157
std::optional< Scalar > computeBhpAtThpLimitInj(const Simulator &ebos_simulator, const SummaryState &summary_state, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:2122
void calculateExplicitQuantities(const Simulator &simulator, const WellStateType &well_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:734
std::vector< Scalar > computeWellPotentialWithTHP(const WellStateType &well_state, const Simulator &simulator, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:470
void computeInitialSegmentFluids(const Simulator &simulator)
Definition: MultisegmentWell_impl.hpp:677
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:198
static constexpr int Oil
Definition: WellInterfaceFluidSystem.hpp:62
static constexpr int Water
Definition: WellInterfaceFluidSystem.hpp:61
static constexpr int Gas
Definition: WellInterfaceFluidSystem.hpp:63
int pvtRegionIdx() const
Definition: WellInterfaceGeneric.hpp:127
Definition: WellInterface.hpp:76
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: WellInterface.hpp:81
typename WellInterfaceFluidSystem< FluidSystem >::RateConverterType RateConverterType
Definition: WellInterface.hpp:103
BlackOilFluidState< Eval, FluidSystem, has_temperature, has_energy, Indices::compositionSwitchIdx >=0, has_watVapor, has_brine, has_saltPrecip, has_disgas_in_water, Indices::numPhases > FluidState
Definition: WellInterface.hpp:135
Dune::BCRSMatrix< Opm::MatrixBlock< Scalar, 1, 1 > > PressureMatrix
Definition: WellInterface.hpp:97
GetPropType< TypeTag, Properties::IntensiveQuantities > IntensiveQuantities
Definition: WellInterface.hpp:86
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: WellInterface.hpp:82
GetPropType< TypeTag, Properties::MaterialLaw > MaterialLaw
Definition: WellInterface.hpp:87
typename FluidSystem::IndexTraitsType IndexTraits
Definition: WellInterface.hpp:84
Dune::BlockVector< VectorBlockType > BVector
Definition: WellInterface.hpp:96
static constexpr bool has_polymer
Definition: WellInterface.hpp:113
typename Base::ModelParameters ModelParameters
Definition: WellInterface.hpp:109
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: WellInterface.hpp:83
static constexpr bool has_solvent
Definition: WellInterface.hpp:111
typename Base::Eval Eval
Definition: WellInterface.hpp:95
WellState< Scalar, IndexTraits > WellStateType
Definition: WellInterface.hpp:99
GetPropType< TypeTag, Properties::Indices > Indices
Definition: WellInterface.hpp:85
GetPropType< TypeTag, Properties::SparseMatrixAdapter > SparseMatrixAdapter
Definition: WellInterface.hpp:88
Definition: WellProdIndexCalculator.hpp:37
Definition: WellState.hpp:66
Defines the common properties required by the porous medium multi-phase models.
Definition: blackoilboundaryratevector.hh:39
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
Static data associated with a well perforation.
Definition: PerforationData.hpp:30
Definition: PerforationData.hpp:41