99 class BlackoilWellModel :
public WellConnectionAuxiliaryModule<TypeTag, BlackoilWellModel<TypeTag>>
100 ,
public BlackoilWellModelGeneric<GetPropType<TypeTag, Properties::Scalar>,
101 typename GetPropType<TypeTag, Properties::FluidSystem>::IndexTraitsType>
117 using WellConnectionModule = WellConnectionAuxiliaryModule<TypeTag, BlackoilWellModel<TypeTag>>;
119 using IndexTraits =
typename FluidSystem::IndexTraitsType;
123 static const int numEq = Indices::numEq;
124 static const int solventSaturationIdx = Indices::solventSaturationIdx;
128 static constexpr bool has_micp_ = Indices::enableMICP;
132 using VectorBlockType = Dune::FieldVector<Scalar, numEq>;
133 using BVector = Dune::BlockVector<VectorBlockType>;
139 using RateConverterType = RateConverter::
140 SurfaceToReservoirVoidage<FluidSystem, std::vector<int> >;
143 using AverageRegionalPressureType = RegionAverageCalculator::
144 AverageRegionalPressure<FluidSystem, std::vector<int> >;
148 explicit BlackoilWellModel(Simulator& simulator);
151 void initWellContainer(
const int reportStepIdx)
override;
155 OPM_TIMEBLOCK(beginEpsiode);
156 beginReportStep(simulator_.episodeIndex());
159 void beginTimeStep();
161 void beginIteration()
163 OPM_TIMEBLOCK(beginIteration);
164 assemble(simulator_.model().newtonMethod().numIterations(),
165 simulator_.timeStepSize());
173 OPM_TIMEBLOCK(endTimeStep);
174 timeStepSucceeded(simulator_.time(), simulator_.timeStepSize());
182 void computeTotalRatesForDof(RateVector& rate,
183 unsigned globalIdx)
const;
185 template <
class Context>
186 void computeTotalRatesForDof(RateVector& rate,
187 const Context& context,
189 unsigned timeIdx)
const;
192 using WellInterfacePtr = std::shared_ptr<WellInterface<TypeTag> >;
194 using BlackoilWellModelGeneric<Scalar, IndexTraits>::initFromRestartFile;
195 void initFromRestartFile(
const RestartValue& restartValues)
197 initFromRestartFile(restartValues,
198 this->simulator_.vanguard().transferWTestState(),
200 param_.use_multisegment_well_,
201 this->simulator_.vanguard().enableDistributedWells());
204 using BlackoilWellModelGeneric<Scalar, IndexTraits>::prepareDeserialize;
205 void prepareDeserialize(
const int report_step)
207 prepareDeserialize(report_step, grid().size(0),
208 param_.use_multisegment_well_,
209 this->simulator_.vanguard().enableDistributedWells());
212 data::Wells wellData()
const
214 auto wsrpt = this->wellState()
215 .report(this->simulator_.vanguard().globalCell().data(),
216 [
this](
const int well_index)
218 return this->wasDynamicallyShutThisTimeStep(well_index);
224 this->assignWellTracerRates(wsrpt);
226 if (
const auto& rspec = eclState().runspec();
227 rspec.co2Storage() || rspec.h2Storage())
233 this->assignMassGasRate(wsrpt, FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, 0));
236 this->assignWellTargets(wsrpt);
247 data::WellBlockAveragePressures wellBlockAveragePressures()
const
249 return this->wbp_.computeWellBlockAveragePressures(this->gravity_);
252#if COMPILE_GPU_BRIDGE
258 ConvergenceReport getWellConvergence(
const std::vector<Scalar>& B_avg,
const bool checkWellGroupControlsAndNetwork =
false)
const;
262 void addWellContributions(SparseMatrixAdapter& jacobian)
const;
265 void addReservoirSourceTerms(GlobalEqVector& residual,
266 const std::vector<typename SparseMatrixAdapter::MatrixBlock*>& diagMatAddress)
const;
269 void beginReportStep(
const int time_step);
284 std::tuple<bool, Scalar>
285 updateNetworks(
const bool mandatory_network_balance,
DeferredLogger& deferred_logger,
const bool relax_network_tolerance =
false);
288 void updateAndCommunicate(
const int reportStepIdx,
289 const int iterationIdx,
292 bool updateGroupControls(
const Group& group,
294 const int reportStepIdx,
295 const int iterationIdx);
297 WellInterfacePtr getWell(
const std::string& well_name)
const;
299 using PressureMatrix = Dune::BCRSMatrix<Opm::MatrixBlock<Scalar, 1, 1>>;
301 void addWellPressureEquations(PressureMatrix& jacobian,
302 const BVector& weights,
303 const bool use_well_weights)
const;
304 void addWellPressureEquationsStruct(PressureMatrix& jacobian)
const;
305 void addWellPressureEquationsDomain(PressureMatrix& jacobian,
306 const BVector& weights,
307 const bool use_well_weights,
308 const int domainIndex)
const
311 OPM_THROW(std::logic_error,
"Attempt to access NLDD data without a NLDD solver");
313 return nldd_->addWellPressureEquations(jacobian,
322 return well_container_;
328 OPM_THROW(std::logic_error,
"Attempt to access NLDD data without a NLDD solver");
330 return nldd_->well_local_cells();
333 const std::map<std::string, int>& well_domain()
const
336 OPM_THROW(std::logic_error,
"Attempt to access NLDD data without a NLDD solver");
339 return nldd_->well_domain();
342 auto begin()
const {
return well_container_.begin(); }
343 auto end()
const {
return well_container_.end(); }
344 bool empty()
const {
return well_container_.empty(); }
346 bool addMatrixContributions()
const
347 {
return param_.matrix_add_well_contributions_; }
349 int numStrictIterations()
const
350 {
return param_.strict_outer_iter_wells_; }
354 return simulator_.vanguard().compressedIndexForInterior(cartesian_cell_idx);
357 int compressedIndexForInteriorLGR(
const std::string& lgr_tag,
const Connection& conn)
const override
359 return simulator_.vanguard().compressedIndexForInteriorLGR(lgr_tag, conn);
364 void recoverWellSolutionAndUpdateWellState(
const BVector& x);
368 void recoverWellSolutionAndUpdateWellStateDomain(
const BVector& x,
369 const int domainIdx);
371 const Grid& grid()
const
372 {
return simulator_.vanguard().grid(); }
374 const Simulator& simulator()
const
375 {
return simulator_; }
377 void setNlddAdapter(BlackoilWellModelNldd<TypeTag>* mod)
380#ifdef RESERVOIR_COUPLING_ENABLED
381 ReservoirCouplingMaster& reservoirCouplingMaster() {
382 return *(this->simulator_.reservoirCouplingMaster());
384 ReservoirCouplingSlave& reservoirCouplingSlave() {
385 return *(this->simulator_.reservoirCouplingSlave());
387 bool isReservoirCouplingMaster()
const {
388 return this->simulator_.reservoirCouplingMaster() !=
nullptr;
390 bool isReservoirCouplingSlave()
const {
391 return this->simulator_.reservoirCouplingSlave() !=
nullptr;
393 void setReservoirCouplingMaster(ReservoirCouplingMaster *master)
395 this->guide_rate_handler_.setReservoirCouplingMaster(master);
397 void setReservoirCouplingSlave(ReservoirCouplingSlave *slave)
399 this->guide_rate_handler_.setReservoirCouplingSlave(slave);
403 Simulator& simulator_;
406 std::vector<WellInterfacePtr> well_container_{};
408 std::vector<bool> is_cell_perforated_{};
410 void initializeWellState(
const int timeStepIdx);
413 void createWellContainer(
const int report_step)
override;
416 createWellPointer(
const int wellID,
417 const int report_step)
const;
419 template <
typename WellType>
420 std::unique_ptr<WellType>
421 createTypedWellPointer(
const int wellID,
422 const int time_step)
const;
424 WellInterfacePtr createWellForWellTest(
const std::string& well_name,
425 const int report_step,
426 DeferredLogger& deferred_logger)
const;
428 const ModelParameters param_;
429 std::size_t global_num_cells_{};
431 std::size_t local_num_cells_{};
433 std::vector<Scalar> depth_{};
434 bool alternative_well_rate_init_{};
435 std::map<std::string, Scalar> well_group_thp_calc_;
436 std::unique_ptr<RateConverterType> rateConverter_{};
437 std::map<std::string, std::unique_ptr<AverageRegionalPressureType>> regionalAveragePressureCalculator_{};
439 SimulatorReportSingle last_report_{};
440 GuideRateHandler<Scalar, IndexTraits> guide_rate_handler_{};
443 bool network_needs_more_balancing_force_another_newton_iteration_{
false};
446 void doPreStepNetworkRebalance(DeferredLogger& deferred_logger);
448 std::vector<Scalar> B_avg_{};
450 const EquilGrid& equilGrid()
const
451 {
return simulator_.vanguard().equilGrid(); }
453 const EclipseState& eclState()
const
454 {
return simulator_.vanguard().eclState(); }
458 void assemble(
const int iterationIdx,
465 std::tuple<bool, bool, Scalar> updateWellControlsAndNetworkIteration(
const bool mandatory_network_balance,
466 const bool relax_network_tolerance,
467 const bool optimize_gas_lift,
469 DeferredLogger& local_deferredLogger);
471 bool updateWellControlsAndNetwork(
const bool mandatory_network_balance,
473 DeferredLogger& local_deferredLogger);
475 bool computeWellGroupThp(
const double dt, DeferredLogger& local_deferredLogger);
486 const bool enableWellPIScaling);
494 void timeStepSucceeded(
const double simulationTime,
const double dt);
497 void endReportStep();
500 void updatePrimaryVariables(DeferredLogger& deferred_logger);
502 void updateAverageFormationFactor();
504 void computePotentials(
const std::size_t widx,
505 const WellState<Scalar, IndexTraits>& well_state_copy,
506 std::string& exc_msg,
507 ExceptionType::ExcEnum& exc_type,
508 DeferredLogger& deferred_logger)
override;
510 const std::vector<Scalar>& wellPerfEfficiencyFactors()
const;
512 void calculateProductivityIndexValuesShutWells(
const int reportStepIdx, DeferredLogger& deferred_logger)
override;
513 void calculateProductivityIndexValues(DeferredLogger& deferred_logger)
override;
514 void calculateProductivityIndexValues(
const WellInterface<TypeTag>* wellPtr,
515 DeferredLogger& deferred_logger);
518 int numConservationQuantities()
const;
520 int reportStepIndex()
const;
522 void assembleWellEq(
const double dt, DeferredLogger& deferred_logger);
524 void prepareWellsBeforeAssembling(
const double dt, DeferredLogger& deferred_logger);
527 void assembleWellEqWithoutIteration(
const double dt, DeferredLogger& deferred_logger);
529 void extractLegacyCellPvtRegionIndex_();
531 void extractLegacyDepth_();
536 void wellTesting(
const int timeStepIdx,
const double simulationTime, DeferredLogger& deferred_logger);
538 void calcResvCoeff(
const int fipnum,
540 const std::vector<Scalar>& production_rates,
541 std::vector<Scalar>& resv_coeff)
override;
543 void calcInjResvCoeff(
const int fipnum,
545 std::vector<Scalar>& resv_coeff)
override;
547 void computeWellTemperature();
550 BlackoilWellModelGasLift<TypeTag> gaslift_;
551 BlackoilWellModelNldd<TypeTag>* nldd_ =
nullptr;
557 mutable BVector x_local_;
559 void assignWellTracerRates(data::Wells& wsrpt)
const;