Skip to content

Commit 2b74e15

Browse files
authored
fix multiphase flash (#1286)
* update * fixed error
1 parent 320b7c3 commit 2b74e15

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

src/main/java/neqsim/thermo/system/SystemThermo.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -3338,7 +3338,7 @@ public final void initBeta() {
33383338
}
33393339
if (!isInitialized && this.getSumBeta() < 1.0 - phaseFractionMinimumLimit
33403340
|| this.getSumBeta() > 1.0 + phaseFractionMinimumLimit) {
3341-
logger.warn("SystemThermo:initBeta - Sum of beta does not equal 1.0. " + beta);
3341+
// logger.warn("SystemThermo:initBeta - Sum of beta does not equal 1.0. " + beta);
33423342
}
33433343
}
33443344

@@ -5104,7 +5104,9 @@ public void setMolarCompositionOfNamedComponents(String nameDef, double[] molarC
51045104
}
51055105

51065106
/**
5107-
* <p>setMixingRuleParametersForComponent.</p>
5107+
* <p>
5108+
* setMixingRuleParametersForComponent.
5109+
* </p>
51085110
*
51095111
* @param compName a {@link java.lang.String} object
51105112
*/

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

+14-4
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ public void stabilityAnalysis() {
324324
}
325325
}
326326
}
327-
328327
for (int i = 0; i < minimumGibbsEnergySystem.getPhase(0).getNumberOfComponents(); i++) {
328+
329329
if (minimumGibbsEnergySystem.getPhase(0).getComponent(i).isHydrocarbon()
330330
&& minimumGibbsEnergySystem.getPhase(0).getComponent(i).getz() > 1e-50) {
331331
if (Math.abs(
@@ -344,15 +344,14 @@ public void stabilityAnalysis() {
344344
}
345345
}
346346
}
347-
347+
boolean checkdForHCmix = false;
348348
for (int j = system.getPhase(0).getNumberOfComponents() - 1; j >= 0; j--) {
349349
if (minimumGibbsEnergySystem.getPhase(0).getComponent(j).getx() < 1e-100
350350
|| (minimumGibbsEnergySystem.getPhase(0).getComponent(j).getIonicCharge() != 0)
351351
|| (minimumGibbsEnergySystem.getPhase(0).getComponent(j).isHydrocarbon()
352352
&& j != hydrocarbonTestCompNumb && j != lightTestCompNumb)) {
353353
continue;
354354
}
355-
356355
double nomb = 0.0;
357356
for (int cc = 0; cc < system.getPhase(0).getNumberOfComponents(); cc++) {
358357
nomb = cc == j ? 1.0 : 1.0e-12;
@@ -362,12 +361,23 @@ public void stabilityAnalysis() {
362361

363362
if (clonedSystem.get(0).isPhase(1)) {
364363
try {
365-
clonedSystem.get(0).getPhase(1).getComponent(cc).setx(nomb);
364+
if (system.getPhase(1).getType() == PhaseType.AQUEOUS && !checkdForHCmix) {
365+
clonedSystem.get(0).getPhase(1).getComponent(cc)
366+
.setx(clonedSystem.get(0).getPhase(0).getComponent(cc).getK()
367+
/ clonedSystem.get(0).getPhase(0).getComponent(cc).getx());
368+
} else {
369+
clonedSystem.get(0).getPhase(1).getComponent(cc).setx(nomb);
370+
}
366371
} catch (Exception ex) {
367372
logger.warn(ex.getMessage());
368373
}
369374
}
370375
}
376+
377+
if (system.getPhase(1).getType() == PhaseType.AQUEOUS && !checkdForHCmix) {
378+
checkdForHCmix = true;
379+
}
380+
371381
// if(minimumGibbsEnergySystem.getPhase(0).getComponent(j).getName().equals("water")
372382
// && minimumGibbsEnergySystem.isChemicalSystem()) continue;
373383
// logger.info("STAB CHECK COMP " +

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

+30-4
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ void testSetAllocationComposition() throws IOException {
122122
assertEquals(0.0046202437, x_methane_A19, 1e-9);
123123

124124
// double[][] interactionParams =
125-
// ((PhaseEos) testSystem.getPhase(0)).getMixingRule().getBinaryInteractionParameters();
125+
// ((PhaseEos)
126+
// testSystem.getPhase(0)).getMixingRule().getBinaryInteractionParameters();
126127

127128
// System.out.println(Arrays.deepToString(interactionParams));
128129
}
@@ -134,7 +135,8 @@ void testReadFluid1() throws IOException {
134135
testSystem.setPressure(50.0, "bara");
135136

136137
// neqsim.thermo.util.readwrite.TablePrinter.printTable(
137-
// (((PhaseEos) testSystem.getPhase(0)).getMixingRule().getBinaryInteractionParameters()));
138+
// (((PhaseEos)
139+
// testSystem.getPhase(0)).getMixingRule().getBinaryInteractionParameters()));
138140

139141
// for (int i = 0; i < testSystem.getNumberOfComponents(); i++) {
140142
// System.out.println(testSystem.getComponent(i).getName() + " TC "
@@ -173,8 +175,8 @@ void testFluidWater() throws IOException {
173175

174176
// testSystem.prettyPrint();
175177

176-
neqsim.thermo.util.readwrite.TablePrinter.printTable(
177-
(((PhaseEos) testSystem.getPhase(0)).getMixingRule().getBinaryInteractionParameters()));
178+
//neqsim.thermo.util.readwrite.TablePrinter.printTable(
179+
// (((PhaseEos) testSystem.getPhase(0)).getMixingRule().getBinaryInteractionParameters()));
178180
double[][] paramsPhase0 =
179181
((PhaseEos) testSystem.getPhase(0)).getMixingRule().getBinaryInteractionParameters();
180182
double[][] paramsPhase1 =
@@ -190,4 +192,28 @@ void testFluidWater() throws IOException {
190192
}
191193
}
192194
}
195+
196+
@Test
197+
void testFluidWater2() throws IOException {
198+
testSystem = EclipseFluidReadWrite.read(fluid_water);
199+
testSystem.setMultiPhaseCheck(true);
200+
201+
// testSystem.init(0);
202+
203+
double molcomp[] = new double[] {.005823483446243756, 0.011911670685498591, 0.7510528953701038,
204+
0.06432302170169239, 0.027440959875481938, 0.003176445516132957, 0.0068822986182880755,
205+
0.0015882227580664785, 0.002029395746418279, 0.0018529265510775586, 0.0021176303440886383,
206+
0.001235284367385039, 0.001235284367385039, 0.0008823459767035993, 0.00044117298835179964,
207+
0.00017646919534071987, 0.00405500399809711783049249174136};
208+
209+
testSystem.setMolarComposition(molcomp);
210+
211+
ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem);
212+
testSystem.setPressure(60.0, "bara");
213+
testSystem.setTemperature(65.0, "C");
214+
testOps.TPflash();
215+
216+
Assertions.assertEquals(3, testSystem.getNumberOfPhases());
217+
218+
}
193219
}

0 commit comments

Comments
 (0)