20#ifndef OPM_BLACKOIL_WELL_MODEL_NETWORK_PRESSURE_COMPUTATION_HPP
21#define OPM_BLACKOIL_WELL_MODEL_NETWORK_PRESSURE_COMPUTATION_HPP
23#include <opm/common/TimingMacros.hpp>
25#include <opm/input/eclipse/Schedule/Group/GSatProd.hpp>
26#include <opm/input/eclipse/Schedule/Network/ExtNetwork.hpp>
27#include <opm/input/eclipse/Schedule/Schedule.hpp>
28#include <opm/input/eclipse/Schedule/ScheduleState.hpp>
29#include <opm/input/eclipse/Schedule/VFPProdTable.hpp>
31#include <opm/output/data/Groups.hpp>
50template<
typename Scalar,
typename IndexTraits,
typename VfpProperties>
54template<
typename Scalar,
typename IndexTraits>
60 std::ranges::transform(rates, rates.begin(), [](
const auto r) { return -r; });
63 template <
class GroupState>
64 static const std::vector<Scalar>
70 template<
typename Branch>
73 const std::vector<Scalar>& rates,
74 const Scalar up_press,
75 const Branch& upbranch,
76 const UnitSystem& unit_system)
81 const auto alq_type = vfp_props.
getTable(table_id).getALQType();
82 const auto dimension = VFPProdTable::ALQDimension(alq_type, unit_system);
83 const Scalar alq = upbranch.alq_value(dimension).value_or(0.0);
85 return vfp_props.
bhp(table_id,
86 rates[IndexTraits::waterPhaseIdx],
87 rates[IndexTraits::oilPhaseIdx],
88 rates[IndexTraits::gasPhaseIdx],
98template<
typename Scalar,
typename IndexTraits>
105 template <
class GroupState>
106 static const std::vector<Scalar>
112 template<
typename Branch>
115 const std::vector<Scalar>& rates,
116 const Scalar up_press,
120 return vfp_props.
bhp(table_id,
121 rates[IndexTraits::waterPhaseIdx],
122 rates[IndexTraits::oilPhaseIdx],
123 rates[IndexTraits::gasPhaseIdx],
131template<
typename GenericWellModel,
typename VfpProperties,
typename Communication = Parallel::Communication>
136 const Network::ExtNetwork& network,
137 const VfpProperties& vfp_props,
138 const UnitSystem& unit_system,
139 const int report_step_idx,
141 : well_model_(well_model)
143 , vfp_props_(vfp_props)
144 , unit_system_(unit_system)
145 , report_step_idx_(report_step_idx)
150 using Scalar =
typename GenericWellModel::Scalar;
152 std::pair<std::map<std::string, Scalar>, std::map<std::string, data::BranchData>>
run()
154 const auto roots = network_.roots();
155 for (
const auto& root : roots) {
161 const auto [root_to_child_nodes, leaf_nodes] = collectTreeNodes(root.get().name());
165 auto node_inflows = initializeLeafInflows(leaf_nodes);
171 accumulateInflows(root_to_child_nodes, node_inflows);
175 computeNodePressures(root_to_child_nodes, node_inflows);
178 return {node_pressures_, branch_data_};
182 std::pair<std::vector<std::string>, std::set<std::string>>
183 collectTreeNodes(
const std::string& root)
const
185 std::stack<std::string> children;
186 std::set<std::string> leaf_nodes;
187 std::vector<std::string> root_to_child_nodes;
189 while (!children.empty()) {
190 const auto node = children.top();
192 root_to_child_nodes.push_back(node);
193 auto branches = network_.downtree_branches(node);
194 if (branches.empty()) {
195 leaf_nodes.insert(node);
197 for (
const auto& branch : branches) {
198 children.push(branch.downtree_node());
202 assert(children.empty());
203 return {root_to_child_nodes, leaf_nodes};
206 std::map<std::string, std::vector<Scalar>>
207 initializeLeafInflows(
const std::set<std::string>& leaf_nodes)
const
209 std::map<std::string, std::vector<Scalar>> node_inflows;
210 const std::vector<Scalar> zero_rates(3, 0.0);
212 for (
const auto& node : leaf_nodes) {
214 if (!well_model_.groupStateHelper().groupState().has_production_rates(node)) {
215 node_inflows[node] = zero_rates;
219 using Calc = NetworkVfpPressureCalculator<Scalar, IndexTraits, VfpProperties>;
220 node_inflows[node] = Calc::leafNodeRate(well_model_.groupStateHelper().groupState(), node);
221 if (network_.node(node).add_gas_lift_gas()) {
222 addGasLiftGas(node, node_inflows[node]);
229 void addGasLiftGas(
const std::string& node,
230 std::vector<Scalar>& rates)
const
232 const auto& group = well_model_.schedule().getGroup(node, report_step_idx_);
233 const auto& well_state = well_model_.groupStateHelper().wellState();
236 for (
const std::string& wellname : group.wells()) {
237 const Well& well = well_model_.schedule().getWell(wellname, report_step_idx_);
238 if (well.isInjector() || !well_state.isOpen(wellname)) {
242 const Scalar efficiency = well.getEfficiencyFactor(
true)
243 * well_state.getGlobalEfficiencyScalingFactor(wellname);
244 const auto& well_index = well_state.index(wellname);
245 if (well_index.has_value() &&
246 well_state.wellIsOwned(well_index.value(), wellname))
248 alq += well_state.well(wellname).alq_state.get() * efficiency;
257 alq = comm_.sum(alq);
260 if (group.hasSatelliteProduction()) {
261 const auto gsrate = this->well_model_
262 .schedule()[this->report_step_idx_]
263 .satelliteProduction(node)
264 .getRate(GSatProd::Rate::GLift, this->well_model_.summaryState());
266 alq +=
static_cast<Scalar>(gsrate);
269 rates[IndexTraits::gasPhaseIdx] += alq;
272 void accumulateInflows(
const std::vector<std::string>& root_to_child_nodes,
273 std::map<std::string, std::vector<Scalar>>& node_inflows)
const
275 const auto child_to_root_nodes = std::ranges::reverse_view(root_to_child_nodes);
277 for (
const auto& node : child_to_root_nodes) {
278 const auto upbranch = network_.uptree_branch(node);
282 std::vector<Scalar>& up = node_inflows[(*upbranch).uptree_node()];
283 const std::vector<Scalar>& down = node_inflows[node];
285 const Scalar efficiency = network_.node(node).efficiency();
287 up = std::vector<Scalar>(down.size(), 0.0);
289 assert(up.size() == down.size());
290 for (std::size_t ii = 0; ii < up.size(); ++ii) {
291 up[ii] += efficiency * down[ii];
296 void computeNodePressures(
const std::vector<std::string>& root_to_child_nodes,
297 const std::map<std::string, std::vector<Scalar>>& node_inflows)
299 for (
const auto& node : root_to_child_nodes) {
301 if (node_pressures_.find(node) != node_pressures_.end()) {
305 const auto terminal_pressure = network_.node(node).terminal_pressure();
306 const auto upbranch = network_.uptree_branch(node);
307 assert(upbranch || terminal_pressure);
308 using Calc = NetworkVfpPressureCalculator<Scalar, IndexTraits, VfpProperties>;
310 if (terminal_pressure) {
311 node_pressures_[node] = *terminal_pressure;
314 const Scalar up_press = node_pressures_[(*upbranch).uptree_node()];
315 auto rates = node_inflows.at(node);
316 branch_data_.try_emplace(node,
317 *terminal_pressure - up_press,
318 rates[IndexTraits::oilPhaseIdx],
319 rates[IndexTraits::waterPhaseIdx],
320 rates[IndexTraits::gasPhaseIdx]);
323 branch_data_.emplace(node, data::BranchData{0.0, 0.0, 0.0, 0.0});
328 const Scalar up_press = node_pressures_[(*upbranch).uptree_node()];
329 const auto vfp_table = (*upbranch).vfp_table();
332 if (network_.node(node).as_choke()) {
334 node_pressures_[node] = well_model_.groupStateHelper().groupState().well_group_thp(node);
336 node_pressures_[node] = up_press;
338 auto rates = node_inflows.at(node);
339 branch_data_.try_emplace(node,
340 node_pressures_[node] - up_press,
341 rates[IndexTraits::oilPhaseIdx],
342 rates[IndexTraits::waterPhaseIdx],
343 rates[IndexTraits::gasPhaseIdx]);
347 OPM_TIMEBLOCK(NetworkVfpCalculations);
348 auto rates = node_inflows.at(node);
349 assert(rates.size() == 3);
350 Calc::prepareRates(rates);
351 auto node_pressure = Calc::compute(vfp_props_, *vfp_table, rates, up_press, *upbranch, unit_system_);
352 node_pressures_[node] = node_pressure;
354 branch_data_.try_emplace(node,
355 node_pressure - up_press,
356 -rates[IndexTraits::oilPhaseIdx],
357 -rates[IndexTraits::waterPhaseIdx],
358 -rates[IndexTraits::gasPhaseIdx]);
362 const GenericWellModel& well_model_;
363 const Network::ExtNetwork& network_;
364 const VfpProperties& vfp_props_;
365 const UnitSystem& unit_system_;
366 const int report_step_idx_;
368 std::map<std::string, Scalar> node_pressures_;
369 std::map<std::string, data::BranchData> branch_data_;
Definition: GroupState.hpp:41
const std::vector< Scalar > & network_leaf_node_injection_rates(const std::string &gname) const
const std::vector< Scalar > & network_leaf_node_production_rates(const std::string &gname) const
Class to compute network pressures using VFP tables, given flow rates for each group and fixed pressu...
Definition: BlackoilWellModelNetworkPressureComputation.hpp:133
typename GenericWellModel::Scalar Scalar
Definition: BlackoilWellModelNetworkPressureComputation.hpp:150
std::pair< std::map< std::string, Scalar >, std::map< std::string, data::BranchData > > run()
Definition: BlackoilWellModelNetworkPressureComputation.hpp:152
GenericWellModel::IndexTraits IndexTraits
Definition: BlackoilWellModelNetworkPressureComputation.hpp:151
NetworkPressureComputation(const GenericWellModel &well_model, const Network::ExtNetwork &network, const VfpProperties &vfp_props, const UnitSystem &unit_system, const int report_step_idx, const Communication &comm)
Definition: BlackoilWellModelNetworkPressureComputation.hpp:135
Definition: VFPInjProperties.hpp:34
EvalWell bhp(const int table_id, const EvalWell &aqua, const EvalWell &liquid, const EvalWell &vapour, const Scalar thp) const
Definition: VFPProdProperties.hpp:38
EvalWell bhp(const int table_id, const EvalWell &aqua, const EvalWell &liquid, const EvalWell &vapour, const Scalar thp, const Scalar alq, const Scalar explicit_wfr, const Scalar explicit_gfr, const bool use_expvfp) const
const VFPProdTable & getTable(const int table_id) const
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: blackoilbioeffectsmodules.hh:45
static Scalar compute(const VFPInjProperties< Scalar > &vfp_props, const int table_id, const std::vector< Scalar > &rates, const Scalar up_press, const Branch &, const UnitSystem &)
Definition: BlackoilWellModelNetworkPressureComputation.hpp:113
static void prepareRates(std::vector< Scalar > &)
Definition: BlackoilWellModelNetworkPressureComputation.hpp:101
static const std::vector< Scalar > leafNodeRate(const GroupState &group_state, const std::string &node)
Definition: BlackoilWellModelNetworkPressureComputation.hpp:107
static const std::vector< Scalar > leafNodeRate(const GroupState &group_state, const std::string &node)
Definition: BlackoilWellModelNetworkPressureComputation.hpp:65
static Scalar compute(const VFPProdProperties< Scalar > &vfp_props, const int table_id, const std::vector< Scalar > &rates, const Scalar up_press, const Branch &upbranch, const UnitSystem &unit_system)
Definition: BlackoilWellModelNetworkPressureComputation.hpp:71
static void prepareRates(std::vector< Scalar > &rates)
Definition: BlackoilWellModelNetworkPressureComputation.hpp:57
Helper class to insulate the NetworkPressureComputation class from the differences between production...
Definition: BlackoilWellModelNetworkPressureComputation.hpp:51