-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathIGA2D513.m
160 lines (151 loc) · 4.81 KB
/
IGA2D513.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
% 2DIA solves a 2D problem using Isogeometric Analysis.
% Input:
% n: defined accordingly to the knot vector X;
% p: degree of the NURBS surface defined in direction x;
% X: knot vector in direction x;
% m: defined accordingly to the knot vector Y;
% q: degree of the NURBS surface defined in direction y;
% Y: knot vector in direction y;
% Pw: weighted control points.
% Output:
%function [S] = IA2D(s, f, a_1)
clear all;
% Load coefficients for the integration of the stiffness terms.
load wxi_p4_q4_kXi0_kEta0_4elementsXi_4elementsEta;
%load wp_p4_q4_k5_l5_rXi0_rEta0_TolX-5_TolFun-5
wp_stiffness = wxi;
% Load coefficients for the integration of the force terms.
%load wxi_p2_k0_4elements
load wp_p2_q2_k4_l4_rXi1_rEta1;
wp_force = wxi;
% Definition of the model.
% ========================
%[n, p, Xi, m, q, Eta, P] = defineSquareParametric();
[n, p, Xi, m, q, Eta, P] = defineBsplinePlateHole();
%[n, p, Xi, m, q, Eta, P] = defineToroidalSurface();
%[n, p, Xi, m, q, Eta, P] = defineExperimental();
% Definition of the PDE.
% ======================
f = inline('1', 'x', 'y');
a_1 = inline('1', 'x', 'y');
g_N = inline('x', 'x', 'y');
% Mesh refinement.
% ================
for i = 0.25:0.25:0.75
k = findSpan(n, p, i, Xi);
if Xi(k+1) ~= i
[n, Xi, m, Eta, P] =...
computeSurfKnotInsertion(n, p, Xi, m, q, Eta,...
P, 0, i, k, 0, 1);
end
k = findSpan(m, q, i, Eta);
if Eta(k+1) ~= i
[n, Xi, m, Eta, P] =...
computeSurfKnotInsertion(n, p, Xi, m, q, Eta,...
P, 1, i, k, 0, 1);
end
end
% Boundary conditions.
% ====================
% Connectivity matrix.
C = zeros(n+1, m+1);
% Setting nodes with Dirichlet boundary conditions applied:
% 0: no constraint is applied;
% 1: means Dirichlet condition is applied;
% 2: means Neumann condition is applied.
C(:, 1) = 2;
C(1, :) = 1;
C(n+1, :) = 1;
C(:, m+1) = 1;
% Setting the values matrix.
D = zeros(n+1, m+1);
% Setting nodes with Dirichlet boundary conditions applied.
D(:, 1) = 0;
D(1, :) = 0;
D(n+1, :) = 1;
D(:, m+1) = 2;
% Setting the edges with Neumann boundary conditions in the parametric
% domain.
N = [1, 0, 0, 0];
% Computation of the matrices.
% ============================
% Preallocation of the stiffness matrix and of the force vector.
S(sum(sum(C==0)), sum(sum(C==0))) = 0;
F(sum(sum(C==0))) = 0;
% Indices of the matrices.
a = 0;
b = 0;
for ki = 0:n
for li = 0:m
printf("Working: %f%%\n", (n*ki + li)/(n*m)*100)
% ki and li are the indices of the first B-spline function.
% If the node is a Dirichlet node, then skip to the next
% iteration.
if C(ki+1, li+1) == 1, continue; end;
% Integration of the homogeneous part of the force vector.
F(a+1) = computeForceIntegralBsplines02...
(n, p, Xi, m, q, Eta, P, ki, li, f, g_N, a_1, wp_force, N);
% Iteration on the second B-spline basis function.
for kj = 0:n
for lj = 0:m
% If the node belongs to the set of Dirichlet nodes then
% it is taken into account only for the force vector.
if C(kj+1, lj+1) == 1
% If the Dirichlet condition is homogeneous then
% it is convenient to short-circuited so that
% the integral is not computed.
if D(kj+1, lj+1) ~= 0
% The term is subtracted from the force vector
% term.
F(a+1) = F(a+1)-D(kj+1, lj+1).*...
computeStiffnessIntegralBsplines02...
(n, p, Xi, m, q, Eta, P, ki, li, kj, lj,...
wp_stiffness, a_1);
end
continue;
end
% Skip the terms which can be computed by exploiting
% symmetry.
if b < a, b = b+1; continue; end
ki, kj, li, lj
% Stiffness term.
S(a+1, b+1) = computeStiffnessIntegralBsplines02...
(n, p, Xi, m, q, Eta, P, ki, li, kj, lj,...
wp_stiffness, a_1);
b = b+1;
end
end
a = a+1;
b = 0;
end
end
% Complete the lower triangle (symmetry).
for i = 1:length(S(1, :))
for j = 1:i
S(i, j) = S(j, i);
end
end
% Solution of the linear system.
% ==============================
S
F = F'
Uv = linsolve(S, F)
% Creation of the solution function.
% ==================================
a = 0;
U = zeros(size(P(:, :, 1)));
for ki = 0:n
for li = 0:m
if C(ki+1, li+1) == 1, continue; end;
U(ki+1, li+1) = Uv(a+1);
a = a+1;
end
end
U = U+D;
P(:, :, 3) = U;
colormap("jet");
drawBsplineSurf(n, p, Xi, m, q, Eta, P);
axis([-4, 0, 0, 4]);
view([-26, 18]);
shading interp;
colorbar;