-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdptable.cpp
More file actions
229 lines (169 loc) · 7.09 KB
/
dptable.cpp
File metadata and controls
229 lines (169 loc) · 7.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#include "dptable.h"
#include <iostream>
using std::cout;
using std::endl;
namespace ResOpt
{
DpTable::DpTable()
{
}
//-----------------------------------------------------------------------------------------------
// Adds a row of data to the tables
//-----------------------------------------------------------------------------------------------
void DpTable::addRow(double dp, double gas, double oil, double water)
{
m_dp.push_back(dp);
m_gas.push_back(gas);
m_oil.push_back(oil);
m_wat.push_back(water);
}
//-----------------------------------------------------------------------------------------------
// finds the uniquie entries for the gas, oil, and water
//-----------------------------------------------------------------------------------------------
void DpTable::process()
{
for(int i = 0; i < numberOfRows(); ++i)
{
// the gas
if(!m_entries_gas.contains(m_gas.at(i))) m_entries_gas.push_back(m_gas.at(i));
// the oil
if(!m_entries_oil.contains(m_oil.at(i))) m_entries_oil.push_back(m_oil.at(i));
// the water
if(!m_entries_wat.contains(m_wat.at(i))) m_entries_wat.push_back(m_wat.at(i));
}
// sorting the entries
qSort(m_entries_gas.begin(), m_entries_gas.end());
qSort(m_entries_oil.begin(), m_entries_oil.end());
qSort(m_entries_wat.begin(), m_entries_wat.end());
}
//-----------------------------------------------------------------------------------------------
// finds the index for the upper gas, oil, and water in the entries lists
//-----------------------------------------------------------------------------------------------
QList<int> DpTable::findUpperEntries(double gas, double oil, double water)
{
int i_g = 0;
int i_o = 0;
int i_w = 0;
QList<int> indexes;
// finding the entry index for gas
for(int i = 0; i < m_entries_gas.size(); ++i)
{
if(m_entries_gas.at(i) > gas)
{
i_g = i;
break;
}
}
// finding the entry index for oil
for(int i = 0; i < m_entries_oil.size(); ++i)
{
if(m_entries_oil.at(i) > oil)
{
i_o = i;
break;
}
}
// finding the entry index for water
for(int i = 0; i < m_entries_wat.size(); ++i)
{
if(m_entries_wat.at(i) > water)
{
i_w = i;
break;
}
}
// populating the list
indexes << i_g << i_o << i_w;
return indexes;
}
//-----------------------------------------------------------------------------------------------
// finds the index in the main table that corresponds to the entries in the entries table
//-----------------------------------------------------------------------------------------------
int DpTable::findTableIndex(int gas_entry, int oil_entry, int water_entry)
{
int index = 0;
double gas = m_entries_gas.at(gas_entry);
double oil = m_entries_oil.at(oil_entry);
double water = m_entries_wat.at(water_entry);
for(int i = 0; i < m_gas.size(); ++i)
{
// first checknig the gas rate
if(m_gas.at(i) == gas)
{
// then checking the oil rate
if(m_oil.at(i) == oil)
{
// then checking the water rate
if(m_wat.at(i) == water)
{
index = i;
break;
} // water
} // oil
} // gas
} // for loop
return index;
}
//-----------------------------------------------------------------------------------------------
// interpolates the table, returns the pressure drop
//-----------------------------------------------------------------------------------------------
double DpTable::interpolate(double gas, double oil, double water)
{
// processing the table if not already done
if(m_entries_gas.size() == 0) process();
// checking that the desired point lies within the table
if(gas < m_entries_gas.at(0) || gas > m_entries_gas.at(m_entries_gas.size() - 1))
{
cout << endl << "### Runtime Error ###" << endl
<< "The specified gas rate falls outside the range of the DP table..." << endl
<< "QG : " << gas << endl
<< "QG_MAX: " << m_entries_gas.at(m_entries_gas.size() - 1) << endl
<< "QG_MIN: " << m_entries_gas.at(0) << endl;
return 1000;
}
if(oil < m_entries_oil.at(0) || oil > m_entries_oil.at(m_entries_oil.size() - 1))
{
cout << endl << "### Runtime Error ###" << endl
<< "The specified oil rate falls outside the range of the DP table..." << endl
<< "QO : " << oil << endl
<< "QO_MAX: " << m_entries_oil.at(m_entries_oil.size() - 1) << endl
<< "QO_MIN: " << m_entries_oil.at(0) << endl;
return 1000;
}
if(water < m_entries_wat.at(0) || water > m_entries_wat.at(m_entries_wat.size() - 1))
{
cout << endl << "### Runtime Error ###" << endl
<< "The specified water rate falls outside the range of the DP table..." << endl
<< "QW : " << water << endl
<< "QW_MAX: " << m_entries_wat.at(m_entries_wat.size() - 1) << endl
<< "QW_MIN: " << m_entries_wat.at(0) << endl;
return 1000;
}
// getting the upper points
QList<int> i_upper = findUpperEntries(gas, oil, water);
// calculating the difference to the lower bounding points
double xd = (gas - m_entries_gas.at(i_upper.at(0) - 1)) / (m_entries_gas.at(i_upper.at(0)) - m_entries_gas.at(i_upper.at(0) - 1));
double yd = (oil - m_entries_oil.at(i_upper.at(1) - 1)) / (m_entries_oil.at(i_upper.at(1)) - m_entries_oil.at(i_upper.at(1) - 1));
double zd = (water - m_entries_wat.at(i_upper.at(2) - 1)) / (m_entries_wat.at(i_upper.at(2)) - m_entries_wat.at(i_upper.at(2) - 1));
// getting the indexes for the eight bounding points
int i_000 = findTableIndex(i_upper.at(0) - 1, i_upper.at(1) - 1, i_upper.at(2) - 1);
int i_010 = findTableIndex(i_upper.at(0) - 1, i_upper.at(1) , i_upper.at(2) - 1);
int i_001 = findTableIndex(i_upper.at(0) - 1, i_upper.at(1) - 1, i_upper.at(2) );
int i_011 = findTableIndex(i_upper.at(0) - 1, i_upper.at(1) , i_upper.at(2) );
int i_100 = findTableIndex(i_upper.at(0) , i_upper.at(1) - 1, i_upper.at(2) - 1);
int i_110 = findTableIndex(i_upper.at(0) , i_upper.at(1) , i_upper.at(2) - 1);
int i_101 = findTableIndex(i_upper.at(0) , i_upper.at(1) - 1, i_upper.at(2) );
int i_111 = findTableIndex(i_upper.at(0) , i_upper.at(1) , i_upper.at(2) );
//interpolating along x (gas)
double c_00 = m_dp.at(i_000) * (1 - xd) + m_dp.at(i_100) * xd;
double c_10 = m_dp.at(i_010) * (1 - xd) + m_dp.at(i_110) * xd;
double c_01 = m_dp.at(i_001) * (1 - xd) + m_dp.at(i_101) * xd;
double c_11 = m_dp.at(i_011) * (1 - xd) + m_dp.at(i_111) * xd;
// interpolating along y (oil)
double c_0 = c_00 * (1 - yd) + c_10 * yd;
double c_1 = c_01 * (1 - yd) + c_11 * yd;
// interpolating along z (water)
double c = c_0 * (1 - zd) + c_1 * zd;
return c;
}
} // namespace ResOpt