-
Notifications
You must be signed in to change notification settings - Fork 1
/
global_assemble.m
52 lines (45 loc) · 1.47 KB
/
global_assemble.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
function [gradG,resG] = global_assemble(gradG,resG,gradGl,resGl,econn,J,BC)
% Assembles the global stiffness matrix and force vector
% based on the element information supplied.
npe = length(econn);
for nna=1:npe
A = econn(nna);
Rind = 3*A-2:3*A; rind = 3*nna-2:3*nna;
% Boundary conditions
BCflag = zeros(3,1);
[nBC,~] = size(BC);
for iBC=1:nBC
% Check node list for BC
if (fastintersect(A,BC{iBC,3}))
% If dirichlet, allow no change to node value
if (BC{iBC,1}(1)=='d')
if (BC{iBC,1}(2)=='x')
ind = 3*A-2;
BCflag(1) = 1;
elseif (BC{iBC,1}(2)=='y')
ind = 3*A-1;
BCflag(2) = 2;
else % (BC{iBC,1}(2)=='p')
ind = 3*A;
BCflag(3) = 3;
end
resG(ind) = 0;
gradG(ind,:) = 0;
gradG(ind,ind) = 1;
end
end
end
% Remove zero values from BCflag
BCf1 = BCflag(BCflag~=0);
% According to BCflag, skip certain indices
Rind(BCf1) = []; rind(BCf1) = [];
% Global force vector
resG(Rind) = resG(Rind) + resGl(rind)*J;
for nnb=1:npe
B = econn(nnb);
Cind = 3*B-2:3*B; cind = 3*nnb-2:3*nnb;
% Global stiffness matrix
gradG(Rind,Cind) = gradG(Rind,Cind) ...
+ gradGl(rind,cind)*J;
end
end