Skip to content

Commit 02d8e8b

Browse files
authored
start update (#1170)
* start update * update * update * added test
1 parent 7c2999b commit 02d8e8b

File tree

2 files changed

+215
-0
lines changed

2 files changed

+215
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package neqsim.process.equipment.diffpressure;
2+
3+
import org.junit.jupiter.api.Test;
4+
import neqsim.process.equipment.stream.Stream;
5+
import neqsim.process.processmodel.ProcessSystem;
6+
import neqsim.thermo.system.SystemInterface;
7+
import neqsim.thermo.system.SystemSrkEos;
8+
9+
public class OrificeTest {
10+
@Test
11+
void testCalc_dp() {
12+
// Step 1: Create a fluid with the SRK equation of state
13+
SystemInterface fluid1 = new SystemSrkEos(303.15, 10.0); // 30 C and 10 bara
14+
fluid1.addComponent("methane", 1.0, "kg/sec");
15+
fluid1.setMixingRule(2);
16+
17+
// Step 2: Create a stream with the fluid
18+
Stream stream1 = new Stream("stream 1", fluid1);
19+
stream1.setFlowRate(3000.0, "kg/hr");
20+
21+
// Step 3: Define and set up the orifice unit operation
22+
Orifice orif1 = new Orifice("orifice 1");
23+
orif1.setInputStream(stream1);
24+
orif1.setOrificeParameters(0.07366, 0.05, 0.61); // Diameter, outer diameter, and discharge
25+
// coefficient
26+
27+
// Step 4: Define the output stream after the orifice
28+
Stream stream2 = new Stream("stream 2", orif1.getOutputStream());
29+
30+
// Step 5: Set up and run the process system
31+
ProcessSystem oilProcess = new ProcessSystem();
32+
oilProcess.add(stream1);
33+
oilProcess.add(orif1);
34+
oilProcess.add(stream2);
35+
36+
oilProcess.run();
37+
38+
// Output the pressure after the orifice
39+
System.out.println("Pressure out of orifice: " + stream2.getPressure("bara") + " bara");
40+
41+
}
42+
}

0 commit comments

Comments
 (0)