Calculate Gas Behavior Step-by-Step in Simple Model

  • Thread starter Innovine
  • Start date
  • Tags
    Gas Model
In summary, @user wants help calculating rates of change of temperatures and pressures in a gas flow simulation. @user also asks for help understanding a flow rate equation. @user is unfamiliar with differential equations and digital simulation, but would like to try and fake it. @user asks for help specifying the valve/orifice and when that is done, what would be the pressure 1 second later.
  • #1
Innovine
22
5
TL;DR Summary
I wish to model a simple system with two pressurized gas containers connected by a valve.
Hi,
I wish to write a simple simulation of gas behavior. I have two tanks, connected by a valve. When the valve is opened, the gas will obviously flow and after some time it will reach an equilibrium.

I could really do with some help in calculating the rates of change of the temperatures and pressures. My code has an Update function which gets called 50 times a second, and in there I want to calculate the current state of the system.

I've been looking at ideal gas laws and valve flow rate equations but everything I've seen so far just seems to describe the steady state at the end. Can anyone help me work out how to do this step by step as the gas flows.

I guess I need some kind of flow rate parameter on the valve too.
It's fine to simplify the model a lot, I just want to get a gross idea of how this behaves..

Any help would be greatly appreciated!
 
  • Like
Likes sandy stone
Engineering news on Phys.org
  • #3
Sadly no, as I'm not really understanding everything there.

I've been trying to understand the coefficient of flow equation, but I am a bit unsure how to use it...

I guess I can simplify my problem to a tank of gas at 100,000,000pa pressure, 300k, and a volume of 0.2m^3, venting its contents to a vacuum. How would I go about specifying the valve/oriface, and when that is done, what would be the pressure 1 second later..
 
  • #5
This is actually a very difficult problem, but fortunately a near identical question was asked a few months ago:

https://www.physicsforums.com/threads/unsteady-filling-of-a-vacuum-tank.971992/
One potential difference is that due to the high pressure your flow is going to be supersonic for much of the time (and therefore fixed, which actually makes it easier). Once the pressures reach a certain threshold difference it will switch to subsonic and variable.
 
  • Like
Likes Chestermiller and berkeman
  • #6
russ_watters said:
This is actually a very difficult problem, but fortunately a near identical question was asked a few months ago:

https://www.physicsforums.com/threads/unsteady-filling-of-a-vacuum-tank.971992/
One potential difference is that due to the high pressure your flow is going to be supersonic for much of the time (and therefore fixed, which actually makes it easier). Once the pressures reach a certain threshold difference it will switch to subsonic and variable.

Ouch! Thanks I looked through that thread and sadly I cannot follow it, and I see I'll need months to brush up my math before I tackle that level. So my question now becomes, how can I fake this in an easy way to give an approximate result? Even with always using choked flow I don't know how to calculate this. If the flow is always choked, does that mean I would have a constant number of moles passing through the valve per unit time? Then I'd use PV=nRT each time step, just making n decrease linearly and keeping V and T constant, might that give an approximate result?
 
  • #7
Calculating the flow is difficult, but it is not the entire problem.

This is a time dependent problem. You will have to solve it for pressure versus time. We can help you with the equations, but first tell us. Are you familiar with differential equations and digital simulation?
 
  • #8
Innovine said:
How would I go about specifying the valve/orifice,
That is the easy part because, if you are concerned with achieving a particular time target for completing the transfer, you can choose any nozzle throat size you want; but, the larger nozzle, the higher flow rate and therefore the larger the flow rate of change per each unit of time for a given supply tank size.

While you have sonic flow (not supersonic flow, supersonic refers only to the gas velocity in the exhausting divergent section of a sonic nozzle but it does not effect the sonic mass flow, kg/sec, through the throat). Also, the flow rate will not be constant because the mass flow rate through a sonic nozzle is a function of its inlet pressure. During sonic flow, if you ignored the effect of expansion cooling in the supply tank (not a good idea if you want any kind of accuracy) then the the sonic flow rate of change due to the supply tank pressure reduction would be linear.

