Why is time steps changing the graphic? (diffusion equation)
Show older comments
This is a model to know how the heat will pass through the soil (diffusion equation). It's working good with this time steps, but my problem is when I put the dt bigger than 500 (even if I change n_steps). The graphic becomes crazy, it's totally unphysical. Why is it happening? Thank you.
% set model parameters & constants dt = 240; % time step (s)
n_steps = 2*15; % number of time steps (15 steps = 1h)
J = 10; % number of soil levels
D = 1e-7; % diffusion coefficient (m^2 s^{-1})
soil_depth = 0.1; % soil depth (m)
dz = soil_depth/J; % depth increment (m)
DD = D*dt/(dz*dz); % calculate coefficient for FTCS scheme
% set up vertical z grid (j index) and time grid (n index)
ja = [1:J]; % set up an array for vertical levels
ja2 = [2:J-1]; % set up an array for the interior vertical levels
z(ja) = (ja - 0.5)*dz; % define z grid with levels at midpoint of soil layers
na = [1:n_steps]; % set up an array for time grid
% define initial conditions, T_i is initial temperature, i.e. T_i(ja)=T(0,ja)
Trock = 10;
T_i(ja) = Trock;
Tair= 40;
% The function Tair was defined in other script and called
% function t = Tair(n)
% t=10+10*sin(2*pi*n/360) obs: dt=240 or 4 minutes, so 1/360 of day
% end
% Problem becomes calculation of T(n,j) , where n index is for time, j index is for depth
T(na,ja) = NaN %set up array of correct dimensions
% Calculate first time step ----------------------------------------
% Note this has to be done separately, as Matlab indices must be integers
% Use top boundary condition derived in lectures (section 6.2)
T(1,1) = T_i(1)+DD*(T_i(2)-3*T_i(1)+2*Tair(1)); % Top BC
T(1,ja2) = T_i(ja2)+DD*(T_i(ja2+1)-2*T_i(ja2)+T_i(ja2-1)); % Interior points
T(1,J) = T_i(J)+DD*(2*Trock-3*T_i(J)+T_i(J-1)); % Bottom BC
% Calculate all subsequent time steps----------------------------------
% Use for loop over time (n), filling in T array as we go
for n=2:n_steps
T(n,1) = T(n-1,1)+DD*(T(n-1,2)-3*T(n-1,1)+2*Tair);
T(n,ja2) = T(n-1,ja2)+DD*(T(n-1,ja2+1)-2*T(n-1,ja2)+T(n-1,ja2-1));
T(n,J) = T(n-1,J)+DD*(2*Trock-3*T(n-1,J)+T(n-1,J));
end
% plot results-----------------------------------------
plot(T(30,:),z,'b-o')
hold on;
xlabel('Temperature (^o C)')
ylabel('Depth (m)')
set(gca,'ydir','reverse')
axis([0 40 0 0.1])
Accepted Answer
More Answers (0)
Categories
Find more on Structural Mechanics 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!