From 2300cc10ad06c2d51008b8f368b990b2114645f2 Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Sun, 5 Jan 2025 12:25:55 +0000 Subject: [PATCH 1/2] fix mixer minimum pressure --- .../neqsim/process/equipment/mixer/Mixer.java | 13 +++++---- .../process/equipment/mixer/MixerTest.java | 27 +++++++++++++++++++ .../SalesGasAndStableOilTest.java | 2 +- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/main/java/neqsim/process/equipment/mixer/Mixer.java b/src/main/java/neqsim/process/equipment/mixer/Mixer.java index a78c2c82d7..fb2fdc56d3 100644 --- a/src/main/java/neqsim/process/equipment/mixer/Mixer.java +++ b/src/main/java/neqsim/process/equipment/mixer/Mixer.java @@ -36,6 +36,7 @@ public class Mixer extends ProcessEquipmentBaseClass implements MixerInterface { protected StreamInterface mixedStream; private boolean isSetOutTemperature = false; private double outTemperature = Double.NaN; + double lowestPressure = Double.NEGATIVE_INFINITY; /** *
@@ -106,13 +107,17 @@ public StreamInterface getStream(int i) { public void mixStream() { int index = 0; String compName = new String(); - double lowestPressure = mixedStream.getThermoSystem().getPhase(0).getPressure(); + lowestPressure = mixedStream.getThermoSystem().getPhase(0).getPressure(); boolean hasAddedNewComponent = false; for (int k = 1; k < streams.size(); k++) { if (streams.get(k).getThermoSystem().getPhase(0).getPressure() < lowestPressure) { lowestPressure = streams.get(k).getThermoSystem().getPhase(0).getPressure(); - mixedStream.getThermoSystem().getPhase(0).setPressure(lowestPressure); } + } + for (int k = 0; k < streams.size(); k++) { + // streams.get(k).getThermoSystem().getPhase(0).setPressure(lowestPressure); + } + for (int k = 1; k < streams.size(); k++) { for (int i = 0; i < streams.get(k).getThermoSystem().getPhase(0) .getNumberOfComponents(); i++) { boolean gotComponent = false; @@ -212,7 +217,7 @@ public void run(UUID id) { mixedStream.getThermoSystem().init(0); mixStream(); - + mixedStream.setPressure(lowestPressure); enthalpy = calcMixStreamEnthalpy(); // System.out.println("temp guess " + guessTemperature()); if (isSetOutTemperature) { @@ -244,13 +249,11 @@ public void run(UUID id) { mixedStream.getThermoSystem().init(2); } - // System.out.println("enthalpy: " + // mixedStream.getThermoSystem().getEnthalpy()) // System.out.println("enthalpy: " + en // System.out.println("temperature: " + - // System.out.println("beta " + mixedStream.getThermoSystem( // outStream.setThermoSystem(mixedStream.getThermoSystem()); setCalculationIdentifier(id); diff --git a/src/test/java/neqsim/process/equipment/mixer/MixerTest.java b/src/test/java/neqsim/process/equipment/mixer/MixerTest.java index e872225184..3164ba9845 100644 --- a/src/test/java/neqsim/process/equipment/mixer/MixerTest.java +++ b/src/test/java/neqsim/process/equipment/mixer/MixerTest.java @@ -6,6 +6,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import neqsim.process.equipment.stream.Stream; +import neqsim.process.equipment.stream.StreamInterface; import neqsim.process.processmodel.ProcessSystem; import neqsim.thermo.system.SystemSrkEos; @@ -81,4 +82,30 @@ void testNeedRecalculation() { processOps.run(); assertFalse(gasStream.needRecalculation()); } + + /** + * Test method for {@link neqsim.process.equipment.mixer.Mixer#run()}. + */ + @Test + void testRunDifferentPressures() { + StreamInterface gasStream2 = (StreamInterface) gasStream.clone(); + StreamInterface waterStream2 = (StreamInterface) waterStream.clone(); + + gasStream2.setPressure(10.0, "bara"); + waterStream2.setPressure(30.0, "bara"); + + gasStream2.run(); + waterStream2.run(); + + double totalEnthalpy = + gasStream2.getFluid().getEnthalpy("J") + waterStream2.getFluid().getEnthalpy("J"); + + Mixer testMixer = new Mixer("test mixer"); + testMixer.addStream(waterStream2); + testMixer.addStream(gasStream2); + testMixer.run(); + + assertEquals(totalEnthalpy, testMixer.getOutletStream().getFluid().getEnthalpy("J"), 1e-1); + assertEquals(10.0, testMixer.getOutletStream().getPressure("bara"), 1e-1); + } } diff --git a/src/test/java/neqsim/process/processmodel/SalesGasAndStableOilTest.java b/src/test/java/neqsim/process/processmodel/SalesGasAndStableOilTest.java index a2a5d5655f..9aef10e6b2 100644 --- a/src/test/java/neqsim/process/processmodel/SalesGasAndStableOilTest.java +++ b/src/test/java/neqsim/process/processmodel/SalesGasAndStableOilTest.java @@ -239,7 +239,7 @@ public void testProcess2() { dewPointControlCooler2.setOutTemperature(-15.0, "C"); dewPointControlCooler2.setOutPressure(59.5, "bara"); dewPointControlCooler2.run(); - Assertions.assertEquals(0.967383748675644, + Assertions.assertEquals(0.96737504327, dewPointControlCooler2.getOutStream().getFluid().getBeta(), 1e-6); Separator dewPointScrubber2 = new neqsim.process.equipment.separator.Separator( "dew point scrubber 2", dewPointControlCooler2.getOutStream()); From 9333dc529406e4b845856ead9049600635331c2b Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Mon, 6 Jan 2025 07:48:01 +0000 Subject: [PATCH 2/2] update model --- .../MultiStreamHeatExchanger.java | 1 + .../MultiStreamHeatExchangerTest.java | 93 +++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/src/main/java/neqsim/process/equipment/heatexchanger/MultiStreamHeatExchanger.java b/src/main/java/neqsim/process/equipment/heatexchanger/MultiStreamHeatExchanger.java index 0f457ad006..e20b71c385 100644 --- a/src/main/java/neqsim/process/equipment/heatexchanger/MultiStreamHeatExchanger.java +++ b/src/main/java/neqsim/process/equipment/heatexchanger/MultiStreamHeatExchanger.java @@ -714,6 +714,7 @@ public void run(UUID id) { iterations = 0; } setCalculationIdentifier(id); + firstTime = true; } diff --git a/src/test/java/neqsim/process/equipment/heatexchanger/MultiStreamHeatExchangerTest.java b/src/test/java/neqsim/process/equipment/heatexchanger/MultiStreamHeatExchangerTest.java index 3cde44b4e9..10b146a173 100644 --- a/src/test/java/neqsim/process/equipment/heatexchanger/MultiStreamHeatExchangerTest.java +++ b/src/test/java/neqsim/process/equipment/heatexchanger/MultiStreamHeatExchangerTest.java @@ -5,7 +5,11 @@ import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import neqsim.process.equipment.expander.Expander; +import neqsim.process.equipment.separator.Separator; import neqsim.process.equipment.stream.Stream; +import neqsim.process.equipment.util.Recycle; +import neqsim.process.equipment.valve.ThrottlingValve; import neqsim.thermodynamicoperations.ThermodynamicOperations; public class MultiStreamHeatExchangerTest { @@ -72,6 +76,95 @@ void testRun1() { } + @Test + void testRun2() { + + neqsim.process.processmodel.ProcessSystem operations = + new neqsim.process.processmodel.ProcessSystem(); + + Stream feed_stream = new Stream("Stream1", testSystem); + feed_stream.setTemperature(30.0, "C"); + feed_stream.setPressure(75.0, "bara"); + feed_stream.setFlowRate(1000.0, "kg/hr"); + feed_stream.run(); + operations.add(feed_stream); + + Separator separator = new Separator("sep 1", feed_stream); + operations.add(separator); + + Stream stream_Cold = new Stream("Stream2", testSystem.clone()); + stream_Cold.setTemperature(-5.0, "C"); + stream_Cold.setPressure(50.0, "bara"); + stream_Cold.setFlowRate(310.0, "kg/hr"); + stream_Cold.run(); + operations.add(stream_Cold); + + Stream stream_Cold2 = new Stream("Stream3", testSystem.clone()); + stream_Cold2.setTemperature(-5.0, "C"); + stream_Cold2.setPressure(50.0, "bara"); + stream_Cold2.setFlowRate(50.0, "kg/hr"); + stream_Cold2.run(); + operations.add(stream_Cold2); + + MultiStreamHeatExchanger heatEx = new MultiStreamHeatExchanger("heatEx"); + heatEx.addInStream(separator.getGasOutStream()); + heatEx.addInStream(stream_Cold); + heatEx.addInStream(stream_Cold2); + // heatEx.setUAvalue(1000); + heatEx.setTemperatureApproach(5); + heatEx.run(); + operations.add(heatEx); + + Separator dewseparator = new Separator("sep 2", heatEx.getOutStream(0)); + dewseparator.run(); + operations.add(dewseparator); + + + Expander expander = new Expander("expander", dewseparator.getGasOutStream()); + expander.setOutletPressure(50., "bara"); + expander.run(); + operations.add(expander); + + ThrottlingValve jt_valve = new ThrottlingValve("JT valve", dewseparator.getLiquidOutStream()); + jt_valve.setOutletPressure(50.0, "bara"); + jt_valve.run(); + operations.add(jt_valve); + + Separator separator2 = new Separator("sep 3", expander.getOutletStream()); + separator2.addStream(jt_valve.getOutletStream()); + separator2.run(); + operations.add(separator2); + + Recycle gas_expander_resycle = new neqsim.process.equipment.util.Recycle("gas recycl"); + gas_expander_resycle.addStream(separator2.getGasOutStream()); + gas_expander_resycle.setOutletStream(stream_Cold); + gas_expander_resycle.setTolerance(1e-3); + gas_expander_resycle.run(); + operations.add(gas_expander_resycle); + + Recycle liq_expander_resycle = new neqsim.process.equipment.util.Recycle("liq recycl"); + liq_expander_resycle.addStream(separator2.getLiquidOutStream()); + liq_expander_resycle.setOutletStream(stream_Cold2); + liq_expander_resycle.setTolerance(1e-3); + liq_expander_resycle.run(); + operations.add(liq_expander_resycle); + + operations.run(); + + separator2.getFluid().prettyPrint(); + heatEx.getOutStream(0).getFluid().prettyPrint(); + + assertEquals(-34.6818572, separator2.getFluid().getTemperature("C"), 1e-3); + assertEquals(25.0, heatEx.getOutStream(1).getTemperature("C"), 1e-3); + + heatEx.setUAvalue(5000); + operations.run(); + + assertEquals(-26.931795168, separator2.getFluid().getTemperature("C"), 1e-3); + assertEquals(17.37650429489, heatEx.getOutStream(1).getTemperature("C"), 1e-3); + + } + }