-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFEmesh2Fiedler.m
36 lines (36 loc) · 1.16 KB
/
FEmesh2Fiedler.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
%%
%%%%%%%%%%%%%%%%%%%%
%%% Example Code %%%
%%%%%%%%%%%%%%%%%%%%
%% Load FE mesh
clc
clear
load('FEmesh.mat')
%% Create Graph from FEM
st = zeros(size(elements,1)*8,2);
for i=1:size(elements,1)
st(8*i-7:8*i,:) = [elements(i,1),elements(i,2);
elements(i,2),elements(i,3);
elements(i,3),elements(i,4);
elements(i,4),elements(i,1);
elements(i,2),elements(i,1);
elements(i,3),elements(i,2);
elements(i,4),elements(i,3);
elements(i,1),elements(i,4)];
end
st = unique(st,'rows');
G = digraph(st(:,1),st(:,2));
%% Calculate the Fiedler Vector
Adj = adjacency(G); % Adjacency Matrix
Degree = zeros(size(Adj)); % Degree Matrix
Degree(logical(eye(length(sum(Adj))))) = sum(Adj);
L = Degree - Adj; % The Laplacian
[e,v] = eigs(sparse(L),2,'sm', struct('disp',0));
nodes_3d = [nodes,e(:,2)];
%% Plot
figure(1)
patch('Faces',elements,'Vertices',nodes_3d(:,2:4), ...
'FaceVertexCData',nodes_3d(:,4), ...
'FaceColor','interp','edgecolor','None')
view(30,30)
axis off, axis on, grid on