From 2b5f92df318e60ad06550d30845addb02d54af50 Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Wed, 11 Dec 2024 19:19:29 +0000 Subject: [PATCH] update valve calc --- .../equipment/valve/ThrottlingValve.java | 35 ++++++++++-- .../equipment/valve/ThrottlingValveTest.java | 53 +++++++++++++++++++ 2 files changed, 84 insertions(+), 4 deletions(-) diff --git a/src/main/java/neqsim/process/equipment/valve/ThrottlingValve.java b/src/main/java/neqsim/process/equipment/valve/ThrottlingValve.java index 11893883a3..7ce1a8c26d 100644 --- a/src/main/java/neqsim/process/equipment/valve/ThrottlingValve.java +++ b/src/main/java/neqsim/process/equipment/valve/ThrottlingValve.java @@ -45,6 +45,7 @@ public class ThrottlingValve extends TwoPortEquipment implements ValveInterface boolean isCalcPressure = false; private boolean gasValve = true; private double Fp = 1.0; + private double deltaPressure = 0.0; /** * * Constructor for ThrottlingValve. @@ -415,12 +416,20 @@ public double calcPercentValveOpening(double Pus, double Pds, double rhous, doub public void run(UUID id) { // System.out.println("valve running.."); // outStream.setSpecification(inletStream.getSpecification()); - thermoSystem = getInletStream().getThermoSystem().clone(); + if (getInletStream().getThermoSystem() != null) { + thermoSystem = getInletStream().getThermoSystem().clone(); + } else { + logger.error("Inlet stream thermo system is null"); + return; + } ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem); thermoSystem.init(3); double enthalpy = thermoSystem.getEnthalpy(); inStream.getThermoSystem().initPhysicalProperties(PhysicalPropertyType.MASS_DENSITY); double outp = 0.0; + if (pressure == 0) { + pressure = inStream.getThermoSystem().getPressure(); + } if (inStream.getThermoSystem().hasPhaseType(PhaseType.GAS) && inStream.getThermoSystem().getVolumeFraction(0) > 0.9) { @@ -441,6 +450,12 @@ public void run(UUID id) { } setOutletPressure(outp); } + if (deltaPressure != 0) { + thermoSystem.setPressure(thermoSystem.getPressure(pressureUnit) - deltaPressure, + pressureUnit); + setOutletPressure(thermoSystem.getPressure()); + + } if ((thermoSystem.getPressure(pressureUnit) - pressure) < 0) { if (isAcceptNegativeDP()) { @@ -456,14 +471,15 @@ public void run(UUID id) { // System.out.println("enthalpy inn.." + enthalpy); // thermoOps.PHflash(enthalpy, 0); if (isIsoThermal() || Math.abs(pressure - inStream.getThermoSystem().getPressure()) < 1e-6 - || thermoSystem.getNumberOfMoles() < 1e-12) { + || thermoSystem.getNumberOfMoles() < 1e-12 || pressure == 0) { thermoOps.TPflash(); } else { thermoOps.PHflash(enthalpy, 0); } outStream.setThermoSystem(thermoSystem); // System.out.println("Total volume flow " + - // outStream.getThermoSystem().getVolume()); + // Uncomment the line below to get the volume of the outlet stream's thermodynamic system + // System.out.println("Total volume flow " + outStream.getThermoSystem().getVolume()); // System.out.println("density valve " + // inletStream.getThermoSystem().getDensity()); @@ -522,7 +538,9 @@ public void run(UUID id) { } /** {@inheritDoc} */ - @Override + /** + * This annotation is used to exclude the method from Jacoco code coverage reports. + */ @ExcludeFromJacocoGeneratedReport public void displayResult() { thermoSystem.display(getName()); @@ -813,4 +831,13 @@ public double getFp() { public void setFp(double fp) { Fp = fp; } + + public double getDeltaPressure() { + return deltaPressure; + } + + public void setDeltaPressure(double deltaPressure, String unit) { + this.deltaPressure = deltaPressure; + this.pressureUnit = unit; + } } diff --git a/src/test/java/neqsim/process/equipment/valve/ThrottlingValveTest.java b/src/test/java/neqsim/process/equipment/valve/ThrottlingValveTest.java index c66214278e..aebf76c716 100644 --- a/src/test/java/neqsim/process/equipment/valve/ThrottlingValveTest.java +++ b/src/test/java/neqsim/process/equipment/valve/ThrottlingValveTest.java @@ -52,4 +52,57 @@ void testCalcCvLiquid() { assertEquals(100, stream1.getFlowRate("kg/hr"), 1e-2); assertEquals(3.015805897362369E-4, valve1.getCv("US"), 1e-2); } + + @Test + void testSetDeltaPressure() { + neqsim.thermo.system.SystemInterface testSystem2 = + new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00); + testSystem2.addComponent("methane", 1.0); + testSystem2.setMixingRule(2); + + Stream stream1 = new Stream("Stream1", testSystem2); + stream1.setFlowRate(100.0, "kg/hr"); + stream1.setPressure(100.0, "bara"); + stream1.setTemperature(55.0, "C"); + stream1.run(); + + double deltaPressure = 10.0; + ThrottlingValve valve1 = new ThrottlingValve("valve_1", stream1); + valve1.setDeltaPressure(deltaPressure, "bara"); + valve1.run(); + + Stream stream2 = new Stream("Stream1", valve1.getOutletStream()); + stream2.getPressure("bara"); + stream2.run(); + + assertEquals(deltaPressure, valve1.getDeltaPressure(), 1e-2); + assertEquals(deltaPressure, stream1.getPressure("bara") - stream2.getPressure("bara"), 1e-4); + assertEquals(52.269428855, stream2.getTemperature("C"), 1e-2); + } + + @Test + void testSetDeltaPressure2() { + neqsim.thermo.system.SystemInterface testSystem2 = + new neqsim.thermo.system.SystemSrkEos((273.15 + 25.0), 10.00); + testSystem2.addComponent("methane", 1.0); + testSystem2.setMixingRule(2); + + Stream stream1 = new Stream("Stream1", testSystem2); + stream1.setFlowRate(100.0, "kg/hr"); + stream1.setPressure(100.0, "bara"); + stream1.setTemperature(55.0, "C"); + stream1.run(); + + double deltaPressure = 0.0; + ThrottlingValve valve1 = new ThrottlingValve("valve_1", stream1); + valve1.run(); + + Stream stream2 = new Stream("Stream1", valve1.getOutletStream()); + stream2.getPressure("bara"); + stream2.run(); + + assertEquals(deltaPressure, valve1.getDeltaPressure(), 1e-2); + assertEquals(deltaPressure, stream1.getPressure("bara") - stream2.getPressure("bara"), 1e-4); + assertEquals(55.0, stream2.getTemperature("C"), 1e-2); + } }