- #1
JeroenM
- 5
- 1
- TL;DR Summary
- Trying to model a piston that compresses air and pushes it out of a nozzle
Hi,
I'm have been trying to model an airsoft replica, as an electrical engineer fluid dynamics, thermodynamics is a complete new flied for me and with with help of Ai i have been learning a lot about this subject. So far I have come a long way in making something my first model sort of worked but the output energy was about 40% higher then actual measurements. So i have been trying several things to see where the losses are and how to model them using Matlab. To make things a bit simpler I removed as many components as possible to make the model in steps.
So the first part I'm now trying to model is a cylinder (with diameter of 23.85mm) with a outlet on one end that is 4.5mm in diameter and 35mm long and on the other end there is a piston which will compress the air and push it out of the smaller hole. The piston is driven by a spring (150mm spring with 692N/m springconstant and pre compressed to a length of 55mm).
So the model looks like this
I measured the pressure inside the chamber using an absolute pressure sensor and the graph looks like this:
The pressure peaks at 350kPa when the piston slams into the end of the cylinder from what I conclude is that the flow gets choked at 250kPa (more rapid rise).
From what I so far know and assume is that all the "losses" is due to the friction force of the oring (to create the seal of the piston) which is pressure depended and the fact that the air needs to be pressed through a hole. For now I modelled this using the orifice formula which i'm not sure if the correct way I also tried the sudden contraction formula but that doesn't seem to fit at all.
So I made the following code in matlab (snippet):
So below is a picture of the simulation vs the measured data of the pressure inside the cylinder
So the simulation is pretty close except that the peak is missing in the simulation, so either the simulation is wrong or the measurement is wrong (pressure is measure through a hole on the side of the cylinder right before the endstop).
I used CFD simulation to see what I could expect and got the following results:
The inlet is a mass air flow of 50gr/s and the outlet is a static presure of 101325 pascal. From the total pressure inside the cylinder and ATM I have a pressure difference of 74kPa which I used to calculate the Coefficient of discharge value which is about 0.85. But the simulation gives different pressure values (static, dynamic, relative and total pressure) for the inlet (on the right) and the outlet (on the left) I'm not sure any more which one to use especially of the left side (pressure average is 101325, total pressure average is 151371 pascal so not sure which one to use). If use the total pressure only the pressure difference between inlet and outlet is only 23888 pascal which seems very low and would not explain why the pressure inside the cylinder is 175kPa. Here is really the lack of knowledge to understand what is happing here.
So to sum it up it up where I have my doubts:
Who can help me to point where I might be wrong ?
Best regards,
Jeroen
I'm have been trying to model an airsoft replica, as an electrical engineer fluid dynamics, thermodynamics is a complete new flied for me and with with help of Ai i have been learning a lot about this subject. So far I have come a long way in making something my first model sort of worked but the output energy was about 40% higher then actual measurements. So i have been trying several things to see where the losses are and how to model them using Matlab. To make things a bit simpler I removed as many components as possible to make the model in steps.
So the first part I'm now trying to model is a cylinder (with diameter of 23.85mm) with a outlet on one end that is 4.5mm in diameter and 35mm long and on the other end there is a piston which will compress the air and push it out of the smaller hole. The piston is driven by a spring (150mm spring with 692N/m springconstant and pre compressed to a length of 55mm).
So the model looks like this
I measured the pressure inside the chamber using an absolute pressure sensor and the graph looks like this:
The pressure peaks at 350kPa when the piston slams into the end of the cylinder from what I conclude is that the flow gets choked at 250kPa (more rapid rise).
From what I so far know and assume is that all the "losses" is due to the friction force of the oring (to create the seal of the piston) which is pressure depended and the fact that the air needs to be pressed through a hole. For now I modelled this using the orifice formula which i'm not sure if the correct way I also tried the sudden contraction formula but that doesn't seem to fit at all.
So I made the following code in matlab (snippet):
- Calculate the volume in the cylinder based on piston position (t=0 pos = 0, Lc is the cylinder length of 55mm)
- Calculate the pressure in the chamber using the air mass temperature and volume
- Calculate the temperature rise due to rapid compression
- Calculate the air density based on the new temperature and pressure
- Assume the air velocity inside the cylinder the same as the piston velocity
- Check if the flow is subsonic or choked flow based on the pressure of the cylinder and atmospheric pressure (P2 is assumed to be P ATM)
- Calculate the velocity and mass air flow through the "orifice" with either subsonic flow or choked flow. this part I'm not sure if correct because it is not really an orifice plate but more a sudden contraction to a smaller pipe (of 35mm length) in to to atmosphere but so far it seems to fit the best.
- Calculate the new air mass inside the cylinder
- Calculate the force of the spring using hooks law (1/3 of the mass is added to the total mass of the piston)
- Calculate the friction force of the oring based on the pressure inside the cylinder and P0 (P ATM). I use for mu a value of 2 (which seems to be way to high a value of 0.5 or lower is what I have expected) and the A_seal is the area of the oring which is for now the circumference (33.4mm) of the oring times the width (2.58mm) of the oring (also not sure if this is correct).
- Calculate the pressure force on the piston based on the area of the piston head and the delta pressure on the piston (P_cylinder - P0)
- Calculate netto force on the piston.
- Calculate the acceleration, velocity and position of the piston
- Check if piston is at the end (position > 55mm)
Simulation model:
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
% Update air density in chamber
rho_air_chamber(n) = P(n) / (R * Temp(n));
v_air_chamber(n) = v_p(n-1); %Air velocity in chamber same as piston
% Density at the orifice (isentropic relationship)
P_orifice(n) = P(n) - (0.5 * rho_air_chamber(n) * v_air_chamber(n)^2); % Simplified pressure drop to orifice
rho_orifice = P_orifice(n) / (R * Temp(n));
P2=P0; %P2 is Atmospheric pressure
% Calculate orifice flow
delta_P_orifice(n) = P(n) - P2; % Pressure difference across orifice
pressure_ratio = P2 / 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
v_air_orifice(n) = sqrt( (2*gamma*R*Temp(n))/(gamma-1) * (1-(P2/P(n))^((gamma-1)/gamma)));
m_dot_orifice(n) = C_d * An * P(n) * sqrt(2 / (R * Temp(n))* (gamma / (gamma - 1)) * ((P2/P(n))^(2/gamma) - (P2/P(n))^((gamma+1)/gamma) ) );
%*C_d_f(n)
else
m_dot_orifice(n) = 0;
end
else % Choked flow
flow_regime(n) = 2; % Chokedflow_regime(n) = 2; % Choked
v_air_orifice(n) = sqrt(gamma*R*Temp(n)*(2/(gamma+1)));
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
if m_air_chamber(n)<0
m_air_chamber(n)=0;
end
% Spring force (Hooke's Law with pre-load)
F_spring(n) = k * (x_preload - x_p(n-1)); % Spring force with pre-load
% Friction force (based on seal)
F_friction(n) = (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_friction(n) - F_pressure(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;
% Apply saturation to piston position
if x_p(n) < 0
x_p(n) = 0;
v_p(n) = 0;
elseif x_p(n) > Lc
x_p(n) = Lc;
v_p(n) = 0;
break;
end
end
So below is a picture of the simulation vs the measured data of the pressure inside the cylinder
So the simulation is pretty close except that the peak is missing in the simulation, so either the simulation is wrong or the measurement is wrong (pressure is measure through a hole on the side of the cylinder right before the endstop).
I used CFD simulation to see what I could expect and got the following results:
The inlet is a mass air flow of 50gr/s and the outlet is a static presure of 101325 pascal. From the total pressure inside the cylinder and ATM I have a pressure difference of 74kPa which I used to calculate the Coefficient of discharge value which is about 0.85. But the simulation gives different pressure values (static, dynamic, relative and total pressure) for the inlet (on the right) and the outlet (on the left) I'm not sure any more which one to use especially of the left side (pressure average is 101325, total pressure average is 151371 pascal so not sure which one to use). If use the total pressure only the pressure difference between inlet and outlet is only 23888 pascal which seems very low and would not explain why the pressure inside the cylinder is 175kPa. Here is really the lack of knowledge to understand what is happing here.
So to sum it up it up where I have my doubts:
- Doubt if the orifice formula is the correct one, but if so not sure if i should P0 as value inside the formula especially because the choked flow seems to start at 250kPa in the measurement.
- There is friction force inside the system but based on my model is seems to be very high, friction coefficient of 2 seems to be very high and unrealistic. Tried to simulate this using FEM but not much succes there or very low friction numbers.
Who can help me to point where I might be wrong ?
Best regards,
Jeroen
Attachments
Last edited: