GithubHelp home page GithubHelp logo

hietwll / lbm_taichi Goto Github PK

View Code? Open in Web Editor NEW
205.0 5.0 36.0 24 KB

Fluid solver based on Lattice Boltzmann method implemented by taichi programming language

Python 100.00%
fluid-solver lattice-boltzmann-method taichi

lbm_taichi's Introduction

LBM_Taichi

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.

Usage

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 assumes dx = dy = dt = 1.0, where dx and dy 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 on bc_type. If bc_type = 0, velocity is set as constant value (Dirichlet condition ) given in bc_value. If bc_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 when bc_type = 0.

Example1: Lid-driven Cavity Flow

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.

Example2: Kármán Vortex Street

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

Contributors

hietwll avatar wyq977 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

lbm_taichi's Issues

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:
image
Is this an internal problem of the solver? How can I make it more robust? Thanks.

请问边界条件的做法

你好!我在Taichi论坛上膜拜了你的Homework以后找到了这里:)
我也从事过一些CFD计算的学习但是对于LBM法不是很熟悉,想请问你在代码中的边界条件的这种做法(apply_bc_core)是有参考什么书或者代码吗?感觉这样的用法真的太好了,也可以适用在不是LBM的求解器中想尝试一下。

谢谢!

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.