From d0a25bd1a16cdc34f0ff291a497467ae89ab9b41 Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Wed, 8 Nov 2023 21:44:07 +0100 Subject: [PATCH] added flow setter (#838) * added flow setter * improve setter * fix bug * fix errors --- .../measurementDevice/MultiPhaseMeter.java | 54 +++ .../powerGeneration/GasTurbine.java | 5 +- .../processEquipment/util/FlowSetter.java | 347 ++++++++++++++++++ .../datasmoothing}/DataSmoother.java | 0 .../processEquipment/util/FlowSetterTest.java | 53 +++ 5 files changed, 457 insertions(+), 2 deletions(-) create mode 100644 src/main/java/neqsim/processSimulation/processEquipment/util/FlowSetter.java rename src/main/java/neqsim/statistics/{dataAnalysis/dataSmoothing => dataanalysis/datasmoothing}/DataSmoother.java (100%) create mode 100644 src/test/java/neqsim/processSimulation/processEquipment/util/FlowSetterTest.java diff --git a/src/main/java/neqsim/processSimulation/measurementDevice/MultiPhaseMeter.java b/src/main/java/neqsim/processSimulation/measurementDevice/MultiPhaseMeter.java index 14e238ed1e..ca54cb576b 100644 --- a/src/main/java/neqsim/processSimulation/measurementDevice/MultiPhaseMeter.java +++ b/src/main/java/neqsim/processSimulation/measurementDevice/MultiPhaseMeter.java @@ -139,6 +139,60 @@ public double getMeasuredValue(String measurement, String unit) { return tempFluid.getPhase("gas").getCorrectedVolume() / tempFluid.getPhase("oil").getCorrectedVolume(); } + if (measurement.equals("Gas Flow Rate")) { + SystemInterface tempFluid = stream.getThermoSystem().clone(); + tempFluid.setTemperature(temperature, unitT); + tempFluid.setPressure(pressure, unitP); + ThermodynamicOperations thermoOps = new ThermodynamicOperations(tempFluid); + try { + thermoOps.TPflash(); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + return Double.NaN; + } + // tempFluid.display(); + if (!tempFluid.hasPhaseType("gas")) { + return Double.NaN; + } + tempFluid.initPhysicalProperties("density"); + return tempFluid.getPhase("gas").getFlowRate(unit); + } + if (measurement.equals("Oil Flow Rate")) { + SystemInterface tempFluid = stream.getThermoSystem().clone(); + tempFluid.setTemperature(temperature, unitT); + tempFluid.setPressure(pressure, unitP); + ThermodynamicOperations thermoOps = new ThermodynamicOperations(tempFluid); + try { + thermoOps.TPflash(); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + return Double.NaN; + } + // tempFluid.display(); + if (!tempFluid.hasPhaseType("oil")) { + return Double.NaN; + } + tempFluid.initPhysicalProperties("density"); + return tempFluid.getPhase("oil").getFlowRate(unit); + } + if (measurement.equals("Water Flow Rate")) { + SystemInterface tempFluid = stream.getThermoSystem().clone(); + tempFluid.setTemperature(temperature, unitT); + tempFluid.setPressure(pressure, unitP); + ThermodynamicOperations thermoOps = new ThermodynamicOperations(tempFluid); + try { + thermoOps.TPflash(); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + return Double.NaN; + } + // tempFluid.display(); + if (!tempFluid.hasPhaseType("aqueous")) { + return Double.NaN; + } + tempFluid.initPhysicalProperties("density"); + return tempFluid.getPhase("aqueous").getFlowRate(unit); + } if (measurement.equals("gasDensity") || measurement.equals("oilDensity") || measurement.equals("waterDensity")) { SystemInterface tempFluid = stream.getThermoSystem().clone(); diff --git a/src/main/java/neqsim/processSimulation/processEquipment/powerGeneration/GasTurbine.java b/src/main/java/neqsim/processSimulation/processEquipment/powerGeneration/GasTurbine.java index 09f1fb903a..a15f6d7f7f 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/powerGeneration/GasTurbine.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/powerGeneration/GasTurbine.java @@ -199,9 +199,10 @@ public void run(UUID id) { * * *
- * calcIdealAirGasRatio - *
* Calculates ideal air fuel ratio [kg air/kg fuel] + * + * + * @return ideal air fuel ratio [kg air/kg fuel] */ public double calcIdealAirFuelRatio() { thermoSystem = inStream.getThermoSystem().clone(); diff --git a/src/main/java/neqsim/processSimulation/processEquipment/util/FlowSetter.java b/src/main/java/neqsim/processSimulation/processEquipment/util/FlowSetter.java new file mode 100644 index 0000000000..166a5c1e81 --- /dev/null +++ b/src/main/java/neqsim/processSimulation/processEquipment/util/FlowSetter.java @@ -0,0 +1,347 @@ +package neqsim.processSimulation.processEquipment.util; + +import java.util.UUID; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import neqsim.processSimulation.processEquipment.TwoPortEquipment; +import neqsim.processSimulation.processEquipment.stream.StreamInterface; +import neqsim.thermo.system.SystemInterface; +import neqsim.thermodynamicOperations.ThermodynamicOperations; + +/** + *+ * FlowSetter class. + *
+ * + * @author esol + * @version $Id: $Id + */ +public class FlowSetter extends TwoPortEquipment { + private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(GORfitter.class); + + double pressure = 1.01325; + double temperature = 15.0; + String unitT = "C"; + String unitP = "bara"; + + private double gasFlowRate; + private double oilFlowRate; + private double waterFlowRate; + String unitGasFlowRate = "Sm3/day"; + String unitOilFlowRate = "m3/hr"; + String unitWaterFlowRate = "m3/hr"; + + @Deprecated + /** + *+ * Constructor for FlowSetter. + *
+ */ + public FlowSetter() { + super("Flow Setter"); + } + + /** + *+ * Constructor for FlowSetter. + *
+ * + * @param stream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object + */ + @Deprecated + public FlowSetter(StreamInterface stream) { + this("Flow Setter", stream); + } + + /** + *+ * Constructor for FlowSetter. + *
+ * + * @param name a {@link java.lang.String} object + * @param stream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object + */ + public FlowSetter(String name, StreamInterface stream) { + super(name, stream); + } + + + /** + * {@inheritDoc} + * + *
+ * Setter for the field inletStream
.
+ *
+ * Getter for the field pressure
.
+ *
+ * Setter for the field pressure
.
+ *
+ * getTemperature. + *
+ * + * @return a double + */ + public double getTemperature() { + return temperature; + } + + /** + *
+ * Setter for the field temperature
.
+ *
+ * Get setGasFlowRate + *
+ * + * @param flowRate flow rate + * @param flowUnit Supported units are Sm3/sec, Sm3/hr, Sm3/day, MSm3/day + * + */ + public void setGasFlowRate(double flowRate, String flowUnit) { + double conversionFactor = 1.0; + switch (flowUnit) { + case "Sm3/sec": + conversionFactor = 1.0; + break; + case "Sm3/hr": + conversionFactor = 1.0 / 3600.0; + break; + case "Sm3/day": + conversionFactor = 1.0 / 3600.0 / 24.0; + break; + default: + throw new RuntimeException("unit not supported " + flowUnit); + } + gasFlowRate = flowRate * conversionFactor; + } + + /** + *+ * Get getGasFlowRate + *
+ * + * @param flowUnit Supported units are Sm3/sec, Sm3/hr, Sm3/day, MSm3/day + * @return gas flow rate in unit sm3/sec + */ + public double getGasFlowRate(String flowUnit) { + double conversionFactor = 1.0; + switch (flowUnit) { + case "Sm3/sec": + conversionFactor = 1.0; + break; + case "Sm3/hr": + conversionFactor = 1.0 / 3600.0; + break; + case "Sm3/day": + conversionFactor = 1.0 / 3600.0 / 24.0; + break; + case "MSm3/day": + conversionFactor = 1.0 / 3600.0 / 24.0 / 1e6; + break; + default: + throw new RuntimeException("unit not supported " + flowUnit); + } + return gasFlowRate * conversionFactor; + } + + /** + *+ * Get setOilFlowRate + *
+ * + * @param flowRate flow rate + * @param flowUnit Supported units are m3/sec, m3/hr, m3/day + * + */ + public void setOilFlowRate(double flowRate, String flowUnit) { + double conversionFactor = 1.0; + switch (flowUnit) { + case "m3/sec": + conversionFactor = 1.0; + break; + case "m3/hr": + conversionFactor = 1.0 / 3600.0; + break; + case "m3/day": + conversionFactor = 1.0 / 3600.0 / 24.0; + break; + default: + throw new RuntimeException("unit not supported " + flowUnit); + } + oilFlowRate = flowRate * conversionFactor; + } + + /** + *+ * Get getOilFlowRate + *
+ * + * @param flowUnit Supported units are m3/sec, m3/hr, m3/day + * @return oil flow rate in unit m3/sec + */ + public double getOilFlowRate(String flowUnit) { + double conversionFactor = 1.0; + switch (flowUnit) { + case "m3/sec": + conversionFactor = 1.0; + break; + case "m3/hr": + conversionFactor = 1.0 / 3600.0; + break; + case "m3/day": + conversionFactor = 1.0 / 3600.0 / 24.0; + break; + default: + throw new RuntimeException("unit not supported " + flowUnit); + } + return oilFlowRate * conversionFactor; + } + + /** + *+ * Get setWaterFlowRate + *
+ * + * @param flowRate flow rate + * @param flowUnit Supported units are m3/sec, m3/hr, m3/day + * + */ + public void setWaterFlowRate(double flowRate, String flowUnit) { + double conversionFactor = 1.0; + switch (flowUnit) { + case "m3/sec": + conversionFactor = 1.0; + break; + case "m3/hr": + conversionFactor = 1.0 / 3600.0; + break; + case "m3/day": + conversionFactor = 1.0 / 3600.0 / 24.0; + break; + default: + throw new RuntimeException("unit not supported " + flowUnit); + } + waterFlowRate = flowRate * conversionFactor; + } + + /** + *+ * Get getWaterFlowRate + *
+ * + * @param flowUnit Supported units are m3/sec, m3/hr, m3/day + * @return water flow rate in unit m3/sec + */ + public double getWaterFlowRate(String flowUnit) { + double conversionFactor = 1.0; + switch (flowUnit) { + case "m3/sec": + conversionFactor = 1.0; + break; + case "m3/hr": + conversionFactor = 1.0 / 3600.0; + break; + case "m3/day": + conversionFactor = 1.0 / 3600.0 / 24.0; + break; + default: + throw new RuntimeException("unit not supported " + flowUnit); + } + return waterFlowRate * conversionFactor; + } + + /** {@inheritDoc} */ + @Override + public void run(UUID id) { + SystemInterface tempFluid = inStream.getThermoSystem().clone(); + double flow = tempFluid.getFlowRate("kg/sec"); + + if (flow < 1e-6) { + outStream.setThermoSystem(tempFluid); + return; + } + + tempFluid.setTemperature(temperature, unitT); + tempFluid.setPressure(pressure, unitP); + + ThermodynamicOperations thermoOps = new ThermodynamicOperations(tempFluid); + try { + thermoOps.TPflash(); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } + + tempFluid.initPhysicalProperties("density"); + + double[] moleChange = new double[tempFluid.getNumberOfComponents()]; + for (int i = 0; i < tempFluid.getNumberOfComponents(); i++) { + moleChange[i] = tempFluid.getPhase("gas").getComponent(i).getx() + * (getGasFlowRate("Sm3/sec") / tempFluid.getPhase("gas").getMolarVolume("m3/mol")) + + tempFluid.getPhase("oil").getComponent(i).getx() + * (getOilFlowRate("m3/sec") / tempFluid.getPhase("oil").getMolarVolume("m3/mol")) + - tempFluid.getComponent(i).getNumberOfmoles(); + } + tempFluid.init(0); + for (int i = 0; i < tempFluid.getNumberOfComponents(); i++) { + tempFluid.addComponent(i, moleChange[i]); + } + if (waterFlowRate > 0) { + tempFluid.addComponent("water", waterFlowRate * 1000.0, "kg/sec"); + } + tempFluid.setPressure((inStream.getThermoSystem()).getPressure()); + tempFluid.setTemperature((inStream.getThermoSystem()).getTemperature()); + + try { + thermoOps.TPflash(); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + } + outStream.setThermoSystem(tempFluid); + outStream.setCalculationIdentifier(id); + setCalculationIdentifier(id); + } + +} diff --git a/src/main/java/neqsim/statistics/dataAnalysis/dataSmoothing/DataSmoother.java b/src/main/java/neqsim/statistics/dataanalysis/datasmoothing/DataSmoother.java similarity index 100% rename from src/main/java/neqsim/statistics/dataAnalysis/dataSmoothing/DataSmoother.java rename to src/main/java/neqsim/statistics/dataanalysis/datasmoothing/DataSmoother.java diff --git a/src/test/java/neqsim/processSimulation/processEquipment/util/FlowSetterTest.java b/src/test/java/neqsim/processSimulation/processEquipment/util/FlowSetterTest.java new file mode 100644 index 0000000000..0f71fec185 --- /dev/null +++ b/src/test/java/neqsim/processSimulation/processEquipment/util/FlowSetterTest.java @@ -0,0 +1,53 @@ +package neqsim.processSimulation.processEquipment.util; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; +import neqsim.processSimulation.measurementDevice.MultiPhaseMeter; +import neqsim.processSimulation.processEquipment.stream.Stream; +import neqsim.thermo.system.SystemInterface; +import neqsim.thermo.system.SystemSrkEos; + +public class FlowSetterTest { + @Test + void testMain() { + SystemInterface testFluid = new SystemSrkEos(338.15, 50.0); + testFluid.addComponent("nitrogen", 1.205); + testFluid.addComponent("CO2", 1.340); + testFluid.addComponent("methane", 87.974); + testFluid.addComponent("ethane", 5.258); + testFluid.addComponent("propane", 3.283); + testFluid.addComponent("i-butane", 0.082); + testFluid.addComponent("n-butane", 0.487); + testFluid.addComponent("i-pentane", 0.056); + testFluid.addComponent("n-pentane", 1.053); + testFluid.addComponent("nC10", 4.053); + testFluid.addComponent("water", 10.00); + testFluid.setMixingRule(2); + testFluid.setMultiPhaseCheck(true); + + Stream stream_1 = new Stream("Stream1", testFluid); + stream_1.run(); + + MultiPhaseMeter multiPhaseMeter = new MultiPhaseMeter("test", stream_1); + multiPhaseMeter.setTemperature(15.0, "C"); + multiPhaseMeter.setPressure(1.01325, "bara"); + + FlowSetter flowset = new FlowSetter("flowset", stream_1); + flowset.setTemperature(15.0, "C"); + flowset.setPressure(1.01325, "bara"); + flowset.setGasFlowRate(multiPhaseMeter.getMeasuredValue("Gas Flow Rate", "Sm3/hr"), "Sm3/hr"); + flowset.setOilFlowRate(multiPhaseMeter.getMeasuredValue("Oil Flow Rate", "m3/hr"), "m3/hr"); + flowset.setWaterFlowRate(multiPhaseMeter.getMeasuredValue("Water Flow Rate", "m3/hr"), "m3/hr"); + neqsim.processSimulation.processSystem.ProcessSystem operations = + new neqsim.processSimulation.processSystem.ProcessSystem(); + operations.add(stream_1); + operations.add(multiPhaseMeter); + operations.add(flowset); + operations.run(); + + assertEquals(flowset.getOutletStream().getFlowRate("kg/sec"), stream_1.getFlowRate("kg/sec"), + 1.0); + + flowset.getOutletStream().getFluid().prettyPrint(); + } +}