My Matlab code for 1D convection Diffusion problem is taking too much time to execute

clc;
clear all;
phia=1; %Boundary Conditions
phib=0; %Boundary Conditions
gamma=0.1;
L=1; %Length of a bar
nx=5; %No. of subdomains
dx=L/nx; %finite volume length
phi=zeros(nx+2,1);
u=0.1;
rho=1;
D=gamma/dx;
F=rho*u;
tolearnce=1e-7;
error=1;
phi(1,1)=phia;
phi(7,1)=phib;
iter=0;
x=0:dx:L;
% p= rho*u*L/gamma;
phi_exact = phia + (phib-phia).*((exp(rho*u*x/gamma)-1)./ (exp(rho*u*L/gamma)-1));
figure (1);
plot(x,phi_exact,'ro')
while error>tolearnce
phi_old=phi;
for i=2
a_E1=D-F/2;
a_W1=0;
Spa=-(2*D+F);
Sua=(2*D+F)*phia;
a_P1=a_E1+a_W1-Spa;
phi(i,1)=(a_E1*phi(i+1) + a_W1*phi(i-1)+ Sua)/a_P1;
end
for i=3:nx
a_W2=D+F/2;
a_E2=D-F/2;
a_P2=2*D;
phi(i,1)=(a_E2*phi(i+1) + a_W2*phi(i-1))/a_P2;
end
for i=6
a_W3=D+F/2;
a_E3=0;
Spb=-(2*D-F);
Sub=(2*D-F)*phib;
a_P3=a_E3+a_W3-Spb;
phi(i,1)=(a_E3*phi(i+1) + a_W3*phi(i-1)+ Sub)/a_P3;
end
iter=iter+1;
end
figure(1)
hold on
plot(x,phi,'b','Linewidth',1);
legend('Exact solution','Difference_Scheme');

Réponses (1)

You set the values
tolearnce=1e-7;
error=1;
before you enter the while loop, and you never change them. Therefore, the loop will never be exited.

Catégories

En savoir plus sur Fluid Dynamics dans Centre d'aide et File Exchange

Produits

Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by