Skip to content

Commit

Permalink
bug fix suggestion.
Browse files Browse the repository at this point in the history
Bug had to do when we create a stream from another stream (as we do for stream2). Then we set temperature and pressure on it - but it does not set it on the correct stream
  • Loading branch information
EvenSol committed Feb 16, 2024
1 parent ffb996a commit 55a2dfa
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class MultiPhaseMeter extends StreamMeasurementDeviceBaseClass {
private static final long serialVersionUID = 1000;
static Logger logger = LogManager.getLogger(MultiPhaseMeter.class);

double pressure = 10.0;
double temperature = 298.15;
double pressure = 1.01325;
double temperature = 288.15;
String unitT;
String unitP;

Expand Down Expand Up @@ -111,15 +111,15 @@ public double getMeasuredValue(String unit) {
*/
public double getMeasuredValue(String measurement, String unit) {
if (measurement.equals("mass rate")) {
return stream.getThermoSystem().getFlowRate(unit);
return stream.getFlowRate(unit);
}

if (stream.getThermoSystem().getFlowRate("kg/hr") < 1e-10) {
if (stream.getFlowRate("kg/hr") < 1e-10) {
return Double.NaN;
}

if (measurement.equals("GOR")) {
SystemInterface tempFluid = stream.getThermoSystem().clone();
SystemInterface tempFluid = stream.getFluid().clone();
tempFluid.setTemperature(temperature, unitT);
tempFluid.setPressure(pressure, unitP);
ThermodynamicOperations thermoOps = new ThermodynamicOperations(tempFluid);
Expand Down Expand Up @@ -249,13 +249,14 @@ public double getMeasuredValue(String measurement, String unit) {
}
tempFluid.initPhysicalProperties("density");

double GOR_in_sm3_sm3 = tempFluid.getPhase("gas").getFlowRate("Sm3/hr")/tempFluid.getPhase("oil").getFlowRate("Sm3/hr");
double GOR_in_sm3_sm3 = tempFluid.getPhase("gas").getFlowRate("Sm3/hr")
/ tempFluid.getPhase("oil").getFlowRate("m3/hr");
double GOR_via_corrected_volume = tempFluid.getPhase("gas").getCorrectedVolume()
/ tempFluid.getPhase("oil").getCorrectedVolume();
/ tempFluid.getPhase("oil").getCorrectedVolume();


System.out.println("Stream 2 (results inside MPM) " + " GOR sm3/sm3 " + GOR_in_sm3_sm3 + " GOR Corrected by volume "
+ GOR_via_corrected_volume);
System.out.println("Stream 2 (results inside MPM) " + " GOR sm3/sm3 " + GOR_in_sm3_sm3
+ " GOR Corrected by volume " + GOR_via_corrected_volume);

System.out.println("Stream 2 (results inside MPM) getPhase(gas).getCorrectedVolume() "
+ tempFluid.getPhase("gas").getCorrectedVolume());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ public Stream() {
* Constructor for Stream.
* </p>
*
* @param stream a
* {@link neqsim.processSimulation.processEquipment.stream.StreamInterface}
* object
* @param stream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object
*/
@Deprecated
public Stream(StreamInterface stream) {
Expand Down Expand Up @@ -87,13 +85,12 @@ public Stream(String name) {
/**
* Constructor for Stream.
*
* @param name name of stream
* @param name name of stream
* @param stream input stream
*/
public Stream(String name, StreamInterface stream) {
this(name);
this.setStream(stream);
thermoSystem = stream.getThermoSystem();
numberOfStreams++;
streamNumber = numberOfStreams;
}
Expand All @@ -103,7 +100,7 @@ public Stream(String name, StreamInterface stream) {
* Constructor for Stream.
* </p>
*
* @param name a {@link java.lang.String} object
* @param name a {@link java.lang.String} object
* @param thermoSystem a {@link neqsim.thermo.system.SystemInterface} object
*/
public Stream(String name, SystemInterface thermoSystem) {
Expand Down Expand Up @@ -138,12 +135,12 @@ public void setGasQuality(double gasQuality) {
/** {@inheritDoc} */
@Override
public double getHydrateEquilibriumTemperature() {
if (!thermoSystem.getPhase(0).hasComponent("water")) {
if (!getFluid().getPhase(0).hasComponent("water")) {
System.out.println("ny hydrate: no water in stream: " + name);
return 0.0;
}
try {
SystemInterface copySystem = thermoSystem.clone();
SystemInterface copySystem = getFluid().clone();
copySystem.setHydrateCheck(true);
ThermodynamicOperations thermoOps = new ThermodynamicOperations(copySystem);
thermoOps.hydrateFormationTemperature();
Expand All @@ -163,7 +160,7 @@ public double getHydrateEquilibriumTemperature() {
* @return a double
*/
public double getSolidFormationTemperature(String solidName) {
SystemInterface copySystem = thermoSystem.clone();
SystemInterface copySystem = getFluid().clone();

try {
if (solidName.equals("hydrate")) {
Expand Down Expand Up @@ -195,14 +192,14 @@ public Stream clone() {
if (stream != null) {
clonedSystem.setStream((Stream) stream.clone());
}
clonedSystem.thermoSystem = getThermoSystem().clone();
clonedSystem.thermoSystem = getFluid().clone();
return clonedSystem;
}

/** {@inheritDoc} */
@Override
public double getTemperature() {
return thermoSystem.getTemperature();
return getFluid().getTemperature();
}

/** {@inheritDoc} */
Expand All @@ -214,7 +211,7 @@ public double getTemperature(String unit) {
/** {@inheritDoc} */
@Override
public double getPressure() {
return thermoSystem.getPressure();
return getFluid().getPressure();
}

/** {@inheritDoc} */
Expand All @@ -226,23 +223,29 @@ public double getPressure(String unit) {
/** {@inheritDoc} */
@Override
public double getMolarRate() {
return thermoSystem.getTotalNumberOfMoles();
return getFluid().getTotalNumberOfMoles();
}

/** {@inheritDoc} */
@Override
public void setThermoSystem(SystemInterface thermoSystem) {
this.thermoSystem = thermoSystem;
// TODO: when is stream not null?
if (stream != null) {
stream.setThermoSystem(thermoSystem);
} else {
this.thermoSystem = thermoSystem;
}
// TODO: when is stream not null?

}

/** {@inheritDoc} */
@Override
public void setFluid(SystemInterface fluid) {
this.setThermoSystem(fluid);
if (stream != null) {
stream.setFluid(fluid);
} else {
this.setThermoSystem(fluid);
}
}

/** {@inheritDoc} */
Expand All @@ -255,7 +258,8 @@ public void setThermoSystemFromPhase(SystemInterface thermoSystem, String phaseT
} else if (thermoSystem.hasPhaseType("oil")) {
this.thermoSystem = thermoSystem.phaseToSystem(thermoSystem.getPhaseNumberOfPhase("oil"));
} else if (thermoSystem.hasPhaseType("aqueous")) {
this.thermoSystem = thermoSystem.phaseToSystem(thermoSystem.getPhaseNumberOfPhase("aqueous"));
this.thermoSystem =
thermoSystem.phaseToSystem(thermoSystem.getPhaseNumberOfPhase("aqueous"));
} else {
System.out.println("no phase of type " + phaseTypeName);
System.out.println("...returning empty system ");
Expand All @@ -282,7 +286,7 @@ public void setEmptyThermoSystem(SystemInterface thermoSystem) {
/** {@inheritDoc} */
@Override
public SystemInterface getThermoSystem() {
return this.thermoSystem;
return this.getFluid();
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -310,9 +314,9 @@ public void runTPflash() {
thermoSystem = this.stream.getThermoSystem().clone();
}

ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem);
ThermodynamicOperations thermoOps = new ThermodynamicOperations(getFluid());
thermoOps.TPflash();
thermoSystem.initProperties();
getFluid().initProperties();
}

/** {@inheritDoc} */
Expand All @@ -336,13 +340,11 @@ public boolean needRecalculation() {
@Override
public void run(UUID id) {
// System.out.println("start flashing stream... " + streamNumber);
if (stream != null) {
thermoSystem = this.stream.getThermoSystem().clone();
}
thermoSystem = getFluid().clone();

ThermodynamicOperations thermoOps = new ThermodynamicOperations(thermoSystem);

if (stream != null && getThermoSystem().getNumberOfComponents() == 1
&& getSpecification().equals("TP")) {
if (thermoSystem.getNumberOfComponents() == 1 && getSpecification().equals("TP")) {
setSpecification("PH");
}
if (getSpecification().equals("TP")) {
Expand All @@ -368,7 +370,8 @@ && getSpecification().equals("TP")) {
double gasEnthalpy = thermoSystem.getPhase(0).getEnthalpy();
double liquidEnthalpy = thermoSystem.getPhase(1).getEnthalpy();

double enthalpySpec = getGasQuality() * gasEnthalpy + (1.0 - getGasQuality()) * liquidEnthalpy;
double enthalpySpec =
getGasQuality() * gasEnthalpy + (1.0 - getGasQuality()) * liquidEnthalpy;
thermoOps.PHflash(enthalpySpec);
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
Expand All @@ -390,7 +393,7 @@ && getSpecification().equals("TP")) {
}
} else if (getSpecification().equals("PH")) {
try {
thermoOps.PHflash(getThermoSystem().getEnthalpy(), 0);
thermoOps.PHflash(thermoSystem.getEnthalpy(), 0);
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
thermoOps.TPflash();
Expand All @@ -401,10 +404,13 @@ && getSpecification().equals("TP")) {

thermoSystem.initProperties();

lastFlowRate = getFluid().getFlowRate("kg/hr");
lastTemperature = getFluid().getTemperature();
lastPressure = getFluid().getPressure();
lastFlowRate = thermoSystem.getFlowRate("kg/hr");
lastTemperature = thermoSystem.getTemperature();
lastPressure = thermoSystem.getPressure();

if (stream != null) {
stream.setFluid(thermoSystem);
}
// System.out.println("number of phases: " + thermoSystem.getNumberOfPhases());
// System.out.println("beta: " + thermoSystem.getBeta());
setCalculationIdentifier(id);
Expand All @@ -413,7 +419,7 @@ && getSpecification().equals("TP")) {
/** {@inheritDoc} */
@Override
public void displayResult() {
thermoSystem.display(name);
getFluid().display(name);
}

/**
Expand All @@ -424,7 +430,7 @@ public void displayResult() {
* @return an array of {@link java.lang.String} objects
*/
public String[][] getResultTable() {
return thermoSystem.getResultTable();
return getFluid().getResultTable();
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -458,7 +464,7 @@ public void runController(double dt, UUID id) {
/** {@inheritDoc} */
@Override
public void flashStream() {
ThermodynamicOperations ops = new ThermodynamicOperations(thermoSystem);
ThermodynamicOperations ops = new ThermodynamicOperations(getFluid());
ops.TPflash();
}

Expand All @@ -468,7 +474,7 @@ public void flashStream() {
* </p>
*/
public void phaseEnvelope() {
SystemInterface localSyst = thermoSystem.clone();
SystemInterface localSyst = getFluid().clone();
ThermodynamicOperations ops = new ThermodynamicOperations(localSyst);
ops.setRunAsThread(true);
ops.calcPTphaseEnvelope(true);
Expand All @@ -480,7 +486,7 @@ public void phaseEnvelope() {
/** {@inheritDoc} */
@Override
public double CCB(String unit) {
SystemInterface localSyst = thermoSystem.clone();
SystemInterface localSyst = getFluid().clone();
ThermodynamicOperations ops = new ThermodynamicOperations(localSyst);
ops.setRunAsThread(true);
ops.calcPTphaseEnvelope(true);
Expand All @@ -501,7 +507,7 @@ public double CCB(String unit) {
/** {@inheritDoc} */
@Override
public double CCT(String unit) {
SystemInterface localSyst = thermoSystem.clone();
SystemInterface localSyst = getFluid().clone();
ThermodynamicOperations ops = new ThermodynamicOperations(localSyst);
ops.setRunAsThread(true);
ops.calcPTphaseEnvelope(true);
Expand All @@ -522,7 +528,7 @@ public double CCT(String unit) {
/** {@inheritDoc} */
@Override
public double TVP(double temperature, String unit) {
SystemInterface localSyst = thermoSystem.clone();
SystemInterface localSyst = getFluid().clone();
localSyst.setTemperature(temperature, unit);
ThermodynamicOperations ops = new ThermodynamicOperations(localSyst);
try {
Expand All @@ -535,7 +541,7 @@ public double TVP(double temperature, String unit) {
/** {@inheritDoc} */
@Override
public String[][] reportResults() {
return thermoSystem.getResultTable();
return getFluid().getResultTable();
}

/**
Expand All @@ -544,9 +550,9 @@ public String[][] reportResults() {
* </p>
*
* @param propertyName a {@link java.lang.String} object
* @param unit a {@link java.lang.String} object
* @param phase a {@link java.lang.String} object
* @param component a {@link java.lang.String} object
* @param unit a {@link java.lang.String} object
* @param phase a {@link java.lang.String} object
* @param component a {@link java.lang.String} object
* @return a {@link java.lang.Object} object
*/
public Object getProperty(String propertyName, String unit, String phase, String component) {
Expand All @@ -560,7 +566,7 @@ public Object getProperty(String propertyName, String unit, String phase, String
/** {@inheritDoc} */
@Override
public double GCV() {
Standard_ISO6976 standard = new Standard_ISO6976(thermoSystem.clone(), 0, 15.55, "volume");
Standard_ISO6976 standard = new Standard_ISO6976(getFluid().clone(), 0, 15.55, "volume");
standard.setReferenceState("real");
standard.calculate();
return standard.getValue("GCV") * 1.0e3;
Expand All @@ -569,7 +575,7 @@ public double GCV() {
/** {@inheritDoc} */
@Override
public double LCV() {
Standard_ISO6976 standard = new Standard_ISO6976(thermoSystem.clone(), 0, 15.55, "volume");
Standard_ISO6976 standard = new Standard_ISO6976(getFluid().clone(), 0, 15.55, "volume");
standard.setReferenceState("real");
standard.calculate();
return standard.getValue("InferiorCalorificValue") * 1.0e3;
Expand All @@ -580,12 +586,20 @@ public double LCV() {
* Setter for the field <code>stream</code>.
* </p>
*
* @param stream a
* {@link neqsim.processSimulation.processEquipment.stream.StreamInterface}
* object
* @param stream a {@link neqsim.processSimulation.processEquipment.stream.StreamInterface} object
*/
public void setStream(StreamInterface stream) {
this.stream = stream;
}

/** {@inheritDoc} */
@Override
public SystemInterface getFluid() {
if (stream != null) {
return stream.getFluid();
} else {
return thermoSystem;
}
}

}

0 comments on commit 55a2dfa

Please sign in to comment.