From 3ae379458ff9a4b9f0e9cf38d85098f21fc5b5c2 Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Thu, 21 Dec 2023 09:25:26 +0100 Subject: [PATCH] added test for umrpru (#886) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * added test for umrpru * updated * update * fix bug saturation temperature and add test * update name * Update src/main/java/neqsim/PVTsimulation/simulation/SaturationTemperature.java good suggestion Co-authored-by: Jørgen Engelsen * Update src/test/java/neqsim/PVTsimulation/simulation/SaturationTemperatureTest.java Co-authored-by: Jørgen Engelsen * Update src/main/java/neqsim/PVTsimulation/simulation/SaturationPressure.java Co-authored-by: Jørgen Engelsen * Update SaturationTemperature.java * Update SaturationPressure.java --------- Co-authored-by: Jørgen Engelsen --- .../simulation/SaturationPressure.java | 10 +- .../simulation/SaturationTemperature.java | 9 +- .../simulation/SaturationPressureTest.java | 42 +++--- .../simulation/SaturationTemperatureTest.java | 126 +++++++++++++----- .../system/SystemUMRPRUMCEosNewTest.java | 58 ++++++++ 5 files changed, 188 insertions(+), 57 deletions(-) diff --git a/src/main/java/neqsim/PVTsimulation/simulation/SaturationPressure.java b/src/main/java/neqsim/PVTsimulation/simulation/SaturationPressure.java index b20bb57dcc..b82cbcf3d3 100644 --- a/src/main/java/neqsim/PVTsimulation/simulation/SaturationPressure.java +++ b/src/main/java/neqsim/PVTsimulation/simulation/SaturationPressure.java @@ -31,7 +31,12 @@ public SaturationPressure(SystemInterface tempSystem) { * @return a double */ public double calcSaturationPressure() { - getThermoSystem().isImplementedCompositionDeriativesofFugacity(false); + boolean isMultiPhaseCheckChanged = false; + if (!getThermoSystem().doMultiPhaseCheck()) { + isMultiPhaseCheckChanged = true; + getThermoSystem().setMultiPhaseCheck(true); + } + // getThermoSystem().isImplementedCompositionDeriativesofFugacity(false); getThermoSystem().setPressure(1.0); do { getThermoSystem().setPressure(getThermoSystem().getPressure() + 10.0); @@ -62,6 +67,9 @@ public double calcSaturationPressure() { } while (Math.abs(maxPres - minPres) > 1e-5 && iteration < 500); getThermoSystem().setPressure(maxPres); thermoOps.TPflash(); + if (isMultiPhaseCheckChanged) { + getThermoSystem().setMultiPhaseCheck(false); + } return getThermoSystem().getPressure(); } diff --git a/src/main/java/neqsim/PVTsimulation/simulation/SaturationTemperature.java b/src/main/java/neqsim/PVTsimulation/simulation/SaturationTemperature.java index 85a9dd37ce..7cd1761062 100644 --- a/src/main/java/neqsim/PVTsimulation/simulation/SaturationTemperature.java +++ b/src/main/java/neqsim/PVTsimulation/simulation/SaturationTemperature.java @@ -31,7 +31,11 @@ public SaturationTemperature(SystemInterface tempSystem) { * @return a double */ public double calcSaturationTemperature() { - getThermoSystem().isImplementedCompositionDeriativesofFugacity(false); + boolean isMultiPhaseCheckChanged = false; + if (!getThermoSystem().doMultiPhaseCheck()) { + isMultiPhaseCheckChanged = true; + getThermoSystem().setMultiPhaseCheck(true); + } do { getThermoSystem().setTemperature(getThermoSystem().getTemperature() - 10.0); thermoOps.TPflash(); @@ -57,6 +61,9 @@ public double calcSaturationTemperature() { } while (Math.abs(maxTemp - minTemp) > 1e-5 && iteration < 500); getThermoSystem().setTemperature(maxTemp); thermoOps.TPflash(); + if (isMultiPhaseCheckChanged) { + getThermoSystem().setMultiPhaseCheck(false); + } return getThermoSystem().getTemperature(); } diff --git a/src/test/java/neqsim/PVTsimulation/simulation/SaturationPressureTest.java b/src/test/java/neqsim/PVTsimulation/simulation/SaturationPressureTest.java index f72e964ae9..abb20d024d 100644 --- a/src/test/java/neqsim/PVTsimulation/simulation/SaturationPressureTest.java +++ b/src/test/java/neqsim/PVTsimulation/simulation/SaturationPressureTest.java @@ -10,27 +10,27 @@ class SaturationPressureTest extends neqsim.NeqSimTest { @BeforeAll static void setUpBeforeClass() throws Exception {} - + @Test void testCalcSaturationPressure() { - SystemInterface tempSystem = new SystemSrkEos(273.15 + 20, 10.0); - tempSystem.addComponent("nitrogen", 0.34); - tempSystem.addComponent("CO2", 0.59); - tempSystem.addComponent("methane", 87.42); - tempSystem.addComponent("ethane", 3.02); - tempSystem.addComponent("propane", 4.31); - tempSystem.addComponent("i-butane", 0.93); - tempSystem.addComponent("n-butane", 1.71); - tempSystem.addComponent("i-pentane", 0.74); - tempSystem.addComponent("n-pentane", 0.85); - tempSystem.addComponent("n-hexane", 0.38); - tempSystem.addTBPfraction("C7", 0.05, 109.00 / 1000.0, 0.6912); - tempSystem.addTBPfraction("C8", 0.069, 120.20 / 1000.0, 0.7255); - tempSystem.addTBPfraction("C9", 0.014, 129.5 / 1000.0, 0.7454); - tempSystem.addTBPfraction("C10", 0.0078, 135.3 / 1000.0, 0.7864); - tempSystem.setMixingRule(2); - SimulationInterface satPresSim = new SaturationPressure(tempSystem); - satPresSim.run(); - assertEquals(satPresSim.getThermoSystem().getPressure(), 122.28338813781738, 0.1); - } + SystemInterface tempSystem = new SystemSrkEos(273.15 + 20, 10.0); + tempSystem.addComponent("nitrogen", 0.34); + tempSystem.addComponent("CO2", 0.59); + tempSystem.addComponent("methane", 87.42); + tempSystem.addComponent("ethane", 3.02); + tempSystem.addComponent("propane", 4.31); + tempSystem.addComponent("i-butane", 0.93); + tempSystem.addComponent("n-butane", 1.71); + tempSystem.addComponent("i-pentane", 0.74); + tempSystem.addComponent("n-pentane", 0.85); + tempSystem.addComponent("n-hexane", 0.38); + tempSystem.addTBPfraction("C7", 0.05, 109.00 / 1000.0, 0.6912); + tempSystem.addTBPfraction("C8", 0.069, 120.20 / 1000.0, 0.7255); + tempSystem.addTBPfraction("C9", 0.014, 129.5 / 1000.0, 0.7454); + tempSystem.addTBPfraction("C10", 0.0078, 135.3 / 1000.0, 0.7864); + tempSystem.setMixingRule(2); + SimulationInterface satPresSim = new SaturationPressure(tempSystem); + satPresSim.run(); + assertEquals(satPresSim.getThermoSystem().getPressure(), 126.1631355285644, 0.1); + } } diff --git a/src/test/java/neqsim/PVTsimulation/simulation/SaturationTemperatureTest.java b/src/test/java/neqsim/PVTsimulation/simulation/SaturationTemperatureTest.java index f80fce67b8..b43432f72d 100644 --- a/src/test/java/neqsim/PVTsimulation/simulation/SaturationTemperatureTest.java +++ b/src/test/java/neqsim/PVTsimulation/simulation/SaturationTemperatureTest.java @@ -1,51 +1,109 @@ package neqsim.PVTsimulation.simulation; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import neqsim.thermo.system.SystemInterface; import neqsim.thermo.system.SystemSrkEos; +import neqsim.thermo.system.SystemUMRPRUMCEos; +import neqsim.thermodynamicOperations.ThermodynamicOperations; /** * @author ESOL * */ class SaturationTemperatureTest extends neqsim.NeqSimTest { - /** - * @throws java.lang.Exception - */ - @BeforeAll - static void setUpBeforeClass() throws Exception {} + /** + * @throws java.lang.Exception + */ + @BeforeAll + static void setUpBeforeClass() throws Exception {} - /** - * Test method for - * {@link neqsim.PVTsimulation.simulation.SaturationTemperature#calcSaturationTemperature()}. - */ - @Test - void testCalcSaturationTemperature() { - SystemInterface tempSystem = new SystemSrkEos(273.15 + 220, 60.0); - tempSystem.addComponent("nitrogen", 0.34); - tempSystem.addComponent("CO2", 3.59); - tempSystem.addComponent("methane", 67.42); - tempSystem.addComponent("ethane", 9.02); - tempSystem.addComponent("propane", 4.31); - tempSystem.addComponent("i-butane", 0.93); - tempSystem.addComponent("n-butane", 1.71); - tempSystem.addComponent("i-pentane", 0.74); - tempSystem.addComponent("n-pentane", 0.85); - tempSystem.addComponent("n-hexane", 0.38); - tempSystem.addTBPfraction("C7", 0.5, 109.00 / 1000.0, 0.6912); - tempSystem.addTBPfraction("C8", 0.69, 120.20 / 1000.0, 0.7255); - tempSystem.addTBPfraction("C9", 0.14, 129.5 / 1000.0, 0.7454); - tempSystem.addTBPfraction("C10", 0.08, 135.3 / 1000.0, 0.7864); - // tempSystem.createDatabase(true); - tempSystem.setMixingRule(2); // "HV", "UNIFAC_UMRPRU"); - tempSystem.init(0); - tempSystem.init(1); - // tempSystem.saveFluid(928); + /** + * Test method for + * {@link neqsim.PVTsimulation.simulation.SaturationTemperature#calcSaturationTemperature()}. + */ + @Test + void testCalcSaturationTemperature() { + SystemInterface tempSystem = new SystemSrkEos(273.15 + 220, 60.0); + tempSystem.addComponent("nitrogen", 0.34); + tempSystem.addComponent("CO2", 3.59); + tempSystem.addComponent("methane", 67.42); + tempSystem.addComponent("ethane", 9.02); + tempSystem.addComponent("propane", 4.31); + tempSystem.addComponent("i-butane", 0.93); + tempSystem.addComponent("n-butane", 1.71); + tempSystem.addComponent("i-pentane", 0.74); + tempSystem.addComponent("n-pentane", 0.85); + tempSystem.addComponent("n-hexane", 0.38); + tempSystem.addTBPfraction("C7", 0.5, 109.00 / 1000.0, 0.6912); + tempSystem.addTBPfraction("C8", 0.69, 120.20 / 1000.0, 0.7255); + tempSystem.addTBPfraction("C9", 0.14, 129.5 / 1000.0, 0.7454); + tempSystem.addTBPfraction("C10", 0.08, 135.3 / 1000.0, 0.7864); + // tempSystem.createDatabase(true); + tempSystem.setMixingRule(2); // "HV", "UNIFAC_UMRPRU"); + tempSystem.init(0); + tempSystem.init(1); + // tempSystem.saveFluid(928); - SimulationInterface satPresSim = new SaturationTemperature(tempSystem); - satPresSim.run(); - assertEquals(tempSystem.getTemperature(), 380.3071922, 0.1); + SimulationInterface satPresSim = new SaturationTemperature(tempSystem); + satPresSim.run(); + assertEquals(tempSystem.getTemperature(), 380.3071922, 0.1); + } + + /** + *

+ * checkSaturationTemperatureToPhaseEnvelope. + *

+ * + * @throws Exception + */ + @Test + @DisplayName("calculate phase envelope using UMR") + public void checkSaturationTemperatureToPhaseEnvelope() throws Exception { + SystemUMRPRUMCEos testSystem = new neqsim.thermo.system.SystemUMRPRUMCEos(298.0, 10.0); + testSystem.addComponent("N2", 0.00675317857); + testSystem.addComponent("CO2", .02833662296); + testSystem.addComponent("methane", 0.8363194562); + testSystem.addComponent("ethane", 0.06934307324); + testSystem.addComponent("propane", 0.03645246567); + testSystem.addComponent("i-butane", 0.0052133558); + testSystem.addComponent("n-butane", 0.01013260919); + testSystem.addComponent("i-pentane", 0.00227310164); + testSystem.addComponent("n-pentane", 0.00224658464); + testSystem.addComponent("2-m-C5", 0.00049491); + testSystem.addComponent("3-m-C5", 0.00025783); + testSystem.addComponent("n-hexane", 0.00065099); + testSystem.addComponent("c-hexane", .00061676); + testSystem.addComponent("n-heptane", 0.00038552); + testSystem.addComponent("benzene", 0.00016852); + testSystem.addComponent("n-octane", 0.00007629); + testSystem.addComponent("c-C7", 0.0002401); + testSystem.addComponent("toluene", 0.0000993); + testSystem.addComponent("n-nonane", 0.00001943); + testSystem.addComponent("c-C8", 0.00001848); + testSystem.addComponent("m-Xylene", 0.00002216); + testSystem.addComponent("nC10", 0.00000905); + testSystem.addComponent("nC11", 0.000000001); + testSystem.addComponent("nC12", 0.000000001); + + testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); + testSystem.init(0); + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + try { + testOps.calcPTphaseEnvelope(); + } catch (Exception ex) { + assertTrue(false); + throw new Exception(ex); } + assertEquals((testOps.get("cricondentherm")[0] - 273.15), 23.469, 0.02); + assertEquals(testOps.get("cricondentherm")[1], 46.9326702068279, 0.02); + + testSystem.setPressure(testOps.get("cricondentherm")[1], "bara"); + SaturationTemperature satTempSim = new SaturationTemperature(testSystem); + satTempSim.run(); + assertEquals(satTempSim.getThermoSystem().getTemperature() - 273.15, 23.469396812206867, 0.001); + } } diff --git a/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java b/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java index 38393fb617..96925abf07 100644 --- a/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java +++ b/src/test/java/neqsim/thermo/system/SystemUMRPRUMCEosNewTest.java @@ -8,6 +8,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import neqsim.PVTsimulation.simulation.SaturationPressure; import neqsim.thermodynamicOperations.ThermodynamicOperations; class SystemUMRPRUMCEosNewTest extends neqsim.NeqSimTest { @@ -214,4 +215,61 @@ public void checkPhaseEnvelope() throws Exception { } assertEquals(testOps.get("cricondenbar")[1], 130.686140727503, 0.02); } + + /** + *

+ * checkPhaseEnvelope2. + *

+ * + * @throws Exception + */ + @Test + @DisplayName("calculate phase envelope using UMR") + public void checkPhaseEnvelope2() throws Exception { + testSystem = new neqsim.thermo.system.SystemUMRPRUMCEos(298.0, 10.0); + testSystem.addComponent("N2", 0.00675317857); + testSystem.addComponent("CO2", .02833662296); + testSystem.addComponent("methane", 0.8363194562); + testSystem.addComponent("ethane", 0.06934307324); + testSystem.addComponent("propane", 0.03645246567); + testSystem.addComponent("i-butane", 0.0052133558); + testSystem.addComponent("n-butane", 0.01013260919); + testSystem.addComponent("i-pentane", 0.00227310164); + testSystem.addComponent("n-pentane", 0.00224658464); + testSystem.addComponent("2-m-C5", 0.00049491); + testSystem.addComponent("3-m-C5", 0.00025783); + testSystem.addComponent("n-hexane", 0.00065099); + testSystem.addComponent("c-hexane", .00061676); + testSystem.addComponent("n-heptane", 0.00038552); + testSystem.addComponent("benzene", 0.00016852); + testSystem.addComponent("n-octane", 0.00007629); + testSystem.addComponent("c-C7", 0.0002401); + testSystem.addComponent("toluene", 0.0000993); + testSystem.addComponent("n-nonane", 0.00001943); + testSystem.addComponent("c-C8", 0.00001848); + testSystem.addComponent("m-Xylene", 0.00002216); + testSystem.addComponent("nC10", 0.00000905); + testSystem.addComponent("nC11", 0.000000001); + testSystem.addComponent("nC12", 0.000000001); + + testSystem.setMixingRule("HV", "UNIFAC_UMRPRU"); + testSystem.init(0); + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + try { + testOps.calcPTphaseEnvelope(); + logger.info("Cricondenbar " + (testOps.get("cricondenbar")[0] - 273.15) + " " + + testOps.get("cricondenbar")[1]); + } catch (Exception ex) { + assertTrue(false); + throw new Exception(ex); + } + assertEquals((testOps.get("cricondenbar")[0] - 273.15), -11.09948347, 0.02); + assertEquals(testOps.get("cricondenbar")[1], 104.75329137038476, 0.02); + + testSystem.setTemperature(-11.09948347, "C"); + SaturationPressure satPresSim = new SaturationPressure(testSystem); + satPresSim.run(); + assertEquals(satPresSim.getThermoSystem().getPressure(), 104.7532, 0.001); + + } }