Skip to content

Commit

Permalink
added flow setter
Browse files Browse the repository at this point in the history
  • Loading branch information
EvenSol committed Nov 7, 2023
1 parent 5e0caba commit acab8bd
Show file tree
Hide file tree
Showing 3 changed files with 293 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,42 @@ 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("gasDensity") || measurement.equals("oilDensity")
|| measurement.equals("waterDensity")) {
SystemInterface tempFluid = stream.getThermoSystem().clone();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
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;

/**
* <p>
* FlowSetter class.
* </p>
*
* @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
/**
* <p>
* Constructor for FlowSetter.
* </p>
*/
public FlowSetter() {
super("Flow Setter");
}

/**
* <p>
* Constructor for FlowSetter.
* </p>
*
* @param stream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object
*/
@Deprecated
public FlowSetter(StreamInterface stream) {
this("Flow Setter", stream);
}

/**
* <p>
* Constructor for FlowSetter.
* </p>
*
* @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}
*
* <p>
* Setter for the field <code>inletStream</code>.
* </p>
*/
public void setInletStream(StreamInterface inletStream) {
this.inStream = inletStream;
try {
this.outStream = inletStream.clone();
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
}

/**
* <p>
* Getter for the field <code>pressure</code>.
* </p>
*
* @return a double
*/
public double getPressure() {
return pressure;
}

/**
* <p>
* Setter for the field <code>pressure</code>.
* </p>
*
* @param pressure a double
* @param unitP a {@link java.lang.String} object
*/
public void setPressure(double pressure, String unitP) {
this.pressure = pressure;
this.unitP = unitP;
}

/**
* <p>
* getTemperature.
* </p>
*
* @return a double
*/
public double getTemperature() {
return temperature;
}

/**
* <p>
* Setter for the field <code>temperature</code>.
* </p>
*
* @param temperature a double
* @param unitT a {@link java.lang.String} object
*/
public void setTemperature(double temperature, String unitT) {
this.temperature = temperature;
this.unitT = unitT;
}

public void setGasFlowRate(double flowRate, String flowUnit) {
gasFlowRate = flowRate;
unitGasFlowRate = flowUnit;
}

public double getGasFlowRate(String flowUnit) {
return gasFlowRate;
}

public void setOilFlowRate(double flowRate, String flowUnit) {
oilFlowRate = flowRate;
unitOilFlowRate = flowUnit;
}

public double getOilFlowRate(String flowUnit) {
return oilFlowRate;
}

public void setWaterFlowRate(double flowRate, String flowUnit) {
waterFlowRate = flowRate;
unitWaterFlowRate = flowUnit;
}

public double getWaterFlowRate(String flowUnit) {
return waterFlowRate;
}

/** {@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("Sm3/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]);
}
tempFluid.setPressure((inStream.getThermoSystem()).getPressure());
tempFluid.setTemperature((inStream.getThermoSystem()).getTemperature());
tempFluid.setTotalFlowRate(flow, "kg/sec");
try {
thermoOps.TPflash();
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
outStream.setThermoSystem(tempFluid);
outStream.setCalculationIdentifier(id);
setCalculationIdentifier(id);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package neqsim.processSimulation.processEquipment.util;

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.setMixingRule(2);
testFluid.setMultiPhaseCheck(true);

testFluid.setTemperature(90.0, "C");
testFluid.setPressure(60.0, "bara");
testFluid.setTotalFlowRate(1e6, "kg/hr");

Stream stream_1 = new Stream("Stream1", testFluid);
stream_1.run();

MultiPhaseMeter multiPhaseMeter = new MultiPhaseMeter("test", stream_1);
multiPhaseMeter.setTemperature(90.0, "C");
multiPhaseMeter.setPressure(60.0, "bara");

FlowSetter flowset = new FlowSetter("flowset", stream_1);
flowset.setGasFlowRate(multiPhaseMeter.getMeasuredValue("Gas Flow Rate", "Sm3/hr"), "Sm3/hr");
flowset.setOilFlowRate(multiPhaseMeter.getMeasuredValue("Oil Flow Rate", "Sm3/hr"), "Sm3/hr");

neqsim.processSimulation.processSystem.ProcessSystem operations =
new neqsim.processSimulation.processSystem.ProcessSystem();
operations.add(stream_1);
operations.add(multiPhaseMeter);
operations.add(flowset);
operations.run();
}
}

0 comments on commit acab8bd

Please sign in to comment.