This script implements a 2d fluid solver based on Lattice Boltzmann method using Taichi programming language. The high-performance cross-platform CFD (computational fluid dynamics) solver can be achieved within 200 lines thanks to taichi.
To numerically solve a fluid-dynamics problem, the domain size, fluid property, boundary conditions and initial conditions should be given. In this code, these parameters can be specified by instancing the solver:
lbm = lbm_solver(nx, ny, niu, bc_type, bc_value)
The meaning of each parameter is:
nx
,ny
define domain size. Note that they are given in dimensionless form (ie. lattice units), which assumesdx = dy = dt = 1.0
, wheredx
anddy
are discrete grid sizes,dt
is the time interval of one step.niu
is the fluid viscosity in lattice units. Note there is a transformation between SI units and lattice units.bc_type
is a four-element python list denoting the[left, top, right, bottom]
boundary condition type. The velocity at the boundary is set based onbc_type
. Ifbc_type = 0
, velocity is set as constant value (Dirichlet condition ) given inbc_value
. Ifbc_type = 1
, the derivative of velocity in boundary normal direction is set to zero (Neumann condition).bc_value
is a(4,2)
python list, it gives constant velocity value at each boundary whenbc_type = 0
.
Lid-driven cavity flow is benchmark fluid-dynamics problem used to verify the solver accuracy. To compare simulation results based on different unit-systems, the flow Reynolds number Re
should keep the same. In this case, Re
is defined as Re = U * L / niu
, so a solver with Re = 1000
can be given by:
lbm = lbm_solver(256, 256, 0.0255, [0, 0, 0, 0],
[[0.0, 0.0], [0.1, 0.0], [0.0, 0.0], [0.0, 0.0]])
Here Re = U * (nx-1) * dx / niu = 0.1 * 255.0 / 0.0255
. The velocity magnitude is shown in the contour below and x-component of velocity in the middle line is compared with result from literature.
Kármán vortex street is an interesting phenomenon in fluid dynamics. When fluids flow pass blunt body (say a cylinder), there exists a repeating pattern of swirling vortices, caused by a process known as vortex shedding. The Reynolds number of this flow is defined as Re = U * D / niu
, where D
means diameter. A solver with Re = 200
can be given by:
lbm = lbm_solver(401, 101, 0.005, [0, 0, 1, 0],
[[0.1, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]],
1, [80.0, 50.0, 10.0])
lbm_taichi's People
Forkers
luoshuifish tennyxu0731 mriko saullocastro seuzht zeta1999 gweiqi flyfishm icfda zhang-zhi-tong sireesha-upenn alphapo-cfd victoriacity erikyann ayoubajax jiandandema gugid lynnmusy hydra5 xcw1227 luoyining slarkwayne heyweiko albert0418 zhaozelin2000 omjee10 yichen-liu-0931 albert-jt libaroma linglai27 caijt961117 danialamini hgl-pong jiatuoanlbm_taichi's Issues
Extension of current code to 3D
Dear @hietwll , do you have plans to extend the current code to 3D?
Kind regards
Saullo G. P. Castro
velocity becomes nan after few steps when initial velocity set to 0.2
I set the initial inlet velocity of Karman Vortex Street to 0.2, and kept other configs as below:
lbm = lbm_solver(
"Karman Vortex Street",
801,
201,
0.01,
[0, 0, 1, 0],
[[0.2, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]],
1,
[160.0, 100.0, 20.0])
Then I ran it by python lbm_solver.py
, but got velocity and vorticity nan after first few steps:
Is this an internal problem of the solver? How can I make it more robust? Thanks.
请问边界条件的做法
你好!我在Taichi论坛上膜拜了你的Homework以后找到了这里:)
我也从事过一些CFD计算的学习但是对于LBM法不是很熟悉,想请问你在代码中的边界条件的这种做法(apply_bc_core)是有参考什么书或者代码吗?感觉这样的用法真的太好了,也可以适用在不是LBM的求解器中想尝试一下。
谢谢!
Question: Advection in LBM_Taichi and Diffusion in D2Q9
- 想问一下advection在LBM是怎么实现的, 有点看不懂, 是这两行嘛
Line 77 in b2d758a
Line 77 in b2d758a
- 想问下为什么我试着diffusion 结果不是很理想,感觉边界的rho(density) 很奇怪
代码:https://github.com/wyq977/LBM_Taichi/tree/test-diffusion
谢谢🙏
Compile error with latest Taichi1.60
[Taichi] version 1.6.0, llvm 15.0.1, commit f1c6fbbd, win, python 3.8.3
[Taichi] Starting on arch=cuda
Traceback (most recent call last):
File ".\lbm_solver.py", line 185, in
lbm.solve()
File ".\lbm_solver.py", line 154, in solve
self.apply_bc()
File "D:\Dev\Anaconda3\lib\site-packages\taichi\lang\kernel_impl.py", line 1035, in call
raise type(e)("\n" + str(e)) from None
taichi.lang.exception.TaichiSyntaxError:
File ".\lbm_solver.py", line 101, in apply_bc:
for j in ti.ndrange(1, self.ny - 1):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# left: dr = 0; ibc = 0; jbc = j; inb = 1; jnb = j
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ndrange for loop with number of the loop variables not equal to the dimension of the ndrange is not supported. Please check if the number of arguments of ti.ndrange() is equal to the number of the loop variables.
Which version of Taichi is supported?
Ask for permisson of including this repo in Taichi's official demos
@hietwll Hi, thank you for this great project. Our Taichi development team thinks this project is great and hopes to include it in Taichi's official demos: https://github.com/taichi-dev/taichi/tree/master/python/taichi/examples
We may probably modify the code a bit (for formatting and GUI event handling reasons) and credit the example to you. Looking for your permission!
Question: how to do advection in LBM
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.