-
Notifications
You must be signed in to change notification settings - Fork 4
/
runme.m
88 lines (64 loc) · 1.63 KB
/
runme.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
clear all;
clc;
close all;
%% Initialize a two component PDE model.
model = createpde();
%% Computational domain, defined by polygon.
gd = [2; 4
0; 1; 1; 0;
0; 0; 1; 1;
];
[dl, bt] = decsg(gd);
% Plot the computational domain.
figure(1);
pdegplot(dl, 'EdgeLabels', 'on', 'FaceLabels', 'on')
xlabel("x");
ylabel("y");
axis equal
%% Attach the computational domain to the PDE model.
geometryFromEdges(model, dl);
%% Specify the kind of model from the generic formula.
specifyCoefficients(model, ...
'm', 0, ...
'd', 1, ...
'c', 1, ...
'a', 0, ...
'f', 0 ...
);
%% Boundary conditions
applyBoundaryCondition(model, ...
'dirichlet', ...
'edge', [2, 3], ...
'u', 0);
applyBoundaryCondition(model, ...
'dirichlet', ...
'edge', [4], ...
'u', 1);
applyBoundaryCondition(model, ...
'neumann', ...
'edge', [1], ...
'g', 0, ...
'q', 0);
%% Initial conditions.
setInitialConditions(model, @fn_u0);
%% Generate mesh.
generateMesh(model, 'Hmax', 0.1);
figure(2)
pdeplot(model)
axis equal
%% Time domain
t = 0:10:100;
%% Solve the PDE
result = solvepde(model, t);
u = result.NodalSolution;
%% Visualize the solution
fig = figure(3);
for i=1:length(t)
pdeplot(model, 'XYData', u(:, i), 'ZData', u(:,i), 'FaceAlpha', 0.5, 'ColorMap', 'default', 'Mesh', 'on')
title("Poisson");
xlabel("x");
ylabel("y");
zlabel("u(x,y,t)");
drawnow limitrate;
F(i)=getframe(fig);
end