Skip to content

Commit 44c805c

Browse files
authored
try fix (#1029)
* try fix * update
1 parent a812763 commit 44c805c

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,15 @@ public boolean stabilityCheck() {
352352
this.solidPhaseFlash();
353353
}
354354
} else {
355+
RachfordRice rachfordRice = new RachfordRice();
355356
try {
356-
system.setBeta(RachfordRice.calcBeta(system.getKvector(), system.getzvector()));
357+
system.setBeta(rachfordRice.calcBeta(system.getKvector(), system.getzvector()));
357358
} catch (Exception ex) {
359+
if (!Double.isNaN(rachfordRice.getBeta()[0])) {
360+
system.setBeta(rachfordRice.getBeta()[0]);
361+
} else {
362+
system.setBeta(Double.NaN);
363+
}
358364
logger.error(ex.getMessage(), ex);
359365
}
360366
system.calc_x_y();

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

+15-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66

77
package neqsim.thermodynamicOperations.flashOps;
88

9+
import java.io.Serializable;
10+
911
/**
1012
* RachfordRice classes.
1113
*
1214
* @author Even Solbraa
1315
*/
14-
public class RachfordRice {
16+
public class RachfordRice implements Serializable {
1517
private static final long serialVersionUID = 1000;
18+
private double[] beta = new double[2];
1619

1720
/**
1821
* <p>
@@ -25,7 +28,7 @@ public class RachfordRice {
2528
* @throws neqsim.util.exception.IsNaNException if any.
2629
* @throws neqsim.util.exception.TooManyIterationsException if any.
2730
*/
28-
public static double calcBeta(double[] K, double[] z) throws neqsim.util.exception.IsNaNException,
31+
public double calcBeta(double[] K, double[] z) throws neqsim.util.exception.IsNaNException,
2932
neqsim.util.exception.TooManyIterationsException {
3033

3134
int i;
@@ -138,6 +141,8 @@ public static double calcBeta(double[] K, double[] z) throws neqsim.util.excepti
138141
} else if (nybeta >= 1.0 - tolerance) {
139142
nybeta = 1.0 - tolerance;
140143
}
144+
beta[0] = nybeta;
145+
beta[1] = 1.0 - nybeta;
141146

142147
if (iterations >= maxIterations) {
143148
throw new neqsim.util.exception.TooManyIterationsException(new RachfordRice(), "calcBeta",
@@ -159,8 +164,7 @@ public static double calcBeta(double[] K, double[] z) throws neqsim.util.excepti
159164
* @throws neqsim.util.exception.IsNaNException if any.
160165
* @throws neqsim.util.exception.TooManyIterationsException if any.
161166
*/
162-
public static double calcBeta2(double[] K, double[] z)
163-
throws neqsim.util.exception.IsNaNException,
167+
public double calcBeta2(double[] K, double[] z) throws neqsim.util.exception.IsNaNException,
164168
neqsim.util.exception.TooManyIterationsException {
165169

166170
double tolerance = neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit;
@@ -269,6 +273,9 @@ public static double calcBeta2(double[] K, double[] z)
269273
V = 1.0 - tolerance;
270274
}
271275

276+
beta[0] = V;
277+
beta[1] = 1.0 - V;
278+
272279
if (iter >= maxIterations) {
273280
throw new neqsim.util.exception.TooManyIterationsException(new RachfordRice(), "calcBeta",
274281
maxIterations);
@@ -280,4 +287,8 @@ public static double calcBeta2(double[] K, double[] z)
280287
return V;
281288
}
282289

290+
public double[] getBeta() {
291+
return beta;
292+
}
293+
283294
}

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

+12-5
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ public void sucsSubs() {
9090
}
9191

9292
double oldBeta = system.getBeta();
93+
94+
RachfordRice rachfordRice = new RachfordRice();
9395
try {
94-
system.setBeta(RachfordRice.calcBeta(system.getKvector(), system.getzvector()));
96+
system.setBeta(rachfordRice.calcBeta(system.getKvector(), system.getzvector()));
9597
} catch (IsNaNException ex) {
9698
logger.warn("Not able to calculate beta. Value is NaN");
9799
system.setBeta(oldBeta);
@@ -132,13 +134,16 @@ public void accselerateSucsSubs() {
132134
system.getPhase(1).getComponent(i).setK(Math.exp(lnK[i]));
133135
}
134136
double oldBeta = system.getBeta();
137+
RachfordRice rachfordRice = new RachfordRice();
135138
try {
136-
system.setBeta(RachfordRice.calcBeta(system.getKvector(), system.getzvector()));
139+
system.setBeta(rachfordRice.calcBeta(system.getKvector(), system.getzvector()));
137140
} catch (Exception ex) {
141+
system.setBeta(rachfordRice.getBeta()[0]);
138142
if (system.getBeta() > 1.0 - betaTolerance || system.getBeta() < betaTolerance) {
139143
system.setBeta(oldBeta);
140144
}
141-
logger.info("temperature " + system.getTemperature() + " pressure " + system.getPressure());
145+
// logger.info("temperature " + system.getTemperature() + " pressure " +
146+
// system.getPressure());
142147
logger.error(ex.getMessage(), ex);
143148
}
144149

@@ -178,7 +183,8 @@ public void resetK() {
178183
system.getPhase(1).getComponents()[i].setK(Math.exp(lnK[i]));
179184
}
180185
try {
181-
system.setBeta(RachfordRice.calcBeta(system.getKvector(), system.getzvector()));
186+
RachfordRice rachfordRice = new RachfordRice();
187+
system.setBeta(rachfordRice.calcBeta(system.getKvector(), system.getzvector()));
182188
system.calc_x_y();
183189
system.init(1);
184190
} catch (Exception ex) {
@@ -249,7 +255,8 @@ public void run() {
249255

250256
// Calculates phase fractions and initial composition based on Wilson K-factors
251257
try {
252-
system.setBeta(RachfordRice.calcBeta(system.getKvector(), system.getzvector()));
258+
RachfordRice rachfordRice = new RachfordRice();
259+
system.setBeta(rachfordRice.calcBeta(system.getKvector(), system.getzvector()));
253260
} catch (Exception ex) {
254261
logger.error(ex.getMessage(), ex);
255262
}

src/test/java/neqsim/thermodynamicOperations/flashOps/RachfordRiceTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ void testCalcBeta() {
1111
double[] K = new double[] {2.0, 0.01};
1212

1313
try {
14-
Assertions.assertEquals(0.407070707, RachfordRice.calcBeta(K, z), 1e-6);
14+
RachfordRice rachfordRice = new RachfordRice();
15+
Assertions.assertEquals(0.407070707, rachfordRice.calcBeta(K, z), 1e-6);
1516
} catch (Exception e) {
1617
e.printStackTrace();
1718
}
@@ -25,7 +26,8 @@ void testCalcBetaMethod2() {
2526
double[] K = new double[] {2.0, 0.01};
2627

2728
try {
28-
Assertions.assertEquals(0.407070707, RachfordRice.calcBeta(K, z), 1e-6);
29+
RachfordRice rachfordRice = new RachfordRice();
30+
Assertions.assertEquals(0.407070707, rachfordRice.calcBeta(K, z), 1e-6);
2931
} catch (Exception e) {
3032
e.printStackTrace();
3133
}

0 commit comments

Comments
 (0)