格点法matlab代码,Matlab实现格子玻尔兹曼方法.pdf

Matlab实现格子玻尔兹曼方法

Matlab 实现格子玻尔兹曼方法

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

% 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/3 6,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);

% MA

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用Matlab实现格子玻尔兹曼方法计算多相流体中的压强边界的示例代码: ```matlab % 设置模拟参数 nx = 100; % x方向上的格点数 ny = 100; % y方向上的格点数 nt = 1000; % 模拟的时间步数 rho1 = 1.0; % 流体1的密度 rho2 = 2.0; % 流体2的密度 viscosity1 = 0.1; % 流体1的粘度 viscosity2 = 0.2; % 流体2的粘度 tau = 0.6; % 松弛时间 omega = 1 / tau; % 松弛参数 g = [0, -9.8]; % 重力加速度 w = [4/9, 1/9, 1/9, 1/9, 1/9, 1/36, 1/36, 1/36, 1/36]; % 权重系数 % 初始化流场 f = zeros(nx, ny, 9); rho = ones(nx, ny); u = zeros(nx, ny, 2); % 边界条件 p = @(rho) rho * 0.1961 * 0.85; s = zeros(nx, ny); s(:, 1) = 1; % 左边界为固体壁面 % 迭代计算 for t = 1:nt % 计算宏观量 rho = sum(f, 3); u(:, :, 1) = (f(:, :, 2) + f(:, :, 5) + f(:, :, 6) - f(:, :, 4) - f(:, :, 7) - f(:, :, 8)) ./ rho; u(:, :, 2) = (f(:, :, 3) + f(:, :, 5) + f(:, :, 7) - f(:, :, 1) - f(:, :, 6) - f(:, :, 9)) ./ rho; u(isnan(u)) = 0; u(s == 1, :) = 0; % 固体壁面处速度为0 % 计算压强 p1 = p(rho); p2 = p(rho2 - rho); p = p1 + p2; % 计算碰撞 feq = zeros(nx, ny, 9); for i = 1:9 cu = 3 * (i - 1) * (u(:, :, 1) * w(i) + u(:, :, 2) * w(i)); u2 = u(:, :, 1).^2 + u(:, :, 2).^2; feq(:, :, i) = rho .* w(i) .* (1 + cu + 0.5 * cu.^2 - 1.5 * u2); end f = omega * feq + (1 - omega) * f; % 处理边界 f(:, 1, 2) = f(:, 1, 4); f(:, 1, 5) = f(:, 1, 7) + 0.5 * (f(:, 1, 3) - f(:, 1, 1)) + 0.5 * rho(:, 1) .* g(2); f(:, 1, 6) = f(:, 1, 8) + 0.5 * (f(:, 1, 1) - f(:, 1, 3)) - 0.5 * rho(:, 1) .* g(2); f(s == 1, :) = 0; % 固体壁面处速度为0 % 计算流场 for i = 1:9 f(:, :, i) = circshift(f(:, :, i), [0, 0, -i+1]); end for i = 1:9 f(:, :, i) = conv2(f(:, :, i), [1, 1; 1, 1], 'same') - f(:, :, i); end for i = 1:9 f(:, :, i) = circshift(f(:, :, i), [0, 0, i-1]); end end % 输出结果 imagesc(rho) colorbar ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值