//Valve flow calculation script for BasicAirData.eu blog
//Used for preliminary pneumatic sizing
//JLJ@www.basicairdata.eu

R=8.314462175;//J/mol/K Gas constant 
Mwair=28.97e-3;//kg/mol Molecular 
Rair=R/Mwair;
P1=108751;//Inport
P2=61640;//Outport
Pr=101325;//Reference pressure
T1=(273.15+20);
T2=T1;
Tr=273.15;//Reference temperature
rhoref=1.2922;//Density of air at Pr,Tr
//Valve 01-211P-015H0 63111A 6V DC 2W Producer FAS
Kv=0.55;//
Kv1=Kv/1000*60;//0.033 m^3/h 
rho1=P1/Pr*Tr/T1*rhoref;
rho2=P2/Pr*Tr/T2*rhoref;
P1=P1/100000;
P2=P2/100000;
Qv1=519*Kv1/((rhoref*T1/((P1-P2)*P1))^0.5)
Qm1=Qv1*rhoref;
printf("Flow m^3/h %f \n",Qv1)
printf("Flow kg/h %f\n",Qm1)
printf("Flow kg/s %f\n",Qm1/3600)
//Calculus for the pressure variation in a closed volume
//with a single inflow. The flowrate is the higher flowrate deliverable by the valve.
V=7.85e-4;//m^3
Ttank=T1; //°K
//P=rho1RairTtank
//rho1=M/V
//Pdot=1/VRairTtankmdot
//mdot is the flowrate
mdot=Qm1/3600; //kg/s
Pdot=1/V*Rair*Ttank*mdot;
printf("Max pressure slope Pa/s %.2f\n",Pdot)
