Skip to content

Commit d21106b

Browse files
authored
improve flash (#1205)
* update * update * update * update * update * update
1 parent 0a880ae commit d21106b

File tree

10 files changed

+88
-24
lines changed

10 files changed

+88
-24
lines changed

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ public void calculate() {
9999

100100
this.thermoSystem.setPressure(TVP * 0.9);
101101
try {
102-
// ASTM D323 -08 method is used for this property calculation. It is defined at the pressure
102+
// ASTM D323 -08 method is used for this property calculation. It is defined at
103+
// the pressure
103104
// at 100°F (37.8°C) at which 80% of the stream by volume is vapor at 100°F. In
104105
this.thermoOps.TVfractionFlash(0.8);
105106
} catch (Exception ex) {
106-
logger.error(ex.getMessage(), ex);
107+
logger.error("not able to find RVP...", ex);
107108
}
108109

109110
VPCR4 = this.thermoSystem.getPressure();
@@ -116,7 +117,8 @@ public void calculate() {
116117
fluid1.init(0);
117118
}
118119
try {
119-
// ASTM D323 -08 method is used for this property calculation. It is defined at the pressure
120+
// ASTM D323 -08 method is used for this property calculation. It is defined at
121+
// the pressure
120122
// at 100°F (37.8°C) at which 80% of the stream by volume is vapor at 100°F. In
121123
this.thermoOps.TVfractionFlash(0.8);
122124
} catch (Exception ex) {

src/main/java/neqsim/thermo/phase/PhaseEos.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,7 @@ public double molarVolume(double pressure, double temperature, double A, double
352352
BonVold = 100;
353353
}
354354
if (BonV < 0) {
355-
// BonV = Math.abs(BonV);
356-
BonV = 1.0e-10;
355+
BonV = BonVold / 2;
357356
BonVold = 10;
358357
}
359358

src/main/java/neqsim/thermodynamicoperations/ThermodynamicOperations.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,11 @@ public void TVflash(double Vspec) {
601601
*/
602602
public void TVfractionFlash(double Vspec) {
603603
operation = new neqsim.thermodynamicoperations.flashops.TVfractionFlash(system, Vspec);
604-
getOperation().run();
604+
try {
605+
getOperation().run();
606+
} catch (Exception e) {
607+
throw e;
608+
}
605609
}
606610

607611
/**

src/main/java/neqsim/thermodynamicoperations/flashops/Flash.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public int findLowestGibbsEnergyPhase() {
6565
if (!findLowestGibbsPhaseIsChecked) {
6666
minimumGibbsEnergySystem = system.clone();
6767
minimumGibbsEnergySystem.init(0);
68+
if (minimumGibbsEnergySystem.getTotalNumberOfMoles() < 1e-20) {
69+
minimumGibbsEnergySystem.setTotalNumberOfMoles(1.0);
70+
}
6871
minimumGibbsEnergySystem.init(1);
6972
if ((minimumGibbsEnergySystem.getPhase(0).getGibbsEnergy()
7073
* (1.0 - Math.signum(minimumGibbsEnergySystem.getPhase(0).getGibbsEnergy())
@@ -168,7 +171,12 @@ public void stabilityAnalysis() throws neqsim.util.exception.IsNaNException,
168171

169172
if ((iterations <= maxiterations - 10)
170173
|| !system.isImplementedCompositionDeriativesofFugacity()) {
171-
clonedSystem.init(1, j);
174+
try {
175+
clonedSystem.init(1, j);
176+
} catch (Exception e) {
177+
logger.error(e.toString());
178+
throw e;
179+
}
172180
fNormOld = fNorm;
173181
for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) {
174182
f.set(i, 0, Math.sqrt(Wi[j][i]) * (Math.log(Wi[j][i])
@@ -263,7 +271,7 @@ public void stabilityAnalysis() throws neqsim.util.exception.IsNaNException,
263271
// logger.info("iterations " + iterations);
264272
// logger.info("f.norm1() " + f.norm1());
265273
if (iterations >= maxiterations) {
266-
// logger.error("err staability check " + error[j]);
274+
logger.error("err staability check " + error[j]);
267275
throw new neqsim.util.exception.TooManyIterationsException("too many iterations", null,
268276
maxiterations);
269277
}

src/main/java/neqsim/thermodynamicoperations/flashops/TPmultiflash.java

+2
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ public double solveBeta() {
199199
try {
200200
ans = dQdBM.solve(dQM).transpose();
201201
} catch (Exception ex) {
202+
logger.error(ex.getMessage());
203+
break;
202204
}
203205
betaMatrix = betaMatrix.minus(ans.scale(iter / (iter + 3.0)));
204206
removePhase = false;

src/main/java/neqsim/thermodynamicoperations/flashops/TVfractionFlash.java

+22-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
package neqsim.thermodynamicoperations.flashops;
88

9+
import org.apache.logging.log4j.LogManager;
10+
import org.apache.logging.log4j.Logger;
911
import neqsim.thermo.system.SystemInterface;
1012

1113
/**
@@ -18,6 +20,7 @@
1820
*/
1921
public class TVfractionFlash extends Flash {
2022
private static final long serialVersionUID = 1000;
23+
static Logger logger = LogManager.getLogger(TVfractionFlash.class);
2124

2225
double Vfractionspec = 0;
2326
Flash tpFlash;
@@ -86,12 +89,23 @@ public double solveQ() {
8689
if (nyPres <= 0.0) {
8790
nyPres = oldPres * 0.9;
8891
}
92+
if (Math.abs(nyPres - oldPres) >= 10.0) {
93+
nyPres = oldPres + Math.signum(nyPres - oldPres) * 10.0;
94+
}
8995
system.setPressure(nyPres);
90-
tpFlash.run();
96+
if (system.getPressure() < 5000) {
97+
tpFlash.run();
98+
} else {
99+
logger.error("too high pressure in TVfractionFLash.....stopping");
100+
break;
101+
}
91102

92103
error = Math.abs(dqdv / Vfractionspec);
93-
// System.out.println("error " + error + "iteration " + iterations + " dQdv " + calcdQdV()
94-
// + " new pressure " + nyPres + " error " + Math.abs((nyPres - oldPres) / (nyPres))
104+
logger.debug("pressure " + nyPres + " iteration " + iterations);
105+
// System.out.println("error " + error + "iteration " + iterations + " dQdv " +
106+
// calcdQdV()
107+
// + " new pressure " + nyPres + " error " + Math.abs((nyPres - oldPres) /
108+
// (nyPres))
95109
// + " numberofphases " + system.getNumberOfPhases());
96110
} while ((error > 1e-6 && Math.abs(pressureStep) > 1e-6 && iterations < 200) || iterations < 6);
97111
return nyPres;
@@ -109,8 +123,11 @@ public void run() {
109123
}
110124

111125
// System.out.println("enthalpy: " + system.getEnthalpy());
112-
solveQ();
113-
126+
try {
127+
solveQ();
128+
} catch (Exception e) {
129+
throw e;
130+
}
114131
// System.out.println("volume: " + system.getVolume());
115132
// System.out.println("Temperature: " + system.getTemperature());
116133
}

src/test/java/neqsim/process/equipment/pipeline/AdiabaticTwoPhasePipeTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.junit.jupiter.api.Assertions;
44
import org.junit.jupiter.api.Test;
5-
import neqsim.process.equipment.pipeline.AdiabaticTwoPhasePipe;
65
import neqsim.process.equipment.stream.Stream;
76

87
public class AdiabaticTwoPhasePipeTest {
@@ -42,10 +41,11 @@ public void testMain() {
4241
// System.out.println("out pressure " + pipe2.getOutletStream().getPressure("bara"));
4342
// System.out.println("velocity " + pipe2.getSuperficialVelocity());
4443

45-
Assertions.assertEquals(75.0000001, pipe2.getOutletStream().getFluid().getFlowRate("MSm3/day"));
46-
Assertions.assertEquals(153.58741116226855, pipe.getOutletStream().getPressure("bara"));
47-
Assertions.assertEquals(4.207400548548574, pipe.getSuperficialVelocity());
48-
Assertions.assertEquals(146.28492500260614, pipe2.getOutletStream().getPressure("bara"));
49-
Assertions.assertEquals(60.751298047046646, pipe2.getSuperficialVelocity());
44+
Assertions.assertEquals(75.0000001, pipe2.getOutletStream().getFluid().getFlowRate("MSm3/day"),
45+
1e-5);
46+
Assertions.assertEquals(153.58741116226855, pipe.getOutletStream().getPressure("bara"), 1e-6);
47+
Assertions.assertEquals(4.207400548548574, pipe.getSuperficialVelocity(), 1e-6);
48+
Assertions.assertEquals(146.28492500260614, pipe2.getOutletStream().getPressure("bara"), 0.001);
49+
Assertions.assertEquals(60.751298047046646, pipe2.getSuperficialVelocity(), 0.01);
5050
}
5151
}

src/test/java/neqsim/process/processmodel/SalesGasAndStableOilTest.java

+34-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package neqsim.process.processmodel;
22

3-
import static org.junit.jupiter.api.Assertions.assertAll;
43
import java.io.File;
54
import org.junit.jupiter.api.Assertions;
65
import org.junit.jupiter.api.Test;
76
import neqsim.process.equipment.compressor.Compressor;
7+
import neqsim.process.equipment.expander.Expander;
88
import neqsim.process.equipment.heatexchanger.Cooler;
99
import neqsim.process.equipment.heatexchanger.Heater;
1010
import neqsim.process.equipment.mixer.Mixer;
1111
import neqsim.process.equipment.pump.Pump;
1212
import neqsim.process.equipment.separator.Separator;
1313
import neqsim.process.equipment.separator.ThreePhaseSeparator;
1414
import neqsim.process.equipment.stream.Stream;
15+
import neqsim.process.equipment.util.Recycle;
1516
import neqsim.process.equipment.valve.ThrottlingValve;
1617
import neqsim.thermo.system.SystemInterface;
1718

@@ -235,10 +236,10 @@ public void testProcess2() {
235236

236237
Cooler dewPointControlCooler2 = new neqsim.process.equipment.heatexchanger.Cooler(
237238
"dew point cooler 2", dewPointScrubber.getGasOutStream());
238-
dewPointControlCooler2.setOutTemperature(-5.0, "C");
239+
dewPointControlCooler2.setOutTemperature(-15.0, "C");
239240
dewPointControlCooler2.setOutPressure(59.5, "bara");
240241
dewPointControlCooler2.run();
241-
Assertions.assertEquals(0.9808118997528,
242+
Assertions.assertEquals(0.967383748675644,
242243
dewPointControlCooler2.getOutStream().getFluid().getBeta(), 1e-6);
243244
Separator dewPointScrubber2 = new neqsim.process.equipment.separator.Separator(
244245
"dew point scrubber 2", dewPointControlCooler2.getOutStream());
@@ -259,6 +260,36 @@ public void testProcess2() {
259260
lpLiqmixer.addStream(firstStageScrubber2.getLiquidOutStream());
260261
lpLiqmixer.run();
261262

263+
Recycle hpResycle = new neqsim.process.equipment.util.Recycle("HP liq resycle");
264+
hpResycle.addStream(hpLiqmixer.getOutStream());
265+
hpResycle.setOutletStream(oilFirstStage);
266+
hpResycle.setTolerance(1e-2);
267+
hpResycle.run();
268+
269+
Recycle mpResycle = new neqsim.process.equipment.util.Recycle("MP liq resycle");
270+
mpResycle.addStream(mpLiqmixer.getOutStream());
271+
mpResycle.setOutletStream(oilSeccondStage);
272+
mpResycle.setTolerance(1e-2);
273+
mpResycle.run();
274+
275+
Recycle lpResycle = new neqsim.process.equipment.util.Recycle("LP liq resycle");
276+
lpResycle.addStream(lpLiqmixer.getOutStream());
277+
lpResycle.setOutletStream(oilThirdStage);
278+
lpResycle.setTolerance(1e-2);
279+
lpResycle.run();
280+
281+
Expander turboexpander =
282+
new neqsim.process.equipment.expander.Expander("TEX", dewPointScrubber2.getGasOutStream());
283+
turboexpander.setIsentropicEfficiency(0.80);
284+
turboexpander.setOutletPressure(50.0);
285+
turboexpander.run();
286+
// turboexpander.getFluid().prettyPrint();
287+
288+
Separator DPCUScrubber = new neqsim.process.equipment.separator.Separator("TEX LT scrubber",
289+
turboexpander.getOutStream());
290+
DPCUScrubber.run();
291+
292+
// DPCUScrubber.getFluid().prettyPrint();
262293
// richGasMixer.getOutStream().getFluid().prettyPrint();
263294

264295

src/test/java/neqsim/thermo/util/readwrite/EclipseFluidReadWriteTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void testReadFluidR() throws IOException {
103103
testSystem.setPressure(530.97, "bara");
104104
testSystem.setTemperature(105.0, "C");
105105
testOps.TPflash();
106-
testSystem.prettyPrint();
106+
// testSystem.prettyPrint();
107107
// Assertions.assertEquals(0.9270363530255, testSystem.getBeta(0), 1e-6);
108108

109109
testSystem = EclipseFluidReadWrite.read(filer);

src/test/java/neqsim/thermodynamicoperations/flashops/TPFlashTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ void testRun5() {
9696
testOps = new ThermodynamicOperations(testSystem5);
9797
testOps.TPflash();
9898
testSystem5.initProperties();
99+
// testSystem5.prettyPrint();
99100
double beta = testSystem5.getBeta();
100-
assertEquals(6.272876522701802E-7, beta, 1e-5);
101+
assertEquals(0.999999372713993, beta, 1e-9);
101102
}
102103

103104
@Test

0 commit comments

Comments
 (0)