My Project
WellBhpThpCalculator.hpp
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 <string>
30#include <vector>
31
32namespace Opm
33{
34
35class DeferredLogger;
36class SummaryState;
37class Well;
38class WellInterfaceGeneric;
39class WellState;
40
43public:
45 WellBhpThpCalculator(const WellInterfaceGeneric& well) : well_(well) {}
46
48 bool wellHasTHPConstraints(const SummaryState& summaryState) const;
49
51 double getTHPConstraint(const SummaryState& summaryState) const;
52
54 double mostStrictBhpFromBhpLimits(const SummaryState& summaryState) const;
55
57 double calculateThpFromBhp(const std::vector<double>& rates,
58 const double bhp,
59 const double rho,
60 const double alq,
61 DeferredLogger& deferred_logger) const;
62
64 std::optional<double>
65 computeBhpAtThpLimitProd(const std::function<std::vector<double>(const double)>& frates,
66 const SummaryState& summary_state,
67 const double maxPerfPress,
68 const double rho,
69 const double alq_value,
70 const double thp_limit,
71 DeferredLogger& deferred_logger) const;
72
74 std::optional<double>
75 computeBhpAtThpLimitInj(const std::function<std::vector<double>(const double)>& frates,
76 const SummaryState& summary_state,
77 const double rho,
78 const double flo_rel_tol,
79 const int max_iteration,
80 const bool throwOnError,
81 DeferredLogger& deferred_logger) const;
82
84 void updateThp(const double rho,
85 const bool stop_or_zero_rate_target,
86 const std::function<double()>& alq_value,
87 const std::array<unsigned,3>& active,
88 WellState& well_state,
89 DeferredLogger& deferred_logger) const;
90
91 template<class EvalWell>
92 EvalWell calculateBhpFromThp(const WellState& well_state,
93 const std::vector<EvalWell>& rates,
94 const Well& well,
95 const SummaryState& summaryState,
96 const double rho,
97 DeferredLogger& deferred_logger) const;
98
99private:
101 template<class ErrorPolicy>
102 std::optional<double>
103 computeBhpAtThpLimitInjImpl(const std::function<std::vector<double>(const double)>& frates,
104 const SummaryState& summary_state,
105 const double rho,
106 const double flo_rel_tol,
107 const int max_iteration,
108 DeferredLogger& deferred_logger) const;
109
111 std::optional<double>
112 bhpMax(const std::function<double(const double)>& fflo,
113 const double bhp_limit,
114 const double maxPerfPress,
115 const double vfp_flo_front,
116 DeferredLogger& deferred_logger) const;
117
119 std::optional<double>
120 computeBhpAtThpLimit(const std::function<std::vector<double>(const double)>& frates,
121 const std::function<double(const std::vector<double>)>& fbhp,
122 const std::array<double, 2>& range,
123 DeferredLogger& deferred_logger) const;
124
126 bool bisectBracket(const std::function<double(const double)>& eq,
127 const std::array<double, 2>& range,
128 double& low, double& high,
129 std::optional<double>& approximate_solution,
130 DeferredLogger& deferred_logger) const;
131
133 static bool bruteForceBracket(const std::function<double(const double)>& eq,
134 const std::array<double, 2>& range,
135 double& low, double& high,
136 DeferredLogger& deferred_logger);
137
138 const WellInterfaceGeneric& well_;
139};
140
141}
142
143#endif // OPM_WELL_BHP_THP_CALCULATOR_HEADER_INCLUDED
Definition: DeferredLogger.hpp:57
Class for computing BHP limits.
Definition: WellBhpThpCalculator.hpp:42
void updateThp(const double rho, const bool stop_or_zero_rate_target, const std::function< double()> &alq_value, const std::array< unsigned, 3 > &active, WellState &well_state, DeferredLogger &deferred_logger) const
Update THP.
Definition: WellBhpThpCalculator.cpp:226
std::optional< double > computeBhpAtThpLimitProd(const std::function< std::vector< double >(const double)> &frates, const SummaryState &summary_state, const double maxPerfPress, const double rho, const double alq_value, const double thp_limit, DeferredLogger &deferred_logger) const
Compute BHP from THP limit for a producer.
Definition: WellBhpThpCalculator.cpp:142
double mostStrictBhpFromBhpLimits(const SummaryState &summaryState) const
Obtain the most strict BHP from BHP limits.
Definition: WellBhpThpCalculator.cpp:85
bool wellHasTHPConstraints(const SummaryState &summaryState) const
Checks if well has THP constraints.
Definition: WellBhpThpCalculator.cpp:51
double calculateThpFromBhp(const std::vector< double > &rates, const double bhp, const double rho, const double alq, DeferredLogger &deferred_logger) const
Calculates THP from BHP.
Definition: WellBhpThpCalculator.cpp:101
double getTHPConstraint(const SummaryState &summaryState) const
Get THP constraint for well.
Definition: WellBhpThpCalculator.cpp:69
std::optional< double > computeBhpAtThpLimitInj(const std::function< std::vector< double >(const double)> &frates, const SummaryState &summary_state, const double rho, const double flo_rel_tol, const int max_iteration, const bool throwOnError, DeferredLogger &deferred_logger) const
Compute BHP from THP limit for an injector.
Definition: WellBhpThpCalculator.cpp:207
WellBhpThpCalculator(const WellInterfaceGeneric &well)
Constructor sets reference to well.
Definition: WellBhpThpCalculator.hpp:45
Definition: WellInterfaceGeneric.hpp:51
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition: WellState.hpp:60
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27