- #1
Atr cheema
- 69
- 0
The following lines of codes implements 1D diffusion equation on 10 m long rod with fixed temperature at right boundary and right boundary temperature varying with time.
My question is how can I implement a symmetry boundary condition. I mean the temperature calculated for 9th node is assigned to 10th node? Also I want to know how can I implement infinite boundary condition?
Code:
xsize = 10; % Model size, m
xnum = 10; % Number of nodes
xstp = xsize/(xnum-1); % Grid step
tnum = 504; % number of timesteps
kappa = 833.33; % k/rhocp; % Thermal diffusivity, m^2/s
dt = 300; % Timestep
x = 0:xstp:xsize; %Creating vector for nodal point positions
tlbc = sin(linspace(0.1,2.9,tnum)); % left boundary condition
%Define initial temperature profile
tback = 0; % background temperature, K
for i=1:1:xnum
% Background profile
t0imp(i) = tback; % profile for implicit solving
end
end
% Time cycle
timesum=0; % Elapsed time
for t=1:1:tnum
% Matrix of coefficients initialization for implicit solving
L = sparse(xnum,xnum);
% Vector of right part initialization for implicit solving
R = zeros(xnum,1);
% Implicit solving of 1D temperature equation: dT/dt=kappa*d2T/dx2
% Composing matrix of coefficients L()
% and vector (column) of right parts R()
% First point: T=tback
L(1,1) = 1;
R(1,1) = tlbc(t);
% Intermediate points
for i=2:1:xnum-1
% dT/dt=kappa*d2T/dx2
% Tnew(i)/dt-kappa*(Tnew(i-1)-2*Tnew(i)+Tnew(i+1))/dx^2=Told(i)/dt
%%% Eq 10.6
L(i,i-1) = -kappa/xstp^2;
L(i,i) = 1/dt+2*kappa/xstp^2;
L(i,i+1) = -kappa/xstp^2;
R(i,1) = t0imp(i)/dt;
end
% Last point:T=tback
L(xnum,xnum) = 1;
R(xnum,1) = tback;
% Obtaining solution for implicit temperature profile
t1imp = L\R;
end
My question is how can I implement a symmetry boundary condition. I mean the temperature calculated for 9th node is assigned to 10th node? Also I want to know how can I implement infinite boundary condition?