Skip to content

Commit

Permalink
update1 (#1175)
Browse files Browse the repository at this point in the history
  • Loading branch information
EvenSol authored Nov 11, 2024
1 parent 9be6384 commit c7d52cb
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 27 deletions.
14 changes: 0 additions & 14 deletions src/main/java/neqsim/process/equipment/mixer/Mixer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -195,19 +194,6 @@ public StreamInterface getOutletStream() {
return mixedStream;
}

/** {@inheritDoc} */
@Override
public boolean needRecalculation() {
Iterator<StreamInterface> iter = streams.iterator();
while (iter.hasNext()) {
StreamInterface str = iter.next();
if (!str.solved()) {
return true;
}
}
return false;
}

/** {@inheritDoc} */
@Override
public void run(UUID id) {
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/neqsim/process/equipment/separator/Separator.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public class Separator extends ProcessEquipmentBaseClass implements SeparatorInt
ArrayList<SeparatorSection> separatorSection = new ArrayList<SeparatorSection>();

SeparatorMechanicalDesign separatorMechanicalDesign;
private double lastEnthalpy;
private double lastFlowRate;
private double lastPressure;

/**
* Constructor for Separator.
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -268,7 +282,6 @@ public void run(UUID id) {
logger.error(ex.getMessage(), ex);
}
}

setCalculationIdentifier(id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public class ThreePhaseSeparator extends Separator {

boolean useTempMultiPhaseCheck = false;

private double lastEnthalpy;
private double lastFlowRate;
private double lastPressure;

/**
* Constructor for ThreePhaseSeparator.
*
Expand All @@ -56,8 +60,7 @@ public ThreePhaseSeparator(String name) {
* </p>
*
* @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);
Expand Down Expand Up @@ -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()) {
Expand Down
37 changes: 35 additions & 2 deletions src/main/java/neqsim/process/equipment/splitter/Splitter.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -60,8 +66,7 @@ public Splitter(String name, StreamInterface inStream) {
* </p>
*
* @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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/neqsim/process/equipment/stream/Stream.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions src/test/java/neqsim/process/equipment/mixer/MixerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down

0 comments on commit c7d52cb

Please sign in to comment.