120 views (last 30 days)
Mohamed on 2 Oct 2022
Commented: Cris LaPierre on 29 Aug 2024 at 12:01
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 question:
Here is the code:
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
...
...
%%%%% 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)=exp(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_old(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);
The code to call the function is:
But i get this:
The server timed out while running your solution. Potential reasons include inefficient code, an infinite loop, and excessive output. Try to improve your solution.
is there any way to improve it ?
Samson on 7 Nov 2022
Hi Mohamed,
I have exactly the same issue, and reviewed the class. and I don't see where is went wrong
did you solve it ?
Samson on 7 Nov 2022
omega_old seems to be one of the issue.. and my SOR doesnt seem to work /:

Bhavesh Gyanchandani on 8 Jul 2023
Edited: Walter Roberson on 9 Aug 2024 at 17:55
Here is the assignment code which i wrote
It is correct
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(:)); % Write the free stream bc here
%%%%% Set relax params, tol, extra variables %%%%%
r_psi=1.8; % Set the relaxation parameter here, psi equation
r_omega=0.9; % Set the relaxation parameter here, omega equation
delta=1.e-08; % error tolerance
error=2*delta; % initialize error variable
...
...
%%%%% 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)+h*h*exp(2*xi(i))*omega(i,j));% Write psi equation here
end
end
error_psi=max(abs(psi(:)-psi_old(:)));
omega(1,:)=(psi(3,:) - 8*psi(2,:))/(2*h^2); % Write the boundary condition here
for i=2:n-1
for j=2:m-1
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)*((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)))); % Write omega equation here
end
end
error_omega=max(abs(omega(:)-omega_old(:)));
error=max(error_psi, error_omega);
end
plot_Re10(psi);
SANTHOSH on 8 Aug 2024 at 9:40
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 9:58
@Bhavesh Gyanchandani. i got good plot. but after submitting it shows "Variable psi has an incorrect value and Variable omega has an incorrect value". can you pls help me to overcome this issue

Cris LaPierre on 3 Oct 2022
Edited: Cris LaPierre on 3 Oct 2022
This error message means your code is taking too long to execute. This is usually caused by accidentally creating an infinite loop.
As a side note this appears to be an assignment. Are you aware and ok with posting this here knowing that it can't be deleted?
The gray lines in your screenshot are locked lines, meaning they are lines your instructor has written for you. You can't (and likely shouldn't) change those. That means you are left with what you have written for psi(i,j), omega(1,:), and omega_old(1,j). I'm assuming your equations are correct but just contain a syntax error somewhere.
A quick inspection leads me to believe your for loops should be calculating omega, and not omega_old. It also seems odd to be hardcoding the row to 1 inside nested for loops. Perhaps you should be indexing the same as you did for psi?
SANTHOSH on 29 Aug 2024 at 4:50
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, :) = 1; % Free stream boundary condition
r_psi = 1.0; % Relaxation parameter for psi equation
r_omega = 1.0; % Relaxation parameter for omega equation
delta = 1.e-08; % Error tolerance
error = 2*delta; % Initialize error variable
x = xi*cos(theta);
y = xi*sin(theta);
%%%%% Main SOR Loop %%%%%
while (error > delta)
psi_old = psi; omega_old = omega;
% Update psi
for i = 2:n-1
for j = 2:m-1
if (x(i, j)^2 + y(i, j)^2 < 1)
psi(i, j) = 0; % No-slip boundary condition on cylinder
else
psi(i, j) = (1 - r_psi)*psi_old(i, j) + r_psi/4*(psi_old(i+1, j) + psi_old(i-1, j) + psi_old(i, j+1) + psi_old(i, j-1));
end
end
end
error_psi = max(abs(psi(:) - psi_old(:)));
% Update omega
omega(1, :) = 0; % Set vorticity to zero at the outer boundary
for i = 2:n-1
for j = 2:m-1
if (x(i, j)^2 + y(i, j)^2 < 1)
omega(i, j) = 0; % No vorticity inside the cylinder
else
omega(i, j) = (1 - r_omega)*omega_old(i, j) + r_omega/4*(omega_old(i+1, j) + omega_old(i-1, j) + omega_old(i, j+1) + omega_old(i, j-1)) - (psi(i, j+1) - psi(i, j-1))/(2*h);
end
end
end
error_omega = max(abs(omega(:) - omega_old(:)));
error = max(error_psi, error_omega);
end
plot_Re10(psi);
end
Cris LaPierre on 29 Aug 2024 at 12:01
Please share a screenshot from Coursera so we can see how you are entering this.