From a81212f42f36853aa9cd2d060122f4b685ede8c8 Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Sun, 3 Dec 2023 20:24:49 +0000 Subject: [PATCH] added test and fix --- .../processEquipment/separator/Separator.java | 22 +++- .../valve/ThrottlingValve.java | 8 +- .../flashOps/PHflashSingleComp.java | 6 +- .../ProcessSystemRunTransientTest.java | 105 ++++++++++++++++-- .../flashOps/VUFlashTest.java | 49 ++++++++ 5 files changed, 172 insertions(+), 18 deletions(-) create mode 100644 src/test/java/neqsim/thermodynamicOperations/flashOps/VUFlashTest.java diff --git a/src/main/java/neqsim/processSimulation/processEquipment/separator/Separator.java b/src/main/java/neqsim/processSimulation/processEquipment/separator/Separator.java index 30b89921b6..2e6e279ffb 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/separator/Separator.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/separator/Separator.java @@ -244,7 +244,11 @@ public void run(UUID id) { if (thermoSystem2.hasPhaseType("aqueous") || thermoSystem2.hasPhaseType("oil")) { liquidOutStream.run(id); } else { - liquidOutStream.getFluid().init(3); + try { + liquidOutStream.getFluid().init(3); + } catch (Exception e) { + logger.error(e.getMessage()); + } } if (getCalculateSteadyState()) { thermoSystem = thermoSystem2; @@ -274,7 +278,6 @@ public void run(UUID id) { ops.TPflash(); thermoSystem.init(3); thermoSystem.initPhysicalProperties("density"); - // thermoSystem.prettyPrint(); if (thermoSystem.hasPhaseType("oil") || thermoSystem.hasPhaseType("aqueous")) { liquidLevel = thermoSystem.getPhase(1).getVolume("m3") / (liquidVolume + gasVolume); liquidVolume = getLiquidLevel() * 3.14 / 4.0 * getInternalDiameter() @@ -324,17 +327,24 @@ public void runTransient(double dt, UUID id) { } catch (Exception e) { logger.error(e.getMessage()); } + double deliq = 0.0; + if (thermoSystem.hasPhaseType("oil") || thermoSystem.hasPhaseType("aqueous")) { + deliq = -liquidOutStream.getThermoSystem().getEnthalpy(); + } double deltaEnergy = inletStreamMixer.getOutletStream().getThermoSystem().getEnthalpy() - - gasOutStream.getThermoSystem().getEnthalpy() - - liquidOutStream.getThermoSystem().getEnthalpy(); + - gasOutStream.getThermoSystem().getEnthalpy() + deliq; double newEnergy = thermoSystem.getInternalEnergy() + dt * deltaEnergy; thermoSystem.init(0); for (int i = 0; i < thermoSystem.getPhase(0).getNumberOfComponents(); i++) { double dncomp = 0.0; dncomp += inletStreamMixer.getOutletStream().getThermoSystem().getComponent(i).getNumberOfmoles(); - dncomp += -gasOutStream.getThermoSystem().getComponent(i).getNumberOfmoles() - - liquidOutStream.getThermoSystem().getComponent(i).getNumberOfmoles(); + double dniliq = 0.0; + if (thermoSystem.hasPhaseType("oil") || thermoSystem.hasPhaseType("aqueous")) { + dniliq = -liquidOutStream.getThermoSystem().getComponent(i).getNumberOfmoles(); + } + dncomp += -gasOutStream.getThermoSystem().getComponent(i).getNumberOfmoles() + dniliq; + thermoSystem.addComponent(i, dncomp * dt); } ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem); diff --git a/src/main/java/neqsim/processSimulation/processEquipment/valve/ThrottlingValve.java b/src/main/java/neqsim/processSimulation/processEquipment/valve/ThrottlingValve.java index 2e2374edee..eb8e51b4d0 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/valve/ThrottlingValve.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/valve/ThrottlingValve.java @@ -231,8 +231,12 @@ public void run(UUID id) { molarFlow = inStream.getThermoSystem().getTotalNumberOfMoles(); } - inStream.getThermoSystem().setTotalNumberOfMoles(molarFlow); - inStream.getThermoSystem().init(3); + try { + inStream.getThermoSystem().setTotalNumberOfMoles(molarFlow); + inStream.getThermoSystem().init(3); + } catch (Exception e) { + logger.error(e.getMessage()); + } // inletStream.run(id); outStream.setThermoSystem(thermoSystem.clone()); diff --git a/src/main/java/neqsim/thermodynamicOperations/flashOps/PHflashSingleComp.java b/src/main/java/neqsim/thermodynamicOperations/flashOps/PHflashSingleComp.java index b30115a77b..14ca103ef4 100644 --- a/src/main/java/neqsim/thermodynamicOperations/flashOps/PHflashSingleComp.java +++ b/src/main/java/neqsim/thermodynamicOperations/flashOps/PHflashSingleComp.java @@ -41,7 +41,11 @@ public void run() { try { bubOps.TPflash(); if (system.getPhase(0).getType() == PhaseType.GAS) { - bubOps.dewPointTemperatureFlash(); + try { + bubOps.dewPointTemperatureFlash(); + } catch (Exception e) { + system.setTemperature(298.0); + } } else { bubOps.bubblePointTemperatureFlash(); } diff --git a/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java index 5907521ff2..737641bf1b 100644 --- a/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java +++ b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java @@ -98,9 +98,9 @@ public void testDynamicCalculation() { // transient behaviour p.setTimeStep(1.0); for (int i = 0; i < 50; i++) { - // System.out.println("volume flow " + flowTransmitter.getMeasuredValue() + " valve opening " - // + valve1.getPercentValveOpening() + " pressure " - // + separator1.getGasOutStream().getPressure()); + // System.out.println("volume flow " + flowTransmitter.getMeasuredValue() + " valve opening " + // + valve1.getPercentValveOpening() + " pressure " + // + separator1.getGasOutStream().getPressure()); p.runTransient(); for (SimulationInterface sim : p.getUnitOperations()) { assertEquals(sim.getCalculationIdentifier(), p.getCalculationIdentifier()); @@ -113,13 +113,13 @@ public void testDynamicCalculation2() { neqsim.thermo.system.SystemInterface testSystem2 = new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00); testSystem2.addComponent("methane", 1.1); - testSystem2.addComponent("n-heptane", 1.001); + testSystem2.addComponent("water", 1.001); testSystem2.setMixingRule(2); neqsim.thermo.system.SystemInterface testSystem3 = new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00); testSystem3.addComponent("methane", 1.1); - testSystem3.addComponent("n-heptane", 0.001); + testSystem3.addComponent("water", 0.001); testSystem3.setMixingRule(2); Stream stream1 = new Stream("Stream1", testSystem2); @@ -206,10 +206,97 @@ public void testDynamicCalculation2() { // p.displayResult(); p.setTimeStep(2.0); for (int i = 0; i < 500; i++) { - // System.out.println("pressure " + separator1.getGasOutStream().getPressure() + " flow " - // + separator1.getGasOutStream().getFlowRate("kg/hr") + " sepr height " - // + separatorLevelTransmitter.getMeasuredValue() + "valve2 opening " - // + valve2.getPercentValveOpening() + "valve3 opening " + valve3.getPercentValveOpening()); + System.out.println("pressure " + separator1.getGasOutStream().getPressure() + " flow " + + separator1.getGasOutStream().getFlowRate("kg/hr") + " sepr height " + + separatorLevelTransmitter.getMeasuredValue() + "valve2 opening " + + valve2.getPercentValveOpening() + "valve3 opening " + valve3.getPercentValveOpening()); + p.runTransient(); + for (SimulationInterface sim : p.getUnitOperations()) { + assertEquals(p.getCalculationIdentifier(), sim.getCalculationIdentifier()); + } + } + } + + @Test + public void testDynamicCalculation3() { + neqsim.thermo.system.SystemInterface testSystem2 = + new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00); + testSystem2.addComponent("methane", 1.1); + testSystem2.addComponent("ethane", 0.1); + testSystem2.setMixingRule(2); + + neqsim.thermo.system.SystemInterface testSystem3 = + new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00); + testSystem3.addComponent("methane", 1.1); + testSystem2.addComponent("ethane", 0.1); + testSystem3.setMixingRule(2); + + Stream stream1 = new Stream("Stream1", testSystem2); + stream1.setFlowRate(100.0, "kg/hr"); + stream1.setPressure(10.0, "bara"); + stream1.setTemperature(25.0, "C"); + + Stream streamPurge = new Stream("StreamPurge", testSystem3); + streamPurge.setFlowRate(5.0, "kg/hr"); + streamPurge.setPressure(10.0, "bara"); + streamPurge.setTemperature(25.0, "C"); + + ThrottlingValve valve1 = new ThrottlingValve("valve_1", stream1); + valve1.setOutletPressure(7.0); + valve1.setPercentValveOpening(50); + valve1.setCalculateSteadyState(false); + + ThrottlingValve valvePurge = new ThrottlingValve("valve_purge", streamPurge); + valvePurge.setOutletPressure(7.0); + valvePurge.setPercentValveOpening(50); + valvePurge.setCalculateSteadyState(false); + + Separator separator1 = new Separator("separator_1"); + separator1.addStream(valve1.getOutletStream()); + separator1.addStream(valvePurge.getOutletStream()); + separator1.setCalculateSteadyState(false); + separator1.setSeparatorLength(3.0); + separator1.setInternalDiameter(0.8); + separator1.setLiquidLevel(0.0); + + ThrottlingValve valve3 = new ThrottlingValve("valve_3", separator1.getGasOutStream()); + valve3.setOutletPressure(1.0); + valve3.setPercentValveOpening(50); + valve3.setCalculateSteadyState(false); + + PressureTransmitter separatorPressureTransmitter = + new PressureTransmitter(separator1.getGasOutStream()); + separatorPressureTransmitter.setUnit("bar"); + separatorPressureTransmitter.setMaximumValue(10.0); + separatorPressureTransmitter.setMinimumValue(1.0); + + ControllerDeviceInterface separatorPressureController = new ControllerDeviceBaseClass(); + separatorPressureController.setTransmitter(separatorPressureTransmitter); + separatorPressureController.setReverseActing(false); + separatorPressureController.setControllerSetPoint(5.0); + separatorPressureController.setControllerParameters(0.5, 100.0, 0.0); + + p.add(stream1); + p.add(streamPurge); + p.add(valve1); + p.add(valvePurge); + p.add(separator1); + p.add(valve3); + + p.add(separatorPressureTransmitter); + valve3.setController(separatorPressureController); + + p.run(); + for (SimulationInterface sim : p.getUnitOperations()) { + assertEquals(sim.getCalculationIdentifier(), p.getCalculationIdentifier()); + } + + // p.displayResult(); + p.setTimeStep(0.01); + for (int i = 0; i < 50; i++) { + System.out.println("pressure " + separator1.getGasOutStream().getPressure() + " flow " + + separator1.getGasOutStream().getFlowRate("kg/hr") + "valve3 opening " + + valve3.getPercentValveOpening()); p.runTransient(); for (SimulationInterface sim : p.getUnitOperations()) { assertEquals(p.getCalculationIdentifier(), sim.getCalculationIdentifier()); diff --git a/src/test/java/neqsim/thermodynamicOperations/flashOps/VUFlashTest.java b/src/test/java/neqsim/thermodynamicOperations/flashOps/VUFlashTest.java new file mode 100644 index 0000000000..1cf0cd3216 --- /dev/null +++ b/src/test/java/neqsim/thermodynamicOperations/flashOps/VUFlashTest.java @@ -0,0 +1,49 @@ +package neqsim.thermodynamicOperations.flashOps; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import neqsim.thermodynamicOperations.ThermodynamicOperations; + +/** + * Test VUFlash. + */ +class VUFlashTest { + static Logger logger = LogManager.getLogger(VUFlashTest.class); + + static neqsim.thermo.system.SystemInterface testSystem = null; + static neqsim.thermo.system.SystemInterface testSystem2 = null; + static ThermodynamicOperations testOps = null; + + /** + * Sets up test system. + * + * @throws java.lang.Exception + */ + @BeforeEach + void setUp() throws Exception { + + } + + @Test + void testVUflash() { + testSystem = new neqsim.thermo.system.SystemUMRPRUMCEos(293.15, 23.5); + testSystem.addComponent("methane", 1.0); + testSystem.addComponent("ethane", 0.01); + testSystem.addComponent("n-pentane", 0.01); + testSystem.setMixingRule("classic"); + testOps = new ThermodynamicOperations(testSystem); + testOps.TPflash(); + testSystem.initProperties(); + + double volume = testSystem.getVolume("m3"); + double internalenergy = testSystem.getInternalEnergy("J"); + + testOps.VUflash(volume * 1.1, internalenergy, "m3", "J"); + + assertEquals(21.387, testSystem.getPressure(), 0.01); + } + +}