23 #ifndef OPM_BLACKOILWELLMODEL_GENERIC_HEADER_INCLUDED 24 #define OPM_BLACKOILWELLMODEL_GENERIC_HEADER_INCLUDED 26 #include <opm/output/data/GuideRateValue.hpp> 28 #include <opm/input/eclipse/Schedule/Group/GuideRate.hpp> 29 #include <opm/input/eclipse/Schedule/Well/PAvg.hpp> 30 #include <opm/input/eclipse/Schedule/Well/PAvgCalculator.hpp> 31 #include <opm/input/eclipse/Schedule/Well/PAvgCalculatorCollection.hpp> 32 #include <opm/input/eclipse/Schedule/Well/WellTestState.hpp> 34 #include <opm/simulators/flow/NewtonIterationContext.hpp> 35 #include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp> 36 #include <opm/simulators/wells/BlackoilWellModelGenericParameters.hpp> 37 #include <opm/simulators/wells/BlackoilWellModelWBP.hpp> 38 #include <opm/simulators/wells/ConnectionIndexMap.hpp> 39 #include <opm/simulators/wells/ParallelPAvgDynamicSourceData.hpp> 40 #include <opm/simulators/wells/ParallelWBPCalculation.hpp> 41 #include <opm/simulators/wells/ParallelWellInfo.hpp> 42 #include <opm/simulators/wells/PerforationData.hpp> 43 #include <opm/simulators/wells/WellFilterCake.hpp> 44 #include <opm/simulators/wells/GroupStateHelper.hpp> 45 #include <opm/simulators/wells/WellProdIndexCalculator.hpp> 46 #include <opm/simulators/wells/WellTracerRate.hpp> 47 #include <opm/simulators/wells/WGState.hpp> 56 #include <unordered_map> 57 #include <unordered_set> 64 template<
typename Scalar,
typename IndexTraits>
class BlackoilWellModelGasLiftGeneric;
70 class GuideRateConfig;
73 struct SimulatorUpdate;
77 template<
typename Scalar,
typename IndexTraits>
class WellState;
80 namespace Opm {
namespace data {
82 struct GroupGuideRates;
83 class GroupAndNetworkValues;
96 template<
typename ScalarT,
typename IndexTraitsT>
101 using Scalar = ScalarT;
102 using IndexTraits = IndexTraitsT;
107 const SummaryState& summaryState,
108 const EclipseState& eclState,
110 const Parallel::Communication& comm,
114 virtual int compressedIndexForInteriorLGR([[maybe_unused]]
const std::string& lgr_tag,
115 [[maybe_unused]]
const Connection& conn)
const 117 throw std::runtime_error(
"compressedIndexForInteriorLGR not implemented");
120 int numLocalWells()
const;
121 int numLocalWellsEnd()
const;
122 int numLocalNonshutWells()
const;
123 int numPhases()
const;
135 bool anyMSWellOpenLocal()
const;
137 const std::vector<Well>& eclWells()
const 138 {
return wells_ecl_; }
140 bool terminalOutput()
const 141 {
return terminal_output_; }
143 const Well& getWellEcl(
const std::string& well_name)
const;
144 std::vector<Well> getLocalWells(
const int timeStepIdx)
const;
145 const Schedule& schedule()
const {
return schedule_; }
146 const PhaseUsageInfo<IndexTraits>& phaseUsage()
const {
return phase_usage_info_; }
147 const GroupState<Scalar>& groupState()
const {
return this->active_wgstate_.group_state; }
148 std::vector<const WellInterfaceGeneric<Scalar, IndexTraits>*> genericWells()
const 149 {
return {well_container_generic_.begin(), well_container_generic_.end()}; }
151 std::vector<WellInterfaceGeneric<Scalar, IndexTraits>*> genericWells()
152 {
return well_container_generic_; }
157 const WellState<Scalar, IndexTraits>& wellState()
const 159 return this->active_wgstate_.well_state;
165 WellState<Scalar, IndexTraits>& wellState()
167 return this->active_wgstate_.well_state;
178 const WellState<Scalar, IndexTraits>& nupcolWellState()
const 180 return this->nupcol_wgstate_.well_state;
182 WellState<Scalar, IndexTraits>& nupcolWellState()
184 return this->nupcol_wgstate_.well_state;
186 GroupState<Scalar>& groupState() {
return this->active_wgstate_.group_state; }
188 WellTestState& wellTestState() {
return this->active_wgstate_.well_test_state; }
190 const WellTestState& wellTestState()
const {
return this->active_wgstate_.well_test_state; }
192 Scalar wellPI(
const int well_index)
const;
193 Scalar wellPI(
const std::string& well_name)
const;
195 void updateEclWells(
const int timeStepIdx,
196 const SimulatorUpdate& sim_update,
197 const SummaryState& st);
199 void initFromRestartFile(
const RestartValue& restartValues,
200 std::unique_ptr<WellTestState> wtestState,
201 const std::size_t numCells,
202 bool enable_distributed_wells);
204 void prepareDeserialize(
int report_step,
205 const std::size_t numCells,
206 bool enable_distributed_wells);
214 void commitWGState();
216 data::GroupAndNetworkValues groupAndNetworkData(
const int reportStepIdx)
const;
221 const double simulation_time,
222 const bool dont_shut_grup_wells);
224 const std::vector<PerforationData<Scalar>>& perfData(
const int well_idx)
const 225 {
return well_perf_data_[well_idx]; }
227 const Parallel::Communication& comm()
const {
return comm_; }
229 const EclipseState& eclipseState()
const {
return eclState_; }
231 const SummaryState& summaryState()
const {
return summaryState_; }
233 const GuideRate& guideRate()
const {
return guideRate_; }
234 GuideRate& guideRate() {
return guideRate_; }
236 const std::map<std::string, double>& wellOpenTimes()
const {
return well_open_times_; }
237 const std::map<std::string, double>& wellCloseTimes()
const {
return well_close_times_; }
240 std::vector<int> getCellsForConnections(
const Well& well)
const;
242 bool reportStepStarts()
const {
return report_step_starts_; }
244 void updateClosedWellsThisStep(
const std::string& well_name)
const 246 this->closed_this_step_.insert(well_name);
248 bool wasDynamicallyShutThisTimeStep(
const std::string& well_name)
const;
250 void logPrimaryVars()
const;
252 template<
class Serializer>
253 void serializeOp(Serializer& serializer)
255 serializer(initial_step_);
256 serializer(report_step_starts_);
257 serializer(last_run_wellpi_);
258 serializer(local_shut_wells_);
259 serializer(closed_this_step_);
260 serializer(guideRate_);
261 serializer(genNetwork_);
262 serializer(prev_inj_multipliers_);
263 serializer(active_wgstate_);
264 serializer(last_valid_wgstate_);
265 serializer(nupcol_wgstate_);
266 serializer(switched_prod_groups_);
267 serializer(switched_inj_groups_);
268 serializer(closed_offending_wells_);
269 serializer(gen_gaslift_);
272 bool operator==(
const BlackoilWellModelGeneric& rhs)
const;
274 const ParallelWellInfo<Scalar>&
275 parallelWellInfo(
const std::size_t idx)
const 276 {
return local_parallel_well_info_[idx].get(); }
278 bool isOwner(
const std::string& wname)
const 280 return this->parallelWellSatisfies
281 (wname, [](
const auto& pwInfo) {
return pwInfo.isOwner(); });
284 bool hasLocalCells(
const std::string& wname)
const 286 return this->parallelWellSatisfies
287 (wname, [](
const auto& pwInfo) {
return pwInfo.hasLocalCells(); });
290 const ConnectionIndexMap& connectionIndexMap(
const std::size_t idx)
291 {
return conn_idx_map_[idx]; }
293 GroupStateHelperType& groupStateHelper() {
return group_state_helper_; }
294 const GroupStateHelperType& groupStateHelper()
const {
return group_state_helper_; }
295 std::pair<int, int> getGroupFipnumAndPvtreg()
const;
297 virtual void calcResvCoeff(
const int fipnum,
299 const std::vector<Scalar>& production_rates,
300 std::vector<Scalar>& resv_coeff)
const = 0;
301 virtual void calcInjResvCoeff(
const int fipnum,
303 std::vector<Scalar>& resv_coeff)
const = 0;
305 const VFPProperties<Scalar,IndexTraits>& getVFPProperties()
const 307 return *vfp_properties_;
310 void updateAndCommunicateGroupData(
const int reportStepIdx,
313 const bool update_wellgrouptarget);
315 const NewtonIterationContext& iterationContext()
const 316 {
return iter_ctx_; }
318 const EclipseState& eclState()
const 319 {
return eclState_; }
349 const WellState<Scalar, IndexTraits>& prevWellState()
const 351 return this->last_valid_wgstate_.well_state;
354 const WGState<Scalar, IndexTraits>& prevWGState()
const 356 return this->last_valid_wgstate_;
364 void commitWGState(WGState<Scalar, IndexTraits> wgstate)
366 this->last_valid_wgstate_ = std::move(wgstate);
376 this->active_wgstate_ = this->last_valid_wgstate_;
377 this->genNetwork_.resetState();
379 this->group_state_helper_.updateState(this->wellState(), this->groupState());
387 void updateNupcolWGState()
389 this->nupcol_wgstate_ = this->active_wgstate_;
392 void reportGroupSwitching(DeferredLogger& local_deferredLogger)
const;
396 std::vector<std::reference_wrapper<ParallelWellInfo<Scalar>>>
399 void initializeWellProdIndCalculators();
400 void initializeWellPerfData();
402 bool wasDynamicallyShutThisTimeStep(
const std::size_t well_index)
const;
404 void updateWsolvent(
const Group& group,
405 const int reportStepIdx,
406 const WellState<Scalar, IndexTraits>& wellState);
407 void setWsolvent(
const Group& group,
408 const int reportStepIdx,
429 const int reportStepIndex)
const;
431 void assignWellTargets(data::Wells& wsrpt)
const;
432 void assignProductionWellTargets(
const Well& well, data::WellControlLimits& limits)
const;
433 void assignInjectionWellTargets(
const Well& well, data::WellControlLimits& limits)
const;
435 void assignGroupControl(
const Group& group,
436 data::GroupData& gdata)
const;
437 void assignGroupValues(
const int reportStepIdx,
438 std::map<std::string, data::GroupData>& gvalues)
const;
440 void calculateEfficiencyFactors(
const int reportStepIdx);
442 void checkGconsaleLimits(
const Group& group,
443 WellState<Scalar, IndexTraits>& well_state,
444 const int reportStepIdx,
445 DeferredLogger& deferred_logger);
447 void checkGEconLimits(
const Group& group,
448 const double simulation_time,
449 const int report_step_idx,
450 DeferredLogger& deferred_logger);
452 bool checkGroupHigherConstraints(
const Group& group,
453 DeferredLogger& deferred_logger,
454 const int reportStepIdx,
455 const bool update_group_switching_log);
457 void inferLocalShutWells();
459 void setRepRadiusPerfLength();
461 virtual void computePotentials(
const std::size_t widx,
462 const WellState<Scalar, IndexTraits>& well_state_copy,
463 std::string& exc_msg,
464 ExceptionType::ExcEnum& exc_type) = 0;
467 void updateWellPotentials(
const int reportStepIdx,
468 const bool onlyAfterEvent,
469 const SummaryConfig& summaryConfig,
470 DeferredLogger& deferred_logger);
474 void updateInjMult(DeferredLogger& deferred_logger);
475 void updateInjFCMult(DeferredLogger& deferred_logger);
477 void updateFiltrationModelsPostStep(
const double dt,
478 const std::size_t water_index,
479 DeferredLogger& deferred_logger);
481 void updateFiltrationModelsPreStep(DeferredLogger& deferred_logger);
484 virtual void createWellContainer(
const int time_step) = 0;
485 virtual void initWellContainer(
const int reportStepIdx) = 0;
487 virtual void calculateProductivityIndexValuesShutWells(
const int reportStepIdx,
488 DeferredLogger& deferred_logger) = 0;
489 virtual void calculateProductivityIndexValues(DeferredLogger& deferred_logger) = 0;
491 void runWellPIScaling(
const int reportStepIdx,
492 DeferredLogger& local_deferredLogger);
497 std::vector<std::vector<int>> getMaxWellConnections()
const;
499 std::vector<std::string> getWellsForTesting(
const int timeStepIdx,
500 const double simulationTime);
502 using WellTracerRates = std::unordered_map<int, std::vector<WellTracerRate<Scalar>>>;
503 void assignWellTracerRates(data::Wells& wsrpt,
504 const WellTracerRates& wellTracerRates,
505 const unsigned reportStep)
const;
507 using MswTracerRates = std::unordered_map<int, std::vector<MSWellTracerRate<Scalar>>>;
508 void assignMswTracerRates(data::Wells& wsrpt,
509 const MswTracerRates& mswTracerRates,
510 const unsigned reportStep)
const;
512 void assignMassGasRate(data::Wells& wsrpt,
513 const Scalar gasDensity)
const;
517 const SummaryState& summaryState_;
518 const EclipseState& eclState_;
519 const Parallel::Communication& comm_;
520 const BlackoilWellModelGenericParameters<Scalar> param_;
521 const NewtonIterationContext& iter_ctx_;
522 BlackoilWellModelGasLiftGeneric<Scalar, IndexTraits>& gen_gaslift_;
523 BlackoilWellModelWBP<Scalar, IndexTraits> wbp_;
525 const PhaseUsageInfo<IndexTraits>& phase_usage_info_;
526 bool terminal_output_{
false};
527 bool wells_active_{
false};
528 bool initial_step_{};
529 bool report_step_starts_{};
531 std::optional<int> last_run_wellpi_{};
533 std::vector<Well> wells_ecl_;
534 std::vector<std::vector<PerforationData<Scalar>>> well_perf_data_;
537 std::map<std::string, double> well_open_times_;
540 std::map<std::string, double> well_close_times_;
542 std::vector<ConnectionIndexMap> conn_idx_map_{};
543 std::function<bool(const std::string&)> not_on_process_{};
546 std::vector<WellInterfaceGeneric<Scalar, IndexTraits>*> well_container_generic_{};
548 std::vector<int> local_shut_wells_{};
550 std::vector<ParallelWellInfo<Scalar>> parallel_well_info_;
551 std::vector<std::reference_wrapper<ParallelWellInfo<Scalar>>> local_parallel_well_info_;
553 std::vector<WellProdIndexCalculator<Scalar>> prod_index_calc_;
555 std::vector<int> pvt_region_idx_;
557 mutable std::unordered_set<std::string> closed_this_step_;
559 GuideRate guideRate_;
560 std::unique_ptr<VFPProperties<Scalar, IndexTraits>> vfp_properties_{};
563 std::unordered_map<std::string, std::vector<Scalar>> prev_inj_multipliers_;
566 std::unordered_map<std::string, WellFilterCake<Scalar, IndexTraits>> filter_cake_;
574 WGState<Scalar, IndexTraits> active_wgstate_;
575 WGState<Scalar, IndexTraits> last_valid_wgstate_;
576 WGState<Scalar, IndexTraits> nupcol_wgstate_;
577 GroupStateHelperType group_state_helper_;
580 bool wellStructureChangedDynamically_{
false};
583 std::map<std::string, std::vector<Group::ProductionCMode>> switched_prod_groups_;
584 std::map<std::string, std::array<std::vector<Group::InjectionCMode>, 3>> switched_inj_groups_;
586 std::map<std::string, std::pair<std::string, std::string>> closed_offending_wells_;
590 bool allConnectionsClosed(
const Well& well_ecl)
const;
595 template <
typename Iter,
typename Body>
596 void wellUpdateLoop(Iter first, Iter last,
const int timeStepIdx, Body&& body);
598 void updateEclWellsConstraints(
const int timeStepIdx,
599 const SimulatorUpdate& sim_update,
600 const SummaryState& st);
602 void updateEclWellsCTFFromAction(
const int timeStepIdx,
603 const SimulatorUpdate& sim_update);
618 template <
typename Predicate>
619 bool parallelWellSatisfies(
const std::string& wname, Predicate&& p)
const 621 const auto pwInfoPos =
622 std::ranges::find_if(this->parallel_well_info_,
623 [&wname](
const auto& pwInfo)
624 {
return pwInfo.name() == wname; });
626 return (pwInfoPos != this->parallel_well_info_.end())
645 template <
typename LoopBody>
646 void loopOwnedWells(LoopBody&& loopBody)
const;
Class for handling the blackoil well model.
Definition: ActionHandler.hpp:39
Context for iteration-dependent decisions in the Newton solver.
Definition: NewtonIterationContext.hpp:43
A thin wrapper class that holds one VFPProdProperties and one VFPInjProperties object.
Definition: BlackoilWellModelGeneric.hpp:75
WellGroupEvents report_step_start_events_
Well group events at start of report step.
Definition: BlackoilWellModelGeneric.hpp:578
bool hasOpenLocalWell(const std::string &well_name) const
Returns true if well is defined, open and has connections on current rank.
Definition: BlackoilWellModelGeneric.cpp:170
Definition: BlackoilWellModelGeneric.hpp:89
Definition: BlackoilWellModelGeneric.hpp:67
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
Definition: blackoilnewtonmethodparams.hpp:31
Class for handling the blackoil well network model.
Definition: BlackoilWellModelGeneric.hpp:65
Definition: BlackoilWellModelGeneric.hpp:66
bool wellsActive() const
return true if wells are available in the reservoir
Definition: BlackoilWellModelGeneric.cpp:179
Definition: BlackoilWellModelGasLift.hpp:41
void assignShutConnections(data::Wells &wsrpt, const int reportStepIndex) const
Assign basic result quantities for shut connections of wells owned by current rank.
Definition: BlackoilWellModelGeneric.cpp:1121
Definition: GasLiftGroupInfo.hpp:38
Definition: BlackoilWellModelGeneric.hpp:68
bool forceShutWellByName(const std::string &wellname, const double simulation_time, const bool dont_shut_grup_wells)
Shut down any single well Returns true if the well was actually found and shut.
Definition: BlackoilWellModelGeneric.cpp:1434
void assignDynamicWellStatus(data::Wells &wsrpt) const
Assign dynamic well status for each well owned by current rank.
Definition: BlackoilWellModelGeneric.cpp:1102
virtual int compressedIndexForInterior(int cartesian_cell_idx) const =0
get compressed index for interior cells (-1, otherwise
std::vector< std::reference_wrapper< ParallelWellInfo< Scalar > > > createLocalParallelWellInfo(const std::vector< Well > &wells)
Create the parallel well information.
Definition: BlackoilWellModelGeneric.cpp:311
bool hasLocalWell(const std::string &wname) const
Returns true if well is defined and has connections on current rank.
Definition: BlackoilWellModelGeneric.cpp:160
Definition: BlackoilWellModelGeneric.hpp:76
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition: TemperatureModel.hpp:65