Putting Togather the Right hand Side of the Navier Stokes Equation
clc
clear
L=30;
M=30;
N=30;
time=10;
for t=1:time;
for i=1:L;
for j=1:M;
for k=1:N;
u(i,j,k,t)=randn(1,1);
v(i,j,k,t)=randn(1,1);
w(i,j,k,t)=randn(1,1);
dudx(i,j,k,t)=randn(1,1);
dudy(i,j,k,t)=randn(1,1);
dudz(i,j,k,t)=randn(1,1);
RS(i,j,k,t)=u(i,j,k,t)*dudx(i,j,k,t)+v(i,j,k,t)*dudy(i,j,k,t)+w(i,j,k,t)*dudz(i,j,k,t);
end
end
end
end
figure('Position',[5 5 1700 900])
contour(RS(:,:,1,3),12)
xlabel('x axis')
ylabel('y axis')
title('Plotting the Right Hand Side')
set(gca,'XLim',[0 M],'YLim',[0 N])
grid on
clear
L=30;
M=30;
N=30;
time=10;
for t=1:time;
for i=1:L;
for j=1:M;
for k=1:N;
u(i,j,k,t)=randn(1,1);
v(i,j,k,t)=randn(1,1);
w(i,j,k,t)=randn(1,1);
dudx(i,j,k,t)=randn(1,1);
dudy(i,j,k,t)=randn(1,1);
dudz(i,j,k,t)=randn(1,1);
RS(i,j,k,t)=u(i,j,k,t)*dudx(i,j,k,t)+v(i,j,k,t)*dudy(i,j,k,t)+w(i,j,k,t)*dudz(i,j,k,t);
end
end
end
end
figure('Position',[5 5 1700 900])
contour(RS(:,:,1,3),12)
xlabel('x axis')
ylabel('y axis')
title('Plotting the Right Hand Side')
set(gca,'XLim',[0 M],'YLim',[0 N])
grid on
Navier Stokes Equations
%Navire_stokes
%u
%v
%w
%du/dx
%du/dy
%du/dz
%d2u/dx2
%mu
clc
clear
N=5;
M=5;
mu=1.2*0.00001;
delta_t=0.001;
dx=0.01;
dy=0.01;
dz=0.01;
n=0;
nn=0;
for t=1:10;
n=n+1;
if (t==1)
t=n;
for i=1:N;
for j=1:M;
u(i,j,t)=randn(1,1);
v(i,j,t)=randn(1,1);
w(i,j,t)=randn(1,1);
dudx(i,j,t)=randn(1,1);
dudy(i,j,t)=randn(1,1);
dudz(i,j,t)=randn(1,1);
d2udx2(i,j,t)=randn(1,1);
dvdx(i,j,t)=randn(1,1);
dvdy(i,j,t)=randn(1,1);
dvdz(i,j,t)=randn(1,1);
d2vdx2(i,j,t)=randn(1,1);
dpdx(i,j,t)=1.3/dx;
dpdy(i,j,t)=3.2/dy;
end
end
for i=1:N;
for j=1:M;
RHS1(i,j,t)=-u(i,j,t)*dudx(i,j,t)-v(i,j,t)*dudy(i,j,t)-w(i,j,t)*dudz(i,j,t)+mu*d2udx2(i,j,t)-dpdx(i,j,t);
RHS2(i,j,t)=-u(i,j,t)*dvdx(i,j,t)-v(i,j,t)*dvdy(i,j,t)-w(i,j,t)*dvdz(i,j,t)+mu*d2vdx2(i,j,t)-dpdy(i,j,t);
RHS3(i,j,t)=randn(1,1);
end
end
for i=1:N;
for j=1:M;
u(i,j,t+1)=u(i,j,t)+delta_t*RHS1(i,j,t);
v(i,j,t+1)=v(i,j,t)+delta_t*RHS2(i,j,t);
w(i,j,t+1)=w(i,j,t)+delta_t*RHS3(i,j,t);
total=[ u(i,j,t+1) v(i,j,t+1) w(i,j,t+1)];
v(i,j,t)=norm(total);
end
end
elseif (t>1)
nn=nn+1;
t=nn;
for i=1:N;
for j=1:M;
dudx(i,j,t)=u(i,j,t)/dx;
dudy(i,j,t)=u(i,j,t)/dy;
dudz(i,j,t)=u(i,j,t)/dz;
d2udx2(i,j,t)=u(i,j,t)/(dx*dx);
dvdx(i,j,t)=v(i,j,t)/dx;
dvdy(i,j,t)=v(i,j,t)/dy;
dvdz(i,j,t)=v(i,j,t)/dz;
d2vdx2(i,j,t)=v(i,j,t)/(dx*dx);
dpdx(i,j,t)=1.3/dx;
dpdy(i,j,t)=3.2/dy;
RHS1(i,j,t)=-u(i,j,t)*dudx(i,j,t)-v(i,j,t)*dudy(i,j,t)-w(i,j,t)*dudz(i,j,t)+mu*d2udx2(i,j,t)-dpdx(i,j,t);
RHS2(i,j,t)=-u(i,j,t)*dvdx(i,j,t)-v(i,j,t)*dvdy(i,j,t)-w(i,j,t)*dvdz(i,j,t)+mu*d2vdx2(i,j,t)-dpdy(i,j,t);
RHS3(i,j,t)=randn(1,1);
end
end
for i=1:N;
for j=1:M;
u(i,j,t+1)=u(i,j,t)+delta_t*RHS1(i,j,t);
v(i,j,t+1)=v(i,j,t)+delta_t*RHS2(i,j,t);
w(i,j,t+1)=w(i,j,t)+delta_t*RHS3(i,j,t);
total=[ u(i,j,t+1) v(i,j,t+1) w(i,j,t+1)];
v(i,j,t)=norm(total);
end
end
end
end
%u
%v
%w
%du/dx
%du/dy
%du/dz
%d2u/dx2
%mu
clc
clear
N=5;
M=5;
mu=1.2*0.00001;
delta_t=0.001;
dx=0.01;
dy=0.01;
dz=0.01;
n=0;
nn=0;
for t=1:10;
n=n+1;
if (t==1)
t=n;
for i=1:N;
for j=1:M;
u(i,j,t)=randn(1,1);
v(i,j,t)=randn(1,1);
w(i,j,t)=randn(1,1);
dudx(i,j,t)=randn(1,1);
dudy(i,j,t)=randn(1,1);
dudz(i,j,t)=randn(1,1);
d2udx2(i,j,t)=randn(1,1);
dvdx(i,j,t)=randn(1,1);
dvdy(i,j,t)=randn(1,1);
dvdz(i,j,t)=randn(1,1);
d2vdx2(i,j,t)=randn(1,1);
dpdx(i,j,t)=1.3/dx;
dpdy(i,j,t)=3.2/dy;
end
end
for i=1:N;
for j=1:M;
RHS1(i,j,t)=-u(i,j,t)*dudx(i,j,t)-v(i,j,t)*dudy(i,j,t)-w(i,j,t)*dudz(i,j,t)+mu*d2udx2(i,j,t)-dpdx(i,j,t);
RHS2(i,j,t)=-u(i,j,t)*dvdx(i,j,t)-v(i,j,t)*dvdy(i,j,t)-w(i,j,t)*dvdz(i,j,t)+mu*d2vdx2(i,j,t)-dpdy(i,j,t);
RHS3(i,j,t)=randn(1,1);
end
end
for i=1:N;
for j=1:M;
u(i,j,t+1)=u(i,j,t)+delta_t*RHS1(i,j,t);
v(i,j,t+1)=v(i,j,t)+delta_t*RHS2(i,j,t);
w(i,j,t+1)=w(i,j,t)+delta_t*RHS3(i,j,t);
total=[ u(i,j,t+1) v(i,j,t+1) w(i,j,t+1)];
v(i,j,t)=norm(total);
end
end
elseif (t>1)
nn=nn+1;
t=nn;
for i=1:N;
for j=1:M;
dudx(i,j,t)=u(i,j,t)/dx;
dudy(i,j,t)=u(i,j,t)/dy;
dudz(i,j,t)=u(i,j,t)/dz;
d2udx2(i,j,t)=u(i,j,t)/(dx*dx);
dvdx(i,j,t)=v(i,j,t)/dx;
dvdy(i,j,t)=v(i,j,t)/dy;
dvdz(i,j,t)=v(i,j,t)/dz;
d2vdx2(i,j,t)=v(i,j,t)/(dx*dx);
dpdx(i,j,t)=1.3/dx;
dpdy(i,j,t)=3.2/dy;
RHS1(i,j,t)=-u(i,j,t)*dudx(i,j,t)-v(i,j,t)*dudy(i,j,t)-w(i,j,t)*dudz(i,j,t)+mu*d2udx2(i,j,t)-dpdx(i,j,t);
RHS2(i,j,t)=-u(i,j,t)*dvdx(i,j,t)-v(i,j,t)*dvdy(i,j,t)-w(i,j,t)*dvdz(i,j,t)+mu*d2vdx2(i,j,t)-dpdy(i,j,t);
RHS3(i,j,t)=randn(1,1);
end
end
for i=1:N;
for j=1:M;
u(i,j,t+1)=u(i,j,t)+delta_t*RHS1(i,j,t);
v(i,j,t+1)=v(i,j,t)+delta_t*RHS2(i,j,t);
w(i,j,t+1)=w(i,j,t)+delta_t*RHS3(i,j,t);
total=[ u(i,j,t+1) v(i,j,t+1) w(i,j,t+1)];
v(i,j,t)=norm(total);
end
end
end
end
Unless otherwise noted, all content on this site is @Copyright by Ahmed Al Makky 2012-2013 - http://cfd2012.com