diff --git a/src/main/java/neqsim/thermodynamicoperations/flashops/Flash.java b/src/main/java/neqsim/thermodynamicoperations/flashops/Flash.java index 623fd829a..c1296c08c 100644 --- a/src/main/java/neqsim/thermodynamicoperations/flashops/Flash.java +++ b/src/main/java/neqsim/thermodynamicoperations/flashops/Flash.java @@ -65,6 +65,7 @@ public int findLowestGibbsEnergyPhase() { if (!findLowestGibbsPhaseIsChecked) { minimumGibbsEnergySystem = system.clone(); minimumGibbsEnergySystem.init(0); + minimumGibbsEnergySystem.setTotalNumberOfMoles(1.0); minimumGibbsEnergySystem.init(1); if ((minimumGibbsEnergySystem.getPhase(0).getGibbsEnergy() * (1.0 - Math.signum(minimumGibbsEnergySystem.getPhase(0).getGibbsEnergy()) @@ -119,8 +120,10 @@ public void stabilityAnalysis() throws neqsim.util.exception.IsNaNException, sumw[1] = 0.0; sumw[0] = 0.0; for (int i = 0; i < clonedSystem.getPhase(0).getNumberOfComponents(); i++) { - sumw[1] += clonedSystem.getPhase(0).getComponent(i).getz() - / clonedSystem.getPhase(0).getComponent(i).getK(); + if (clonedSystem.getPhase(0).getComponent(i).getK() > 0) { + sumw[1] += clonedSystem.getPhase(0).getComponent(i).getz() + / clonedSystem.getPhase(0).getComponent(i).getK(); + } if (clonedSystem.getPhase(0).getComponent(i).getz() > 0) { sumw[0] += clonedSystem.getPhase(0).getComponent(i).getK() * clonedSystem.getPhase(0).getComponent(i).getz(); @@ -168,7 +171,17 @@ public void stabilityAnalysis() throws neqsim.util.exception.IsNaNException, if ((iterations <= maxiterations - 10) || !system.isImplementedCompositionDeriativesofFugacity()) { - clonedSystem.init(1, j); + try { + clonedSystem.init(1, j); + } catch (Exception e) { + if (j == 0) { + clonedSystem.init(1, 1); + } else { + clonedSystem.init(1, 0); + } + logger.error(e.toString()); + throw e; + } fNormOld = fNorm; for (int i = 0; i < clonedSystem.getPhases()[0].getNumberOfComponents(); i++) { f.set(i, 0, Math.sqrt(Wi[j][i]) * (Math.log(Wi[j][i]) @@ -263,7 +276,7 @@ public void stabilityAnalysis() throws neqsim.util.exception.IsNaNException, // logger.info("iterations " + iterations); // logger.info("f.norm1() " + f.norm1()); if (iterations >= maxiterations) { - // logger.error("err staability check " + error[j]); + logger.error("err staability check " + error[j]); throw new neqsim.util.exception.TooManyIterationsException("too many iterations", null, maxiterations); }