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.
-
A bent pipe. Fluid is pumped through an S-shaped pipe with a gently pulsing flow rate. At each bend, the flow peels away from the inside wall (known as ‘separation’), shedding eddies that tumble along the pipe and mix the dye.
-
A jet through a valve. Fluid is forced through a narrow throat between two cones. It emerges as a jet, whose edges roll up into vortices that break down into a chaotic, mixing flow in the widening cone.
-
A switching junction. A pipe splits into two branches, each with a valve that opens and closes in turn. Watch the flow redirect itself as the valves switch, and squeeze past each valve as it opens. When both valves are shut, the flow stops entirely: there’s nowhere for the fluid to go.
-
A wavy channel. Fluid flows smoothly through the first part of a sinuous channel. After the trough, the flow separates from the wall, and a train of vortices is shed along the rising section. Their dark cores are pockets of undyed fluid trapped by the spinning flow.
-
Dosing through a contraction. A wide chamber narrows to a thin tube. Each dose starts with a burst of flow that throws up vortices in the chamber, before the flow slows and settles into a calm, steady stream.
-
A rising plume. Warm, dyed fluid is released from a vent at the bottom. Because it is lighter than its surroundings, it rises and sways, rolling up into puffs as it goes.
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:
- Advection. The transport terms, such as $\v{u}\cdot\vnabla S$, are computed with a third-order ‘upwind’ scheme, which takes values from the direction the flow is coming from (Kawamura, Takami & Kuwahara, 1986). This keeps the dye sharp, but slightly damps the very smallest eddies, those only a few grid points across. In VisualPDE syntax, the derivative for positive $u$ is
(S_xb2 + 2*S_x)/3. In each simulation’s equations, these terms appear as $A_u$, $A_v$ and $A_S$, which are defined (and hidden from the typeset equations) in the Substitutions menu. - Timestepping. We use the classical Runge–Kutta scheme (RK4). The simpler forward Euler scheme is unstable for these pressure waves unless the viscosity is large.
- Fitting the screen. Each device is drawn so that it fits the shape of your screen, so it will look a little smaller in very wide or tall windows.
- Speed. Each simulation caps its frame rate at 60 frames per second (see Max FPS), so that it runs at the same speed on displays with high refresh rates.
How faithful are these simulations?
We checked the method against two classical flows, which are included as simulations you can run yourself.
- Flow in a straight channel. A uniform flow entering a channel should settle into a parabolic profile, with a maximum speed exactly 1.5 times its average speed (Poiseuille flow). Our simulation gives a ratio of 1.53, an error of 2%, which falls to 0.5% on a grid three times finer. The pressure drop along the channel is within 6% of its exact value (2% on the finer grid), and the fluid inside the walls moves at less than 0.1% of the flow speed.
- Flow past a cylinder. At a Reynolds number of 100, the wake behind a cylinder sheds vortices at a frequency given by a Strouhal number of about 0.165 (Williamson, 1996). Our simulation gives 0.175. This is a little high because, to fit on the screen, the cylinder sits only four diameters downstream of the inflow, which holds the oncoming flow perfectly uniform. Moving the cylinder ten diameters from the inflow, in a larger domain and on a finer grid, gives 0.166.
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:
- They are 2D. Real pipes are 3D, and 3D turbulence breaks eddies down into ever-smaller ones. In 2D, eddies instead tend to merge into larger ones, so our flows look smoother and more organised than real turbulent flows.
- The Reynolds numbers are moderate. Based on the width and average speed of each pipe, they range from around 800 (the contraction) to around 5000 (the plume), as the grid can’t resolve the fine detail of faster flows. Real devices often operate at much higher Reynolds numbers.
- Some features are artistic. The pulsed dye, the fading of old dye, and the plume’s fluctuating vent are all choices made to show the flow clearly. In the pipes and valves, the dye doesn’t affect the motion of the fluid at all. In the plume, the dye also marks warm fluid, so its fading acts like the fluid slowly cooling, and the fluctuating vent represents a turbulent source.
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.
