www.gusucode.com > pde 案例源码 matlab代码程序 > pde/DSlicesThrough3DGeometryExample.m

    %% 2-D Slices Through 3-D Geometry
% This example shows how to obtain plots from 2-D slices through a 3-D
% geometry.
%
% The problem is
%
% $$\frac{\partial u}{\partial t} - \Delta u = f$$
%
% on a 3-D slab with dimensions 10-by-10-by-1, where $u = 0$ at time |t =
% 0|, boundary conditions are Dirichlet, and
%
% $$f \left( x,y,z \right) = 1 + y + 10z^2$$
%
%% Set Up and Solve the PDE
% Define a function for the nonlinear |f| coefficient in the syntax as
% given in
% <http://www.mathworks.com/help/pde/ug/f-coefficient-for-specifycoefficients.html
% f Coefficient for specifyCoefficients>.
%
%  function bcMatrix = myfffun(region,state)
%  
%  bcMatrix = 1+10*region.z.^2+region.y;
%
% Import the geometry and examine the face labels.
model = createpde;
g = importGeometry(model,'Plate10x10x1.stl');
pdegplot(g,'FaceLabels','on','FaceAlpha',0.5)
%%
% The faces are numbered 1 through 6.
%
% Create the coefficients and boundary conditions.
c = 1;
a = 0;
d = 1;
f = @myfffun;
specifyCoefficients(model,'m',0,'d',d,'c',c,'a',a,'f',f);

applyBoundaryCondition(model,'dirichlet','face',1:6,'u',0);
%%
% Set a zero initial condition.
setInitialConditions(model,0);
%%
% Create a mesh with sides no longer than 0.3.
generateMesh(model,'Hmax',0.3);
%%
% Set times from 0 through 0.2 and solve the PDE.
tlist = 0:0.02:0.2;
results = solvepde(model,tlist);
%% Plot Slices Through the Solution
% Create a grid of |(x,y,z)| points, where |x = 5|, |y| ranges from 0
% through 10, and |z| ranges from 0 through 1. Interpolate the solution to
% these grid points and all times.
yy = 0:0.5:10;
zz = 0:0.25:1;
[YY,ZZ] = meshgrid(yy,zz);
XX = 5*ones(size(YY));
uintrp = interpolateSolution(results,XX,YY,ZZ,1:length(tlist));
%%
% The solution matrix |uintrp| has 11 columns, one for each time in
% |tlist|. Take the interpolated solution for the second column, which
% corresponds to time 0.02.
usol = uintrp(:,2);
%%
% The elements of |usol| come from interpolating the solution to the |XX|,
% |YY|, and |ZZ| matrices, which are each 5-by-21, corresponding to
% |z-by-y| variables. Reshape |usol| to the same 5-by-21 size, and make a
% surface plot of the solution. Also make surface plots corresponding to
% times 0.06, 0.10, and 0.20.
figure
usol = reshape(usol,size(XX));
subplot(2,2,1)
surf(usol)
title('t = 0.02')
zlim([0,1.5])
xlim([1,21])
ylim([1,5])

usol = uintrp(:,4);
usol = reshape(usol,size(XX));
subplot(2,2,2)
surf(usol)
title('t = 0.06')
zlim([0,1.5])
xlim([1,21])
ylim([1,5])

usol = uintrp(:,6);
usol = reshape(usol,size(XX));
subplot(2,2,3)
surf(usol)
title('t = 0.10')
zlim([0,1.5])
xlim([1,21])
ylim([1,5])

usol = uintrp(:,11);
usol = reshape(usol,size(XX));
subplot(2,2,4)
surf(usol)
title('t = 0.20')
zlim([0,1.5])
xlim([1,21])
ylim([1,5])