-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_sparse_ind.m
116 lines (96 loc) · 3.4 KB
/
get_sparse_ind.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
function [gradG,resG] = get_spars_ind(gradG,resG,gradGlf,gradGlm,...
resGlf,resGlm,ne,econn,Jr,Jf,BC)
% Determines the indices needed for the sparse treatment of gradG
indflagvec = zeros((5*nnode+1)*(5*nnode),1);
nentry = sum(indflagvec);
trow = zeros(nentry,1); tcol = trow; gradGvec = trow;
for ie = 1:nentry
trow(ie) = irow;
tcol(ie) = icol;
end
for iBC=1:nBC
% Only care about the matching BC here
if (BC{iBC,1}(1)=='m')
mBC = [mBC iBC];
end
end
nacc = 0;
for ne=1:nelem
mflag = 0;
for iBC=1:length(mBC)
% Only care about the matching BC here
if (fastintersect(ne,BC{iBC,2}))
mflag = 1;
end
end
if (solver.mesh.tag(ne)) % solid
for nna=1:npe
A = econn(nna);
Rind = 5*A-4:5*A-3; rind = 2*nna-1:2*nna;
Pind = 5*A-2; % pressure index
% Set pressure to 0 in internal solid nodes
pflag = 1;
% If matching BC exists for this element
if (mflag)
% Check node list for BC
if (fastintersect(A,BC{iBC,3}))
% Do not touch pressure eq for a matching node
pflag = 0;
end
end
% Modify pressure eq if needed
if (pflag)
nacc = nacc+1;
trow(nacc) = Pind;
tcol(nacc) = Pind;
end
% Global tangent matrix
for nnb=1:npe
for ii = 1:2
for jj = 1:2
nacc = nacc+1;
trow(nacc) = Rind(ii);
tcol(nacc) = Cind(jj);
end
end
end
% Mesh motion indices and residual vector
MindA = 5*A-1:5*A;
% Set mesh motion equal to solid/fluid solution at every solid node
for nn=1:2
nacc = nacc+1;
trow(nacc) = MindA(ii);
tcol(nacc) = MindA(ii);
trow(nacc) = MindA(ii);
tcol(nacc) = MindA(ii)-3;
end
end
else % fluid
for nna=1:npe
A = econn(nna);
Rindf = 5*A-4:5*A-2; rindf = 3*nna-2:3*nna;
Rindm = 5*A-1:5*A ; rindm = 2*nna-1:2*nna;
% If matching BC exists for this element
if (mflag)
% Check node list for BC
if (fastintersect(A,BC{iBC,3}))
% Do not allow mesh eq's to contribute at matching BC
Rindm = []; rindm = [];
end
end
% Global residual vector
resG(Rindf) = resG(Rindf) + resGlf(rindf)*Jf;
resG(Rindm) = resG(Rindm) + resGlm(rindm)*Jr;
for nnb=1:npe
B = econn(nnb);
Cindf = 5*B-4:5*B-2; cindf = 3*nnb-2:3*nnb;
Cindm = 5*B-1:5*B ; cindm = 2*nnb-1:2*nnb;
% Global tangent matrix
gradG(Rindf,Cindf) = gradG(Rindf,Cindf) ...
+ gradGlf(rindf,cindf)*Jf;
gradG(Rindm,Cindm) = gradG(Rindm,Cindm) ...
+ gradGlm(rindm,cindm)*Jr;
for nn=1:3
end
end
end