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

improve flash #1205

Merged
merged 6 commits into from
Dec 9, 2024
Merged
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 @@ -99,11 +99,12 @@ public void calculate() {

this.thermoSystem.setPressure(TVP * 0.9);
try {
// ASTM D323 -08 method is used for this property calculation. It is defined at the pressure
// ASTM D323 -08 method is used for this property calculation. It is defined at
// the pressure
// at 100°F (37.8°C) at which 80% of the stream by volume is vapor at 100°F. In
this.thermoOps.TVfractionFlash(0.8);
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
logger.error("not able to find RVP...", ex);
}

VPCR4 = this.thermoSystem.getPressure();
Expand All @@ -116,7 +117,8 @@ public void calculate() {
fluid1.init(0);
}
try {
// ASTM D323 -08 method is used for this property calculation. It is defined at the pressure
// ASTM D323 -08 method is used for this property calculation. It is defined at
// the pressure
// at 100°F (37.8°C) at which 80% of the stream by volume is vapor at 100°F. In
this.thermoOps.TVfractionFlash(0.8);
} catch (Exception ex) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/neqsim/thermo/phase/PhaseEos.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ public double molarVolume(double pressure, double temperature, double A, double
BonVold = 100;
}
if (BonV < 0) {
// BonV = Math.abs(BonV);
BonV = 1.0e-10;
BonV = BonVold / 2;
BonVold = 10;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,11 @@ public void TVflash(double Vspec) {
*/
public void TVfractionFlash(double Vspec) {
operation = new neqsim.thermodynamicoperations.flashops.TVfractionFlash(system, Vspec);
getOperation().run();
try {
getOperation().run();
} catch (Exception e) {
throw e;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public int findLowestGibbsEnergyPhase() {
if (!findLowestGibbsPhaseIsChecked) {
minimumGibbsEnergySystem = system.clone();
minimumGibbsEnergySystem.init(0);
if (minimumGibbsEnergySystem.getTotalNumberOfMoles() < 1e-20) {
minimumGibbsEnergySystem.setTotalNumberOfMoles(1.0);
}
minimumGibbsEnergySystem.init(1);
if ((minimumGibbsEnergySystem.getPhase(0).getGibbsEnergy()
* (1.0 - Math.signum(minimumGibbsEnergySystem.getPhase(0).getGibbsEnergy())
Expand Down Expand Up @@ -168,7 +171,12 @@ 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) {
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])
Expand Down Expand Up @@ -263,7 +271,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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ public double solveBeta() {
try {
ans = dQdBM.solve(dQM).transpose();
} catch (Exception ex) {
logger.error(ex.getMessage());
break;
}
betaMatrix = betaMatrix.minus(ans.scale(iter / (iter + 3.0)));
removePhase = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

package neqsim.thermodynamicoperations.flashops;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import neqsim.thermo.system.SystemInterface;

/**
Expand All @@ -18,6 +20,7 @@
*/
public class TVfractionFlash extends Flash {
private static final long serialVersionUID = 1000;
static Logger logger = LogManager.getLogger(TVfractionFlash.class);

double Vfractionspec = 0;
Flash tpFlash;
Expand Down Expand Up @@ -86,12 +89,23 @@ public double solveQ() {
if (nyPres <= 0.0) {
nyPres = oldPres * 0.9;
}
if (Math.abs(nyPres - oldPres) >= 10.0) {
nyPres = oldPres + Math.signum(nyPres - oldPres) * 10.0;
}
system.setPressure(nyPres);
tpFlash.run();
if (system.getPressure() < 5000) {
tpFlash.run();
} else {
logger.error("too high pressure in TVfractionFLash.....stopping");
break;
}

error = Math.abs(dqdv / Vfractionspec);
// System.out.println("error " + error + "iteration " + iterations + " dQdv " + calcdQdV()
// + " new pressure " + nyPres + " error " + Math.abs((nyPres - oldPres) / (nyPres))
logger.debug("pressure " + nyPres + " iteration " + iterations);
// System.out.println("error " + error + "iteration " + iterations + " dQdv " +
// calcdQdV()
// + " new pressure " + nyPres + " error " + Math.abs((nyPres - oldPres) /
// (nyPres))
// + " numberofphases " + system.getNumberOfPhases());
} while ((error > 1e-6 && Math.abs(pressureStep) > 1e-6 && iterations < 200) || iterations < 6);
return nyPres;
Expand All @@ -109,8 +123,11 @@ public void run() {
}

// System.out.println("enthalpy: " + system.getEnthalpy());
solveQ();

try {
solveQ();
} catch (Exception e) {
throw e;
}
// System.out.println("volume: " + system.getVolume());
// System.out.println("Temperature: " + system.getTemperature());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import neqsim.process.equipment.pipeline.AdiabaticTwoPhasePipe;
import neqsim.process.equipment.stream.Stream;

public class AdiabaticTwoPhasePipeTest {
Expand Down Expand Up @@ -42,10 +41,11 @@ public void testMain() {
// System.out.println("out pressure " + pipe2.getOutletStream().getPressure("bara"));
// System.out.println("velocity " + pipe2.getSuperficialVelocity());

Assertions.assertEquals(75.0000001, pipe2.getOutletStream().getFluid().getFlowRate("MSm3/day"));
Assertions.assertEquals(153.58741116226855, pipe.getOutletStream().getPressure("bara"));
Assertions.assertEquals(4.207400548548574, pipe.getSuperficialVelocity());
Assertions.assertEquals(146.28492500260614, pipe2.getOutletStream().getPressure("bara"));
Assertions.assertEquals(60.751298047046646, pipe2.getSuperficialVelocity());
Assertions.assertEquals(75.0000001, pipe2.getOutletStream().getFluid().getFlowRate("MSm3/day"),
1e-5);
Assertions.assertEquals(153.58741116226855, pipe.getOutletStream().getPressure("bara"), 1e-6);
Assertions.assertEquals(4.207400548548574, pipe.getSuperficialVelocity(), 1e-6);
Assertions.assertEquals(146.28492500260614, pipe2.getOutletStream().getPressure("bara"), 0.001);
Assertions.assertEquals(60.751298047046646, pipe2.getSuperficialVelocity(), 0.01);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package neqsim.process.processmodel;

import static org.junit.jupiter.api.Assertions.assertAll;
import java.io.File;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import neqsim.process.equipment.compressor.Compressor;
import neqsim.process.equipment.expander.Expander;
import neqsim.process.equipment.heatexchanger.Cooler;
import neqsim.process.equipment.heatexchanger.Heater;
import neqsim.process.equipment.mixer.Mixer;
import neqsim.process.equipment.pump.Pump;
import neqsim.process.equipment.separator.Separator;
import neqsim.process.equipment.separator.ThreePhaseSeparator;
import neqsim.process.equipment.stream.Stream;
import neqsim.process.equipment.util.Recycle;
import neqsim.process.equipment.valve.ThrottlingValve;
import neqsim.thermo.system.SystemInterface;

Expand Down Expand Up @@ -235,10 +236,10 @@ public void testProcess2() {

Cooler dewPointControlCooler2 = new neqsim.process.equipment.heatexchanger.Cooler(
"dew point cooler 2", dewPointScrubber.getGasOutStream());
dewPointControlCooler2.setOutTemperature(-5.0, "C");
dewPointControlCooler2.setOutTemperature(-15.0, "C");
dewPointControlCooler2.setOutPressure(59.5, "bara");
dewPointControlCooler2.run();
Assertions.assertEquals(0.9808118997528,
Assertions.assertEquals(0.967383748675644,
dewPointControlCooler2.getOutStream().getFluid().getBeta(), 1e-6);
Separator dewPointScrubber2 = new neqsim.process.equipment.separator.Separator(
"dew point scrubber 2", dewPointControlCooler2.getOutStream());
Expand All @@ -259,6 +260,36 @@ public void testProcess2() {
lpLiqmixer.addStream(firstStageScrubber2.getLiquidOutStream());
lpLiqmixer.run();

Recycle hpResycle = new neqsim.process.equipment.util.Recycle("HP liq resycle");
hpResycle.addStream(hpLiqmixer.getOutStream());
hpResycle.setOutletStream(oilFirstStage);
hpResycle.setTolerance(1e-2);
hpResycle.run();

Recycle mpResycle = new neqsim.process.equipment.util.Recycle("MP liq resycle");
mpResycle.addStream(mpLiqmixer.getOutStream());
mpResycle.setOutletStream(oilSeccondStage);
mpResycle.setTolerance(1e-2);
mpResycle.run();

Recycle lpResycle = new neqsim.process.equipment.util.Recycle("LP liq resycle");
lpResycle.addStream(lpLiqmixer.getOutStream());
lpResycle.setOutletStream(oilThirdStage);
lpResycle.setTolerance(1e-2);
lpResycle.run();

Expander turboexpander =
new neqsim.process.equipment.expander.Expander("TEX", dewPointScrubber2.getGasOutStream());
turboexpander.setIsentropicEfficiency(0.80);
turboexpander.setOutletPressure(50.0);
turboexpander.run();
// turboexpander.getFluid().prettyPrint();

Separator DPCUScrubber = new neqsim.process.equipment.separator.Separator("TEX LT scrubber",
turboexpander.getOutStream());
DPCUScrubber.run();

// DPCUScrubber.getFluid().prettyPrint();
// richGasMixer.getOutStream().getFluid().prettyPrint();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void testReadFluidR() throws IOException {
testSystem.setPressure(530.97, "bara");
testSystem.setTemperature(105.0, "C");
testOps.TPflash();
testSystem.prettyPrint();
// testSystem.prettyPrint();
// Assertions.assertEquals(0.9270363530255, testSystem.getBeta(0), 1e-6);

testSystem = EclipseFluidReadWrite.read(filer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ void testRun5() {
testOps = new ThermodynamicOperations(testSystem5);
testOps.TPflash();
testSystem5.initProperties();
// testSystem5.prettyPrint();
double beta = testSystem5.getBeta();
assertEquals(6.272876522701802E-7, beta, 1e-5);
assertEquals(0.999999372713993, beta, 1e-9);
}

@Test
Expand Down
Loading