diff --git a/src/main/java/neqsim/process/equipment/mixer/Mixer.java b/src/main/java/neqsim/process/equipment/mixer/Mixer.java index 860d73867..9e8269406 100644 --- a/src/main/java/neqsim/process/equipment/mixer/Mixer.java +++ b/src/main/java/neqsim/process/equipment/mixer/Mixer.java @@ -5,7 +5,6 @@ import java.text.DecimalFormat; import java.text.FieldPosition; import java.util.ArrayList; -import java.util.Iterator; import java.util.Objects; import java.util.UUID; import javax.swing.JDialog; @@ -195,19 +194,6 @@ public StreamInterface getOutletStream() { return mixedStream; } - /** {@inheritDoc} */ - @Override - public boolean needRecalculation() { - Iterator iter = streams.iterator(); - while (iter.hasNext()) { - StreamInterface str = iter.next(); - if (!str.solved()) { - return true; - } - } - return false; - } - /** {@inheritDoc} */ @Override public void run(UUID id) { diff --git a/src/main/java/neqsim/process/equipment/separator/Separator.java b/src/main/java/neqsim/process/equipment/separator/Separator.java index c8d35ad65..81f86346c 100644 --- a/src/main/java/neqsim/process/equipment/separator/Separator.java +++ b/src/main/java/neqsim/process/equipment/separator/Separator.java @@ -73,6 +73,9 @@ public class Separator extends ProcessEquipmentBaseClass implements SeparatorInt ArrayList separatorSection = new ArrayList(); SeparatorMechanicalDesign separatorMechanicalDesign; + private double lastEnthalpy; + private double lastFlowRate; + private double lastPressure; /** * Constructor for Separator. @@ -196,6 +199,17 @@ public SystemInterface getThermoSystem() { @Override public void run(UUID id) { inletStreamMixer.run(id); + double enthalpy = inletStreamMixer.getOutletStream().getFluid().getEnthalpy(); + double flow = inletStreamMixer.getOutletStream().getFlowRate("kg/hr"); + double pres = inletStreamMixer.getOutletStream().getPressure(); + if (Math.abs((lastEnthalpy - enthalpy) / enthalpy) < 1e-6 + && Math.abs((lastFlowRate - flow) / flow) < 1e-6 + && Math.abs((lastPressure - pres) / pres) < 1e-6) { + return; + } + lastEnthalpy = inletStreamMixer.getOutletStream().getFluid().getEnthalpy(); + lastFlowRate = inletStreamMixer.getOutletStream().getFlowRate("kg/hr"); + lastPressure = inletStreamMixer.getOutletStream().getPressure(); thermoSystem2 = inletStreamMixer.getOutletStream().getThermoSystem().clone(); thermoSystem2.setPressure(thermoSystem2.getPressure() - pressureDrop); @@ -268,7 +282,6 @@ public void run(UUID id) { logger.error(ex.getMessage(), ex); } } - setCalculationIdentifier(id); } diff --git a/src/main/java/neqsim/process/equipment/separator/ThreePhaseSeparator.java b/src/main/java/neqsim/process/equipment/separator/ThreePhaseSeparator.java index dd2f4b774..87c389467 100644 --- a/src/main/java/neqsim/process/equipment/separator/ThreePhaseSeparator.java +++ b/src/main/java/neqsim/process/equipment/separator/ThreePhaseSeparator.java @@ -41,6 +41,10 @@ public class ThreePhaseSeparator extends Separator { boolean useTempMultiPhaseCheck = false; + private double lastEnthalpy; + private double lastFlowRate; + private double lastPressure; + /** * Constructor for ThreePhaseSeparator. * @@ -56,8 +60,7 @@ public ThreePhaseSeparator(String name) { *

* * @param name a {@link java.lang.String} object - * @param inletStream a {@link neqsim.process.equipment.stream.StreamInterface} - * object + * @param inletStream a {@link neqsim.process.equipment.stream.StreamInterface} object */ public ThreePhaseSeparator(String name, StreamInterface inletStream) { super(name, inletStream); @@ -139,6 +142,17 @@ public StreamInterface getOilOutStream() { @Override public void run(UUID id) { inletStreamMixer.run(id); + double enthalpy = inletStreamMixer.getOutletStream().getFluid().getEnthalpy(); + double flow = inletStreamMixer.getOutletStream().getFlowRate("kg/hr"); + double pres = inletStreamMixer.getOutletStream().getPressure(); + if (Math.abs((lastEnthalpy - enthalpy) / enthalpy) < 1e-6 + && Math.abs((lastFlowRate - flow) / flow) < 1e-6 + && Math.abs((lastPressure - pres) / pres) < 1e-6) { + return; + } + lastEnthalpy = inletStreamMixer.getOutletStream().getFluid().getEnthalpy(); + lastFlowRate = inletStreamMixer.getOutletStream().getFlowRate("kg/hr"); + lastPressure = inletStreamMixer.getOutletStream().getPressure(); thermoSystem = inletStreamMixer.getOutletStream().getThermoSystem().clone(); if (!thermoSystem.doMultiPhaseCheck()) { diff --git a/src/main/java/neqsim/process/equipment/splitter/Splitter.java b/src/main/java/neqsim/process/equipment/splitter/Splitter.java index 1edc3494c..a18d3bf67 100644 --- a/src/main/java/neqsim/process/equipment/splitter/Splitter.java +++ b/src/main/java/neqsim/process/equipment/splitter/Splitter.java @@ -1,5 +1,6 @@ package neqsim.process.equipment.splitter; +import java.util.Arrays; import java.util.UUID; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -33,6 +34,11 @@ public class Splitter extends ProcessEquipmentBaseClass implements SplitterInter double[] splitFactor = new double[1]; double[] flowRates; String flowUnit = "mole/sec"; + protected double[] oldSplitFactor = null; + protected double lastTemperature = 0.0; + protected double lastPressure = 0.0; + protected double lastFlowRate = 0.0; + protected double[] lastComposition = null; /** * Constructor for Splitter. @@ -60,8 +66,7 @@ public Splitter(String name, StreamInterface inStream) { *

* * @param name a {@link java.lang.String} object - * @param inletStream a {@link neqsim.process.equipment.stream.StreamInterface} - * object + * @param inletStream a {@link neqsim.process.equipment.stream.StreamInterface} object * @param i a int */ public Splitter(String name, StreamInterface inletStream, int i) { @@ -178,6 +183,22 @@ public StreamInterface getSplitStream(int i) { return splitStream[i]; } + /** {@inheritDoc} */ + @Override + public boolean needRecalculation() { + if (inletStream.getFluid().getTemperature() == lastTemperature + && inletStream.getFluid().getPressure() == lastPressure + && Math.abs(inletStream.getFluid().getFlowRate("kg/hr") - lastFlowRate) + / inletStream.getFluid().getFlowRate("kg/hr") < 1e-6 + && Arrays.equals(splitFactor, oldSplitFactor)) { + isSolved = true; + return false; + } else { + isSolved = false; + return true; + } + } + /** {@inheritDoc} */ @Override public void run(UUID id) { @@ -216,6 +237,12 @@ public void run(UUID id) { thermoOps.TPflash(); } + lastFlowRate = thermoSystem.getFlowRate("kg/hr"); + lastTemperature = thermoSystem.getTemperature(); + lastPressure = thermoSystem.getPressure(); + lastComposition = thermoSystem.getMolarComposition(); + oldSplitFactor = Arrays.copyOf(splitFactor, splitFactor.length); + setCalculationIdentifier(id); } @@ -237,6 +264,12 @@ public void runTransient(double dt, UUID id) { inletStream.setThermoSystem(mixer.getThermoSystem()); inletStream.run(); + + lastFlowRate = thermoSystem.getFlowRate("kg/hr"); + lastTemperature = thermoSystem.getTemperature(); + lastPressure = thermoSystem.getPressure(); + lastComposition = thermoSystem.getMolarComposition(); + oldSplitFactor = Arrays.copyOf(splitFactor, splitFactor.length); setCalculationIdentifier(id); } } diff --git a/src/main/java/neqsim/process/equipment/stream/Stream.java b/src/main/java/neqsim/process/equipment/stream/Stream.java index aa2f5d163..623d41f4f 100644 --- a/src/main/java/neqsim/process/equipment/stream/Stream.java +++ b/src/main/java/neqsim/process/equipment/stream/Stream.java @@ -7,6 +7,7 @@ package neqsim.process.equipment.stream; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.UUID; import org.apache.logging.log4j.LogManager; @@ -46,6 +47,8 @@ public class Stream extends ProcessEquipmentBaseClass implements StreamInterface protected double lastTemperature = 0.0; protected double lastPressure = 0.0; protected double lastFlowRate = 0.0; + protected double[] lastComposition = null; + /** * Constructor for Stream. @@ -317,7 +320,8 @@ public boolean needRecalculation() { } if (getFluid().getTemperature() == lastTemperature && getFluid().getPressure() == lastPressure && Math.abs(getFluid().getFlowRate("kg/hr") - lastFlowRate) - / getFluid().getFlowRate("kg/hr") < 1e-6) { + / getFluid().getFlowRate("kg/hr") < 1e-6 + && Arrays.equals(getFluid().getMolarComposition(), lastComposition)) { isSolved = true; return false; } else { @@ -400,6 +404,7 @@ && getSpecification().equals("TP")) { lastFlowRate = thermoSystem.getFlowRate("kg/hr"); lastTemperature = thermoSystem.getTemperature(); lastPressure = thermoSystem.getPressure(); + lastComposition = thermoSystem.getMolarComposition(); if (stream != null) { stream.setFluid(thermoSystem); diff --git a/src/test/java/neqsim/process/equipment/mixer/MixerTest.java b/src/test/java/neqsim/process/equipment/mixer/MixerTest.java index 4d953c2ec..e87222518 100644 --- a/src/test/java/neqsim/process/equipment/mixer/MixerTest.java +++ b/src/test/java/neqsim/process/equipment/mixer/MixerTest.java @@ -5,7 +5,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import neqsim.process.equipment.mixer.Mixer; import neqsim.process.equipment.stream.Stream; import neqsim.process.processmodel.ProcessSystem; import neqsim.thermo.system.SystemSrkEos; @@ -77,12 +76,9 @@ void testNeedRecalculation() { processOps.run(); assertFalse(gasStream.needRecalculation()); assertFalse(waterStream.needRecalculation()); - assertFalse(testMixer.needRecalculation()); gasStream.setFlowRate(100.1, "kg/hr"); assertTrue(gasStream.needRecalculation()); - assertTrue(testMixer.needRecalculation()); processOps.run(); assertFalse(gasStream.needRecalculation()); - assertFalse(testMixer.needRecalculation()); } } diff --git a/src/test/java/neqsim/process/processmodel/CompressorModule.java b/src/test/java/neqsim/process/processmodel/CompressorModule.java index 38991ce72..a8d326090 100644 --- a/src/test/java/neqsim/process/processmodel/CompressorModule.java +++ b/src/test/java/neqsim/process/processmodel/CompressorModule.java @@ -134,11 +134,10 @@ public void testProcess() { operations.run(); - assertEquals(2042.17826, recycleScrubberStream.getFlowRate("kg/hr"), 0.1); + assertEquals(2046.0527, recycleScrubberStream.getFlowRate("kg/hr"), 0.1); neqsim.process.equipment.compressor.CompressorChartGenerator compchartgenerator = - new neqsim.process.equipment.compressor.CompressorChartGenerator( - seccondStageCompressor); + new neqsim.process.equipment.compressor.CompressorChartGenerator(seccondStageCompressor); compchartgenerator.generateCompressorChart("mid range"); seccondStageCompressor.setCompressorChart(compchartgenerator.generateCompressorChart("normal"));