0% found this document useful (0 votes)
69 views8 pages

Canalplot: %ancho de Entrada

This document contains code to simulate fluid flow through a 2D channel with obstacles using the lattice Boltzmann method. The code defines the geometry and boundary conditions of the channel, initializes the fluid velocity and height fields, then iteratively solves the lattice Boltzmann equation to model fluid flow over many time steps. Particle tracking is also implemented to visualize pathlines of tracer particles released in the flow field.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views8 pages

Canalplot: %ancho de Entrada

This document contains code to simulate fluid flow through a 2D channel with obstacles using the lattice Boltzmann method. The code defines the geometry and boundary conditions of the channel, initializes the fluid velocity and height fields, then iteratively solves the lattice Boltzmann equation to model fluid flow over many time steps. Particle tracking is also implemented to visualize pathlines of tracer particles released in the flow field.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

CANALPLOT

clear all; close all; clc


L=600; H=124; km=2000;
U=10;rho=1000;
b=100;%ancho de entrada
dx=10; dy=2; alpha=(dx/dy)^2; A=-2*(1+alpha);
nxt=L/dx+1; nyt=H/dy+1;
nxa=1; nya=12/dy+1;
nxb=200/dx+1; nyb=12/dy+1;
nxc=250/dx+1; nyc=1;
nxd=350/dx+1; nyd=1;
nxe=400/dx+1; nye=12/dy+1;
nxf=600/dx+1; nyf=12/dy+1;
nxg=1; nyg=112/dy+1;%(57)
nxh=nxb; nyh=nyg;
nxi=nxc; nyi=124/dy+1;
nxj=nxd; nyj=nyi;
nxk=nxe; nyk=nyg;
nxl=nxf; nyl=nyg;
Lo=280; Lf=320;%Lmites izquierdo y derecho del bloque cuadrado( de 40 x
40)
ho=42; hf=82;%Lmites inferior y superior del bloque cuadrado
zi=zeros(nxt,nyt);
for i=1:nxt %Asignando valor de zi en el bloque cuadrado
for j=1:nyt
x(i,j)=(i-1)*dx;
y(i,j)=(j-1)*dy;
if x(i,j)>=Lo && x(i,j)<=Lf
if y(i,j)>=ho && y(i,j)<=hf
zi(i,j)=U*b/2;
end
end
end
end
%PARTE DE ABAJO DEL CANAL
for j=1:nya %Bloque I
for i=1:nxb
zi(i,j)=0;
end
end
for i=22:25 %Bloque2
ny=round(-6/5*i+161/5);
for j=1:ny
zi(i,j)=0;
end
end
for i=nxc:nxd %Bloque3
for j=1
zi(i,j)=0;
end
end
for i=37:40 %Bloque4
ny=round(6/5*i-211/5);
for j=1:ny;
zi(i,j)=0;
end

end
for j=1:nye %Bloque 5
for i=41:nxf
zi(i,j)=0;
end
end
% PARTE DE ARRIBA DEL CANAL
for j=nyg:nyt %Bloque 6
for i=1:nxh
zi(i,j)=U*b;
end
end
for i=22:25 %Bloque 7
ny=round(6/5*i+159/5)
for j=ny:nyt
zi(i,j)=U*100;
end
end
for i=nxi:nxj %Bloque 8
for j=nyt
zi(i,j)=U*100;
end
end
for i=37:40 %Bloque 9
ny=round(-6/5*i+531/5);
for j=ny:nyt
zi(i,j)=U*100;
end
end
for j=nyk:nyt %Bloque 10
for i=41:nxf
zi(i,j)=U*100;
end
end
for i=1 %zi en la entrada
for j=nya+1:nyg-1
zi(i,j)=U*(j-7)*dy;
end
end
for i=nxt%zi en la salida
for j=nya+1:nyg-1
zi(i,j)=U*(j-7)*dy;
end
end
for j=1:nyt%velocidades iniciales
for i=1:nxt
u(i,j)=U;
v(i,j)=0;
end
end
%Proceso iterativo
X(:,:,1)=zi;
vel(1:nxt,1:nyt)=0;
for k=1:km
for j=2:nyt-1

for i=2:nxt-1
X(i,j,k+1)=-(alpha*X(i,j-1,k)+X(i-1,j,k)+X(i+1,j,k)
+alpha*X(i,j+1,k))/A;
end
end
%Restaurando valores constantes de fronteras
%PARTE DE ABAJO
for j=1:nya %Bloque I
for i=1:nxb
X(i,j,k+1)=0;
end
end
for i=22:25 %Boque2
ny=round(-6/5*i+161/5);
for j=1:ny
X(i,j,k+1)=0;
end
end
for i=nxc:nxd %Boque3
for j=1
X(i,j,k+1)=0;
end
end
for i=37:40 %Boque4
ny=round(6/5*i-211/5);
for j=1:ny;
X(i,j,k+1)=0;
end
end
for j=1:nye %Bloque 5
for i=41:nxf
X(i,j,k+1)=0;
end
end
% PARTE DE ARRIBA
for j=nyg:nyt %Bloque 6
for i=1:nxh
X(i,j,k+1)=U*b;
end
end
for i=22:25 %Boque 7
ny=round(6/5*i+159/5);
for j=ny:nyt
X(i,j,k+1)=U*100;
end
end
for i=nxi:nxj %Boque 8
for j=nyt
X(i,j,k+1)=U*100;
end
end
for i=37:40 %Boque 9
ny=round(-6/5*i+531/5);
for j=ny:nyt
X(i,j,k+1)=U*100;
end
end

for j=nyk:nyt %Bloque 10


