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

Bug dehydration glycol column test and bug fixes #782

Merged
merged 7 commits into from
Jul 25, 2023
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
2 changes: 1 addition & 1 deletion src/main/java/neqsim/log4j2.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name = PropertiesConfig
filters = threshold

filter.threshold.type = ThresholdFilter
filter.threshold.level = debug
filter.threshold.level = DEBUG

appenders = console

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import java.util.ArrayList;
import java.util.Objects;
import java.util.UUID;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import neqsim.processSimulation.processEquipment.ProcessEquipmentBaseClass;
import neqsim.processSimulation.processEquipment.heatExchanger.Heater;
import neqsim.processSimulation.processEquipment.mixer.Mixer;
Expand Down Expand Up @@ -38,6 +36,7 @@ public class DistillationColumn extends ProcessEquipmentBaseClass implements Dis
double topTrayPressure = -1.0;
double bottomTrayPressure = -1.0;
int numberOfTrays = 1;
int maxNumberOfIterations = 10;
private int feedTrayNumber = 1;
StreamInterface stream_3 = new Stream("stream_3");
StreamInterface gasOutStream = new Stream("gasOutStream");
Expand All @@ -48,6 +47,7 @@ public class DistillationColumn extends ProcessEquipmentBaseClass implements Dis
neqsim.processSimulation.processSystem.ProcessSystem distoperations;
Heater heater;
Separator separator2;
private double err = 1.0e10;

/**
* <p>
Expand Down Expand Up @@ -157,7 +157,8 @@ public void init() {
((MixerInterface) trays.get(numberOfTrays - 1)).getThermoSystem().getTemperature();
reboilerTemperature = ((MixerInterface) trays.get(0)).getThermoSystem().getTemperature();

// double deltaTemp = (reboilerTemperature - condenserTemperature) / (numberOfTrays * 1.0);
// double deltaTemp = (reboilerTemperature - condenserTemperature) /
// (numberOfTrays * 1.0);
double feedTrayTemperature = getTray(getFeedTrayNumber()).getThermoSystem().getTemperature();

double deltaTempCondenser =
Expand Down Expand Up @@ -324,7 +325,7 @@ public void run(UUID id) {
if (isDoInitializion()) {
this.init();
}
double err = 1.0e10;
err = 1.0e10;
double errOld;
int iter = 0;
double[] oldtemps = new double[numberOfTrays];
Expand Down Expand Up @@ -358,7 +359,7 @@ public void run(UUID id) {
((SimpleTray) trays.get(i)).run(id);
}

for (int i = numberOfTrays - 2; i == feedTrayNumber; i--) {
for (int i = numberOfTrays - 2; i >= feedTrayNumber; i--) {
int replaceStream = trays.get(i).getNumberOfInputStreams() - 1;
((Mixer) trays.get(i)).replaceStream(replaceStream,
trays.get(i + 1).getLiquidOutStream());
Expand All @@ -369,10 +370,12 @@ public void run(UUID id) {
oldtemps[i] - ((MixerInterface) trays.get(i)).getThermoSystem().getTemperature());
}
logger.info("error iter " + err + " iteration " + iter);
// System.out.println("error iter " + err + " iteration " + iter);
// massBalanceCheck();
} while (err > 1e-4 && err < errOld && iter < 10); // && !massBalanceCheck());

} while (err > 1e-4 && err < errOld && iter < maxNumberOfIterations); // &&
// !massBalanceCheck());
// massBalanceCheck();
// componentMassBalanceCheck("water");
gasOutStream.setThermoSystem(
trays.get(numberOfTrays - 1).getGasOutStream().getThermoSystem().clone());
gasOutStream.setCalculationIdentifier(id);
Expand All @@ -393,6 +396,69 @@ public void displayResult() {
distoperations.displayResult();
}

/**
* <p>
* component componentMassBalanceCheck.
* </p>
*
* @return a boolean
*/
public boolean componentMassBalanceCheck(String componentName) {
double[] massInput = new double[numberOfTrays];
double[] massOutput = new double[numberOfTrays];
double[] massBalance = new double[numberOfTrays];
double[] massFeedInput = new double[numberOfTrays];
for (int i = 0; i < numberOfTrays; i++) {
int numberOfInputStreams = trays.get(i).getNumberOfInputStreams() - 2;
if (i == 0 || i == numberOfTrays - 1) {
numberOfInputStreams = trays.get(i).getNumberOfInputStreams() - 1;
}

for (int j = 0; j < numberOfInputStreams; j++) {
for (int k = 0; k < trays.get(i).getStream(j).getFluid().getNumberOfPhases(); k++) {
massFeedInput[i] += trays.get(i).getStream(j).getFluid().getPhase(k)
.getComponent(componentName).getFlowRate("kg/hr");
}
}

}

for (int i = 0; i < numberOfTrays; i++) {
int numberOfInputStreams = trays.get(i).getNumberOfInputStreams();
for (int j = 0; j < numberOfInputStreams; j++) {
for (int k = 0; k < trays.get(i).getStream(j).getFluid().getNumberOfPhases(); k++) {
massInput[i] += trays.get(i).getStream(j).getFluid().getPhase(k)
.getComponent(componentName).getFlowRate("kg/hr");
}
}
massOutput[i] += trays.get(i).getGasOutStream().getFluid().getComponent(componentName)
.getFlowRate("kg/hr");
massOutput[i] += trays.get(i).getLiquidOutStream().getFluid().getComponent(componentName)
.getFlowRate("kg/hr");
massBalance[i] = massInput[i] - massOutput[i];

System.out.println("component " + componentName + " tray " + i + " number of input streams "
+ numberOfInputStreams + " massinput " + massInput[i] + " massoutput " + massOutput[i]
+ " massbalance " + massBalance[i] + " gasout "
+ trays.get(i).getGasOutStream().getFluid().getComponent("water").getFlowRate("kg/hr")
+ " liquidout "
+ trays.get(i).getLiquidOutStream().getFluid().getComponent("water").getFlowRate("kg/hr")
+ " pressure " + trays.get(i).getGasOutStream().getPressure() + " temperature "
+ trays.get(i).getGasOutStream().getTemperature("C") + " feedtotray " + massFeedInput[i]);

}

double massError = 0.0;
for (int i = 0; i < numberOfTrays; i++) {
massError += Math.abs(massBalance[i]);
}
if (massError > 1e-6) {
return false;
} else {
return true;
}
}

