Skip to content

Commit 5b99a15

Browse files
authored
remove unhandeled runtime exception (#1042)
* remove unhandeled runtime exception * added possibility to chenge method used in Rachford RIce * update * Update PhaseEos.java
1 parent 8e983c0 commit 5b99a15

File tree

3 files changed

+63
-30
lines changed

3 files changed

+63
-30
lines changed

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

+17-19
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public void init(double totalNumberOfMoles, int numberOfComponents, int initType
109109
}
110110
} catch (Exception ex) {
111111
logger.warn("Failed to solve for molarVolume within the iteration limit.");
112+
logger.error(ex.getMessage());
112113
throw new RuntimeException(ex);
113114
// logger.error("too many iterations in volume calc!", ex);
114115
// logger.info("moles " + numberOfMolesInPhase);
@@ -191,21 +192,20 @@ public void resetMixingRule(int type) {
191192
* molarVolume2.
192193
* </p>
193194
*
194-
* @param pressure a double
195+
* @param pressure a double
195196
* @param temperature a double
196-
* @param A a double
197-
* @param B a double
198-
* @param pt the PhaseType of the phase.
197+
* @param A a double
198+
* @param B a double
199+
* @param pt the PhaseType of the phase.
199200
* @return a double
200-
* @throws neqsim.util.exception.IsNaNException if any.
201+
* @throws neqsim.util.exception.IsNaNException if any.
201202
* @throws neqsim.util.exception.TooManyIterationsException if any.
202203
*/
203204
public double molarVolume2(double pressure, double temperature, double A, double B, PhaseType pt)
204205
throws neqsim.util.exception.IsNaNException,
205206
neqsim.util.exception.TooManyIterationsException {
206-
double BonV =
207-
pt == PhaseType.LIQUID ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature())
208-
: pressure * getB() / (numberOfMolesInPhase * temperature * R);
207+
double BonV = pt == PhaseType.LIQUID ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature())
208+
: pressure * getB() / (numberOfMolesInPhase * temperature * R);
209209
if (BonV < 0) {
210210
BonV = 0.0;
211211
}
@@ -288,9 +288,8 @@ public double molarVolume2(double pressure, double temperature, double A, double
288288
public double molarVolume(double pressure, double temperature, double A, double B, PhaseType pt)
289289
throws neqsim.util.exception.IsNaNException,
290290
neqsim.util.exception.TooManyIterationsException {
291-
double BonV =
292-
pt == PhaseType.LIQUID ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature())
293-
: pressure * getB() / (numberOfMolesInPhase * temperature * R);
291+
double BonV = pt == PhaseType.LIQUID ? 2.0 / (2.0 + temperature / getPseudoCriticalTemperature())
292+
: pressure * getB() / (numberOfMolesInPhase * temperature * R);
294293

295294
if (BonV < 0) {
296295
BonV = 1.0e-4;
@@ -438,10 +437,10 @@ public double calcAi(int compNumb, PhaseInterface phase, double temperature, dou
438437
* calcAT.
439438
* </p>
440439
*
441-
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
440+
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
442441
* @param temperature a double
443-
* @param pressure a double
444-
* @param numbcomp a int
442+
* @param pressure a double
443+
* @param numbcomp a int
445444
* @return a double
446445
*/
447446
public double calcAT(PhaseInterface phase, double temperature, double pressure, int numbcomp) {
@@ -454,10 +453,10 @@ public double calcAT(PhaseInterface phase, double temperature, double pressure,
454453
* calcATT.
455454
* </p>
456455
*
457-
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
456+
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
458457
* @param temperature a double
459-
* @param pressure a double
460-
* @param numbcomp a int
458+
* @param pressure a double
459+
* @param numbcomp a int
461460
* @return a double
462461
*/
463462
public double calcATT(PhaseInterface phase, double temperature, double pressure, int numbcomp) {
@@ -1199,8 +1198,7 @@ public double[][] dFdxdxMatrixSimple() {
11991198
}
12001199

12011200
for (int i = 0; i < numberOfComponents; i++) {
1202-
matrix[i][numberOfComponents] =
1203-
(FBT + FBD * AT) * Bi[i] + FDT * Ai[i] + FD * componentArray[i].getAiT(); // dFdndT
1201+
matrix[i][numberOfComponents] = (FBT + FBD * AT) * Bi[i] + FDT * Ai[i] + FD * componentArray[i].getAiT(); // dFdndT
12041202
matrix[numberOfComponents][i] = matrix[i][numberOfComponents];
12051203

12061204
matrix[i][numberOfComponents + 1] = FnV + FBV * Bi[i] + FDV * Ai[i]; // dFdndV

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

+37-11
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,52 @@
1818
public class RachfordRice implements Serializable {
1919
private static final long serialVersionUID = 1000;
2020
private double[] beta = new double[2];
21+
private static String method = "Michelsen2001"; // alternative use Nielsen2023
22+
23+
public static String getMethod() {
24+
return RachfordRice.method;
25+
}
26+
27+
public static void setMethod(String method) {
28+
RachfordRice.method = method;
29+
}
2130

2231
/**
2332
* <p>
2433
* calcBeta. For gas liquid systems.
2534
* </p>
2635
*
27-
* Method based on Michelsen Mollerup, 2001
36+
* Method used is defined in method String variable
2837
*
2938
* @return Beta Mole fraction of gas phase
3039
* @throws neqsim.util.exception.IsNaNException if any.
3140
* @throws neqsim.util.exception.TooManyIterationsException if any.
3241
*/
3342
public double calcBeta(double[] K, double[] z) throws neqsim.util.exception.IsNaNException,
3443
neqsim.util.exception.TooManyIterationsException {
44+
if (method.equals("Michelsen2001")) {
45+
return calcBetaMichelsen2001(K, z);
46+
} else if (method.equals("Nielsen2023")) {
47+
return calcBetaNielsen2023(K, z);
48+
} else {
49+
return calcBetaMichelsen2001(K, z);
50+
}
51+
}
52+
53+
/**
54+
* <p>
55+
* calcBeta. For gas liquid systems.
56+
* </p>
57+
*
58+
* Method based on Michelsen Mollerup, 2001
59+
*
60+
* @return Beta Mole fraction of gas phase
61+
* @throws neqsim.util.exception.IsNaNException if any.
62+
* @throws neqsim.util.exception.TooManyIterationsException if any.
63+
*/
64+
public double calcBetaMichelsen2001(double[] K, double[] z)
65+
throws neqsim.util.exception.IsNaNException,
66+
neqsim.util.exception.TooManyIterationsException {
3567

3668
int i;
3769
double tolerance = neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit;
@@ -156,19 +188,18 @@ public double calcBeta(double[] K, double[] z) throws neqsim.util.exception.IsNa
156188
return nybeta;
157189
}
158190

159-
160-
161191
/**
162192
* <p>
163-
* calcBeta. For gas liquid systems. Method based on Avoiding round-off error in the Rachford–Rice
164-
* equation, Nielsen, Lia, 2023
193+
* calcBetaNielsen2023. For gas liquid systems. Method based on Avoiding round-off error in the
194+
* Rachford–Rice equation, Nielsen, Lia, 2023
165195
* </p>
166196
*
167197
* @return Beta Mole fraction of gas phase
168198
* @throws neqsim.util.exception.IsNaNException if any.
169199
* @throws neqsim.util.exception.TooManyIterationsException if any.
170200
*/
171-
public double calcBeta2(double[] K, double[] z) throws neqsim.util.exception.IsNaNException,
201+
public double calcBetaNielsen2023(double[] K, double[] z)
202+
throws neqsim.util.exception.IsNaNException,
172203
neqsim.util.exception.TooManyIterationsException {
173204

174205
double tolerance = neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit;
@@ -295,8 +326,6 @@ public double[] getBeta() {
295326
return beta;
296327
}
297328

298-
299-
300329
/** {@inheritDoc} */
301330
public final double calcBetaS(SystemInterface system) throws neqsim.util.exception.IsNaNException,
302331
neqsim.util.exception.TooManyIterationsException {
@@ -447,7 +476,4 @@ public final double calcBetaS(SystemInterface system) throws neqsim.util.excepti
447476
return this.beta[0];
448477
}
449478

450-
451479
}
452-
453-

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

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ void testCalcBeta() {
1717
e.printStackTrace();
1818
}
1919

20+
try {
21+
RachfordRice rachfordRice = new RachfordRice();
22+
rachfordRice.setMethod("Nielsen2023");
23+
Assertions.assertEquals(0.407070707, rachfordRice.calcBeta(K, z), 1e-6);
24+
rachfordRice.setMethod("Michelsen2001");
25+
} catch (Exception e) {
26+
e.printStackTrace();
27+
}
28+
2029
}
2130

2231
@Test

0 commit comments

Comments
 (0)