can anyone please help me with this ?
15 views (last 30 days)
Show older comments
im trying to compute the steady solutions for the stream function and scalar vorticity for a 2d flow around an infinite cylinder at RE = 10 Here is the code:
[psi, omega] = flow_around_cylinder_steady
function [psi, omega] = flow_around_cylinder_steady
Re=10;
%%%%% define the grid %%%%%
n=101; m=101; % number of grid points
N=n-1; M=m-1; % number of grid intervals
h=pi/M; % grid spacing based on theta variable
xi=(0:N)*h; theta=(0:M)*h; % xi and theta variables on the grid
%%%%% Initialize the flow fields %%%%%
psi=zeros(n,m);
omega=zeros(n,m);
psi(n,:)=exp(xi(n)) * sin(theta(:));
%%%%% Set relax params, tol, extra variables %%%%%
r_psi=1.8;
r_omega=0.9;
delta=1.e-08; % error tolerance
error=2*delta; % initialize error variable
%%%%% Add any additional variable definitions here %%%%%
...
...
%%%%% Main SOR Loop %%%%%
while (error > delta)
psi_old = psi; omega_old = omega;
for i=2:n-1
for j=2:m-1
psi(i,j)=sin(xi(i)) * sin(theta(j));
end
end
error_psi=max(abs(psi(:)-psi_old(:)));
omega(1,:)= (psi(3,j) - 8*psi(2,j)) * 1/(2*h^2);
for i=2:n-1
for j=2:m-1
omega(1,j)= (psi(3,j) - 8*psi(2,j)) * 1/(2*h^2);
end
end
error_omega=max(abs(omega(:)-omega_old(:)));
error=max(error_psi, error_omega);
end
%plot_Re10(psi);
end
The code to call the function is: [psi, omega] = flow_around_cylinder_steady;
The gray areas cannot be changed
but i keep getting a message saying that my psi and omega variables are incorrect.
can anyone please help me pinpoint the exact area of my problem and let me know how to fix it ?
5 Comments
SANTHOSH
on 8 Aug 2024 at 9:39
but after run the function i couldnt be able to submit. it shows that " Variable psi has an incorrect value and Variable omega has an incorrect value"
SANTHOSH
on 8 Aug 2024 at 10:36
@Mohamed Mohamed @Torsten can anyone pls help me on this. i got the plot, but still i couldnt be able to submit. here is the complete code which i have used. i culdnt be able to submit it. it shows "Variable psi has an incorrect value and Variable omega has an incorrect value". i have attached my screen thank you in advance
Answers (1)
Aisha Singhania
on 10 Jul 2023
Edited: Aisha Singhania
on 10 Jul 2023
There are some things you need to change, try some of these codes. Although I am not sure myself but hopefully this does help you. These were some of the errors I had noticed in your code.
%%%%% Main SOR Loop %%%%%
while (error > delta)
psi_old = psi; omega_old = omega;
for i=2:n-1
for j=2:m-1
psi(i,j)=(1-r_psi)*psi(i,j)+(r_psi/4)*...
(psi(i+1,j)+psi(i-1,j)+psi(i,j+1)+psi(i,j-1)+fac(i)*omega(i,j));
end
end
error_psi=max(abs(psi(:)-psi_old(:)));
omega(1,:)=(1/(2*h^2))*(psi(3,:)-8*psi(2,:)); %Second order bc
for i=2:n-1
for j=2:m-1
f(i,j)=...
(psi(i+1,j)-psi(i-1,j))*(omega(i,j+1)-omega(i,j-1))...
-(psi(i,j+1)-psi(i,j-1))*(omega(i+1,j)-omega(i-1,j));
omega(i,j)=(1-r_omega)*omega(i,j)+(r_omega/4)*...
(omega(i+1,j)+omega(i-1,j)+omega(i,j+1)+omega(i,j-1)...
+(Re/8)*f(i,j));
end
end
error_omega=max(abs(omega(:)-omega_old(:)));
error=max(error_psi, error_omega);
end
plot_Re10(psi);
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!