opm-simulators
GuideRateHandler.hpp
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 
20 #ifndef OPM_GUIDERATE_HANDLER_HPP
21 #define OPM_GUIDERATE_HANDLER_HPP
22 
23 #include <opm/simulators/wells/rescoup/RescoupProxy.hpp>
24 #include <opm/input/eclipse/Schedule/Group/GuideRate.hpp>
25 #include <opm/output/data/Groups.hpp>
26 #include <opm/output/data/GuideRateValue.hpp>
27 #include <opm/simulators/utils/DeferredLogger.hpp>
28 #include <opm/simulators/wells/BlackoilWellModelGeneric.hpp>
29 #include <opm/simulators/wells/BlackoilWellModelGuideRates.hpp>
30 #include <opm/simulators/wells/GroupState.hpp>
31 #include <opm/simulators/wells/WellState.hpp>
32 namespace Opm {
33 
45 template<typename Scalar, typename IndexTraits>
47 public:
48 
49 #ifdef RESERVOIR_COUPLING_ENABLED
50  using Potentials = ReservoirCoupling::Potentials<Scalar>;
51 #endif
52 
60  public:
62  GuideRateHandler<Scalar, IndexTraits> &parent, const int report_step_idx, const double sim_time
63  );
64 
65  DeferredLogger &deferredLogger() { return this->parent_.deferredLogger(); }
69  void dumpGuideRates();
70  private:
71  void dumpGuideRatesRecursive_(const Group& group, int level);
72  void getGroupGuideRatesInjection_(
73  const Group& group,
74  const data::GroupGuideRates& group_guide_rate,
75  std::vector<std::string>& msg_items
76  ) const;
77  void getGroupGuideRatesProduction_(
78  const Group& group,
79  const data::GroupGuideRates& group_guide_rate,
80  std::vector<std::string>& msg_items
81  ) const;
88  void printGroupGuideRates_(const Group& group, int level);
89  void printHeader_();
90  void printFooter_();
91  void printWellGuideRates_(const Well& well, int level);
92 
94  const int report_step_idx_;
95  const double sim_time_;
97  const Schedule& schedule_;
98  const Parallel::Communication& comm_;
99  std::unordered_map<std::string, data::GuideRateValue> well_guide_rates_;
100  std::unordered_map<std::string, data::GroupGuideRates> group_guide_rates_;
101  };
102 
111  public:
114  const int report_step_idx,
115  const double sim_time,
116  const WellState<Scalar, IndexTraits> &well_state,
117  GroupState<Scalar> &group_state,
118  const int num_phases
119  );
120 
121  bool isReservoirCouplingMaster() const { return this->parent_.isReservoirCouplingMaster(); }
122  ReservoirCouplingMaster<Scalar>& reservoirCouplingMaster() {
123  return this->parent_.reservoirCouplingMaster();
124  }
125  const Parallel::Communication &comm() const { return this->parent_.comm_; }
126  DeferredLogger &deferredLogger() { return this->parent_.deferredLogger(); }
127  GuideRate &guideRate() { return this->parent_.guide_rate_; }
128  const PhaseUsageInfo<IndexTraits>& phaseUsage() const { return this->parent_.phaseUsage(); }
129  const SummaryState &summaryState() const { return this->parent_.summary_state_; }
130  const Schedule &schedule() const { return this->parent_.schedule_; }
134  void update();
135 
136  private:
137 #ifdef RESERVOIR_COUPLING_ENABLED
138  bool isMasterGroup_(const Group& group);
139 #endif
140  void updateGuideRatesForInjectionGroups_(const Group& group);
147  void updateGuideRatesForProductionGroups_(const Group& group, std::vector<Scalar>& pot);
148  void updateGuideRatesForWells_();
149 #ifdef RESERVOIR_COUPLING_ENABLED
150  void updateProductionGroupPotentialFromSlaveGroup_(
151  const Group& group, std::vector<Scalar>& pot);
152 #endif
153  void updateProductionGroupPotentialFromSubGroups(
154  const Group& group, std::vector<Scalar>& pot);
155 
157  const int report_step_idx_;
158  const double sim_time_;
159  const WellState<Scalar, IndexTraits> &well_state_;
160  GroupState<Scalar> &group_state_;
161  const int num_phases_;
162  const UnitSystem& unit_system_;
163  };
164 
167  const Schedule& schedule,
168  const SummaryState& summary_state,
169  const Parallel::Communication& comm
170  );
171 
172  // === Reservoir Coupling ===
173 
176  const ReservoirCoupling::Proxy<Scalar>& rescoup() const { return rescoup_; }
177 
178  bool isReservoirCouplingMaster() const { return rescoup_.isMaster(); }
179  bool isReservoirCouplingSlave() const { return rescoup_.isSlave(); }
180 
181  ReservoirCouplingMaster<Scalar>& reservoirCouplingMaster() { return rescoup_.master(); }
182  ReservoirCouplingSlave<Scalar>& reservoirCouplingSlave() { return rescoup_.slave(); }
183 
184 #ifdef RESERVOIR_COUPLING_ENABLED
185  void sendSlaveGroupPotentialsToMaster(const GroupState<Scalar>& group_state);
186  void setReservoirCouplingMaster(ReservoirCouplingMaster<Scalar>* master) {
187  rescoup_.setMaster(master);
188  }
189  void setReservoirCouplingSlave(ReservoirCouplingSlave<Scalar>* slave) {
190  rescoup_.setSlave(slave);
191  }
192 #endif
193  DeferredLogger& deferredLogger() const { return this->well_model_.groupStateHelper().deferredLogger(); }
202  void debugDumpGuideRates(const int report_step_idx, const double sim_time);
203  const Parallel::Communication& getComm() const { return comm_; }
204  const GuideRate& guideRate() { return guide_rate_; }
205  const PhaseUsageInfo<IndexTraits>& phaseUsage() const { return well_model_.phaseUsage(); }
206  const Schedule& schedule() const { return schedule_; }
207  const SummaryState& summaryState() const { return summary_state_; }
216  void updateGuideRates(const int report_step_idx,
217  const double sim_time,
218  const WellState<Scalar, IndexTraits>& well_state,
219  GroupState<Scalar>& group_state);
220 
221  const BlackoilWellModelGeneric<Scalar, IndexTraits>& wellModel() const { return well_model_; }
222  BlackoilWellModelGeneric<Scalar, IndexTraits>& wellModel() { return well_model_; }
223 private:
224  void debugDumpGuideRatesRecursive_(const Group& group) const;
225  BlackoilWellModelGeneric<Scalar, IndexTraits>& well_model_;
226  const Schedule& schedule_;
227  const SummaryState& summary_state_;
228  const Parallel::Communication& comm_;
229  GuideRate& guide_rate_;
230  ReservoirCoupling::Proxy<Scalar> rescoup_{};
231 };
232 
233 } // namespace Opm
234 
235 #endif // OPM_GUIDERATE_HANDLER_HPP
Class for handling the blackoil well model.
Definition: ActionHandler.hpp:39
void update()
Triggers the guide rate update process for the current simulation step.
Definition: GuideRateHandler.cpp:433
ReservoirCoupling::Proxy< Scalar > & rescoup()
Get the reservoir coupling proxy.
Definition: GuideRateHandler.hpp:175
Definition: BlackoilWellModelConstraints.hpp:34
Responsible for formatting and printing guide rate information to logs.
Definition: GuideRateHandler.hpp:59
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
Definition: ReservoirCoupling.hpp:187
Definition: DeferredLogger.hpp:56
Handles computation and reporting of guide rates for wells and groups.
Definition: GuideRateHandler.hpp:46
Computes and updates guide rate values for wells and groups.
Definition: GuideRateHandler.hpp:110
void updateGuideRates(const int report_step_idx, const double sim_time, const WellState< Scalar, IndexTraits > &well_state, GroupState< Scalar > &group_state)
Updates guide rates for the current simulation step.
Definition: GuideRateHandler.cpp:123
Definition: GasLiftGroupInfo.hpp:38
Definition: ReservoirCouplingMaster.hpp:38
void debugDumpGuideRates(const int report_step_idx, const double sim_time)
Dumps guide rate information to the logger in a readable format.
Definition: GuideRateHandler.cpp:111
Thin proxy for reservoir coupling master/slave pointers.
Definition: RescoupProxy.hpp:54
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition: TemperatureModel.hpp:61
void dumpGuideRates()
Dumps guide rates for all wells and groups in a hierarchical structure.
Definition: GuideRateHandler.cpp:164