Modeling Air Compression Cylinder

Click For Summary
The discussion revolves around modeling an air compression cylinder for an airsoft replica, focusing on fluid dynamics and thermodynamics. The user is attempting to refine their model in MATLAB after initial outputs exceeded actual measurements by 40%. Key challenges include accurately accounting for pressure losses due to friction from the piston seal and flow restrictions at the outlet. The user is uncertain about the applicability of orifice formulas and the friction coefficient used in their calculations, suspecting measurement errors in pressure readings. The conversation highlights the complexities of modeling compressible flow and the need for further experimentation to validate assumptions and improve accuracy.
  • #31
Chestermiller said:
This is not a force balance on the piston; it seems to be a force balance on the gas.
The equation with ##F## involved is meant to be Newtons 2nd Law applied to the projectile. I'm just trying to look at some barrel effects as the projectile pushes the gas out of it.

I tried the "Energy Equation" too for the force balance on the gas:

$$ \dot Q - \dot W_s = \frac{d}{dt} \int_{cv} \left( \frac{V^2}{2} + gh + u \right) \rho ~dV\llap{-} + \int_{cs} \left( \frac{V^2}{2} + gh + u + \frac{P}{\rho} \right) \rho \boldsymbol{V} \cdot d \boldsymbol{A} $$

And I get a slightly different term:

$$ 0 = \frac{d}{dt} \int_{cv} \left( \frac{V^2}{2} \right) \rho ~dV\llap{-} + P_{atm} V A - P_i V A $$

$$ 0 = \rho A \frac{d}{dt} \left( \frac{V^2}{2} \int_{z}^{L} dz \right) + P_{atm} V A - P_i V A $$

$$ 0 = \rho A \left( V \dot V \left( L - z \right) - \frac{V^2}{2} \dot z \right) + P_{atm} V A - P_i V A $$

Now divide everything through by ##VA##, ## V = \dot z ## and move ##P_i## to LHS:

$$ P_i = P_{atm} + \rho \left( \ddot z \left( L - z \right) - \frac{1}{2} \dot z ^2 \right) $$

Now if you compare with the result for ##P_i## in post 28 I see that there is now a factor of ##\frac{1}{2}## that shows up the ##\dot z ^2 ##...

Now if you flip to the free body of the projectile being pushed by some arbitrary force ##F## (this would be the compressed gas behind it) for the sake of argument it's the same result ...almost...

$$ F - P_{atm}A - \rho A \ddot z (L-z) + \rho A \frac{1}{2} \dot z^2 = m \ddot z $$

The factor of ##1/2## that appears when using Energy is somewhat concerning - but I've seen that discrepancy between momentum and energy analysis with chains being accelerated from rest in these forums, but it is not as concerning as why the ##\dot z^2## term appears to aide ##F##? The fact that the control volume is losing mass is somehow helping ##F## via ##\dot z##. Is that real or mistake?
 
Engineering news on Phys.org
  • #32
erobz said:
The equation with ##F## involved is meant to be Newtons 2nd Law applied to the projectile. I'm just trying to look at some barrel effects as the projectile pushes the gas out of it.

I tried the "Energy Equation" too for the force balance on the gas:

$$ \dot Q - \dot W_s = \frac{d}{dt} \int_{cv} \left( \frac{V^2}{2} + gh + u \right) \rho ~dV\llap{-} + \int_{cs} \left( \frac{V^2}{2} + gh + u + \frac{P}{\rho} \right) \rho \boldsymbol{V} \cdot d \boldsymbol{A} $$

And I get a slightly different term:

$$ 0 = \frac{d}{dt} \int_{cv} \left( \frac{V^2}{2} \right) \rho ~dV\llap{-} + P_{atm} V A - P_i V A $$

$$ 0 = \rho A \frac{d}{dt} \left( \frac{V^2}{2} \int_{z}^{L} dz \right) + P_{atm} V A - P_i V A $$

$$ 0 = \rho A \left( V \dot V \left( L - z \right) - \frac{V^2}{2} \dot z \right) + P_{atm} V A - P_i V A $$

