-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectElectrostatics.m
More file actions
52 lines (43 loc) · 1.14 KB
/
Copy pathProjectElectrostatics.m
File metadata and controls
52 lines (43 loc) · 1.14 KB
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
%% ProjectElectrostatics - Solve electrostatic potential on a scattering geometry
clear all;
close all;
Config();
%% Setup
functPlot = @(x) abs(x);
Sys.pOrd = 4;
Sys.hOrd = 1;
Mesh = IOrPoly('ModelScatteringDD', 'q34a0.01A', Sys.hOrd, 1);
Mesh.BC.Dir = [1 133];
Sys.V{1} = 1;
Sys.V{2} = 0;
[Sys, Mesh] = AssembLin(Sys, Mesh);
%% Build linear system with Dirichlet BCs
Sys.A = Sys.S;
Sys.b = 0 * Sys.fs;
if isfield(Sys, 'Dir')
for ibc = 1:length(Sys.Dir)
Sys.b = Sys.b - Sys.A(:, Sys.Dir{ibc}) ...
* ones(length(Sys.Dir{ibc}), 1) * Sys.V{ibc};
end
for ibc = 1:length(Sys.Dir)
Sys.b(Sys.Dir{ibc}) = Sys.V{ibc};
Sys.A(Sys.Dir{ibc}, :) = 0;
Sys.A(:, Sys.Dir{ibc}) = 0;
Sys.A(Sys.Dir{ibc}, Sys.Dir{ibc}) = eye(length(Sys.Dir{ibc}));
end
end
%% Solve
tic
Sys.u = Sys.A \ Sys.b;
fprintf('Direct solver: %g s\n', toc);
%% Postprocessing
IOwVTK(Sys, Mesh, 'volt');
figure;
pdeplot(Mesh.refNode.', [], Mesh.refEle.', ...
'xydata', (functPlot(Sys.u)), ...
'zdata', (functPlot(Sys.u)), ...
'mesh', 'off', ...
'colormap', 'jet', 'xygrid', 'off');
axis equal;
camlight left;
lighting phong;