From df5659e7450b45bf334b8a5795805e041efc83b2 Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Sun, 3 Nov 2024 09:31:49 +0100 Subject: [PATCH] added error pressure (#1160) --- .../processequipment/util/Recycle.java | 91 +++++++++++++++---- 1 file changed, 72 insertions(+), 19 deletions(-) diff --git a/src/main/java/neqsim/processsimulation/processequipment/util/Recycle.java b/src/main/java/neqsim/processsimulation/processequipment/util/Recycle.java index fdd107f2b..d5a3537c8 100644 --- a/src/main/java/neqsim/processsimulation/processequipment/util/Recycle.java +++ b/src/main/java/neqsim/processsimulation/processequipment/util/Recycle.java @@ -35,9 +35,11 @@ public class Recycle extends ProcessEquipmentBaseClass implements MixerInterface private double errorComposition = 1e10; private double errorFlow = 1e10; private double errorTemperature = 1e10; + private double errorPressure = 1e10; private double flowTolerance = 1e-2; private double compositionTolerance = 1e-2; private double temperatureTolerance = 1e-2; + private double pressureTolerance = 1e-2; /** *

@@ -181,7 +183,9 @@ public void addStream(StreamInterface newStream) { *

* * @param i a int - * @return a {@link neqsim.processsimulation.processequipment.stream.StreamInterface} object + * @return a + * {@link neqsim.processsimulation.processequipment.stream.StreamInterface} + * object */ public StreamInterface getStream(int i) { return streams.get(i); @@ -200,13 +204,11 @@ public void mixStream() { for (int i = 0; i < streams.get(k).getThermoSystem().getPhase(0) .getNumberOfComponents(); i++) { boolean gotComponent = false; - String componentName = - streams.get(k).getThermoSystem().getPhase(0).getComponent(i).getName(); + String componentName = streams.get(k).getThermoSystem().getPhase(0).getComponent(i).getName(); // logger.info("adding: " + componentName); // int numberOfPhases = streams.get(k).getThermoSystem().getNumberOfPhases(); - double moles = - streams.get(k).getThermoSystem().getPhase(0).getComponent(i).getNumberOfmoles(); + double moles = streams.get(k).getThermoSystem().getPhase(0).getComponent(i).getNumberOfmoles(); // logger.info("moles: " + moles + " " + // mixedStream.getThermoSystem().getPhase(0).getNumberOfComponents()); for (int p = 0; p < mixedStream.getThermoSystem().getPhase(0) @@ -214,8 +216,7 @@ public void mixStream() { if (mixedStream.getThermoSystem().getPhase(0).getComponent(p).getName() .equals(componentName)) { gotComponent = true; - index = - streams.get(0).getThermoSystem().getPhase(0).getComponent(p).getComponentNumber(); + index = streams.get(0).getThermoSystem().getPhase(0).getComponent(p).getComponentNumber(); // compName = streams.get(0).getThermoSystem().getPhase(0).getComponent(p) // .getComponentName(); } @@ -285,8 +286,9 @@ public StreamInterface getOutStream() { * initiateDownstreamProperties. *

* - * @param outstream a {@link neqsim.processsimulation.processequipment.stream.StreamInterface} - * object + * @param outstream a + * {@link neqsim.processsimulation.processequipment.stream.StreamInterface} + * object */ public void initiateDownstreamProperties(StreamInterface outstream) { lastIterationStream = outstream.clone(); @@ -349,6 +351,7 @@ public void run(UUID id) { setErrorCompositon(compositionBalanceCheck()); setErrorFlow(flowBalanceCheck()); setErrorTemperature(temperatureBalanceCheck()); + setErrorPressure(pressureBalanceCheck()); lastIterationStream = mixedStream.clone(); outletStream.setThermoSystem(mixedStream.getThermoSystem()); outletStream.setCalculationIdentifier(id); @@ -374,12 +377,10 @@ public void run(UUID id) { public double flowBalanceCheck() { double abs_sum_errorFlow = 0.0; if (mixedStream.getFlowRate("kg/sec") < 1.0) { - abs_sum_errorFlow += - Math.abs(mixedStream.getFlowRate("kg/sec") - lastIterationStream.getFlowRate("kg/sec")); + abs_sum_errorFlow += Math.abs(mixedStream.getFlowRate("kg/sec") - lastIterationStream.getFlowRate("kg/sec")); } else { - abs_sum_errorFlow += - Math.abs(mixedStream.getFlowRate("kg/sec") - lastIterationStream.getFlowRate("kg/sec")) - / mixedStream.getFlowRate("kg/sec") * 100.0; + abs_sum_errorFlow += Math.abs(mixedStream.getFlowRate("kg/sec") - lastIterationStream.getFlowRate("kg/sec")) + / mixedStream.getFlowRate("kg/sec") * 100.0; } return abs_sum_errorFlow; } @@ -406,7 +407,6 @@ public double compositionBalanceCheck() { return abs_sum_error; } - /** *

* temperatureBalanceCheck. @@ -424,9 +424,27 @@ public double temperatureBalanceCheck() { return error; } + /** + *

+ * pressureBalanceCheck. + *

+ * + * @return a double + */ + public double pressureBalanceCheck() { + double error = 0.0; + for (int i = 0; i < mixedStream.getThermoSystem().getNumberOfPhases(); i++) { + error += Math.abs((mixedStream.getThermoSystem().getPhase(i).getPressure() + - lastIterationStream.getThermoSystem().getPhase(i).getPressure()) + / lastIterationStream.getThermoSystem().getPhase(i).getPressure()) * 100.0; + } + return error; + } + /** {@inheritDoc} */ @Override - public void displayResult() {} + public void displayResult() { + } /** {@inheritDoc} */ @Override @@ -476,6 +494,17 @@ public void setErrorTemperature(double errorTemperature) { this.errorTemperature = errorTemperature; } + /** + *

+ * Setter for the field errorPressure. + *

+ * + * @param errorPressure the errorPressure to set + */ + public void setErrorPressure(double errorPressure) { + this.errorPressure = errorPressure; + } + /** *

* Setter for the field errorFlow. @@ -498,6 +527,28 @@ public double getErrorFlow() { return errorFlow; } + /** + *

+ * Getter for the field errorTemperature. + *

+ * + * @return a double + */ + public double getErrorTemperature() { + return errorTemperature; + } + + /** + *

+ * Getter for the field errorPressure. + *

+ * + * @return a double + */ + public double getErrorPressure() { + return errorPressure; + } + /** *

* Setter for the field errorComposition. @@ -547,7 +598,8 @@ public void setPriority(int priority) { public boolean solved() { if (Math.abs(this.errorComposition) < compositionTolerance && Math.abs(this.errorFlow) < flowTolerance - && Math.abs(this.errorTemperature) < temperatureTolerance && iterations > 1) { + && Math.abs(this.errorTemperature) < temperatureTolerance + && Math.abs(this.errorPressure) < pressureTolerance && iterations > 1) { return true; } else { return false; @@ -576,8 +628,9 @@ public StreamInterface getOutletStream() { * Setter for the field outletStream. *

* - * @param outletStream a {@link neqsim.processsimulation.processequipment.stream.StreamInterface} - * object + * @param outletStream a + * {@link neqsim.processsimulation.processequipment.stream.StreamInterface} + * object */ public void setOutletStream(StreamInterface outletStream) { this.outletStream = outletStream;