A Tesla valve
Channel: Nils Berglund
Date: 18/03/2023

This simulation has been a long time coming! Illustrating the working of a Tesla wave has been suggested in comments on this channel for the first time over one and a half years ago, and many times since then. Only at the time, I was mostly simulating the linear wave equation, which is not suitable for a Tesla valve simulation, because it is reversible. When I started simulating non-linear equations of fluids, it took a while to solve various issues with boundary conditions. But here is finally a fist version of such a simulation that illustrates the basic principle, although some improvements in parameter choices are possible.  
A Tesla valve is a clever one-way fluid valve without moving parts, that was invented (and patented) by Nikola Tesla in 1920. The design used here features two conduits attached to the main pipe, and folded back on it. When used in the forward direction, the fluid can easily flow along the main pipe. When used in the backward direction, however, the back-folded conduits make the fluid interact with the flow in the main pipe, slowing it down or even stopping it altogether. 
The simulation uses the compressible Euler equations, with some added dissipation, in order to avoid numerical instabilities. The boundary conditions are imposed by multiplying the fields with a cut-off function, that smoothly interpolates between 0 and 1 when moving across the boundary of the pipes, effectively introducing a boundary layer.
The video has four parts, showing the same simulation with two different color schemes and at two different speeds:
Forward direction, speed: 0:00
Forward direction, vorticity: 1:02
Backward direction, speed: 2:04
Backward direction, vorticity: 3:06
In the first and third part, the color hue shows the speed of the fluid (the norm of the velocity). In the second and fourth part, the color hue depends on the vorticity of the fluid, which measures its quantity of rotation (given by the curl, or rotational, of the velocity field). The velocity field of the fluid is materialized by 1000 tracer particles, whose initial position is distributed randomly over the simulation region. There are periodic boundary conditions, which is why vortices can be seen wrap around the displayed rectangular region.
The compressible Euler equations are partial differential equations for the density and the velocity field of the fluid. The system as such is not closed, because the right-hand side of the velocity equation involves the pressure, which has to be linked to known quantities by a thermodynamic relation. I assumed here that the fluid is an ideal gas, so that the pressure is proportional to the density. 
In a sense, the compressible Euler equations are easier to simulate than the incompressible ones, because one does not have to impose a zero divergence condition on the velocity field. However, they appear to be a bit more unstable numerically, and I had to add a smoothing mechanism to avoid blow-up. This mechanism is equivalent to adding a small viscosity, making the equations effectively a version of the Navier-Stokes equations. 

Render time: Parts 1 and 2 - 55 minutes 7 seconds
Parts 3 and 4 - 55 minutes 8 seconds
Color scheme: Parts 1 and 3 - Inferno by Nathaniel J. Smith and Stefan van der Walt
https://github.com/BIDS/colormap
Parts 2 and 4 - Turbo, by Anton Mikhailovhttps://gist.github.com/mikhailov-work/6a308c20e494d9e0ccc29036b28faa7a
 
Music: "Warzone" by Anno Domini Beats@AnnoDominiBeats

See also https://images.math.cnrs.fr/Des-ondes-dans-mon-billard-partie-I.html for more explanations (in French) on  a few previous simulations of wave equations. 

The simulation solves the 2D compressible Euler equation by discretization (finite differences).

C code: https://github.com/nilsberglund-orleans/YouTube-simulations
https://www.idpoisson.fr/berglund/software.html
Many thanks to Marco Mancini and Julian Kauth for helping me to accelerate my code!