Question: NEED HELP TO DEBUG THE FOLLOWING CODE: LID DRIVEN CAVITY USING SIMPLE APPROACH. REFER CFD BOOK BY JOHN D ANDERSON FOR THE ALGORITHM & THE

NEED HELP TO DEBUG THE FOLLOWING CODE: LID DRIVEN CAVITY USING SIMPLE APPROACH. REFER CFD BOOK BY JOHN D ANDERSON FOR THE ALGORITHM & THE STAGGERED GRID
% Two-dimensional Flow Solver with Pressure Correction Method
clc;
clear all;
close all;
% GEOMETRY CONSTANTS
L =1.0; % length of domain, m
H =1.0; % height of domain, m
Nxp =129; % # of points in x direction at which pressure is resolved = No. of columns
Nyp =129; % # of points in y direction at which pressure is resolved = No. of rows
Nxu = Nxp +1; % # of points in x direction at which u velocity is resolved
Nyu = Nyp; % # of points in y direction at which u velocity is resolved
Nxv = Nxp +2; % # of points in x direction at which v velocity is resolved
Nyv = Nyp +1; % # of points in y direction at which v velocity is resolved
dx = L/(Nxp-1); % in x direction
dy = H/(Nyp-1); % in y direction
dt =1e-3; % time resolution, seconds
alpha_p =0.1; % under-relaxation factor for pressure
alpha_u =0.1; % under-relaxation factor for u velocity
alpha_v =0.1; % under-relaxation factor for v velocity
% FLUID CONSTANTS
rho =1.0; % density, kg/m^3
mu =0.1; % dynamic viscosity, kg/m s
% Reynolds Number, Re =100
% INITIAL CONDITIONS
pstar = ones(Nyp,Nxp);
pstar1= ones(Nyp,Nxp);
ustar = zeros(Nyu,Nxu);
vstar = zeros(Nyv,Nxv);
rho_ustar = rho.*ustar;
rho_vstar = rho.*vstar;
pprime = zeros(Nyp,Nxp);
pprime1= zeros(Nyp,Nxp);
uprime = zeros(Nyu,Nxu);
vprime = zeros(Nyv,Nxv);
A = zeros(Nyu,Nxu);
B = zeros(Nyv,Nxv);
% BOUNDARY CONDITIONS
ustar(1,:)=1;
v = vstar;
u = ustar; % horizontal velocity, ft/s
% Set boundary conditions for corners
u(Nyu,1)=0; % Bottom-left corner
u(Nyu,Nxu)=0; % Bottom-right corner
v(1,1)=0; % Top-left corner
v(Nyv,1)=0; % Bottom-left corner
v(1,Nxv)=0; % Top-right corner
v(Nyv,Nxv)=0; % Bottom-right corner
% Convergence criterion
tolerance =1e-16;
% PRESSURE CORRECTION METHOD
b =-dt/(dx)^2;
c =-dt/(dy)^2;
a =-2*(b + c);
d = zeros(Nyp,Nxp); % mass flow term in continuity equation
for iter =1:10000
for i =1:Nxp-1% column, 1 to 128
for j =2:Nyu-1% row, 2 to 128
k = Nyp-((Nyp-j)+1)+1; %2 to 128
kv = Nyv-((Nyv-j))+1; %3 to 129
ku = Nyu-((Nyu-j)+1)+1; %2 to 128
vbar1=0.5*(v(kv-1,i+1)+v(kv-1,i+2));
vbar2=0.5*(v(kv,i+1)+v(kv,i+2));
A(ku,i+1)=-((rho*(u(ku,i+2)^2)-rho*(u(ku,i)^2))/(2*dx)...
+((rho*u(ku-1,i+1)*vbar1)-(rho*u(ku+1,i+1)*vbar2))/(2*dy))...
+ mu*((u(ku,i+2)-2*u(ku,i+1)+u(ku,i))/(dx^2)...
+(u(ku-1,i+1)-2*u(ku,i+1)+u(ku+1,i+1))/(dy^2));
rho_ustar(ku,i+1)= rho_ustar(ku,i+1)+ A(ku,i+1)*dt ...
-(dt/dx)*(pstar(k,i+1)- pstar(k,i));
if i ==1
ustar(ku,i)=-ustar(ku,i+1);
end
if i == Nxp-1
ustar(ku,i+2)=-ustar(ku,i+1);
end
u(ku,i+1)= ustar(ku,i+1);
end
end
u = ustar;
for i =2:Nxu-2% column, 1 to 128
for j =1:Nyu-1% row, 1 to 128
k = Nyp-((Nyp-j))+1; %2 to 129
kv = Nyv-((Nyv-j))+2; %3 to 130
ku = Nyu-((Nyu-j))+1; %2 to 129
ubar1=0.5*(u(ku,i+1)+u(ku-1,i+1));
ubar2=0.5*(u(ku,i)+u(ku-1,i));
B(kv-1,i+1)=-(((rho*v(kv-1,i+2)*ubar1)-(rho*v(kv-1,i)*ubar2))/(2*dx)...
+(rho*(v(kv-2,i+1)^2)-rho*(v(kv,i+1)^2))/(2*dy))...
+ mu*((v(kv-1,i+2)-2*v(kv-1,i+1)+v(kv-1,i))/(dx^2)...
+(v(kv-2,i+1)-2*v(kv-1,i+1)+v(kv,i+1))/(dy^2));
rho_vstar(kv-1,i+1)= rho_vstar(kv-1,i+1)+ B(kv-1,i+1)*dt ...
-(dt/dy)*(pstar(k-1,i)- pstar(k,i));
vstar(kv-1,i+1)= rho_vstar(kv-1,i+1)/rho;
vstar(1,:)=-vstar(2,:);
vstar(Nyv,:)=-vstar(Nyv-1,:);
v(kv-1,i+1)= vstar(kv-1,i+1);
end
end
v = vstar;
max_divergence =0; % Initia

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!