Skip to content
Draft
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 @@ -150,4 +150,6 @@ public interface TBPModelInterface {
* @return a {@link java.lang.String} object
*/
public String getName();

public void setBoilingPoint(double boilingPoint);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@ public TBPfractionModel() {}
public abstract class TBPBaseModel implements TBPModelInterface, Cloneable, java.io.Serializable {
/** Serialization version UID. */
private static final long serialVersionUID = 1000;

private double boilingPoint = 0.0;
protected boolean calcm = true;

public void setBoilingPoint(double boilingPoint) {
this.boilingPoint = boilingPoint;
}

public double getBoilingPoint() {
return boilingPoint;
}

/** {@inheritDoc} */
@Override
public String getName() {
Expand All @@ -46,6 +54,9 @@ public String getName() {
/** {@inheritDoc} */
@Override
public double calcTB(double molarMass, double density) {
if (getBoilingPoint() > 0.0) {
return getBoilingPoint();
}
return Math.pow((molarMass / 5.805e-5 * Math.pow(density, 0.9371)), 1.0 / 2.3776);
}

Expand Down Expand Up @@ -189,10 +200,13 @@ public double calcm(double molarMass, double density) {
return TBPfractionCoefs[2][0] + TBPfractionCoefs[2][1] * molarMass
+ TBPfractionCoefs[2][2] * density + TBPfractionCoefs[2][3] * Math.pow(molarMass, 2.0);
}

/** {@inheritDoc} */
@Override
public double calcTB(double molarMass, double density) {
if (getBoilingPoint() > 0.0) {
return getBoilingPoint();
}
if (molarMass < 540) {
return 2E-06 * Math.pow(molarMass, 3) - 0.0035 * Math.pow(molarMass, 2) + 2.4003 * molarMass
+ 171.74;
Expand Down Expand Up @@ -249,6 +263,41 @@ public PedersenTBPModelPR() {
}
}


public class PedersenTBPModelPR2 extends PedersenTBPModelSRK {
/** Serialization version UID. */

private static final long serialVersionUID = 1000;

public PedersenTBPModelPR2() {
double[][] TBPfractionCoefOil2 = {{73.4043, 97.3562, 0.618744, -2059.32, 0.0},
{0.0728462, 2.18811, 163.91, -4043.23, 1.0 / 4.0},
{0.373765, 0.00549269, 0.0117934, -4.93049e-6, 0.0}};
double[][] TBPfractionCoefHeavyOil2 = {{9.13222e2, 1.01134e1, 4.54194e-2, -1.3587e4, 0.0},
{1.28155, 1.26838, 1.67106e2, -8.10164e3, 0.25},
{-2.3838e-1, 6.10147e-2, 1.32349, -6.52067e-3, 0.0}};
double[] TPBracketcoefs2 = {0.25969, 0.50033};
TBPfractionCoefOil = TBPfractionCoefOil2;
TBPfractionCoefsHeavyOil = TBPfractionCoefHeavyOil2;
TPBracketcoefs = TPBracketcoefs2;
}

/** {@inheritDoc} */
@Override
public double calcTB(double molarMass, double density) {
if (getBoilingPoint() > 0.0) {
return getBoilingPoint();
}
//Søreide correlation
double calculated_TB = (1928.3 - 1.695e5 * Math.pow(molarMass, -0.03522)
* Math.pow(density, 3.266) * Math.exp(-4.922e-3 * molarMass - 4.7685 * density
+ 3.462e-3 * molarMass * density));
return calculated_TB/1.8;
}
}



public class PedersenTBPModelPRHeavyOil extends PedersenTBPModelPR {
/** Serialization version UID. */
private static final long serialVersionUID = 1000;
Expand Down Expand Up @@ -309,10 +358,10 @@ public double calcAcentricFactor2(double molarMass, double density) {
/** {@inheritDoc} */
@Override
public double calcTB(double molarMass, double density) {
// Soreide method (Whitson book)
return 5.0 / 9.0 * (1928.3 - 1.695e5 * Math.pow(molarMass, -0.03522)
* Math.pow(density, 3.266)
* Math.exp(-4.922e-3 * molarMass - 4.7685 * density + 3.462e-3 * molarMass * density)); // 97.58*Math.pow(molarMass,0.3323)*Math.pow(density,0.04609);
if (getBoilingPoint() > 0.0) {
return getBoilingPoint();
}
return 97.58*Math.pow(molarMass,0.3323)*Math.pow(density,0.04609);
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -521,6 +570,8 @@ public TBPModelInterface getModel(String name) {
return new PedersenTBPModelSRKHeavyOil();
} else if (name.equals("PedersenPR")) {
return new PedersenTBPModelPR();
} else if (name.equals("PedersenPR2")) {
return new PedersenTBPModelPR2();
} else if (name.equals("PedersenPRHeavyOil")) {
logger.info("using PR heavy oil TBp.................");
return new PedersenTBPModelPRHeavyOil();
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/neqsim/thermo/system/SystemInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,29 @@ public void addTBPfraction(String componentName, double numberOfMoles, double mo
public void addTBPfraction(String componentName, double numberOfMoles, double molarMass,
double density, double criticalTemperature, double criticalPressure, double acentricFactor);

/**
* <p>
* addTBPfraction2.
* </p>
*
* @param componentName a {@link java.lang.String} object
* @param numberOfMoles a double
* @param molarMass a double
* @param boilingPoint a double
*/
public void addTBPfraction2(String componentName, double numberOfMoles, double molarMass,
double boilingPoint);

/**
* Calculate density from boiling point and molar mass using TBP correlation.
*
* @param molarMass molar mass in kg/mol
* @param boilingPoint boiling point in K
* @return density in g/cm3
*/
public double calculateDensityFromBoilingPoint(double molarMass, double boilingPoint);


/**
* Add to component names.
*
Expand Down Expand Up @@ -2679,4 +2702,19 @@ public default void setPhysicalPropertyModel(int type) {
* @param molarComposition an array of molar compositions to set for the matching components
*/
public void setMolarCompositionOfNamedComponents(String nameDef, double[] molarComposition);

/**
* Add TBP fraction using density and boiling point, calculating molar mass.
*/
public void addTBPfraction3(String componentName, double numberOfMoles, double density,
double boilingPoint);

/**
* Add TBP fraction using molar mass , density and boiling point
*/
public void addTBPfraction4(String componentName, double numberOfMoles, double molarMass, double density,
double boilingPoint);

public double calculateMolarMassFromDensityAndBoilingPoint(double density, double boilingPoint);

}
155 changes: 155 additions & 0 deletions src/main/java/neqsim/thermo/system/SystemThermo.java
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,161 @@ public String[][] createTable(String name) {
return table;
}

/** {@inheritDoc} */
@Override
public void addTBPfraction2(String componentName, double numberOfMoles, double molarMass,
double boilingPoint) {
if (boilingPoint <= 0.0) {
throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this,
"addTBPfraction2", "boilingPoint", "must be positive."));
}
if (molarMass <= 0.0) {
throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this,
"addTBPfraction2", "molarMass", "must be positive."));
}

// Calculate density from boiling point and molar mass using inverse Søreide
// correlation
double density = calculateDensityFromBoilingPoint(molarMass, boilingPoint);

// Call the existing addTBPfraction method with the calculated density
addTBPfraction(componentName, numberOfMoles, molarMass, density);
}

/**
* Calculates density from boiling point and molar mass
*
* @param molarMass molar mass in kg/mol
* @param boilingPoint boiling point in Kelvin
* @return density in g/cm³
*/
public double calculateDensityFromBoilingPoint(double molarMass, double boilingPoint)
{
double TB = boilingPoint;

double lower = 0.5;
double upper = 1.5;
double tolerance = 1e-5;
int maxIterations = 1000;
double density = 0.8;
double calculated_density = 0.0;
double fmidOLD = 9999.0;
double f_mid;
double calculated_TB;
double lowerOLD = 0.1;
double upperOLD = 1.5;

for (int i = 0; i < maxIterations; i++) {

density = 0.5 * (lower + upper);
calculated_TB = characterization.getTBPModel().calcTB(molarMass * 1000, density);
f_mid = calculated_TB - TB;

if (Math.abs(f_mid) < tolerance) {
return calculated_density;
}

if (Math.abs(lower - upper) < tolerance) {
return calculated_density; // Return the midpoint as density
}

if (f_mid < 0) {
lowerOLD = lower;
lower = density;
} else {
upperOLD = upper;
upper = density;
}

if ((Math.abs(f_mid) < Math.abs(fmidOLD))) {
fmidOLD = f_mid;
calculated_density = density;
}
}
return calculated_density;
// Return the midpoint as density
}


/**
* Add TBP fraction using density and boiling point, calculating molar mass.
*/
@Override
public void addTBPfraction3(String componentName, double numberOfMoles, double density,
double boilingPoint) {
if (boilingPoint <= 0.0) {
throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this,
"addTBPfraction3", "boilingPoint", "must be positive."));
}
if (density <= 0.0) {
throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this,
"addTBPfraction3", "density", "must be positive."));
}
double molarMass = calculateMolarMassFromDensityAndBoilingPoint(density, boilingPoint);
addTBPfraction(componentName, numberOfMoles, molarMass, density);
}

/**
* Calculates molar mass from density and boiling point
*
* @param density density in g/cm³
* @param boilingPoint boiling point in Kelvin
* @return molar mass in kg/mol
*/
public double calculateMolarMassFromDensityAndBoilingPoint(double density, double boilingPoint) {

double TB = boilingPoint;


double lower = 0.01;
double upper = 0.5;
double tolerance = 1e-5;
int maxIterations = 1000;
double molarMass = 0.8;
double calculatedMolarMass = 0.0;
double fmidOLD = 9999.0;
double f_mid;
double calculated_TB;


for (int i = 0; i < maxIterations; i++) {

molarMass = 0.5 * (lower + upper);
calculated_TB = characterization.getTBPModel().calcTB(molarMass * 1000, density);
f_mid = calculated_TB - TB;

if (Math.abs(f_mid) < tolerance) {
return calculatedMolarMass;
}

if (Math.abs(lower - upper) < tolerance) {
return calculatedMolarMass; // Return the midpoint as density
}

if (f_mid < 0) {
lower = molarMass;
} else {
upper = molarMass;
}

if ((Math.abs(f_mid) < Math.abs(fmidOLD))) {
fmidOLD = f_mid;
calculatedMolarMass = molarMass;
}
}
return calculatedMolarMass;
}

/**
* Add TBP fraction using density and boiling point, calculating molar mass.
*/
@Override
public void addTBPfraction4(String componentName, double numberOfMoles, double molarMass, double density,
double boilingPoint) {
characterization.getTBPModel().setBoilingPoint(boilingPoint);
addTBPfraction(componentName, numberOfMoles, molarMass, density);
}

/** {@inheritDoc} */
@Override
public void deleteFluidPhase(int phaseNum) {
Expand Down
Loading