% 3D Lattice Boltzmann (BGK) model of a fluid.
% D3Q19 model. At each timestep, particle densities propagate
% outwards in the directions indicated in the figure. An
% equivalent 'equilibrium' density is found, and the densities
% relax towards that state, in a proportion governed by omega.
% Iain Haslam, March 2006.
nx=24;ny=nx;nz=nx; omega=1.0; density=1.0;t1=1/3; t2=1/18; t3=1/36;
F=repmat(density/19,[nx ny nz 19]); FEQ=F; matsize=nx*ny*nz;
CI=[0:matsize:matsize*19];
BOUND=zeros(nx,ny,nz);
for i=1:nx, for j=1:ny, for k=1:nz
BOUND(i,j,k)=((i-5)^2+(j-6)^2+(k-7)^2)<6;
end, end, end
BOUND(:,:,1)=1;BOUND(:,1,:)=1;
ON=find(BOUND); %matrix offset of each Occupied Node
TO_REFLECT=[ON+CI(2) ON+CI(3) ON+CI(4) ON+CI(5) ON+CI(6) ON+CI(7) ON+CI(8) ...
ON+CI(9) ON+CI(10) ON+CI(11) ON+CI(12) ON+CI(13) ON+CI(14) ON+CI(15) ...
ON+CI(16) ON+CI(17) ON+CI(18) ON+CI(19)];
REFLECTED=[ON+CI(3) ON+CI(2) ON+CI(5) ON+CI(4) ON+CI(7) ON+CI(6) ON+CI(11) ...
ON+CI(10) ON+CI(9) ON+CI(8) ON+CI(15) ON+CI(14) ON+CI(13) ON+CI(12) ...
ON+CI(19) ON+CI(18) ON+CI(17) ON+CI(16)];
avu=1; prevavu=1; ts=0; deltaU=1e-7; numactivenodes=sum(sum(sum(1-BOUND)));
while (ts<4000 & 1e-10<abs((prevavu-avu)/avu)) | ts<100
% Propagate
%nearest-neighbours
F(:,:,:,2)=F(:,:,[nz 1:nz-1],2);
F(:,:,:,3)=F(:,:,[2:nz 1],3);
F(:,:,:,4)=F(:,[ny 1:ny-1],:,4);
F(:,:,:,5)=F(:,[2:ny 1],:,5);
F(:,:,:,6)=F([nx 1:nx-1],:,:,6);
F(:,:,:,7)=F([2:nx 1],:,:,7);
%next-nearest neighbours
F(:,:,:,8)= F([nx 1:nx-1],[ny 1:ny-1],:,8);
F(:,:,:,9)= F([nx 1:nx-1],[2:ny 1],:,9);
F(:,:,:,10)=F([2:nx 1],[ny 1:ny-1],:,10);
F(:,:,:,11)=F([2:nx 1],[2:ny 1],:,11);
F(:,:,:,12)=F([nx 1:nx-1],:,[nz 1:nz-1],12);
F(:,:,:,13)=F([nx 1:nx-1],:,[2:nz 1],13);
F(:,:,:,14)=F([2:nx 1],:,[nz 1:nz-1],14);
F(:,:,:,15)=F([2:nx 1],:,[2:nz 1],15);
F(:,:,:,16)=F(:,[ny 1:ny-1],[nz 1:nz-1],16);
F(:,:,:,17)=F(:,[ny 1:ny-1],[2:nz 1],17);
F(:,:,:,18)=F(:,[2:ny 1],[nz 1:nz-1],18);
F(:,:,:,19)=F(:,[2:ny 1],[2:nz 1],19);
BOUNCEDBACK=F(TO_REFLECT); %Densities bouncing back at next timestep
% Relax; calculate equilibrium state (FEQ) with equivalent speed and density to F
DENSITY = sum(F,4);
UX=(sum(F(:,:,:,[6 8 9 12 13]),4)-sum(F(:,:,:,[7 10 11 14 15]),4))./DENSITY;
UY=(sum(F(:,:,:,[4 8 10 16 17]),4)-sum(F(:,:,:,[5 9 11 18 19]),4))./DENSITY;
UZ=(sum(F(:,:,:,[2 12 14 16 18]),4)-sum(F(:,:,:,[3 13 15 17 19]),4))./DENSITY;
UX(1,:,:)=UX(1,:,:)+deltaU; %Increase inlet pressure
UX(ON)=0; UY(ON)=0; UZ(ON)=0; DENSITY(ON)=0; U_SQU=UX.^2+UY.^2+UZ.^2;
U8=UX+UY;U9=UX-UY;U10=-UX+UY;U11=-U8;U12=UX+UZ;U13=UX-UZ;
U14=-U13;U15=-U12;U16=UY+UZ;U17=UY-UZ;U18=-U17;U19=-U16;
% Calculate equilibrium distribution: stationary
FEQ(:,:,:,1)=t1*DENSITY.*(1-3*U_SQU/2);
% nearest-neighbours
FEQ(:,:,:,2)=t2*DENSITY.*(1 + 3*UZ + 9/2*UZ.^2 - 3/2*U_SQU);
FEQ(:,:,:,3)=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)*F;
F(REFLECTED)=BOUNCEDBACK;
prevavu=avu;avu=sum(sum(sum(UX)))/numactivenodes; ts=ts+1;
end
figure;zcut=5;colormap(gray(2));image(2-BOUND(:,:,5));hold on;
quiver(UX(:,:,zcut),UY(:,:,zcut));xlabel('y');ylabel('x');
title(['Flow field at z=',num2str(zcut),', after ',num2str(ts),'\deltat']);
figure;ycut=5;colormap(gray(2));image(2-squeeze(BOUND(:,ycut,:)));hold on;
quiver(squeeze(UX(:,ycut,:)),squeeze(UZ(:,ycut,:)));xlabel('z');ylabel('x');
title(['Flow field at y=',num2str(ycut),', after ',num2str(ts),'\deltat']);
没有合适的资源?快使用搜索试试~ 我知道了~
国外经典LBM D2Q9 D3Q19模型的matlab代码.zip
共10个文件
m:5个
png:3个
rar:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 2 下载量 127 浏览量
2023-11-11
09:29:30
上传
评论 2
收藏 78KB ZIP 举报
温馨提示
1.版本:matlab2014/2019a/2021a,内含运行结果,不会运行可私信 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。 5.作者介绍:某大厂资深算法工程师,从事Matlab算法仿真工作10年;擅长智能优化算法、神经网络预测、信号处理、元胞自动机等多种领域的算法仿真实验,更多仿真源码、数据集定制私信+。
资源推荐
资源详情
资源评论
收起资源包目录
国外经典LBM D2Q9 D3Q19模型的matlab代码.zip (10个子文件)
国外经典LBM D2Q9 D3Q19模型的matlab代码
Porous_Medium_Flows.asv 3KB
3.png 17KB
savevtk.m 1KB
Porous_Medium_Flows.rar 1KB
LBMval.m 4KB
lbm3dvectors.png 20KB
Porous_Medium_Flows.m 3KB
4.png 33KB
savevtkvector.m 1KB
Porous_Medium_Flows_3D.m 5KB
共 10 条
- 1
资源评论
- 泇暅2024-03-16资源内容总结的很到位,内容详实,很受用,学到了~
- |--|%2023-11-30感谢大佬,让我及时解决了当下的问题,解燃眉之急,必须支持!
Matlab科研辅导帮
- 粉丝: 1w+
- 资源: 7553
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功