diff --git a/src/main/java/neqsim/processSimulation/processEquipment/heatExchanger/HeatExchanger.java b/src/main/java/neqsim/processSimulation/processEquipment/heatExchanger/HeatExchanger.java index 32a863044b..4eb831a699 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/heatExchanger/HeatExchanger.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/heatExchanger/HeatExchanger.java @@ -42,9 +42,11 @@ public class HeatExchanger extends Heater implements HeatExchangerInterface { private double hotColdDutyBalance = 1.0; boolean firstTime = true; public double guessOutTemperature = 273.15 + 130.0; + public String guessOutTemperatureUnit = "K"; int outStreamSpecificationNumber = 0; public double thermalEffectiveness = 0.0; private String flowArrangement = "concentric tube counterflow"; + private boolean useDeltaT = false; /** *
@@ -259,16 +261,111 @@ public void runSpecifiedStream(UUID id) { outStream[nonOutStreamSpecifiedStreamNumber].setFluid(systemOut0); } + /** + *
+ * runSpecifiedStream. + *
+ * + * @param id UUID of run + */ + public void runDeltaT(UUID id) { + + if (getSpecification().equals("out stream")) { + runSpecifiedStream(id); + } else if (firstTime) { + firstTime = false; + SystemInterface systemOut0 = inStream[0].getThermoSystem().clone(); + outStream[0].setThermoSystem(systemOut0); + outStream[0].getThermoSystem().setTemperature(guessOutTemperature, guessOutTemperatureUnit); + outStream[0].run(id); + run(id); + } else { + int streamToCalculate = 0; + + for (StreamInterface stream : inStream) { + stream.run(); + } + + int streamToSet = 1; + SystemInterface systemOut0 = inStream[streamToSet].getThermoSystem().clone(); + SystemInterface systemOut1 = inStream[streamToCalculate].getThermoSystem().clone(); + double sign = Math.signum( + inStream[streamToCalculate].getTemperature() - inStream[streamToSet].getTemperature()); + // systemOut1.setTemperature(inTemp1); + outStream[streamToSet].setThermoSystem(systemOut0); + outStream[streamToCalculate].setThermoSystem(systemOut1); + outStream[streamToSet] + .setTemperature(inStream[streamToCalculate].getTemperature() + sign * deltaT, "K"); + if (!outStream[streamToSet].getSpecification().equals("TP")) { + outStream[streamToSet].runTPflash(); + } + outStream[streamToSet].run(id); + double dEntalphy1 = outStream[streamToSet].getThermoSystem().getEnthalpy() + - inStream[streamToSet].getThermoSystem().getEnthalpy(); + double C1 = + Math.abs(dEntalphy1) / Math.abs((outStream[streamToSet].getThermoSystem().getTemperature() + - inStream[streamToSet].getThermoSystem().getTemperature())); + + outStream[streamToCalculate].setTemperature( + inStream[streamToSet].getThermoSystem().getTemperature() - sign * deltaT, "K"); + if (!outStream[streamToCalculate].getSpecification().equals("TP")) { + outStream[streamToCalculate].runTPflash(); + } + outStream[streamToCalculate].run(id); + double dEntalphy2 = outStream[streamToCalculate].getThermoSystem().getEnthalpy() + - inStream[streamToCalculate].getThermoSystem().getEnthalpy(); + double C2 = Math.abs(dEntalphy2) + / Math.abs(outStream[streamToCalculate].getThermoSystem().getTemperature() + - inStream[streamToCalculate].getThermoSystem().getTemperature()); + double Cmin = C1; + double Cmax = C2; + if (C2 < C1) { + Cmin = C2; + Cmax = C1; + } + double Cr = Cmin / Cmax; + if (Math.abs(dEntalphy1) < Math.abs(dEntalphy2)) { + int streamCHange = streamToCalculate; + streamToCalculate = streamToSet; + streamToSet = streamCHange; + } + + double dEntalphy = outStream[streamToSet].getThermoSystem().getEnthalpy() + - inStream[streamToSet].getThermoSystem().getEnthalpy(); + // System.out.println("dent " + dEntalphy); + ThermodynamicOperations testOps = + new ThermodynamicOperations(outStream[streamToCalculate].getThermoSystem()); + testOps.PHflash(inStream[streamToCalculate].getThermoSystem().getEnthalpy() - dEntalphy, 0); + + if (Math.abs(thermalEffectiveness - 1.0) > 1e-10) { + testOps = new ThermodynamicOperations(outStream[streamToSet].getThermoSystem()); + testOps.PHflash(inStream[streamToSet].getThermoSystem().getEnthalpy() + dEntalphy, 0); + } + duty = dEntalphy; + hotColdDutyBalance = 1.0; + + UAvalue = dEntalphy / (outStream[streamToSet].getThermoSystem().getTemperature() + - inStream[streamToSet].getThermoSystem().getTemperature()); + } + + setCalculationIdentifier(id); + + } + /** {@inheritDoc} */ @Override public void run(UUID id) { + if (useDeltaT) { + runDeltaT(id); + return; + } if (getSpecification().equals("out stream")) { runSpecifiedStream(id); } else if (firstTime) { firstTime = false; SystemInterface systemOut0 = inStream[0].getThermoSystem().clone(); outStream[0].setThermoSystem(systemOut0); - outStream[0].getThermoSystem().setTemperature(guessOutTemperature); + outStream[0].getThermoSystem().setTemperature(guessOutTemperature, guessOutTemperatureUnit); outStream[0].run(id); run(id); } else { @@ -294,10 +391,7 @@ public void run(UUID id) { // systemOut1.setTemperature(inTemp1); outStream[streamToSet].setThermoSystem(systemOut0); outStream[streamToCalculate].setThermoSystem(systemOut1); - outStream[streamToSet] - .setTemperature(inStream[streamToCalculate].getThermoSystem().getTemperature(), "K"); - outStream[streamToSet].getThermoSystem() - .setTemperature(inStream[streamToCalculate].getThermoSystem().getTemperature()); + outStream[streamToSet].setTemperature(inStream[streamToCalculate].getTemperature(), "K"); if (!outStream[streamToSet].getSpecification().equals("TP")) { outStream[streamToSet].runTPflash(); } @@ -310,8 +404,6 @@ public void run(UUID id) { outStream[streamToCalculate] .setTemperature(inStream[streamToSet].getThermoSystem().getTemperature(), "K"); - outStream[streamToCalculate].getThermoSystem() - .setTemperature(inStream[streamToSet].getThermoSystem().getTemperature()); if (!outStream[streamToCalculate].getSpecification().equals("TP")) { outStream[streamToCalculate].runTPflash(); } @@ -438,6 +530,19 @@ public double getGuessOutTemperature() { */ public void setGuessOutTemperature(double guessOutTemperature) { this.guessOutTemperature = guessOutTemperature; + this.guessOutTemperatureUnit = "K"; + } + + /** + *
+ * Setter for the field guessOutTemperature
.
+ *