Skip to content

Commit

Permalink
Merge branch 'equinor:master' into getcompname
Browse files Browse the repository at this point in the history
  • Loading branch information
asmfstatoil authored Feb 4, 2025
2 parents f12d319 + 31b92d3 commit 23e8b5a
Show file tree
Hide file tree
Showing 30 changed files with 2,892 additions and 1,243 deletions.
163 changes: 163 additions & 0 deletions src/main/java/neqsim/process/equipment/diffpressure/Orifice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package neqsim.process.equipment.diffpressure;

import java.util.UUID;
import neqsim.process.equipment.TwoPortEquipment;
import neqsim.process.equipment.stream.StreamInterface;
import neqsim.thermo.system.SystemInterface;

public class Orifice extends TwoPortEquipment {
private static final long serialVersionUID = 1L;
private StreamInterface inputstream;
private StreamInterface outputstream;
private Double dp;
private Double diameter;
private Double diameter_outer;
private Double C;
private double orificeDiameter;
private double pressureUpstream;
private double pressureDownstream;
private double dischargeCoefficient;

public Orifice(String name) {
super(name);
}

public Orifice(String name, double diameter, double orificeDiameter, double pressureUpstream,
double pressureDownstream, double dischargeCoefficient) {
super(name);
this.diameter = diameter;
this.orificeDiameter = orificeDiameter;
this.pressureUpstream = pressureUpstream;
this.pressureDownstream = pressureDownstream;
this.dischargeCoefficient = dischargeCoefficient;
}

public void setOrificeParameters(Double diameter, Double diameter_outer, Double C) {
this.diameter = diameter;
this.diameter_outer = diameter_outer;
this.C = C;
}

public Double calc_dp() {
double beta = orificeDiameter / diameter;
double beta2 = beta * beta;
double beta4 = beta2 * beta2;
double dP = pressureUpstream - pressureDownstream;

double deltaW = (Math.sqrt(1.0 - beta4 * (1.0 - dischargeCoefficient * dischargeCoefficient))
- dischargeCoefficient * beta2)
/ (Math.sqrt(1.0 - beta4 * (1.0 - dischargeCoefficient * dischargeCoefficient))
+ dischargeCoefficient * beta2)
* dP;

return deltaW;
}

/**
* Calculates the orifice discharge coefficient using the Reader-Harris Gallagher method.
*
* @param D Upstream internal pipe diameter, in meters.
* @param Do Diameter of orifice at flow conditions, in meters.
* @param rho Density of fluid at P1, in kg/m^3.
* @param mu Viscosity of fluid at P1, in Pa*s.
* @param m Mass flow rate of fluid through the orifice, in kg/s.
* @param taps Tap type ("corner", "flange", "D", or "D/2").
* @return Discharge coefficient of the orifice.
*/
public static double calculateDischargeCoefficient(double D, double Do, double rho, double mu,
double m, String taps) {
double A_pipe = 0.25 * Math.PI * D * D;
double v = m / (A_pipe * rho);
double Re_D = rho * v * D / mu;
double beta = Do / D;
double beta2 = beta * beta;
double beta4 = beta2 * beta2;
double beta8 = beta4 * beta4;

double L1;
double L2_prime;
if ("corner".equalsIgnoreCase(taps)) {
L1 = 0.0;
L2_prime = 0.0;
} else if ("flange".equalsIgnoreCase(taps)) {
L1 = L2_prime = 0.0254 / D;
} else if ("D".equalsIgnoreCase(taps) || "D/2".equalsIgnoreCase(taps)) {
L1 = 1.0;
L2_prime = 0.47;
} else {
throw new IllegalArgumentException("Unsupported tap type: " + taps);
}

double A = Math.pow(19000 * beta / Re_D, 0.8);
double M2_prime = 2.0 * L2_prime / (1.0 - beta);

double deltaCUpstream = ((0.043 + 0.08 * Math.exp(-10 * L1) - 0.123 * Math.exp(-7 * L1))
* (1.0 - 0.11 * A) * beta4 / (1.0 - beta4));

double deltaCDownstream =
-0.031 * (M2_prime - 0.8 * Math.pow(M2_prime, 1.1)) * Math.pow(beta, 1.3);
double C_inf_C_s =
0.5961 + 0.0261 * beta2 - 0.216 * beta8 + 0.000521 * Math.pow(1e6 * beta / Re_D, 0.7)
+ (0.0188 + 0.0063 * A) * Math.pow(beta, 3.5) * Math.pow(1e6 / Re_D, 0.3);

return C_inf_C_s + deltaCUpstream + deltaCDownstream;
}

/**
* Calculates the expansibility factor for orifice plate calculations.
*
* @param D Upstream internal pipe diameter, in meters.
* @param Do Diameter of orifice at flow conditions, in meters.
* @param P1 Static pressure of fluid upstream, in Pa.
* @param P2 Static pressure of fluid downstream, in Pa.
* @param k Isentropic exponent of fluid.
* @return Expansibility factor (1 for incompressible fluids).
*/
public static double calculateExpansibility(double D, double Do, double P1, double P2, double k) {
double beta = Do / D;
double beta4 = Math.pow(beta, 4);
return 1.0 - (0.351 + beta4 * (0.93 * beta4 + 0.256)) * (1.0 - Math.pow(P2 / P1, 1.0 / k));
}

/**
* Calculates the non-recoverable pressure drop across the orifice plate.
*
* @param D Upstream internal pipe diameter, in meters.
* @param Do Diameter of orifice at flow conditions, in meters.
* @param P1 Static pressure of fluid upstream, in Pa.
* @param P2 Static pressure of fluid downstream, in Pa.
* @param C Discharge coefficient.
* @return Non-recoverable pressure drop, in Pa.
*/
public static double calculatePressureDrop(double D, double Do, double P1, double P2, double C) {
double beta = Do / D;
double beta2 = beta * beta;
double beta4 = beta2 * beta2;
double dP = P1 - P2;
double deltaW = (Math.sqrt(1.0 - beta4 * (1.0 - C * C)) - C * beta2)
/ (Math.sqrt(1.0 - beta4 * (1.0 - C * C)) + C * beta2) * dP;
return deltaW;
}

/**
* Calculates the diameter ratio (beta) of the orifice plate.
*
* @param D Upstream internal pipe diameter, in meters.
* @param Do Diameter of orifice at flow conditions, in meters.
* @return Diameter ratio (beta).
*/
public static double calculateBetaRatio(double D, double Do) {
return Do / D;
}

@Override
public void run(UUID uuid) {
if (inputstream != null && outputstream != null) {
double newPressure = inputstream.getPressure("bara") - calc_dp();
SystemInterface outfluid = (SystemInterface) inStream.clone();
outfluid.setPressure(newPressure);
outStream.setFluid(outfluid);
outStream.run();
}
}
}
21 changes: 19 additions & 2 deletions src/main/java/neqsim/process/equipment/pump/Pump.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class Pump extends TwoPortEquipment implements PumpInterface {
public double isentropicEfficiency = 1.0;
public boolean powerSet = false;
private String pressureUnit = "bara";
private PumpChart pumpChart = new PumpChart();
private PumpChartInterface pumpChart = new PumpChart();

/**
* Constructor for Pump.
Expand Down Expand Up @@ -439,7 +439,7 @@ public double getSpeed() {
*
* @return a {@link neqsim.process.equipment.pump.PumpChart} object
*/
public PumpChart getPumpChart() {
public PumpChartInterface getPumpChart() {
return pumpChart;
}

Expand All @@ -449,4 +449,21 @@ public String toJson() {
return new GsonBuilder().serializeSpecialFloatingPointValues().create()
.toJson(new PumpResponse(this));
}

/**
* {@inheritDoc}
*
* <p>
* Set CompressorChartType
* </p>
*/
public void setPumpChartType(String type) {
if (type.equals("simple") || type.equals("fan law")) {
pumpChart = new PumpChart();
} else if (type.equals("interpolate and extrapolate")) {
pumpChart = new PumpChartAlternativeMapLookupExtrapolate();
} else {
pumpChart = new PumpChart();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package neqsim.process.equipment.pump;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import neqsim.process.equipment.compressor.CompressorChartAlternativeMapLookupExtrapolate;

/**
* <p>
* CompressorChartAlternativeMapLookupExtrapolate class.
* </p>
*
* @author ASMF
*/
public class PumpChartAlternativeMapLookupExtrapolate
extends CompressorChartAlternativeMapLookupExtrapolate implements PumpChartInterface {
/** Serialization version UID. */
private static final long serialVersionUID = 1000;
/** Logger object for class. */
static Logger logger = LogManager.getLogger(PumpChartAlternativeMapLookupExtrapolate.class);
boolean usePumpChart = false;

@Override
public double getHead(double flow, double speed) {
// Implement the method logic here
return getPolytropicHead(flow, speed);
}

@Override
public boolean isUsePumpChart() {
// Implement the method logic here
return usePumpChart;
}

@Override
public double getEfficiency(double flow, double speed) {
// Implement the method logic here
return getPolytropicEfficiency(flow, speed);
}

@Override
public void setUsePumpChart(boolean usePumpChart) {
this.usePumpChart = usePumpChart;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@ public interface PumpInterface extends ProcessEquipmentInterface, TwoPortInterfa
* @return a double
*/
public double getPower();

/**
* <p>
* setPumpChartType.
* </p>
*
* @param type a {@link java.lang.String} object
*/
public void setPumpChartType(String type);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ public class TwoPhaseSeparator extends Separator {
/** Serialization version UID. */
private static final long serialVersionUID = 1000;

SystemInterface thermoSystem;

SystemInterface gasSystem;
SystemInterface waterSystem;
SystemInterface liquidSystem;
SystemInterface thermoSystemCloned;

StreamInterface inletStream;
StreamInterface gasOutStream;
StreamInterface liquidOutStream;

/**
* Constructor for TwoPhaseSeparator.
*
Expand All @@ -43,68 +32,12 @@ public TwoPhaseSeparator(String name) {
* Constructor for TwoPhaseSeparator.
* </p>
*
* @param name a {@link java.lang.String} object
* @param inletStream a {@link neqsim.process.equipment.stream.StreamInterface} object
* @param name a {@link java.lang.String} object
* @param inletStream a {@link neqsim.process.equipment.stream.StreamInterface}
* object
*/
public TwoPhaseSeparator(String name, StreamInterface inletStream) {
super(name, inletStream);
}

/** {@inheritDoc} */
@Override
public void setInletStream(StreamInterface inletStream) {
this.inletStream = inletStream;

thermoSystem = inletStream.getThermoSystem().clone();
gasSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[0]);
gasOutStream = new Stream("gasOutStream", gasSystem);

thermoSystem = inletStream.getThermoSystem().clone();
liquidSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[1]);
liquidOutStream = new Stream("liquidOutStream", liquidSystem);
}

/** {@inheritDoc} */
@Override
public StreamInterface getLiquidOutStream() {
return liquidOutStream;
}

/** {@inheritDoc} */
@Override
public StreamInterface getGasOutStream() {
return gasOutStream;
}

/** {@inheritDoc} */
@Override
public StreamInterface getGas() {
return getGasOutStream();
}

/** {@inheritDoc} */
@Override
public StreamInterface getLiquid() {
return getLiquidOutStream();
}

/** {@inheritDoc} */
@Override
public void run(UUID id) {
thermoSystem = inletStream.getThermoSystem().clone();
gasSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[0]);
gasSystem.setNumberOfPhases(1);
gasOutStream.setThermoSystem(gasSystem);

thermoSystem = inletStream.getThermoSystem().clone();
liquidSystem = thermoSystem.phaseToSystem(thermoSystem.getPhases()[1]);
liquidSystem.setNumberOfPhases(1);
liquidOutStream.setThermoSystem(liquidSystem);
setCalculationIdentifier(id);
}

/** {@inheritDoc} */
@Override
@ExcludeFromJacocoGeneratedReport
public void displayResult() {}
}
Loading

0 comments on commit 23e8b5a

Please sign in to comment.