How to obtain convergence of the curve to my boundary condtion?

9 views (last 30 days)
I want a curve in each 'j'th iteration. But, I didn't get convergence of the curve to plot each 'j'th iterations between limit 1 to 0. Because, my boundary condition i.e.
T(1,:)=1;T(end,:)=0
doesn't fit with my code. how to use code for convergence condition?
Further, My data values of each 'j'the iterations are not gradual values along my boundary condition and the data values in 'j' th iteration are increasing only.,
clc; close all; clear all;
ymax=20; m=80; dy=ymax/m; %'i'th row
xmax=1; n=20; dx=xmax/n; %'j'th column
tmax=100; nt=500; dt=tmax/nt;
tol=1e-5; max_difference=1;
%====================INTIALIZATION=================================%
UOLD=zeros(m,n); VOLD=zeros(m,n);
TNEW=0; TOLD=ones(m,n);
A=zeros([1,m]);
B=A;
C=A;
D=A;
T=TOLD;
tic
for j=1:n
for i=1:m
if j>i
C(i)=(dt*VOLD(i,j)/4*dy)-(dt/(2*dy^2));
elseif i>j
A(i)=(-dt*VOLD(i,j)/4*dy)-(dt/(2*dy^2));
elseif i==j
B(i)=1+(dt*UOLD(i,j)/2*dx)+(dt/(dy^2));
end
end
end
for j=2:n
for i=1:m
D(i)=(-dt*UOLD(i,j)*(-TNEW+TOLD(i,j)-TNEW)/2*dx)+(dt/(2*dy^2)*(TOLD(i+1,j)-2*TOLD(i,j)+TNEW))-(dt*VOLD(i,j)/4*dy*(TNEW-TOLD(i+1,j)-TOLD(i,j)));
end
end
T(:,j)=TriDiag(A,B,C,D); %call tridiagonal
dt=0.2+dt;
%T(1,:)=1;T(end,:)=0; % how to use thsi to get perfect curve
Thanks for advance!

Answers (1)

