forked from lyc102/ifem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathachol.m
61 lines (58 loc) · 1.42 KB
/
achol.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
function [L,p,Ac] = achol(A)
%% ACHOL approximated Cholosiky factorization
%
% L: lower triangular matrix
% p: permutation s.t. L is an approximated factorization of A(p,p)
% p(1:Nf) is the index of fine nodes
N = size(A,1);
p = zeros(N,1);
%% Multilvel factorization
level = ceil(log(N)/log(2))+1;
% level = 3;
i = cell(level,1);
j = cell(level,1);
s = cell(level,1);
isM = cell(level,1);
cpointer = 1;
pc = (1:N)'; % global index;
for k = 1:level-1
% find Af and Afc
[isM{k},As] = mis(A);
[i{k},j{k},s{k},A] = af(A,As,isM{k});
% map the index to global index of nodes
i{k} = pc(i{k});
j{k} = pc(j{k});
% record permutation
endpointer = cpointer + sum(isM{k})-1;
p(cpointer:endpointer) = pc(isM{k});
pc = pc(~isM{k}); % global indx of coarse nodes
cpointer = endpointer+1;
% exit the multilevel decomposition if A is empty
if isempty(A)
level = k;
break
end
end
p(cpointer:N) = pc;
% coarest level
Ac = A; % coarest grid matrix
if ~isempty(Ac)
Nc = size(Ac,1);
i{level} = pc((1:Nc)');
j{level} = pc((1:Nc)');
s{level} = sqrt(diag(Ac));
end
% Lc = ichol(Ac);
% [ic,jc,sc] = find(Lc);
% i{level} = pc(ic);
% j{level} = pc(jc);
% s{level} = sc;
%% Merge multilevel factorization into a big one
% map the index to permuated one
pinv(p) = (1:N)';
ii = pinv(cell2mat(i));
jj = pinv(cell2mat(j));
ss = cell2mat(s);
% generate L
L = sparse(ii,jj,ss,N,N);
% R = L';