Effacer les filtres
Effacer les filtres

Finite Differencing Transient Conduction

3 vues (au cours des 30 derniers jours)
Tony Stianchie
Tony Stianchie le 7 Mai 2023
Déplacé(e) : VBBV le 7 Mai 2023
Hello,
I'm attempting to conduct a finite difference approach to a transient conduction problem.
  • Rows are time steps
  • Columns are Length
My initial condition is:
  • At time = 0, Temp Is uniform at 573K (except for at L=0 where it's 673K).
My Boundary Condition is:
  • Temp = 673K at L = 0, constant
  • at L = L, no heat transfer, insulated
My descritization loop appears below.
I can populate T0 with the intial and boundary conditions above, but am running into a problem in the finitie difference for loop.
Any help is appreciated.
clc
clear all
close all
ri = 0.0125;
ro = 0.0375;
R = ro-ri;
t=2000;
k = 50; %W/mK
cp = 1750; %W s /kg K
rho = 1500; %kg/m3
alpha = k /(rho*cp); % m2/s
dr = 50;
dt = 1;
FO = alpha* dt/(dr^2);
T0 = zeros(t+1,51);
T1 = zeros(t+1,51);
for i = 1:t
T0(i,1) = 673;
T0 = T1;
end
for j = 2:t
for i = 1
T0(i,j) = 573;
T0 = T1;
end
end
for j = 3:t
for i = 2:t
T0(i,j) = (dr/R)*FO*T1(i+1,j)-(dr/R)*FO*T1(i,j)+FO*T1(i-1,j)-2*FO*T1(i,j)+FO*T1(i+1,j);
end
T0 = T1;
end
  1 commentaire
Torsten
Torsten le 7 Mai 2023
Déplacé(e) : VBBV le 7 Mai 2023
Why do both loops run over t ?
And why do you divide by R = ro-ri and not be r ?
Two of many other errors in your code.
Seems you better stick to the "pdepe" solution.

Connectez-vous pour commenter.

Réponse acceptée

VBBV
VBBV le 7 Mai 2023
Modifié(e) : VBBV le 7 Mai 2023
May be the central and forward difference schemes are not correct, but the following change will avoid the code errors
clc
clear all
close all
ri = 0.0125;
ro = 0.0375;
R = ro-ri;
t=2000;
k = 50; %W/mK
cp = 1750; %W s /kg K
rho = 1500; %kg/m3
alpha = k /(rho*cp); % m2/s
dr = 50;
dt = 1;
FO = alpha* dt/(dr^2);
T0 = zeros(t+1,51);
T1 = zeros(t+1,51);
for i = 1:t+1
T0(i,1) = 673;
end
for j = 1:t+1
T0(1,j) = 573;
end
T1 = T0;
for j = 2:t
for i = 2:t
% T0(i,j) = FO*((dr/R)*(T1(i+1,j)-T1(i,j))+T1(i-1,j)-(2*T1(i,j)+T1(i+1,j)));
T0(i,j) = T1(i,j)+ (dr/R)*FO*T1(i+1,j)-(dr/R)*FO*T1(i,j)+(FO*T1(i-1,j)-2*FO*T1(i,j)+FO*T1(i+1,j));
end
T1 = T0;
end
T0, T1

Plus de réponses (1)

Walter Roberson
Walter Roberson le 7 Mai 2023
T0 = zeros(t+1,51);
T1 = zeros(t+1,51);
Okay, both zeros
for i = 1:t
T0(i,1) = 673;
You replace a particular element of T0 with 673. On the first iteration, T0 will now have 673 in row 1 column 1, and zeros everywhere else.
T0 = T1;
And there you overwrite all of T0 with the zeros stored in T1. If that were your intent then you could be more efficient by just skipping the loop entirely since you already st T0 to all 0.

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by