From 664843773eb60521b2f0b4fabfca5be0409ec886 Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Wed, 4 May 2022 07:34:44 +0200 Subject: [PATCH] added pH analyser (#401) * added pH analyser * Update pHProbe.java * updated pHprobe and separator response --- .../measurementDevice/pHProbe.java | 139 ++++++++++++------ .../util/monitor/SeparatorResponse.java | 94 +++++++----- .../measurementDevice/pHProbeTest.java | 79 ++++++++++ 3 files changed, 228 insertions(+), 84 deletions(-) create mode 100644 src/test/java/neqsim/processSimulation/measurementDevice/pHProbeTest.java diff --git a/src/main/java/neqsim/processSimulation/measurementDevice/pHProbe.java b/src/main/java/neqsim/processSimulation/measurementDevice/pHProbe.java index 04a92b18b..03e890425 100644 --- a/src/main/java/neqsim/processSimulation/measurementDevice/pHProbe.java +++ b/src/main/java/neqsim/processSimulation/measurementDevice/pHProbe.java @@ -13,61 +13,108 @@ * @version $Id: $Id */ public class pHProbe extends MeasurementDeviceBaseClass { - private static final long serialVersionUID = 1000; + private static final long serialVersionUID = 1000; - protected int streamNumber = 0; - /** Constant numberOfStreams=0 */ - protected static int numberOfStreams = 0; - protected String name = new String(); - protected StreamInterface stream = null; - protected SystemInterface reactiveThermoSystem; - protected ThermodynamicOperations thermoOps; + protected StreamInterface stream = null; + protected SystemInterface reactiveThermoSystem; + protected ThermodynamicOperations thermoOps; + private double alkanility = 0.0; - /** - *

- * Constructor for pHProbe. - *

- */ - public pHProbe() {} + /** + *

+ * Constructor for pHProbe. + *

+ */ + public pHProbe() {} - /** - *

- * Constructor for pHProbe. - *

- * - * @param stream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} - * object - */ - public pHProbe(StreamInterface stream) { - this.stream = stream; - numberOfStreams++; - streamNumber = numberOfStreams; - } + /** + *

+ * Constructor for pHProbe. + *

+ * + * @param stream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object + */ + public pHProbe(StreamInterface stream) { + this.stream = stream; + } + + /** + *

+ * run. + *

+ */ + public void run() { - /** - *

- * run. - *

- */ - public void run() { - if (stream != null) { - reactiveThermoSystem = - this.stream.getThermoSystem().setModel("Electrolyte-CPA-EOS-statoil"); + if (stream != null) { + if (stream.getFluid().hasPhaseType("aqueous")) { + reactiveThermoSystem = stream.getFluid().clone(); + // reactiveThermoSystem = stream.getFluid().phaseToSystem("aqueous"); + reactiveThermoSystem = reactiveThermoSystem.setModel("Electrolyte-CPA-EOS-statoil"); + if (getAlkanility() > 1e-10) { + double waterkg = reactiveThermoSystem.getComponent("water").getTotalFlowRate("kg/sec"); + reactiveThermoSystem.addComponent("Na+", waterkg * getAlkanility() / 1e3); + reactiveThermoSystem.addComponent("OH-", waterkg * getAlkanility() / 1e3); + } + if (!reactiveThermoSystem.isChemicalSystem()) { + reactiveThermoSystem.chemicalReactionInit(); + reactiveThermoSystem.setMixingRule(10); + reactiveThermoSystem.setMultiPhaseCheck(false); } thermoOps = new ThermodynamicOperations(reactiveThermoSystem); thermoOps.TPflash(); + } else + return; } + } - /** {@inheritDoc} */ - @Override - public void displayResult() { - System.out.println("measured temperature " + stream.getTemperature()); - } + /** {@inheritDoc} */ + @Override + public void displayResult() { + System.out.println("measured temperature " + stream.getTemperature()); + } - /** {@inheritDoc} */ - @Override - public double getMeasuredValue() { + /** {@inheritDoc} */ + @Override + public double getMeasuredValue() { + if (stream != null) { + if (stream.getFluid().hasPhaseType("aqueous")) { + reactiveThermoSystem = stream.getFluid().clone(); + // reactiveThermoSystem = stream.getFluid().phaseToSystem("aqueous"); + reactiveThermoSystem = reactiveThermoSystem.setModel("Electrolyte-CPA-EOS-statoil"); + if (getAlkanility() > 1e-10) { + double waterkg = reactiveThermoSystem.getComponent("water").getTotalFlowRate("kg/sec"); + reactiveThermoSystem.addComponent("Na+", waterkg * getAlkanility() / 1e3); + reactiveThermoSystem.addComponent("OH-", waterkg * getAlkanility() / 1e3); + } + if (!reactiveThermoSystem.isChemicalSystem()) { + reactiveThermoSystem.chemicalReactionInit(); + reactiveThermoSystem.setMixingRule(10); + reactiveThermoSystem.setMultiPhaseCheck(false); + } + thermoOps = new ThermodynamicOperations(reactiveThermoSystem); + thermoOps.TPflash(); return reactiveThermoSystem.getPhase(reactiveThermoSystem.getPhaseNumberOfPhase("aqueous")) - .getpH(); - } + .getpH(); + } else { + System.out.println("no aqueous phase for pH analyser"); + return 7.0; + } + } else + System.out.println("no stream connected to pH analyser"); + return Double.NaN; + } + + /** + * @return the alkanility + */ + public double getAlkanility() { + return alkanility; + } + + /** + * @param alkanility the alkanility to set + */ + public void setAlkanility(double alkanility) { + this.alkanility = alkanility; + } } diff --git a/src/main/java/neqsim/processSimulation/util/monitor/SeparatorResponse.java b/src/main/java/neqsim/processSimulation/util/monitor/SeparatorResponse.java index a79ac5d43..756230a71 100644 --- a/src/main/java/neqsim/processSimulation/util/monitor/SeparatorResponse.java +++ b/src/main/java/neqsim/processSimulation/util/monitor/SeparatorResponse.java @@ -12,47 +12,65 @@ * @version $Id: $Id */ public class SeparatorResponse { - public String name; - public Double gasLoadFactor; - public Double massflow; - public Fluid gasFluid, oilFluid; + public String name; + public Double gasLoadFactor; + public Double massflow; + public Fluid gasFluid, liquidFluid, oilFluid, waterFluid; - /** - *

- * Constructor for SeparatorResponse. - *

- */ - public SeparatorResponse() {} + /** + *

+ * Constructor for SeparatorResponse. + *

+ */ + public SeparatorResponse() {} - /** - *

- * Constructor for SeparatorResponse. - *

- * - * @param inputSeparator a - * {@link neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator} object - */ - public SeparatorResponse(ThreePhaseSeparator inputSeparator) { - name = inputSeparator.getName(); - massflow = inputSeparator.getFluid().getFlowRate("kg/hr"); - gasLoadFactor = inputSeparator.getGasLoadFactor(); - oilFluid = new Fluid(inputSeparator.getOilOutStream().getFluid()); - gasFluid = new Fluid(inputSeparator.getGasOutStream().getFluid()); + /** + *

+ * Constructor for SeparatorResponse. + *

+ * + * @param inputSeparator a + * {@link neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator} object + */ + public SeparatorResponse(ThreePhaseSeparator inputSeparator) { + name = inputSeparator.getName(); + massflow = inputSeparator.getFluid().getFlowRate("kg/hr"); + gasLoadFactor = inputSeparator.getGasLoadFactor(); + if (inputSeparator.getThermoSystem().hasPhaseType("aqueous")) { + waterFluid = new Fluid(inputSeparator.getWaterOutStream().getFluid()); } + if (inputSeparator.getThermoSystem().hasPhaseType("oil")) { + oilFluid = new Fluid(inputSeparator.getOilOutStream().getFluid()); + } + if (inputSeparator.getThermoSystem().hasPhaseType("gas")) { + gasFluid = new Fluid(inputSeparator.getGasOutStream().getFluid()); + } + } - /** - *

- * Constructor for SeparatorResponse. - *

- * - * @param inputSeparator a {@link neqsim.processSimulation.processEquipment.separator.Separator} - * object - */ - public SeparatorResponse(Separator inputSeparator) { - name = inputSeparator.getName(); - massflow = inputSeparator.getFluid().getFlowRate("kg/hr"); - gasLoadFactor = inputSeparator.getGasLoadFactor(); - oilFluid = new Fluid(inputSeparator.getLiquidOutStream().getFluid()); - gasFluid = new Fluid(inputSeparator.getGasOutStream().getFluid()); + /** + *

+ * Constructor for SeparatorResponse. + *

+ * + * @param inputSeparator a {@link neqsim.processSimulation.processEquipment.separator.Separator} + * object + */ + public SeparatorResponse(Separator inputSeparator) { + name = inputSeparator.getName(); + massflow = inputSeparator.getFluid().getFlowRate("kg/hr"); + gasLoadFactor = inputSeparator.getGasLoadFactor(); + if (inputSeparator.getThermoSystem().hasPhaseType("aqueous")) { + waterFluid = new Fluid(inputSeparator.getThermoSystem().phaseToSystem("aqueous")); + } + if (inputSeparator.getThermoSystem().hasPhaseType("oil")) { + oilFluid = new Fluid(inputSeparator.getThermoSystem().phaseToSystem("oil")); + } + if (inputSeparator.getThermoSystem().hasPhaseType("gas")) { + gasFluid = new Fluid(inputSeparator.getGasOutStream().getFluid()); + } + if (inputSeparator.getThermoSystem().hasPhaseType("oil") + || inputSeparator.getThermoSystem().hasPhaseType("aqueous")) { + liquidFluid = new Fluid(inputSeparator.getLiquidOutStream().getFluid()); } + } } diff --git a/src/test/java/neqsim/processSimulation/measurementDevice/pHProbeTest.java b/src/test/java/neqsim/processSimulation/measurementDevice/pHProbeTest.java new file mode 100644 index 000000000..68b8d2b27 --- /dev/null +++ b/src/test/java/neqsim/processSimulation/measurementDevice/pHProbeTest.java @@ -0,0 +1,79 @@ +package neqsim.processSimulation.measurementDevice; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import neqsim.processSimulation.processEquipment.stream.Stream; +import neqsim.thermo.system.SystemInterface; +import neqsim.thermo.system.SystemSrkCPAstatoil; +import neqsim.thermo.system.SystemSrkEos; + +class pHProbeTest { + + @BeforeAll + static void setUpBeforeClass() throws Exception {} + + @Test + void testGetMeasuredValue() { + SystemInterface testFluid = new SystemSrkCPAstatoil(318.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", 14.053); + testFluid.addComponent("water", 141.053); + testFluid.setMixingRule(10); + testFluid.setMultiPhaseCheck(true); + + Stream stream_1 = new Stream("Stream1", testFluid); + stream_1.run(); + + pHProbe phmeasurement = new pHProbe(stream_1); + phmeasurement.run(); + System.out.println("pH " + phmeasurement.getMeasuredValue()); + assertEquals(4.079098133484792, phmeasurement.getMeasuredValue(),0.01); + } + + @Test + void testGetMeasuredValueWithAlkanility() { + SystemInterface testFluid = new SystemSrkCPAstatoil(318.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", 14.053); + testFluid.addComponent("water", 141.053); + testFluid.setMixingRule(10); + testFluid.setMultiPhaseCheck(true); + + Stream stream_1 = new Stream("Stream1", testFluid); + stream_1.run(); + + pHProbe phmeasurement = new pHProbe(stream_1); + phmeasurement.setAlkanility(50.0); + phmeasurement.run(); + System.out.println("pH " + phmeasurement.getMeasuredValue()); + assertEquals(5.629055432357595, phmeasurement.getMeasuredValue(),0.01); + } + + @Test + void testPHProbe() { + //fail("Not yet implemented"); + } + + @Test + void testPHProbeStreamInterface() { + //fail("Not yet implemented"); + } + +}