CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Laplace Eq. Numerical Sol. with SOR Method-MATLAB Code

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 3, 2020, 16:27
Default Laplace Eq. Numerical Sol. with SOR Method-MATLAB Code
  #1
New Member
 
jist
Join Date: Feb 2020
Posts: 3
Rep Power: 6
jist is on a distinguished road
Hi all,
I've been given analytical solution of U=x^2-y^2 which satisfies the Laplace Eq. and its numerical solution as S for a square domain. Boundary conditions setted from analytical solution 'U' and unchanged through the code. Internal points of S taken as 0 at initial.
Then i am asked that to perform 20 iterations of SOR method with relaxation factor (omega) changing 1 to 2 with an interval of 0.002.
I should've been able to calculate error between analytical and numerical solution for each relaxation factor at the end of 20th iteration with given MATLAB code below but errors do not match with the solution at all.
Can anybody tell me what is it that i am doing wrong? Thanks in advence.
Here is my code,
Code:
clc
close all
clear all

N=21;
iteration=20;
deltax=1/(N-1);
deltay=deltax;
delomega=0.002;
omegai=1;
Nomega=1/(0.002);
x=linspace(0,1,21);
y=linspace(0,1,21);
omega=linspace(1,2,Nomega);

%analytical solution 
u=zeros(N,N);
for j=1:N
    for i=1:N
        u(i,j)=x(i)^2-y(j)^2;
    end
end
s=zeros(N,N);
s(1,:)=u(1,:);
s(N,:)=u(N,:);
s(:,1)=u(:,1);
s(:,N)=u(:,N);

error=0;
for k=1:Nomega
    for l=1:iteration
        for j=2:N-1
            for i=2:N-1
                R=s(i+1,j)+s(i-1,j)+s(i,j+1)+s(i,j-1)-4*(s(i,j))-(deltax^2)*s(i,j); 
                s(i,j)=s(i,j)+0.25*(1+delomega*k)*R;
            end
        end
    if l==iteration
        error=error+abs(u(i,j)-s(i,j));
        %error_(k,1)=omega(k);
        error_(k)=error/((N-2)*(N-2));
    end
    end
end

plot(omega(:),error_(:));
xlabel('\omega');
ylabel('Error');
grid on
grid minor
jist is offline   Reply With Quote

Old   April 3, 2020, 16:30
Default
  #2
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,893
Rep Power: 73
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
First, correct "U=x^2+y^2" in "U=x^2-y^2", otherwise the solution does not satisfy the Laplace euqation.


Then, why do you think to get an accurate solution after only 20 iterations??
FMDenaro is offline   Reply With Quote

Old   April 3, 2020, 16:52
Default
  #3
New Member
 
jist
Join Date: Feb 2020
Posts: 3
Rep Power: 6
jist is on a distinguished road
Sorry for the typo, it was x^2-y^2 as stated in the code.
Well this part is not about how to get an accurate solution via iteration. I will simply run the code for smaller mesh sizes to see how mesh sizes impact the solution.

Quote:
Originally Posted by FMDenaro View Post
First, correct "U=x^2+y^2" in "U=x^2-y^2", otherwise the solution does not satisfy the Laplace euqation.


Then, why do you think to get an accurate solution after only 20 iterations??
jist is offline   Reply With Quote

Old   April 3, 2020, 17:19
Default
  #4
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,893
Rep Power: 73
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
Quote:
Originally Posted by jist View Post
Sorry for the typo, it was x^2-y^2 as stated in the code.
Well this part is not about how to get an accurate solution via iteration. I will simply run the code for smaller mesh sizes to see how mesh sizes impact the solution.



You wrote "but errors do not match with the solution at all."
FMDenaro is offline   Reply With Quote

Old   April 3, 2020, 18:44
Default
  #5
New Member
 
jist
Join Date: Feb 2020
Posts: 3
Rep Power: 6
jist is on a distinguished road
I have the solution plot (error as a function of omega and grid sizes) for the scenario i explained but i am not getting the same results. What i tried to ask was that am i doing anything wrong with SOR or the error between analytical and numerical solution?
Quote:
Originally Posted by FMDenaro View Post
You wrote "but errors do not match with the solution at all."
jist is offline   Reply With Quote

Old   April 3, 2020, 19:02
Default
  #6
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,893
Rep Power: 73
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
You have a 2D map of the error as function of two variables. Plot the contour and the surface and check for the values producing the minimum error. Be aware that you cannot see a decreasing of the error for smaller mesh sizes.
FMDenaro is offline   Reply With Quote

Reply

Tags
laplace equation, matlab code, relaxation factor, sor

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
required keller box matlab code hymadyapa Main CFD Forum 4 November 28, 2019 01:59
MATLAB Code for Quasi-One-Dimensional Nozzle Flows mikasa Main CFD Forum 7 April 19, 2017 09:00
matlab code for Conjugate Gradient method in conduction problem raminostadi ANSYS 0 February 6, 2017 06:16
sample code for SIMPLER-algorithm in matlab behrouz Main CFD Forum 3 September 16, 2015 10:53
Fluent FFT functionality equivalent MATLAB code Mojtaba.a FLUENT 0 January 27, 2015 08:56


All times are GMT -4. The time now is 06:38.