Matlab实现格子玻尔兹曼方法(Lattice Boltzmann Method,LBM)模拟

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% cylinder.m: Flow around a cyliner, using LBM

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% This program is free software; you can redistribute it and/or

% modify it under the terms of the GNU General Public License

% as published by the Free Software Foundation; either version 2

% of the License, or (at your option) any later version.

% This program is distributed in the hope that it will be useful,

% but WITHOUT ANY WARRANTY; without even the implied warranty of

% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

% GNU General Public License for more details.

% You should have received a copy of the GNU General Public

% License along with this program; if not, write to the Free

% Software Foundation, Inc., 51 Franklin Street, Fifth Floor,

% Boston, MA  02110-1301, USA.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear

% GENERAL FLOW CONSTANTS

lx         = 250;

ly         = 51;

obst_x = lx/5+1;   % position of the cylinder; (exact

obst_y = ly/2+1;   % y-symmetry is avoided)

obst_r = ly/10+1;  % radius of the cylinder

uMax  = 0.02;      % maximum velocity of Poiseuille inflow

Re     = 100;      % Reynolds number

nu    = uMax * 2.*obst_r / Re;   % kinematic viscosity

omega  = 1. / (3*nu+1./2.);      % relaxation parameter

maxT   = 400000;   % total number of iterations

tPlot  = 5;        % cycles

% D2Q9 LATTICE CONSTANTS

t  = [4/9, 1/9,1/9,1/9,1/9, 1/36,1/36,1/36,1/36];

cx = [  0,   1,  0, -1,  0,    1,  -1,  -1,   1];

cy = [  0,   0,  1,  0, -1,    1,   1,  -1,  -1];

opp = [ 1,   4,  5,  2,  3,    8,   9,   6,   7];

col = [2:(ly-1)];

[y,x] = meshgrid(1:ly,1:lx);

obst = (x-obst_x).^2 + (y-obst_y).^2 <= obst_r.^2;

obst(:,[1,ly]) = 1;

bbRegion = find(obst);

% INITIAL CONDITION: (rho=0, u=0) ==> fIn(i) = t(i)

