www.gusucode.com > LBM格子波尔兹曼 matlab例程源码程序 > porous_cylinder2d.m

    clc
clear

% Load LBM-C Variables
lbm_c_vars

% Project Variables
ProjName = 'porcylinder';
DomainFile = 'porcylinder.dom';
OutputFile = 'porcylinder.res';

% Solution Constants
Tau = 1.0;
Lx = 500;
Ly = 100;
Lz = 1;
DeltaX = 1;
DeltaT = 1;
C_smag = 0;

% Solution Configuration
ColType = 'NTPOR';
Force = 0;
MicroBC = 1;
MacroBC = 1;
Init = 0;
Tolerance = 0;

% Timing Data
MaxT = 10000;
FileOut = 500;
ScreenMes = 50;
SteadyCheck = 0;

% Output Variables
Ux = 1;
Uy = 1;
Uz = 0;
Rho = 1;
P = 1;
ScreenX = 0;
ScreenY = floor(Ly/2);
ScreenZ = 0;
Interactive = 0;

% Domain Arrays
porosity = zeros(Lx,Ly);
micro_bc = zeros(Lx,Ly);
macro_bc = zeros(Lx,Ly);

porosity(:,[1,Ly]) = 1;
obst_x = floor((1/5)*Lx);
obst_y = floor((1/2)*Ly)-2;
obst_r = 20;

for i = 0:(Lx)
    for j = 0:(Ly)
        if (i-obst_x)^2 + (j-obst_y)^2<= obst_r^2
            porosity(i,j) = 0.5;
        end
    end
end

micro_bc(1,:) = ZOU_HE_P_x;
micro_bc(Lx,:) = ZOU_HE_P_X;
macro_bc(1,:) = PRESCRIBED_RHO;
macro_bc(Lx,:) = PRESCRIBED_RHO;
rho = zeros(Lx,Ly);
rho(1,:) = 1.00002;
rho(Lx,:) = 0.99998;
velocity = zeros(3,Lx,Ly);
    
write_ascii_input
write_cgns_input

fname_in = [ProjName,'.lbmc'];
command = ['lbm-c-2d ',fname_in];
system(command);

time_values = read_output_times(OutputFile);

ux = read_output_field(OutputFile,length(time_values),'VelocityX');
uy = read_output_field(OutputFile,length(time_values),'VelocityY');
rho = read_output_field(OutputFile,length(time_values),'Density');

for i = 1:length(time_values)
    ux = read_output_field(OutputFile,i,'VelocityX');
    uy = read_output_field(OutputFile,i,'VelocityY');
    u = sqrt(ux.*ux+uy.*uy);
    imagesc(u');
    pause
end