Once the nozzle's discharge backpressure increases to the point that the nozzle flow becomes subsonic then both the supply tank expansion cooling and the receiving tank compression heating will affect the rate of flow. Additionally at your pressures, the compressibility factor Z has to be included in the calculation. Using a filling of a vacuum tank will not change any of the above requirements because a flow is based upon absolute pressure.
Note: For the initial flow at your highest pressure there have not been any Z factor values determined, the highest pressure they are available for is 500 Bar abs. This is because the Z factors are determined experimentally, not by calculation.

Maybe a good staring point to learn some of the issues would be first developing a flow calculation for a nozzle flowing sonic into the atmosphere over a period of time. This would require addressing issue of supply tank expansion cooling vs flow rate of of change; and, then expand on that by adding the receiving tank part of the problem which requires the issue of the pressure at the end of the flow temperature vs the pressure loss due to cooling of the receiving tank. For an accurate fill time the heat transfer for both tanks during the transfer must also be taken into consideration.

Trust me on that last point, been there, done that; and in my case I was only trying to determine (accurately) the number of small tanks the could be filled to a given pressure from a single larger tank starting with a given higher pressure; and that final heat transfer issue ultimately killed my whole project. Keep in mind that the the tank's heat transfer rates are continuously changing as the supply and the receiving tank's internal temperatures vary throughout the transfer process.

Ultimately, as stated in the above post, and you observed in the referenced thread, it is very complicated process.
 
  • #9
anorlunda said:
Calculating the flow is difficult, but it is not the entire problem.

This is a time dependent problem. You will have to solve it for pressure versus time. We can help you with the equations, but first tell us. Are you familiar with differential equations and digital simulation?
I knew how to work with a differential equation 25 years ago, but sadly its all faded away. I kind of get what is intended, but I've no idea how to use them now. I am feeling very much out of my depth here :( you'll have to take it very easy on me. I am now reading a bunch of math to improve myself, but it requires some time and practice.
 
Last edited:
  • #10
I am quite curious about one thing... if the pressure difference across my valve is large, am I correct in thinking that this causes a choked flow, and when that occurs, the number of molecules of gas passing through the valve per unit time becomes a constant?

If this is so, it seems reasonably straightforward to just move x number of molecules from tank to tank each timestep, and calculate new pressures from the ideal gas law, keeping T constant (as a bit of a simplification).
What do you guys think of this approach? If it seems reasonable, maybe i can consider adding some changes to T afterwards.
In my scenario, the behavior as the pressures equalize does not have to be so accurate. I could probably continue with choked flow all the time, or just reduce the amount of choked flow as the pressure diffential becomes low, reaching zero flow at zero difference. These kinds of gross estimations are quite OK, and if there's a way to add very gross temperature approximations to it, I'd be super happy to hear some suggestions :)
 
  • #11
I realize I do need to have the temperature in there too. :/
 
  • #12
The number of molecules passing equals mass flow (kg/sec); and, as I stated above, the mass flow during sonic (choked flow) is controlled by the inlet pressure, i.e. as your supply tank and nozzle inlet pressure declines the mass flow amount will decline proportionally.
The only way to insure that the nozzle is maintained in choked flow is to limit your target receiving tank filled pressure to below the critical pressure ratio for the gas you are transferring (i.e. for air that ratio is abs P in / abs P out >= 1.4).
If you have a specified receiving tank pressure requirement that exceeds the critical ratio for your gas then as your supply tank pressure declines and your receiving tank pressure rises you are going to enter subsonic flow in the latter tank filling stage and cannot by any method "maintain choked flow".
 
  • #13
By "maintain choked flow" I just mean continue to use the choked flow equation in my model at all times. I've been saying from the start that I don't need very accurate behavior, i just need some kind of solution, any solution, which i can actually solve, and the closer to real the better...

I've been bashing my head against this quite a lot now, and think I have most of the things which I need, but there's one big issue that's confusing me, and it is the change in temperature, and how that's connected to changes in p. No matter which way I twist the equations I have both p and t as unknowns.
In real life, if I have a high pressure tank which I vent from, what regulates t so that p and t fall together, rather than say t remaining constant and p falling faster, or even p remaining constant with t rapidly changing?? I suspect that the environment plays some role, in trying to keep t the same as the ambient temperature? How can I add this so the only unknown will be the pressure? For example, I can pretend I have a heater/cooling system on my pressurized tank which attempts to change t to a particular value. I guess there's some relationship with the energy used by that system and the effectiveness of the result, but I have no idea how to proceed here. Again, I'm not looking for an exact simulation, just whatever approximation I can make to get it to behave very roughly like it might in real life. I can cut whatever corners necessary, including just using choked flow equations all the time, or just adding constants or curves instead of advanced calculations, etc. The most important thing for me is that I can actually have some kind of working model, and then the priority shifts to having more accuracy. But right now I don't even have any solution whatsoever...
 
  • #14
