-
Notifications
You must be signed in to change notification settings - Fork 0
/
regu_evanesc.m
213 lines (181 loc) · 6.9 KB
/
regu_evanesc.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
% 05/09/2016
% Algo de régularisation evanescente
close all;
clear all;
addpath(genpath('./tools'))
% Parameters
E = 70000; % MPa : Young modulus
nu = 0.3; % Poisson ratio
fscalar = 1; % N.mm-1 : Loading on the plate
niter = 20;
mu = .01; % Regularization parameter
br = .0; % noise
erc = 0; % use the Erc functionnal
% Boundary conditions
% first index : index of the boundary
% second index : 1=x, 2=y
% third : value
% [0,1,value] marks a dirichlet regularization therm on x
dirichlet = [4,1,0;
4,2,0];
neumann = [1,2,fscalar;
2,1,fscalar;
3,2,fscalar];
% Import the mesh
[ nodes,elements,ntoelem,boundary,order ] = readmesh( 'meshes/plate.msh' );
nnodes = size(nodes,1);
% find the nodes in the corners and suppress the element :
xmax = max(nodes(:,1));
xmin = min(nodes(:,1));
ymax = max(nodes(:,2));
ymin = min(nodes(:,2));
no1 = findNode(xmin, ymin, nodes, 1e-5);
no2 = findNode(xmax, ymin, nodes, 1e-5);
no3 = findNode(xmax, ymax, nodes, 1e-5);
no4 = findNode(xmin, ymax, nodes, 1e-5);
% Suppress some nodes from the boundaries
boundaryp1 = suppressBound( boundary, [no3;no4], 3 );
boundaryp1 = suppressBound( boundaryp1, [no1;no2], 1 );
% Then, build the stiffness matrix :
[K,C,nbloq] = Krig (nodes,elements,E,nu,order,boundary,dirichlet);
Kinter = K(1:2*nnodes, 1:2*nnodes);
M = mass_mat(nodes, elements);
% Some indices
[node2b4, b2node4] = mapBound(4, boundaryp1, nnodes);
[node2b3, b2node3] = mapBound(3, boundaryp1, nnodes);
[node2b1, b2node1] = mapBound(1, boundaryp1, nnodes);
[node2b2, b2node2] = mapBound(2, boundaryp1, nnodes);
b2node12 = [b2node1;b2node2];
b2node123 = [b2node1;b2node2;b2node3]; % nodes
bbound = [2*b2node123-1; 2*b2node123]; % dof
bbred = [2*b2node1-1; 2*b2node2-1; 2*b2node1; 2*b2node2];
nbound = size(bbound,1);
bbzero = [2*b2node4-1; 2*b2node4]; % dof with Dirichlet BC
% The right hand side :
f = loading(nbloq,nodes,boundary,neumann);
% Solve the problem :
uin = K\f;
% Extract displacement and Lagrange multiplicators :
uref = uin(1:2*nnodes,1);
lagr = uin(2*nnodes+1:end,1);
urefb = ( 1 + br*randn(2*nnodes,1) ) .* uref;
frefb = f(1:2*nnodes);
sigma = stress(uref,E,nu,nodes,elements,order,1,ntoelem);
plotGMSH({uref,'Vect_U';sigma,'stress'}, elements, nodes, 'reference');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Computation of the inner stiffness
dirichlet1 = [4,1,0;4,2,0];
[K1,C1,nbloq1,node2c1,c2node1] = Krig (nodes,elements,E,nu,order,boundary,dirichlet1);
neumann1 = []; % There is no alone Neumann
f1 = loading( nbloq, nodes, boundary, neumann1 );
%% Schur operator
[ S, b, map ] = schurComp2( Kinter, f1(1:2*nnodes), bbound, bbzero );
[ Sr, ~ , ~ ] = schurComp2( Kinter, f1(1:2*nnodes), bbred, bbzero );
Sre = zeros(2*nnodes); Sre(bbred,bbred) = Sr; Sre = Sre(bbound,bbound); % Extend Sr on Gamma
eyeR = zeros(2*nnodes); eyeR(bbred,bbred) = 1; eyeR = eyeR(bbound,bbound); % 1 on R, 0 elsewhere
Dr = inv(Sr); Dre = zeros(2*nnodes); Dre(bbred,bbred) = Dr; Dre = Dre(bbound,bbound);
D = inv(S);
error = zeros(niter,1);
residual = zeros(niter,1);
regulari = zeros(niter,1);
%% Mass matrices
Mr = bMass_mat(nodes, boundary, [2;1]);
Mrt = 1/E*Mr; % Ideally 1/EL
M = bMass_mat(nodes, boundary, [3;2;1]);
Mt = 1/E*M;
Mm = bMass_mat(nodes, boundary, 3);
% Debug
%M = eye(2*nnodes); M([2*b2node3-1,2*b2node3],[2*b2node3-1,2*b2node3]) = 0;
%Mr = eye(2*nnodes);
%Mt = 1/E*M;
%Mrt = 1/E*Mr;
% Extract coords
Mr = Mr(bbound, bbound);
Mrt = Mrt(bbound, bbound);
M = M(bbound, bbound);
Mt = Mt(bbound, bbound);
Mm = Mm(bbound, bbound);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Evanescent regularization method
Itere = zeros( 2*nnodes, 1 );
Iteref = zeros( 2*nnodes, 1 );
% Compute errors
error(1) = (Itere(bbound)-uref(bbound))'*Mm*...
(Itere(bbound)-uref(bbound)) / (uref(bbound)'*Mm*uref(bbound));
residual(1) = (Itere(bbound)-urefb(bbound))'*Mr*...
(Itere(bbound)-urefb(bbound)) / (uref(bbound)'*Mr*uref(bbound));
regulari(1) = (Itere(bbound)-Itere(bbound))'*M*...
(Itere(bbound)-Itere(bbound)) / (uref(bbound)'*M*uref(bbound));
% Build the fat matrix
if erc == 1
Atot = [zeros(size(M)), -eyeR-mu*eye(size(M,1)), S'
-eyeR-mu*eye(size(M,1)), zeros(size(M)), -eye(size(M,1),size(S,1))
S, -eye(size(S,1), size(M,1)), zeros(size(M))];
else
Atot = [Mr+mu*M, zeros(size(M)), S'
zeros(size(M)), Mrt+mu*Mt, -eye(size(M,1),size(S,1))
S, -eye(size(S,1), size(M,1)), zeros(size(M))];
end
disp( [ 'Log of the cond of the problem :', num2str(log10(cond(Atot))) ] )
plot(log10(abs(eig(Atot))));
% plot(eig(Atot));
figure;
for i = 2:niter
% Rhs
if erc == 1
btot = [-Sre*urefb(bbound) - mu*S*Itere(bbound)
-Dre*frefb(bbound) - mu*D*Iteref(bbound)
b]; % Don't forget to add Kinter*uimp if needed
else
btot = [Mr*urefb(bbound) + mu*M*Itere(bbound)
Mrt*frefb(bbound) + mu*Mt*Iteref(bbound)
b]; % Don't forget to add Kinter*uimp if needed
end
% Solve and extract the relevant parts
Iterep = Itere;
xtot = Atot\btot;
Itere(bbound) = xtot(1:nbound);
Iteref(bbound) = xtot(nbound+1:2*nbound);
% Compute errors
error(i) = (Itere(bbound)-uref(bbound))'*Mm*...
(Itere(bbound)-uref(bbound)) / (uref(bbound)'*Mm*uref(bbound));
residual(i) = (Itere(bbound)-urefb(bbound))'*Mr*...
(Itere(bbound)-urefb(bbound)) / (uref(bbound)'*Mr*uref(bbound));
%regulari(i) = (Itere(bbound)-Iterep(bbound))'*M*...
% (Itere(bbound)-Iterep(bbound)) / (uref(bbound)'*M*uref(bbound));
regulari(i) = Itere(bbound)'*M*Itere(bbound) / (uref(bbound)'*M*uref(bbound));
end
hold on
plot(log10(error),'Color','blue')
plot(log10(residual),'Color','red')
legend('error (log)','residual (log)')
figure;
% L-curve :
%loglog(residual,regulari);
%figure
%%%%
%% Final problem : compute u
% DN problem
dirichlet = [4,1,0;4,2,0;
3,1,0;3,2,0;
1,1,0;1,2,0;
2,1,0;2,2,0];
neumann = [];
[K,C,nbloq] = Krig (nodes,elements,E,nu,order,boundary,dirichlet);
fdir1 = dirichletRhs(urefb, 1, C, boundary);
fdir2 = dirichletRhs(urefb, 2, C, boundary);
fdir3 = dirichletRhs(Itere, 3, C, boundary);
usoli = K \ assembleDirichlet( [fdir1+fdir3,fdir2] );
usol = usoli(1:2*nnodes,1);
fsol = Kinter*usol;
hold on;
plot(frefb(2*b2node3), 'Color', 'red')
plot(fsol(2*b2node3), 'Color', 'blue')
figure;
hold on;
plot(uref(2*b2node3), 'Color', 'red')
plot(usol(2*b2node3), 'Color', 'blue')
total_error = norm(usol-uref)/norm(uref);
% Compute stress :
sigma = stress(usol,E,nu,nodes,elements,order,1,ntoelem);
plotGMSH({usol,'U_vect';sigma,'stress'}, elements, nodes, 'solution');