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/Network/ExtNetwork.hpp>
26#include <opm/input/eclipse/Schedule/Schedule.hpp>
27#include <opm/input/eclipse/Schedule/VFPProdTable.hpp>
46template<
typename Scalar,
typename IndexTraits,
typename VfpProperties>
50template<
typename Scalar,
typename IndexTraits>
56 std::ranges::transform(rates, rates.begin(), [](
const auto r) { return -r; });
59 template <
class GroupState>
60 static const std::vector<Scalar>
66 template<
typename Branch>
69 const std::vector<Scalar>& rates,
70 const Scalar up_press,
71 const Branch& upbranch,
72 const UnitSystem& unit_system)
77 const auto alq_type = vfp_props.
getTable(table_id).getALQType();
78 const auto dimension = VFPProdTable::ALQDimension(alq_type, unit_system);
79 const Scalar alq = upbranch.alq_value(dimension).value_or(0.0);
81 return vfp_props.
bhp(table_id,
82 rates[IndexTraits::waterPhaseIdx],
83 rates[IndexTraits::oilPhaseIdx],
84 rates[IndexTraits::gasPhaseIdx],
94template<
typename Scalar,
typename IndexTraits>
101 template <
class GroupState>
102 static const std::vector<Scalar>
108 template<
typename Branch>
111 const std::vector<Scalar>& rates,
112 const Scalar up_press,
116 return vfp_props.
bhp(table_id,
117 rates[IndexTraits::waterPhaseIdx],
118 rates[IndexTraits::oilPhaseIdx],
119 rates[IndexTraits::gasPhaseIdx],
127template<
typename GenericWellModel,
typename VfpProperties,
typename Communication = Parallel::Communication>
132 const Network::ExtNetwork& network,
133 const VfpProperties& vfp_props,
134 const UnitSystem& unit_system,
135 const int report_step_idx,
137 : well_model_(well_model)
139 , vfp_props_(vfp_props)
140 , unit_system_(unit_system)
141 , report_step_idx_(report_step_idx)
146 using Scalar =
typename GenericWellModel::Scalar;
149 std::map<std::string, Scalar>
run()
151 const auto roots = network_.roots();
152 for (
const auto& root : roots) {
158 const auto [root_to_child_nodes, leaf_nodes] = collectTreeNodes(root.get().name());
162 auto node_inflows = initializeLeafInflows(leaf_nodes);
168 accumulateInflows(root_to_child_nodes, node_inflows);
172 computeNodePressures(root_to_child_nodes, node_inflows);
175 return node_pressures_;
179 std::pair<std::vector<std::string>, std::set<std::string>>
180 collectTreeNodes(
const std::string& root)
const
182 std::stack<std::string> children;
183 std::set<std::string> leaf_nodes;
184 std::vector<std::string> root_to_child_nodes;
186 while (!children.empty()) {
187 const auto node = children.top();
189 root_to_child_nodes.push_back(node);
190 auto branches = network_.downtree_branches(node);
191 if (branches.empty()) {
192 leaf_nodes.insert(node);
194 for (
const auto& branch : branches) {
195 children.push(branch.downtree_node());
199 assert(children.empty());
200 return {root_to_child_nodes, leaf_nodes};
203 std::map<std::string, std::vector<Scalar>>
204 initializeLeafInflows(
const std::set<std::string>& leaf_nodes)
const
206 std::map<std::string, std::vector<Scalar>> node_inflows;
207 const std::vector<Scalar> zero_rates(3, 0.0);
209 for (
const auto& node : leaf_nodes) {
211 if (!well_model_.groupStateHelper().groupState().has_production_rates(node)) {
212 node_inflows[node] = zero_rates;
216 using Calc = NetworkVfpPressureCalculator<Scalar, IndexTraits, VfpProperties>;
217 node_inflows[node] = Calc::leafNodeRate(well_model_.groupStateHelper().groupState(), node);
218 if (network_.node(node).add_gas_lift_gas()) {
219 addGasLiftGas(node, node_inflows[node]);
226 void addGasLiftGas(
const std::string& node,
227 std::vector<Scalar>& rates)
const
229 const auto& group = well_model_.schedule().getGroup(node, report_step_idx_);
230 const auto& well_state = well_model_.groupStateHelper().wellState();
233 for (
const std::string& wellname : group.wells()) {
234 const Well& well = well_model_.schedule().getWell(wellname, report_step_idx_);
235 if (well.isInjector() || !well_state.isOpen(wellname)) {
239 const Scalar efficiency = well.getEfficiencyFactor(
true)
240 * well_state.getGlobalEfficiencyScalingFactor(wellname);
241 const auto& well_index = well_state.index(wellname);
242 if (well_index.has_value() &&
243 well_state.wellIsOwned(well_index.value(), wellname))
245 alq += well_state.well(wellname).alq_state.get() * efficiency;
254 alq = comm_.sum(alq);
257 if (group.hasSatelliteProduction()) {
258 const auto& gsat_prod = well_model_.schedule()[report_step_idx_].gsatprod().get(node, well_model_.summaryState());
259 alq += gsat_prod.rate[GSatProd::GSatProdGroupProp::Rate::GLift];
262 rates[IndexTraits::gasPhaseIdx] += alq;
265 void accumulateInflows(
const std::vector<std::string>& root_to_child_nodes,
266 std::map<std::string, std::vector<Scalar>>& node_inflows)
const
268 const auto child_to_root_nodes = std::ranges::reverse_view(root_to_child_nodes);
270 for (
const auto& node : child_to_root_nodes) {
271 const auto upbranch = network_.uptree_branch(node);
275 std::vector<Scalar>& up = node_inflows[(*upbranch).uptree_node()];
276 const std::vector<Scalar>& down = node_inflows[node];
278 const Scalar efficiency = network_.node(node).efficiency();
280 up = std::vector<Scalar>(down.size(), 0.0);
282 assert(up.size() == down.size());
283 for (std::size_t ii = 0; ii < up.size(); ++ii) {
284 up[ii] += efficiency * down[ii];
289 void computeNodePressures(
const std::vector<std::string>& root_to_child_nodes,
290 const std::map<std::string, std::vector<Scalar>>& node_inflows)
292 for (
const auto& node : root_to_child_nodes) {
293 const auto terminal_pressure = network_.node(node).terminal_pressure();
294 if (terminal_pressure) {
295 node_pressures_[node] = *terminal_pressure;
299 const auto upbranch = network_.uptree_branch(node);
301 const Scalar up_press = node_pressures_[(*upbranch).uptree_node()];
302 const auto vfp_table = (*upbranch).vfp_table();
305 if (network_.node(node).as_choke()) {
307 node_pressures_[node] = well_model_.groupStateHelper().groupState().well_group_thp(node);
309 node_pressures_[node] = up_press;
314 OPM_TIMEBLOCK(NetworkVfpCalculations);
315 auto rates = node_inflows.at(node);
316 assert(rates.size() == 3);
317 using Calc = NetworkVfpPressureCalculator<Scalar, IndexTraits, VfpProperties>;
318 Calc::prepareRates(rates);
319 node_pressures_[node]
320 = Calc::compute(vfp_props_, *vfp_table, rates, up_press, *upbranch, unit_system_);
324 const GenericWellModel& well_model_;
325 const Network::ExtNetwork& network_;
326 const VfpProperties& vfp_props_;
327 const UnitSystem& unit_system_;
328 const int report_step_idx_;
330 std::map<std::string, Scalar> node_pressures_;
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:129
typename GenericWellModel::Scalar Scalar
Definition: BlackoilWellModelNetworkPressureComputation.hpp:146
GenericWellModel::IndexTraits IndexTraits
Definition: BlackoilWellModelNetworkPressureComputation.hpp:147
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:131
std::map< std::string, Scalar > run()
Definition: BlackoilWellModelNetworkPressureComputation.hpp:149
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:109
static void prepareRates(std::vector< Scalar > &)
Definition: BlackoilWellModelNetworkPressureComputation.hpp:97
static const std::vector< Scalar > leafNodeRate(const GroupState &group_state, const std::string &node)
Definition: BlackoilWellModelNetworkPressureComputation.hpp:103
static const std::vector< Scalar > leafNodeRate(const GroupState &group_state, const std::string &node)
Definition: BlackoilWellModelNetworkPressureComputation.hpp:61
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:67
static void prepareRates(std::vector< Scalar > &rates)
Definition: BlackoilWellModelNetworkPressureComputation.hpp:53
Helper class to insulate the NetworkPressureComputation class from the differences between production...
Definition: BlackoilWellModelNetworkPressureComputation.hpp:47