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

Updat-PVT #1002

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
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 @@ -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();

/**
Expand Down Expand Up @@ -129,6 +130,19 @@ public void setTemperature(double temperature) {
this.temperature = temperature;
}

/**
* <p>
* Setter for the field <code>temperature</code>.
* </p>
*
* @param temperature the temperature to set
* @param temperatureUnit the unit of temperature as string
*/
public void setTemperature(double temperature, String temperatureUnit) {
this.temperature = temperature;
this.temperatureUnit = temperatureUnit;
}

/**
* <p>
* Getter for the field <code>pressures</code>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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} */
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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();
Expand All @@ -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());
Expand All @@ -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");
}

/**
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand All @@ -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];
Expand All @@ -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]);
Expand All @@ -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();
Expand All @@ -125,49 +134,35 @@ 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();
totalGasStandardVolume += getGasStandardVolume()[i];
// 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);
Expand All @@ -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]);
*/
}
}

/**
* *
* <p>
* main.
* main
* </p>
*
* @param args an array of {@link java.lang.String} objects
Expand All @@ -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);
Expand All @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,14 @@ public interface SimulationInterface {
* object
*/
public LevenbergMarquardt getOptimizer();

/**
* <p>
* Setter for the field <code>temperature</code>.
* </p>
*
* @param temperature the temperature to set
* @param temperatureUnit the unit of temperature as string
*/
public void setTemperature(double temperature, String temperatureUnit);
}
Loading
Loading