Flows in pipes and devices

Fluids are always on the move inside the things we build. Water bends around the corners of pipes, jets squeeze through valves, and steam billows upwards from a vent. On this page, we simulate a handful of these flows by solving the Navier–Stokes equations inside pipes and devices, using a dye to show where the fluid goes.

We’re aiming to capture the qualitative behaviour of these flows - where eddies form, how jets break up, and how a flow settles down - rather than to compute precise values. These simulations are illustrations, not engineering tools, and we’ll be honest below about what they can and can’t tell you.

The flows

Each of these simulations shows a dye carried by the flow. Press to outline the walls and valves of the device, or to instead see the speed of the fluid, its vorticity (how much it is spinning), or its pressure.

You can change the speed of the flow, the viscosity $\nu$, and how quickly old dye fades (more on this below) in the Parameters menu. Increasing $\nu$ gives smoother, more sedate flows; decreasing it gives more eddies.

The equations

We solve the 2D incompressible Navier–Stokes equations for the fluid velocity $\v{u} = (u,v)$ and pressure $p$,

\[\begin{aligned} \pd{\v{u}}{t} + (\v{u}\cdot \vnabla) \v{u} &= - \vnabla p + \nu \nabla^2 \v{u} - \frac{\chi}{\eta}\v{u},\\ \vnabla\cdot\v{u} &= 0, \end{aligned}\]

where $\nu$ is the viscosity. The final term, $-\chi\v{u}/\eta$, is how we include the walls of each device, and is discussed below.

The dye is a passive scalar $S$, which is carried along by the flow and diffuses slowly with diffusion coefficient $D$,

\[\pd{S}{t} + \v{u}\cdot\vnabla S = D\nabla^2 S - \lambda S.\]

The final term lets old dye fade at a slow rate $\lambda$. Dye is added to the flow at the inlet of each device, in pulses, so that patches of undyed (black) fluid show the motion.

For the plume, the dye also marks warm fluid. We then add a buoyancy force $\beta S$ to the vertical velocity equation, which is the Boussinesq approximation also used in our thermal convection example.

Walls

Rather than shaping the computational domain to fit each device, we fill a rectangle with fluid and make the walls out of a very resistive ‘porous’ material. The function $\chi(x,y)$ is equal to 1 inside the walls and 0 in the fluid, smoothly changing between the two over a couple of grid points. Inside the walls, the term $-\chi\v{u}/\eta$ brings the fluid to rest very quickly.

This is known as Brinkman penalisation (Angot, Bruneau & Fabrie, 1999). As $\eta \to 0$, it reproduces the usual ‘no-slip’ condition, where fluid sticks to the walls. We take $\eta$ equal to the timestep, which stops the fluid inside the walls within a single step. Valves are discs of wall that grow to close off a pipe and shrink to open it again. Because the fluid is incompressible, it can’t be pushed into a closed pipe, so the flow into the junction is turned down before both of its valves shut.

Inflow and outflow

Fluid enters through the left-hand edge of the domain (or the bottom, for the plume) with a prescribed, parabolic velocity profile, matching a fully developed flow in a pipe. Its strength can vary in time, to pulse the flow or to switch it off when every valve is closed.

All other edges are left ‘open’: there, we set $p=0$ and impose zero normal derivatives on the velocity, so fluid can leave freely. Wherever an edge passes through a wall, the walls hold the fluid at rest anyway, so the same conditions can be used for every device.

Open boundaries are a common source of trouble in fluid simulations, as eddies leaving the domain can reflect back in and grow. To avoid this, we add a thin ‘sponge’ layer next to each open edge, where the viscosity is increased by $\nu_s$ and the dye is removed. In the equations, $\sigma$ marks the sponge layers, rising from 0 to 1 across them. This calms the flow just before it leaves the screen.

Numerical details

VisualPDE can’t solve the incompressibility condition $\vnabla\cdot\v{u} = 0$ directly, as it is non-local. As in our Navier–Stokes example, we instead let the pressure evolve according to

\[\pd{p}{t} = -c^2\vnabla \cdot \v{u} + \nu\nabla^2 p,\]

which is known as entropically damped artificial compressibility (Clausen, 2013). Here, $c$ is the speed of pressure waves, which must be fast compared to the flow. We use $c = 12$ in the bent pipe, valve, junction and contraction, whose flows pulse or switch, and $c = 6$ and $c = 10$ in the steadier wavy channel and plume. This keeps $\vnabla\cdot\v{u}$ small whilst letting the simulations run quickly. One consequence is worth knowing: during sudden changes, such as the start of each dose in the contraction, the fluid behaves a little as if it were in a flexible tube. Some of it is briefly stored by compressing it, so the change takes a moment to reach the far end of the device. The flow averaged over time is unaffected.

A few other choices are worth knowing about:

How faithful are these simulations?

We checked the method against two classical flows, which are included as simulations you can run yourself.

We also checked that the speed ratio, the pressure drop, and the shedding frequency all change by less than 1% when the pressure-wave speed $c$ is reduced from 10 to 6, the lowest value used in the device simulations.

That said, please take these simulations with a healthy pinch of salt. In particular:

What these simulations do capture faithfully is the mechanisms: separation at bends, the roll-up of jets, the shedding of vortices, and the redirection of flow by valves. These all come directly from the equations above, without any extra forcing to make the flow more lively.

Embedding

To show any of these simulations without the VisualPDE interface (for example, as a background on a web page), embed it in an iframe and add &clean to the end of its link, as in

<iframe src="https://visualpde.com/sim/?preset=FlowBentPipe&clean" frameborder="0"></iframe>

Embedded simulations pause automatically when they scroll out of view, and restart themselves if they ever become unstable. Each device rescales itself to fit the shape of the frame, from wide banners to tall phone screens.