24#ifndef OPM_BLACKOILWELLMODEL_HEADER_INCLUDED
25#define OPM_BLACKOILWELLMODEL_HEADER_INCLUDED
27#include <opm/common/OpmLog/OpmLog.hpp>
36#include <opm/grid/utility/SparseTable.hpp>
38#include <opm/input/eclipse/Schedule/Group/Group.hpp>
39#include <opm/input/eclipse/Schedule/Group/GuideRate.hpp>
40#include <opm/input/eclipse/Schedule/Schedule.hpp>
41#include <opm/input/eclipse/Schedule/Well/WellTestState.hpp>
45#include <opm/simulators/flow/countGlobalCells.hpp>
47#include <opm/simulators/flow/SubDomain.hpp>
49#include <opm/simulators/linalg/matrixblock.hh>
51#include <opm/simulators/wells/BlackoilWellModelGeneric.hpp>
52#include <opm/simulators/wells/BlackoilWellModelGuideRates.hpp>
53#include <opm/simulators/wells/GasLiftGroupInfo.hpp>
54#include <opm/simulators/wells/GasLiftSingleWell.hpp>
55#include <opm/simulators/wells/GasLiftSingleWellGeneric.hpp>
56#include <opm/simulators/wells/GasLiftWellState.hpp>
57#include <opm/simulators/wells/MultisegmentWell.hpp>
58#include <opm/simulators/wells/ParallelWBPCalculation.hpp>
59#include <opm/simulators/wells/ParallelWellInfo.hpp>
60#include <opm/simulators/wells/PerforationData.hpp>
63#include <opm/simulators/wells/StandardWell.hpp>
64#include <opm/simulators/wells/VFPInjProperties.hpp>
65#include <opm/simulators/wells/VFPProdProperties.hpp>
66#include <opm/simulators/wells/WGState.hpp>
67#include <opm/simulators/wells/WellGroupHelpers.hpp>
68#include <opm/simulators/wells/WellInterface.hpp>
69#include <opm/simulators/wells/WellProdIndexCalculator.hpp>
70#include <opm/simulators/wells/WellState.hpp>
72#include <opm/simulators/timestepping/SimulatorReport.hpp>
73#include <opm/simulators/timestepping/gatherConvergenceReport.hpp>
75#include <dune/common/fmatrix.hh>
76#include <dune/istl/bcrsmatrix.hh>
77#include <dune/istl/matrixmatrix.hh>
79#include <opm/material/densead/Math.hpp>
81#include <opm/simulators/utils/DeferredLogger.hpp>
83namespace Opm::Parameters {
96 template<
typename TypeTag>
114 using GLiftOptWells =
typename BlackoilWellModelGeneric<Scalar>::GLiftOptWells;
115 using GLiftProdWells =
typename BlackoilWellModelGeneric<Scalar>::GLiftProdWells;
116 using GLiftWellStateMap =
117 typename BlackoilWellModelGeneric<Scalar>::GLiftWellStateMap;
118 using GLiftEclWells =
typename GasLiftGroupInfo<Scalar>::GLiftEclWells;
119 using GLiftSyncGroups =
typename GasLiftSingleWellGeneric<Scalar>::GLiftSyncGroups;
124 typedef typename BaseAuxiliaryModule<TypeTag>::NeighborSet NeighborSet;
126 static const int numEq = Indices::numEq;
127 static const int solventSaturationIdx = Indices::solventSaturationIdx;
135 typedef Dune::FieldVector<Scalar, numEq > VectorBlockType;
136 typedef Dune::BlockVector<VectorBlockType> BVector;
142 using RateConverterType = RateConverter::
143 SurfaceToReservoirVoidage<FluidSystem, std::vector<int> >;
146 using AverageRegionalPressureType = RegionAverageCalculator::
147 AverageRegionalPressure<FluidSystem, std::vector<int> >;
154 void initWellContainer(
const int reportStepIdx)
override;
163 void addNeighbors(std::vector<NeighborSet>& neighbors)
const override;
168 void linearize(SparseMatrixAdapter& jacobian, GlobalEqVector& res)
override;
169 void linearizeDomain(
const Domain& domain, SparseMatrixAdapter& jacobian, GlobalEqVector& res);
173 recoverWellSolutionAndUpdateWellState(deltaX);
176 void postSolveDomain(GlobalEqVector& deltaX,
const Domain& domain)
178 recoverWellSolutionAndUpdateWellStateDomain(deltaX, domain);
185 template <
class Restarter>
186 void deserialize(Restarter& )
195 template <
class Restarter>
203 OPM_TIMEBLOCK(beginEpsiode);
204 beginReportStep(simulator_.episodeIndex());
207 void beginTimeStep();
209 void beginIteration()
211 OPM_TIMEBLOCK(beginIteration);
212 assemble(simulator_.model().newtonMethod().numIterations(),
213 simulator_.timeStepSize());
221 OPM_TIMEBLOCK(endTimeStep);
222 timeStepSucceeded(simulator_.time(), simulator_.timeStepSize());
230 void computeTotalRatesForDof(RateVector& rate,
231 unsigned globalIdx)
const;
233 template <
class Context>
234 void computeTotalRatesForDof(RateVector& rate,
235 const Context& context,
237 unsigned timeIdx)
const;
240 using WellInterfacePtr = std::shared_ptr<WellInterface<TypeTag> >;
242 using BlackoilWellModelGeneric<Scalar>::initFromRestartFile;
243 void initFromRestartFile(
const RestartValue& restartValues)
245 initFromRestartFile(restartValues,
246 this->simulator_.vanguard().transferWTestState(),
251 using BlackoilWellModelGeneric<Scalar>::prepareDeserialize;
252 void prepareDeserialize(
const int report_step)
254 prepareDeserialize(report_step, grid().size(0),
258 data::Wells wellData()
const
260 auto wsrpt = this->wellState()
261 .report(simulator_.vanguard().globalCell().data(),
262 [
this](
const int well_index) ->
bool
264 return this->wasDynamicallyShutThisTimeStep(well_index);
268 const auto& tracerRates = this->simulator_.problem()
269 .tracerModel().getWellTracerRates();
270 const auto& freeTracerRates = simulator_.problem()
271 .tracerModel().getWellFreeTracerRates();
272 const auto& solTracerRates = simulator_.problem()
273 .tracerModel().getWellSolTracerRates();
274 const auto& mswTracerRates = simulator_.problem()
275 .tracerModel().getMswTracerRates();
277 this->assignWellTracerRates(wsrpt, tracerRates);
278 this->assignWellTracerRates(wsrpt, freeTracerRates);
279 this->assignWellTracerRates(wsrpt, solTracerRates);
280 this->assignMswTracerRates(wsrpt, mswTracerRates);
283 BlackoilWellModelGuideRates(*
this)
284 .assignWellGuideRates(wsrpt, this->reportStepIndex());
286 this->assignWellTargets(wsrpt);
287 this->assignShutConnections(wsrpt, this->reportStepIndex());
291 if (eclState().runspec().co2Storage()) {
292 this->assignMassGasRate(wsrpt, FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, 0));
297 data::WellBlockAveragePressures wellBlockAveragePressures()
const
299 return this->computeWellBlockAveragePressures();
303 void apply(
const BVector& x, BVector& Ax)
const;
305 void applyDomain(
const BVector& x, BVector& Ax,
const int domainIndex)
const;
307#if COMPILE_BDA_BRIDGE
309 void getWellContributions(WellContributions<Scalar>& x)
const;
313 void applyScaleAdd(
const Scalar alpha,
const BVector& x, BVector& Ax)
const;
315 void applyScaleAddDomain(
const Scalar alpha,
const BVector& x, BVector& Ax,
const int domainIndex)
const;
318 ConvergenceReport getWellConvergence(
const std::vector<Scalar>& B_avg,
const bool checkWellGroupControls =
false)
const;
321 ConvergenceReport getDomainWellConvergence(
const Domain& domain,
322 const std::vector<Scalar>& B_avg,
323 DeferredLogger& local_deferredLogger)
const;
325 const SimulatorReportSingle& lastReport()
const;
327 void addWellContributions(SparseMatrixAdapter& jacobian)
const;
330 void addReservoirSourceTerms(GlobalEqVector& residual,
331 std::vector<typename SparseMatrixAdapter::MatrixBlock*>& diagMatAddress)
const;
334 void beginReportStep(
const int time_step);
344 void prepareTimeStep(DeferredLogger& deferred_logger);
345 void initPrimaryVariablesEvaluation()
const;
346 void initPrimaryVariablesEvaluationDomain(
const Domain& domain)
const;
348 std::pair<bool, bool>
349 updateWellControls(
const bool mandatory_network_balance, DeferredLogger& deferred_logger,
const bool relax_network_tolerance =
false);
351 void updateAndCommunicate(
const int reportStepIdx,
352 const int iterationIdx,
353 DeferredLogger& deferred_logger);
355 bool updateGroupControls(
const Group& group,
356 DeferredLogger& deferred_logger,
357 const int reportStepIdx,
358 const int iterationIdx);
360 WellInterfacePtr getWell(
const std::string& well_name)
const;
361 bool hasWell(
const std::string& well_name)
const;
363 using PressureMatrix = Dune::BCRSMatrix<Opm::MatrixBlock<Scalar, 1, 1>>;
365 void addWellPressureEquations(PressureMatrix& jacobian,
const BVector& weights,
const bool use_well_weights)
const;
367 void addWellPressureEquationsDomain([[maybe_unused]] PressureMatrix& jacobian,
368 [[maybe_unused]]
const BVector& weights,
369 [[maybe_unused]]
const bool use_well_weights,
370 [[maybe_unused]]
const int domainIndex)
const;
373 void addWellPressureEquationsStruct(PressureMatrix& jacobian)
const;
375 void initGliftEclWellMap(GLiftEclWells &ecl_well_map);
380 return well_container_;
385 void assembleDomain(
const int iterationIdx,
387 const Domain& domain);
388 void updateWellControlsDomain(
DeferredLogger& deferred_logger,
const Domain& domain);
390 void logPrimaryVars()
const;
391 std::vector<Scalar> getPrimaryVarsDomain(
const Domain& domain)
const;
392 void setPrimaryVarsDomain(
const Domain& domain,
const std::vector<Scalar>& vars);
394 void setupDomains(
const std::vector<Domain>& domains);
400 std::vector<WellInterfacePtr> well_container_{};
402 std::vector<bool> is_cell_perforated_{};
404 void initializeWellState(
const int timeStepIdx);
407 void createWellContainer(
const int report_step)
override;
410 createWellPointer(
const int wellID,
411 const int report_step)
const;
413 template <
typename WellType>
414 std::unique_ptr<WellType>
415 createTypedWellPointer(
const int wellID,
416 const int time_step)
const;
418 WellInterfacePtr createWellForWellTest(
const std::string& well_name,
const int report_step, DeferredLogger& deferred_logger)
const;
421 const ModelParameters param_;
422 std::size_t global_num_cells_{};
424 std::size_t local_num_cells_{};
426 std::vector<Scalar> depth_{};
427 bool alternative_well_rate_init_{};
428 std::map<std::string, Scalar> well_group_thp_calc_;
429 std::unique_ptr<RateConverterType> rateConverter_{};
430 std::map<std::string, std::unique_ptr<AverageRegionalPressureType>> regionalAveragePressureCalculator_{};
434 std::optional<typename std::vector<WellInterfacePtr>::size_type> openWellIdx_{};
435 std::size_t wbpCalcIdx_{};
438 std::vector<WBPCalcID> wbpCalcMap_{};
443 void doPreStepNetworkRebalance(DeferredLogger& deferred_logger);
446 mutable BVector scaleAddRes_{};
448 std::vector<Scalar> B_avg_{};
451 std::map<std::string, int> well_domain_;
454 SparseTable<int> well_local_cells_;
456 const Grid& grid()
const
457 {
return simulator_.
vanguard().grid(); }
459 const EquilGrid& equilGrid()
const
460 {
return simulator_.
vanguard().equilGrid(); }
462 const EclipseState& eclState()
const
463 {
return simulator_.
vanguard().eclState(); }
467 void assemble(
const int iterationIdx,
474 std::pair<bool, bool> updateWellControlsAndNetworkIteration(
const bool mandatory_network_balance,
475 const bool relax_network_tolerance,
477 DeferredLogger& local_deferredLogger);
479 bool updateWellControlsAndNetwork(
const bool mandatory_network_balance,
481 DeferredLogger& local_deferredLogger);
483 void computeWellGroupThp(
const double dt, DeferredLogger& local_deferredLogger);
494 const bool enableWellPIScaling);
502 void timeStepSucceeded(
const double simulationTime,
const double dt);
505 void endReportStep();
509 void recoverWellSolutionAndUpdateWellState(
const BVector& x);
513 void recoverWellSolutionAndUpdateWellStateDomain(
const BVector& x,
const Domain& domain);
516 void updatePrimaryVariables(DeferredLogger& deferred_logger);
518 void initializeWBPCalculationService();
520 data::WellBlockAveragePressures
521 computeWellBlockAveragePressures()
const;
524 makeWellSourceEvaluatorFactory(
const std::vector<Well>::size_type wellIdx)
const;
526 void registerOpenWellsForWBPCalculation();
528 void updateAverageFormationFactor();
530 void computePotentials(
const std::size_t widx,
531 const WellState<Scalar>& well_state_copy,
532 std::string& exc_msg,
533 ExceptionType::ExcEnum& exc_type,
534 DeferredLogger& deferred_logger)
override;
536 const std::vector<Scalar>& wellPerfEfficiencyFactors()
const;
538 void calculateProductivityIndexValuesShutWells(
const int reportStepIdx, DeferredLogger& deferred_logger)
override;
539 void calculateProductivityIndexValues(DeferredLogger& deferred_logger)
override;
540 void calculateProductivityIndexValues(
const WellInterface<TypeTag>* wellPtr,
541 DeferredLogger& deferred_logger);
544 int numComponents()
const;
546 int reportStepIndex()
const;
548 void assembleWellEq(
const double dt, DeferredLogger& deferred_logger);
549 void assembleWellEqDomain(
const double dt,
const Domain& domain, DeferredLogger& deferred_logger);
551 void prepareWellsBeforeAssembling(
const double dt, DeferredLogger& deferred_logger);
554 void assembleWellEqWithoutIteration(
const double dt, DeferredLogger& deferred_logger);
556 bool maybeDoGasLiftOptimize(DeferredLogger& deferred_logger);
558 void gasLiftOptimizationStage1(DeferredLogger& deferred_logger,
559 GLiftProdWells& prod_wells,
560 GLiftOptWells& glift_wells,
561 GasLiftGroupInfo<Scalar>& group_info,
562 GLiftWellStateMap& state_map);
565 void gasLiftOptimizationStage1SingleWell(WellInterface<TypeTag>* well,
566 DeferredLogger& deferred_logger,
567 GLiftProdWells& prod_wells,
568 GLiftOptWells& glift_wells,
569 GasLiftGroupInfo<Scalar>& group_info,
570 GLiftWellStateMap& state_map,
571 GLiftSyncGroups& groups_to_sync);
573 void extractLegacyCellPvtRegionIndex_();
575 void extractLegacyDepth_();
578 void updateWellTestState(
const double& simulationTime, WellTestState& wellTestState)
const;
580 void wellTesting(
const int timeStepIdx,
const double simulationTime, DeferredLogger& deferred_logger);
582 void calcResvCoeff(
const int fipnum,
584 const std::vector<Scalar>& production_rates,
585 std::vector<Scalar>& resv_coeff)
override;
587 void calcInjResvCoeff(
const int fipnum,
589 std::vector<Scalar>& resv_coeff)
override;
591 void computeWellTemperature();
594 return simulator_.
vanguard().compressedIndexForInterior(cartesian_cell_idx);
604 mutable BVector x_local_;
605 mutable BVector Ax_local_;
606 mutable BVector res_local_;
607 mutable GlobalEqVector linearize_res_local_;
613#ifndef OPM_BLACKOILWELLMODEL_IMPL_HEADER_INCLUDED
614#include "BlackoilWellModel_impl.hpp"
Helper class for grid instantiation of ECL file-format using problems.
Facility for converting component rates at surface conditions to phase (voidage) rates at reservoir c...
Facility for converting component rates at surface conditions to phase (voidage) rates at reservoir c...
Base class for specifying auxiliary equations.
Base class for specifying auxiliary equations.
Definition baseauxiliarymodule.hh:56
Contains the high level supplements required to extend the black oil model by MICP.
Definition blackoilmicpmodules.hh:49
Contains the high level supplements required to extend the black oil model by polymer.
Definition blackoilpolymermodules.hh:54
Class for handling the blackoil well model.
Definition GroupEconomicLimitsChecker.hpp:35
Class for handling the blackoil well model.
Definition WellInterface.hpp:31
void initializeGroupStructure(const int reportStepIdx)
Initialize group control modes/constraints and group solution state.
Definition BlackoilWellModel_impl.hpp:394
void serialize(Restarter &)
This method writes the complete state of the well to the harddisk.
Definition BlackoilWellModel.hpp:196
const std::vector< WellInterfacePtr > & localNonshutWells() const
Get list of local nonshut wells.
Definition BlackoilWellModel.hpp:378
void postSolve(GlobalEqVector &deltaX) override
This method is called after the linear solver has been called but before the solution is updated for ...
Definition BlackoilWellModel.hpp:171
void applyInitial() override
Set the initial condition of the auxiliary module in the solution vector.
Definition BlackoilWellModel.hpp:165
unsigned numDofs() const override
Returns the number of additional degrees of freedom required for the auxiliary module.
Definition BlackoilWellModel.hpp:159
void calculateExplicitQuantities(DeferredLogger &deferred_logger) const
Calculating the explict quantities used in the well calculation.
Definition BlackoilWellModel_impl.hpp:2154
void initializeLocalWellStructure(const int reportStepIdx, const bool enableWellPIScaling)
Update rank's notion of intersecting wells and their associate solution variables.
Definition BlackoilWellModel_impl.hpp:349
void addNeighbors(std::vector< NeighborSet > &neighbors) const override
Specify the additional neighboring correlations caused by the auxiliary module.
Definition BlackoilWellModel_impl.hpp:188
void linearize(SparseMatrixAdapter &jacobian, GlobalEqVector &res) override
Linearize the auxiliary equation.
Definition BlackoilWellModel_impl.hpp:229
void updateWellTestState(const double &simulationTime, WellTestState &wellTestState) const
upate the wellTestState related to economic limits
Definition BlackoilWellModel_impl.hpp:2489
int compressedIndexForInterior(int cartesian_cell_idx) const override
get compressed index for interior cells (-1, otherwise
Definition BlackoilWellModel.hpp:593
Definition DeferredLogger.hpp:57
Definition WellInterface.hpp:30
std::function< Evaluator()> EvaluatorFactory
Callback for constructing a source term evaluation function on the current MPI rank.
Definition ParallelWBPCalculation.hpp:63
Manages the initializing and running of time dependent problems.
Definition simulator.hh:92
Vanguard & vanguard()
Return a reference to the grid manager of simulation.
Definition simulator.hh:260
This class serves to eliminate the need to include the WellContributions into the matrix (with –matri...
Definition StandardWellEval.hpp:41
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilboundaryratevector.hh:37
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:235
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242
Solver parameters for the BlackoilModel.
Definition BlackoilModelParameters.hpp:162
bool use_multisegment_well_
Whether to use MultisegmentWell to handle multisegment wells it is something temporary before the mul...
Definition BlackoilModelParameters.hpp:259
Definition BlackoilWellModel.hpp:433
Definition BlackoilWellModel.hpp:85
Definition BlackoilPhases.hpp:46
A struct for returning timing data from a simulator to its caller.
Definition SimulatorReport.hpp:34
Representing a part of a grid, in a way suitable for performing local solves.
Definition SubDomain.hpp:62