WellBhpThpCalculator.hpp
Go to the documentation of this file.
1/*
2 Copyright 2017 SINTEF Digital, Mathematics and Cybernetics.
3 Copyright 2017 Statoil ASA.
4 Copyright 2017 IRIS
5 Copyright 2019 Norce
6
7 This file is part of the Open Porous Media project (OPM).
8
9 OPM is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 OPM is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with OPM. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23
24#ifndef OPM_WELL_BPH_THP_CALCULATOR_HEADER_INCLUDED
25#define OPM_WELL_BPH_THP_CALCULATOR_HEADER_INCLUDED
26
27#include <functional>
28#include <optional>
29#include <vector>
30
31namespace Opm {
32
33class DeferredLogger;
34class SummaryState;
35class Well;
36template<typename Scalar, typename IndexTraits> class WellInterfaceGeneric;
37template<typename Scalar, typename IndexTraits> class WellState;
38
40template<typename Scalar, typename IndexTraits>
42public:
45
47 bool wellHasTHPConstraints(const SummaryState& summaryState) const;
48
50 Scalar getTHPConstraint(const SummaryState& summaryState) const;
51
53 Scalar mostStrictBhpFromBhpLimits(const SummaryState& summaryState) const;
54
56 Scalar calculateThpFromBhp(const std::vector<Scalar>& rates,
57 const Scalar bhp,
58 const Scalar rho,
59 const std::optional<Scalar>& alq,
60 const Scalar thp_limit,
61 DeferredLogger& deferred_logger) const;
62
64 std::optional<Scalar>
65 computeBhpAtThpLimitProd(const std::function<std::vector<Scalar>(const Scalar)>& frates,
66 const SummaryState& summary_state,
67 const Scalar maxPerfPress,
68 const Scalar rho,
69 const Scalar alq_value,
70 const Scalar thp_limit,
71 DeferredLogger& deferred_logger) const;
72
74 std::optional<Scalar>
75 computeBhpAtThpLimitInj(const std::function<std::vector<Scalar>(const Scalar)>& frates,
76 const SummaryState& summary_state,
77 const Scalar rho,
78 const Scalar flo_rel_tol,
79 const int max_iteration,
80 const bool throwOnError,
81 DeferredLogger& deferred_logger) const;
82
84 void updateThp(const Scalar rho,
85 const std::function<Scalar()>& alq_value,
87 const SummaryState& summary_state,
88 DeferredLogger& deferred_logger) const;
89
90 template<class EvalWell>
92 const std::vector<EvalWell>& rates,
93 const Well& well,
94 const SummaryState& summaryState,
95 const Scalar rho,
96 DeferredLogger& deferred_logger) const;
97
99 const Well& well,
100 const SummaryState& summaryState,
101 const Scalar rho) const;
102
104 const Well& well,
105 const std::vector<Scalar>& rates,
106 const SummaryState& summaryState) const;
107
108 std::optional<Scalar>
110 const Well& well,
111 const std::vector<Scalar>& rates,
112 const Scalar rho,
113 const SummaryState& summaryState) const;
114
115 std::pair<Scalar, Scalar>
117 const Well& well,
118 const SummaryState& summary_state) const;
119
121 static bool bruteForceBracketCommonTHP(const std::function<Scalar(const Scalar)>& eq,
122 const std::array<Scalar, 2>& range,
123 Scalar& low, Scalar& high,
124 std::optional<Scalar>& approximate_solution,
125 const Scalar& limit,
126 DeferredLogger& deferred_logger);
127
129 static bool bruteForceBracketCommonTHP(const std::function<Scalar(const Scalar)>& eq,
130 Scalar& min_thp, Scalar& max_thp);
131
132private:
134 template<class ErrorPolicy>
135 std::optional<Scalar>
136 computeBhpAtThpLimitInjImpl(const std::function<std::vector<Scalar>(const Scalar)>& frates,
137 const SummaryState& summary_state,
138 const Scalar rho,
139 const Scalar flo_rel_tol,
140 const int max_iteration,
141 DeferredLogger& deferred_logger) const;
142
144 std::optional<Scalar>
145 bhpMax(const std::function<Scalar(const Scalar)>& fflo,
146 const Scalar bhp_limit,
147 const Scalar maxPerfPress,
148 const Scalar vfp_flo_front,
149 DeferredLogger& deferred_logger) const;
150
152 std::optional<Scalar>
153 computeBhpAtThpLimit(const std::function<std::vector<Scalar>(const Scalar)>& frates,
154 const std::function<Scalar(const std::vector<Scalar>)>& fbhp,
155 const std::array<Scalar, 2>& range,
156 DeferredLogger& deferred_logger) const;
157
159 Scalar getVfpBhpAdjustment(const Scalar bph_tab, const Scalar thp_limit) const;
160
162 bool bisectBracket(const std::function<Scalar(const Scalar)>& eq,
163 const std::array<Scalar, 2>& range,
164 Scalar& low, Scalar& high,
165 std::optional<Scalar>& approximate_solution,
166 DeferredLogger& deferred_logger) const;
167
169 static bool bruteForceBracket(const std::function<Scalar(const Scalar)>& eq,
170 const std::array<Scalar, 2>& range,
171 Scalar& low, Scalar& high,
172 DeferredLogger& deferred_logger);
173
174
175 Scalar findThpFromBhpIteratively(const std::function<Scalar(const Scalar, const Scalar)>& thp_func,
176 const Scalar bhp,
177 const Scalar thp_limit,
178 const Scalar dp,
179 DeferredLogger& deferred_logger) const;
180
182};
183
184}
185
186#endif // OPM_WELL_BHP_THP_CALCULATOR_HEADER_INCLUDED
Definition: DeferredLogger.hpp:57
Class for computing BHP limits.
Definition: WellBhpThpCalculator.hpp:41
WellBhpThpCalculator(const WellInterfaceGeneric< Scalar, IndexTraits > &well)
Constructor sets reference to well.
Definition: WellBhpThpCalculator.hpp:44
Scalar calculateThpFromBhp(const std::vector< Scalar > &rates, const Scalar bhp, const Scalar rho, const std::optional< Scalar > &alq, const Scalar thp_limit, DeferredLogger &deferred_logger) const
Calculates THP from BHP.
static bool bruteForceBracketCommonTHP(const std::function< Scalar(const Scalar)> &eq, const std::array< Scalar, 2 > &range, Scalar &low, Scalar &high, std::optional< Scalar > &approximate_solution, const Scalar &limit, DeferredLogger &deferred_logger)
Find limits using brute-force solver.
std::optional< Scalar > computeBhpAtThpLimitProd(const std::function< std::vector< Scalar >(const Scalar)> &frates, const SummaryState &summary_state, const Scalar maxPerfPress, const Scalar rho, const Scalar alq_value, const Scalar thp_limit, DeferredLogger &deferred_logger) const
Compute BHP from THP limit for a producer.
Scalar calculateMinimumBhpFromThp(const WellState< Scalar, IndexTraits > &well_state, const Well &well, const SummaryState &summaryState, const Scalar rho) const
std::pair< Scalar, Scalar > getFloIPR(const WellState< Scalar, IndexTraits > &well_state, const Well &well, const SummaryState &summary_state) const
Scalar mostStrictBhpFromBhpLimits(const SummaryState &summaryState) const
Obtain the most strict BHP from BHP limits.
void updateThp(const Scalar rho, const std::function< Scalar()> &alq_value, WellState< Scalar, IndexTraits > &well_state, const SummaryState &summary_state, DeferredLogger &deferred_logger) const
Update THP.
bool isStableSolution(const WellState< Scalar, IndexTraits > &well_state, const Well &well, const std::vector< Scalar > &rates, const SummaryState &summaryState) const
Scalar getTHPConstraint(const SummaryState &summaryState) const
Get THP constraint for well.
EvalWell calculateBhpFromThp(const WellState< Scalar, IndexTraits > &well_state, const std::vector< EvalWell > &rates, const Well &well, const SummaryState &summaryState, const Scalar rho, DeferredLogger &deferred_logger) const
static bool bruteForceBracketCommonTHP(const std::function< Scalar(const Scalar)> &eq, Scalar &min_thp, Scalar &max_thp)
Find limits using brute-force solver.
std::optional< Scalar > computeBhpAtThpLimitInj(const std::function< std::vector< Scalar >(const Scalar)> &frates, const SummaryState &summary_state, const Scalar rho, const Scalar flo_rel_tol, const int max_iteration, const bool throwOnError, DeferredLogger &deferred_logger) const
Compute BHP from THP limit for an injector.
bool wellHasTHPConstraints(const SummaryState &summaryState) const
Checks if well has THP constraints.
std::optional< Scalar > estimateStableBhp(const WellState< Scalar, IndexTraits > &well_state, const Well &well, const std::vector< Scalar > &rates, const Scalar rho, const SummaryState &summaryState) const
Definition: WellInterfaceGeneric.hpp:53
Definition: WellState.hpp:66
Definition: blackoilboundaryratevector.hh:39