Skip to content

Commit

Permalink
Merge pull request #83 from equinor/updates_compressors
Browse files Browse the repository at this point in the history
fixed bug in stability analysis in flash
  • Loading branch information
EvenSol authored Nov 29, 2019
2 parents 9c89ea9 + 5f0e402 commit 87da2af
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/main/java/neqsim/thermodynamicOperations/flashOps/Flash.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,35 +112,35 @@ public void stabilityAnalysis()
sumw[0] += clonedSystem.getPhase(0).getComponent(i).getK()
* clonedSystem.getPhase(0).getComponent(i).getz();
}

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

int start=0;
int end= clonedSystem.getPhase(0).getNumberOfComponents();
// System.out.println("sumw0 " + sumw[0]);
// System.out.println("sumw1 " + sumw[1]);

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

for (int i = 0; i < clonedSystem.getPhase(0).getNumberOfComponents(); i++) {
clonedSystem.getPhase(1).getComponent(i).setx(clonedSystem.getPhase(0).getComponent(i).getz()
/ clonedSystem.getPhase(0).getComponent(i).getK() / sumw[1]);
clonedSystem.getPhase(0).getComponent(i).setx(clonedSystem.getPhase(0).getComponent(i).getK()
* clonedSystem.getPhase(0).getComponent(i).getz() / sumw[0]);
}
//for (int j = 0; j < clonedSystem.getNumberOfPhases(); j++) {
for (int j = start; j == end; j=j+mult) {

// for (int j = 0; j < clonedSystem.getNumberOfPhases(); j++) {
for (int j = start; j >= end; j = j + mult) {
for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) {
Wi[j][i] = clonedSystem.getPhase(j).getComponent(i).getx();
logWi[i] = Math.log(Wi[j][i]);
}
iterations = 0;
fNorm = 1.0e10;

do {
iterations++;
error[j] = 0.0;
Expand All @@ -163,7 +163,7 @@ public void stabilityAnalysis()
+ clonedSystem.getPhase(j).getComponent(i).getLogFugasityCoeffisient() - d[i]));
}
fNorm = f.norm2();
if(fNorm>fNormOld && iterations > 3) {
if (fNorm > fNormOld && iterations > 3) {
break;
}
if (iterations % 7 == 0 && fNorm < fNormOld && !secondOrderStabilityAnalysis) {
Expand Down Expand Up @@ -236,7 +236,8 @@ public void stabilityAnalysis()
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);
// logger.info("fnorm " + f.norm1() + " err " + error[j] + " iterations " +
// iterations + " phase " + j);

} while ((f.norm1() > 1e-6 && iterations < maxiterations) || (iterations % 7) == 0 || iterations < 3);
// (error[j]<oldErr && oldErr<oldOldErr) &&
Expand Down

0 comments on commit 87da2af

Please sign in to comment.