fIn = reshape( t' * ones(1,lx*ly), 9, lx, ly);

% MAIN LOOP (TIME CYCLES)

for cycle = 1:maxT

% MACROSCOPIC VARIABLES

rho = sum(fIn);

ux  = reshape ( ...

(cx * reshape(fIn,9,lx*ly)), 1,lx,ly) ./rho;

uy  = reshape ( ...

(cy * reshape(fIn,9,lx*ly)), 1,lx,ly) ./rho;

% MACROSCOPIC (DIRICHLET) BOUNDARY CONDITIONS

% Inlet: Poiseuille profile

L = ly-2; y = col-1.5;

ux(:,1,col) = 4 * uMax / (L*L) * (y.*L-y.*y);

uy(:,1,col) = 0;

rho(:,1,col) = 1 ./ (1-ux(:,1,col)) .* ( ...

sum(fIn([1,3,5],1,col)) + ...

2*sum(fIn([4,7,8],1,col)) );

% Outlet: Zero gradient on rho/ux

rho(:,lx,col) = rho(:,lx-1,col);

uy(:,lx,col)  = 0;

ux(:,lx,col)  = ux(:,lx-1,col);

% COLLISION STEP

for i=1:9

cu = 3*(cx(i)*ux+cy(i)*uy);

fEq(i,:,:)  = rho .* t(i) .* ...

( 1 + cu + 1/2*(cu.*cu) ...

- 3/2*(ux.^2+uy.^2) );

fOut(i,:,:) = fIn(i,:,:) - ...

omega .* (fIn(i,:,:)-fEq(i,:,:));

end

% MICROSCOPIC BOUNDARY CONDITIONS

for i=1:9

% Left boundary

fOut(i,1,col) = fEq(i,1,col) + ...

18*t(i)*cx(i)*cy(i)* ( fIn(8,1,col) - ...

fIn(7,1,col)-fEq(8,1,col)+fEq(7,1,col) );

% Right boundary

fOut(i,lx,col) = fEq(i,lx,col) + ...

18*t(i)*cx(i)*cy(i)* ( fIn(6,lx,col) - ...

fIn(9,lx,col)-fEq(6,lx,col)+fEq(9,lx,col) );

% Bounce back region

fOut(i,bbRegion) = fIn(opp(i),bbRegion);

end

% STREAMING STEP

for i=1:9

fIn(i,:,:) = ...

circshift(fOut(i,:,:), [0,cx(i),cy(i)]);

end

% VISUALIZATION

if (mod(cycle,tPlot)==0)

u = reshape(sqrt(ux.^2+uy.^2),lx,ly);

u(bbRegion) = nan;

imagesc(u');

axis equal off; drawnow

end

end

lbm matlab,LBM的matlab代码相关推荐

  1. matlab中调用java代码_Matlab中调用第三方Java代码

    在Java中采用Matlab JA Builder可以实现调用m文件,采用这样的方式,可在Matlab的M文件中,直接调用Java类.这种方式可以表示为Java--> Matlab( m, Ja ...

  2. 举例说明使用MATLAB Coder从MATLAB生成C/C++代码步骤

    MATLAB Coder可以从MATLAB代码生成独立的.可读性强.可移植的C/C++代码. 使用MATLAB Coder产生代码的3个步骤:准备用于产生代码的MATLAB算法:检查MATLAB代码的 ...

  3. 【Matlab开发】MATLAB编译C/C++代码

    在使用MATLAB编译C/C++代码时,C/C++代码中要使用一个mexFunction函数,那么这个函数是如何定义,在编译时又是如何实现的呢?下面我将使用实例进行说明. 如一个简单的函数: doub ...

  4. python直方图均衡化代码_基于matlab的直方图均衡化代码

    基于matlab的直方图均衡化代码 2007-04-15 20:15 clear all %一,图像的预处理,读入彩***像将其灰度化 PS=imread('1.jpg');             ...

  5. matlab中codegen是什么,从 MATLAB 代码生成 C/C++ 代码。 - MATLAB codegen - MathWorks 中国...

    -c生成 C/C++ 代码,但不调用 make 命令. -config:dll使用默认配置参数生成动态 C/C++ 库. -config:exe使用默认配置参数生成静态 C/C++ 可执行文件. -c ...

  6. matlab时频分析代码

    当进行时频分析时,MATLAB提供了多种函数和工具箱,下面是一个简单的MATLAB时频分析代码示例: 假设我们有一个信号x和一个采样频率fs.以下是使用MATLAB信号处理工具箱的代码: ```mat ...

  7. 自适应滤波器设计及matlab实现,自适应滤波器设计及Matlab实现附程序代码

    自适应滤波器设计及Matlab实现附程序代码 维纳自适应滤波器设计及 Matlab 实现摘 要本文从随机噪声的特性出发,分析了传统滤波和自适应滤波基本工作原理和性能,以及滤波技术的现状和发展前景.然后 ...

  8. 【基于matlab数字图像处理GUI代码】_数字图像处理考核论文_大作业_项目

    基于matlab数字图像处理GUI代码 代码: function varargout = Image_processing_GUI(varargin) % IMAGE_PROCESSING_GUI M ...

  9. 智能群算法的CEC2017测试集 纯matlab版以及matlab与C++版 代码以及详细使用说明

    CEC2017 用于智能群算法性能测试评价.废话少说.我在网上搜不到纯matlab代码.滥竽充数的太多.这里我给大家分享 纯matlab版,MATLAB与c++交叉编译版的CEC2017. 我的文件: ...

  10. Romberg积分法MATLAB实现(附代码、实例、详解)

    第一部分:问题分析 (1)实验题目:龙贝格积分算法 具体实验要求:用matlab编写龙贝格积分的代码,要求代码实现用户输入了被积函数.积分区间.精度之后,龙贝格积分表(T-数表). (2)实验目的:让 ...

最新文章

  1. java之ibatis数据缓存
  2. iOS App 目录结构
  3. ZooKeeper学习第七期--ZooKeeper一致性原理
  4. 通过反射创建私有化构造的类,并为私有化属性复制。调用私有化方法
  5. 2021年高考成绩查询衡阳市八中,优秀!衡阳2020年各大高中成绩出炉!
  6. DBCC CHECKDB 数据库或表修复
  7. 视频教程-IT必备技能Cisco认证CCNA全集-思科认证
  8. matlab5.0软件下载,MATLAB手机版
  9. Good Numbers (hard version)cf#595(Div.3)
  10. js代码在调试状态执行正确,但是正常使用时没有反应
  11. 省市县三级菜单联动,含显示默认城市,只显示默认省
  12. 如何实现前后端分离开发
  13. 在unbuntu16.04上安装网易云音乐
  14. JSF Chapter11
  15. Java实现CRC16 CCITT
  16. 中介兴风 深圳楼市起浪
  17. luogu 题解 P1217 【[USACO1.5]回文质数 Prime Palindromes】
  18. pdf转txt java_pdf转换txt怎么操作?pdf文件可以转换成txt文件吗?
  19. java共享锁和排他锁的区别_排他锁和共享锁分别是什么?有什么不同?
  20. spark submit参数及调优(转载)

热门文章

  1. 人脸识别相比较其他生物识别技术,人脸识别主要有什么优缺点
  2. 一篇文章讲清楚什么是数据网格和数据网格的原则
  3. 基于Python+Django+Vue+MYSQL的医院排队叫号系统
  4. 【解决】Linux  (centos7)扩容磁盘不显示扩容后的磁盘或者磁盘大小两种情况
  5. 傅里叶变换与香农采样定理学习笔记
  6. 机械式键盘软件测试,驱动软件测试 中/低端篇_新贵 GM-500机械键盘_键鼠评测-中关村在线...
  7. opencv检测尺寸+部署时踩过的坑
  8. linux 装Broadcom原生网卡
  9. MP3 Gain 4.3.0 特别版 Mac 优秀 MP3 声音增大工具
  10. laravel安装-中文语言包