Now divide everything through by ##VA##, ## V = \dot z ## and move ##P_i## to LHS:

$$ P_i = P_{atm} + \rho \left( \ddot z \left( L - z \right) - \frac{1}{2} \dot z ^2 \right) $$

Now if you compare with the result for ##P_i## in post 28 I see that there is now a factor of ##\frac{1}{2}## that shows up the ##\dot z ^2 ##...

Now if you flip to the free body of the projectile being pushed by some arbitrary force ##F## (this would be the compressed gas behind it) for the sake of argument it's the same result ...almost...

$$ F - P_{atm}A - \rho A \ddot z (L-z) + \rho A \frac{1}{2} \dot z^2 = m \ddot z $$

The factor of ##1/2## that appears when using Energy is somewhat concerning - but I've seen that discrepancy between momentum and energy analysis with chains being accelerated from rest in these forums, but it is not as concerning as why the ##\dot z^2## term appears to aide ##F##? The fact that the control volume is losing mass is somehow helping ##F## via ##\dot z##. Is that real or mistake?
Sorry, I don't follow. The analysis I did so far was application of the first law of thermodynamics to the gas in the chamber (control value) and a force balance on the piston. Later, when I have time, I will provide the analysis of the (Bernoulli equation for the mechanical energy balance on the overall air in the chamber and exit tube.
 
  • #33
Chestermiller said:
Sorry, I don't follow. The analysis I did so far was application of the first law of thermodynamics to the gas in the chamber (control value) and a force balance on the piston. Later, when I have time, I will provide the analysis of the (Bernoulli equation for the mechanical energy balance on the overall air in the chamber and exit tube.
I was just playing around with deriving how much pressure the projectile sees from in front of it. It is clearing the barrel as it is traveling along its length and both accelerating and discharging mass in front of it. I'm running into some theoretical questions along the way.

If the notation I'm using is foreign I will show more steps and assumptions?
 
  • #34
erobz said:
I was just playing around with deriving how much pressure the projectile sees from in front of it. It is clearing the barrel as it is traveling along its length and both accelerating and discharging mass in front of it. I'm running into some theoretical questions along the way.

If the notation I'm using is foreign I will show more steps and assumptions?
Oh. I was analyzing the original problem
 
  • #35
UThis is a continuation of the analysis I presented in post #30. It is for the case of an inviscid gas, without piston friction (temporarily). It addresses the situation submitted by the OP in post #1.

The present analysis uses the subscript C to represent the parameter values in the large chamber, T to represent the parameter values in the exit tube, and zero to represent parameter values at time zero.

The part of analysis for the transition from the large chamber to the exit tube make use of the Bernoulli equation and the assumption of quasi steady state for the flow. Under this assumption, we obtain (The detailed analysis is in the book Introduction to Chemical Engineering Thermodynamics by Smith and Van Ness):$$u_2^2-u_1^2=\frac{2P_Cv_C\gamma}{\gamma-1}\left[1-\left(\frac{P_{atm}}{P_C}\right)^{\frac{\gamma-1}{\gamma}}\right]$$where ##u_1=-\frac{dx}{dt}## is the velocity of the piston, ##u_2## is the discharge velocity at the exit of the tube, and ##v_C=\frac{A_C x}{m}## is the specific volume of the air in the chamber. To get the mass discharge rate of air coming out the exit of the tube, we multiply the air velocity at the tube exit ##u_2## by the density of the air in the tube ##1/v_T## and the cross sectional area of the tube ##A_T## to obtain $$\dot{m}=-\frac{u_2A_T}{v_T}$$The specific volume of the air at the exit of the tube is related to the specific volume of the air in the chamber by: $$v_T=v_C\left(\frac{P_{atm}}{P_C}\right)^{1/\gamma} $$

Now to summarize. We have 3 coupled first order ordinary equations in time to solve for the three dependent variables m, x, and u (where u is the velocity of the piston): $$\frac{dm}{dt}=\dot{m}=-\frac{u_2A_T}{v_T}$$ $$\frac{dx}{dt}=-u_1$$and $$M\frac{du_1}{dt}=k(d-L+x)-(P_C-P_{atm})A$$
 
