Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add inflow unit #893

Merged
merged 7 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class Compressor extends TwoPortEquipment implements CompressorInterface
public SystemInterface thermoSystem;
private double outTemperature = 298.15;
private boolean useOutTemperature = false;
private double compressionRatio = 2.0;
private boolean useCompressionRatio = false;
private CompressorPropertyProfile propertyProfile = new CompressorPropertyProfile();
public double dH = 0.0;
public double inletEnthalpy = 0;
Expand Down Expand Up @@ -360,6 +362,9 @@ public void run(UUID id) {
double orginalMolarFLow = thermoSystem.getTotalNumberOfMoles();
double fractionAntiSurge = 0.0;
double kappa = 0.0;
if (useCompressionRatio) {
setOutletPressure(presinn * compressionRatio);
}
if (useOutTemperature) {
if (useRigorousPolytropicMethod) {
solveEfficiency(outTemperature);
Expand Down Expand Up @@ -668,7 +673,7 @@ public void run(UUID id) {
polytropicFluidHead =
getPower() / getThermoSystem().getFlowRate("kg/sec") / 1000.0 * getPolytropicEfficiency();
polytropicHeadMeter = polytropicFluidHead * 1000.0 / 9.81;

compressionRatio = getOutletPressure() / presinn;
setCalculationIdentifier(id);
}

Expand Down Expand Up @@ -1401,4 +1406,13 @@ public double getMaximumSpeed() {
public double getMinimumSpeed() {
return minspeed;
}

public void setCompressionRatio(double compRatio) {
this.compressionRatio = compRatio;
useCompressionRatio = true;
}

public double getCompressionRatio() {
return compressionRatio;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class PipeBeggsAndBrills extends Pipeline {
// Roughness of the pipe wall [m]
private double pipeWallRoughness = 1e-5;

// Flag to run isothermal calculations
// Flag to run isothermal calculations
private boolean runIsothermal = false;

// Flow pattern of the fluid in the pipe
Expand Down Expand Up @@ -109,7 +109,7 @@ public class PipeBeggsAndBrills extends Pipeline {

private double cumulativeElevation;

//For segment calculation
// For segment calculation
double length;
double elevation;

Expand Down Expand Up @@ -340,7 +340,7 @@ public void calculateMissingValue() {
throw new RuntimeException(
new neqsim.util.exception.InvalidInputException("PipeBeggsAndBrills", "calcMissingValue",
"elevation or length or angle", "cannot be null"));
}
}

}

Expand Down Expand Up @@ -675,7 +675,7 @@ public void run(UUID id) {
testOps.TPflash();
system.initProperties();

if (!runIsothermal){
if (!runIsothermal) {
enthalpyInlet = system.getEnthalpy();
}
double pipeInletPressure = system.getPressure();
Expand All @@ -700,7 +700,7 @@ public void run(UUID id) {
}

system.setPressure(pressureOut);
if (!runIsothermal){
if (!runIsothermal) {
testOps.PHflash(enthalpyInlet);
}
system.initProperties();
Expand All @@ -711,6 +711,21 @@ public void run(UUID id) {
outStream.setCalculationIdentifier(id);
}

/**
* {@inheritDoc}
*
* <p>
* runTransient.
* </p>
*/
@Override
public void runTransient(double dt, UUID id) {
run(id);
increaseTime(dt);
return;

}

/** {@inheritDoc} */
@Override
public void displayResult() {
Expand Down Expand Up @@ -740,14 +755,14 @@ public double getAngle() {


/**
* @return total length of the pipe in m
* @return total length of the pipe in m
*/
public double getLength() {
return cumulativeLength;
}

/**
* @return total elevation of the pipe in m
/**
* @return total elevation of the pipe in m
*/
public double getElevation() {
return cumulativeElevation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package neqsim.processSimulation.processEquipment.reservoir;

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.processSimulation.processEquipment.valve.ThrottlingValve;
import neqsim.thermo.system.SystemInterface;

/**
* <p>
* WellFlow class.
Expand All @@ -8,5 +16,93 @@
* @author asmund
* @version $Id: $Id
*/
public class WellFlow {
public class WellFlow extends TwoPortEquipment {
private static final long serialVersionUID = 1000;
static Logger logger = LogManager.getLogger(ThrottlingValve.class);
SystemInterface thermoSystem;
private double wellProductionIndex = 0;
double pressureOut = 1.0;
String pressureUnit = "bara";
boolean useWellProductionIndex = false;
boolean calcpressure = true;


/**
* <p>
* Constructor for WellFlow.
* </p>
*
* @param name a {@link java.lang.String} object
*/
public WellFlow(String name) {
super(name);
}

/** {@inheritDoc} */
@Override
public void setInletStream(StreamInterface stream) {
super.setInletStream(stream);
StreamInterface outStream = stream.clone();
outStream.setName("outStream");
super.setOutletStream(outStream);
}

/** {@inheritDoc} */
@Override
public void run(UUID id) {
thermoSystem = getInletStream().getThermoSystem().clone();
thermoSystem.setPressure(pressureOut, pressureUnit);
outStream.setThermoSystem(thermoSystem);
if (useWellProductionIndex) {
if (calcpressure) {
double presout = 1.0;
if (Math.pow(getInletStream().getPressure("bara"), 2.0)
- getInletStream().getFlowRate("MSm3/day") / wellProductionIndex > 0) {
presout = Math.sqrt(Math.pow(getInletStream().getPressure("bara"), 2.0)
- getInletStream().getFlowRate("MSm3/day") / wellProductionIndex);
} else {
logger.error("pressure lower that 0");
throw new RuntimeException(
new neqsim.util.exception.InvalidInputException("WellFlow", "run: calcOutletPressure",
"pressure", "- Outlet pressure is negative" + pressureOut));
}
// System.out.println("out pres " + presout);
outStream.setPressure(presout, "bara");
} else {
double flow = wellProductionIndex * (Math.pow(getInletStream().getPressure("bara"), 2.0)
- Math.pow(thermoSystem.getPressure("bara"), 2.0));
outStream.setFlowRate(flow, "MSm3/day");
}
} else {
wellProductionIndex = getInletStream().getFlowRate("MSm3/day")
/ (Math.pow(getInletStream().getPressure("bara"), 2.0)
- Math.pow(thermoSystem.getPressure("bara"), 2.0));
}
outStream.run();
}

/** {@inheritDoc} */
@Override
public void runTransient(double dt, UUID id) {
if (getCalculateSteadyState()) {
run(id);
increaseTime(dt);
return;
}
double flow = wellProductionIndex * (Math.pow(getInletStream().getPressure("bara"), 2.0)
- Math.pow(thermoSystem.getPressure("bara"), 2.0));

outStream.setFlowRate(flow, "MSm3/day");
outStream.run();
}

public double getWellProductionIndex() {
return wellProductionIndex;
}

public void setWellProductionIndex(double wellProductionIndex) {
useWellProductionIndex = true;
this.wellProductionIndex = wellProductionIndex;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class Adjuster extends ProcessEquipmentBaseClass {
ProcessEquipmentInterface targetEquipment = null;

String adjustedVariable = "";
String adjustedVariableUnit = "";
double maxAdjustedValue = 1e10;
double minAdjustedValue = -1e10;
String targetVariable = "";
String targetPhase = "";
String targetComponent = "";
Expand Down Expand Up @@ -59,6 +62,22 @@ public Adjuster(String name) {
super(name);
}

/**
* <p>
* setAdjustedVariable.
* </p>
*
* @param adjustedEquipment a
* {@link neqsim.processSimulation.processEquipment.ProcessEquipmentInterface} object
* @param adjstedVariable a {@link java.lang.String} object
*/
public void setAdjustedVariable(ProcessEquipmentInterface adjustedEquipment,
String adjstedVariable, String unit) {
this.adjustedEquipment = adjustedEquipment;
this.adjustedVariable = adjstedVariable;
this.adjustedVariableUnit = unit;
}

/**
* <p>
* setAdjustedVariable.
Expand Down Expand Up @@ -144,6 +163,8 @@ public void run(UUID id) {

if (adjustedVariable.equals("mass flow")) {
inputValue = ((Stream) adjustedEquipment).getThermoSystem().getFlowRate("kg/hr");
} else if (adjustedVariable.equals("flow") && adjustedVariableUnit != null) {
inputValue = ((Stream) adjustedEquipment).getThermoSystem().getFlowRate(adjustedVariableUnit);
} else {
inputValue = ((Stream) adjustedEquipment).getThermoSystem().getNumberOfMoles();
}
Expand Down Expand Up @@ -177,16 +198,30 @@ public void run(UUID id) {
if (adjustedVariable.equals("mass flow")) {
((Stream) adjustedEquipment).getThermoSystem().setTotalFlowRate(inputValue + deviation,
"kg/hr");
} else if (adjustedVariable.equals("flow") && adjustedVariableUnit != null) {
((Stream) adjustedEquipment).getThermoSystem().setTotalFlowRate(
inputValue + Math.signum(deviation) * inputValue / 100.0, adjustedVariableUnit);
} else {
((Stream) adjustedEquipment).getThermoSystem().setTotalFlowRate(inputValue + deviation,
"mol/sec");
}
} else {
double derivate = (error - oldError) / (inputValue - oldInputValue);
double newVal = error / derivate;
if (inputValue - newVal > maxAdjustedValue) {
newVal = inputValue - maxAdjustedValue;
error = 0;
}
if (inputValue - newVal < minAdjustedValue) {
newVal = inputValue - minAdjustedValue;
error = 0;
}
if (adjustedVariable.equals("mass flow")) {
((Stream) adjustedEquipment).getThermoSystem().setTotalFlowRate(inputValue - newVal,
"kg/hr");
} else if (adjustedVariable.equals("flow") && adjustedVariableUnit != null) {
((Stream) adjustedEquipment).getThermoSystem().setTotalFlowRate(inputValue - newVal,
adjustedVariableUnit);
} else {
((Stream) adjustedEquipment).getThermoSystem().setTotalFlowRate(inputValue - newVal,
"mol/sec");
Expand Down Expand Up @@ -305,4 +340,28 @@ public boolean isActivateWhenLess() {
public void setActivateWhenLess(boolean activateWhenLess) {
this.activateWhenLess = activateWhenLess;
}

public void setMaxAdjustedValue(double maxVal) {
maxAdjustedValue = maxVal;
if (maxAdjustedValue < minAdjustedValue) {
minAdjustedValue = maxAdjustedValue;
}
}

public void setMinAdjustedValue(double minVal) {
minAdjustedValue = minVal;
if (minAdjustedValue > maxAdjustedValue) {
maxAdjustedValue = minAdjustedValue;
}

}

public double getMaxAdjustedValue() {
return maxAdjustedValue;
}

public double getMinAdjustedValue() {
return minAdjustedValue;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,38 @@ public void add(ProcessEquipmentInterface operation) {
}
}

/**
* <p>
* add.
* </p>
*
*/
public void add(int position, ProcessEquipmentInterface operation) {
ArrayList<ProcessEquipmentInterface> units = this.getUnitOperations();

for (ProcessEquipmentInterface unit : units) {
if (unit == operation) {
return;
}
}

if (getAllUnitNames().contains(operation.getName())) {
String currClass = operation.getClass().getSimpleName();
int num = 1;
for (ProcessEquipmentInterface unit : units) {
if (unit.getClass().getSimpleName().equals(currClass)) {
num++;
}
}
operation.setName(currClass + Integer.toString(num));
}

getUnitOperations().add(position, operation);
if (operation instanceof ModuleInterface) {
((ModuleInterface) operation).initializeModule();
}
}

/**
* <p>
* add.
Expand Down
Loading
Loading