-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathDifferentialLiberation.java
More file actions
326 lines (301 loc) · 10.1 KB
/
DifferentialLiberation.java
File metadata and controls
326 lines (301 loc) · 10.1 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
package neqsim.PVTsimulation.simulation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import neqsim.thermo.ThermodynamicConstantsInterface;
import neqsim.thermo.phase.PhaseType;
import neqsim.thermo.system.SystemInterface;
import neqsim.thermo.system.SystemSrkEos;
/**
* <p>
* DifferentialLiberation class.
* </p>
*
* @author esol
* @version $Id: $Id
*/
public class DifferentialLiberation extends BasePVTsimulation {
static Logger logger = LogManager.getLogger(DifferentialLiberation.class);
double VoilStd = 0.0;
double[] relativeVolume = null;
double[] totalVolume = null;
double[] liquidVolumeRelativeToVsat = null;
double[] liquidVolume = null;
private double[] oilDensity = null;
private double[] gasStandardVolume = null;
double saturationVolume = 0;
double saturationPressure = 0;
boolean saturationConditionFound = false;
private double[] Bo;
private double[] Bg;
private double[] Rs;
private double[] Zgas;
private double[] relGasGravity;
double[] gasVolume;
/**
* <p>
* Constructor for DifferentialLiberation.
* </p>
*
* @param tempSystem a {@link neqsim.thermo.system.SystemInterface} object
*/
public DifferentialLiberation(SystemInterface tempSystem) {
super(tempSystem);
}
/**
* <p>
* calcSaturationConditions.
* </p>
*/
public void calcSaturationConditions() {
getThermoSystem().setPressure(1.0);
do {
getThermoSystem().setPressure(getThermoSystem().getPressure() + 10.0);
} while (getThermoSystem().getNumberOfPhases() == 1
&& getThermoSystem().getPressure() < 1000.0);
do {
getThermoSystem().setPressure(getThermoSystem().getPressure() + 10.0);
thermoOps.TPflash();
} while (getThermoSystem().getNumberOfPhases() > 1 && getThermoSystem().getPressure() < 1000.0);
double minPres = getThermoSystem().getPressure() - 10.0;
double maxPres = getThermoSystem().getPressure();
do {
getThermoSystem().setPressure((minPres + maxPres) / 2.0);
thermoOps.TPflash();
if (getThermoSystem().getNumberOfPhases() > 1) {
minPres = getThermoSystem().getPressure();
} else {
maxPres = getThermoSystem().getPressure();
}
} while (Math.abs(maxPres - minPres) > 1e-5);
/*
* try { thermoOps.dewPointPressureFlash(); } catch (Exception ex) {
* logger.error(ex.getMessage(), ex); }
*/
getThermoSystem().initPhysicalProperties();
saturationVolume = getThermoSystem().getPhase(0).getMass()
/ getThermoSystem().getPhase(0).getPhysicalProperties().getDensity();
saturationPressure = getThermoSystem().getPressure();
saturationConditionFound = true;
}
/**
* <p>
* runCalc.
* </p>
*/
public void runCalc() {
saturationConditionFound = false;
relativeVolume = new double[pressures.length];
double[] mass = new double[pressures.length];
totalVolume = new double[pressures.length];
liquidVolumeRelativeToVsat = new double[pressures.length];
liquidVolume = new double[pressures.length];
gasVolume = new double[pressures.length];
gasStandardVolume = new double[pressures.length];
Bo = new double[pressures.length];
Bg = new double[pressures.length];
Rs = new double[pressures.length];
Zgas = new double[pressures.length];
relGasGravity = new double[pressures.length];
oilDensity = new double[pressures.length];
double totalGasStandardVolume = 0;
if (!Double.isNaN(temperature)) {
getThermoSystem().setTemperature(temperature, temperatureUnit);
}
for (int i = 0; i < pressures.length; i++) {
getThermoSystem().setPressure(pressures[i]);
try {
thermoOps.TPflash();
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
getThermoSystem().initPhysicalProperties();
oilDensity[i] = getThermoSystem().getDensity("kg/m3");
mass[i] = getThermoSystem().getMass("kg");
totalVolume[i] = mass[i] / oilDensity[i];
liquidVolume[i] = totalVolume[i];
if (getThermoSystem().getNumberOfPhases() > 1) {
if (!saturationConditionFound) {
calcSaturationConditions();
getThermoSystem().setPressure(pressures[i]);
try {
thermoOps.TPflash();
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
}
gasStandardVolume[i] = getThermoSystem().getPhase(PhaseType.GAS).getMass()
/ getThermoSystem().getPhase(PhaseType.GAS).getPhysicalProperties().getDensity()
* getThermoSystem().getPhase(0).getPressure()
/ ThermodynamicConstantsInterface.referencePressure
/ getThermoSystem().getPhase(0).getZ() * 288.15 / getThermoSystem().getTemperature();
totalGasStandardVolume += getGasStandardVolume()[i];
// if (totalVolume[i] > saturationVolume) {
Zgas[i] = getThermoSystem().getPhase(0).getZ();
relGasGravity[i] = getThermoSystem().getPhase(0).getMolarMass() / 0.028;
if (getThermoSystem().hasPhaseType(PhaseType.GAS)
&& getThermoSystem().hasPhaseType(PhaseType.OIL)) {
oilDensity[i] = getThermoSystem().getPhase(1).getPhysicalProperties().getDensity();
liquidVolume[i] = getThermoSystem().getPhase(1).getMass() / oilDensity[i];
getThermoSystem().getPhase(1).getMass();
} else if (getThermoSystem().hasPhaseType("oil")) {
oilDensity[i] = getThermoSystem().getPhase(0).getPhysicalProperties().getDensity();
liquidVolume[i] = getThermoSystem().getPhase(0).getMass() / oilDensity[i];
} else {
oilDensity[i] = getThermoSystem().getPhase(0).getPhysicalProperties().getDensity();
liquidVolume[i] = getThermoSystem().getPhase(0).getMass() / oilDensity[i];
}
if (getThermoSystem().getNumberOfPhases() > 1) {
gasVolume[i] = getThermoSystem().getPhase(PhaseType.GAS).getMass()
/ getThermoSystem().getPhase(PhaseType.GAS).getPhysicalProperties().getDensity();
}
liquidVolumeRelativeToVsat[i] = liquidVolume[i] / saturationVolume;
getThermoSystem().removePhase(0);
}
}
getThermoSystem().setPressure(ThermodynamicConstantsInterface.referencePressure);
getThermoSystem().setTemperature(288.15);
try {
thermoOps.TPflash();
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
getThermoSystem().initPhysicalProperties();
VoilStd = getThermoSystem().getPhase(PhaseType.OIL).getMass()
/ getThermoSystem().getPhase(PhaseType.OIL).getPhysicalProperties().getDensity();
if (getThermoSystem().hasPhaseType(PhaseType.GAS)) {
totalGasStandardVolume += getThermoSystem().getPhase(PhaseType.GAS).getCorrectedVolume();
}
double total = 0;
for (int i = 0; i < pressures.length; i++) {
relativeVolume[i] = totalVolume[i] / saturationVolume;
Bo[i] = liquidVolume[i] / VoilStd;
total += getGasStandardVolume()[i];
Rs[i] = (totalGasStandardVolume - total) / VoilStd;
if (Zgas[i] > 1e-10) {
Bg[i] = gasVolume[i] / getGasStandardVolume()[i];
}
/*
* System.out.println("pressure " + pressures[i] + " Bo " + getBo()[i] + " Bg " + getBg()[i] +
* " Rs " + getRs()[i] + " oil density " + getOilDensity()[i] + " gas gracvity " +
* getRelGasGravity()[i] + " Zgas " + getZgas()[i] + " gasstdvol " +
* getGasStandardVolume()[i]);
*/
}
}
/**
* *
* <p>
* main
* </p>
*
* @param args an array of {@link java.lang.String} objects
*/
public static void main(String[] args) {
SystemInterface tempSystem = new SystemSrkEos(273.15 + 83.5, 450.0);
tempSystem.addComponent("nitrogen", 0.586);
tempSystem.addComponent("CO2", 0.087);
tempSystem.addComponent("methane", 107.0209);
tempSystem.addComponent("ethane", 15.176);
tempSystem.addComponent("propane", 6.652);
tempSystem.addComponent("i-butane", 3.533);
tempSystem.addComponent("n-butane", 5.544);
tempSystem.addComponent("i-pentane", 1.585);
tempSystem.addComponent("n-pentane", 2.036);
tempSystem.addTBPfraction("C6", 2.879, 84.9 / 1000.0, 0.6668);
tempSystem.addTBPfraction("C7", 4.435, 93.2 / 1000.0, 0.7243);
tempSystem.addTBPfraction("C8", 4.815, 105.7 / 1000.0, 0.7527);
tempSystem.addTBPfraction("C9", 3.488, 119.8 / 1000.0, 0.7743);
tempSystem.addPlusFraction("C10", 45.944, 320.0 / 1000.0, 0.924);
tempSystem.getCharacterization().characterisePlusFraction();
DifferentialLiberation differentialLiberation = new DifferentialLiberation(tempSystem);
differentialLiberation.setPressures(
new double[] {350.0, 250.0, 200.0, 150.0, 100.0, 70.0, 50.0, 40.0, 30.0, 20.0, 1.0});
differentialLiberation.setTemperature(83.5, "C");
differentialLiberation.runCalc();
}
/**
* <p>
* Getter for the field <code>relativeVolume</code>.
* </p>
*
* @return the relativeVolume
*/
public double[] getRelativeVolume() {
return relativeVolume;
}
/** {@inheritDoc} */
@Override
public double getSaturationPressure() {
return saturationPressure;
}
/**
* <p>
* getBo.
* </p>
*
* @return the Bo
*/
public double[] getBo() {
return Bo;
}
/**
* <p>
* getBg.
* </p>
*
* @return the Bg
*/
public double[] getBg() {
return Bg;
}
/**
* <p>
* getRs.
* </p>
*
* @return the Rs
*/
public double[] getRs() {
return Rs;
}
/**
* <p>
* getZgas.
* </p>
*
* @return the Zgas
*/
public double[] getZgas() {
return Zgas;
}
/**
* <p>
* Getter for the field <code>relGasGravity</code>.
* </p>
*
* @return the relGasGravity
*/
public double[] getRelGasGravity() {
return relGasGravity;
}
/**
* <p>
* Getter for the field <code>gasStandardVolume</code>.
* </p>
*
* @return the gasStandardVolume
*/
public double[] getGasStandardVolume() {
return gasStandardVolume;
}
/**
* <p>
* Getter for the field <code>oilDensity</code>.
* </p>
*
* @return the oilDensity
*/
public double[] getOilDensity() {
return oilDensity;
}
}