Last edited:
  • #36
So as a simple physics model applying conservation of energy treating the gas trapped between piston and bb as incompressible and without significant mass:

$$ \frac{1}{2}kx_o^2 = \frac{1}{2}M_{p} v^2 + \frac{1}{2} \frac{1}{3}M_s v^2 + \frac{1}{2}M_{bb} \left( \frac{D_p}{D_{bb}}\right)^4 v^2 $$

1736518051905.png


Is this in the ballpark upper bound for the velocity of piston as the BB leaves the barrel?

Giving for the BB and upper bound of:

$$ v_{bb} = \left( \frac{D_{p}}{D_b} \right)^4 v \approx 1500~\text{m/s} $$

If its even half that in actuality, I've done some other ballpark calculations that say the back pressure from accelerating the air ahead of the bb out of the barrel could be significant.
 
Last edited:
  • #37
WOW! At mach 4.5 you could save a lot on gun powder. 😱
 
  • #38
Tom.G said:
WOW! At mach 4.5 you could save a lot on gun powder. 😱
:smile:
 
  • #39
Tom.G said:
WOW! At mach 4.5 you could save a lot on gun powder. 😱
It could be significant at mach 1 (or less) too. As far as I know the OP is looking for deviations in simulation vs. measurement.

So I just imagined a tube of length ##L## and diameter ##D## and constant friction factor ##f##. For unsteady- incompressible flow of the gas in the barrel initially at rest I get this for the pressure in front of the projectile as it clears the barrel:

$$ P = P_{atm} + \rho L \dot v + \rho f \frac{L}{D}\frac{v^2}{2} $$

So for a constant a pressure differential across the tube the flow would begin to accelerate from rest. I ignore the decrease in mass, so a solution is able to be obtained.

I'm trying to answer "what pressure would I need to reach a certain velocity in the flow by the time an element would travel the length of the barrel":

with ##u =(P-P_{atm} )-\rho f \frac{L}{D}\frac{v^2}{2}## the ODE becomes linear separable:

$$ -\frac{D}{f}\frac{du}{dz}=u$$

After I solve for everything in terms of ##v## ( the desired projectile velocity at the end of the barrel) I get this:

1736618148073.png



It quadratic and here is a plot with some reasonable parameters I believe.

1736618295786.png


Sorry to mix English and metric but I just have more sense of scale with psi over pascals. Is a 10 psi back pressure ignorable, what is the pressure behind the projectile pushing it?
 
Last edited:
  • #40
Hi have been sick last couple of days, but have been able to measure the pressure in the chamber and in the barrel (add the exit of the nozzle) and the pressure in the barrel right at the end (when the bb exits).

Simulation_vs_measuremen_complete_setup.PNG


It seems that the pressure in the chamber is a bit higher then what is measured so need to recheck all the measurements (initial air-mass and the mass-air-flow) the ratio between chamber and barrel/nozzle pressure seems to be in the right area. Think if I can get these to match the simulation completely matches reality. So maybe the assumption that the bb sees another force might be incorrect.

Also noticed that the pressure normally is dropping below ATM when the piston is going backwards. so in the measurement above I made sure the spring was already compressed.
 
  • #41
JeroenM said:
Hi have been sick last couple of days, but have been able to measure the pressure in the chamber and in the barrel (add the exit of the nozzle) and the pressure in the barrel right at the end (when the bb exits).

View attachment 355800

It seems that the pressure in the chamber is a bit higher then what is measured so need to recheck all the measurements (initial air-mass and the mass-air-flow) the ratio between chamber and barrel/nozzle pressure seems to be in the right area. Think if I can get these to match the simulation completely matches reality. So maybe the assumption that the bb sees another force might be incorrect.

