diff --git a/src/main/java/neqsim/PVTsimulation/simulation/BasePVTsimulation.java b/src/main/java/neqsim/PVTsimulation/simulation/BasePVTsimulation.java index 1f36923035..b5b6da66ce 100644 --- a/src/main/java/neqsim/PVTsimulation/simulation/BasePVTsimulation.java +++ b/src/main/java/neqsim/PVTsimulation/simulation/BasePVTsimulation.java @@ -18,12 +18,13 @@ public class BasePVTsimulation implements SimulationInterface { public ThermodynamicOperations thermoOps = null; private double pressure; public double[] pressures = {381.5, 338.9, 290.6, 242.3, 194.1, 145.8, 145.8, 97.5, 49.3}; - public double temperature = 289.0; + public double temperature = Double.NaN; double[][] experimentalData = null; double saturationVolume = 0; double saturationPressure = 0; double saturationTemperature; double Zsaturation = 0; + String temperatureUnit = "K"; public LevenbergMarquardt optimizer = new LevenbergMarquardt(); /** @@ -129,6 +130,19 @@ public void setTemperature(double temperature) { this.temperature = temperature; } + /** + *
+ * Setter for the field temperature
.
+ *
* Getter for the field pressures
.
diff --git a/src/main/java/neqsim/PVTsimulation/simulation/ConstantMassExpansion.java b/src/main/java/neqsim/PVTsimulation/simulation/ConstantMassExpansion.java
index d88e76a658..3a773d58d2 100644
--- a/src/main/java/neqsim/PVTsimulation/simulation/ConstantMassExpansion.java
+++ b/src/main/java/neqsim/PVTsimulation/simulation/ConstantMassExpansion.java
@@ -87,6 +87,13 @@ public void calcSaturationConditions() {
saturationPressure = getThermoSystem().getPressure();
Zsaturation = getThermoSystem().getZ();
saturationConditionFound = true;
+
+ getThermoSystem().initPhysicalProperties();
+ saturationVolume = getThermoSystem().getPhase(0).getMass()
+ / getThermoSystem().getPhase(0).getPhysicalProperties().getDensity();
+ saturationPressure = getThermoSystem().getPressure();
+ Zsaturation = getThermoSystem().getZ();
+ saturationConditionFound = true;
}
/** {@inheritDoc} */
@@ -116,7 +123,9 @@ public void runCalc() {
viscosity = new double[pressures.length];
viscosityOil = new double[pressures.length];
gasExpensionFactor = new double[pressures.length];
- getThermoSystem().setTemperature(temperature);
+ if (!Double.isNaN(temperature)) {
+ getThermoSystem().setTemperature(temperature, temperatureUnit);
+ }
if (!saturationConditionFound) {
calcSaturationConditions();
try {
@@ -152,10 +161,10 @@ public void runCalc() {
density[i] = getThermoSystem().getPhase(0).getDensity("kg/m3");
gasVolume[i] = getThermoSystem().getPhase(0).getNumberOfMolesInPhase()
* getThermoSystem().getPhase(0).getMolarMass() / density[i]; // getThermoSystem().getPhase(0).getVolume();
- gasStandardVolume[i] = getThermoSystem().getPhase(0).getVolume()
- * getThermoSystem().getPhase(0).getPressure()
- / ThermodynamicConstantsInterface.referencePressure
- / getThermoSystem().getPhase(0).getZ() * 288.15 / getThermoSystem().getTemperature();
+ gasStandardVolume[i] =
+ getThermoSystem().getPhase(0).getVolume() * getThermoSystem().getPhase(0).getPressure()
+ / ThermodynamicConstantsInterface.referencePressure
+ / getThermoSystem().getPhase(0).getZ() * 288.15 / getThermoSystem().getTemperature();
Bg[i] = gasVolume[i] * 1e5 / gasStandardVolume[i];
Zgas[i] = getThermoSystem().getPhase(0).getZ();
if (getThermoSystem().getNumberOfPhases() == 1) {
diff --git a/src/main/java/neqsim/PVTsimulation/simulation/ConstantVolumeDepletion.java b/src/main/java/neqsim/PVTsimulation/simulation/ConstantVolumeDepletion.java
index f33511e385..4810d5c25d 100644
--- a/src/main/java/neqsim/PVTsimulation/simulation/ConstantVolumeDepletion.java
+++ b/src/main/java/neqsim/PVTsimulation/simulation/ConstantVolumeDepletion.java
@@ -110,7 +110,9 @@ public void runCalc() {
liquidRelativeVolume = new double[pressures.length];
cummulativeMolePercDepleted = new double[pressures.length];
double totalNumberOfMoles = getThermoSystem().getTotalNumberOfMoles();
- getThermoSystem().setTemperature(temperature);
+ if (!Double.isNaN(temperature)) {
+ getThermoSystem().setTemperature(temperature, temperatureUnit);
+ }
for (int i = 0; i < pressures.length; i++) {
getThermoSystem().setPressure(pressures[i]);
@@ -119,11 +121,9 @@ public void runCalc() {
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
- // getThermoSystem().display();
+ getThermoSystem().initPhysicalProperties();
+
totalVolume[i] = getThermoSystem().getVolume();
- System.out.println("volume " + totalVolume[i]);
- cummulativeMolePercDepleted[i] =
- 100.0 - getThermoSystem().getTotalNumberOfMoles() / totalNumberOfMoles * 100;
if (getThermoSystem().getNumberOfPhases() > 1) {
if (!saturationConditionFound) {
calcSaturationConditions();
@@ -134,27 +134,23 @@ public void runCalc() {
logger.error(ex.getMessage(), ex);
}
}
+ cummulativeMolePercDepleted[i] =
+ 100 - getThermoSystem().getTotalNumberOfMoles() / totalNumberOfMoles * 100;
// if (totalVolume[i] > saturationVolume) {
liquidVolume[i] = getThermoSystem().getPhase(1).getVolume();
liquidVolumeRelativeToVsat[i] = liquidVolume[i] / saturationVolume;
Zgas[i] = getThermoSystem().getPhase(0).getZ();
Zmix[i] = getThermoSystem().getZ();
- if (getThermoSystem().getNumberOfPhases() > 1) {
- liquidRelativeVolume[i] =
- getThermoSystem().getPhase("oil").getVolume() / saturationVolume * 100;
- }
+ liquidRelativeVolume[i] = liquidVolume[i] / saturationVolume * 100;
- double volumeCorrection = getThermoSystem().getVolume() - saturationVolume;
- double test = volumeCorrection / getThermoSystem().getPhase(0).getMolarVolume();
+ double volumeCorrection = totalVolume[i] - saturationVolume;
+ double test = volumeCorrection / getThermoSystem().getPhase(0).getVolume();
for (int j = 0; j < getThermoSystem().getPhase(0).getNumberOfComponents(); j++) {
try {
double change =
- (test * getThermoSystem().getPhase(0).getComponent(j).getx() < getThermoSystem()
- .getPhase(0).getComponent(j).getNumberOfMolesInPhase())
- ? test * getThermoSystem().getPhase(0).getComponent(j).getx()
- : test * getThermoSystem().getPhase(0).getComponent(j).getx();
+ test * getThermoSystem().getPhase(0).getComponent(j).getNumberOfMolesInPhase();
getThermoSystem().addComponent(j, -change);
} catch (Exception e) {
logger.debug(e.getMessage());
@@ -165,9 +161,13 @@ public void runCalc() {
for (int i = 0; i < pressures.length; i++) {
relativeVolume[i] = totalVolume[i] / saturationVolume;
- System.out.println("rel volume " + relativeVolume[i]);
+ liquidVolumeRelativeToVsat[i] = liquidVolume[i] / saturationVolume;
+ // System.out.println("rel volume " + relativeVolume[i]);
}
- System.out.println("test finished");
+ for (int i = 0; i < pressures.length; i++) {
+ // System.out.println("liq rel volume " + liquidRelativeVolume[i]);
+ }
+ // System.out.println("test finished");
}
/**
@@ -188,7 +188,9 @@ public void runTuning() {
SystemInterface tempSystem = getThermoSystem(); // getThermoSystem().clone();
- tempSystem.setTemperature(temperature);
+ if (!Double.isNaN(temperature)) {
+ getThermoSystem().setTemperature(temperature, temperatureUnit);
+ }
tempSystem.setPressure(pressures[i]);
// thermoOps.TPflash();
// tempSystem.display();
diff --git a/src/main/java/neqsim/PVTsimulation/simulation/DifferentialLiberation.java b/src/main/java/neqsim/PVTsimulation/simulation/DifferentialLiberation.java
index 248516c045..ce6f986c68 100644
--- a/src/main/java/neqsim/PVTsimulation/simulation/DifferentialLiberation.java
+++ b/src/main/java/neqsim/PVTsimulation/simulation/DifferentialLiberation.java
@@ -3,6 +3,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import neqsim.thermo.ThermodynamicConstantsInterface;
+import neqsim.thermo.phase.PhaseType;
import neqsim.thermo.system.SystemInterface;
import neqsim.thermo.system.SystemSrkEos;
@@ -77,7 +78,9 @@ public void calcSaturationConditions() {
* try { thermoOps.dewPointPressureFlash(); } catch (Exception ex) {
* logger.error(ex.getMessage(), ex); }
*/
- saturationVolume = getThermoSystem().getVolume();
+ getThermoSystem().initPhysicalProperties();
+ saturationVolume = getThermoSystem().getPhase(0).getMass()
+ / getThermoSystem().getPhase(0).getPhysicalProperties().getDensity();
saturationPressure = getThermoSystem().getPressure();
saturationConditionFound = true;
}
@@ -90,6 +93,7 @@ public void calcSaturationConditions() {
public void runCalc() {
saturationConditionFound = false;
relativeVolume = new double[pressures.length];
+ double[] mass = new double[pressures.length];
totalVolume = new double[pressures.length];
liquidVolumeRelativeToVsat = new double[pressures.length];
liquidVolume = new double[pressures.length];
@@ -103,7 +107,9 @@ public void runCalc() {
oilDensity = new double[pressures.length];
double totalGasStandardVolume = 0;
- getThermoSystem().setTemperature(temperature);
+ if (!Double.isNaN(temperature)) {
+ getThermoSystem().setTemperature(temperature, temperatureUnit);
+ }
for (int i = 0; i < pressures.length; i++) {
getThermoSystem().setPressure(pressures[i]);
@@ -112,9 +118,12 @@ public void runCalc() {
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
- totalVolume[i] = getThermoSystem().getVolume();
- liquidVolume[i] = getThermoSystem().getVolume();
+ getThermoSystem().initPhysicalProperties();
+ oilDensity[i] = getThermoSystem().getDensity("kg/m3");
+ mass[i] = getThermoSystem().getMass("kg");
+ totalVolume[i] = mass[i] / oilDensity[i];
+ liquidVolume[i] = totalVolume[i];
if (getThermoSystem().getNumberOfPhases() > 1) {
if (!saturationConditionFound) {
calcSaturationConditions();
@@ -125,7 +134,8 @@ public void runCalc() {
logger.error(ex.getMessage(), ex);
}
}
- gasStandardVolume[i] = getThermoSystem().getPhase(0).getVolume()
+ gasStandardVolume[i] = getThermoSystem().getPhase(PhaseType.GAS).getMass()
+ / getThermoSystem().getPhase(PhaseType.GAS).getPhysicalProperties().getDensity()
* getThermoSystem().getPhase(0).getPressure()
/ ThermodynamicConstantsInterface.referencePressure
/ getThermoSystem().getPhase(0).getZ() * 288.15 / getThermoSystem().getTemperature();
@@ -133,41 +143,26 @@ public void runCalc() {
// if (totalVolume[i] > saturationVolume) {
Zgas[i] = getThermoSystem().getPhase(0).getZ();
relGasGravity[i] = getThermoSystem().getPhase(0).getMolarMass() / 0.028;
- getThermoSystem().initPhysicalProperties();
- if (getThermoSystem().hasPhaseType("gas") && getThermoSystem().hasPhaseType("oil")) {
- liquidVolume[i] = getThermoSystem().getPhase(1).getVolume();
+ if (getThermoSystem().hasPhaseType(PhaseType.GAS)
+ && getThermoSystem().hasPhaseType(PhaseType.OIL)) {
oilDensity[i] = getThermoSystem().getPhase(1).getPhysicalProperties().getDensity();
+ liquidVolume[i] = getThermoSystem().getPhase(1).getMass() / oilDensity[i];
+ getThermoSystem().getPhase(1).getMass();
} else if (getThermoSystem().hasPhaseType("oil")) {
- liquidVolume[i] = getThermoSystem().getPhase(0).getVolume();
oilDensity[i] = getThermoSystem().getPhase(0).getPhysicalProperties().getDensity();
+ liquidVolume[i] = getThermoSystem().getPhase(0).getMass() / oilDensity[i];
} else {
- liquidVolume[i] = getThermoSystem().getPhase(0).getVolume();
oilDensity[i] = getThermoSystem().getPhase(0).getPhysicalProperties().getDensity();
+ liquidVolume[i] = getThermoSystem().getPhase(0).getMass() / oilDensity[i];
}
if (getThermoSystem().getNumberOfPhases() > 1) {
- gasVolume[i] = getThermoSystem().getPhase(0).getVolume();
- } else {
- gasVolume[i] = 0.0;
+ gasVolume[i] = getThermoSystem().getPhase(PhaseType.GAS).getMass()
+ / getThermoSystem().getPhase(PhaseType.GAS).getPhysicalProperties().getDensity();
}
liquidVolumeRelativeToVsat[i] = liquidVolume[i] / saturationVolume;
- double volumeCorrection =
- getThermoSystem().getVolume() - getThermoSystem().getPhase(1).getVolume();
- double test = volumeCorrection / getThermoSystem().getPhase(0).getMolarVolume();
-
- for (int j = 0; j < getThermoSystem().getPhase(0).getNumberOfComponents(); j++) {
- try {
- double change =
- (test * getThermoSystem().getPhase(0).getComponent(j).getx() < getThermoSystem()
- .getPhase(0).getComponent(j).getNumberOfMolesInPhase())
- ? test * getThermoSystem().getPhase(0).getComponent(j).getx()
- : test * getThermoSystem().getPhase(0).getComponent(j).getx();
- getThermoSystem().addComponent(j, -change);
- } catch (Exception e) {
- logger.debug(e.getMessage());
- }
- }
+ getThermoSystem().removePhase(0);
}
}
getThermoSystem().setPressure(ThermodynamicConstantsInterface.referencePressure);
@@ -177,29 +172,35 @@ public void runCalc() {
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
- VoilStd = getThermoSystem().getPhase(1).getVolume();
- totalGasStandardVolume += getThermoSystem().getPhase(0).getVolume();
- // getThermoSystem().display();
+ getThermoSystem().initPhysicalProperties();
+ VoilStd = getThermoSystem().getPhase(PhaseType.OIL).getMass()
+ / getThermoSystem().getPhase(PhaseType.OIL).getPhysicalProperties().getDensity();
+ if (getThermoSystem().hasPhaseType(PhaseType.GAS)) {
+ totalGasStandardVolume += getThermoSystem().getPhase(PhaseType.GAS).getCorrectedVolume();
+ }
+
double total = 0;
for (int i = 0; i < pressures.length; i++) {
relativeVolume[i] = totalVolume[i] / saturationVolume;
Bo[i] = liquidVolume[i] / VoilStd;
total += getGasStandardVolume()[i];
+ Rs[i] = (totalGasStandardVolume - total) / VoilStd;
if (Zgas[i] > 1e-10) {
Bg[i] = gasVolume[i] / getGasStandardVolume()[i];
- Rs[i] = (totalGasStandardVolume - total) / VoilStd;
}
/*
- * System.out.println("Bo " + getBo()[i] + " Bg " + getBg()[i] + " Rs " + getRs()[i] +
- * " oil density " + getOilDensity()[i] + " gas gracvity " + getRelGasGravity()[i] + " Zgas "
- * + getZgas()[i] + " gasstdvol " + getGasStandardVolume()[i]);
+ * System.out.println("pressure " + pressures[i] + " Bo " + getBo()[i] + " Bg " + getBg()[i] +
+ * " Rs " + getRs()[i] + " oil density " + getOilDensity()[i] + " gas gracvity " +
+ * getRelGasGravity()[i] + " Zgas " + getZgas()[i] + " gasstdvol " +
+ * getGasStandardVolume()[i]);
*/
}
}
/**
+ * *
*
- * main. + * main *
* * @param args an array of {@link java.lang.String} objects @@ -208,11 +209,11 @@ public static void main(String[] args) { SystemInterface tempSystem = new SystemSrkEos(273.15 + 83.5, 450.0); tempSystem.addComponent("nitrogen", 0.586); tempSystem.addComponent("CO2", 0.087); - tempSystem.addComponent("methane", 17.0209); - tempSystem.addComponent("ethane", 5.176); + tempSystem.addComponent("methane", 107.0209); + tempSystem.addComponent("ethane", 15.176); tempSystem.addComponent("propane", 6.652); - tempSystem.addComponent("i-butane", 1.533); - tempSystem.addComponent("n-butane", 3.544); + tempSystem.addComponent("i-butane", 3.533); + tempSystem.addComponent("n-butane", 5.544); tempSystem.addComponent("i-pentane", 1.585); tempSystem.addComponent("n-pentane", 2.036); tempSystem.addTBPfraction("C6", 2.879, 84.9 / 1000.0, 0.6668); @@ -221,13 +222,12 @@ public static void main(String[] args) { tempSystem.addTBPfraction("C9", 3.488, 119.8 / 1000.0, 0.7743); tempSystem.addPlusFraction("C10", 45.944, 320.0 / 1000.0, 0.924); tempSystem.getCharacterization().characterisePlusFraction(); - tempSystem.getCharacterization().characterisePlusFraction(); - - tempSystem.createDatabase(true); - tempSystem.setMixingRule(2); - DifferentialLiberation CVDsim = new DifferentialLiberation(tempSystem); - CVDsim.runCalc(); + DifferentialLiberation differentialLiberation = new DifferentialLiberation(tempSystem); + differentialLiberation.setPressures( + new double[] {350.0, 250.0, 200.0, 150.0, 100.0, 70.0, 50.0, 40.0, 30.0, 20.0, 1.0}); + differentialLiberation.setTemperature(83.5, "C"); + differentialLiberation.runCalc(); } /** diff --git a/src/main/java/neqsim/PVTsimulation/simulation/SaturationPressure.java b/src/main/java/neqsim/PVTsimulation/simulation/SaturationPressure.java index 2b22f83c9f..957e3f4435 100644 --- a/src/main/java/neqsim/PVTsimulation/simulation/SaturationPressure.java +++ b/src/main/java/neqsim/PVTsimulation/simulation/SaturationPressure.java @@ -31,6 +31,11 @@ public SaturationPressure(SystemInterface tempSystem) { * @return a double */ public double calcSaturationPressure() { + + if (!Double.isNaN(temperature)) { + getThermoSystem().setTemperature(temperature, temperatureUnit); + } + boolean isMultiPhaseCheckChanged = false; if (!getThermoSystem().doMultiPhaseCheck()) { isMultiPhaseCheckChanged = true; diff --git a/src/main/java/neqsim/PVTsimulation/simulation/SimulationInterface.java b/src/main/java/neqsim/PVTsimulation/simulation/SimulationInterface.java index 4e5def965a..fab1696d8f 100644 --- a/src/main/java/neqsim/PVTsimulation/simulation/SimulationInterface.java +++ b/src/main/java/neqsim/PVTsimulation/simulation/SimulationInterface.java @@ -56,4 +56,14 @@ public interface SimulationInterface { * object */ public LevenbergMarquardt getOptimizer(); + + /** + *
+ * Setter for the field temperature
.
+ *