opm-simulators
VFPHelpers.hpp
1 /*
2  Copyright 2015 SINTEF ICT, Applied Mathematics.
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 
21 #ifndef OPM_AUTODIFF_VFPHELPERS_HPP_
22 #define OPM_AUTODIFF_VFPHELPERS_HPP_
23 
24 #include <functional>
25 #include <map>
26 #include <vector>
27 #include <optional>
28 
32 namespace Opm {
33 
34 class VFPInjTable;
35 class VFPProdTable;
36 
37 namespace detail {
38 
42 template<class Scalar>
44 {
45  VFPEvaluation() : value(0.0), dthp(0.0), dwfr(0.0), dgfr(0.0), dalq(0.0), dflo(0.0) {};
46  Scalar value;
47  Scalar dthp;
48  Scalar dwfr;
49  Scalar dgfr;
50  Scalar dalq;
51  Scalar dflo;
52 };
53 
54 template<class Scalar>
56 template<class Scalar>
58 template<class Scalar>
59 VFPEvaluation<Scalar> operator*(Scalar lhs, const VFPEvaluation<Scalar>& rhs);
60 
64 template<class Scalar>
65 struct InterpData
66 {
67  InterpData() : ind_{0, 0}, inv_dist_(0.0), factor_(0.0) {}
68  int ind_[2]; //[First element greater than or equal to value, Last element smaller than or equal to value]
69  Scalar inv_dist_; // 1 / distance between the two end points of the segment. Used to calculate derivatives and uses 1.0 / 0.0 = 0.0 as a convention
70  Scalar factor_; // Interpolation factor
71 };
72 
78 template <typename T>
79 T getFlo(const VFPProdTable& table,
80  const T& aqua,
81  const T& liquid,
82  const T& vapour);
83 
89 template <typename T>
90 T getFlo(const VFPInjTable& table,
91  const T& aqua,
92  const T& liquid,
93  const T& vapour);
94 
99 template <typename T>
100 T getWFR(const VFPProdTable& table,
101  const T& aqua,
102  const T& liquid,
103  const T& vapour);
104 
109 template <typename T>
110 T getGFR(const VFPProdTable& table,
111  const T& aqua,
112  const T& liquid,
113  const T& vapour);
114 
118 template <typename T>
119 const T& getTable(const std::map<int, std::reference_wrapper<const T>>& tables, int table_id);
120 
124 template <typename T>
125 bool hasTable(const std::map<int, std::reference_wrapper<const T>>& tables, int table_id) {
126  const auto entry = tables.find(table_id);
127  return (entry != tables.end() );
128 }
129 
133 template <typename TYPE, typename TABLE>
134 TYPE getType(const TABLE& table);
135 
136 }
137 
138 template<class Scalar>
139 class VFPHelpers {
140 public:
147  static detail::InterpData<Scalar> findInterpData(const Scalar value_in,
148  const std::vector<double>& values);
149 
153  static detail::VFPEvaluation<Scalar> interpolate(const VFPProdTable& table,
154  const detail::InterpData<Scalar>& flo_i,
155  const detail::InterpData<Scalar>& thp_i,
156  const detail::InterpData<Scalar>& wfr_i,
157  const detail::InterpData<Scalar>& gfr_i,
158  const detail::InterpData<Scalar>& alq_i);
159 
164  static detail::VFPEvaluation<Scalar> interpolate(const VFPInjTable& table,
165  const detail::InterpData<Scalar>& flo_i,
166  const detail::InterpData<Scalar>& thp_i);
167 
168  static detail::VFPEvaluation<Scalar> bhp(const VFPProdTable& table,
169  const Scalar aqua,
170  const Scalar liquid,
171  const Scalar vapour,
172  const Scalar thp,
173  const Scalar alq,
174  const Scalar explicit_wfr,
175  const Scalar explicit_gfr,
176  const bool use_vfpexplicit);
177 
178  static detail::VFPEvaluation<Scalar> bhp(const VFPInjTable& table,
179  const Scalar aqua,
180  const Scalar liquid,
181  const Scalar vapour,
182  const Scalar thp);
183 
190  static Scalar findTHP(const std::vector<Scalar>& bhp_array,
191  const std::vector<double>& thp_array,
192  Scalar bhp,
193  const bool find_largest = true);
194 
198  static std::pair<Scalar, Scalar>
199  getMinimumBHPCoordinate(const VFPProdTable& table,
200  const Scalar thp,
201  const Scalar wfr,
202  const Scalar gfr,
203  const Scalar alq);
204 
209  static std::optional<std::pair<Scalar, Scalar>>
210  intersectWithIPR(const VFPProdTable& table,
211  const Scalar thp,
212  const Scalar wfr,
213  const Scalar gfr,
214  const Scalar alq,
215  const Scalar ipr_a,
216  const Scalar ipr_b,
217  const std::function<Scalar(const Scalar)>& adjust_bhp);
218 };
219 
220 } // namespace
221 
222 #endif /* OPM_AUTODIFF_VFPHELPERS_HPP_ */
static detail::VFPEvaluation< Scalar > interpolate(const VFPProdTable &table, const detail::InterpData< Scalar > &flo_i, const detail::InterpData< Scalar > &thp_i, const detail::InterpData< Scalar > &wfr_i, const detail::InterpData< Scalar > &gfr_i, const detail::InterpData< Scalar > &alq_i)
Helper function which interpolates data using the indices etc.
Definition: VFPHelpers.cpp:146
An "ADB-like" structure with a single value and a set of derivatives.
Definition: VFPHelpers.hpp:43
static std::optional< std::pair< Scalar, Scalar > > intersectWithIPR(const VFPProdTable &table, const Scalar thp, const Scalar wfr, const Scalar gfr, const Scalar alq, const Scalar ipr_a, const Scalar ipr_b, const std::function< Scalar(const Scalar)> &adjust_bhp)
Get (flo, bhp) at largest occuring stable vfp/ipr-intersection if it exists.
Definition: VFPHelpers.cpp:551
static std::pair< Scalar, Scalar > getMinimumBHPCoordinate(const VFPProdTable &table, const Scalar thp, const Scalar wfr, const Scalar gfr, const Scalar alq)
Get (flo, bhp) at minimum bhp for given thp,wfr,gfr,alq.
Definition: VFPHelpers.cpp:518
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
Helper struct for linear interpolation.
Definition: VFPHelpers.hpp:65
static Scalar findTHP(const std::vector< Scalar > &bhp_array, const std::vector< double > &thp_array, Scalar bhp, const bool find_largest=true)
This function finds the value of THP given a specific BHP.
Definition: VFPHelpers.cpp:365
Definition: VFPHelpers.hpp:139
static detail::InterpData< Scalar > findInterpData(const Scalar value_in, const std::vector< double > &values)
Helper function to find indices etc.
Definition: VFPHelpers.cpp:84