/**
* <p>
* massBalanceCheck.
Expand All @@ -405,7 +471,8 @@ public boolean massBalanceCheck() {
double[] massOutput = new double[numberOfTrays];
double[] massBalance = new double[numberOfTrays];
// System.out.println("water in feed "
// + feedStream.getFluid().getPhase(0).getComponent("water").getNumberOfmoles());
// +
// feedStream.getFluid().getPhase(0).getComponent("water").getNumberOfmoles());
// System.out.println("water in strip gas feed " +
// trays.get(0).getStream(0).getFluid().getPhase(0)
// .getComponent("water").getNumberOfmoles());
Expand All @@ -429,7 +496,7 @@ public boolean massBalanceCheck() {
* " water in gasout " +
* trays.get(i).getGasOutStream().getFluid().getPhase(0).getComponent("water")
* .getNumberOfmoles() + " water in liquidout " +
* trays.get(i).getLiquidOutStream().getFluid().getPhase(0).getComponent("water")
* trays.get(i).getLiquidOutStream().getFluid().getPhase(0).getComponent( "water")
* .getNumberOfmoles() + " pressure " + trays.get(i).getGasOutStream().getPressure() +
* " temperature " + trays.get(i).getGasOutStream().getTemperature("C"));
*/
Expand Down Expand Up @@ -651,6 +718,28 @@ public double getInternalDiameter() {
return internalDiameter;
}

/**
* <p>
* Getter for the field <code>solved</code>.
* </p>
*
* @return a boolean
*/
public boolean solved() {
return (err < 1e-4);
}

/**
* <p>
* Setter for the field <code>maxNumberOfIterations</code>.
* </p>
*
* @param maxIter a double
*/
public void setMaxNumberOfIterations(int maxIter) {
this.maxNumberOfIterations = maxIter;
}

/**
* <p>
* Setter for the field <code>internalDiameter</code>.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package neqsim.processSimulation.processEquipment.distillation;

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import neqsim.processSimulation.processEquipment.stream.Stream;

public class DistillationColumnTest {

/**
* @throws java.lang.Exception
*/
@BeforeEach

