Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix mixer minimum pressure #1232

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ public void run(UUID id) {
iterations = 0;
}
setCalculationIdentifier(id);
firstTime = true;
}


Expand Down
13 changes: 8 additions & 5 deletions src/main/java/neqsim/process/equipment/mixer/Mixer.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Mixer extends ProcessEquipmentBaseClass implements MixerInterface {
protected StreamInterface mixedStream;
private boolean isSetOutTemperature = false;
private double outTemperature = Double.NaN;
double lowestPressure = Double.NEGATIVE_INFINITY;

/**
* <p>
Expand Down Expand Up @@ -106,13 +107,17 @@ public StreamInterface getStream(int i) {
public void mixStream() {
int index = 0;
String compName = new String();
double lowestPressure = mixedStream.getThermoSystem().getPhase(0).getPressure();
lowestPressure = mixedStream.getThermoSystem().getPhase(0).getPressure();
boolean hasAddedNewComponent = false;
for (int k = 1; k < streams.size(); k++) {
if (streams.get(k).getThermoSystem().getPhase(0).getPressure() < lowestPressure) {
lowestPressure = streams.get(k).getThermoSystem().getPhase(0).getPressure();
mixedStream.getThermoSystem().getPhase(0).setPressure(lowestPressure);
}
}
for (int k = 0; k < streams.size(); k++) {
// streams.get(k).getThermoSystem().getPhase(0).setPressure(lowestPressure);
}
for (int k = 1; k < streams.size(); k++) {
for (int i = 0; i < streams.get(k).getThermoSystem().getPhase(0)
.getNumberOfComponents(); i++) {
boolean gotComponent = false;
Expand Down Expand Up @@ -212,7 +217,7 @@ public void run(UUID id) {
mixedStream.getThermoSystem().init(0);

mixStream();

mixedStream.setPressure(lowestPressure);
enthalpy = calcMixStreamEnthalpy();
// System.out.println("temp guess " + guessTemperature());
if (isSetOutTemperature) {
Expand Down Expand Up @@ -244,13 +249,11 @@ public void run(UUID id) {
mixedStream.getThermoSystem().init(2);
}


// System.out.println("enthalpy: " +
// mixedStream.getThermoSystem().getEnthalpy())
// System.out.println("enthalpy: " + en
// System.out.println("temperature: " +


// System.out.println("beta " + mixedStream.getThermoSystem(
// outStream.setThermoSystem(mixedStream.getThermoSystem());
setCalculationIdentifier(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import neqsim.process.equipment.expander.Expander;
import neqsim.process.equipment.separator.Separator;
import neqsim.process.equipment.stream.Stream;
import neqsim.process.equipment.util.Recycle;
import neqsim.process.equipment.valve.ThrottlingValve;
import neqsim.thermodynamicoperations.ThermodynamicOperations;

public class MultiStreamHeatExchangerTest {
Expand Down Expand Up @@ -72,6 +76,95 @@ void testRun1() {

}

@Test
void testRun2() {

neqsim.process.processmodel.ProcessSystem operations =
new neqsim.process.processmodel.ProcessSystem();

Stream feed_stream = new Stream("Stream1", testSystem);
feed_stream.setTemperature(30.0, "C");
feed_stream.setPressure(75.0, "bara");
feed_stream.setFlowRate(1000.0, "kg/hr");
feed_stream.run();
operations.add(feed_stream);

Separator separator = new Separator("sep 1", feed_stream);
operations.add(separator);

Stream stream_Cold = new Stream("Stream2", testSystem.clone());
stream_Cold.setTemperature(-5.0, "C");
stream_Cold.setPressure(50.0, "bara");
stream_Cold.setFlowRate(310.0, "kg/hr");
stream_Cold.run();
operations.add(stream_Cold);

Stream stream_Cold2 = new Stream("Stream3", testSystem.clone());
stream_Cold2.setTemperature(-5.0, "C");
stream_Cold2.setPressure(50.0, "bara");
stream_Cold2.setFlowRate(50.0, "kg/hr");
stream_Cold2.run();
operations.add(stream_Cold2);

MultiStreamHeatExchanger heatEx = new MultiStreamHeatExchanger("heatEx");
heatEx.addInStream(separator.getGasOutStream());
heatEx.addInStream(stream_Cold);
heatEx.addInStream(stream_Cold2);
// heatEx.setUAvalue(1000);
heatEx.setTemperatureApproach(5);
heatEx.run();
operations.add(heatEx);

Separator dewseparator = new Separator("sep 2", heatEx.getOutStream(0));
dewseparator.run();
operations.add(dewseparator);


Expander expander = new Expander("expander", dewseparator.getGasOutStream());
expander.setOutletPressure(50., "bara");
expander.run();
operations.add(expander);

ThrottlingValve jt_valve = new ThrottlingValve("JT valve", dewseparator.getLiquidOutStream());
jt_valve.setOutletPressure(50.0, "bara");
jt_valve.run();
operations.add(jt_valve);

Separator separator2 = new Separator("sep 3", expander.getOutletStream());
separator2.addStream(jt_valve.getOutletStream());
separator2.run();
operations.add(separator2);

Recycle gas_expander_resycle = new neqsim.process.equipment.util.Recycle("gas recycl");
gas_expander_resycle.addStream(separator2.getGasOutStream());
gas_expander_resycle.setOutletStream(stream_Cold);
gas_expander_resycle.setTolerance(1e-3);
gas_expander_resycle.run();
operations.add(gas_expander_resycle);

Recycle liq_expander_resycle = new neqsim.process.equipment.util.Recycle("liq recycl");
liq_expander_resycle.addStream(separator2.getLiquidOutStream());
liq_expander_resycle.setOutletStream(stream_Cold2);
liq_expander_resycle.setTolerance(1e-3);
liq_expander_resycle.run();
operations.add(liq_expander_resycle);

operations.run();

separator2.getFluid().prettyPrint();
heatEx.getOutStream(0).getFluid().prettyPrint();

assertEquals(-34.6818572, separator2.getFluid().getTemperature("C"), 1e-3);
assertEquals(25.0, heatEx.getOutStream(1).getTemperature("C"), 1e-3);

heatEx.setUAvalue(5000);
operations.run();

assertEquals(-26.931795168, separator2.getFluid().getTemperature("C"), 1e-3);
assertEquals(17.37650429489, heatEx.getOutStream(1).getTemperature("C"), 1e-3);

}



}
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/neqsim/process/equipment/mixer/MixerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import neqsim.process.equipment.stream.Stream;
import neqsim.process.equipment.stream.StreamInterface;
import neqsim.process.processmodel.ProcessSystem;
import neqsim.thermo.system.SystemSrkEos;

Expand Down Expand Up @@ -81,4 +82,30 @@ void testNeedRecalculation() {
processOps.run();
assertFalse(gasStream.needRecalculation());
}

/**
* Test method for {@link neqsim.process.equipment.mixer.Mixer#run()}.
*/
@Test
void testRunDifferentPressures() {
StreamInterface gasStream2 = (StreamInterface) gasStream.clone();
StreamInterface waterStream2 = (StreamInterface) waterStream.clone();

gasStream2.setPressure(10.0, "bara");
waterStream2.setPressure(30.0, "bara");

gasStream2.run();
waterStream2.run();

double totalEnthalpy =
gasStream2.getFluid().getEnthalpy("J") + waterStream2.getFluid().getEnthalpy("J");

Mixer testMixer = new Mixer("test mixer");
testMixer.addStream(waterStream2);
testMixer.addStream(gasStream2);
testMixer.run();

assertEquals(totalEnthalpy, testMixer.getOutletStream().getFluid().getEnthalpy("J"), 1e-1);
assertEquals(10.0, testMixer.getOutletStream().getPressure("bara"), 1e-1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void testProcess2() {
dewPointControlCooler2.setOutTemperature(-15.0, "C");
dewPointControlCooler2.setOutPressure(59.5, "bara");
dewPointControlCooler2.run();
Assertions.assertEquals(0.967383748675644,
Assertions.assertEquals(0.96737504327,
dewPointControlCooler2.getOutStream().getFluid().getBeta(), 1e-6);
Separator dewPointScrubber2 = new neqsim.process.equipment.separator.Separator(
"dew point scrubber 2", dewPointControlCooler2.getOutStream());
Expand Down
Loading