101 using Grid = GetPropType<TypeTag, Properties::Grid>;
102 using EquilGrid = GetPropType<TypeTag, Properties::EquilGrid>;
103 using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
104 using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
105 using Indices = GetPropType<TypeTag, Properties::Indices>;
106 using Simulator = GetPropType<TypeTag, Properties::Simulator>;
107 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
108 using RateVector = GetPropType<TypeTag, Properties::RateVector>;
109 using GlobalEqVector = GetPropType<TypeTag, Properties::GlobalEqVector>;
110 using SparseMatrixAdapter = GetPropType<TypeTag, Properties::SparseMatrixAdapter>;
112 using GLiftOptWells =
typename BlackoilWellModelGeneric::GLiftOptWells;
113 using GLiftProdWells =
typename BlackoilWellModelGeneric::GLiftProdWells;
114 using GLiftWellStateMap =
115 typename BlackoilWellModelGeneric::GLiftWellStateMap;
116 using GLiftEclWells =
typename GasLiftGroupInfo::GLiftEclWells;
117 using GLiftSyncGroups =
typename GasLiftSingleWellGeneric::GLiftSyncGroups;
118 constexpr static std::size_t pressureVarIndex = GetPropType<TypeTag, Properties::Indices>::pressureSwitchIdx;
119 typedef typename BaseAuxiliaryModule<TypeTag>::NeighborSet NeighborSet;
121 static const int numEq = Indices::numEq;
122 static const int solventSaturationIdx = Indices::solventSaturationIdx;
123 static constexpr bool has_solvent_ = getPropValue<TypeTag, Properties::EnableSolvent>();
124 static constexpr bool has_polymer_ = getPropValue<TypeTag, Properties::EnablePolymer>();
125 static constexpr bool has_energy_ = getPropValue<TypeTag, Properties::EnableEnergy>();
126 static constexpr bool has_micp_ = getPropValue<TypeTag, Properties::EnableMICP>();
130 typedef Dune::FieldVector<Scalar, numEq > VectorBlockType;
131 typedef Dune::BlockVector<VectorBlockType> BVector;
133 typedef BlackOilPolymerModule<TypeTag> PolymerModule;
134 typedef BlackOilMICPModule<TypeTag> MICPModule;
138 SurfaceToReservoirVoidage<FluidSystem, std::vector<int> >;
142 AverageRegionalPressure<FluidSystem, std::vector<int> >;
149 void initWellContainer(
const int reportStepIdx)
override;
154 unsigned numDofs()
const override
158 void addNeighbors(std::vector<NeighborSet>& neighbors)
const override;
160 void applyInitial()
override
163 void linearize(SparseMatrixAdapter& jacobian, GlobalEqVector& res)
override;
164 void linearizeDomain(
const Domain& domain, SparseMatrixAdapter& jacobian, GlobalEqVector& res);
166 void postSolve(GlobalEqVector& deltaX)
override
168 recoverWellSolutionAndUpdateWellState(deltaX);
171 void postSolveDomain(GlobalEqVector& deltaX,
const Domain& domain)
173 recoverWellSolutionAndUpdateWellStateDomain(deltaX, domain);
180 template <
class Restarter>
181 void deserialize(Restarter& )
190 template <
class Restarter>
198 OPM_TIMEBLOCK(beginEpsiode);
199 beginReportStep(simulator_.episodeIndex());
202 void beginTimeStep();
204 void beginIteration()
206 OPM_TIMEBLOCK(beginIteration);
207 assemble(simulator_.model().newtonMethod().numIterations(),
208 simulator_.timeStepSize());
216 OPM_TIMEBLOCK(endTimeStep);
217 timeStepSucceeded(simulator_.time(), simulator_.timeStepSize());
225 void computeTotalRatesForDof(RateVector& rate,
226 unsigned globalIdx)
const;
228 template <
class Context>
229 void computeTotalRatesForDof(RateVector& rate,
230 const Context& context,
232 unsigned timeIdx)
const;
235 using WellInterfacePtr = std::shared_ptr<WellInterface<TypeTag> >;
237 using BlackoilWellModelGeneric::initFromRestartFile;
238 void initFromRestartFile(
const RestartValue& restartValues)
240 initFromRestartFile(restartValues,
241 this->simulator_.vanguard().transferWTestState(),
243 param_.use_multisegment_well_);
246 using BlackoilWellModelGeneric::prepareDeserialize;
247 void prepareDeserialize(
const int report_step)
249 prepareDeserialize(report_step, grid().size(0),
250 param_.use_multisegment_well_);
253 data::Wells wellData()
const
255 auto wsrpt = this->wellState()
256 .report(simulator_.vanguard().globalCell().data(),
257 [
this](
const int well_index) ->
bool
259 return this->wasDynamicallyShutThisTimeStep(well_index);
262 const auto& tracerRates = simulator_.problem().tracerModel().getWellTracerRates();
263 this->assignWellTracerRates(wsrpt, tracerRates);
266 BlackoilWellModelGuideRates(*this).assignWellGuideRates(wsrpt, this->reportStepIndex());
267 this->assignShutConnections(wsrpt, this->reportStepIndex());
272 data::WellBlockAveragePressures wellBlockAveragePressures()
const
274 return this->computeWellBlockAveragePressures();
278 void apply( BVector& r)
const;
281 void apply(
const BVector& x, BVector& Ax)
const;
284 void getWellContributions(WellContributions& x)
const;
287 void applyScaleAdd(
const Scalar alpha,
const BVector& x, BVector& Ax)
const;
290 ConvergenceReport getWellConvergence(
const std::vector<Scalar>& B_avg,
const bool checkWellGroupControls =
false)
const;
293 ConvergenceReport getDomainWellConvergence(
const Domain& domain,
294 const std::vector<Scalar>& B_avg,
295 DeferredLogger& local_deferredLogger)
const;
297 const SimulatorReportSingle& lastReport()
const;
299 void addWellContributions(SparseMatrixAdapter& jacobian)
const;
302 void addReservoirSourceTerms(GlobalEqVector& residual,
303 std::vector<typename SparseMatrixAdapter::MatrixBlock*>& diagMatAddress)
const;
306 void beginReportStep(
const int time_step);
316 void prepareTimeStep(DeferredLogger& deferred_logger);
317 void initPrimaryVariablesEvaluation()
const;
318 void initPrimaryVariablesEvaluationDomain(
const Domain& domain)
const;
320 std::pair<bool, bool>
321 updateWellControls(
const bool mandatory_network_balance, DeferredLogger& deferred_logger,
const bool relax_network_tolerance =
false);
323 void updateAndCommunicate(
const int reportStepIdx,
324 const int iterationIdx,
325 DeferredLogger& deferred_logger);
327 bool updateGroupControls(
const Group& group,
328 DeferredLogger& deferred_logger,
329 const int reportStepIdx,
330 const int iterationIdx);
332 WellInterfacePtr getWell(
const std::string& well_name)
const;
333 bool hasWell(
const std::string& well_name)
const;
335 using PressureMatrix = Dune::BCRSMatrix<Opm::MatrixBlock<double, 1, 1>>;
337 void addWellPressureEquations(PressureMatrix& jacobian,
const BVector& weights,
const bool use_well_weights)
const;
339 void addWellPressureEquationsStruct(PressureMatrix& jacobian)
const;
341 void initGliftEclWellMap(GLiftEclWells &ecl_well_map);
346 return well_container_;
351 void assembleDomain(
const int iterationIdx,
353 const Domain& domain);
354 void updateWellControlsDomain(
DeferredLogger& deferred_logger,
const Domain& domain);
356 void logPrimaryVars()
const;
357 std::vector<double> getPrimaryVarsDomain(
const Domain& domain)
const;
358 void setPrimaryVarsDomain(
const Domain& domain,
const std::vector<double>& vars);
360 void setupDomains(
const std::vector<Domain>& domains);
363 Simulator& simulator_;
366 std::vector<WellInterfacePtr> well_container_{};
368 std::vector<bool> is_cell_perforated_{};
370 void initializeWellState(
const int timeStepIdx);
373 void createWellContainer(
const int report_step)
override;
376 createWellPointer(
const int wellID,
377 const int report_step)
const;
379 template <
typename WellType>
380 std::unique_ptr<WellType>
381 createTypedWellPointer(
const int wellID,
382 const int time_step)
const;
384 WellInterfacePtr createWellForWellTest(
const std::string& well_name,
const int report_step, DeferredLogger& deferred_logger)
const;
387 const ModelParameters param_;
388 std::size_t global_num_cells_{};
390 std::size_t local_num_cells_{};
392 std::vector<double> depth_{};
393 bool alternative_well_rate_init_{};
395 std::unique_ptr<RateConverterType> rateConverter_{};
396 std::map<std::string, std::unique_ptr<AverageRegionalPressureType>> regionalAveragePressureCalculator_{};
400 std::optional<typename std::vector<WellInterfacePtr>::size_type> openWellIdx_{};
401 std::size_t wbpCalcIdx_{};
404 std::vector<WBPCalcID> wbpCalcMap_{};
409 void doPreStepNetworkRebalance(DeferredLogger& deferred_logger);
412 mutable BVector scaleAddRes_{};
414 std::vector<Scalar> B_avg_{};
417 std::map<std::string, int> well_domain_;
419 const Grid& grid()
const
420 {
return simulator_.vanguard().grid(); }
422 const EquilGrid& equilGrid()
const
423 {
return simulator_.vanguard().equilGrid(); }
425 const EclipseState& eclState()
const
426 {
return simulator_.vanguard().eclState(); }
430 void assemble(
const int iterationIdx,
437 std::pair<bool, bool> updateWellControlsAndNetworkIteration(
const bool mandatory_network_balance,
438 const bool relax_network_tolerance,
440 DeferredLogger& local_deferredLogger);
442 bool updateWellControlsAndNetwork(
const bool mandatory_network_balance,
444 DeferredLogger& local_deferredLogger);
455 const bool enableWellPIScaling);
463 void timeStepSucceeded(
const double simulationTime,
const double dt);
466 void endReportStep();
470 void recoverWellSolutionAndUpdateWellState(
const BVector& x);
474 void recoverWellSolutionAndUpdateWellStateDomain(
const BVector& x,
const Domain& domain);
477 void updatePrimaryVariables(DeferredLogger& deferred_logger);
479 void initializeWBPCalculationService();
481 data::WellBlockAveragePressures
482 computeWellBlockAveragePressures()
const;
485 makeWellSourceEvaluatorFactory(
const std::vector<Well>::size_type wellIdx)
const;
487 void registerOpenWellsForWBPCalculation();
489 void updateAverageFormationFactor();
491 void computePotentials(
const std::size_t widx,
492 const WellState& well_state_copy,
493 std::string& exc_msg,
494 ExceptionType::ExcEnum& exc_type,
495 DeferredLogger& deferred_logger)
override;
497 const std::vector<double>& wellPerfEfficiencyFactors()
const;
499 void calculateProductivityIndexValuesShutWells(
const int reportStepIdx, DeferredLogger& deferred_logger)
override;
500 void calculateProductivityIndexValues(DeferredLogger& deferred_logger)
override;
501 void calculateProductivityIndexValues(
const WellInterface<TypeTag>* wellPtr,
502 DeferredLogger& deferred_logger);
505 int numComponents()
const;
507 int reportStepIndex()
const;
509 void assembleWellEq(
const double dt, DeferredLogger& deferred_logger);
510 void assembleWellEqDomain(
const double dt,
const Domain& domain, DeferredLogger& deferred_logger);
512 void prepareWellsBeforeAssembling(
const double dt, DeferredLogger& deferred_logger);
515 void assembleWellEqWithoutIteration(
const double dt, DeferredLogger& deferred_logger);
517 bool maybeDoGasLiftOptimize(DeferredLogger& deferred_logger);
519 void gasLiftOptimizationStage1(DeferredLogger& deferred_logger,
520 GLiftProdWells &prod_wells, GLiftOptWells &glift_wells,
521 GasLiftGroupInfo &group_info, GLiftWellStateMap &state_map);
524 void gasLiftOptimizationStage1SingleWell(WellInterface<TypeTag> *well,
525 DeferredLogger& deferred_logger,
526 GLiftProdWells &prod_wells, GLiftOptWells &glift_wells,
527 GasLiftGroupInfo &group_info, GLiftWellStateMap &state_map,
528 GLiftSyncGroups& groups_to_sync);
530 void extractLegacyCellPvtRegionIndex_();
532 void extractLegacyDepth_();
535 void updateWellTestState(
const double& simulationTime, WellTestState& wellTestState)
const;
537 void wellTesting(
const int timeStepIdx,
const double simulationTime, DeferredLogger& deferred_logger);
539 void calcRates(
const int fipnum,
541 const std::vector<double>& production_rates,
542 std::vector<double>& resv_coeff)
override;
544 void calcInjRates(
const int fipnum,
546 std::vector<double>& resv_coeff)
override;
548 void computeWellTemperature();
551 return simulator_.vanguard().compressedIndexForInterior(cartesian_cell_idx);