Skip to content

Commit

Permalink
added pH analyser (#401)
Browse files Browse the repository at this point in the history
* added pH analyser

* Update pHProbe.java

* updated pHprobe and separator response
  • Loading branch information
EvenSol authored May 4, 2022
1 parent 3e1ada1 commit 6648437
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 84 deletions.
139 changes: 93 additions & 46 deletions src/main/java/neqsim/processSimulation/measurementDevice/pHProbe.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>numberOfStreams=0</code> */
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;

/**
* <p>
* Constructor for pHProbe.
* </p>
*/
public pHProbe() {}
/**
* <p>
* Constructor for pHProbe.
* </p>
*/
public pHProbe() {}

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

/**
* <p>
* run.
* </p>
*/
public void run() {

/**
* <p>
* run.
* </p>
*/
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* <p>
* Constructor for SeparatorResponse.
* </p>
*/
public SeparatorResponse() {}
/**
* <p>
* Constructor for SeparatorResponse.
* </p>
*/
public SeparatorResponse() {}

/**
* <p>
* Constructor for SeparatorResponse.
* </p>
*
* @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());
/**
* <p>
* Constructor for SeparatorResponse.
* </p>
*
* @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());
}
}

/**
* <p>
* Constructor for SeparatorResponse.
* </p>
*
* @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());
/**
* <p>
* Constructor for SeparatorResponse.
* </p>
*
* @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());
}
}
}
Original file line number Diff line number Diff line change
@@ -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");
}

}

0 comments on commit 6648437

Please sign in to comment.