From 92a7b582dbeb071af4bf8d6dfef46b1ed01a75ce Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Sun, 8 Dec 2024 07:57:28 +0100 Subject: [PATCH] added option to add energy stream (#1202) --- .../equipment/compressor/Compressor.java | 4 ++ .../process/equipment/expander/Expander.java | 17 +++--- .../equipment/stream/EnergyStream.java | 15 ++++++ .../equipment/compressor/CompressorTest.java | 52 +++++++++++++++++++ 4 files changed, 82 insertions(+), 6 deletions(-) diff --git a/src/main/java/neqsim/process/equipment/compressor/Compressor.java b/src/main/java/neqsim/process/equipment/compressor/Compressor.java index 3219e9cf63..35b415ec6f 100644 --- a/src/main/java/neqsim/process/equipment/compressor/Compressor.java +++ b/src/main/java/neqsim/process/equipment/compressor/Compressor.java @@ -296,6 +296,10 @@ public void run(UUID id) { return; } + if (isSetEnergyStream()) { + setPower(energyStream.getDuty()); + } + ThermodynamicOperations thermoOps = new ThermodynamicOperations(getThermoSystem()); thermoOps = new ThermodynamicOperations(getThermoSystem()); getThermoSystem().init(3); diff --git a/src/main/java/neqsim/process/equipment/expander/Expander.java b/src/main/java/neqsim/process/equipment/expander/Expander.java index 606c8079ea..e740044de8 100644 --- a/src/main/java/neqsim/process/equipment/expander/Expander.java +++ b/src/main/java/neqsim/process/equipment/expander/Expander.java @@ -31,8 +31,7 @@ public Expander(String name) { *

* * @param name a {@link java.lang.String} object - * @param inletStream a {@link neqsim.process.equipment.stream.StreamInterface} - * object + * @param inletStream a {@link neqsim.process.equipment.stream.StreamInterface} object */ public Expander(String name, StreamInterface inletStream) { super(name, inletStream); @@ -51,18 +50,21 @@ public void run(UUID id) { // double densInn = getThermoSystem().getDensity(); double entropy = getThermoSystem().getEntropy(); inletEnthalpy = hinn; - + double hout = hinn; if (usePolytropicCalc) { int numbersteps = 40; double dp = (pressure - getThermoSystem().getPressure()) / (1.0 * numbersteps); + for (int i = 0; i < numbersteps; i++) { entropy = getThermoSystem().getEntropy(); - hinn = getThermoSystem().getEnthalpy(); + double hinn_loc = getThermoSystem().getEnthalpy(); getThermoSystem().setPressure(getThermoSystem().getPressure() + dp); thermoOps.PSflash(entropy); - double hout = hinn + (getThermoSystem().getEnthalpy() - hinn) * polytropicEfficiency; + hout = hinn_loc + (getThermoSystem().getEnthalpy() - hinn_loc) * polytropicEfficiency; thermoOps.PHflash(hout, 0); } + + dH = hout - hinn; /* * HYSYS method double oldPolyt = 10.5; int iter = 0; do { * @@ -87,12 +89,15 @@ public void run(UUID id) { if (!powerSet) { dH = (getThermoSystem().getEnthalpy() - hinn) * isentropicEfficiency; } - double hout = hinn + dH; + hout = hinn + dH; isentropicEfficiency = dH / (getThermoSystem().getEnthalpy() - hinn); // System.out.println("isentropicEfficiency.. " + isentropicEfficiency); dH = hout - hinn; thermoOps.PHflash(hout, 0); } + if (isSetEnergyStream()) { + energyStream.setDuty(-dH); + } // thermoSystem.display(); outStream.setThermoSystem(getThermoSystem()); setCalculationIdentifier(id); diff --git a/src/main/java/neqsim/process/equipment/stream/EnergyStream.java b/src/main/java/neqsim/process/equipment/stream/EnergyStream.java index 30d2c0e551..35c2897374 100644 --- a/src/main/java/neqsim/process/equipment/stream/EnergyStream.java +++ b/src/main/java/neqsim/process/equipment/stream/EnergyStream.java @@ -15,9 +15,16 @@ public class EnergyStream implements java.io.Serializable, Cloneable { private static final long serialVersionUID = 1000; static Logger logger = LogManager.getLogger(EnergyStream.class); + private String name = ""; private double duty = 0.0; + public EnergyStream() {} + + public EnergyStream(String name) { + this.name = name; + } + /** {@inheritDoc} */ @Override public EnergyStream clone() { @@ -73,4 +80,12 @@ public boolean equals(Object obj) { EnergyStream other = (EnergyStream) obj; return Double.doubleToLongBits(duty) == Double.doubleToLongBits(other.duty); } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } } diff --git a/src/test/java/neqsim/process/equipment/compressor/CompressorTest.java b/src/test/java/neqsim/process/equipment/compressor/CompressorTest.java index bf5b6e523a..e4eae7fa30 100644 --- a/src/test/java/neqsim/process/equipment/compressor/CompressorTest.java +++ b/src/test/java/neqsim/process/equipment/compressor/CompressorTest.java @@ -12,6 +12,8 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import neqsim.process.equipment.expander.Expander; +import neqsim.process.equipment.stream.EnergyStream; import neqsim.process.equipment.stream.Stream; import neqsim.process.processmodel.ProcessSystem; import neqsim.thermo.system.SystemSrkEos; @@ -292,4 +294,54 @@ public void testPowerEffSpec() { assertEquals(139.7216108, compressor1.getOutletStream().getTemperature("C"), 0.01); // compressor1.getOutletStream().getFluid().prettyPrint(); } + + + /** + *

+ * test run with energy stream input. + *

+ */ + @Test + public void testRunWithEnergyStreamInput() { + SystemSrkEos testSystem = new SystemSrkEos(315.0, 10.0); + testSystem.addComponent("nitrogen", 2.0); + testSystem.addComponent("methane", 50.0); + testSystem.setMixingRule(2); + + Stream inletStream = new Stream("feed stream", testSystem); + inletStream.setPressure(100, "bara"); + inletStream.setTemperature(30, "C"); + inletStream.setFlowRate(1, "MSm3/day"); + inletStream.run(); + + EnergyStream estream1 = new EnergyStream("e_stream"); + + Expander expander1 = new Expander("expander 1", inletStream); + expander1.setPolytropicEfficiency(0.8); + expander1.setUsePolytropicCalc(true); + // expander1.setIsentropicEfficiency(1.0); + expander1.setOutletPressure(55.0, "bara"); + expander1.setEnergyStream(estream1); + expander1.run(); + + assertEquals(481376.2230301, estream1.getDuty(), 0.01); + + compressor1 = new Compressor("compressor 1", expander1.getOutletStream()); + compressor1.setUsePolytropicCalc(true); + compressor1.setPolytropicEfficiency(0.8); + // compressor1.setIsentropicEfficiency(1.0); + compressor1.setEnergyStream(estream1); + compressor1.setCalcPressureOut(true); + compressor1.run(); + + assertEquals(481376.2230301, compressor1.getPower(), 0.01); + + processOps = new ProcessSystem(); + processOps.add(inletStream); + processOps.add(expander1); + processOps.add(compressor1); + processOps.run(); + + assertEquals(81.61462472, compressor1.getOutletPressure(), 0.01); + } }