Skip to content

Commit

Permalink
1063 add delta t specification for heat exchangers (#1071)
Browse files Browse the repository at this point in the history
* first version

* update delta T with HX

* update delta T HX
  • Loading branch information
EvenSol authored Aug 4, 2024
1 parent 60de720 commit 7612ec4
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* <p>
Expand Down Expand Up @@ -259,16 +261,111 @@ public void runSpecifiedStream(UUID id) {
outStream[nonOutStreamSpecifiedStreamNumber].setFluid(systemOut0);
}

/**
* <p>
* runSpecifiedStream.
* </p>
*
* @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 {
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -438,6 +530,19 @@ public double getGuessOutTemperature() {
*/
public void setGuessOutTemperature(double guessOutTemperature) {
this.guessOutTemperature = guessOutTemperature;
this.guessOutTemperatureUnit = "K";
}

/**
* <p>
* Setter for the field <code>guessOutTemperature</code>.
* </p>
*
* @param guessOutTemperature a double
*/
public void setGuessOutTemperature(double guessOutTemperature, String unit) {
this.guessOutTemperature = guessOutTemperature;
this.guessOutTemperatureUnit = unit;
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -635,4 +740,21 @@ public String toJson() {
return new GsonBuilder().serializeSpecialFloatingPointValues().create()
.toJson(new HXResponse(this));
}


public void setUseDeltaT(boolean useDeltaT) {
this.useDeltaT = useDeltaT;
}

private double deltaT = 1.0;

public double getDeltaT() {
return deltaT;
}

public void setDeltaT(double deltaT) {
useDeltaT = true;
this.deltaT = deltaT;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package neqsim.processSimulation.processEquipment.heatExchanger;

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import neqsim.processSimulation.processEquipment.separator.Separator;
Expand Down Expand Up @@ -36,11 +37,17 @@ void setUp() {
@Test
void testRun1() {
Stream stream_Hot = new Stream("Stream1", testSystem);
stream_Hot.setTemperature(100.0, "C");
stream_Hot.setFlowRate(1000.0, "kg/hr");
Stream stream_Cold = new Stream("Stream2", testSystem.clone());
stream_Cold.setTemperature(20.0, "C");
stream_Cold.setFlowRate(310.0, "kg/hr");

HeatExchanger heatEx = new HeatExchanger("heatEx");
heatEx.setFeedStream(0, stream_Hot);
heatEx.setFeedStream(1, stream_Cold); // resyc.getOutStream());
HeatExchanger heatEx = new HeatExchanger("heatEx", stream_Hot, stream_Cold);
// heatEx.setFeedStream(0, stream_Hot);
// heatEx.setFeedStream(1, stream_Cold); // resyc.getOutStream());
heatEx.setGuessOutTemperature(80.0, "C");
heatEx.setUAvalue(1000);

Separator sep = new Separator("sep", stream_Hot);

Expand All @@ -56,14 +63,14 @@ void testRun1() {
neqsim.processSimulation.processSystem.ProcessSystem operations =
new neqsim.processSimulation.processSystem.ProcessSystem();
operations.add(stream_Hot);
operations.add(stream_Cold);
operations.add(heatEx);
operations.add(sep);
operations.add(oilOutStream);
operations.add(valv1);
operations.add(resyc);

operations.run();

// heatEx.getOutStream(0).displayResult();
// resyc.getOutStream().displayResult();
}
Expand Down Expand Up @@ -94,8 +101,19 @@ void testRun2() {
operations.add(heatExchanger1);

operations.run();
// operations.displayResult();
// heatExchanger1.getOutStream(0).displayResult();
// heatExchanger1.getOutStream(1).displayResult();
assertEquals(heatExchanger1.getDuty(), -9674.051890272862, 1e-1);

heatExchanger1.setDeltaT(1.0);
heatExchanger1.run();

assertEquals(15780.77130, heatExchanger1.getUAvalue(), 1e-3);

heatExchanger1 = new neqsim.processSimulation.processEquipment.heatExchanger.HeatExchanger(
"heatEx", stream_Hot, stream_Cold);
heatExchanger1.setDeltaT(1.0);
heatExchanger1.run();

assertEquals(15780.77130, heatExchanger1.getUAvalue(), 1e-3);

}
}

0 comments on commit 7612ec4

Please sign in to comment.