Skip to content

Commit 0c20923

Browse files
authored
fixed bug in TPflash. Added TVflash test (#454)
1 parent 5fadcde commit 0c20923

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

src/main/java/neqsim/thermodynamicOperations/flashOps/TPflash.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public void setNewK() {
166166
* </p>
167167
*/
168168
public void resetK() {
169+
169170
for (i = 0; i < system.getPhase(0).getNumberOfComponents(); i++) {
170171
lnK[i] = lnOldK[i];
171172
system.getPhase(0).getComponents()[i].setK(Math.exp(lnK[i]));
@@ -402,7 +403,7 @@ public void run() {
402403
gibbsEnergy = system.getGibbsEnergy();
403404

404405
if ((gibbsEnergy - gibbsEnergyOld) / Math.abs(gibbsEnergyOld) > 1e-3
405-
&& !system.isChemicalSystem()) {
406+
&& !system.isChemicalSystem() && timeFromLastGibbsFail>0) {
406407
resetK();
407408
timeFromLastGibbsFail = 0;
408409
// logger.info("gibbs decrease " + (gibbsEnergy - gibbsEnergyOld) /
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
*
3+
*/
4+
package neqsim.thermodynamicOperations.flashOps;
5+
6+
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
import org.junit.jupiter.api.BeforeEach;
8+
import org.junit.jupiter.api.Test;
9+
import neqsim.thermodynamicOperations.ThermodynamicOperations;
10+
11+
/**
12+
* @author ESOL
13+
*
14+
*/
15+
class TVFlashTest {
16+
17+
static neqsim.thermo.system.SystemInterface testSystem = null;
18+
static neqsim.thermo.system.SystemInterface testSystem2 = null;
19+
static ThermodynamicOperations testOps = null;
20+
21+
/**
22+
* @throws java.lang.Exception
23+
*/
24+
@BeforeEach
25+
void setUp() throws Exception {
26+
testSystem = new neqsim.thermo.system.SystemUMRPRUMCEos(293.15, 0.1);
27+
testSystem.addComponent("methane", 0.0);
28+
testSystem.addComponent("ethane", 0.0);
29+
testSystem.addComponent("n-pentane", 9E-1);
30+
testSystem.addComponent("nC16", 1E-1);
31+
testSystem.setMixingRule("classic");
32+
testOps = new ThermodynamicOperations(testSystem);
33+
testOps.TPflash();
34+
testSystem.initProperties();
35+
testSystem.setTotalFlowRate(1.0, "kg/sec");
36+
testOps.TPflash();
37+
testSystem.initProperties();
38+
39+
testSystem2 = new neqsim.thermo.system.SystemUMRPRUMCEos(293.15, 0.1);
40+
testSystem2.addComponent("methane", 8.5E-1);
41+
testSystem2.addComponent("ethane", 1.5E-1);
42+
testSystem2.addComponent("n-pentane", 0);
43+
testSystem2.addComponent("nC16", 0);
44+
testSystem2.setMixingRule("classic");
45+
ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem2);
46+
testOps.TPflash();
47+
testSystem2.initProperties();
48+
testSystem2.setTotalFlowRate(0.3, "kg/sec");
49+
testOps.TPflash();
50+
testSystem2.initProperties();
51+
}
52+
53+
@Test
54+
void testTVflash() {
55+
double total_rig_volume = 0.998;
56+
57+
for(int i=0;i<50;i++) {
58+
testSystem.addFluid(testSystem2);
59+
ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem);
60+
try {
61+
testOps.TVflash(total_rig_volume, "m3");
62+
}
63+
catch(Exception e) {
64+
System.out.println("error iterations " + i);
65+
e.printStackTrace();
66+
}
67+
}
68+
assertEquals(235263.80103781424, testSystem.getEnthalpy(), 1e-2);
69+
}
70+
71+
}
72+

0 commit comments

Comments
 (0)