|
| 1 | +package neqsim.process.equipment.diffpressure; |
| 2 | + |
| 3 | +import java.util.UUID; |
| 4 | +import neqsim.process.equipment.TwoPortEquipment; |
| 5 | +import neqsim.process.equipment.stream.StreamInterface; |
| 6 | +import neqsim.thermo.system.SystemInterface; |
| 7 | + |
| 8 | +public class Orifice extends TwoPortEquipment { |
| 9 | + private static final long serialVersionUID = 1L; |
| 10 | + private String name; |
| 11 | + private StreamInterface inputstream; |
| 12 | + private StreamInterface outputstream; |
| 13 | + private Double dp; |
| 14 | + private Double diameter; |
| 15 | + private Double diameter_outer; |
| 16 | + private Double C; |
| 17 | + private double orificeDiameter; |
| 18 | + private double pressureUpstream; |
| 19 | + private double pressureDownstream; |
| 20 | + private double dischargeCoefficient; |
| 21 | + |
| 22 | + public Orifice(String name) { |
| 23 | + super(name); |
| 24 | + } |
| 25 | + |
| 26 | + public Orifice(String name, double diameter, double orificeDiameter, double pressureUpstream, |
| 27 | + double pressureDownstream, double dischargeCoefficient) { |
| 28 | + super(name); |
| 29 | + this.diameter = diameter; |
| 30 | + this.orificeDiameter = orificeDiameter; |
| 31 | + this.pressureUpstream = pressureUpstream; |
| 32 | + this.pressureDownstream = pressureDownstream; |
| 33 | + this.dischargeCoefficient = dischargeCoefficient; |
| 34 | + } |
| 35 | + |
| 36 | + public void setInputStream(StreamInterface stream) { |
| 37 | + this.inputstream = stream; |
| 38 | + this.outputstream = (StreamInterface) stream.clone(); |
| 39 | + } |
| 40 | + |
| 41 | + public StreamInterface getOutputStream() { |
| 42 | + return outputstream; |
| 43 | + } |
| 44 | + |
| 45 | + public void setOrificeParameters(Double diameter, Double diameter_outer, Double C) { |
| 46 | + this.diameter = diameter; |
| 47 | + this.diameter_outer = diameter_outer; |
| 48 | + this.C = C; |
| 49 | + } |
| 50 | + |
| 51 | + public Double calc_dp() { |
| 52 | + double beta = orificeDiameter / diameter; |
| 53 | + double beta2 = beta * beta; |
| 54 | + double beta4 = beta2 * beta2; |
| 55 | + double dP = pressureUpstream - pressureDownstream; |
| 56 | + |
| 57 | + double deltaW = (Math.sqrt(1.0 - beta4 * (1.0 - dischargeCoefficient * dischargeCoefficient)) |
| 58 | + - dischargeCoefficient * beta2) |
| 59 | + / (Math.sqrt(1.0 - beta4 * (1.0 - dischargeCoefficient * dischargeCoefficient)) |
| 60 | + + dischargeCoefficient * beta2) |
| 61 | + * dP; |
| 62 | + |
| 63 | + return deltaW; |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Calculates the orifice discharge coefficient using the Reader-Harris Gallagher method. |
| 68 | + * |
| 69 | + * @param D Upstream internal pipe diameter, in meters. |
| 70 | + * @param Do Diameter of orifice at flow conditions, in meters. |
| 71 | + * @param rho Density of fluid at P1, in kg/m^3. |
| 72 | + * @param mu Viscosity of fluid at P1, in Pa*s. |
| 73 | + * @param m Mass flow rate of fluid through the orifice, in kg/s. |
| 74 | + * @param taps Tap type ("corner", "flange", "D", or "D/2"). |
| 75 | + * @return Discharge coefficient of the orifice. |
| 76 | + */ |
| 77 | + public static double calculateDischargeCoefficient(double D, double Do, double rho, double mu, |
| 78 | + double m, String taps) { |
| 79 | + double A_pipe = 0.25 * Math.PI * D * D; |
| 80 | + double v = m / (A_pipe * rho); |
| 81 | + double Re_D = rho * v * D / mu; |
| 82 | + double beta = Do / D; |
| 83 | + double beta2 = beta * beta; |
| 84 | + double beta4 = beta2 * beta2; |
| 85 | + double beta8 = beta4 * beta4; |
| 86 | + |
| 87 | + double L1, L2_prime; |
| 88 | + if ("corner".equalsIgnoreCase(taps)) { |
| 89 | + L1 = 0.0; |
| 90 | + L2_prime = 0.0; |
| 91 | + } else if ("flange".equalsIgnoreCase(taps)) { |
| 92 | + L1 = L2_prime = 0.0254 / D; |
| 93 | + } else if ("D".equalsIgnoreCase(taps) || "D/2".equalsIgnoreCase(taps)) { |
| 94 | + L1 = 1.0; |
| 95 | + L2_prime = 0.47; |
| 96 | + } else { |
| 97 | + throw new IllegalArgumentException("Unsupported tap type: " + taps); |
| 98 | + } |
| 99 | + |
| 100 | + double A = Math.pow(19000 * beta / Re_D, 0.8); |
| 101 | + double M2_prime = 2.0 * L2_prime / (1.0 - beta); |
| 102 | + |
| 103 | + double deltaCUpstream = ((0.043 + 0.08 * Math.exp(-10 * L1) - 0.123 * Math.exp(-7 * L1)) |
| 104 | + * (1.0 - 0.11 * A) * beta4 / (1.0 - beta4)); |
| 105 | + |
| 106 | + double deltaCDownstream = |
| 107 | + -0.031 * (M2_prime - 0.8 * Math.pow(M2_prime, 1.1)) * Math.pow(beta, 1.3); |
| 108 | + double C_inf_C_s = |
| 109 | + 0.5961 + 0.0261 * beta2 - 0.216 * beta8 + 0.000521 * Math.pow(1e6 * beta / Re_D, 0.7) |
| 110 | + + (0.0188 + 0.0063 * A) * Math.pow(beta, 3.5) * Math.pow(1e6 / Re_D, 0.3); |
| 111 | + |
| 112 | + return C_inf_C_s + deltaCUpstream + deltaCDownstream; |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Calculates the expansibility factor for orifice plate calculations. |
| 117 | + * |
| 118 | + * @param D Upstream internal pipe diameter, in meters. |
| 119 | + * @param Do Diameter of orifice at flow conditions, in meters. |
| 120 | + * @param P1 Static pressure of fluid upstream, in Pa. |
| 121 | + * @param P2 Static pressure of fluid downstream, in Pa. |
| 122 | + * @param k Isentropic exponent of fluid. |
| 123 | + * @return Expansibility factor (1 for incompressible fluids). |
| 124 | + */ |
| 125 | + public static double calculateExpansibility(double D, double Do, double P1, double P2, double k) { |
| 126 | + double beta = Do / D; |
| 127 | + double beta4 = Math.pow(beta, 4); |
| 128 | + return 1.0 - (0.351 + beta4 * (0.93 * beta4 + 0.256)) * (1.0 - Math.pow(P2 / P1, 1.0 / k)); |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * Calculates the non-recoverable pressure drop across the orifice plate. |
| 133 | + * |
| 134 | + * @param D Upstream internal pipe diameter, in meters. |
| 135 | + * @param Do Diameter of orifice at flow conditions, in meters. |
| 136 | + * @param P1 Static pressure of fluid upstream, in Pa. |
| 137 | + * @param P2 Static pressure of fluid downstream, in Pa. |
| 138 | + * @param C Discharge coefficient. |
| 139 | + * @return Non-recoverable pressure drop, in Pa. |
| 140 | + */ |
| 141 | + public static double calculatePressureDrop(double D, double Do, double P1, double P2, double C) { |
| 142 | + double beta = Do / D; |
| 143 | + double beta2 = beta * beta; |
| 144 | + double beta4 = beta2 * beta2; |
| 145 | + double dP = P1 - P2; |
| 146 | + double deltaW = (Math.sqrt(1.0 - beta4 * (1.0 - C * C)) - C * beta2) |
| 147 | + / (Math.sqrt(1.0 - beta4 * (1.0 - C * C)) + C * beta2) * dP; |
| 148 | + return deltaW; |
| 149 | + } |
| 150 | + |
| 151 | + /** |
| 152 | + * Calculates the diameter ratio (beta) of the orifice plate. |
| 153 | + * |
| 154 | + * @param D Upstream internal pipe diameter, in meters. |
| 155 | + * @param Do Diameter of orifice at flow conditions, in meters. |
| 156 | + * @return Diameter ratio (beta). |
| 157 | + */ |
| 158 | + public static double calculateBetaRatio(double D, double Do) { |
| 159 | + return Do / D; |
| 160 | + } |
| 161 | + |
| 162 | + @Override |
| 163 | + public void run(UUID uuid) { |
| 164 | + if (inputstream != null && outputstream != null) { |
| 165 | + double newPressure = inputstream.getPressure("bara") - calc_dp(); |
| 166 | + SystemInterface outfluid = (SystemInterface) inStream.clone(); |
| 167 | + outfluid.setPressure(newPressure); |
| 168 | + outStream.setFluid(outfluid); |
| 169 | + outStream.run(); |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | +} |
0 commit comments