So start out by using the model referenced by Russ in post #5, and then add complexity from there.
 
  • #15
Chestermiller said:
So start out by using the model referenced by Russ in post #5, and then add complexity from there.
 
  • #16
Unfortunately that's way beyond my ability...
 
  • #17
Innovine said:
Unfortunately that's way beyond my ability...
There is a simplified version given in later posts in the thread in which the expansivity factor is linearized.
 
  • #18
Chestermiller said:
There is a simplified version given in later posts in the thread in which the expansivity factor is linearized.
Thanks, but I am not even able to see what you're referring to, never mind make any sense of it.
While there's no doubt very useful information in that thread, I think I'm in need of MUCH more basic help.
 
  • #19
This is where I am now:
I can simplify my problem to a single pressurized tank, with a valve to vent the contents to a vacuum. Using the ideal gas law, I am able to calculate the pressure in my tank given an initial temperature.

Now I next turn to the valve, and have found an equation for flow factor. K=Q root(SG/dP)

Am I correct in assuming that the flow factor is basically how open the valve is, and putting different numbers in here will give me Q, the volumetric flow rate?
I think that the flow rate is m^3/hr but I get confused regarding what to do next. Is that m´^3 at 1bar, or the pressure in my tank? My goal here is to calculate the mass of gass moving through the valve in a small piece of time, then subtract that from the initial mass, and use PV=nRT to come to a new p and t value.

However, I'm a bit confused as to how to separate these two unknowns. I see that the total energy is E=3/2.nRT and I guess there's a conservation of energy, but now I'm lost as to what to do next.

Hope this gives a quick insight into my current level of understanding and thought processes. Just a little nudge in the right direction would be so much more welcome than pages of equations, as I just drown.

Sorry about the lack of fancy formatting, I'm on my phone. I'll try and improve on this somewhat in my next post.
 
  • #20
Innovine said:
Now I next turn to the valve, and have found an equation for flow factor. K=Q root(SG/dP)
Go to the below to find the correct formula for sonic gas flow through a nozzle
https://en.wikipedia.org/wiki/Choked_flow
 
  • #21
  • #22
I can't say for sure without seeing the source of the equation but equation's using SG (Specific Gravity) are generally used for liquid flows; and, K factors are efficiency factors addressing the inlet and outlet configurations for an orifice; so, K cannot be used as a substitute for the size of the orifice itself.

As a result, for a basic calculation, ignoring temperature effects (isothermal), once you select an orifice size you can use your initial Supply tank mass with the critical gas flow rate equation in a series of selected pressure successive declining pressure increments between Max P tank and Min P tank to determine an approximate amount of mass flow at each increment and the time for each increment to determine the time required to totally vent the tank.

If you want to include temperature simply recalculate the tank gas T vs P for each successive tank pressure flow calculation; however, unless you can incorporate the temperature rise from the surrounding ambient temperature in each step's new supply tank pressure increment, without an heat transfer value for warming the supply tank gas during its venting its theoretical temperature at the end of your venting calculation will be absolute zero °K, which is far from accurate for actual Earth atmospheric temperature conditions.

Personally, from my previous experience on this type of process, I would suggest you use the isothermal method. If you select smaller orifice sizes the venting time will be longer and the longer the venting time, the closer the isothermal case will come to simulating the actual time with heat transfer.
 
  • #23
Understood, thanks, and I really am starting to get somewhere now at last. I found the equation with K here:https://en.wikipedia.org/wiki/Flow_coefficient

