BAGS - btrettel's air gun simulation

Threads about how water guns work and other miscellaneous water gun technology threads.
User avatar
SSCBen
Posts: 6449
Joined: Sat Mar 22, 2003 1:00 pm

Re: BAGS - btrettel's air gun simulation

Post by SSCBen » Fri Jan 23, 2009 2:51 am

The coefficient of friction is one thing that most people won't know, but the approach to that problem that GGDT (now at least) and BAGS take is similar. If I can blow the projectile out the barrel with my mouth, I put in 2 psi as the "friction pressure". If there's more friction I make a quick test rig and see how much pressure is required to move the projectile.

The web interface should feature no optimization aside from finding the ideal barrel length of a given situation. Anything else would take too long even if write an optimized search method and use constraints. Sometimes I leave BAGS running loops for hours. Heck, I once left my external ballistics model running for something like 8 days straight to make a big table of values with good precision.

I've been looking at trying to fit measured pressure curves to BAGS. Basically, you can know most of the inputs except for the flow coefficient. In reality the flow coefficient (Cv here for those who don't know) is basically a big fudge factor and it'll vary with pressure and gas chamber volume. If you know the barrel pressure vs. time, you can figure out the relationship between the flow coefficient and the pressure differential with reasonable accuracy.

Just as a test I simulated a gun where Cv = 3 + 0.02 * dP, made a regression of the barrel pressure vs. time curve, and then ran it through my program which simulates the gun, finds Cv from the pressure curve, and makes a table of Cv vs. dP. I then made a regression of that curve... it came up as Cv = 3.0286 + 0.019763 * dP. Pretty dang close.

Of course, this approach requires you to know the barrel pressure with respect to time. You can figure that out with coils on the barrel and a magnetic projectile as I mentioned earlier with a link. The math to figure it out would be pretty complicated but I think I can simplify it with some approximations. You also could use the piezo like in the other link I had, but I'm not completely sure if that approach makes anything meaningful.
Last edited by SSCBen on Fri Jan 23, 2009 3:14 am, edited 1 time in total.

User avatar
SSCBen
Posts: 6449
Joined: Sat Mar 22, 2003 1:00 pm

Re: BAGS - btrettel's air gun simulation

Post by SSCBen » Mon Jan 26, 2009 8:17 pm

The plan at the moment is to completely rewrite BAGS from the ground up to take more things into account and be more useful. BAGS will be more like a library of functions this time around. This will make BAGS much more powerful because those who'll only want something basic like GGDT can easily have it, and those who want to work more closely with the data can too. Writing programs to optimize guns, make regressions from data, etc. will be much easier with this approach.

I'm going to read a good deal about compressible flow before starting, so don't expect any big changes soon.

User avatar
Silence
Posts: 3825
Joined: Sun Apr 09, 2006 9:01 pm

Re: BAGS - btrettel's air gun simulation

Post by Silence » Mon Jan 26, 2009 9:03 pm

That sounds pretty useful at the moment. Keep us posted!

User avatar
SSCBen
Posts: 6449
Joined: Sat Mar 22, 2003 1:00 pm

Re: BAGS - btrettel's air gun simulation

Post by SSCBen » Thu Jan 29, 2009 6:24 pm

I've been looking into including at least some non-idealities in BAGS, but there does not seem to be any benefit you use high pressures (100 bar and up) or high temperatures. The implementation will be a huge pain too, but I'm up for a challenge, especially if it'll make modeling of supersonic situations more accurate.

With that being said, I'll definitely include non-idealities where they'd make a difference in normal situations. For example, to find the number of shots from an HPA tank it would be best to include some non-idealities. Ideal gas assumptions suggest the temperature from the HPA tank through the regulator is constant. Non-ideal assumptions say it'll decrease from about 300 K to 270 K assuming no heat transfer. This is not extremely significant but it will make a difference, so I will include it.

Here's the data I'm looking to import: http://www.nist.gov/srd/PDFfiles/jpcrd581.pdf

Note that I have a full-text version of that report, but I can't find a publicly accessible full-text version. I'll post my spreadsheet version of the data tables later if someone wants a copy. I first need to convert the tables from a molar basis to a mass basis because that is much more useful to me.

Edit: I've decided I'm going to design the new version of BAGS to accommodate both ideal, non-ideal, and mixed models. This will make BAGS even more powerful than I planned and should actually simplify things to a certain extent.
Last edited by SSCBen on Fri Jan 30, 2009 2:50 pm, edited 1 time in total.

