MatLab PDE 绘图问题

MatLab PDE plotting issue

我是 Matlab 环境的新手,我正在 Matlab (2014b) 中进行传热模拟。我打算有不同 materials 的多层墙(目前,只有一个 material - 铜)并在单个图中显示结果。一切正常,直到我尝试将墙的第三层附加到地块上。 下面是 PDE 求解器 (r3-r0) 的基本变量和几何的定义:

k = 400; 
rho = 8960; 
specificHeat = 386; 
thick = .01; 
stefanBoltz = 5.670373e-8; 
hCoeff = 1;
ta = 300;
emiss = .5;

c = thick*k;
a = sprintf('2*%g + 2*%g*%g*u.^3', hCoeff, emiss, stefanBoltz);
f = 2*hCoeff*ta + 2*emiss*stefanBoltz*ta^4;
d = thick*rho*specificHeat;

r0 = [3 4 0 1 1 0 1 1 1.3 1.3];
r1 = [3 4 0 1 1 0 0.6 0.6 1 1];
r2 = [3 4 0 1 1 0 0.3 0.3 0.6 0.6];
r3 = [3 4 0 1 1 0 0 0 0.3 0.3];

现在,下面的一段代码计算通过壁的底层 (r3) 的热传递,输入温度为 1000 K:

gdm = r3';
g = decsg(gdm, 'R3', ('R3')');
hmax = .1; % element size
[p, e, t] = initmesh(g, 'Hmax', hmax);    

numberOfPDE = 1;
pb = pde(numberOfPDE);
pg = pdeGeometryFromEdges(g);
uBottom = pdeBoundaryConditions(pg.Edges(1),'u',1000);
pb.BoundaryConditions = uBottom;

u = pdenonlin(pb,p,e,t,c,a,f, 'jacobian', 'lumped');
fprintf('Temperature at the top edge of the plate = %5.1f degrees-K\n', ...
 u(4));

figure
pdeplot(p, e, t, 'xydata', u, 'contour', 'on', 'colormap', 'jet')

hold on

在"hold on"之后,我基本上重复了"r2"矩形之前的代码,输入温度为"u(4)"(上一层的输出),然后是最后一位代码:

hold off
axis([0,1,0,2])
caxis manual
caxis([u(4) 1000]);
colorbar; 

正如我所说,这一切都有效,第一层和第二层的结果都在同一个图中。但是在我对第三层 (r1) 重复该过程并将结果绘制到原始图中(当然,"hold off" 位位于代码的最后),绘图仅显示结果对于第三层。我不确定这是否是 Matlab 的一些限制或者我的解决方案是否错误,所以我想寻求一些帮助或指导。提前致谢

为了更好地理解,下面是完整的代码:

k = 400;
rho = 8960;
specificHeat = 386;
thick = .01;
stefanBoltz = 5.670373e-8;
hCoeff = 1; 
ta = 300;
emiss = .5;

c = thick*k;
a = sprintf('2*%g + 2*%g*%g*u.^3', hCoeff, emiss, stefanBoltz);
f = 2*hCoeff*ta + 2*emiss*stefanBoltz*ta^4;
d = thick*rho*specificHeat;

r0 = [3 4 0 1 1 0 1 1 1.3 1.3];
r1 = [3 4 0 1 1 0 0.6 0.6 1 1];
r2 = [3 4 0 1 1 0 0.3 0.3 0.6 0.6];
r3 = [3 4 0 1 1 0 0 0 0.3 0.3];
%---------------------------------------------------------

gdm = r3';
g = decsg(gdm, 'R3', ('R3')');
hmax = .1; % element size
[p, e, t] = initmesh(g, 'Hmax', hmax);

numberOfPDE = 1;
pb = pde(numberOfPDE);
pg = pdeGeometryFromEdges(g);
uBottom = pdeBoundaryConditions(pg.Edges(1),'u',1000);
pb.BoundaryConditions = uBottom;

u = pdenonlin(pb,p,e,t,c,a,f, 'jacobian', 'lumped');
fprintf('Temperature at the top edge of the plate = %5.1f degrees-K\n', ...
 u(4));

figure
pdeplot(p, e, t, 'xydata', u, 'contour', 'on', 'colormap', 'jet')

hold on

%----------------------------------------------------------------------
gdm = r2';
g = decsg(gdm, 'R2', ('R2')');
hmax = .1; % element size
[p, e, t] = initmesh(g, 'Hmax', hmax);

numberOfPDE = 1;
pb = pde(numberOfPDE);
pg = pdeGeometryFromEdges(g);
uBottom = pdeBoundaryConditions(pg.Edges(1),'u',u(4));
pb.BoundaryConditions = uBottom;

u = pdenonlin(pb,p,e,t,c,a,f, 'jacobian', 'lumped');
fprintf('Temperature at the top edge of the plate = %5.1f degrees-K\n', ...
 u(4));

pdeplot(p, e, t, 'xydata', u, 'contour', 'on', 'colormap', 'jet')

%----------------------------------------------------------------------------
gdm = r1';
g = decsg(gdm, 'R1', ('R1')');
hmax = .1; % element size
[p, e, t] = initmesh(g, 'Hmax', hmax);

numberOfPDE = 1;
pb = pde(numberOfPDE);
pg = pdeGeometryFromEdges(g);
uBottom = pdeBoundaryConditions(pg.Edges(1),'u',u(4));
pb.BoundaryConditions = uBottom;

u = pdenonlin(pb,p,e,t,c,a,f, 'jacobian', 'lumped');
fprintf('Temperature at the top edge of the plate = %5.1f degrees-K\n', ...
 u(4));

pdeplot(p, e, t, 'xydata', u, 'contour', 'on', 'colormap', 'jet')

%----------------------------------------------------------------------------
gdm = r0';
g = decsg(gdm, 'R0', ('R0')');
hmax = .1; % element size
[p, e, t] = initmesh(g, 'Hmax', hmax);

numberOfPDE = 1;
pb = pde(numberOfPDE);
pg = pdeGeometryFromEdges(g);
uBottom = pdeBoundaryConditions(pg.Edges(1),'u',u(4));
pb.BoundaryConditions = uBottom;

u = pdenonlin(pb,p,e,t,c,a,f, 'jacobian', 'lumped');
fprintf('Temperature at the top edge of the plate = %5.1f degrees-K\n', ...
 u(4));

pdeplot(p, e, t, 'xydata', u, 'contour', 'on', 'colormap', 'jet')

%hold off

axis([0,1,0,2])
%caxis manual
caxis([u(4) 1000]);

出于某种原因(我不太清楚)pdeplot 函数在内部调用 hold off.

因此,要获得所需的结果,您需要在每次调用 pdeplot 后添加一个 hold on