Skip to content

Commit

Permalink
improve TPflash speed (#860)
Browse files Browse the repository at this point in the history
* bug fix

* update flash

* imporve flash
  • Loading branch information
EvenSol authored Nov 25, 2023
1 parent b5c7f95 commit 3910d39
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
import java.awt.BorderLayout;
import java.awt.Container;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import neqsim.api.ioc.CalculationResult;
import neqsim.thermo.component.ComponentHydrate;
import neqsim.thermo.system.SystemInterface;
Expand Down Expand Up @@ -164,7 +161,7 @@ public void TPflash() {
} else {
system.setTotalNumberOfMoles(flowRate);
}
system.init(2);
system.init(1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public void stabilityAnalysis() {
err = 0;

if (iter <= 150 || !system.isImplementedCompositionDeriativesofFugacity()) {
if (iter % 7 == 0 && iter < 150 && useaccsubst) {
if (iter % 7 == 0 && useaccsubst) {
double vec1 = 0.0;

double vec2 = 0.0;
Expand Down Expand Up @@ -420,6 +420,7 @@ public void stabilityAnalysis() {
deltalogWi[i] = logWi[i] - oldlogw[i];
err += Math.abs(logWi[i] - oldlogw[i]);
Wi[j][i] = Math.exp(logWi[i]);
useaccsubst = true;
}
if (iter > 2 && err > errOld) {
useaccsubst = false;
Expand Down Expand Up @@ -840,6 +841,11 @@ public void stabilityAnalysis2() {
}
}
} while ((Math.abs(err) > 1e-9 || err > errOld) && iter < 200);
if (iter > 198) {
System.out.println("too many iterations....." + err + " temperature "
+ system.getTemperature("C") + " C " + system.getPressure("bara") + " bara");
new Exception("to many iterations ");
}
// logger.info("err: " + err + " ITER " + iter);
double xTrivialCheck0 = 0.0;
double xTrivialCheck1 = 0.0;
Expand Down Expand Up @@ -927,6 +933,7 @@ public void run() {
double oldDiff = 1.0e10;
double chemdev = 0;
int iterOut = 0;
double maxerr = 1e-12;
do {
iterOut++;
if (system.isChemicalSystem()) {
Expand Down Expand Up @@ -968,11 +975,16 @@ public void run() {
// diff = Math.abs((system.getBeta(system.getNumberOfPhases() - 1) - oldBeta) /
// oldBeta);
// logger.info("diff multiphase " + diff);
} while (diff > 1e-12 && !removePhase && (diff < oldDiff || iterations < 50)
if (iterations % 50 == 0) {
maxerr *= 100.0;
}
} while (diff > maxerr && !removePhase && (diff < oldDiff || iterations < 50)
&& iterations < 200);
// this.solveBeta(true);
if (iterations >= 199) {
logger.error("error in multiphase flash..did not solve in 200 iterations");
logger.error("diff " + diff + " temperaure " + system.getTemperature("C") + " pressure "
+ system.getPressure("bara"));
diff = this.solveBeta();
}
} while ((Math.abs(chemdev) > 1e-10 && iterOut < 100)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package neqsim.thermodynamicOperations.flashOps;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import neqsim.thermodynamicOperations.ThermodynamicOperations;
Expand Down Expand Up @@ -139,4 +140,49 @@ void testRun6() {
assertEquals(0.27697023508525664, testSystem5.getBeta(), 1e-6);
assertEquals(3, testSystem5.getNumberOfPhases());
}

@Test
void testTPflash1() {
testSystem = new neqsim.thermo.system.SystemSrkEos(273.15 + 177.0, 316.0);
testSystem.addComponent("water", 65.93229747922976);
testSystem.addComponent("NaCl", 0.784426208131475);
testSystem.addComponent("nitrogen", 0.578509157534656);
testSystem.addComponent("methane", 22.584113183429718);
testSystem.addComponent("ethane", 3.43870686718215);
testSystem.addComponent("propane", 0.26487350163523365);
testSystem.addComponent("i-butane", 0.04039429848533373);
testSystem.addComponent("n-butane", 0.1543856425679738);
testSystem.addComponent("i-pentane", 0.04039429848533373);
testSystem.addComponent("n-pentane", 0.1543856425679738);
testSystem.addTBPfraction("C6", 0.568724470114871, 84.93298402237961 / 1000.0,
666.591171644071 / 1000.0);
testSystem.addTBPfraction("C7", 0.9478147516962493, 90.01311937418495 / 1000.0,
746.9101810251765 / 1000.0);
testSystem.addTBPfraction("C8", 0.974840433764089, 102.34691375809437 / 1000.0,
776.2927119017166 / 1000.0);
testSystem.addTBPfraction("C9", 0.5505907716430188, 116.06055719132209 / 1000.0,
791.2983315058531 / 1000.0);
testSystem.addTBPfraction("C10", 1.9704404325720026, 221.831957 / 1000.0, 842.802708 / 1000.0);
testSystem.setMixingRule("classic");
testSystem.setMultiPhaseCheck(true);
testOps = new ThermodynamicOperations(testSystem);

for (int i = 0; i < 50; i++) {
testSystem.setTemperature(i, "C");
for (int j = 1; j < 50; j++) {
testSystem.setPressure(j, "bara");
try {
testOps.TPflash();
testSystem.initProperties();
} catch (Exception e) {
System.out.println("temperature " + testSystem.getTemperature("C") + " pressure "
+ testSystem.getPressure("bara"));
e.printStackTrace();
assertTrue(false);
}
}
}


}
}

0 comments on commit 3910d39

Please sign in to comment.