# How to model/simulate pressures and flows in a network of pipes

I'm having a hard time finding information on how to model/simulate this. I attached a couple files, both of which show an example tank & pump network. It's just nonsense that I made up for this post, but it shows what kind of system I'm trying to simulate.

I've been looking on the web to find information on how to do this, but I keep running into formulas that are way more complex than what I need to do. I just want to know what the pressure and flow is at any node in the system, with 80% or so accuracy. There's no need to consider fluid compression, and we can just use a constant for the resistance experienced through valves or narrowing pipes. We don't need to consider friction of fluid against piping. We can ignore heat. It's important to note, again, that I don't need complete accuracy, it's much more the behavior of the simulated system that is important.

I've tried this going in both directions, that is following a flow path down from the tanks/sources and propogating pressure changes through the system, and I've also tried it directly from the node in question, and considering that each node has a number of source nodes in terms of pressures and flows. Both of these simulated SW systems become highly erratic the further downstream from the pumps that you get, and the more on/off valves that I put into the system.

Even if you just told me where to look or what book to read, that would be a huge help. If there's example source code out there somewhere that does this, I will buy you a 60 oz beer of your choice.

(post edit 4/12)

Thanks for the answers so far, I've ended up spending quite a bit of time looking around for a solution that already exists, because I was just convinced that many have run into this problem before, and knew that it was solvable in a general sense. Part of the reason I was so interested in a general solution is that I can rip through 12 more of these simulations that I have to do quickly and accurately if that's the case.

I've found another piece of software called EPAnet, which seems like a simpler solution than what was listed below, and I'm looking through their SDK at the moment and playing around with it. I'll keep you posted, the few that are interested ... this might not be a big deal to most, but to the few that it matters to it will be huge, so I'll write up what I find.

(edit 4/13)

I've spent the last two days building a solid wrapper around the EPAnet programmer's toolkit, and making a scratch program that does some of the things I want to do. (Incidentally, I've broken a new record for the # of times in a day I can make LabVIEW crash quickly and silently.)

It's really quite complex underneath, and I'm delighted by how much mathematical power I can stand on. I don't think they've fleshed out all the issues, so I've been working around some of them. But it's looking like it's 80% chance so far that it's going to work for what I want.

-
You keep running into horrendous difficulty because the full problem is one of the touchstone "hard" problems in physics (and for that matter in computational methods). Its not my field, but I know a few people who are in it. I don't think they ever use a system as simple as you describe. – dmckee Apr 10 '11 at 20:51
60 oz beer sounds like a fine bounty to me :) Just to make it clear (sorry if I am blind): is your situation stationary (i.e. with constant flows) or not (due to finite amount of water in those tanks)? – Marek Apr 10 '11 at 20:52
It is not stationary, but if I could at least get a stationary model working correctly, I would be much better off than I am right now. I think I could add in special conditions to get a non-stationary system modeled fairly correctly. – Spatula City Apr 10 '11 at 21:08
@Ben Phillips Have you thought of transforming your problem to an electric circuit? Your simplified behavior seems amenable to an electrical analogy (bomb -> source, pipe -> resistor, tank -> capacitor, ...). – mmc Apr 13 '11 at 2:22
Pardon the naive question, but could you explain the various symbols in the diagram? The tanks are obvious enough. I assume the two-triangles thing is a valve. What about the two little circles with lines through them? And the triangle of horizontal lines (looks like an electrical ground symbol)? Also, what is the action of a valve? Does it limit the rate of flow to a fixed value, or just present a fixed aperture, or ...? – nibot Apr 13 '11 at 2:49

My advice is to look into the Lattice Boltzmann Method, which is robust and simple for athermal non-compressible flows. Try out this open source GPL3 software for example:

http://www.lbmethod.org/palabos/

-