-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathassign_tractionBC2.m
74 lines (63 loc) · 2.98 KB
/
assign_tractionBC2.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
function residual_traction = assign_tractionBC2(residual_traction, b_natural, traction_f, time, boundary)
global gcoord
ndof = 2;
residual_traction(:) = 0;
if nargin <= 4
boundary = 'horizontal';
end
if strcmp(boundary, 'horizontal')
temp = [gcoord(b_natural, 1), b_natural];
temp = sortrows(temp);
b_natural = temp(:, 2);
for i = 1:length(b_natural)
if i==1
a = gcoord(b_natural(1), 1);
b = gcoord(b_natural(2), 1);
fun = @(x)((b-x)/(b-a).*traction_f(x, time));
residual_traction(ndof*b_natural(1)-1:ndof*b_natural(1)) = integral(fun, a, b,'ArrayValued',true);
elseif i == length(b_natural)
a = gcoord(b_natural(end-1), 1);
b = gcoord(b_natural(end), 1);
fun = @(x)((x-a)/(b-a).*traction_f(x, time));
residual_traction(ndof*b_natural(end)-1:ndof*b_natural(end)) = integral(fun, a, b, 'ArrayValued',true);
else
a = gcoord(b_natural(i-1), 1);
b = gcoord(b_natural(i+1), 1);
c = gcoord(b_natural(i), 1);
fun = @(x)((x-a)/(c-a).*traction_f(x, time));
residual_traction(ndof*b_natural(i)-1:ndof*b_natural(i)) = ...
residual_traction(ndof*b_natural(i)-1:ndof*b_natural(i)) + integral(fun, a, c, 'ArrayValued',true);
fun = @(x)((b-x)/(b-c).*traction_f(x, time));
residual_traction(ndof*b_natural(i)-1:ndof*b_natural(i)) = ...
residual_traction(ndof*b_natural(i)-1:ndof*b_natural(i)) + integral(fun, c, b, 'ArrayValued',true);
end
end
elseif strcmp(boundary, 'vertical')
temp = [gcoord(b_natural, 2), b_natural]; % 2 columns
temp = sortrows(temp);
b_natural = temp(:, 2);
for i = 1:length(b_natural)
if i==1
a = gcoord(b_natural(1), 2);
b = gcoord(b_natural(2), 2);
fun = @(x)((b-x)/(b-a).*traction_f(x, time));
residual_traction(ndof*b_natural(1)-1:ndof*b_natural(1)) = integral(fun, a, b, 'ArrayValued',true);
elseif i == length(b_natural)
a = gcoord(b_natural(end-1), 2);
b = gcoord(b_natural(end), 2);
fun = @(x)((x-a)/(b-a).*traction_f(x, time));
residual_traction(ndof*b_natural(end)-1:ndof*b_natural(end)) = integral(fun, a, b, 'ArrayValued',true);
else
a = gcoord(b_natural(i-1), 2);
b = gcoord(b_natural(i+1), 2);
c = gcoord(b_natural(i), 2);
fun = @(x)((x-a)/(c-a).*traction_f(x, time));
residual_traction(ndof*b_natural(i)-1:ndof*b_natural(i)) = ...
residual_traction(ndof*b_natural(i)-1:ndof*b_natural(i)) + integral(fun, a, c, 'ArrayValued',true);
fun = @(x)((b-x)/(b-c).*traction_f(x, time));
residual_traction(ndof*b_natural(i)-1:ndof*b_natural(i)) = ...
residual_traction(ndof*b_natural(i)-1:ndof*b_natural(i)) + integral(fun, c, b, 'ArrayValued',true);
end
end
end
end