Skip to content

Commit eedf990

Browse files
authoredMar 21, 2024··
fix: more robust propertyFlash (#967)
1 parent 2c62bfe commit eedf990

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed
 

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.apache.logging.log4j.Logger;
1212
import neqsim.api.ioc.CalculationResult;
1313
import neqsim.thermo.component.ComponentHydrate;
14+
import neqsim.thermo.component.ComponentInterface;
1415
import neqsim.thermo.system.SystemInterface;
1516
import neqsim.thermo.system.SystemProperties;
1617
import neqsim.thermodynamicOperations.flashOps.CalcIonicComposition;
@@ -2031,6 +2032,9 @@ public CalculationResult propertyFlash(List<Double> Spec1, List<Double> Spec2, i
20312032
for (int t = 0; t < Spec1.size(); t++) {
20322033
calculationError[t] = "Sum of fractions must be approximately to 1 or 100, currently ("
20332034
+ String.valueOf(sum[0]) + ")";
2035+
if (sum[0] == 0.0) {
2036+
calculationError[t] = calculationError[t] + ". Have you called init(0)?";
2037+
}
20342038
}
20352039
}
20362040
}
@@ -2065,7 +2069,8 @@ public CalculationResult propertyFlash(List<Double> Spec1, List<Double> Spec2, i
20652069
for (int compIndex = 0; compIndex < fraction.length; compIndex++) {
20662070
// Loop all input component names / fractions
20672071
for (int index = 0; index < components.size(); index++) {
2068-
if (systemComponents[compIndex] == components.get(index)) {
2072+
if (systemComponents[compIndex] == ComponentInterface
2073+
.getComponentNameFromAlias(components.get(index))) {
20692074
fraction[compIndex] = onlineFractions.get(index).get(t).doubleValue();
20702075
break;
20712076
}

‎src/test/java/neqsim/thermodynamicOperations/ThermodynamicOperationsTest.java

+75
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,81 @@ void testFlash() {
5353
}
5454
}
5555

56+
@Test
57+
void testFluidDefined() {
58+
double[] fractions = new double[] {98.0, 2.0};
59+
List<Double> Sp1 =
60+
Arrays.asList(new Double[] {22.1, 23.2, 24.23, 25.98, 25.23, 26.1, 27.3, 28.7, 23.5, 22.7});
61+
List<Double> Sp2 = Arrays.asList(
62+
new Double[] {288.1, 290.1, 295.1, 301.2, 299.3, 310.2, 315.3, 310.0, 305.2, 312.7});
63+
List<String> components = Arrays.asList(new String[] {"O2", "N2"});
64+
List<List<Double>> onlineFractions = new ArrayList<List<Double>>();
65+
66+
for (double d : fractions) {
67+
ArrayList<Double> l = new ArrayList<Double>();
68+
for (int i = 0; i < Sp1.size(); i++) {
69+
l.add(d);
70+
}
71+
onlineFractions.add(l);
72+
}
73+
74+
SystemInterface fluid_static = new SystemSrkEos(273.15 + 45.0, 22.0);
75+
fluid_static.addComponent("N2", fractions[0]);
76+
fluid_static.addComponent("O2", fractions[1]);
77+
fluid_static.setMixingRule(2);
78+
fluid_static.useVolumeCorrection(true);
79+
fluid_static.setMultiPhaseCheck(true);
80+
// fluid_static.init(0);
81+
82+
ThermodynamicOperations fluidOps_static = new ThermodynamicOperations(fluid_static);
83+
CalculationResult res_static = fluidOps_static.propertyFlash(Sp1, Sp2, 1, null, null);
84+
85+
for (String err : res_static.calculationError) {
86+
Assertions.assertEquals(err,
87+
"Sum of fractions must be approximately to 1 or 100, currently (0.0). Have you called init(0)?");
88+
}
89+
// fluid_static.setTotalNumberOfMoles(1);
90+
fluid_static.init(0);
91+
res_static = fluidOps_static.propertyFlash(Sp1, Sp2, 1, null, null);
92+
for (String err : res_static.calculationError) {
93+
Assertions.assertEquals(err, null);
94+
}
95+
96+
SystemInterface fluid = new SystemSrkEos(273.15 + 45.0, 22.0);
97+
fluid.addComponent("nitrogen", 0.79);
98+
fluid.addComponent("oxygen", 0.21);
99+
fluid.setMixingRule(2);
100+
fluid.useVolumeCorrection(true);
101+
fluid.setMultiPhaseCheck(true);
102+
103+
ThermodynamicOperations fluidOps = new ThermodynamicOperations(fluid);
104+
CalculationResult res = fluidOps.propertyFlash(Sp1, Sp2, 1, components, onlineFractions);
105+
Assertions.assertEquals(Sp1.size(), res.calculationError.length);
106+
for (String err : res.calculationError) {
107+
Assertions.assertNull(err);
108+
}
109+
110+
fluid = new SystemSrkEos(273.15 + 45.0, 22.0);
111+
fluid.addComponent("N2", 0.79);
112+
fluid.addComponent("O2", 0.21);
113+
fluid.setMixingRule(2);
114+
fluid.useVolumeCorrection(true);
115+
fluid.setMultiPhaseCheck(true);
116+
117+
118+
fluidOps = new ThermodynamicOperations(fluid);
119+
CalculationResult res2 = fluidOps.propertyFlash(Sp1, Sp2, 1, components, onlineFractions);
120+
Assertions.assertEquals(Sp1.size(), res2.calculationError.length);
121+
for (String err : res2.calculationError) {
122+
Assertions.assertNull(err);
123+
}
124+
125+
Assertions.assertEquals(res, res2);
126+
// todo: why does below not work?
127+
128+
// Assertions.assertArrayEquals(res_static.fluidProperties[0], res.fluidProperties[0]);
129+
}
130+
56131
@Test
57132
void testNeqSimPython() {
58133
SystemInterface thermoSystem = new neqsim.thermo.system.SystemSrkEos(280.0, 10.0);

0 commit comments

Comments
 (0)
Please sign in to comment.