%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% shanChen.m: Multi-component fluid, using a LB method,
% based on the Shan-Chen model
% [X.Shan and H.Chen, http://dx.doi.org/10.1103/PhysRevE.47.1815].
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Lattice Boltzmann sample, written in Matlab
% Copyright (C) 2008 Orestis Malaspinas, Andrea Parmigiani, Jonas Latt
% Address: EPFL-STI-LIN Station 9
% E-mail: [email protected]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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
clf
% GENERAL FLOW CONSTANTS
ly = 201;
lx = 201;
G = -1.2; % Amplitude of the molecular interaction force
omega1 = 1.; % Relaxation parameter for fluid 1
omega2 = 1.; % Relaxation parameter for fluid 2
maxT = 80000; % total number of iterations
tPlot = 40; % iterations between successive graphical outputs
% D2Q9 LATTICE CONSTANTS
tNS = [4/9, 1/9,1/9,1/9,1/9, 1/36,1/36,1/36,1/36];
cxNS = [ 0, 1, 0, -1, 0, 1, -1, -1, 1];
cyNS = [ 0, 0, 1, 0, -1, 1, 1, -1, -1];
oppNS = [ 1, 4, 5, 2, 3, 8, 9, 6, 7];
[y,x] = meshgrid(1:ly,1:lx);
drho = 0.001;
delta_rho = -drho*(1-2.0*rand(lx));
% INITIAL CONDITION FOR BOTH DISTRIBUTION FUNCTIONS: (T=0) ==> TIn(i) = t(i)
for i=1:9
fIn(i,1:lx,1:ly) = tNS(i).*(1.0 + delta_rho);
gIn(i,1:lx,1:ly) = tNS(i).*(1.0 - delta_rho);
end
rho1 = reshape(sum(fIn),lx,ly);% 数组
imagesc(rho1');
colorbar
title('Fluid 1 density');
axis equal off; drawnow
% MAIN LOOP (TIME CYCLES)
Gomega1 = G/omega1;
Gomega2 = G/omega2;
for cycle = 1:maxT
% 宏观变量
rho1 = sum(fIn);
rho2 = sum(gIn);
jx1 = reshape ( (cxNS * reshape(fIn,9,lx*ly)), 1,lx,ly);
jy1 = reshape ( (cyNS * reshape(fIn,9,lx*ly)), 1,lx,ly);
jx2 = reshape ( (cxNS * reshape(gIn,9,lx*ly)), 1,lx,ly);
jy2 = reshape ( (cyNS * reshape(gIn,9,lx*ly)), 1,lx,ly);
rhoTot_OMEGA = rho1*omega1 + rho2*omega2;
uTotX = (jx1*omega1+jx2*omega2) ./ rhoTot_OMEGA;
uTotY = (jy1*omega1+jy2*omega2) ./ rhoTot_OMEGA;
rhoContrib1x = 0.0;
rhoContrib2x = 0.0;
rhoContrib1y = 0.0;
rhoContrib2y = 0.0;
for i=2:9
rhoContrib1x = rhoContrib1x + circshift(rho1*tNS(i), [0,cxNS(i),cyNS(i)])*cxNS(i);
rhoContrib1y = rhoContrib1y + circshift(rho1*tNS(i), [0,cxNS(i),cyNS(i)])*cyNS(i);
rhoContrib2x = rhoContrib2x + circshift(rho2*tNS(i), [0,cxNS(i),cyNS(i)])*cxNS(i);
rhoContrib2y = rhoContrib2y + circshift(rho2*tNS(i), [0,cxNS(i),cyNS(i)])*cyNS(i);
end
uTotX1 = uTotX - Gomega1.*rhoContrib2x; %POTENTIAL CONTRIBUTION OF FLUID 2 ON 1
uTotY1 = uTotY - Gomega1.*rhoContrib2y;
uTotX2 = uTotX - Gomega2.*rhoContrib1x; %POTENTIAL CONTRIBUTION OF FLUID 2 ON 1
uTotY2 = uTotY - Gomega2.*rhoContrib1y;
% COLLISION STEP FLUID 1 AND 2
for i=1:9
cuNS1 = 3*(cxNS(i)*uTotX1+cyNS(i)*uTotY1);
cuNS2 = 3*(cxNS(i)*uTotX2+cyNS(i)*uTotY2);
fEq(i,:,:) = rho1 .* tNS(i) .* ...
( 1 + cuNS1 + 0.5*(cuNS1.*cuNS1) - 1.5*(uTotX1.^2+uTotY1.^2) );
gEq(i,:,:) = rho2 .* tNS(i) .* ...
( 1 + cuNS2 + 0.5*(cuNS2.*cuNS2) - 1.5*(uTotX2.^2+uTotY2.^2) );
fOut(i,:,:) = fIn(i,:,:) - omega1 .* (fIn(i,:,:)-fEq(i,:,:));
gOut(i,:,:) = gIn(i,:,:) - omega2 .* (gIn(i,:,:)-gEq(i,:,:));
end
% STREAMING STEP FLUID 1 AND 2
for i=1:9
fIn(i,:,:) = circshift(fOut(i,:,:), [0,cxNS(i),cyNS(i)]);
gIn(i,:,:) = circshift(gOut(i,:,:), [0,cxNS(i),cyNS(i)]);
end
% VISUALIZATION
if(mod(cycle,tPlot)==0)
rho1 = reshape(rho1,lx,ly);
imagesc(rho1'); colorbar
title('Fluid 1 density');
axis equal off; drawnow
end
end
shanchen.rar_LBM Shan-Chen_lbm伪势模型_shan-chen_伪势LBM_多组分LBM
版权申诉
5星 · 超过95%的资源 30 浏览量
2022-07-15
06:40:17
上传
评论 2
收藏 2KB RAR 举报
朱moyimi
- 粉丝: 64
- 资源: 1万+
最新资源
- 毕业设计基于python矩阵分解的推荐算法研究源码+详细文档+全部数据资料 高分项目.zip
- 基于网络的入侵检测系统源码+数据集+详细文档(高分毕业设计).zip
- 微信小程序源码 旅行故事分享 - 面包旅行App界面设计与文本展示资源下载
- 微信小程序源码 创意互动游戏 - 你画我猜App下载
- 摸底考试_学生版20230305.py
- 课程设计基于FPGA数字钟课程设计源码+课设报告(95分以上).zip
- 基于Java的企业家申报系统设计源码
- Cesium案例,集成各种模型,推演,各种Cesium效果
- 基于Python的Struts2全漏洞扫描利用工具设计源码
- python朴素贝叶斯(Naive Bayes)算法,机器算法
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论16