# Simple gas model?

#### Innovine

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!

Related Mechanical Engineering News on Phys.org

#### anorlunda

Mentor
Gold Member
Welcome to PF.

If you have an orifice flow calculator, can you then finish the job yourself?

#### Innovine

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..

Mentor

#### russ_watters

Mentor
This is actually a very difficult problem, but fortunately a near identical question was asked a few months ago:

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.

#### Innovine

This is actually a very difficult problem, but fortunately a near identical question was asked a few months ago:

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?

#### anorlunda

Mentor
Gold Member
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?

#### JBA

Gold Member
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.

#### Innovine

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:

#### Innovine

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 :)

#### Innovine

I realise I do need to have the temperature in there too. :/

#### JBA

Gold Member
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".

#### Innovine

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...

#### Chestermiller

Mentor
So start out by using the model referenced by Russ in post #5, and then add complexity from there.

#### Innovine

So start out by using the model referenced by Russ in post #5, and then add complexity from there.

#### Innovine

Unfortunately that's way beyond my ability...

#### Chestermiller

Mentor
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.

#### Innovine

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.

#### Innovine

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.

#### JBA

Gold Member
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

#### Innovine

Go to the below to find the correct formula for sonic gas flow through a nozzle
Thanks, but why not the formula I found?

#### JBA

Gold Member
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.

#### Innovine

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...

#### JBA

Gold Member
What might a heat transfer value have for a value?
For the answer to that question go to:

(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.

#### Innovine

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!!

"Simple gas model?"

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving