Skip to content

Commit ad33f31

Browse files
committed
RVP fix
1 parent 68f85e0 commit ad33f31

File tree

4 files changed

+170
-2
lines changed

4 files changed

+170
-2
lines changed

src/main/java/neqsim/standards/oilQuality/Standard_ASTM_D6377.java

+25
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,31 @@ public void calculate() {
4848
logger.error(ex.getMessage(), ex);
4949
}
5050

51+
TVP = this.thermoSystem.getPressure();
52+
53+
this.thermoSystem.setPressure(TVP * 0.9);
54+
try {
55+
// ASTM D323 -08 method is used for this property calculation. It is defined at the pressure
56+
// at 100°F (37.8°C) at which 80% of the stream by volume is vapor at 100°F. In
57+
this.thermoOps.TVfractionFlash(0.8);
58+
} catch (Exception ex) {
59+
logger.error(ex.getMessage(), ex);
60+
}
61+
62+
RVP = this.thermoSystem.getPressure();
63+
}
64+
65+
// old method for RVP
66+
public void calculate2() {
67+
this.thermoSystem.setTemperature(referenceTemperature, "C");
68+
this.thermoSystem.setPressure(ThermodynamicConstantsInterface.referencePressure);
69+
this.thermoOps = new ThermodynamicOperations(thermoSystem);
70+
try {
71+
this.thermoOps.bubblePointPressureFlash(false);
72+
} catch (Exception ex) {
73+
logger.error(ex.getMessage(), ex);
74+
}
75+
5176
TVP = this.thermoSystem.getPressure();
5277
double liquidVolume = thermoSystem.getVolume();
5378

src/main/java/neqsim/thermodynamicOperations/ThermodynamicOperations.java

+12
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,18 @@ public void TVflash(double Vspec) {
576576
getOperation().run();
577577
}
578578

579+
/**
580+
* <p>
581+
* TVfractionFlash.
582+
* </p>
583+
*
584+
* @param Vspec a double volume fraction of first/lightest phase
585+
*/
586+
public void TVfractionFlash(double Vspec) {
587+
operation = new neqsim.thermodynamicOperations.flashOps.TVfractionFlash(system, Vspec);
588+
getOperation().run();
589+
}
590+
579591
/**
580592
* <p>
581593
* PVrefluxFlash.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* TVflash.java
3+
*
4+
* Created on 8. mars 2001, 10:56
5+
*/
6+
7+
package neqsim.thermodynamicOperations.flashOps;
8+
9+
import neqsim.thermo.system.SystemInterface;
10+
11+
/**
12+
* <p>
13+
* TVflash class.
14+
* </p>
15+
*
16+
* @author even solbraa
17+
* @version $Id: $Id
18+
*/
19+
public class TVfractionFlash extends Flash {
20+
private static final long serialVersionUID = 1000;
21+
22+
double Vfractionspec = 0;
23+
Flash tpFlash;
24+
25+
/**
26+
* <p>
27+
* Constructor for TVflash.
28+
* </p>
29+
*
30+
* @param system a {@link neqsim.thermo.system.SystemInterface} object
31+
* @param Vfractionspec a double
32+
*/
33+
public TVfractionFlash(SystemInterface system, double Vfractionspec) {
34+
this.system = system;
35+
this.tpFlash = new TPflash(system);
36+
this.Vfractionspec = Vfractionspec;
37+
}
38+
39+
/**
40+
* <p>
41+
* calcdQdVP.
42+
* </p>
43+
*
44+
* @return a double
45+
*/
46+
public double calcdQdVdP() {
47+
double dQdVP = 0.0;
48+
dQdVP = 1.0 / system.getPhase(i).getdPdVTn() / system.getVolume();
49+
return dQdVP;
50+
}
51+
52+
/**
53+
* <p>
54+
* calcdQdV.
55+
* </p>
56+
*
57+
* @return a double
58+
*/
59+
public double calcdQdV() {
60+
double dQ = system.getPhase(0).getVolume() / system.getVolume() - Vfractionspec;
61+
return dQ;
62+
}
63+
64+
/**
65+
* <p>
66+
* solveQ.
67+
* </p>
68+
*
69+
* @return a double
70+
*/
71+
public double solveQ() {
72+
double oldPres = system.getPressure();
73+
double nyPres = system.getPressure();
74+
double iterations = 1;
75+
double error = 100.0;
76+
double numericdQdVdP = 0.0;
77+
double dQdV = 0.0;
78+
double olddQdV = 0.0;
79+
double pressureStep = 1.0;
80+
do {
81+
82+
iterations++;
83+
oldPres = nyPres;
84+
system.init(3);
85+
double dQDVdP = calcdQdVdP();
86+
87+
numericdQdVdP = (calcdQdV() - olddQdV) / pressureStep;
88+
89+
if (iterations < 5) {
90+
nyPres = oldPres - 1.0 / 10.0 * calcdQdV() / dQDVdP;
91+
} else {
92+
nyPres = oldPres - 1.0 * calcdQdV() / numericdQdVdP;
93+
}
94+
if (nyPres <= 0.0) {
95+
nyPres = oldPres * 0.9;
96+
}
97+
if (nyPres >= oldPres * 2) {
98+
nyPres = oldPres * 2.0;
99+
}
100+
pressureStep = nyPres - oldPres;
101+
102+
olddQdV = calcdQdV();
103+
system.setPressure(nyPres);
104+
tpFlash.run();
105+
error = Math.abs(calcdQdV()) / system.getVolume();
106+
// System.out.println("error " + error + "iteration " + iterations + " dQdv " + calcdQdV()
107+
// + " new pressure " + nyPres + " error " + Math.abs((nyPres - oldPres) / (nyPres))
108+
// + " numberofphases " + system.getNumberOfPhases() + " dQDVdP " + dQDVdP + " dQDVdPnumeric"
109+
// + numericdQdVdP);
110+
111+
} while ((error > 1e-9 && iterations < 200) || iterations < 3);
112+
return nyPres;
113+
}
114+
115+
/** {@inheritDoc} */
116+
@Override
117+
public void run() {
118+
tpFlash.run();
119+
// System.out.println("enthalpy: " + system.getEnthalpy());
120+
solveQ();
121+
122+
// System.out.println("volume: " + system.getVolume());
123+
// System.out.println("Temperature: " + system.getTemperature());
124+
}
125+
126+
/** {@inheritDoc} */
127+
@Override
128+
public org.jfree.chart.JFreeChart getJFreeChart(String name) {
129+
return null;
130+
}
131+
}

src/test/java/neqsim/standards/oilQuality/Standard_ASTM_D6377Test.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void testCalculate() {
1919
Standard_ASTM_D6377 standard = new Standard_ASTM_D6377(testSystem);
2020
standard.setReferenceTemperature(37.8, "C");
2121
standard.calculate();
22-
Assertions.assertEquals(0.94552559993, standard.getValue("RVP", "bara"), 1e-3);
22+
Assertions.assertEquals(1.10455465, standard.getValue("RVP", "bara"), 1e-3);
2323
Assertions.assertEquals(1.666298367, standard.getValue("TVP", "bara"), 1e-3);
2424
}
2525

@@ -38,7 +38,7 @@ void testCalculate2() {
3838
Standard_ASTM_D6377 standard = new Standard_ASTM_D6377(testSystem);
3939
standard.setReferenceTemperature(37.8, "C");
4040
standard.calculate();
41-
Assertions.assertEquals(3.017010, standard.getValue("RVP", "bara"), 1e-3);
41+
Assertions.assertEquals(3.604002003478, standard.getValue("RVP", "bara"), 1e-3);
4242
Assertions.assertEquals(7.8448385024, standard.getValue("TVP", "bara"), 1e-3);
4343
}
4444
}

0 commit comments

Comments
 (0)