0% found this document useful (0 votes)
67 views1 page

Cylinder 2

ejemplos de matlab cylinder

Uploaded by

elvis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views1 page

Cylinder 2

ejemplos de matlab cylinder

Uploaded by

elvis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Printed by Jonas Marcel Ltt

Sep 08, 08 18:20 cylinder.m Page 1/2 Sep 08, 08 18:20 cylinder.m Page 2/2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% cylinder.m: Channel flow past a cylinderical % MAIN LOOP (TIME CYCLES)
% obstacle, using a LB method for cycle = 1:maxT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Lattice Boltzmann sample in Matlab % MACROSCOPIC VARIABLES
% Copyright (C) 20062008 Jonas Latt rho = sum(fIn);
% Address: EPFL, 1015 Lausanne, Switzerland ux = reshape ( (cx * reshape(fIn,9,lx*ly)), 1,lx,ly) ./rho;
% Email: [email protected] uy = reshape ( (cy * reshape(fIn,9,lx*ly)), 1,lx,ly) ./rho;
% Get the most recent version of this file on LBMethod.org:
% http://www.lbmethod.org/_media/numerics:cylinder.m % MACROSCOPIC (DIRICHLET) BOUNDARY CONDITIONS
% % Inlet: Poiseuille profile
% Original implementaion of Zou/He boundary condition by y_phys = col1.5;
% Adriano Sciacovelli (see example "cavity.m") ux(:,in,col) = 4 * uMax / (L*L) * (y_phys.*Ly_phys.*y_phys);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% uy(:,in,col) = 0;
% This program is free software; you can redistribute it and/or rho(:,in,col) = 1 ./ (1ux(:,in,col)) .* ( ...
% modify it under the terms of the GNU General Public License sum(fIn([1,3,5],in,col)) + 2*sum(fIn([4,7,8],in,col)) );
% as published by the Free Software Foundation; either version 2 % Outlet: Constant pressure
% of the License, or (at your option) any later version. rho(:,out,col) = 1;
% This program is distributed in the hope that it will be useful, ux(:,out,col) = 1 + 1 ./ (rho(:,out,col)) .* ( ...
% but WITHOUT ANY WARRANTY; without even the implied warranty of sum(fIn([1,3,5],out,col)) + 2*sum(fIn([2,6,9],out,col)) );
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the uy(:,out,col) = 0;
% GNU General Public License for more details.
% You should have received a copy of the GNU General Public % MICROSCOPIC BOUNDARY CONDITIONS: INLET (Zou/He BC)
% License along with this program; if not, write to the Free fIn(2,in,col) = fIn(4,in,col) + 2/3*rho(:,in,col).*ux(:,in,col);
% Software Foundation, Inc., 51 Franklin Street, Fifth Floor, fIn(6,in,col) = fIn(8,in,col) + 1/2*(fIn(5,in,col)fIn(3,in,col)) ...
% Boston, MA 021101301, USA. + 1/2*rho(:,in,col).*uy(:,in,col) ...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + 1/6*rho(:,in,col).*ux(:,in,col);
fIn(9,in,col) = fIn(7,in,col) + 1/2*(fIn(3,in,col)fIn(5,in,col)) ...
clear 1/2*rho(:,in,col).*uy(:,in,col) ...
+ 1/6*rho(:,in,col).*ux(:,in,col);
% GENERAL FLOW CONSTANTS
lx = 400; % number of cells in xdirection % MICROSCOPIC BOUNDARY CONDITIONS: OUTLET (Zou/He BC)
ly = 100; % number of cells in ydirection fIn(4,out,col) = fIn(2,out,col) 2/3*rho(:,out,col).*ux(:,out,col);
obst_x = lx/5+1; % position of the cylinder; (exact fIn(8,out,col) = fIn(6,out,col) + 1/2*(fIn(3,out,col)fIn(5,out,col)) ...
obst_y = ly/2+3; % ysymmetry is avoided) 1/2*rho(:,out,col).*uy(:,out,col) ...
obst_r = ly/10+1; % radius of the cylinder 1/6*rho(:,out,col).*ux(:,out,col);
uMax = 0.1; % maximum velocity of Poiseuille inflow fIn(7,out,col) = fIn(9,out,col) + 1/2*(fIn(5,out,col)fIn(3,out,col)) ...
Re = 100; % Reynolds number + 1/2*rho(:,out,col).*uy(:,out,col) ...
nu = uMax * 2.*obst_r / Re; % kinematic viscosity 1/6*rho(:,out,col).*ux(:,out,col);
omega = 1. / (3*nu+1./2.); % relaxation parameter
maxT = 400000; % total number of iterations % COLLISION STEP
tPlot = 50; % cycles for i=1:9
cu = 3*(cx(i)*ux+cy(i)*uy);
% D2Q9 LATTICE CONSTANTS fEq(i,:,:) = rho .* t(i) .* ...
t = [4/9, 1/9,1/9,1/9,1/9, 1/36,1/36,1/36,1/36]; ( 1 + cu + 1/2*(cu.*cu) 3/2*(ux.^2+uy.^2) );
cx = [ 0, 1, 0, 1, 0, 1, 1, 1, 1]; fOut(i,:,:) = fIn(i,:,:) omega .* (fIn(i,:,:)fEq(i,:,:));
cy = [ 0, 0, 1, 0, 1, 1, 1, 1, 1]; end
opp = [ 1, 4, 5, 2, 3, 8, 9, 6, 7];
col = [2:(ly1)]; % OBSTACLE (BOUNCEBACK)
in = 1; % position of inlet for i=1:9
out = lx; % position of outlet fOut(i,bbRegion) = fIn(opp(i),bbRegion);
end
[y,x] = meshgrid(1:ly,1:lx); % get coordinate of matrix indices
% STREAMING STEP
obst = ... % Location of cylinder for i=1:9
(xobst_x).^2 + (yobst_y).^2 <= obst_r.^2; fIn(i,:,:) = circshift(fOut(i,:,:), [0,cx(i),cy(i)]);
obst(:,[1,ly]) = 1; % Location of top/bottom boundary end
bbRegion = find(obst); % Boolean mask for bounceback cells
% VISUALIZATION
% INITIAL CONDITION: Poiseuille profile at equilibrium if (mod(cycle,tPlot)==1)
L = ly2; y_phys = y1.5; u = reshape(sqrt(ux.^2+uy.^2),lx,ly);
ux = 4 * uMax / (L*L) * (y_phys.*Ly_phys.*y_phys); u(bbRegion) = nan;
uy = zeros(lx,ly); imagesc(u);
rho = 1; axis equal off; drawnow
for i=1:9 end
cu = 3*(cx(i)*ux+cy(i)*uy); end
fIn(i,:,:) = rho .* t(i) .* ...
( 1 + cu + 1/2*(cu.*cu) 3/2*(ux.^2+uy.^2) );
end

Monday September 08, 2008 cylinder.m 1/1

You might also like