GuideRateHandler.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
20#ifndef OPM_GUIDERATE_HANDLER_HPP
21#define OPM_GUIDERATE_HANDLER_HPP
22
23#if HAVE_MPI
24#define RESERVOIR_COUPLING_ENABLED
25#endif
26#ifdef RESERVOIR_COUPLING_ENABLED
30#endif
31#include <opm/input/eclipse/Schedule/Group/GuideRate.hpp>
32#include <opm/output/data/Groups.hpp>
33#include <opm/output/data/GuideRateValue.hpp>
40namespace Opm {
41
53template<class Scalar>
55public:
56#ifdef RESERVOIR_COUPLING_ENABLED
58#endif
59
67 public:
69 GuideRateHandler<Scalar> &parent, const int report_step_idx, const double sim_time
70 );
71
72 DeferredLogger &deferredLogger() { return this->parent_.deferredLogger(); }
77 private:
78 void dumpGuideRatesRecursive_(const Group& group, int level);
79 void getGroupGuideRatesInjection_(
80 const Group& group,
81 const data::GroupGuideRates& group_guide_rate,
82 std::vector<std::string>& msg_items
83 ) const;
84 void getGroupGuideRatesProduction_(
85 const Group& group,
86 const data::GroupGuideRates& group_guide_rate,
87 std::vector<std::string>& msg_items
88 ) const;
95 void printGroupGuideRates_(const Group& group, int level);
96 void printHeader_();
97 void printFooter_();
98 void printWellGuideRates_(const Well& well, int level);
99
101 const int report_step_idx_;
102 const double sim_time_;
103 const BlackoilWellModelGeneric<Scalar>& well_model_;
104 const Schedule& schedule_;
105 const Parallel::Communication& comm_;
106 std::unordered_map<std::string, data::GuideRateValue> well_guide_rates_;
107 std::unordered_map<std::string, data::GroupGuideRates> group_guide_rates_;
108 };
109
118 public:
121 const int report_step_idx,
122 const double sim_time,
123 const WellState<Scalar> &well_state,
124 GroupState<Scalar> &group_state,
125 const int num_phases
126 );
127
128#ifdef RESERVOIR_COUPLING_ENABLED
129 bool isReservoirCouplingMaster() const { return this->parent_.isReservoirCouplingMaster(); }
131 return this->parent_.reservoirCouplingMaster();
132 }
133#endif
134 const Parallel::Communication &comm() const { return this->parent_.comm_; }
135 DeferredLogger &deferredLogger() { return this->parent_.deferredLogger(); }
136 GuideRate &guideRate() { return this->parent_.guide_rate_; }
137 const PhaseUsage &phaseUsage() const { return this->parent_.phase_usage_; }
138 const SummaryState &summaryState() const { return this->parent_.summary_state_; }
139 const Schedule &schedule() const { return this->parent_.schedule_; }
143 void update();
144
145 private:
146#ifdef RESERVOIR_COUPLING_ENABLED
147 bool isMasterGroup_(const Group& group);
148#endif
149 void updateGuideRatesForInjectionGroups_(const Group& group);
156 void updateGuideRatesForProductionGroups_(const Group& group, std::vector<Scalar>& pot);
157 void updateGuideRatesForWells_();
158#ifdef RESERVOIR_COUPLING_ENABLED
159 void updateProductionGroupPotentialFromSlaveGroup_(
160 const Group& group, std::vector<Scalar>& pot);
161#endif
162 void updateProductionGroupPotentialFromSubGroups(
163 const Group& group, std::vector<Scalar>& pot);
164
166 const int report_step_idx_;
167 const double sim_time_;
168 const WellState<Scalar> &well_state_;
169 GroupState<Scalar> &group_state_;
170 const int num_phases_;
171 const UnitSystem& unit_system_;
172 };
173
176 const Schedule& schedule,
177 const SummaryState& summary_state,
178 const Parallel::Communication& comm
179 );
180
181#ifdef RESERVOIR_COUPLING_ENABLED
183 return this->reservoir_coupling_master_ != nullptr;
184 }
186 return this->reservoir_coupling_slave_ != nullptr;
187 }
189 ReservoirCouplingMaster& reservoirCouplingMaster() { return *(this->reservoir_coupling_master_); }
190 ReservoirCouplingSlave& reservoirCouplingSlave() { return *(this->reservoir_coupling_slave_); }
192 void setReservoirCouplingMaster(ReservoirCouplingMaster *reservoir_coupling_master) {
193 this->reservoir_coupling_master_ = reservoir_coupling_master;
194 }
195 void setReservoirCouplingSlave(ReservoirCouplingSlave *reservoir_coupling_slave) {
196 this->reservoir_coupling_slave_ = reservoir_coupling_slave;
197 }
198#endif
208 void debugDumpGuideRates(const int report_step_idx, const double sim_time);
209 const Parallel::Communication& getComm() const { return comm_; }
210 void setLogger(DeferredLogger *deferred_logger);
211 const Schedule& schedule() const { return schedule_; }
220 void updateGuideRates(const int report_step_idx,
221 const double sim_time,
222 const WellState<Scalar>& well_state,
223 GroupState<Scalar>& group_state);
224
225 const BlackoilWellModelGeneric<Scalar>& wellModel() const { return well_model_; }
226
227private:
228 void debugDumpGuideRatesRecursive_(const Group& group) const;
230 const Schedule& schedule_;
231 const SummaryState& summary_state_;
232 const Parallel::Communication& comm_;
233 const PhaseUsage& phase_usage_;
234 GuideRate& guide_rate_;
235 DeferredLogger *deferred_logger_ = nullptr;
236#ifdef RESERVOIR_COUPLING_ENABLED
237 ReservoirCouplingMaster *reservoir_coupling_master_ = nullptr;
238 ReservoirCouplingSlave *reservoir_coupling_slave_ = nullptr;
239#endif
240};
241
242} // namespace Opm
243
244#endif // OPM_GUIDERATE_HANDLER_HPP
Class for handling the blackoil well model.
Definition: BlackoilWellModelGeneric.hpp:94
Definition: DeferredLogger.hpp:57
Definition: GroupState.hpp:43
Responsible for formatting and printing guide rate information to logs.
Definition: GuideRateHandler.hpp:66
DeferredLogger & deferredLogger()
Definition: GuideRateHandler.hpp:72
GuideRateDumper(GuideRateHandler< Scalar > &parent, const int report_step_idx, const double sim_time)
void dumpGuideRates()
Dumps guide rates for all wells and groups in a hierarchical structure.
Computes and updates guide rate values for wells and groups.
Definition: GuideRateHandler.hpp:117
const Parallel::Communication & comm() const
Definition: GuideRateHandler.hpp:134
GuideRate & guideRate()
Definition: GuideRateHandler.hpp:136
const PhaseUsage & phaseUsage() const
Definition: GuideRateHandler.hpp:137
void update()
Triggers the guide rate update process for the current simulation step.
bool isReservoirCouplingMaster() const
Definition: GuideRateHandler.hpp:129
const Schedule & schedule() const
Definition: GuideRateHandler.hpp:139
const SummaryState & summaryState() const
Definition: GuideRateHandler.hpp:138
UpdateGuideRates(GuideRateHandler< Scalar > &parent, const int report_step_idx, const double sim_time, const WellState< Scalar > &well_state, GroupState< Scalar > &group_state, const int num_phases)
DeferredLogger & deferredLogger()
Definition: GuideRateHandler.hpp:135
ReservoirCouplingMaster & reservoirCouplingMaster()
Definition: GuideRateHandler.hpp:130
Handles computation and reporting of guide rates for wells and groups.
Definition: GuideRateHandler.hpp:54
void setLogger(DeferredLogger *deferred_logger)
void updateGuideRates(const int report_step_idx, const double sim_time, const WellState< Scalar > &well_state, GroupState< Scalar > &group_state)
Updates guide rates for the current simulation step.
DeferredLogger & deferredLogger()
void setReservoirCouplingSlave(ReservoirCouplingSlave *reservoir_coupling_slave)
Definition: GuideRateHandler.hpp:195
bool isReservoirCouplingMaster() const
Definition: GuideRateHandler.hpp:182
void debugDumpGuideRates(const int report_step_idx, const double sim_time)
Dumps guide rate information to the logger in a readable format.
GuideRateHandler(BlackoilWellModelGeneric< Scalar > &well_model, const Schedule &schedule, const SummaryState &summary_state, const Parallel::Communication &comm)
ReservoirCouplingMaster & reservoirCouplingMaster()
Definition: GuideRateHandler.hpp:189
const Schedule & schedule() const
Definition: GuideRateHandler.hpp:211
void sendSlaveGroupPotentialsToMaster(const GroupState< Scalar > &group_state)
bool isReservoirCouplingSlave() const
Definition: GuideRateHandler.hpp:185
void receiveMasterGroupPotentialsFromSlaves()
void setReservoirCouplingMaster(ReservoirCouplingMaster *reservoir_coupling_master)
Definition: GuideRateHandler.hpp:192
const Parallel::Communication & getComm() const
Definition: GuideRateHandler.hpp:209
ReservoirCouplingSlave & reservoirCouplingSlave()
Definition: GuideRateHandler.hpp:190
const BlackoilWellModelGeneric< Scalar > & wellModel() const
Definition: GuideRateHandler.hpp:225
Definition: ReservoirCouplingMaster.hpp:35
Definition: ReservoirCouplingSlave.hpp:35
Definition: WellState.hpp:65
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: blackoilboundaryratevector.hh:39
Definition: BlackoilPhases.hpp:46
Definition: ReservoirCoupling.hpp:62