This example shows the turbulence that forms behind a cyllinder on a 3D grid with uniformly stretched cells. We set a fluid inflow on the left side and add a cylinder to the domain.
%pip install phiflow
from phi.jax.flow import *
# from phi.flow import * # If JAX is not installed. You can use phi.torch or phi.tf as well.
cylinder = geom.infinite_cylinder(x=20, y=50, radius=10, inf_dim='z')
plot({"Top view": cylinder['x,y'], "Side view": cylinder['x,z']})
c:\ProgramData\Anaconda3\envs\phiflow2\lib\site-packages\phiml\math\_shape.py:2048: RuntimeWarning: Stacking shapes with incompatible item names will result in item names being lost. For vector Got ('x', 'y') and ('x', 'z') warnings.warn(f"Stacking shapes with incompatible item names will result in item names being lost. For {name} Got {item_names[index]} and {items}", RuntimeWarning)
<Figure size 864x360 with 2 Axes>
Next, we define the simulation function and set the boundary conditions, resolution, and domain size. We then run the simulation for 200 time steps with $\Delta t=1$.
@jit_compile
def step(v, p, dt=1.):
v = advect.semi_lagrangian(v, v, dt)
return fluid.make_incompressible(v, cylinder, Solve(x0=p))
boundary = {'x-': vec(x=2, y=0, z=0), 'x+': ZERO_GRADIENT, 'y': PERIODIC, 'z': PERIODIC}
v0 = StaggeredGrid((8., 0, 0), boundary, x=128, y=64, z=8, bounds=Box(x=200, y=100, z=5))
v_trj, p_trj = iterate(step, batch(time=200), v0, None)
Let's look at the vorticity of a z cross section over time!
v_trj_2d = v_trj[{'z': 4, 'vector': 'x,y'}]
plot(v_trj_2d.time[100:].curl(), animate='time')
We can also visualize the velocity field using stream lines.
plot(v_trj_2d.time[-1], cylinder['x,y'], overlay='args')
<Figure size 864x360 with 1 Axes>