@Test
public void DistillationColumnTest() throws Exception {

neqsim.thermo.system.SystemInterface richTEG =
new neqsim.thermo.system.SystemSrkCPAstatoil(273.15 + 42.0, 10.00);
richTEG.addComponent("nitrogen", 0.0003884521907420086);
richTEG.addComponent("CO2", 0.3992611934362681);
richTEG.addComponent("methane", 0.1707852619527612);
richTEG.addComponent("ethane", 0.20533172990208282);
richTEG.addComponent("propane", 0.28448628224749795);
richTEG.addComponent("i-butane", 0.04538593257021818);
richTEG.addComponent("n-butane", 0.0001078982825);
richTEG.addComponent("i-pentane", 0.0008015009931573362);
richTEG.addComponent("n-pentane", 0.00007597175884128077);
richTEG.addComponent("n-hexane", 0.0000735238469338);
richTEG.addComponent("n-heptane", 0.0);
richTEG.addComponent("nC8", 0.0);
richTEG.addComponent("nC9", 0.0);
richTEG.addComponent("benzene", 0.001);
richTEG.addComponent("water", 9.281170624865437);
richTEG.addComponent("TEG", 88.61393191277175);
richTEG.setMixingRule(10);
richTEG.setMultiPhaseCheck(false);
richTEG.init(0);

neqsim.thermo.system.SystemInterface gasToReboiler =
new neqsim.thermo.system.SystemSrkCPAstatoil(273.15 + 42.0, 10.00);
gasToReboiler.addComponent("nitrogen", 0.007104922868929818);
gasToReboiler.addComponent("CO2", 4.944830745821265);
gasToReboiler.addComponent("methane", 3.013439464714221);
gasToReboiler.addComponent("ethane", 3.1119159322353815);
gasToReboiler.addComponent("propane", 4.001381171330917);
gasToReboiler.addComponent("i-butane", 0.6934008192075206);
gasToReboiler.addComponent("n-butane", 0.684816349773283);
gasToReboiler.addComponent("i-pentane", 0.24185783393270);
gasToReboiler.addComponent("n-pentane", 0.0032322868124);
gasToReboiler.addComponent("n-hexane", 0.0002651);
gasToReboiler.addComponent("n-heptane", 0.0);
gasToReboiler.addComponent("nC8", 0.0);
gasToReboiler.addComponent("nC9", 0.0);
gasToReboiler.addComponent("benzene", 0.000);
gasToReboiler.addComponent("water", 63.419578687948665);
gasToReboiler.addComponent("TEG", 4.293253985703371);
gasToReboiler.setMixingRule(10);
gasToReboiler.setMultiPhaseCheck(false);
gasToReboiler.init(0);

Stream richTEGStream = new Stream("richTEGS", richTEG);
richTEGStream.setFlowRate(9400.0, "kg/hr");
richTEGStream.setTemperature(100, "C");
richTEGStream.setPressure(1.12, "bara");
richTEGStream.run();

Stream gasToReboilerStream = new Stream("gasToReboilerS", gasToReboiler);
gasToReboilerStream.setFlowRate(290, "kg/hr");
gasToReboilerStream.setTemperature(200, "C");
gasToReboilerStream.setPressure(1.12, "bara");
gasToReboilerStream.run();

DistillationColumn column = new DistillationColumn(1, true, true);
column.setName("TEG regeneration column");
column.addFeedStream(richTEGStream, 1);
column.getReboiler().setOutTemperature(273.15 + 202);
// column.getCondenser().setOutTemperature(273.15 + 95);
column.getCondenser().setHeatInput(-30000.0);
column.getTray(1).addStream(gasToReboilerStream);
column.setTopPressure(1.12);
column.setBottomPressure(1.12);
column.setInternalDiameter(0.56);
// while (!column.solved()) {
column.run();
// }

double waterFlowRateInColumn =
richTEGStream.getFluid().getPhase(0).getComponent("water").getFlowRate("kg/hr")
+ richTEGStream.getFluid().getPhase(1).getComponent("water").getFlowRate("kg/hr");
double waterFlowRateInColumn2 = richTEGStream.getFluid().getComponent("water").getMolarMass()
* richTEGStream.getFluid().getFlowRate("mole/hr")
* richTEGStream.getFluid().getComponent("water").getz();
assertEquals(waterFlowRateInColumn, waterFlowRateInColumn2, 0.00001);

double waterFlowRateInColumnGasToReb = gasToReboilerStream.getFluid().getFlowRate("mole/hr")
* gasToReboilerStream.getFluid().getComponent("water").getMolarMass()
* gasToReboilerStream.getFluid().getComponent("water").getz();
double waterFlowRateOutColumn = column.getGasOutStream().getFluid().getFlowRate("mole/hr")
* column.getGasOutStream().getFluid().getComponent("water").getMolarMass()
* column.getGasOutStream().getFluid().getComponent("water").getz();
double waterFlowRateOutColumnLeanTEG =
column.getLiquidOutStream().getFluid().getFlowRate("mole/hr")
* column.getLiquidOutStream().getFluid().getComponent("water").getMolarMass()
* column.getLiquidOutStream().getFluid().getComponent("water").getz();


double totalWaterIn = waterFlowRateInColumn2 + waterFlowRateInColumnGasToReb;
double totalWaterOut = waterFlowRateOutColumn + waterFlowRateOutColumnLeanTEG;

System.out.println("Column in is " + totalWaterIn + " kg/hr");
System.out.println("Column out is " + totalWaterOut + " kg/hr");
System.out.println("Column is solved " + column.solved());


assertEquals(totalWaterIn, totalWaterOut, 0.1);

System.out.println("Calc Water Flow rate via fluid component " + waterFlowRateInColumn);
System.out.println("Calc Water Flow rate via molar mass and flow rate total "
+ waterFlowRateInColumn2 + " kg/hr");

}
}
Loading