diff --git a/src/main/java/neqsim/processSimulation/processEquipment/separator/Separator.java b/src/main/java/neqsim/processSimulation/processEquipment/separator/Separator.java index a7c0ee96f8..4c60841528 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/separator/Separator.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/separator/Separator.java @@ -312,17 +312,23 @@ public void runTransient(double dt, UUID id) { if (getCalculateSteadyState()) { run(id); increaseTime(dt); + setCalculationIdentifier(id); return; } else { inletStreamMixer.run(id); thermoSystem.init(3); thermoSystem.initPhysicalProperties("density"); - gasOutStream.getThermoSystem().init(3); - liquidOutStream.getThermoSystem().init(3); + try { + gasOutStream.getThermoSystem().init(3); + liquidOutStream.getThermoSystem().init(3); + } catch (Exception e) { + logger.error(e.getMessage()); + } double deltaEnergy = inletStreamMixer.getOutletStream().getThermoSystem().getEnthalpy() - gasOutStream.getThermoSystem().getEnthalpy() - liquidOutStream.getThermoSystem().getEnthalpy(); double newEnergy = thermoSystem.getInternalEnergy() + dt * deltaEnergy; + thermoSystem.init(0); for (int i = 0; i < thermoSystem.getPhase(0).getNumberOfComponents(); i++) { double dncomp = 0.0; for (int j = 0; j < inletStreamMixer.getOutletStream().getFluid() @@ -336,8 +342,19 @@ public void runTransient(double dt, UUID id) { } ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem); thermoOps.VUflash(gasVolume + liquidVolume, newEnergy, "m3", "J"); - setTempPres(thermoSystem.getTemperature(), thermoSystem.getPressure()); thermoSystem.initPhysicalProperties("density"); + + if (thermoSystem.hasPhaseType("gas")) { + gasOutStream.getFluid().setMolarComposition(thermoSystem.getPhase(0).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 = 0.0; if (thermoSystem.hasPhaseType("oil") || thermoSystem.hasPhaseType("aqueous")) { double volumeLoc = 0.0; @@ -353,18 +370,8 @@ public void runTransient(double dt, UUID id) { * getSeparatorLength(); gasVolume = (1.0 - getLiquidLevel()) * 3.14 / 4.0 * getInternalDiameter() * getInternalDiameter() * getSeparatorLength(); + // System.out.println("gas volume " + gasVolume + " liq volime " + liquidVolume); setCalculationIdentifier(id); - - if (thermoSystem.hasPhaseType("gas")) { - gasOutStream.setPressure(thermoSystem.getPressure("bara"), "bara"); - gasOutStream.setTemperature(thermoSystem.getTemperature("C"), "C"); - } - if (thermoSystem.hasPhaseType("oil") || thermoSystem.hasPhaseType("aqueous")) { - liquidOutStream.setPressure(thermoSystem.getPressure("bara"), "bara"); - liquidOutStream.setTemperature(thermoSystem.getTemperature("C"), "C"); - } - gasOutStream.run(); - liquidOutStream.run(); return; } } diff --git a/src/main/java/neqsim/processSimulation/processEquipment/valve/ThrottlingValve.java b/src/main/java/neqsim/processSimulation/processEquipment/valve/ThrottlingValve.java index 6fd0fae3bc..2e2374edee 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; @@ -274,7 +276,7 @@ public void runTransient(double dt, UUID id) { double enthalpy = thermoSystem.getEnthalpy(); thermoSystem.setPressure(getOutletStream().getThermoSystem().getPressure()); // System.out.println("enthalpy inn.." + enthalpy); - if (isIsoThermal()) { + if (isIsoThermal() || thermoSystem.getTotalNumberOfMoles() < 0.0001) { thermoOps.TPflash(); } else { thermoOps.PHflash(enthalpy, 0); @@ -294,14 +296,19 @@ public void runTransient(double dt, UUID id) { // 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); - + if (molarFlow > 1e-4) { + try { + inStream.getThermoSystem().setTotalNumberOfMoles(molarFlow); + inStream.getThermoSystem().init(1); + inStream.run(id); + + 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())); diff --git a/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java index 304bd0557b..4d04363088 100644 --- a/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java +++ b/src/test/java/neqsim/processSimulation/processSystem/ProcessSystemRunTransientTest.java @@ -61,6 +61,9 @@ public void testDynamicCalculation() { 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); @@ -79,7 +82,7 @@ public void testDynamicCalculation() { flowController.setTransmitter(flowTransmitter); flowController.setReverseActing(true); flowController.setControllerSetPoint(63.5); - flowController.setControllerParameters(1.2, 100.0, 0.0); + flowController.setControllerParameters(0.4, 10.0, 0.0); p.add(stream1); p.add(valve1); @@ -120,7 +123,7 @@ public void testDynamicCalculation2() { testSystem3.setMixingRule(2); Stream stream1 = new Stream("Stream1", testSystem2); - stream1.setFlowRate(1000.0, "kg/hr"); + stream1.setFlowRate(100.0, "kg/hr"); stream1.setPressure(10.0, "bara"); stream1.setTemperature(25.0, "C"); @@ -149,7 +152,7 @@ public void testDynamicCalculation2() { ThrottlingValve valve2 = new ThrottlingValve("valve_2", separator1.getLiquidOutStream()); valve2.setOutletPressure(1.0); - valve2.setPercentValveOpening(50); + valve2.setPercentValveOpening(25); valve2.setCalculateSteadyState(false); ThrottlingValve valve3 = new ThrottlingValve("valve_3", separator1.getGasOutStream()); @@ -166,7 +169,7 @@ public void testDynamicCalculation2() { separatorLevelController.setReverseActing(false); separatorLevelController.setTransmitter(separatorLevelTransmitter); separatorLevelController.setControllerSetPoint(0.45); - separatorLevelController.setControllerParameters(0.0510, 200.0, 0.0); + separatorLevelController.setControllerParameters(1.0, 0.0, 0.0); PressureTransmitter separatorPressureTransmitter = new PressureTransmitter(separator1.getGasOutStream()); @@ -178,7 +181,7 @@ public void testDynamicCalculation2() { separatorPressureController.setTransmitter(separatorPressureTransmitter); separatorPressureController.setReverseActing(false); separatorPressureController.setControllerSetPoint(7.0); - separatorPressureController.setControllerParameters(0.05, 0.0, 0.0); + separatorPressureController.setControllerParameters(0.1, 50.0, 0.0); p.add(stream1); p.add(streamPurge); @@ -202,7 +205,7 @@ public void testDynamicCalculation2() { // p.displayResult(); p.setTimeStep(1.0); - for (int i = 0; i < 900; i++) { + for (int i = 0; i < 100; i++) { System.out.println("pressure " + separator1.getGasOutStream().getPressure() + " flow " + separator1.getGasOutStream().getFlowRate("kg/hr") + " sepr height " + separatorLevelTransmitter.getMeasuredValue() + "valve2 opening "