Skip to content

Commit

Permalink
update recycle methods (#1159)
Browse files Browse the repository at this point in the history
* update recycle methods

* update

* remove print
  • Loading branch information
EvenSol authored Nov 2, 2024
1 parent 388818f commit f9f5788
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,16 @@ public class Recycle extends ProcessEquipmentBaseClass implements MixerInterface
protected StreamInterface mixedStream;
StreamInterface lastIterationStream = null;
private StreamInterface outletStream = null;
private double tolerance = 1e-2;
private int priority = 100;
private double error = 1e10;
private double errorFlow = 1e10;
boolean firstTime = true;
int iterations = 0;
int maxIterations = 10;

double compositionAccuracy = 1.0;
double temperatureAccuracy = 1.0;
double flowAccuracy = 1.0e-2;
private double errorComposition = 1e10;
private double errorFlow = 1e10;
private double errorTemperature = 1e10;
private double flowTolerance = 1e-2;
private double compositionTolerance = 1e-2;
private double temperatureTolerance = 1e-2;

/**
* <p>
Expand All @@ -53,35 +52,68 @@ public Recycle(String name) {

/**
* <p>
* Setter for the field <code>compositionAccuracy</code>.
* Setter for the field <code>compositionTolerance</code>.
* </p>
*
* @param compositionTolerance a double
*/
public void setCompositionTolerance(double compositionTolerance) {
this.compositionTolerance = compositionTolerance;
}

/**
* <p>
* Getter for the field <code>compositionTolerance</code>.
* </p>
*
* @param compositionAccuracy a double
* @return a double
*/
public void setCompositionAccuracy(double compositionAccuracy) {
this.compositionAccuracy = compositionAccuracy;
public double getCompositionTolerance() {
return this.compositionTolerance;
}

/**
* <p>
* Setter for the field <code>temperatureAccuracy</code>.
* Setter for the field <code>temperatureTolerance</code>.
* </p>
*
* @param temperatureAccuracy a double
* @param temperatureTolerance a double in % error
*/
public void setTemperatureAccuracy(double temperatureAccuracy) {
this.temperatureAccuracy = temperatureAccuracy;
public void setTemperatureTolerance(double temperatureTolerance) {
this.temperatureTolerance = temperatureTolerance;
}

/**
* <p>
* Setter for the field <code>flowAccuracy</code>.
* Getter for the field <code>temperatureTolerance</code>.
* </p>
*
* @param flowAccuracy a double
* @return a double
*/
public void setFlowAccuracy(double flowAccuracy) {
this.flowAccuracy = flowAccuracy;
public double getTemperatureTolerance() {
return this.temperatureTolerance;
}

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

/**
* <p>
* Getter for the field <code>flowTolerance</code>.
* </p>
*
* @return a double
*/
public double getFlowTolerance() {
return this.flowTolerance;
}

/**
Expand Down Expand Up @@ -285,8 +317,8 @@ public void run(UUID id) {
double enthalpy = 0.0;
SystemInterface thermoSystem2 = streams.get(0).getThermoSystem().clone();
if (numberOfInputStreams == 1 && thermoSystem2.getFlowRate("kg/hr") < 1e-100) {
setError(0);
setErrorFlow(0);
setErrorCompositon(0.0);
setErrorFlow(0.0);
return;
}
mixedStream.setThermoSystem(thermoSystem2);
Expand Down Expand Up @@ -314,8 +346,9 @@ public void run(UUID id) {
testOps.TPflash();
}
mixedStream.setCalculationIdentifier(id);
setError(massBalanceCheck());
setErrorFlow(massBalanceCheck2());
setErrorCompositon(compositionBalanceCheck());
setErrorFlow(flowBalanceCheck());
setErrorTemperature(temperatureBalanceCheck());
lastIterationStream = mixedStream.clone();
outletStream.setThermoSystem(mixedStream.getThermoSystem());
outletStream.setCalculationIdentifier(id);
Expand All @@ -338,7 +371,7 @@ public void run(UUID id) {
*
* @return a double
*/
public double massBalanceCheck2() {
public double flowBalanceCheck() {
double abs_sum_errorFlow = 0.0;
if (mixedStream.getFlowRate("kg/sec") < 1.0) {
abs_sum_errorFlow +=
Expand All @@ -353,37 +386,44 @@ public double massBalanceCheck2() {

/**
* <p>
* massBalanceCheck.
* compositionBalanceCheck.
* </p>
*
* @return a double
*/
public double massBalanceCheck() {
// logger.info("flow rate new " +
// mixedStream.getThermoSystem().getFlowRate("kg/hr"));
// logger.info("temperature " +
// mixedStream.getThermoSystem().getTemperature("C"));
// logger.info("pressure " +
// mixedStream.getThermoSystem().getPressure("bara"));
public double compositionBalanceCheck() {
if (lastIterationStream.getFluid().getNumberOfComponents() != mixedStream.getFluid()
.getNumberOfComponents()) {
return 10.0;
}

double abs_sum_error = 0.0;
for (int i = 0; i < mixedStream.getThermoSystem().getPhase(0).getNumberOfComponents(); i++) {
// logger.info("x last " +
// lastIterationStream.getThermoSystem().getPhase(0).getComponent(i).getx());
// logger.info("x new " +
// mixedStream.getThermoSystem().getPhase(0).getComponent(i).getx());

abs_sum_error += Math.abs(mixedStream.getThermoSystem().getPhase(0).getComponent(i).getx()
- lastIterationStream.getThermoSystem().getPhase(0).getComponent(i).getx());
}

return abs_sum_error;
}


/**
* <p>
* temperatureBalanceCheck.
* </p>
*
* @return a double
*/
public double temperatureBalanceCheck() {
double error = 0.0;
for (int i = 0; i < mixedStream.getThermoSystem().getNumberOfPhases(); i++) {
error += Math.abs((mixedStream.getThermoSystem().getPhase(i).getTemperature()
- lastIterationStream.getThermoSystem().getPhase(i).getTemperature())
/ lastIterationStream.getThermoSystem().getPhase(i).getTemperature()) * 100.0;
}
return error;
}

/** {@inheritDoc} */
@Override
public void displayResult() {}
Expand Down Expand Up @@ -413,68 +453,71 @@ public void setTemperature(double temp) {

/**
* <p>
* Getter for the field <code>tolerance</code>.
* Setter for the tolerance fields.
* </p>
*
* @return the tolerance
* Set tolerances to tolerance input.
*
* @param tolerance the tolerance to set
*/
public double getTolerance() {
return tolerance;
public void setTolerance(double tolerance) {
this.flowTolerance = tolerance;
this.temperatureTolerance = tolerance;
this.compositionTolerance = tolerance;
}

/**
* <p>
* Setter for the field <code>tolerance</code>.
* Setter for the field <code>errorTemperature</code>.
* </p>
*
* @param tolerance the tolerance to set
* @param errorTemperature the errorTemperature to set
*/
public void setTolerance(double tolerance) {
this.tolerance = tolerance;
public void setErrorTemperature(double errorTemperature) {
this.errorTemperature = errorTemperature;
}

/**
* <p>
* Getter for the field <code>error</code>.
* Setter for the field <code>errorFlow</code>.
* </p>
*
* @return the error
* @param errorFlow the error to set
*/
public double getError() {
return error;
public void setErrorFlow(double errorFlow) {
this.errorFlow = errorFlow;
}

/**
* <p>
* Setter for the field <code>error</code>.
* Getter for the field <code>errorFlow</code>.
* </p>
*
* @param error the error to set
* @return a double
*/
public void setError(double error) {
this.error = error;
public double getErrorFlow() {
return errorFlow;
}

/**
* <p>
* Setter for the field <code>errorFlow</code>.
* Setter for the field <code>errorComposition</code>.
* </p>
*
* @param errorFlow the error to set
* @param errorComposition the error to set
*/
public void setErrorFlow(double errorFlow) {
this.errorFlow = errorFlow;
public void setErrorCompositon(double errorComposition) {
this.errorComposition = errorComposition;
}

/**
* <p>
* Getter for the field <code>errorFlow</code>.
* Getter for the field <code>errorComposition</code>.
* </p>
*
* @return a double
*/
public double getErrorFlow() {
return errorFlow;
public double getErrorComposition() {
return errorComposition;
}

/**
Expand Down Expand Up @@ -502,8 +545,9 @@ public void setPriority(int priority) {
/** {@inheritDoc} */
@Override
public boolean solved() {
if (Math.abs(this.error) < tolerance && Math.abs(this.errorFlow) < flowAccuracy
&& iterations > 1) {
if (Math.abs(this.errorComposition) < compositionTolerance
&& Math.abs(this.errorFlow) < flowTolerance
&& Math.abs(this.errorTemperature) < temperatureTolerance && iterations > 1) {
return true;
} else {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void testRunSplitter2() {
Recycle recycle1 = new Recycle("recycle 1");
recycle1.addStream(valve1.getOutletStream());
recycle1.setOutletStream(streamresycl);
recycle1.setFlowAccuracy(1e-6);
recycle1.setFlowTolerance(1e-6);

StreamInterface exportStream = splitter.getSplitStream(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void testProcess() {

operations.run();

assertEquals(2046.8012652616517, recycleScrubberStream.getFlowRate("kg/hr"), 0.1);
assertEquals(2042.17826, recycleScrubberStream.getFlowRate("kg/hr"), 0.1);

neqsim.processsimulation.processequipment.compressor.CompressorChartGenerator compchartgenerator =
new neqsim.processsimulation.processequipment.compressor.CompressorChartGenerator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,6 @@ public void runProcessTEG() throws InterruptedException {
} catch (Exception ex) {
}

System.out.println(splitterGasToFlare.getSplitStream(1).getFlowRate("kg/hr"));
// System.out.println(splitterGasToFlare.getSplitStream(1).getFlowRate("kg/hr"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public void runAntiSurgeProcess2() throws InterruptedException {
Recycle recycl = new Recycle("rec");
recycl.addStream(antisurgevalve.getOutletStream());
recycl.setOutletStream(recyclegasstream);
recycl.setFlowAccuracy(1e-2);
recycl.setFlowTolerance(1e-2);

neqsim.processsimulation.processsystem.ProcessSystem operations =
new neqsim.processsimulation.processsystem.ProcessSystem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ public void testAntiSurgeControl() {
Recycle recycle = new Recycle("recycle 1");
recycle.addStream(recycleValve.getOutletStream());
recycle.setOutletStream(resycstream);
recycle.setFlowAccuracy(1e-4);
recycle.setFlowTolerance(1e-4);

ThrottlingValve valve2 = new ThrottlingValve("valve_2", splitter.getSplitStream(0));
valve2.setOutletPressure(50.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ public void testRun_step() {
Recycle recycleGasFromStripper = new Recycle("stripping gas recirc");
recycleGasFromStripper.addStream(stripper.getGasOutStream());
recycleGasFromStripper.setOutletStream(gasToReboiler);
recycleGasFromStripper.setTolerance(1.0e-2);

neqsim.thermo.system.SystemInterface pureTEG =
(neqsim.thermo.system.SystemInterface) feedGas.clone();
Expand Down

0 comments on commit f9f5788

Please sign in to comment.