Matlab:1D热扩散模型中的Timestep稳定性

时间:2013-03-26 14:52:27

标签: matlab time heat

我在Matlab中有1D热扩散代码,我在10年的时间尺度上使用它,现在我正在尝试使用相同的代码来工作数百万年的规模。显然,如果我保持我的时间步长相同,这将需要很长时间来计算,但如果我增加我的时间步,我会遇到数值稳定性问题。

我的问题是:

我该如何处理这个问题?什么影响最大稳定时间步长?我该如何计算呢?

非常感谢,

亚历

close all
clear all

dx = 4;    % discretization step in m
dt = 0.0000001; % timestep in Myrs
h=1000;        % height of box in m
nx=h/dx+1;
model_lenth=1; %length of model in Myrs
nt=ceil(model_lenth/dt)+1;     % number of tsteps to reach end of model
kappa = 1e-6; % thermal diffusivity
x=0:dx:0+h;     % finite difference mesh
T=38+0.05.*x;  % initial T=Tm everywhere ...
time=zeros(1,nt);
t=0;
Tnew = zeros(1,nx);

%Lower sill
sill_1_thickness=18;
Sill_1_top_position=590;
Sill_1_top=ceil(Sill_1_top_position/dx);
Sill_1_bottom=ceil((Sill_1_top_position+sill_1_thickness)/dx);

%Upper sill
sill_2_thickness=10;
Sill_2_top_position=260;
Sill_2_top=ceil(Sill_2_top_position/dx);
Sill_2_bottom=ceil((Sill_2_top_position+sill_2_thickness)/dx);

%Temperature of dolerite intrusions
Tm=1300;

T(Sill_1_top:Sill_1_bottom)=Tm; %Apply temperature to intrusion 1

% unit conversion to SI:
secinmyr=24*3600*365*1000000;   % dt in sec
dt=dt*secinmyr;

%Plot initial conditions
figure(1), clf
f1 = figure(1); %Make full screen
set(f1,'Units', 'Normalized', 'OuterPosition', [0 0 1 1]); 
plot (T,x,'LineWidth',2)
xlabel('T [^oC]')
ylabel('x[m]')
axis([0 1310 0 1000])
title(' Initial Conditions')
set(gca,'YDir','reverse');

%Main calculation
for it=1:nt

  %Apply temperature to upper intrusion
  if it==10;  
      T(Sill_2_top:Sill_2_bottom)=Tm; 
  end

  for i = 2:nx-1
      Tnew(i) = T(i) + kappa*dt*(T(i+1) - 2*T(i) + T(i-1))/dx/dx;
  end

  Tnew(1) = T(1);
  Tnew(nx) = T(nx);

  time(it) = t;

  T = Tnew; %Set old Temp to = new temp for next loop
  tmyears=(t/secinmyr);

  %Plot a figure which updates in the loop of temperature against depth
  figure(2), clf
  plot (T,x,'LineWidth',2)
  xlabel('T [^oC]')
  ylabel('x[m]')
  title([' Temperature against Depth after ',num2str(tmyears),' Myrs'])
  axis([0 1300 0 1000])
  set(gca,'YDir','reverse');%Reverse y axis

  %Make full screen     
  f2 = figure(2); 
  set(f2,'Units', 'Normalized', 'OuterPosition', [0 0 1 1]); 

  drawnow

  t=t+dt;
end

2 个答案:

答案 0 :(得分:1)

像FTCS这样的显式方案的稳定性条件由$ r = K dt / dx ^ 2< 1/2 $或$ dt< dx ^ 2 /(2K)$其中K是你的扩散系数。为了使4阶导数截断误差项的符号为负,这是必需的。

如果您不希望受时间步长的限制,我建议使用隐式方案(尽管计算成本高于显式方案)。这可以简单地通过使用后向欧拉来表示扩散项而不是前向欧拉来实现。另一种选择是Crank-Nicholson,这也是隐含的。

答案 1 :(得分:0)

@Isopycnal振荡是完全正确的,因为最大稳定步骤在显式方案中受到限制。仅供参考,这通常被称为离散傅立叶数或仅仅是傅立叶数,并且可以查找不同的边界条件。 以下内容可以帮助您推导出Implicit或Crank-Nicholson方案,并提到稳定性Finite-Difference Approximations to the Heat Equation by Gerald W. Recktenwald

抱歉,我还没有代表添加评论