Also noticed that the pressure normally is dropping below ATM when the piston is going backwards. so in the measurement above I made sure the spring was already compressed.
I believe the yellow spike in pressure is acting over the length of the barrel. I think it shows the magnitude is not insignificant. It is working against the projectile as the static gas in the barrel before the spring is released is accelerated out of the barrel ahead of the projectile. That pressure increases the pressure in the chamber that is pushing the projectile relative to a model that doesn’t consider it.

If the bb is already out of the barrel than that pressure is just the pressure behind the bb as it exists ( and I'm mistaken)

What is the timing of the spike relative to the bb position?
 
Last edited:
  • #42
The pressure spike is just as the BB passes the sensor and just before it exits the barrel. I went a step back and did a measurement with the barrel and no BB but I closed the barrel on the end. Same as I did with only the cylinder. But is pretty far off.

So this is with no barrel and closed cylinder:
Closed_port.PNG

Pretty good match sim vs measurement

Below is the same but then with a 300mm (6.05mm barrel) connected.

Closed_barrel.PNG

EDIT:
Just notiched that the pressure in the barrel is not the same as in the chamber but accoring to the measurement it was. Most likely due to the fact that my "nozzle" MFR calculation only works one way.

[CODE lang="matlab" title="Matlab simulation code"]% Initialize air mass in the chamber
m_air_chamber(1) = P0 * Lc*Ap / (R * T); % Initial mass of air in the chamber
m_air_barrel(1)=P0 * Lb*Ab / (R * T); % Initial mass of air in the barrel

for n = 2:n_steps

% Chamber volume
V_c(n) = Lc*Ap - x_p(n-1) * Ap;

% Update chamber pressure (Ideal Gas Law)
P(n) = m_air_chamber(n-1) * R * Temp(n-1) / V_c(n);

Temp(n)=T*(P(n)/P0)^((gamma-1)/gamma); % Calculate temperature rise due to fast adiabatic compression

rho_air_chamber = P(n)/(R*Temp(n));


% Calculate orifice flow
delta_P_orifice(n) = P(n) - P_barrel(n-1); % Pressure difference across orifice
pressure_ratio = P_barrel(n-1) / P(n); % Downstream to upstream pressure ratio

if pressure_ratio > critical_pressure_ratio % Subsonic flow
flow_regime(n) = 1; % Subsonic
if delta_P_orifice(n) > 0

m_dot_orifice(n) = C_d * An * P(n) * sqrt(2 / (R * Temp(n))* (gamma / (gamma - 1)) * ((P_barrel(n-1)/P(n))^(2/gamma) - (P_barrel(n-1)/P(n))^((gamma+1)/gamma) ) );
else
m_dot_orifice(n) = 0;
end
else % Choked flow
flow_regime(n) = 2; % Chokedflow_regime(n) = 2; % Choked
m_dot_orifice(n) = C_d * An *P(n)*sqrt(gamma/(R * Temp(n))) * (2/(gamma+1))^((gamma+1)/(2*(gamma-1)));
end


% Update air mass in chamber and barrel
m_air_chamber(n) = m_air_chamber(n-1) - m_dot_orifice(n) * dt; % Air leaving chamber
m_air_barrel(n) = m_air_barrel(n-1) + m_dot_orifice(n) * dt;

% Update barrel pressure (assuming ideal gas law)
P_barrel(n) = m_air_barrel(n) * R * Temp(n-1) / (Lb * Ab); % Lb is length barrel Ab area barrel

% Update air density in chamber
rho_air_barrel(n) = P_barrel(n) / (R * Temp(n));

% Spring force (Hooke's Law with pre-load)
F_spring(n) = k * (x_preload - x_p(n-1)); % Spring force with pre-load

F_friction(n) = sign(v_p(n-1))*((P(n) - P0) * A_seal * mu); % Friction force on the piston

%Force due to pressure buildup
F_pressure(n) = (P(n)- P0)* Ap;

%Net force on piston
F_n(n) = F_spring(n) - F_pressure(n) - F_friction(n);

% Piston dynamics
a_p(n) = F_n(n) / m_p;
v_p(n) = v_p(n-1) + a_p(n) * dt;
x_p(n) = x_p(n-1) + v_p(n) * dt;[/CODE]
 
Last edited:
  • #43
I have tried to verify all the measurements but so far no succes in lowering the pressure in the simulation. I also found out that when I added the pressure sensor I got extra leakage which caused the difference between simulation and measurement. I have fixed that as good as possible.

This is the model I now have:
Lc = cylinder length
Ap = Piston surface area
x_p = piston position
V_c = Volume inside the cylinder
P(n) = pressure cylinder
P_barrel = pressure barrel and in front of BB
m_air_chamber = mass of the air inside the cylinder
m_air_barrel = mass of the air inside the barrel

Intialize:
$$m_{\text{air_chamber}}(1) = \frac{P_0 \cdot L_c \cdot A_p}{R \cdot T}$$
$$m_{\text{air_barrel}}(1) = \frac{P_0 \cdot L_n \cdot A_b}{R \cdot T}$$

Step 1:
$$V_c(n) = L_c \cdot A_p - x_p(n-1) \cdot A_p$$

Step 2:
$$P(n) = \frac{m_{\text{air_chamber}}(n-1) \cdot R \cdot \text{Temp}(n-1)}{V_c(n)}$$

Step 3:
$$\text{Temp}(n) = T \cdot \left(\frac{P(n)}{P_0}\right)^{\frac{\gamma - 1}{\gamma}}$$

Step 4: Flow is always subsonic because the difference in pressure is always low
$$
m_{\dot{\text{orifice}}}(n) = C_d \cdot A_n \cdot P(n) \cdot
\sqrt{
\frac{2}{R \cdot \text{Temp}(n)}
\cdot
\frac{\gamma}{\gamma - 1}
\cdot
\left(
\left(\frac{P_{\text{barrel}}(n-1)}{P(n)}\right)^{\frac{2}{\gamma}}
-
\left(\frac{P_{\text{barrel}}(n-1)}{P(n)}\right)^{\frac{\gamma + 1}{\gamma}}
\right)
}
$$

Step 5: (calculate leakage around the BB first check if subsonic or choked flow)

For subsonic flow:
$$
m_{\dot{\text{leak}}}(n) = C_d^{\text{leak}} \cdot A_{\text{leak}} \cdot P_{\text{barrel}}(n-1) \cdot
\sqrt{
\frac{2}{R \cdot \text{Temp}(n)}
\cdot
\frac{\gamma}{\gamma - 1}
\cdot
\left(
\left(\frac{P_0}{P_{\text{barrel}}(n-1)}\right)^{\frac{2}{\gamma}}
-
\left(\frac{P_0}{P_{\text{barrel}}(n-1)}\right)^{\frac{\gamma + 1}{\gamma}}
\right)
}
$$

For Choked flow
$$
m_{\dot{\text{leak}}}(n) = C_d^{\text{leak}} \cdot A_{\text{leak}} \cdot P_{\text{barrel}}(n-1) \cdot
\sqrt{
\frac{\gamma}{R \cdot \text{Temp}(n)}
}
\cdot
\left(\frac{2}{\gamma + 1}\right)^{\frac{\gamma + 1}{2 (\gamma - 1)}}
$$

Step 5:
$$m_{\text{air_chamber}}(n) = m_{\text{air_chamber}}(n-1) - m_{\dot{\text{orifice}}}(n) \cdot \Delta t$$

Step 6:
$$
m_{\text{air_barrel}}(n) = m_{\text{air_barrel}}(n-1) + m_{\dot{\text{orifice}}}(n) \cdot \Delta t - m_{\dot{\text{leak}}}(n) \cdot \Delta t
$$

Step 7:
$$
P_{\text{barrel}}(n) = \frac{m_{\text{air_barrel}}(n) \cdot R \cdot \text{Temp}(n)}{x_b(n-1) \cdot A_b}
$$

Step 8:
$$
F_{\text{spring}}(n) = k \cdot (x_{\text{preload}} - x_p(n-1))
$$
$$
F_{\text{friction}}(n) = \text{sign}(v_p(n-1)) \cdot \left( (P(n) - P_0) \cdot A_{\text{seal}} \cdot \mu \right)
$$
$$
F_{\text{pressure}}(n) = (P(n) - P_0) \cdot A_p
$$
$$
F_n(n) = F_{\text{spring}}(n) - F_{\text{friction}}(n) - F_{\text{pressure}}(n)
$$

Step 9:
$$a_p(n) = \frac{F_n(n)}{m_p}$$

$$v_p(n) = v_p(n-1) + a_p(n) \cdot \Delta t$$

$$x_p(n) = x_p(n-1) + v_p(n) \cdot \Delta t$$

Step 10:
$$F_{\text{drag}} = 0.5 \cdot C_{d_{\text{sphere}}} \cdot \rho_{\text{air\_atm}} \cdot v_b(n-1)^2 \cdot A_{\text{bb}}$$

$$F_{\text{bb}}(n) = \left( P_{\text{barrel}}(n) - P_0 \right) \cdot A_{\text{bb}} - F_{\text{drag}}$$
$$a_{b_{\text{drag}}} = \frac{F_{\text{bb}}(n)}{m_b}$$
$$v_b(n) = v_b(n-1) + a_{b_{\text{drag}}} \cdot \Delta t$$
$$x_b(n) = x_b(n-1) + v_b(n) \cdot \Delta t$$

It matches now pretty well, the only small difference is that according to the simulation the BB is sooner out of the barrel then measurement. But there is also a big difference on the left (the right line) in pressure this is probably due to non-linear effect when the air is starting to moving and probably way to difficult to model.
Simulation_vs_measuremen_complete_setup.PNG


So far I'm pretty happy with the results especially with all your help and tips. Still have some discrepancies between the measured spring constant and the measured weights to get the model to fit. I assume that the spring I used is in reality not 100% linear.
 
  • #44
I came across this post while modeling a fire syringe. Key to this analysis is how fast the flow can escape the cylinder, so the pressure/flow characteristic through the hole (entering the tube is causing a pressure loss), tube (general pipe friction) and exit (sharp edged exit is causing a pressure loss) to ambient needs to be modeled correctly. I modeled this in Simcenter Amesim and got fairly good results that match you test data:
1742490410544.png

I'm not accounting for dynamics like inertia and any sensor dynamics so oscillations after the main peak are not captured. Here are some other results:
1742490521708.png

Model sketch:

1742490721264.png
 
  • #45
How did you generate the simulated results (via analytic equation or CFD software)? EDIT: never mind, I see you have used some serious software with built in CFD. What are the characteristics of accurate friction modeling? I tried to come up with something in post no. 39 that seemed to indicate it could be significant (and very much the remaining discrepancy), but I never got any feedback from others that seem to believe gas inertia and viscous effects (within the barrel) were negligible.
 
Last edited:
  • #46
erobz said:
How did you generate the simulated results (via analytic equation or CFD software)? EDIT: never mind, I see you have used some serious software with built in CFD. What are the characteristics of accurate friction modeling? I tried to come up with something in post no. 39 that seemed to indicate it could be significant (and very much the remaining discrepancy), but I never got any feedback from others that seem to believe gas inertia and viscous effects (within the barrel) were negligible.
No CFD is used, only ODEs and algebraic equations that are embedded in the components. For the inlet pressure drop I used a contraction correlations per " IdelCik I.E., Handbook of hydraulic resistance, Third edition, Begell House Inc. 1980" that is embedded in the code. The correlation assumes fully developed flow before and after the contraction, so it is just an estimate here and not predictive. For pipe friction it defines a friction factor through the 'Nikuradse Harp' based on the pipe roughness and Reynolds number. For the outlet friction I used an orifice defined by a flow coefficient that I 'tuned' to get the right response. I could have used and expansion but that again would assume fully developed flow before and after.
Here is a plot of the pressure with varying flow coefficients (cq). I used cq=0.9 to match the test data:
1742500428476.png
 

Similar threads

Replies
0
Views
1K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
7
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
0
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
46K