Skip to content

Commit

Permalink
update flash
Browse files Browse the repository at this point in the history
  • Loading branch information
EvenSol committed Dec 2, 2024
1 parent 83a6815 commit 595a3f1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
28 changes: 14 additions & 14 deletions src/main/java/neqsim/thermodynamicoperations/flashops/Flash.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public abstract class Flash extends BaseOperation {
int i = 0;
int j = 0;
int iterations = 0;
int maxNumberOfIterations = 100;
int maxNumberOfIterations = 50;
double gibbsEnergy = 0;
double gibbsEnergyOld = 0;
double Kold = 0;
Expand Down Expand Up @@ -72,6 +72,8 @@ public int findLowestGibbsEnergyPhase() {
} else {
lowestGibbsEnergyPhase = 1;
}
logger.info("Lowest Gibbs energy phase determined: Phase {}", lowestGibbsEnergyPhase);

findLowestGibbsPhaseIsChecked = true;
}
return lowestGibbsEnergyPhase;
Expand Down Expand Up @@ -113,7 +115,7 @@ public void stabilityAnalysis() throws neqsim.util.exception.IsNaNException,

SystemInterface clonedSystem = minimumGibbsEnergySystem;
clonedSystem.setTotalNumberOfMoles(1.0);

clonedSystem.init(1);
double[] sumw = new double[2];
sumw[1] = 0.0;
sumw[0] = 0.0;
Expand All @@ -124,13 +126,10 @@ public void stabilityAnalysis() throws neqsim.util.exception.IsNaNException,
* clonedSystem.getPhase(0).getComponent(i).getz();
}

// System.out.println("sumw0 " + sumw[0]);
// System.out.println("sumw1 " + sumw[1]);

int start = 0;
int end = 1; // clonedSystem.getNumberOfPhases()-1;
int end = 1;
int mult = 1;
// if (sumw[1] > sumw[0]) {

if (lowestGibbsEnergyPhase == 0) {
start = end;
end = 0;
Expand Down Expand Up @@ -176,7 +175,7 @@ public void stabilityAnalysis() throws neqsim.util.exception.IsNaNException,
}
fNorm = f.norm2();
if (fNorm > fNormOld && iterations > 3 && (iterations - 1) % 7 != 0) {
break;
// break;
}
if (iterations % 7 == 0 && fNorm < fNormOld && !secondOrderStabilityAnalysis) {
double vec1 = 0.0;
Expand Down Expand Up @@ -252,17 +251,18 @@ public void stabilityAnalysis() throws neqsim.util.exception.IsNaNException,
deltalogWi[i] = logWi[i] - oldlogw[i];
clonedSystem.getPhase(j).getComponent(i).setx(Wi[j][i] / sumw[j]);
}
// logger.info("fnorm " + f.norm1() + " err " + error[j] + " iterations " + iterations
// + " phase " + j);
} while ((f.norm1() > 1e-6 && iterations < maxiterations) || (iterations % 7) == 0
|| iterations < 3);
//logger.info("fnorm " + f.norm1() + " err " + error[j] + " iterations " + iterations
// + " phase " + j);
} while ((f.norm1() > 1e-6 && iterations < maxiterations && error[j] > 1e-6)
|| (iterations % 70) == 0 || iterations < 3);
// (error[j]<oldErr && oldErr<oldOldErr) &&
// logger.info("err " + error[j]);
// logger.info("iterations " + iterations);
// logger.info("f.norm1() " + f.norm1());
if (iterations >= maxiterations) {
logger.error("err staability check " + error[j]);
// throw new util.exception.TooManyIterationsException();
//logger.error("err staability check " + error[j]);
throw new neqsim.util.exception.TooManyIterationsException("too many iterations", null,
maxiterations);
}

tm[j] = 1.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,14 @@ public void run() {
system.init(0);
system.init(1);

if (system.getPhase(0).getGibbsEnergy() < system.getPhase(1).getGibbsEnergy()) {
minimumGibbsEnergy = system.getPhase(0).getGibbsEnergy();
if ((system.getPhase(0).getGibbsEnergy()
* (1.0 - Math.signum(system.getPhase(0).getGibbsEnergy()) * 1e-8)) < system.getPhase(1)
.getGibbsEnergy()) {
minGibbsPhase = 0;
} else {
minGibbsPhase = 1;
minimumGibbsEnergy = system.getPhase(1).getGibbsEnergy();
}
// logger.debug("minimum gibbs phase " + minGibbsPhase);

if (system.getPhase(0).getNumberOfComponents() == 1 || system.getMaxNumberOfPhases() == 1) {
system.setNumberOfPhases(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ void testRun2() {

assertEquals(flowline1.getOutletStream().getPressure(), 120, 1e-3);
assertEquals(flowline1.getOutletStream().getFlowRate("MSm3/day"), 4.0, 1e-3);
assertEquals(flowline1.getInletStream().getPressure(), 199.866499892457, 0.1);
assertEquals(flowline1.getInletStream().getPressure(), 199.85522835429, 0.1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@ public void runTEGProcessTest2() {
1e-6);
}

@Test

// @Test
public void testRun_step() {
neqsim.thermo.system.SystemInterface feedGas =
new neqsim.thermo.system.SystemSrkCPAstatoil(273.15 + 42.0, 10.00);
Expand Down

0 comments on commit 595a3f1

Please sign in to comment.