From 80d487ed051388cba2c4db7842efcce5433f430f Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Sun, 3 Dec 2023 23:03:34 +0100 Subject: [PATCH] updated dynamics calc (#868) * updated dynamics calc * updates * update dynamic calc * update model * fix test error * remove output * added test and fix * update * fixed errors control --- .../ControllerDeviceBaseClass.java | 7 +- .../processEquipment/separator/Separator.java | 214 +++++++++++------- .../separator/SeparatorInterface.java | 2 + .../valve/ThrottlingValve.java | 55 +++-- .../processSystem/ProcessSystem.java | 2 +- .../flashOps/PHflashSingleComp.java | 6 +- .../separator/SeparatorTest.java | 4 +- .../ProcessSystemRunTransientTest.java | 194 ++++++++++++---- .../flashOps/VUFlashTest.java | 49 ++++ 9 files changed, 373 insertions(+), 160 deletions(-) create mode 100644 src/test/java/neqsim/thermodynamicOperations/flashOps/VUFlashTest.java diff --git a/src/main/java/neqsim/processSimulation/controllerDevice/ControllerDeviceBaseClass.java b/src/main/java/neqsim/processSimulation/controllerDevice/ControllerDeviceBaseClass.java index 685eb70533..1486f94d3c 100644 --- a/src/main/java/neqsim/processSimulation/controllerDevice/ControllerDeviceBaseClass.java +++ b/src/main/java/neqsim/processSimulation/controllerDevice/ControllerDeviceBaseClass.java @@ -43,7 +43,9 @@ public class ControllerDeviceBaseClass extends NamedBaseClass implements Control private double TintValue = 0.0; /** - *

Constructor for ControllerDeviceBaseClass.

+ *

+ * Constructor for ControllerDeviceBaseClass. + *

*/ public ControllerDeviceBaseClass() { super("controller"); @@ -75,7 +77,8 @@ public void runTransient(double initResponse, double dt, UUID id) { transmitter.getMeasuredPercentValue() - (controllerSetPoint - transmitter.getMinimumValue()) / (transmitter.getMaximumValue() - transmitter.getMinimumValue()) * 100; - TintValue += Kp / Ti * error * dt; + if (Ti > 0) + TintValue += Kp / Ti * error * dt; double TderivValue = Kp * Td * (error - oldError) / dt; response = initResponse + propConstant * (Kp * error + TintValue + TderivValue); // System.out.println("error " + error + " %"); diff --git a/src/main/java/neqsim/processSimulation/processEquipment/separator/Separator.java b/src/main/java/neqsim/processSimulation/processEquipment/separator/Separator.java index e3ababd76a..e1765f7c64 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/separator/Separator.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/separator/Separator.java @@ -60,11 +60,14 @@ public class Separator extends ProcessEquipmentBaseClass implements SeparatorInt /** Inner diameter/height of separator volume. */ private double internalDiameter = 1.0; - double liquidVolume = 1.0; - double gasVolume = 18.0; + /** LiquidLevel as volume fraction of liquidvolume/(liquid + gas volume). */ - private double liquidLevel = liquidVolume / (liquidVolume + gasVolume); + private double liquidLevel = 0.5; + double liquidVolume = + Math.PI * internalDiameter * internalDiameter / 4.0 * separatorLength * liquidLevel; + double gasVolume = + Math.PI * internalDiameter * internalDiameter / 4.0 * separatorLength * (1.0 - liquidLevel); private double designLiquidLevelFraction = 0.8; ArrayList separatorSection = new ArrayList(); @@ -241,50 +244,56 @@ 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()); + } } - // liquidOutStream.setThermoSystemFromPhase(thermoSystem2, "aqueous"); - try { - thermoSystem = thermoSystem2.clone(); - thermoSystem.setTotalNumberOfMoles(1.0e-10); - thermoSystem.init(1); - // System.out.println("number of phases " + thermoSystem.getNumberOfPhases()); - double totalliquidVolume = 0.0; - for (int j = 0; j < thermoSystem.getNumberOfPhases(); j++) { - double relFact = gasVolume / (thermoSystem2.getPhase(j).getVolume() * 1.0e-5); - if (j >= 1) { - relFact = liquidVolume / (thermoSystem2.getPhase(j).getVolume() * 1.0e-5); - - totalliquidVolume += liquidVolume / thermoSystem2.getPhase(j).getMolarVolume(); + if (getCalculateSteadyState()) { + thermoSystem = thermoSystem2; + } else { + try { + liquidVolume = + Math.PI * internalDiameter * internalDiameter / 4.0 * separatorLength * liquidLevel; + gasVolume = Math.PI * internalDiameter * internalDiameter / 4.0 * separatorLength + * (1.0 - liquidLevel); + thermoSystem = thermoSystem2.clone(); + thermoSystem.init(1); + thermoSystem.initPhysicalProperties("density"); + thermoSystem2.initPhysicalProperties("density"); + for (int j = 0; j < thermoSystem.getNumberOfPhases(); j++) { + double relFact = 1.0; + if (thermoSystem.getPhase(j).getPhaseTypeName().equals("gas")) { + relFact = gasVolume / (thermoSystem2.getPhase(j).getVolume("m3")); + } else { + relFact = liquidVolume / (thermoSystem2.getPhase(j).getVolume("m3")); + } + for (int i = 0; i < thermoSystem.getPhase(j).getNumberOfComponents(); i++) { + thermoSystem.addComponent(i, (relFact - 1.0) + * thermoSystem2.getPhase(j).getComponent(i).getNumberOfMolesInPhase(), j); + } } - for (int i = 0; i < thermoSystem.getPhase(j).getNumberOfComponents(); i++) { - thermoSystem.addComponent(thermoSystem.getPhase(j).getComponent(i).getComponentNumber(), - relFact * thermoSystem2.getPhase(j).getComponent(i).getNumberOfMolesInPhase(), j); + ThermodynamicOperations ops = new ThermodynamicOperations(thermoSystem); + ops.TPflash(); + thermoSystem.init(3); + thermoSystem.initPhysicalProperties("density"); + if (thermoSystem.hasPhaseType("oil") || thermoSystem.hasPhaseType("aqueous")) { + liquidLevel = thermoSystem.getPhase(1).getVolume("m3") / (liquidVolume + gasVolume); + liquidVolume = getLiquidLevel() * 3.14 / 4.0 * getInternalDiameter() + * getInternalDiameter() * getSeparatorLength(); + } else { + liquidLevel = 0.0; + liquidVolume = 0.0; } - } - if (thermoSystem.hasPhaseType("gas")) { - thermoSystem.setBeta(gasVolume / thermoSystem2.getPhase(0).getMolarVolume() - / (gasVolume / thermoSystem2.getPhase(0).getMolarVolume() + totalliquidVolume)); + gasVolume = (1.0 - getLiquidLevel()) * 3.14 / 4.0 * getInternalDiameter() + * getInternalDiameter() * getSeparatorLength(); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); } - thermoSystem.initBeta(); - thermoSystem.init(3); - // System.out.println("moles in separator " + thermoSystem.getNumberOfMoles()); - // double volume1 = thermoSystem.getVolume(); - // System.out.println("volume1 bef " + volume1); - // System.out.println("beta " + thermoSystem.getBeta()); - - liquidLevel = thermoSystem.getPhase(1).getVolume() * 1e-5 / (liquidVolume + gasVolume); - liquidVolume = getLiquidLevel() * 3.14 / 4.0 * getInternalDiameter() * getInternalDiameter() - * getSeparatorLength(); - gasVolume = (1.0 - getLiquidLevel()) * 3.14 / 4.0 * getInternalDiameter() - * getInternalDiameter() * getSeparatorLength(); - // System.out.println("moles out" + - // liquidOutStream.getThermoSystem().getTotalNumberOfMoles()); - } catch (Exception ex) { - logger.error(ex.getMessage(), ex); } - thermoSystem = thermoSystem2; + setCalculationIdentifier(id); } @@ -306,50 +315,75 @@ public void runTransient(double dt, UUID id) { if (getCalculateSteadyState()) { run(id); increaseTime(dt); + setCalculationIdentifier(id); return; - } - - inletStreamMixer.run(id); + } else { + inletStreamMixer.run(id); + thermoSystem.init(3); + thermoSystem.initPhysicalProperties("density"); + try { + gasOutStream.getThermoSystem().init(3); + liquidOutStream.getThermoSystem().init(3); + } catch (Exception e) { + logger.error(e.getMessage()); + } + boolean hasliq = false; + double deliq = 0.0; + if (thermoSystem.hasPhaseType("oil") || thermoSystem.hasPhaseType("aqueous")) { + hasliq = true; + deliq = -liquidOutStream.getThermoSystem().getEnthalpy(); + } + double deltaEnergy = inletStreamMixer.getOutletStream().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(); + double dniliq = 0.0; + if (hasliq) { + dniliq = -liquidOutStream.getThermoSystem().getComponent(i).getNumberOfmoles(); + } + dncomp += -gasOutStream.getThermoSystem().getComponent(i).getNumberOfmoles() + dniliq; - // System.out.println("moles out" + - // liquidOutStream.getThermoSystem().getTotalNumberOfMoles()); - // double inMoles = - // inletStreamMixer.getOutStream().getThermoSystem().getTotalNumberOfMoles(); - // double gasoutMoles = gasOutStream.getThermoSystem().getNumberOfMoles(); - // double liqoutMoles = liquidOutStream.getThermoSystem().getNumberOfMoles(); - thermoSystem.init(3); - gasOutStream.getThermoSystem().init(3); - liquidOutStream.getThermoSystem().init(3); - double volume1 = thermoSystem.getVolume(); - // System.out.println("volume1 " + volume1); - double deltaEnergy = inletStreamMixer.getOutletStream().getThermoSystem().getEnthalpy() - - gasOutStream.getThermoSystem().getEnthalpy() - - liquidOutStream.getThermoSystem().getEnthalpy(); - // System.out.println("enthalph delta " + deltaEnergy); - double newEnergy = thermoSystem.getInternalEnergy() + dt * deltaEnergy; - for (int i = 0; i < thermoSystem.getPhase(0).getNumberOfComponents(); i++) { - double dn = inletStreamMixer.getOutletStream().getThermoSystem().getPhase(0).getComponent(i) - .getNumberOfMolesInPhase() - + inletStreamMixer.getOutletStream().getThermoSystem().getPhase(1).getComponent(i) - .getNumberOfMolesInPhase() - - gasOutStream.getThermoSystem().getPhase(0).getComponent(i).getNumberOfMolesInPhase() - - liquidOutStream.getThermoSystem().getPhase(0).getComponent(i).getNumberOfMolesInPhase(); - // System.out.println("dn " + dn); - thermoSystem.addComponent(inletStreamMixer.getOutletStream().getThermoSystem().getPhase(0) - .getComponent(i).getComponentNumber(), dn * dt); - } - ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem); - thermoOps.VUflash(volume1, newEnergy); + thermoSystem.addComponent(i, dncomp * dt); + } + ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem); + thermoOps.VUflash(gasVolume + liquidVolume, newEnergy, "m3", "J"); + thermoSystem.initPhysicalProperties("density"); - setTempPres(thermoSystem.getTemperature(), thermoSystem.getPressure()); + if (thermoSystem.hasPhaseType("gas")) { + gasOutStream.getFluid() + .setMolarComposition(thermoSystem.getPhase("gas").getMolarComposition()); + } + if (thermoSystem.hasPhaseType("oil") || thermoSystem.hasPhaseType("aqueous")) { + if (thermoSystem.getNumberOfPhases() > 1) { + liquidOutStream.getFluid() + .setMolarComposition(thermoSystem.getPhase(1).getMolarComposition()); + } + } + setTempPres(thermoSystem.getTemperature(), thermoSystem.getPressure()); - liquidLevel = thermoSystem.getPhase(1).getVolume() * 1e-5 / (liquidVolume + gasVolume); - // System.out.println("liquid level " + liquidLevel); - liquidVolume = getLiquidLevel() * 3.14 / 4.0 * getInternalDiameter() * getInternalDiameter() - * getSeparatorLength(); - gasVolume = (1.0 - getLiquidLevel()) * 3.14 / 4.0 * getInternalDiameter() - * getInternalDiameter() * getSeparatorLength(); - setCalculationIdentifier(id); + liquidLevel = 0.0; + if (thermoSystem.hasPhaseType("oil") || thermoSystem.hasPhaseType("aqueous")) { + double volumeLoc = 0.0; + if (thermoSystem.hasPhaseType("oil")) { + volumeLoc += thermoSystem.getPhase("oil").getVolume("m3"); + } + if (thermoSystem.hasPhaseType("aqueous")) { + volumeLoc += thermoSystem.getPhase("aqueous").getVolume("m3"); + } + liquidLevel = volumeLoc / (liquidVolume + gasVolume); + } + liquidVolume = getLiquidLevel() * 3.14 / 4.0 * getInternalDiameter() * getInternalDiameter() + * getSeparatorLength(); + gasVolume = (1.0 - getLiquidLevel()) * 3.14 / 4.0 * getInternalDiameter() + * getInternalDiameter() * getSeparatorLength(); + // System.out.println("gas volume " + gasVolume + " liq volime " + liquidVolume); + setCalculationIdentifier(id); + return; + } } /** @@ -441,6 +475,16 @@ public void setGasCarryunderFraction(double gasCarryunderFraction) { this.gasCarryunderFraction = gasCarryunderFraction; } + /** + *

+ * Setter for the field gasCarryunderFraction. + *

+ * + **/ + public void setLiquidLevel(double liquidlev) { + liquidLevel = liquidlev; + } + /** *

* Getter for the field liquidLevel. @@ -499,7 +543,7 @@ public void setInternalDiameter(double diameter) { * @return a double */ public double getGasSuperficialVelocity() { - return thermoSystem.getPhase(0).getTotalVolume() / 1e5 + return thermoSystem.getPhase(0).getVolume("m3") / (neqsim.thermo.ThermodynamicConstantsInterface.pi * getInternalDiameter() * getInternalDiameter() / 4.0); } @@ -554,7 +598,7 @@ public double getDeRatedGasLoadFactor() { if (surfaceTension < 10.0e-3) { derating = 1.0 - 0.5 * (10.0e-3 - surfaceTension) / 10.0e-3; } - System.out.println("derating " + derating); + // System.out.println("derating " + derating); double term1 = (thermoSystem.getPhase(1).getPhysicalProperties().getDensity() - thermoSystem.getPhase(0).getPhysicalProperties().getDensity()) / thermoSystem.getPhase(0).getPhysicalProperties().getDensity(); @@ -577,7 +621,7 @@ public double getDeRatedGasLoadFactor(int phase) { if (surfaceTension < 10.0e-3) { derating = 1.0 - 0.5 * (10.0e-3 - surfaceTension) / 10.0e-3; } - System.out.println("derating " + derating); + // System.out.println("derating " + derating); double term1 = (thermoSystem.getPhase(phase).getPhysicalProperties().getDensity() - thermoSystem.getPhase(0).getPhysicalProperties().getDensity()) / thermoSystem.getPhase(0).getPhysicalProperties().getDensity(); @@ -658,7 +702,7 @@ public SeparatorSection getSeparatorSection(String name) { return sec; } } - System.out.println("no section with name: " + name + " found....."); + // System.out.println("no section with name: " + name + " found....."); return null; } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/separator/SeparatorInterface.java b/src/main/java/neqsim/processSimulation/processEquipment/separator/SeparatorInterface.java index 39982d1a6c..fbebf9556d 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/separator/SeparatorInterface.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/separator/SeparatorInterface.java @@ -35,4 +35,6 @@ public interface SeparatorInterface extends SimulationInterface { * @param diam a double */ public void setInternalDiameter(double diam); + + public void setLiquidLevel(double liquidlev); } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/valve/ThrottlingValve.java b/src/main/java/neqsim/processSimulation/processEquipment/valve/ThrottlingValve.java index 6fd0fae3bc..746329e155 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/valve/ThrottlingValve.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/valve/ThrottlingValve.java @@ -1,6 +1,8 @@ package neqsim.processSimulation.processEquipment.valve; import java.util.UUID; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import neqsim.processSimulation.mechanicalDesign.valve.ValveMechanicalDesign; import neqsim.processSimulation.processEquipment.TwoPortEquipment; import neqsim.processSimulation.processEquipment.stream.StreamInterface; @@ -17,7 +19,7 @@ */ public class ThrottlingValve extends TwoPortEquipment implements ValveInterface { private static final long serialVersionUID = 1000; - + static Logger logger = LogManager.getLogger(ThrottlingValve.class); SystemInterface thermoSystem; private boolean valveCvSet = false; @@ -28,6 +30,8 @@ public class ThrottlingValve extends TwoPortEquipment implements ValveInterface private double Cv; private double maxMolarFlow = 1000.0; private double minMolarFlow = 0.0; + private double maxValveOpening = 100.0; + private double minValveOpening = 0.0; private double percentValveOpening = 100.0; double molarFlow = 0.0; private String pressureUnit = "bara"; @@ -229,8 +233,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()); @@ -286,22 +294,21 @@ public void runTransient(double dt, UUID id) { * Math.sqrt( (inStream.getThermoSystem().getPressure() - outStream.getThermoSystem().getPressure()) / thermoSystem.getDensity()); - // System.out.println("molar flow " + molarFlow); - // System.out.println("Cv " + getCv()); - // System.out.println("density " + inletStream.getThermoSystem().getDensity()); - - // 8 } else { - // molarFlow=inletStream.getThermoSystem().getTotalNumberOfMoles(); - // } - - inStream.getThermoSystem().setTotalNumberOfMoles(molarFlow); - inStream.getThermoSystem().init(1); - inStream.run(id); - - outStream.getThermoSystem().setTotalNumberOfMoles(molarFlow); - outStream.getThermoSystem().init(1); - outStream.run(id); + try { + inStream.getThermoSystem().setTotalNumberOfMoles(molarFlow); + inStream.getThermoSystem().init(1); + // inStream.run(id); + } catch (Exception e) { + logger.error(e.getMessage()); + } + try { + outStream.getThermoSystem().setTotalNumberOfMoles(molarFlow); + outStream.getThermoSystem().init(1); + // outStream.run(id); + } catch (Exception e) { + logger.error(e.getMessage()); + } // System.out.println("delta p valve " + // (inletStream.getThermoSystem().getPressure() - // outStream.getThermoSystem().getPressure())); @@ -323,17 +330,21 @@ public void runController(double dt, UUID id) { if (hasController) { getController().runTransient(this.percentValveOpening, dt, id); this.percentValveOpening = getController().getResponse(); - if (this.percentValveOpening > 100) { - this.percentValveOpening = 100; + if (this.percentValveOpening > maxValveOpening) { + this.percentValveOpening = maxValveOpening; } - if (this.percentValveOpening < 0) { - this.percentValveOpening = 1e-10; + if (this.percentValveOpening < minValveOpening) { + this.percentValveOpening = minValveOpening; } // System.out.println("valve opening " + this.percentValveOpening + " %"); } setCalculationIdentifier(id); } + public void setMinimumValveOpening(double minopen) { + minValveOpening = minopen; + } + /** {@inheritDoc} */ @Override public double getCv() { diff --git a/src/main/java/neqsim/processSimulation/processSystem/ProcessSystem.java b/src/main/java/neqsim/processSimulation/processSystem/ProcessSystem.java index c32529e658..c63a5a38f9 100644 --- a/src/main/java/neqsim/processSimulation/processSystem/ProcessSystem.java +++ b/src/main/java/neqsim/processSimulation/processSystem/ProcessSystem.java @@ -33,7 +33,7 @@ public class ProcessSystem extends SimulationBaseClass { static Logger logger = LogManager.getLogger(ProcessSystem.class); transient Thread thisThread; - String[][] signalDB = new String[1000][100]; + String[][] signalDB = new String[10000][100]; private double surroundingTemperature = 288.15; private int timeStepNumber = 0; private ArrayList unitOperations = 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/processEquipment/separator/SeparatorTest.java b/src/test/java/neqsim/processSimulation/processEquipment/separator/SeparatorTest.java index 0e0c60f2c5..1cde491703 100644 --- a/src/test/java/neqsim/processSimulation/processEquipment/separator/SeparatorTest.java +++ b/src/test/java/neqsim/processSimulation/processEquipment/separator/SeparatorTest.java @@ -50,10 +50,10 @@ public void setUpBeforeClass() throws Exception { @Test public void testFlow() { LevelTransmitter lt = new LevelTransmitter("levelTransmitter", sep); - Assertions.assertEquals(0.05263157894736842, lt.getMeasuredValue(), 1e-12); + Assertions.assertEquals(0.5, lt.getMeasuredValue(), 1e-12); ((StreamInterface) processOps.getUnit("inlet stream")).setFlowRate(0.01, "MSm3/day"); processOps.run(); - Assertions.assertEquals(0.052631578947368494, lt.getMeasuredValue(), 1e-12); + Assertions.assertEquals(0.5, lt.getMeasuredValue(), 1e-12); Assertions.assertEquals(lt.getMeasuredValue() * 100, lt.getMeasuredPercentValue(), 1e-12); } diff --git a/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java index 32d6053ad2..f26409e3b4 100644 --- a/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java +++ b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java @@ -31,12 +31,10 @@ public void testGetName() { } @Test - void testGetTime() { - } + void testGetTime() {} @Test - void testGetTimeStep() { - } + void testGetTimeStep() {} private SystemInterface getTestSystem() { neqsim.thermo.system.SystemInterface testSystem = @@ -49,7 +47,7 @@ private SystemInterface getTestSystem() { return testSystem; } - // @Test + @Test public void testDynamicCalculation() { neqsim.thermo.system.SystemInterface testSystem = getTestSystem(); @@ -59,10 +57,13 @@ public void testDynamicCalculation() { ThrottlingValve valve1 = new ThrottlingValve("valve_1", stream1); valve1.setOutletPressure(5.0); - valve1.setPercentValveOpening(50); + valve1.setPercentValveOpening(40); Separator separator1 = new Separator("sep 1"); separator1.addStream(valve1.getOutletStream()); + separator1.setInternalDiameter(1.0); + separator1.setSeparatorLength(2.5); + separator1.setLiquidLevel(0.5); ThrottlingValve valve2 = new ThrottlingValve("valve_2", separator1.getLiquidOutStream()); valve2.setOutletPressure(1.0); @@ -71,6 +72,7 @@ public void testDynamicCalculation() { ThrottlingValve valve3 = new ThrottlingValve("valve_3", separator1.getGasOutStream()); valve3.setOutletPressure(1.0); valve3.setPercentValveOpening(50); + valve3.setMinimumValveOpening(1.0); VolumeFlowTransmitter flowTransmitter = new VolumeFlowTransmitter(stream1); flowTransmitter.setUnit("kg/hr"); @@ -80,8 +82,8 @@ public void testDynamicCalculation() { ControllerDeviceInterface flowController = new ControllerDeviceBaseClass(); flowController.setTransmitter(flowTransmitter); flowController.setReverseActing(true); - flowController.setControllerSetPoint(63.5); - flowController.setControllerParameters(0.1, 0.10, 0.0); + flowController.setControllerSetPoint(73.5); + flowController.setControllerParameters(0.4, 10.0, 0.0); p.add(stream1); p.add(valve1); @@ -90,20 +92,22 @@ public void testDynamicCalculation() { p.add(valve3); p.add(flowTransmitter); valve1.setController(flowController); + valve1.setCalculateSteadyState(false); p.run(); // transient behaviour p.setTimeStep(1.0); - for (int i = 0; i < 5; i++) { - // logger.info("volume flow " + flowTransmitter.getMeasuredValue() - // + " valve opening " + valve_1.getPercentValveOpening() + " pressure " - // + separator_1.getGasOutStream().getPressure()); + for (int i = 0; i < 50; i++) { + // 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()); } } + assertEquals(73.5, flowTransmitter.getMeasuredValue(), 1.0); } @Test @@ -111,49 +115,65 @@ 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("ethane", 0.10001); testSystem2.addComponent("n-heptane", 1.001); testSystem2.setMixingRule(2); - Stream purgeStream = new Stream("Purge Stream", testSystem2); - ThrottlingValve purgeValve = new ThrottlingValve("purgeValve", purgeStream); - purgeValve.setOutletPressure(7.0); - purgeValve.setPercentValveOpening(50.0); + 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.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"); - neqsim.thermo.system.SystemInterface testSystem = getTestSystem(); - Stream stream1 = new Stream("Stream1", testSystem); - stream1.setCalculateSteadyState(false); 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(purgeValve.getOutletStream()); - separator1.setCalculateSteadyState(true); + separator1.addStream(valvePurge.getOutletStream()); + separator1.setCalculateSteadyState(false); + separator1.setSeparatorLength(3.0); + separator1.setInternalDiameter(0.8); + separator1.setLiquidLevel(0.5); ThrottlingValve valve2 = new ThrottlingValve("valve_2", separator1.getLiquidOutStream()); - valve2.setOutletPressure(5.0); + valve2.setOutletPressure(1.0); valve2.setPercentValveOpening(50); - valve2.setCalculateSteadyState(true); - // valve_2.setCv(10.0); + valve2.setCalculateSteadyState(false); + valve2.setMinimumValveOpening(1.0); ThrottlingValve valve3 = new ThrottlingValve("valve_3", separator1.getGasOutStream()); - valve3.setOutletPressure(5.0); - valve3.setPercentValveOpening(50); - valve3.setCalculateSteadyState(true); - // valve_3.setCv(10.0); + valve3.setOutletPressure(1.0); + valve3.setPercentValveOpening(10); + valve3.setCalculateSteadyState(false); + valve3.setMinimumValveOpening(1.0); LevelTransmitter separatorLevelTransmitter = new LevelTransmitter(separator1); separatorLevelTransmitter.setName("separatorLevelTransmitter1"); - separatorLevelTransmitter.setMaximumValue(1.0); - separatorLevelTransmitter.setMinimumValue(0.0); + separatorLevelTransmitter.setMaximumValue(0.8); + separatorLevelTransmitter.setMinimumValue(0.2); ControllerDeviceInterface separatorLevelController = new ControllerDeviceBaseClass(); - separatorLevelController.setReverseActing(true); + separatorLevelController.setReverseActing(false); separatorLevelController.setTransmitter(separatorLevelTransmitter); - separatorLevelController.setControllerSetPoint(0.3); - separatorLevelController.setControllerParameters(1, 1000.0, 0.0); + separatorLevelController.setControllerSetPoint(0.45); + separatorLevelController.setControllerParameters(5.0, 5000.0, 0.0); PressureTransmitter separatorPressureTransmitter = new PressureTransmitter(separator1.getGasOutStream()); @@ -165,13 +185,12 @@ public void testDynamicCalculation2() { separatorPressureController.setTransmitter(separatorPressureTransmitter); separatorPressureController.setReverseActing(false); separatorPressureController.setControllerSetPoint(7.0); - separatorPressureController.setControllerParameters(0.5, 10.0, 0.0); + separatorPressureController.setControllerParameters(0.35, 0, 0.0); p.add(stream1); + p.add(streamPurge); p.add(valve1); - - p.add(purgeStream); - p.add(purgeValve); + p.add(valvePurge); p.add(separator1); p.add(valve2); p.add(valve3); @@ -189,26 +208,107 @@ public void testDynamicCalculation2() { } // p.displayResult(); - p.setTimeStep(0.01); - for (int i = 0; i < 500; i++) { - // logger.info("pressure "+separator_1.getGasOutStream().getPressure()+ " flow "+ - // separator_1.getGasOutStream().getFlowRate("kg/hr") + " sepr height - // "+separatorLevelTransmitter.getMeasuredValue()); + p.setTimeStep(50.0); + for (int i = 0; i < 200; 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()); p.runTransient(); for (SimulationInterface sim : p.getUnitOperations()) { assertEquals(p.getCalculationIdentifier(), sim.getCalculationIdentifier()); } } + assertEquals(0.45, separatorLevelTransmitter.getMeasuredValue(), 0.01); + } - valve1.setPercentValveOpening(60); + @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); - for (int i = 0; i < 10; i++) { - // logger.info("pressure "+separator_1.getGasOutStream().getPressure()+ " flow "+ - // separator_1.getGasOutStream().getFlowRate("kg/hr")); + 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); + valve3.setMinimumValveOpening(1.0); + + 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, 500.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(20.0); + for (int i = 0; i < 200; 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()); } } + assertEquals(5.0, separator1.getGasOutStream().getPressure(), 0.01); + } } 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); + } + +}