How does gas flow between regions of differing pressures?
How does the momentum of the gas effect that flow between regions of differing pressures?

I am trying to program a simple simulation of gas flowing between regions in a 2d grid. I do not have a very strong background with physics (never got to fluid dynamics).

To try to keep things simple I am assuming that:
-each region in the grid is the same volume
-each region's gas is uniform (sharing x,y velocity {bulk flow?}, temperature, pressure, mass, density etc. )
-each region will interact with the 4 cells around it (up, down, left, right)
-calculations to be done for fractions of a second
-relatively slow flows, in normal pressure and temperature ranges. nothing super sonic or edge cases.

example local grid:

[x] [a] [x]

[b] [c] [d]

[x] [e] [x]

a,b,d & e are low pressure, with no net momentum.
c is high pressure, with net momentum @ d .

this is what I am thinking happens, but I can't find a physics example thats close to this that I can understand the math on.

events during a half second:
c expands pushing gas into regions a, b, d & e.
b would get less gas than a & e due to expansion being opposed by the momentum of c.
d would get more gas than a & e due to expansion being aided by net momentum of c.
pressure overall equalizes some.

a) gains gas & momentum away form b
b) gains small amount of gas and momentum away from b
c) loses gas and momentum @ d decreases.
d) gains large amount of gas and momentum away form b
e) gains gas & momentum away form b

  • $\begingroup$ Well you have a problem then, because you need fluid dynamics for that, differential equations, and numerical methods. I think there are free classes online tho, that can help you, as any answer here would already encompass a small course. $\endgroup$ Apr 14, 2019 at 1:37
  • $\begingroup$ @AtmosphericPrisonEscape do you have any links to those courses handy? or links to similar solutions? I am asking for help with a fluid dynamics question because I never learned fluid dynamics, and I have not been able to find an example that was similar enough to answer my question. its a fairly large field and not very accessible to someone learning from books. learning about pipes and streams is interesting, but doesn't really come near this question. saying I have a problem is a bit redundant, and doesn't feel helpful. $\endgroup$
    – Daniel B.
    Apr 14, 2019 at 6:33
  • $\begingroup$ Well, what you would be googling for is "Computational fluid dynamics introduction", but after looking over a few things including Khan academy, I don't think there are ready solutions to your problem. I can try and give you some hints where to look further in an answer though. $\endgroup$ Apr 14, 2019 at 12:41
  • $\begingroup$ I might suggest doing a search for acoustic phenomena and studying how sound waves propagate in air. Otherwise, I have to wonder what you are trying to model here. Is this large scale such as with the weather (high + low pressure fronts) or is this nearly at a molecular scales. Finally, the iteration levels that you are undertaking are sequential along each cell, whereas in reality, each cell changes cooperatively in parallel. You've cut yourself a big project both for the fundamentals you will need to understand as well as for the programming insights you will need to apply. $\endgroup$ Apr 14, 2019 at 12:54

1 Answer 1


To give you a bit of background on this, what you're trying to do is essentially to solve Richardsons first weather prediction problem (which he did by hand on a 3x3 grid laid over central Europe). For more on this you can see wikipedia.

The first weather models used the primitive equations (which are still used for teaching purposes and other simple problems today). We might simplify those further by assuming your setup is 2D, dropping coriolis force and advective terms, so that the differential equations you want to solve are

  1. The continuity equation $$\frac{\partial \rho}{\partial t} + \frac{\partial v_x}{\partial x} + \frac{\partial v_y}{\partial y} = 0 $$
  2. The Euler equations $$\frac{\partial v_x}{\partial t} = - \frac{1}{\rho} \frac{\partial P}{\partial x}$$ $$\frac{\partial v_y}{\partial t} = - \frac{1}{\rho} \frac{\partial P}{\partial y}$$ and the Equation of state $P=c_s^2 \rho$, where $c_s$ is the constant sound speed.

As next step you need to discretize the differential terms, so that they become solvable on a grid. Without going into details, let us denote any quantity $Q(t,x,y)$ at timestep n and at coordinates $i,j$, where $n,i,j$ are integer values, as $Q^n_{i,j}$.

Then a time difference is approximated in the finite difference framework as $$\frac{\partial Q(t,x,y)}{\partial t} \approx \frac{Q^{n+1}_{i,j}-Q^n_{i,j}}{\Delta t}$$ where $Q^{n+1}_{i,j}$ indicates the Quantity at time n+1, after performing the time integration with timestep $\Delta t$. Similarly for spatial derivatives we can take $$\frac{\partial Q(t,x,y)}{\partial x} \approx \frac{Q^{n}_{i+1,j}-Q^n_{i,j}}{\Delta x}$$ if $v_x >0$ and $$\frac{\partial Q(t,x,y)}{\partial x} \approx \frac{Q^{n}_{i,j}-Q^n_{i-1,j}}{\Delta x}$$ if $v_x < 0$ (note the change in indices $i,j$). We introduced $\Delta x$ here, which is your cell size in x-direction. Similar for $\Delta y$. Same for the y-direction with the j-index. If now the evolution equation for Q is $$\frac{Q^{n+1}_{i,j}-Q^n_{i,j}}{\Delta t} = R,$$ where R is some arbitrary right-hand side, then the computation you have to do is $$Q^{n+1}_{i,j} = Q^n_{i,j} + \Delta t \cdot R,$$ for all quantities Q (in this case $\rho, v_x, v_y$), for all cells (one loop for each direction).

If you want to evolve this system for longer time than only one timestep, then you have to observe that $\Delta t$ underlies the so-called CFL condition. Also observe that no matter how many timesteps you integrate your problem for, you need to consider what your simulation boundaries should do, and what the initial conditions look like.
For the initial conditions I would recommend you to solve the system of discretized equations in such a way, that you have $\partial Q/\partial t=0$ everywhere (so that you start in a steady state), and then you can perturb this steady state by making one $v_{x,ij}$, or $v_{y,ij}$ too large, which seems what you wanted to inspect initially.
In order to see that the boundaries are a problem, consider the following: How do you compute $\partial v_x/\partial x$ at the leftmost cell value? There is no cell value left of it, but you need one, if $v_x < 0$ there. So then you might want to look into periodic boundaries or reflective boundaries.


Yeah, this is the absolute minimum you need to do to solve your problem. You might do faster by hand.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.