Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try fix #1029

Merged
merged 2 commits into from
Jun 19, 2024
Merged

try fix #1029

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,15 @@ public boolean stabilityCheck() {
this.solidPhaseFlash();
}
} else {
RachfordRice rachfordRice = new RachfordRice();
try {
system.setBeta(RachfordRice.calcBeta(system.getKvector(), system.getzvector()));
system.setBeta(rachfordRice.calcBeta(system.getKvector(), system.getzvector()));
} catch (Exception ex) {
if (!Double.isNaN(rachfordRice.getBeta()[0])) {
system.setBeta(rachfordRice.getBeta()[0]);
} else {
system.setBeta(Double.NaN);
}
logger.error(ex.getMessage(), ex);
}
system.calc_x_y();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@

package neqsim.thermodynamicOperations.flashOps;

import java.io.Serializable;

/**
* RachfordRice classes.
*
* @author Even Solbraa
*/
public class RachfordRice {
public class RachfordRice implements Serializable {
private static final long serialVersionUID = 1000;
private double[] beta = new double[2];

/**
* <p>
Expand All @@ -25,7 +28,7 @@ public class RachfordRice {
* @throws neqsim.util.exception.IsNaNException if any.
* @throws neqsim.util.exception.TooManyIterationsException if any.
*/
public static double calcBeta(double[] K, double[] z) throws neqsim.util.exception.IsNaNException,
public double calcBeta(double[] K, double[] z) throws neqsim.util.exception.IsNaNException,
neqsim.util.exception.TooManyIterationsException {

int i;
Expand Down Expand Up @@ -138,6 +141,8 @@ public static double calcBeta(double[] K, double[] z) throws neqsim.util.excepti
} else if (nybeta >= 1.0 - tolerance) {
nybeta = 1.0 - tolerance;
}
beta[0] = nybeta;
beta[1] = 1.0 - nybeta;

if (iterations >= maxIterations) {
throw new neqsim.util.exception.TooManyIterationsException(new RachfordRice(), "calcBeta",
Expand All @@ -159,8 +164,7 @@ public static double calcBeta(double[] K, double[] z) throws neqsim.util.excepti
* @throws neqsim.util.exception.IsNaNException if any.
* @throws neqsim.util.exception.TooManyIterationsException if any.
*/
public static double calcBeta2(double[] K, double[] z)
throws neqsim.util.exception.IsNaNException,
public double calcBeta2(double[] K, double[] z) throws neqsim.util.exception.IsNaNException,
neqsim.util.exception.TooManyIterationsException {

double tolerance = neqsim.thermo.ThermodynamicModelSettings.phaseFractionMinimumLimit;
Expand Down Expand Up @@ -269,6 +273,9 @@ public static double calcBeta2(double[] K, double[] z)
V = 1.0 - tolerance;
}

beta[0] = V;
beta[1] = 1.0 - V;

if (iter >= maxIterations) {
throw new neqsim.util.exception.TooManyIterationsException(new RachfordRice(), "calcBeta",
maxIterations);
Expand All @@ -280,4 +287,8 @@ public static double calcBeta2(double[] K, double[] z)
return V;
}

public double[] getBeta() {
return beta;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ public void sucsSubs() {
}

double oldBeta = system.getBeta();

RachfordRice rachfordRice = new RachfordRice();
try {
system.setBeta(RachfordRice.calcBeta(system.getKvector(), system.getzvector()));
system.setBeta(rachfordRice.calcBeta(system.getKvector(), system.getzvector()));
} catch (IsNaNException ex) {
logger.warn("Not able to calculate beta. Value is NaN");
system.setBeta(oldBeta);
Expand Down Expand Up @@ -132,13 +134,16 @@ public void accselerateSucsSubs() {
system.getPhase(1).getComponent(i).setK(Math.exp(lnK[i]));
}
double oldBeta = system.getBeta();
RachfordRice rachfordRice = new RachfordRice();
try {
system.setBeta(RachfordRice.calcBeta(system.getKvector(), system.getzvector()));
system.setBeta(rachfordRice.calcBeta(system.getKvector(), system.getzvector()));
} catch (Exception ex) {
system.setBeta(rachfordRice.getBeta()[0]);
if (system.getBeta() > 1.0 - betaTolerance || system.getBeta() < betaTolerance) {
system.setBeta(oldBeta);
}
logger.info("temperature " + system.getTemperature() + " pressure " + system.getPressure());
// logger.info("temperature " + system.getTemperature() + " pressure " +
// system.getPressure());
logger.error(ex.getMessage(), ex);
}

Expand Down Expand Up @@ -178,7 +183,8 @@ public void resetK() {
system.getPhase(1).getComponents()[i].setK(Math.exp(lnK[i]));
}
try {
system.setBeta(RachfordRice.calcBeta(system.getKvector(), system.getzvector()));
RachfordRice rachfordRice = new RachfordRice();
system.setBeta(rachfordRice.calcBeta(system.getKvector(), system.getzvector()));
system.calc_x_y();
system.init(1);
} catch (Exception ex) {
Expand Down Expand Up @@ -249,7 +255,8 @@ public void run() {

// Calculates phase fractions and initial composition based on Wilson K-factors
try {
system.setBeta(RachfordRice.calcBeta(system.getKvector(), system.getzvector()));
RachfordRice rachfordRice = new RachfordRice();
system.setBeta(rachfordRice.calcBeta(system.getKvector(), system.getzvector()));
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ void testCalcBeta() {
double[] K = new double[] {2.0, 0.01};

try {
Assertions.assertEquals(0.407070707, RachfordRice.calcBeta(K, z), 1e-6);
RachfordRice rachfordRice = new RachfordRice();
Assertions.assertEquals(0.407070707, rachfordRice.calcBeta(K, z), 1e-6);
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -25,7 +26,8 @@ void testCalcBetaMethod2() {
double[] K = new double[] {2.0, 0.01};

try {
Assertions.assertEquals(0.407070707, RachfordRice.calcBeta(K, z), 1e-6);
RachfordRice rachfordRice = new RachfordRice();
Assertions.assertEquals(0.407070707, rachfordRice.calcBeta(K, z), 1e-6);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down