User avatar
SSCBen
Posts: 6449
Joined: Sat Mar 22, 2003 1:00 pm

Re: BAGS - btrettel's air gun simulation

Post by SSCBen » Sun Feb 01, 2009 3:50 am

I've updated my trettel.org page on BAGS one last time with a big partial list of things I'd like to implement in BAGS 2. This project's going on the backburner as I focus on school and some other things, but I anticipate I'll start working on BAGS 2 at the start of the summer.

User avatar
SSCBen
Posts: 6449
Joined: Sat Mar 22, 2003 1:00 pm

Re: BAGS - btrettel's air gun simulation

Post by SSCBen » Sun Apr 26, 2009 2:14 am

BAGS has been rewritten. BAGS now uses SI units. The code has many more comments. Dynamic pressure modeling has been corrected. Multiple gases can be chosen from. Some crude Mach effects were added (edit: which since have been removed). Earlier temperature drop due to work in the barrel was not always applied and I have fixed that.

BAGS will be released as BAGS 1.0 once I add a GUI, some useful features (like optimization code and calibration against data), and revise BAGS' algorithms further.

I've also since learned that my guess as to how to model the temperature drop from projectile work is correct if energy associated with the gas velocity is neglected. An identical equation can be derived from the Reynolds transport theorem. Multiply the energy equation by dt and integrate between two discrete times using rectangle Riemann sums. Rearrange and you'll have the same equation I used. This I find reassuring as I was just guessing what would be appropriate.

Down the road, BAGS 2.0 will be released. I plan to write a fairly robust CFD code to take wacky heat transfer and shock wave effects into account. It should be pretty interesting, but useless unless you're designing transonic or supersonic gas guns (or looking for a challenging project and potential resume piece like me).
Last edited by SSCBen on Tue Apr 28, 2009 1:43 am, edited 1 time in total.

Roboto
Posts: 6
Joined: Sun Apr 26, 2009 2:44 am

Re: BAGS - btrettel's air gun simulation

Post by Roboto » Sun Apr 26, 2009 2:46 am

So now I have to wait to build my WBL :P

User avatar
SSCBen
Posts: 6449
Joined: Sat Mar 22, 2003 1:00 pm

Re: BAGS - btrettel's air gun simulation

Post by SSCBen » Sun Apr 26, 2009 11:35 am

Welcome to SSC!

There's no significant difference in the results of the new version and the one online at trettel.org that I linked to in the first post. So you can use the existing version if you'd like.

You also can use GGDT if you want something already full developed: http://www.thehalls-in-bfe.com/GGDT/

Edit: Also, once BAGS 1.0 is released a very detailed explanation and justification of its workings will be put online at trettel.org. I do this because I want people to learn about engineering and the more knowledgeable could expose flaws in my model or have suggestions.
Last edited by SSCBen on Sun Apr 26, 2009 4:15 pm, edited 1 time in total.

User avatar
SSCBen
Posts: 6449
Joined: Sat Mar 22, 2003 1:00 pm

Re: BAGS - btrettel's air gun simulation

Post by SSCBen » Fri May 01, 2009 2:06 pm

I've released my current simulation as BAGS 1.0.0: http://trettel.org/bags/

To use this you will also need gas.txt, a file with gas data. It is available on the BAGS page.

The syntax of gas.txt should be fairly obvious. You can modify or add to these values as you'd like. Note that Cp and Cv are in units of J/kmol*K and MW is in units of kg/kmol. Very often Cp and Cv are in units of kJ/kmol*K, so multiply the value by 1000 to convert to J/kmol*K.

Note that CO2 and propane (C3H8) may be inaccurate due to the gas liquefying. Eventually I'll add some code to catch this and I'll stop the simulation at that point because it'd be hard to model and there's no advantage to liquefying the gas outside of storage. I'll also add some code to approximate the vapor pressure of the gas. These changes will require a different gas.txt file.

I've made a decision to completely neglect shock formation from BAGS 1.0. While I'm not completely aware of how GGDT models shocks, I do know that GGDT is inaccurate and as far as I can tell, any model that will accurately predict the effects of shocks should be made differently than BAGS is. BAGS already is accurate for solidly subsonic projectiles and I've added a Mach number output to indicate whether or not the results may be inaccurate.

Most of the variable names are the same as the earlier version of BAGS. The loop is essentially the same as well.

The code is highly commented, however, there are some spots that could do better.
Last edited by SSCBen on Fri May 01, 2009 2:39 pm, edited 1 time in total.

Locked