From 7f887a6f9cbac1b39e3d7e1aa168291f918dcf36 Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Mon, 9 Dec 2024 07:20:48 +0000 Subject: [PATCH 1/6] update --- .../flashops/Flash.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/neqsim/thermodynamicoperations/flashops/Flash.java b/src/main/java/neqsim/thermodynamicoperations/flashops/Flash.java index 623fd829a..c1296c08c 100644 --- a/src/main/java/neqsim/thermodynamicoperations/flashops/Flash.java +++ b/src/main/java/neqsim/thermodynamicoperations/flashops/Flash.java @@ -65,6 +65,7 @@ public int findLowestGibbsEnergyPhase() { if (!findLowestGibbsPhaseIsChecked) { minimumGibbsEnergySystem = system.clone(); minimumGibbsEnergySystem.init(0); + minimumGibbsEnergySystem.setTotalNumberOfMoles(1.0); minimumGibbsEnergySystem.init(1); if ((minimumGibbsEnergySystem.getPhase(0).getGibbsEnergy() * (1.0 - Math.signum(minimumGibbsEnergySystem.getPhase(0).getGibbsEnergy()) @@ -119,8 +120,10 @@ public void stabilityAnalysis() throws neqsim.util.exception.IsNaNException, sumw[1] = 0.0; sumw[0] = 0.0; for (int i = 0; i < clonedSystem.getPhase(0).getNumberOfComponents(); i++) { - sumw[1] += clonedSystem.getPhase(0).getComponent(i).getz() - / clonedSystem.getPhase(0).getComponent(i).getK(); + if (clonedSystem.getPhase(0).getComponent(i).getK() > 0) { + sumw[1] += clonedSystem.getPhase(0).getComponent(i).getz() + / clonedSystem.getPhase(0).getComponent(i).getK(); + } if (clonedSystem.getPhase(0).getComponent(i).getz() > 0) { sumw[0] += clonedSystem.getPhase(0).getComponent(i).getK() * clonedSystem.getPhase(0).getComponent(i).getz(); @@ -168,7 +171,17 @@ 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) { + if (j == 0) { + clonedSystem.init(1, 1); + } else { + clonedSystem.init(1, 0); + } + 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]) @@ -263,7 +276,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); } From a05651521be06095aea779597f72b8ee24ebe92b Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Mon, 9 Dec 2024 07:35:05 +0000 Subject: [PATCH 2/6] update --- .../flashops/Flash.java | 10 ++--- .../pipeline/AdiabaticTwoPhasePipeTest.java | 12 +++--- .../SalesGasAndStableOilTest.java | 37 +++++++++++++++++-- 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/main/java/neqsim/thermodynamicoperations/flashops/Flash.java b/src/main/java/neqsim/thermodynamicoperations/flashops/Flash.java index c1296c08c..25eb7c74a 100644 --- a/src/main/java/neqsim/thermodynamicoperations/flashops/Flash.java +++ b/src/main/java/neqsim/thermodynamicoperations/flashops/Flash.java @@ -65,7 +65,9 @@ public int findLowestGibbsEnergyPhase() { if (!findLowestGibbsPhaseIsChecked) { minimumGibbsEnergySystem = system.clone(); minimumGibbsEnergySystem.init(0); - minimumGibbsEnergySystem.setTotalNumberOfMoles(1.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()) @@ -120,10 +122,8 @@ public void stabilityAnalysis() throws neqsim.util.exception.IsNaNException, sumw[1] = 0.0; sumw[0] = 0.0; for (int i = 0; i < clonedSystem.getPhase(0).getNumberOfComponents(); i++) { - if (clonedSystem.getPhase(0).getComponent(i).getK() > 0) { - sumw[1] += clonedSystem.getPhase(0).getComponent(i).getz() - / clonedSystem.getPhase(0).getComponent(i).getK(); - } + sumw[1] += clonedSystem.getPhase(0).getComponent(i).getz() + / clonedSystem.getPhase(0).getComponent(i).getK(); if (clonedSystem.getPhase(0).getComponent(i).getz() > 0) { sumw[0] += clonedSystem.getPhase(0).getComponent(i).getK() * clonedSystem.getPhase(0).getComponent(i).getz(); diff --git a/src/test/java/neqsim/process/equipment/pipeline/AdiabaticTwoPhasePipeTest.java b/src/test/java/neqsim/process/equipment/pipeline/AdiabaticTwoPhasePipeTest.java index 02d4e1c90..d4823bb7f 100644 --- a/src/test/java/neqsim/process/equipment/pipeline/AdiabaticTwoPhasePipeTest.java +++ b/src/test/java/neqsim/process/equipment/pipeline/AdiabaticTwoPhasePipeTest.java @@ -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 { @@ -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); } } diff --git a/src/test/java/neqsim/process/processmodel/SalesGasAndStableOilTest.java b/src/test/java/neqsim/process/processmodel/SalesGasAndStableOilTest.java index dc263044b..f11c32c03 100644 --- a/src/test/java/neqsim/process/processmodel/SalesGasAndStableOilTest.java +++ b/src/test/java/neqsim/process/processmodel/SalesGasAndStableOilTest.java @@ -1,10 +1,10 @@ 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; @@ -12,6 +12,7 @@ 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; @@ -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()); @@ -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(); From 03b2e0ee47a872120add0d169821b890a63e66de Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Mon, 9 Dec 2024 08:08:54 +0000 Subject: [PATCH 3/6] update --- src/main/java/neqsim/thermo/phase/PhaseEos.java | 3 +-- .../java/neqsim/thermodynamicoperations/flashops/Flash.java | 5 ----- .../process/processmodel/SalesGasAndStableOilTest.java | 4 ++-- .../thermo/util/readwrite/EclipseFluidReadWriteTest.java | 2 +- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/main/java/neqsim/thermo/phase/PhaseEos.java b/src/main/java/neqsim/thermo/phase/PhaseEos.java index cef4c60f0..e6ca571ed 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseEos.java +++ b/src/main/java/neqsim/thermo/phase/PhaseEos.java @@ -353,8 +353,7 @@ public double molarVolume(double pressure, double temperature, double A, double } if (BonV < 0) { // BonV = Math.abs(BonV); - BonV = 1.0e-10; - BonVold = 10; + BonV = BonVold / 2.0; } error = Math.abs((BonV - BonVold) / BonVold); diff --git a/src/main/java/neqsim/thermodynamicoperations/flashops/Flash.java b/src/main/java/neqsim/thermodynamicoperations/flashops/Flash.java index 25eb7c74a..624743025 100644 --- a/src/main/java/neqsim/thermodynamicoperations/flashops/Flash.java +++ b/src/main/java/neqsim/thermodynamicoperations/flashops/Flash.java @@ -174,11 +174,6 @@ public void stabilityAnalysis() throws neqsim.util.exception.IsNaNException, try { clonedSystem.init(1, j); } catch (Exception e) { - if (j == 0) { - clonedSystem.init(1, 1); - } else { - clonedSystem.init(1, 0); - } logger.error(e.toString()); throw e; } diff --git a/src/test/java/neqsim/process/processmodel/SalesGasAndStableOilTest.java b/src/test/java/neqsim/process/processmodel/SalesGasAndStableOilTest.java index f11c32c03..a2a5d5655 100644 --- a/src/test/java/neqsim/process/processmodel/SalesGasAndStableOilTest.java +++ b/src/test/java/neqsim/process/processmodel/SalesGasAndStableOilTest.java @@ -283,13 +283,13 @@ public void testProcess2() { turboexpander.setIsentropicEfficiency(0.80); turboexpander.setOutletPressure(50.0); turboexpander.run(); - turboexpander.getFluid().prettyPrint(); + // turboexpander.getFluid().prettyPrint(); Separator DPCUScrubber = new neqsim.process.equipment.separator.Separator("TEX LT scrubber", turboexpander.getOutStream()); DPCUScrubber.run(); - DPCUScrubber.getFluid().prettyPrint(); + // DPCUScrubber.getFluid().prettyPrint(); // richGasMixer.getOutStream().getFluid().prettyPrint(); diff --git a/src/test/java/neqsim/thermo/util/readwrite/EclipseFluidReadWriteTest.java b/src/test/java/neqsim/thermo/util/readwrite/EclipseFluidReadWriteTest.java index df65226be..2db8b750a 100644 --- a/src/test/java/neqsim/thermo/util/readwrite/EclipseFluidReadWriteTest.java +++ b/src/test/java/neqsim/thermo/util/readwrite/EclipseFluidReadWriteTest.java @@ -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); From 2e10f252fff55e1491f877295dbadcfc9246f5bf Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Mon, 9 Dec 2024 08:56:55 +0000 Subject: [PATCH 4/6] update --- src/main/java/neqsim/thermo/phase/PhaseEos.java | 4 ++-- .../neqsim/thermodynamicoperations/flashops/TPFlashTest.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/neqsim/thermo/phase/PhaseEos.java b/src/main/java/neqsim/thermo/phase/PhaseEos.java index e6ca571ed..6c2f3f8ab 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseEos.java +++ b/src/main/java/neqsim/thermo/phase/PhaseEos.java @@ -352,8 +352,8 @@ public double molarVolume(double pressure, double temperature, double A, double BonVold = 100; } if (BonV < 0) { - // BonV = Math.abs(BonV); - BonV = BonVold / 2.0; + BonV = BonVold / 2; + BonVold = 10; } error = Math.abs((BonV - BonVold) / BonVold); diff --git a/src/test/java/neqsim/thermodynamicoperations/flashops/TPFlashTest.java b/src/test/java/neqsim/thermodynamicoperations/flashops/TPFlashTest.java index d83c32e98..8e2ad523e 100644 --- a/src/test/java/neqsim/thermodynamicoperations/flashops/TPFlashTest.java +++ b/src/test/java/neqsim/thermodynamicoperations/flashops/TPFlashTest.java @@ -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 From 7a6c1e318ed135127a77871fec728d13281be092 Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Mon, 9 Dec 2024 08:59:35 +0000 Subject: [PATCH 5/6] update --- .../neqsim/thermodynamicoperations/flashops/TPFlashTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/neqsim/thermodynamicoperations/flashops/TPFlashTest.java b/src/test/java/neqsim/thermodynamicoperations/flashops/TPFlashTest.java index 8e2ad523e..eab044375 100644 --- a/src/test/java/neqsim/thermodynamicoperations/flashops/TPFlashTest.java +++ b/src/test/java/neqsim/thermodynamicoperations/flashops/TPFlashTest.java @@ -96,7 +96,7 @@ void testRun5() { testOps = new ThermodynamicOperations(testSystem5); testOps.TPflash(); testSystem5.initProperties(); - testSystem5.prettyPrint(); + // testSystem5.prettyPrint(); double beta = testSystem5.getBeta(); assertEquals(0.999999372713993, beta, 1e-9); } From 7cb35f4fd8b94b831fe60d4b2c0aa47ea63a1c11 Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Mon, 9 Dec 2024 12:18:28 +0000 Subject: [PATCH 6/6] update --- .../oilquality/Standard_ASTM_D6377.java | 8 +++--- .../ThermodynamicOperations.java | 6 ++++- .../flashops/TPmultiflash.java | 2 ++ .../flashops/TVfractionFlash.java | 27 +++++++++++++++---- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/main/java/neqsim/standards/oilquality/Standard_ASTM_D6377.java b/src/main/java/neqsim/standards/oilquality/Standard_ASTM_D6377.java index 58e48696d..6baacf2b6 100644 --- a/src/main/java/neqsim/standards/oilquality/Standard_ASTM_D6377.java +++ b/src/main/java/neqsim/standards/oilquality/Standard_ASTM_D6377.java @@ -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(); @@ -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) { diff --git a/src/main/java/neqsim/thermodynamicoperations/ThermodynamicOperations.java b/src/main/java/neqsim/thermodynamicoperations/ThermodynamicOperations.java index 61ed084e1..b2fae0fb6 100644 --- a/src/main/java/neqsim/thermodynamicoperations/ThermodynamicOperations.java +++ b/src/main/java/neqsim/thermodynamicoperations/ThermodynamicOperations.java @@ -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; + } } /** diff --git a/src/main/java/neqsim/thermodynamicoperations/flashops/TPmultiflash.java b/src/main/java/neqsim/thermodynamicoperations/flashops/TPmultiflash.java index 4ed67c1c1..9962efaf0 100644 --- a/src/main/java/neqsim/thermodynamicoperations/flashops/TPmultiflash.java +++ b/src/main/java/neqsim/thermodynamicoperations/flashops/TPmultiflash.java @@ -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; diff --git a/src/main/java/neqsim/thermodynamicoperations/flashops/TVfractionFlash.java b/src/main/java/neqsim/thermodynamicoperations/flashops/TVfractionFlash.java index 8491b6ef0..cb8550780 100644 --- a/src/main/java/neqsim/thermodynamicoperations/flashops/TVfractionFlash.java +++ b/src/main/java/neqsim/thermodynamicoperations/flashops/TVfractionFlash.java @@ -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; /** @@ -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; @@ -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; @@ -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()); }