GroupStateHelper.hpp
Go to the documentation of this file.
1/*
2 Copyright 2025 Equinor ASA
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef OPM_GROUPSTATEHELPER_HEADER_INCLUDED
20#define OPM_GROUPSTATEHELPER_HEADER_INCLUDED
21
23
24#include <opm/common/TimingMacros.hpp>
25#include <opm/input/eclipse/EclipseState/Grid/FieldPropsManager.hpp>
26#include <opm/input/eclipse/Schedule/Group/GPMaint.hpp>
27#include <opm/input/eclipse/Schedule/Group/GSatProd.hpp>
28#include <opm/input/eclipse/Schedule/Group/GuideRate.hpp>
29#include <opm/input/eclipse/Schedule/Schedule.hpp>
30#include <opm/input/eclipse/Schedule/ScheduleState.hpp>
31#include <opm/input/eclipse/Schedule/SummaryState.hpp>
32#include <opm/material/fluidsystems/PhaseUsageInfo.hpp>
38
40
41#include <algorithm>
42#include <map>
43#include <memory>
44#include <optional>
45#include <stdexcept>
46#include <string>
47#include <vector>
48
49namespace Opm
50{
51
52template <typename Scalar, typename IndexTraits>
54{
55public:
56 // RAII guard for temporarily setting wellstate pointer
58 {
59 public:
61 : groupStateHelper_ {groupStateHelper}
62 , previous_state_ptr_ {groupStateHelper_.well_state_}
63 {
64 // Set the new state directly
65 groupStateHelper_.well_state_ = &well_state;
66 }
67
69 {
70 // Restore the previous state
71 groupStateHelper_.well_state_ = previous_state_ptr_;
72 }
73
74 // Delete copy and move operations
79
80 private:
81 GroupStateHelper& groupStateHelper_;
82 const WellState<Scalar, IndexTraits>* previous_state_ptr_;
83 };
84
85 // RAII guard for temporarily setting groupstate pointer
87 {
88 public:
89 GroupStateGuard(GroupStateHelper& group_state_helper, GroupState<Scalar>& group_state)
90 : group_state_helper_ {group_state_helper}
91 , previous_state_ptr_ {group_state_helper.group_state_}
92 {
93 // Set the new state directly
94 group_state_helper_.group_state_ = &group_state;
95 }
96
98 {
99 // Restore the previous state
100 group_state_helper_.group_state_ = previous_state_ptr_;
101 }
102
103 // Delete copy and move operations
108
109 private:
110 GroupStateHelper& group_state_helper_;
111 GroupState<Scalar>* previous_state_ptr_ {nullptr};
112 };
113
127 {
128 public:
134 explicit ScopedLoggerGuard(const GroupStateHelper& helper, bool do_mpi_gather = true)
135 : helper_(&helper)
136 , previous_(helper.deferred_logger_)
137 , do_mpi_gather_(do_mpi_gather)
138 {
139 helper_->deferred_logger_ = &logger_;
140 }
141
143 {
144 if (helper_) {
145 if (do_mpi_gather_) {
146 // 1. Gather messages across MPI ranks
147 DeferredLogger global = gatherDeferredLogger(logger_, helper_->comm());
148
149 // 2. Log on rank 0 (if terminal_output enabled)
150 if (helper_->terminalOutput()) {
151 global.logMessages();
152 }
153 } else {
154 // Just log locally without MPI gather
155 if (helper_->terminalOutput()) {
156 logger_.logMessages();
157 }
158 }
159
160 // 3. Restore previous logger
161 helper_->deferred_logger_ = previous_;
162 }
163 }
164
165 // Delete copy operations and move assignment
169
170 // Move constructor required for pushLogger() return-by-value (must be
171 // available even if elided by RVO)
173 : helper_(other.helper_)
174 , logger_(std::move(other.logger_))
175 , previous_(other.previous_)
176 , do_mpi_gather_(other.do_mpi_gather_)
177 {
178 // Update the helper's pointer to our moved logger
179 if (helper_) {
180 helper_->deferred_logger_ = &logger_;
181 }
182 other.helper_ = nullptr;
183 other.previous_ = nullptr;
184 }
185
186 private:
187 // Pointer (not reference) to allow nulling in move constructor
188 const GroupStateHelper* helper_{nullptr};
189 DeferredLogger logger_; // Owned logger
190 DeferredLogger* previous_{nullptr}; // For restore
191 bool do_mpi_gather_{true}; // Whether to gather messages across MPI ranks
192 };
193
195 GroupState<Scalar>& group_state,
196 const Schedule& schedule,
197 const SummaryState& summary_state,
198 const GuideRate& guide_rate,
199 const PhaseUsageInfo<IndexTraits>& phase_usage_info,
201 bool terminal_output);
202
203 void accumulateGroupEfficiencyFactor(const Group& group, Scalar& factor) const;
204
205 std::pair<bool, Scalar> checkGroupConstraintsInj(const std::string& name,
206 const std::string& parent,
207 const Group& group,
208 const Scalar* rates,
209 const Phase injection_phase,
210 const Scalar efficiency_factor,
211 const std::vector<Scalar>& resv_coeff,
212 const bool check_guide_rate) const;
213
214 std::pair<bool, Scalar> checkGroupConstraintsProd(const std::string& name,
215 const std::string& parent,
216 const Group& group,
217 const Scalar* rates,
218 const Scalar efficiency_factor,
219 const std::vector<Scalar>& resv_coeff,
220 const bool check_guide_rate) const;
221
222 const Parallel::Communication& comm() const { return this->comm_; }
223
227 {
228 if (this->deferred_logger_ == nullptr) {
229 throw std::logic_error("DeferredLogger not set. Call pushLogger() first.");
230 }
231 return *this->deferred_logger_;
232 }
233
234 std::vector<Scalar> getGroupRatesAvailableForHigherLevelControl(const Group& group, const bool is_injector) const;
235
236 Scalar getGuideRate(const std::string& name, const GuideRateModel::Target target) const;
237
238 Scalar getInjectionGroupTarget(const Group& group,
239 const Phase& injection_phase,
240 const std::vector<Scalar>& resv_coeff) const;
241
245 GuideRateModel::Target getInjectionGuideTargetMode(Phase injection_phase) const;
246
247 Scalar getProductionGroupTarget(const Group& group) const;
248
252 GuideRateModel::Target getProductionGuideTargetMode(const Group& group) const;
253
254 GuideRate::RateVector getProductionGroupRateVector(const std::string& group_name) const;
255
257
258 std::optional<GroupTarget> getWellGroupTargetInjector(const std::string& name,
259 const std::string& parent,
260 const Group& group,
261 const Scalar* rates,
262 const Phase injection_phase,
263 const Scalar efficiency_factor,
264 const std::vector<Scalar>& resv_coeff) const;
265
266 std::optional<GroupTarget> getWellGroupTargetProducer(const std::string& name,
267 const std::string& parent,
268 const Group& group,
269 const Scalar* rates,
270 const Scalar efficiency_factor,
271 const std::vector<Scalar>& resv_coeff) const;
272
273 GuideRate::RateVector getWellRateVector(const std::string& name) const;
274
275 std::vector<std::string> groupChainTopBot(const std::string& bottom, const std::string& top) const;
276
279 int groupControlledWells(const std::string& group_name,
280 const std::string& always_included_child,
281 const bool is_production_group,
282 const Phase injection_phase) const;
283
285 {
286 return *this->group_state_;
287 }
288
289 const GuideRate& guideRate() const
290 {
291 return this->guide_rate_;
292 }
293
294 bool isRank0() const
295 {
296 return this->well_state_->isRank0();
297 }
298
299 bool isReservoirCouplingMaster() const { return rescoup_.isMaster(); }
300
301 bool isReservoirCouplingMasterGroup(const Group& group) const { return rescoup_.isMasterGroup(group.name()); }
302
303 bool isReservoirCouplingSlave() const { return rescoup_.isSlave(); }
304
305 constexpr int numPhases() const {
306 return this->wellState().numPhases();
307 }
308
309 int phaseToActivePhaseIdx(const Phase phase) const;
310
312 return this->phase_usage_info_;
313 }
314
316 {
317 return GroupStateGuard(*this, group_state);
318 }
319
333 ScopedLoggerGuard pushLogger(bool do_mpi_gather = true) const
334 {
335 return ScopedLoggerGuard(*this, do_mpi_gather);
336 }
337
339 {
340 return WellStateGuard(*this, well_state);
341 }
342
343 int reportStepIdx() const
344 {
345 return report_step_;
346 }
347
348 const Schedule& schedule() const
349 {
350 return this->schedule_;
351 }
352
354 return rescoup_;
355 }
356
358 return rescoup_;
359 }
360
362 return rescoup_.master();
363 }
364
366 return rescoup_.master();
367 }
368
370 return rescoup_.slave();
371 }
373 return rescoup_.slave();
374 }
375
376#ifdef RESERVOIR_COUPLING_ENABLED
377 void setReservoirCouplingMaster(ReservoirCouplingMaster<Scalar>* master) {
378 rescoup_.setMaster(master);
379 }
380 void setReservoirCouplingSlave(ReservoirCouplingSlave<Scalar>* slave) {
381 rescoup_.setSlave(slave);
382 }
383#endif
384
385 void setCmodeGroup(const Group& group);
386
387 template <class AverageRegionalPressureType>
388 void
390 const FieldPropsManager& fp,
391 std::map<std::string, std::unique_ptr<AverageRegionalPressureType>>&
392 regional_average_pressure_calculator) const;
393
394 void setReportStep(int report_step)
395 {
396 report_step_ = report_step;
397 }
398
399 const SummaryState& summaryState() const
400 {
401 return this->summary_state_;
402 }
403
404 Scalar sumSolventRates(const Group& group, const bool is_injector) const;
405
406 Scalar sumWellResRates(const Group& group, const int phase_pos, const bool injector) const;
407
408 Scalar sumWellSurfaceRates(const Group& group, const int phase_pos, const bool injector) const;
409
410 Scalar sumWellPhaseRates(bool res_rates,
411 const Group& group,
412 const int phase_pos,
413 const bool injector,
414 const bool network = false) const;
415
416 bool terminalOutput() const
417 {
418 return this->terminal_output_;
419 }
420
421 template <class RegionalValues>
422 void updateGpMaintTargetForGroups(const Group& group,
423 const RegionalValues& regional_values,
424 const double dt);
425
428 int updateGroupControlledWells(const bool is_production_group,
429 const Phase injection_phase);
430
431 void updateGroupProductionRates(const Group& group);
432
433 void updateGroupTargetReduction(const Group& group,
434 const bool is_injector);
435
437
438 void updateREINForGroups(const Group& group, bool sum_rank);
439
440 void updateReservoirRatesInjectionGroups(const Group& group);
441
443
444 void updateSurfaceRatesInjectionGroups(const Group& group);
445
446 void updateVREPForGroups(const Group& group);
447
448 void updateWellRates(const Group& group,
449 const WellState<Scalar, IndexTraits>& well_state_nupcol,
450 WellState<Scalar, IndexTraits>& well_state) const;
451
453 {
454 return *this->well_state_;
455 }
456
457 void updateWellRatesFromGroupTargetScale(const Scalar scale,
458 const Group& group,
459 bool is_injector,
460 WellState<Scalar, IndexTraits>& well_state) const;
461
463 std::pair<std::optional<std::string>, Scalar>
464 worstOffendingWell(const Group& group,
465 const Group::ProductionCMode& offended_control) const;
466
467private:
468#ifdef RESERVOIR_COUPLING_ENABLED
473 ReservoirCoupling::Phase activePhaseIdxToRescoupPhase_(int phase_pos) const;
474#endif
475
497 template<typename ReductionLambda, typename FractionLambda>
498 Scalar applyReductionsAndFractions_(const std::vector<std::string>& chain,
499 Scalar orig_target,
500 Scalar current_rate_available,
501 std::size_t local_reduction_level,
502 bool is_production_group,
503 Phase injection_phase,
504 ReductionLambda&& local_reduction_lambda,
505 FractionLambda&& local_fraction_lambda,
506 bool do_addback) const;
507
518 Scalar computeAddbackEfficiency_(const std::vector<std::string>& chain,
519 std::size_t local_reduction_level) const;
520
521 std::string controlGroup_(const Group& group) const;
522
523 GuideRate::RateVector getGuideRateVector_(const std::vector<Scalar>& rates) const;
524
535 std::size_t getLocalReductionLevel_(const std::vector<std::string>& chain,
536 bool is_production_group,
537 Phase injection_phase) const;
538
539 Scalar getReservoirCouplingMasterGroupRate_(const Group& group,
540 const int phase_pos,
541 const bool res_rates,
542 const bool is_injector) const;
543
544 Scalar getSatelliteRate_(const Group& group,
545 const int phase_pos,
546 const bool res_rates,
547 const bool is_injector) const;
548
552 bool isAutoChokeGroupUnderperforming_(const Group& group) const;
553
555 bool isInGroupChainTopBot_(const std::string& bottom, const std::string& top) const;
556
557 bool isSatelliteGroup_(const Group& group) const;
558
559 Scalar satelliteInjectionRate_(const ScheduleState& sched,
560 const Group& group,
561 const int phase_pos,
562 bool res_rates) const;
563
564 Scalar satelliteProductionRate_(const ScheduleState& sched,
565 const Group& group,
566 const GSatProd::GSatProdGroupProp::Rate rate_comp,
567 bool res_rates) const;
568
569 std::optional<GSatProd::GSatProdGroupProp::Rate> selectRateComponent_(const int phase_pos) const;
570
571 int updateGroupControlledWellsRecursive_(const std::string& group_name,
572 const bool is_production_group,
573 const Phase injection_phase);
574
575 void updateGroupTargetReductionRecursive_(const Group& group,
576 const bool is_injector,
577 std::vector<Scalar>& group_target_reduction);
578
579 const WellState<Scalar, IndexTraits>* well_state_ {nullptr};
580 GroupState<Scalar>* group_state_ {nullptr};
581 const Schedule& schedule_;
582 const SummaryState& summary_state_;
583 const GuideRate& guide_rate_;
584 // NOTE: The deferred logger does not change the object "meaningful" state, so it should be ok to
585 // make it mutable and store a pointer to it here.
586 mutable DeferredLogger* deferred_logger_ {nullptr};
587 // NOTE: The phase usage info seems to be read-only throughout the simulation, so it should be safe
588 // to store a reference to it here.
589 const PhaseUsageInfo<IndexTraits>& phase_usage_info_;
590 const Parallel::Communication& comm_;
591 bool terminal_output_ {false};
592 int report_step_ {0};
593 ReservoirCoupling::Proxy<Scalar> rescoup_{};
594};
595
596// -----------------------------------------------------------------------------
597// Template member function implementations
598// -----------------------------------------------------------------------------
599
600// NOTE: This template member function is defined here in the header because the
601// AverageRegionalPressureType type parameter depends on derived class types that are
602// not available when GroupStateHelper.cpp is compiled. Template functions
603// must be visible at their instantiation point.
604// See GroupStateHelper.cpp for detailed rationale.
605template <typename Scalar, typename IndexTraits>
606template <class AverageRegionalPressureType>
607void
609 const Group& group,
610 const FieldPropsManager& fp,
611 std::map<std::string, std::unique_ptr<AverageRegionalPressureType>>& regional_average_pressure_calculator)
612 const
613{
614 for (const std::string& groupName : group.groups()) {
615 this->setRegionAveragePressureCalculator(this->schedule_.getGroup(groupName, this->report_step_),
616 fp,
617 regional_average_pressure_calculator);
618 }
619 const auto& gpm = group.gpmaint();
620 if (!gpm)
621 return;
622
623 const auto& reg = gpm->region();
624 if (!reg)
625 return;
626
627 if (regional_average_pressure_calculator.count(reg->first) == 0) {
628 const std::string name = (reg->first.rfind("FIP", 0) == 0) ? reg->first : "FIP" + reg->first;
629 const auto& fipnum = fp.get_int(name);
630 regional_average_pressure_calculator[reg->first]
631 = std::make_unique<AverageRegionalPressureType>(fipnum);
632 }
633}
634
635// NOTE: This template member function is defined in the header because the
636// RegionalValues type parameter depends on derived class types that are
637// not available when GroupStateHelper.cpp is compiled. Template functions
638// must be visible at their instantiation point.
639// See GroupStateHelper.cpp for detailed rationale.
640template <typename Scalar, typename IndexTraits>
641template <class RegionalValues>
642void
644 const RegionalValues& regional_values,
645 const double dt)
646{
647 OPM_TIMEFUNCTION();
648 for (const std::string& group_name : group.groups()) {
649 const Group& group_tmp = this->schedule_.getGroup(group_name, this->report_step_);
650 this->updateGpMaintTargetForGroups(group_tmp, regional_values, dt);
651 }
652 const auto& gpm = group.gpmaint();
653 if (!gpm)
654 return;
655
656 const auto& region = gpm->region();
657 if (!region)
658 return;
659
660 const auto [name, number] = *region;
661 const Scalar error = gpm->pressure_target() - regional_values.at(name)->pressure(number);
662 Scalar current_rate = 0.0;
663 const auto& pu = this->phase_usage_info_;
664 bool injection = true;
665 Scalar sign = 1.0;
666 switch (gpm->flow_target()) {
667 case GPMaint::FlowTarget::RESV_PROD: {
668 current_rate = -this->groupState().injection_vrep_rate(group.name());
669 injection = false;
670 sign = -1.0;
671 break;
672 }
673 case GPMaint::FlowTarget::RESV_OINJ: {
674 if (pu.phaseIsActive(IndexTraits::oilPhaseIdx)) {
675 const auto io = pu.canonicalToActivePhaseIdx(IndexTraits::oilPhaseIdx);
676 current_rate = this->groupState().injection_reservoir_rates(group.name())[io];
677 }
678 break;
679 }
680 case GPMaint::FlowTarget::RESV_WINJ: {
681 if (pu.phaseIsActive(IndexTraits::waterPhaseIdx)) {
682 const auto iw = pu.canonicalToActivePhaseIdx(IndexTraits::waterPhaseIdx);
683 current_rate = this->groupState().injection_reservoir_rates(group.name())[iw];
684 }
685 break;
686 }
687 case GPMaint::FlowTarget::RESV_GINJ: {
688 if (pu.phaseIsActive(IndexTraits::gasPhaseIdx)) {
689 const auto ig = pu.canonicalToActivePhaseIdx(IndexTraits::gasPhaseIdx);
690 current_rate = this->groupState().injection_reservoir_rates(group.name())[ig];
691 }
692 break;
693 }
694 case GPMaint::FlowTarget::SURF_OINJ: {
695 if (pu.phaseIsActive(IndexTraits::oilPhaseIdx)) {
696 const auto io = pu.canonicalToActivePhaseIdx(IndexTraits::oilPhaseIdx);
697 current_rate = this->groupState().injection_surface_rates(group.name())[io];
698 }
699 break;
700 }
701 case GPMaint::FlowTarget::SURF_WINJ: {
702 if (pu.phaseIsActive(IndexTraits::waterPhaseIdx)) {
703 const auto iw = pu.canonicalToActivePhaseIdx(IndexTraits::waterPhaseIdx);
704 current_rate = this->groupState().injection_surface_rates(group.name())[iw];
705 }
706 break;
707 }
708 case GPMaint::FlowTarget::SURF_GINJ: {
709 if (pu.phaseIsActive(IndexTraits::gasPhaseIdx)) {
710 const auto ig = pu.canonicalToActivePhaseIdx(IndexTraits::gasPhaseIdx);
711 current_rate = this->groupState().injection_surface_rates(group.name())[ig];
712 }
713 break;
714 }
715 default:
716 throw std::invalid_argument("Invalid Flow target type in GPMAINT");
717 }
718 auto& gpmaint_state = this->groupState().gpmaint(group.name());
719 // we only activate gpmaint if pressure is lower than the target regional pressure for injectors
720 // (i.e. error > 0) and higher for producers.
721 bool activate = (injection && error > 0) || (!injection && error < 0);
722 Scalar rate = 0.0;
723 if (activate) {
724 rate = gpm->rate(gpmaint_state, current_rate, error, dt);
725 } else {
726 gpm->resetState(gpmaint_state);
727 }
728 this->groupState().update_gpmaint_target(group.name(), std::max(Scalar {0.0}, sign * rate));
729}
730
731} // namespace Opm
732
733#endif // OPM_GROUPSTATE_HELPER_HEADER_INCLUDED
Definition: DeferredLogger.hpp:57
Definition: GroupStateHelper.hpp:87
GroupStateGuard(GroupStateGuard &&)=delete
GroupStateGuard & operator=(GroupStateGuard &&)=delete
GroupStateGuard(GroupStateHelper &group_state_helper, GroupState< Scalar > &group_state)
Definition: GroupStateHelper.hpp:89
GroupStateGuard(const GroupStateGuard &)=delete
~GroupStateGuard()
Definition: GroupStateHelper.hpp:97
GroupStateGuard & operator=(const GroupStateGuard &)=delete
RAII guard that owns a DeferredLogger and auto-gathers on destruction.
Definition: GroupStateHelper.hpp:127
ScopedLoggerGuard & operator=(const ScopedLoggerGuard &)=delete
ScopedLoggerGuard(ScopedLoggerGuard &&other) noexcept
Definition: GroupStateHelper.hpp:172
ScopedLoggerGuard(const ScopedLoggerGuard &)=delete
ScopedLoggerGuard(const GroupStateHelper &helper, bool do_mpi_gather=true)
Constructor for scoped logger guard.
Definition: GroupStateHelper.hpp:134
~ScopedLoggerGuard()
Definition: GroupStateHelper.hpp:142
ScopedLoggerGuard & operator=(ScopedLoggerGuard &&)=delete
Definition: GroupStateHelper.hpp:58
WellStateGuard(WellStateGuard &&)=delete
WellStateGuard(const WellStateGuard &)=delete
~WellStateGuard()
Definition: GroupStateHelper.hpp:68
WellStateGuard & operator=(const WellStateGuard &)=delete
WellStateGuard & operator=(WellStateGuard &&)=delete
WellStateGuard(GroupStateHelper &groupStateHelper, WellState< Scalar, IndexTraits > &well_state)
Definition: GroupStateHelper.hpp:60
Definition: GroupStateHelper.hpp:54
void updateWellRatesFromGroupTargetScale(const Scalar scale, const Group &group, bool is_injector, WellState< Scalar, IndexTraits > &well_state) const
void setRegionAveragePressureCalculator(const Group &group, const FieldPropsManager &fp, std::map< std::string, std::unique_ptr< AverageRegionalPressureType > > &regional_average_pressure_calculator) const
Definition: GroupStateHelper.hpp:608
void setCmodeGroup(const Group &group)
std::vector< std::string > groupChainTopBot(const std::string &bottom, const std::string &top) const
void updateVREPForGroups(const Group &group)
void updateWellRates(const Group &group, const WellState< Scalar, IndexTraits > &well_state_nupcol, WellState< Scalar, IndexTraits > &well_state) const
std::optional< GroupTarget > getWellGroupTargetProducer(const std::string &name, const std::string &parent, const Group &group, const Scalar *rates, const Scalar efficiency_factor, const std::vector< Scalar > &resv_coeff) const
ReservoirCouplingMaster< Scalar > & reservoirCouplingMaster()
Definition: GroupStateHelper.hpp:361
GroupState< Scalar > & groupState() const
Definition: GroupStateHelper.hpp:284
Scalar sumWellResRates(const Group &group, const int phase_pos, const bool injector) const
void accumulateGroupEfficiencyFactor(const Group &group, Scalar &factor) const
int groupControlledWells(const std::string &group_name, const std::string &always_included_child, const bool is_production_group, const Phase injection_phase) const
const PhaseUsageInfo< IndexTraits > & phaseUsage() const
Definition: GroupStateHelper.hpp:311
const ReservoirCouplingMaster< Scalar > & reservoirCouplingMaster() const
Definition: GroupStateHelper.hpp:365
const SummaryState & summaryState() const
Definition: GroupStateHelper.hpp:399
const GuideRate & guideRate() const
Definition: GroupStateHelper.hpp:289
std::pair< std::optional< std::string >, Scalar > worstOffendingWell(const Group &group, const Group::ProductionCMode &offended_control) const
Returns the name of the worst offending well and its fraction (i.e. violated_phase / preferred_phase)
ReservoirCoupling::Proxy< Scalar > & rescoup()
Definition: GroupStateHelper.hpp:353
void updateReservoirRatesInjectionGroups(const Group &group)
const WellState< Scalar, IndexTraits > & wellState() const
Definition: GroupStateHelper.hpp:452
constexpr int numPhases() const
Definition: GroupStateHelper.hpp:305
GuideRate::RateVector getWellRateVector(const std::string &name) const
ScopedLoggerGuard pushLogger(bool do_mpi_gather=true) const
Push a new logger onto the stack with auto-cleanup on destruction.
Definition: GroupStateHelper.hpp:333
const Parallel::Communication & comm() const
Definition: GroupStateHelper.hpp:222
GuideRateModel::Target getInjectionGuideTargetMode(Phase injection_phase) const
Get the guide rate target mode for an injection phase.
bool isRank0() const
Definition: GroupStateHelper.hpp:294
Scalar sumSolventRates(const Group &group, const bool is_injector) const
const Schedule & schedule() const
Definition: GroupStateHelper.hpp:348
void updateGroupTargetReduction(const Group &group, const bool is_injector)
GuideRate::RateVector getProductionGroupRateVector(const std::string &group_name) const
void updateGroupProductionRates(const Group &group)
bool terminalOutput() const
Definition: GroupStateHelper.hpp:416
typename SingleWellState< Scalar, IndexTraits >::GroupTarget GroupTarget
Definition: GroupStateHelper.hpp:256
void updateGpMaintTargetForGroups(const Group &group, const RegionalValues &regional_values, const double dt)
Definition: GroupStateHelper.hpp:643
int phaseToActivePhaseIdx(const Phase phase) const
std::pair< bool, Scalar > checkGroupConstraintsProd(const std::string &name, const std::string &parent, const Group &group, const Scalar *rates, const Scalar efficiency_factor, const std::vector< Scalar > &resv_coeff, const bool check_guide_rate) const
DeferredLogger & deferredLogger() const
Get the deferred logger.
Definition: GroupStateHelper.hpp:226
Scalar sumWellSurfaceRates(const Group &group, const int phase_pos, const bool injector) const
int reportStepIdx() const
Definition: GroupStateHelper.hpp:343
Scalar getGuideRate(const std::string &name, const GuideRateModel::Target target) const
void setReportStep(int report_step)
Definition: GroupStateHelper.hpp:394
int updateGroupControlledWells(const bool is_production_group, const Phase injection_phase)
void updateState(WellState< Scalar, IndexTraits > &well_state, GroupState< Scalar > &group_state)
std::vector< Scalar > getGroupRatesAvailableForHigherLevelControl(const Group &group, const bool is_injector) const
bool isReservoirCouplingMasterGroup(const Group &group) const
Definition: GroupStateHelper.hpp:301
const ReservoirCoupling::Proxy< Scalar > & rescoup() const
Definition: GroupStateHelper.hpp:357
bool isReservoirCouplingMaster() const
Definition: GroupStateHelper.hpp:299
const ReservoirCouplingSlave< Scalar > & reservoirCouplingSlave() const
Definition: GroupStateHelper.hpp:372
void updateNetworkLeafNodeProductionRates()
WellStateGuard pushWellState(WellState< Scalar, IndexTraits > &well_state)
Definition: GroupStateHelper.hpp:338
Scalar getInjectionGroupTarget(const Group &group, const Phase &injection_phase, const std::vector< Scalar > &resv_coeff) const
GroupStateGuard pushGroupState(GroupState< Scalar > &group_state)
Definition: GroupStateHelper.hpp:315
ReservoirCouplingSlave< Scalar > & reservoirCouplingSlave()
Definition: GroupStateHelper.hpp:369
Scalar sumWellPhaseRates(bool res_rates, const Group &group, const int phase_pos, const bool injector, const bool network=false) const
void updateREINForGroups(const Group &group, bool sum_rank)
bool isReservoirCouplingSlave() const
Definition: GroupStateHelper.hpp:303
GuideRateModel::Target getProductionGuideTargetMode(const Group &group) const
Get the guide rate target mode for a production group.
Scalar getProductionGroupTarget(const Group &group) const
std::pair< bool, Scalar > checkGroupConstraintsInj(const std::string &name, const std::string &parent, const Group &group, const Scalar *rates, const Phase injection_phase, const Scalar efficiency_factor, const std::vector< Scalar > &resv_coeff, const bool check_guide_rate) const
std::optional< GroupTarget > getWellGroupTargetInjector(const std::string &name, const std::string &parent, const Group &group, const Scalar *rates, const Phase injection_phase, const Scalar efficiency_factor, const std::vector< Scalar > &resv_coeff) const
GroupStateHelper(WellState< Scalar, IndexTraits > &well_state, GroupState< Scalar > &group_state, const Schedule &schedule, const SummaryState &summary_state, const GuideRate &guide_rate, const PhaseUsageInfo< IndexTraits > &phase_usage_info, const Parallel::Communication &comm, bool terminal_output)
void updateSurfaceRatesInjectionGroups(const Group &group)
Definition: GroupState.hpp:41
Definition: GasLiftGroupInfo.hpp:37
Thin proxy for reservoir coupling master/slave pointers.
Definition: RescoupProxy.hpp:54
Definition: ReservoirCouplingMaster.hpp:38
Definition: ReservoirCouplingSlave.hpp:40
Definition: WellState.hpp:66
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Phase
Phase indices for reservoir coupling, we currently only support black-oil phases (oil,...
Definition: ReservoirCoupling.hpp:148
Definition: blackoilbioeffectsmodules.hh:43
Opm::DeferredLogger gatherDeferredLogger(const Opm::DeferredLogger &local_deferredlogger, Parallel::Communication communicator)
Create a global log combining local logs.
Definition: SingleWellState.hpp:121