for i=41:nxf
X(i,j,k+1)=U*100;
end
end
for i=1 %zi en la entrada
for j=nya+1:nyg-1
X(i,j,k+1)=U*(j-7)*dy;
end
end
for i=nxt%zi en la salida
for j=nya+1:nyg-1
X(i,j,k+1)=U*(j-7)*dy;
end
end
%del bloque cuadrado del medio
for i=1:nxt
for j=1:nyt
x(i,j)=(i-1)*dx;
y(i,j)=(j-1)*dy;
if x(i,j)>=Lo && x(i,j)<=Lf
if y(i,j)>=ho && y(i,j)<=hf
X(i,j,k+1)=U*b/2;
end
end
end
end
end
zi2=X(:,:,k+1);
for j=2:nyt
for i=2:nxt
u(i,j)=(zi2(i,j)-zi2(i,j-1))/dy;
v(i,j)=-(zi2(i,j)-zi2(i-1,j))/dx;
vel(i,j)=((u(i,j))^2+(v(i,j)^2))^0.5;
end
end

%contourf(x,y,X(:,:,1000),30)
contourf(x,y,zi2,30)
hold on
quiver(x,y,u,v,'k')
tf=100;
nt=100;
dt=tf/(nt-1);
[xo,yo]=ginput
hold on
plot(xo,yo,'w*')
np=length(xo);
% np= numero de particulas

for k=1:nt
for ip=1:np
for i=1:nxt-1
for j=1:nyt-1
if xo(ip)>=x(i,j) && xo(ip)<=x(i+1,j)
if yo(ip)>=y(i,j) && yo(ip)<=y(i,j+1)
Up(ip)=u(i,j);
Vp(ip)=v(i,j);

xp(ip)=xo(ip)+Up(ip)*dt;
yp(ip)=yo(ip)+Vp(ip)*dt;
% break
end
% break
end
%
break
end
%break
end
xo(ip)=xp(ip);
yo(ip)=yp(ip);
end
hold on
plot(xo,yo,'*w')
M(k)=getframe;
end

% calculo de divergencia
dive(1:nxt,1:nyt)=0;
for i=2:nxt-1
for j=2:nyt-1
dux=(u(i+1,j)-u(i-1,j))/(2*dx);
dvy=(v(i,j+1)-v(i,j-1))/(2*dy);
dive(i,j)=dux+dvy;
end
end
figure
contourf(x,y,dive)
colorbar
title('Divergencia')
%Clculo de presiones
%vel=zeros(nxt-1,nyt-1);
%P(1:nxt,1:nyt-1)=0;
for i=2:nxt
for j=2:nyt
P(i,j)=((vel(i,j))^2-(vel(i-1,j))^2)*(rho/2);
end
end
figure
contourf(x,y,P)

colorbar
title('Campo de Presiones')

LAPLACE3
clear all
close all
clc
L=300;
b=60;
dx=10;
dy=2;
km=1000;
U=3;
nx=L/dx+1;
ny=b/dy+1;
Lo=100;
Lf=200;
bo=20;
bf=40;
% delimitacion del solido
for i=1:nx
for j=1:ny
x(i,j)=(i-1)*dx;
y(i,j)=(j-1)*dy;
if x(i,j)>=Lo & x(i,j)<=Lf
if y(i,j)>=bo & y(i,j)<=bf
si(i,j)=U*b/2
end
end
end
end
% definicion de condiciones de frontera
si(1:nx,1)=0;
si(1:nx,ny)=U*b;
si(1,1:ny)=U*dy*(0:ny-1);
si(nx,1:ny)=U*dy*(0:ny-1);
alpha=(dx/dy)^2;
A=-2*(1+alpha);
u(1:nx,1:ny)=U;
v(1:nx,1:ny)=0;
% comienzo del proceso iterativo
X(:,:,1)=si;
for k=1:km
for j=2:ny-1
for i=2:nx-1
X(i,j,k+1)=-(alpha*X(i,j-1,k)+X(i-1,j,k)+X(i+1,j,k)
+alpha*X(i,j+1,k))/A;
end
end
for i=1:nx
for j=1:ny

end

if x(i,j)>=Lo & x(i,j)<=Lf


if y(i,j)>=bo & y(i,j)<=bf
X(i,j,k+1)=si(i,j)
end
end
end

for i=1:nx
X(i,1,k+1)=si(i,1);
X(i,ny,k+1)=si(i,ny);
end
for j=1:ny
X(1,j,k+1)=si(1,j);
X(nx,j,k+1)=si(nx,j);
end
end
% calculo de la velocidad
for i=2:nx-1
for j=2:ny-1
u(i,j)=(X(i,j,k)-X(i,j-1,k))/dy;
v(i,j)=-(X(i,j,k)-X(i-1,j,k))/dx;
end
end
contour(x,y,X(:,:,k),50)
hold on
quiver(x,y,u,v,'k')
%axis equal
tf=100;
nt=100;
dt=tf/(nt-1);
[xo,yo]=ginput
hold on
plot(xo,yo,'r*')
np=length(xo);
% np= numero de particulas
for k=1:nt
for ip=1:np
for i=1:nx-1
for j=1:ny-1
if xo(ip)>=x(i,j) & xo(ip)<=x(i+1,j)
if yo(ip)>=y(i,j) & yo(ip)<=y(i,j+1)
Up(ip)=u(i,j);
Vp(ip)=v(i,j);
xp(ip)=xo(ip)+Up(ip)*dt;
yp(ip)=yo(ip)+Vp(ip)*dt;
% break
end

break
end
break

%
end
%break
end
xo(ip)=xp(ip);
yo(ip)=yp(ip);
end
hold on
plot(xo,yo,'*r')
M(k)=getframe;
end

You might also like