LeoAiE
LeoAiE on 26 Apr 2023
It seems like you are trying to enforce the boundary condition T(1,:) = 1 and T(end,:) = 0 after the solution is computed in each iteration. However, this approach won't necessarily converge to the correct solution.
To incorporate the boundary conditions correctly, you need to modify the system of equations itself. In your case, the boundary conditions should be applied during the construction of the A, B, C, and D matrices.
clc; close all; clear all;
ymax=20; m=80; dy=ymax/m; %'i'th row
xmax=1; n=20; dx=xmax/n; %'j'th column
tmax=100; nt=500; dt=tmax/nt; t=0:dt:tmax; % time at 'j'
tol=1e-2; max_difference(1)=1;
%====================INTIALIZATION=================================%
UOLD=zeros(m,nt); VOLD=zeros(m,nt);
TNEW=0; TOLD=TNEW*ones(m,nt); TWALL=ones(1,length(t));
A=zeros([1,m]);
B=A;
C=A;
D=A;
T=TOLD;
tic
for j=1:nt
for i=1:m
if i == 1 % Top boundary condition
A(1) = 0;
B(1) = 1;
C(1) = 0;
D(1) = 1;
elseif i == m % Bottom boundary condition
A(m) = 0;
B(m) = 1;
C(m) = 0;
D(m) = 0;
elseif j>i
C(i)=(dt*VOLD(i,j)/4*dy)-(dt/(2*dy^2));
elseif i>j
A(i)=(-dt*VOLD(i,j)/4*dy)-(dt/(2*dy^2));
elseif i==j
B(i)=1+(dt*UOLD(i,j)/2*dx)+(dt/(dy^2));
end
end
for j=2:nt
if j==1
for i=1:m
if i==1
D(i)=(-dt*UOLD(i,j)*(-TNEW+TOLD(i,j)-TNEW)/2*dx)+(dt/(2*dy^2)*(TOLD(i+1,j)-2*TOLD(i,j)+TNEW))-(dt*VOLD(i,j)/4*dy*(TNEW-TOLD(i+1,j)-TOLD(i,j)))-(dt/4*dy*VOLD(i,j))-(dt/2*dy^2*TNEW);
elseif i==m
D(i)=(-dt*UOLD(i,j)*(-TNEW+TOLD(i,j)-TNEW)/2*dx)+(dt/(2*dy^2)*(TWALL(j)-2*TOLD(i,j)+TOLD(i-1,j)))-(dt*VOLD(i,j)/4*dy*(TOLD(i-1,j)-TWALL(j)+TOLD(i,j)))-((-dt)/4*dy*VOLD(i,j))-(dt/2*dy^2*TWALL);
else
D(i)=(-dt*UOLD(i,j)*(-TNEW+TOLD(i,j)-TNEW)/2*dx)+(dt/(2*dy^2)*(TOLD(i+1,j)-2*TOLD(i,j)+TOLD(i-1,j)))-(dt*VOLD(i,j)/4*dy*(TOLD(i-1,j)-TOLD(i+1,j)+TOLD(i,j)));
end
end
else
for i=1:m
if i==1
D(i)=(-dt*UOLD(i,j)*(-T(i,j-1)+TOLD(i,j)-TOLD(i,j-1))/2*dx)+(dt/(2*dy^
  2 Comments
Yanni
Yanni on 26 Apr 2023
@Aladdin I'm trying to include your idea in my code,. but it's not working. It's starting with 0 instead of 1 and I couldn't see another BC i.e. 1 at 'm' the iteration.
I want my data values start with 1 and gradually will increase and then gradually decrease to 0. This process should be fall in each column of T. I already shared one column for sample.
Moreover, if we can't use the BC T(1,:)=1;T(end,:)=0, then please consider the initialization
TWALL=ones(1,length(t)) i.e.,1 will fall in first row and no.of time steps.,It means TWALL at Y=0(top BC) and TNEW=0 i.e., 0 will in last row., it means TNEW at Y=m (bottom BC). and interior values should be increase gradually and left over, then reduce to 0. here, " How to use TWALL and TNEW values to fall in T?
LeoAiE
LeoAiE on 26 Apr 2023
Maybe I have an idea of what you are looking for here. Try this
clc; close all; clear all;
ymax=20; m=80; dy=ymax/m; %'i'th row
xmax=1; n=20; dx=xmax/n; %'j'th column
tmax=100; nt=500; dt=tmax/nt; t=0:dt:tmax; % time at 'j'
tol=1e-2; max_difference(1)=1;
%====================INTIALIZATION=================================%
UOLD=zeros(m,nt); VOLD=zeros(m,nt);
TNEW=0; TOLD=TNEW*ones(m,nt); TWALL=ones(1,length(t));
A=zeros([1,m]);
B=A;
C=A;
D=A;
T=TOLD;
tic
for j=1:nt
for i=1:m
if i == 1 % Top boundary condition
A(1) = 0;
B(1) = 1;
C(1) = 0;
D(1) = TWALL(j);
elseif i == m % Bottom boundary condition
A(m) = 0;
B(m) = 1;
C(m) = 0;
D(m) = TNEW;
elseif j>i
C(i)=(dt*VOLD(i,j)/4*dy)-(dt/(2*dy^2));
elseif i>j
A(i)=(-dt*VOLD(i,j)/4*dy)-(dt/(2*dy^2));
elseif i==j
B(i)=1+(dt*UOLD(i,j)/2*dx)+(dt/(dy^2));
end
end
D(1) = TWALL(j); % Top boundary condition
D(m) = TNEW; % Bottom boundary condition
T(:,j)=TriDiag(A,B,C,D); %call tridiagonal
dt=0.2+dt;
TOLD=T;
max_difference(j) = max(abs(T(:,j)-T(:,j-1))./max(1,abs(T(:,j-1))));
if max_difference(j)<tol
break
end
end

Sign in to comment.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!