Streamline of the flow field represented by the Cartesian coordinate system $ \ boldsymbol {x} = (x, y) $, velocity $ \ boldsymbol {u} = (u, v) $ at a certain time $ t $ (Streamline) </ b> is a mathematical ordinary differential equation
As an example, a two-dimensional stationary Taylor-Green vortex:
import matplotlib.pyplot as plt
import numpy as np
from numpy import sin, cos, pi, sqrt
n = 1000
x = np.linspace(0, 2*pi, n)
y = np.linspace(0, 2*pi, n)
X, Y = np.meshgrid(x, y)
# Taylor-Green Vortices
u = sin(X)*cos(Y)
v = - cos(X)*sin(X)
speed = sqrt(u**2 + v**2)
# Plot
plt.figure(1)
plt.streamplot(X, Y, u, v, density=3, color='k', arrowstyle='-', linewidth=0.6)
plt.contourf(X, Y, speed, 100, cmap='viridis')
plt.show()
I was able to draw a streamline. The background is the flow velocity.
This is the main subject. The above matplotlib built-in `streamplot``` is beautiful enough, but if you want to draw more beautifully (artistically), use the method <b> Line Integral Convolution (LIC) </ b>. If you use it, you can draw streamlines very beautifully. [Wikipedia](https://en.wikipedia.org/wiki/Line_integral_convolution) has a brief explanation. For the algorithm, see [Cabral and Leedom, 1993](https://dl.acm.org/doi/pdf/10.1145/166117.166151?casa_token=A78GoJh369IAAAAA%3AfWlns5xYUUWiQC09j8IIMBVDZq4jYTRt_uJX2bQhc4jYTRt_uJX2bQhc4V5d. Examples of streamlines drawn using LIC are [Phillips et al., 2015](https://iopscience.iop.org/article/10.1088/1748-3190/10/5/056020/meta) and [Van Der Kindere et al., 2019](https://link.springer.com/article/10.1007/s00348-019-2678-5) and so on. There is a sample code in [SciPy Cookbook](https://scipy-cookbook.readthedocs.io/items/LineIntegralConvolution.html), so I'm grateful to use it. You can use it by building
`setup.py. Rewrite the first half of the linked
lic_demo.py```. Since I want to display the flow velocity in the background, I multiply the flow velocity by LIC in the last line.
Vector = np.stack([u, v], axis=2)
Vector = np.array(Vector, dtype=np.float32)
texture = np.random.rand(n, n).astype(np.float32)
plt.bone()
frame = 0
dpi = 1000
video = False
if video:
kernellen = 31
for t in np.linspace(0,1,16*5):
kernel = np.sin(np.arange(kernellen)*np.pi/kernellen)*(1+np.sin(2*np.pi*5*(np.arange(kernellen)/float(kernellen)+t)))
kernel = kernel.astype(np.float32)
image = lic_internal.line_integral_convolution(Vector, texture, kernel)
frame += 1
else:
kernellen = 31
kernel = np.sin(np.arange(kernellen)*np.pi/kernellen)
kernel = kernel.astype(np.float32)
image = lic_internal.line_integral_convolution(Vector, texture, kernel)
speed_LIC = image[1:-1, 1:-1]*speed[1:-1, 1:-1]
It's very beautiful.
Mathematica has a built-in `` `LineIntegralConvolutionPlot```!
LineIntegralConvolutionPlot[{{Sin[x] Cos[y], -Sin[y] Cos[x]}, {"noise", 1000, 1000}}, {x, 0, 2 Pi}, {y, 0, 2 Pi},
ColorFunction -> "BlueGreenYellow", RasterSize -> 300]
It was just done ...
Recommended Posts