unless you can incorporate the temperature rise from the surrounding ambient temperature
Now this is something I would be completely prepared to fake! What might a heat transfer value have for a value?`This part of the system is not at all important to me, and I can very easily say that there's a surrounding ambient temperature, and in fact adding a heating system inside the tank is a wishlist item for me...
 
  • #24
Innovine said:
What might a heat transfer value have for a value?
For the answer to that question go to:
https://www.engineeringtoolbox.com/conductive-heat-transfer-d_428.html
(Please, in the future use Google for direct questions like the above. You will get more comprehensive answers than I am capable of taking the time to provide. I will still be willing to answer any followup questions you might still have on a subject.)

The other heat factor that is involved in your process is the following:
Quoting Google:"Specific heat capacity is the amount of heat energy required to raise the temperature of a substance per unit of mass. The specific heat capacity of a material is a physical property. ... In SI units, specific heat capacity (symbol: c) is the amount of heat in joules required to raise 1 gram of a substance 1 Kelvin."

Having provided the above, I would suggest is that you not immediately start trying to incorporate heat transfer and specific heat capacity into your program. Instead, start with a simpler procedure using dT, based upon your tank's (gas) ambient temperature at the start of the venting and an arbitrarily selected tank (gas) temperature at the end of the venting, then divide that total dt by your number of chosen pressure steps to establish a dt between each step. Then use the P vs T relationship to determine your tank pressure for the mass flow in each step. By using this method you can quickly adjust your calculation by simply revising your originally selected final temperature; and, you will avoid having to deal with a combined J's / unit time heat injection rate vs a gas mass heat capacity transfer process.
 
  • #25
I have a little problem there with selecting a final temperature, since I don't know when the player may close the valve. But I'll go have a play aroundewith this now and see what I can come up with, thanks!
 
  • #26
If it helps, keep in mind that the pressure decline and temperature decline are concurrent; so, if you have a fixed maximum staring pressure and orifice size and select a maximum temperature change for the total depressurization and apply a percentage of that change to each of your steps, then it won't matter when the player closes the valve.
 
  • #27
JBA said:
If it helps, keep in mind that the pressure decline and temperature decline are concurrent; so, if you have a fixed maximum staring pressure and orifice size and select a maximum temperature change for the total depressurization and apply a percentage of that change to each of your steps, then it won't matter when the player closes the valve.

I'm going to try implementing some of this today, and that should help me get my head around it, as well as raise a few more concrete questions.
 
  • #28
I took a go at implementing this today and it went pretty well I think. I'm keeping T constant for now. I have run into one big unknown regarding the discharge coefficient. This doesn't have to be all that precise, but still, what ballpark number should I put in here? For example, if I have an oxygen tank pressurized to 150bar, and there's a square centimeter hole in it, how long would it take to depressurize the whole tank to ambient air pressure? Just roughly, are we talking seconds, or minutes... this would help me get a reasonable ballpark value for the discharge coefficient.

It doesn't seem to matter what initial pressure I set, its still more or less the same time to get down to a low P. Does that seem right? I am keeping T constant and using the choked flow equation all the time.

Compared to these numbers: https://physics.stackexchange.com/q...-tank-emptying-over-time-through-a-given-area
I need to set the discharge coefficient to 2.3 (found by experimentation), and then I get a result very close to 1m30sec to get below 1000kPa. I also see the mass flow rate decrease, but i am currently unable to plot the data. I only have this one example to compare with so I don't know if my model works for other initial conditions.
 
Last edited:
  • #29
Innovine said:
I need to set the discharge coefficient to 2.3 (found by experimentation),

I recommend you use "Cd" because this applies directly to the efficiency of the nozzle bore; whereas, "K" is a factor for addressing the effects of the shape at the nozzle entry and pipe inlet size ratio vs the pipe size at the nozzle exit as shown below:

K Factors for Piping Inlets & oulets.JPG


The maximum value for Cd is 1.00 so adjust your nozzle bore area to result in a venting time a bit longer than your target time and then adjust the nozzle flow down to achieve you target venting time using the nozzle Cd coefficient.

For a quick reference on nozzles and nozzle coefficients, including K vs Cd see:
https://neutrium.net/fluid_flow/discharge-coefficient-for-nozzles-and-orifices/
Innovine said:
I also see the mass flow rate decrease, but i am currently unable to plot the data. I only have this one example to compare with so I don't know if my model works for other initial conditions.
If you are using a simple step by step method using the choked gas flow equation then your program should work for any initial condition; but, if you are using atmospheric pressure (0 Bar gauge = 1 Bar absolute) as your outlet backpressure then your flow calculation, which is based Bar abs, will not be precisely accurate below the critical pressure ratio for your gas.
For oxygen which has a k =1.4 the P critical pressure ratio = 0.528, so as soon as your nozzle inlet pressure falls below 1.89 Bar gauge then the idealized flow requires the subsonic flow equation. At the same time, from a practical standpoint, given your high starting pressure, that small flow error at the end of the venting may not be worth worrying about.

Innovine said:
i am currently unable to plot the data.
What are you using for doing your calculation? If you are using MSExcel then it is very easy to plot your data using the "x/y scatter" choice under the "Create Chart" option.
 
  • #30
Thanks JBA, you're a great help. I am using Cd and the formula you linked to earlier, yep. Is there a non-choked version also? The thing with picking nozzles is, when you say adjust the nozzle to get the target venting time, I don't know what a reasonable venting time value actually is, to adjust the nozzle towards.. So for example, if we have a 100bar tank of O2 at 273K and we open a 0.001m^2 hole in the side, very approximately how long does it take to drop to almost atmospheric pressure? I need an actual real world time estimate here, so I can adjust my nozzle to achieve it in my sim.

I am programming this in C# in the Unity game engine. I can probably write values to a text file and plot them in Excel but i haven't gotten to that thet.
 
  • #31
There is no "right" flow time or rate other than what is required by a given system application. For example, in the pressure relief valve company where I gained the majority of my knowledge about gas and liquid flow they have a certified flow test laboratory where they test and certify the flow rates of all sizes of relief valves from very low pressures to up to 70 Barg; and, the nozzle used must remain at critical flow for test accuracy and to do that they require a set of flow nozzles of diameters ranging from 25.4mm to 100mm depending upon the pressure rating and flow capacity of the relief valve being tested.
So you need to establish why the tank oxygen is being vented and how the time it takes for venting relates to what the user is trying to accomplish to determine your appropriate flow rate and thereby your correct nozzle size.
 
  • #32
Of course there is, can you just give me a number. I told you the area. If I drill a hole and uncork it, gas will come out. Will it take 2 seconds or 2 minutes to empty?

Its getting kind of frustrating that you keep saying stuff like "to set the nozzle, pick a time to empty" and I ask "ok, what kind of time" and you reply with "that depends on the nozzle". Are you trolling me now?

Pick any nozzle. That will do. Its a lovely nozzle. How long does it take to empty the tank using that nozzle?

The reasons why the tank is being vented? Because there's a 0.001m ^2 hole in the side of it. That'll do. The user is trying to accomplish the emptying of the tank.

I think perhaps you enjoy discussing flows and nozzles, but really that is not helpful in this situation. I am making a video game, this is a tiny part, I just want to see the pressure needle decrease, and not have it so someone says "thats a bit fast". some rough numbers are all I need. Mnybe I would be bett'r off going to a scuba diving forum and asking how long it takes for a tank to empty if I cut the hose or put a hole in it. That's about the accuracy I require.
 
Last edited:
  • #33
That depends upon the size of the hole you drill.
Once again "the reason the user is venting the gas determines whether the flow should be in seconds i.e. to prevent a overpressure tank from exploding; or, you are simply depressurizing the tank for maintenance which could be several minutes to an hour for a large tank.
For my applications, a blowdown test could be only for a few seconds or a flow test could last for several minutes depending on how long the supply tank pressure will maintain the critical nozzle flow required to accomplish the required test goal.
 
  • #34
Addendum to the above: At your intended high pressure the person drilling the hole is probably going to killed by the escaping gas velocity anyway.
 
  • #35
Beyond all of the above, if you give me more information about how you are applying your venting program then maybe I can give you a better approximation of an appropriate venting time for that application but that will only apply for one given max tank pressure.

From your statement referencing a "player" it would appear that you are using this for an entertainment game and if so, as I stated in another thread regarding how realistic an event simulation needed to be for an game application, consistency of results to insure an even playing field across all player's scenarios is more important than precise accuracy of the simulation. In that respect, if a player needs to react in some manner to your tank venting, then a shorter venting time will be more demanding in terms of the reaction time demanded from the player.
 
Back
Top