forked from lydia1895/PMM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PMM_multi.m
executable file
·299 lines (255 loc) · 9.33 KB
/
PMM_multi.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
function [eta_R, eta_T, Stotal, ud_PMM, kz1v, kz2v,...
pplus, pminus, derx, eps, M, gamma_total, gamma_d1,...
gamma_norm, EH, gamma_sorted, W, u2d0_FMM,gzero,gzero_norm,...
gamma0,gamma_num] =...
PMM_multi(int_P1_Q1,int_P1_Q2, fx_coef, fy_coef, Ex0, Ey0, lambda, theta, phi,...
N_FMM, h, L, refIndices, alpha_ref, beta_ref,...
b_x1, b_x2, N_intervals_x, N_intervals_y, N_basis_x, N_basis_y,...
Dx, Dy, hx, hy, eps_total, mu_total,verbose)
N_total_x = sum(N_basis_x); %total number of basis functions
N_total_y = sum(N_basis_y); %total number of basis functions
N_total_x3 = N_total_x - N_intervals_x; %number of basis functions in "third" basis
N_total_y3 = N_total_y - N_intervals_y;
N_total_3 = N_total_x3*N_total_y3;
n1 = refIndices(1);
n2 = refIndices(2);
k0 = 2*pi/lambda;
alpha0 = k0*n1*sin(theta)*cos(phi);
beta0 = k0*n1*sin(theta)*sin(phi);
gamma0 = k0*n1*cos(theta);
%title = 'plot things'
%{
x_full = PMM_graph(E_PMM, La, alpha0, beta0, alpha_ref, beta_ref,...
b_x1, b_x2, N_intervals_x, N_intervals_y, N_basis_x, N_basis_y, Nx, nx, Ny, ny,...
ax, ay);
%}
gammaminus = zeros(2*N_total_3, L);
pplus = zeros(2*N_total_3, 2*N_total_3, L);
pminus = zeros(2*N_total_3, 2*N_total_3, L);
eps = zeros(N_total_3, N_total_3,L);
derx = zeros(N_total_x3, N_total_x3,L);
M = zeros(4*N_total_3, 4*N_total_3,L);
M31 = zeros(N_total_3, N_total_3,L);
gamma_norm = zeros(4*N_total_3,4*N_total_3,L);
gamma_sorted = zeros(4*N_total_3,4*N_total_3,L);
EH = zeros(4*N_total_3, 4*N_total_3,L);
W = zeros(4*N_total_3, 4*N_total_3, L);
gamma_total = zeros(N_total_3,4,L);
gamma_d1 = zeros(N_total_3,L);
gamma_u1 = zeros(N_total_3,L);
for i=1:L
[gamma_normt, EHt, gamma_sortedt, Wt, pplust, pminust,...
epst, Mt, M31t, gamma_minus_t, gamma_total_t, gamma_d1_t, gamma_u1_t] =...
PMM_gamma(alpha_ref, beta_ref, k0, alpha0, beta0, h(i),...
N_intervals_x, N_intervals_y, N_basis_x, N_basis_y, Dx, Dy, hx, hy,...
eps_total(:,:,:,i), mu_total(:,:,:,i),verbose);
gammaminus(:,i) = gamma_minus_t;
gamma_norm(:,:,i) = gamma_normt;
EH(:,:,i) = EHt;
gamma_sorted(:,:,i) = gamma_sortedt;
W(:,:,i) = Wt;
pplus(:,:,i) = pplust;
pminus(:,:,i) = pminust;
eps(:,:,i) = epst;
M(:,:,i) = Mt;
M31(:,:,i) = M31t;
gamma_total(:,:,i) = gamma_total_t;
gamma_d1(:,i) = gamma_d1_t;
gamma_u1(:,i) = gamma_u1_t;
end
%{
%%%%this is wrong, check out indices for Stotal!!!!!!!!!!!!!!!!!!
Smin1 = eye(4*NN,4*NN);
Rudmin1 = zeros(2*NN,2*NN);
Rud0 = new_recursion_refl_only(Rudmin1, W(:,:,1), W(:,:,2),...
eye(2*NN,2*NN), pminus(:,:,1));
Rudtemp = Rud0;
if L>1
for i=1:(L-1)
Rudi = new_recursion_refl_only(Rudtemp, W(:,:,i), W(:,:,i+1),...
pplus(:,:,i), pminus(:,:,i+1));
Rudtemp = Rudi;
end
end
Rudtotal = new_recursion_refl_only(Rudtemp, W(:,:,L-1), W(:,:,L),...
pplus(:,:,L), eye(2*NN,2*NN));
%}
%S-matrix propagation
Smin1 = eye(4*N_total_3,4*N_total_3);
Stemp = Smin1;
for i=1:(L-1)
Si = new_recursion(Stemp, W(:,:,i), W(:,:,i+1), pplus(:,:,i), pminus(:,:,i+1));
Stemp = Si;
end
Stotal = Stemp;
%{
%%%%%%%%%%from FMM program - for comparison
Smin1 = eye(4*NN,4*NN);
S0 = new_recursion(Smin1, K2, W(:,:,1), eye(2*NN,2*NN), pminus(:,:,1), N);
Stemp = S0;
if L>1
for i=1:(L-1)
Si = new_recursion(Stemp, W(:,:,i), W(:,:,i+1), pplus(:,:,i), pminus(:,:,i+1), N);
Stemp = Si;
end
end
Stotal = new_recursion(Stemp, W(:,:,L), K1, pplus(:,:,L), eye(2*NN,2*NN), N);
%}
if (verbose>5)
title = 'derive incident coefficients'
end
gamma00 = gamma0
%size_gammaminus = size(gammaminus)
gammaminus_new = sort(gammaminus(:,L));
%size_gammaminus_new = size(gammaminus_new(:,L))
[diff_gamma,numbers_diff_gamma] = sort(abs(gammaminus(:,L)+gamma0));
q01 = numbers_diff_gamma(1);
q02 = numbers_diff_gamma(2);
diff_gamma_1 = [diff_gamma(1); diff_gamma(1)/gamma0]
diff_gamma_2 = [diff_gamma(2); diff_gamma(2)/gamma0]
diff_gamma_3 = [diff_gamma(3); diff_gamma(3)/gamma0]
diff_gamma_5 = diff_gamma;
%{
min = abs(gammaminus(1,L)+gamma0);
q01 = 1;
for q2 = 1:2*N_total_3
if abs(gammaminus(q2,L)+gamma0)<min %&&...
%(abs(imag(gammaminus(q2,L))/real(gammaminus(q2,L)))<0.001)
min = abs(gammaminus(q2,L)+gamma0);
q01 = q2;
end
end
gammaminus(q01,L) = gammaminus(q01,L)+100;
q02 = 1;
min = abs(gammaminus(1,L)+gamma0);
for q2 = 1:2*N_total_3
if abs(gammaminus(q2,L)+gamma0)<min %&& (q2~=q01) %&&...
%(abs(imag(gammaminus(q2,L))/real(gammaminus(q2,L)))<0.001)
min = abs(gammaminus(q2,L)+gamma0);
q02 = q2;
end
end
gammaminus(q01,L) = gammaminus(q01,L)-100;
%}
q001 = q01;
q002 = q02;
gg1 = gammaminus(q01,L);
gg2 = gammaminus(q02,L);
gkz0 = gamma0;
gzero_norm = abs((gamma0+gg2)/gamma0);
gzero = abs(gamma0+gg2);
gamma_num=-real(gg2);
u0_1 = zeros(N_total_3,1);
u0_2 = zeros(N_total_3,1);
d2_1 = zeros(N_total_3,1);
d2_2 = zeros(N_total_3,1);
%WL = W(:,:,L);
%maxW = max(WL(:))
N2 = 2*N_total_3;
MW = [W(1,N2+q01,L), W(1,N2+q02,L); W(N_total_3+2,N2+q01,L), W(N_total_3+2,N2+q02,L)];
Isigma = [Ex0*int_P1_Q1; Ey0*int_P1_Q2]*exp(-1j*gamma0*sum(h));
dq = MW\Isigma;
dlast = zeros(2*N_total_3,1);
dlast(q01) = dq(1);
dlast(q02) = dq(2);
delta_inc = cat(1,u0_1,u0_2,dlast);
delta_max = max(delta_inc)
ud_PMM = Stotal*delta_inc;
%ud_PMM_1=max(ud_PMM);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%we have made all calculations in the Gegenbauer basis
%now we have to go back to the Fourier basis
N = N_FMM;
NN = (2*N_FMM+1)*(2*N_FMM+1);
%gamma = zeros(4*NN,4*NN,L);
k1 = k0*n1;
k2 = k0*n2;
alpha_v = zeros(2*N+1,1);
beta_v = zeros(2*N+1,1);
[Nxx, NNxx] = size(b_x1);
[Nyy, NNyy] = size(b_x2);
periodx = b_x1(NNxx)-b_x1(1);
periody = b_x2(NNyy)-b_x2(1);
for m=1:(2*N+1)
alpha_v(m) = (alpha0 + (m-N-1)*2*pi/periodx);
beta_v(m) = (beta0 + (m-N-1)*2*pi/periody);
end
alpha = zeros(NN,NN);
beta = zeros(NN,NN);
for i = 1:(2*N+1)
for j=1:(2*N+1)
m = i+(2*N+1)*(j-1);
beta(m,m) = beta_v(i);
alpha(m,m) = alpha_v(j);
end
end
kz1v = zeros(NN,1);
kz2v = zeros(NN,1);
A1 = zeros(NN,NN);
B1 = zeros(NN,NN);
C1 = zeros(NN,NN);
A2 = zeros(NN,NN);
B2 = zeros(NN,NN);
C2 = zeros(NN,NN);
for i = 1:(2*N+1)
for j=1:(2*N+1)
m = i+(2*N+1)*(j-1);
kz1v(m) = ( k1^2 - (alpha_v(j))^2 - (beta_v(i))^2 )^(1/2);
kz2v(m) = ( k2^2 - (alpha_v(j))^2 - (beta_v(i))^2 )^(1/2);
A1(m,m) = ( k1^2 - (alpha_v(j))^2)/(k0*kz1v(m));
A2(m,m) = ( k2^2 - (alpha_v(j))^2)/(k0*kz2v(m));
B1(m,m) = ( k1^2 - (beta_v(i))^2)/(k0*kz1v(m));
B2(m,m) = ( k2^2 - (beta_v(i))^2)/(k0*kz2v(m));
C1(m,m) = alpha_v(j)*beta_v(i)/(k0*kz1v(m));
C2(m,m) = alpha_v(j)*beta_v(i)/(k0*kz2v(m));
end
end
mzero = zeros(NN,NN);
miden = eye(NN,NN);
%{
K2_1 = cat(2, miden, mzero, miden, mzero);
K2_2 = cat(2, mzero, miden, mzero, miden);
K2_3 = cat(2, -C1, -A1, C1, A1);
%K2_3 = cat(2, -C1, A1, C1, -A1);
K2_4 = cat(2, B1, C1, -B1, -C1);
K2 = cat(1, K2_1, K2_2, K2_3, K2_4); %'2' in Chapter 13, Li
K0_1 = cat(2, miden, mzero, miden, mzero);
K0_2 = cat(2, mzero, miden, mzero, miden);
K0_3 = cat(2, -C2, -A2, C2, A2);
%K0_3 = cat(2, -C2, A2, C2, -A2);
K0_4 = cat(2, B2, C2, -B2, -C2);
K0 = cat(1, K0_1, K0_2, K0_3, K0_4); %'0' in Chapter 13, Li
%}
u2_PMM = ud_PMM(1:2*N_total_3);
d0_PMM = ud_PMM(2*N_total_3+1:4*N_total_3);
u2_1_FMM = fx_coef*W(1:N_total_3, 1:2*N_total_3, L)*u2_PMM;
u2_2_FMM = fy_coef*W(N_total_3+1:2*N_total_3, 1:2*N_total_3, L)*u2_PMM;
d0_1_FMM = fx_coef*W(1:N_total_3, 2*N_total_3+1:4*N_total_3, 1)*d0_PMM;
d0_2_FMM = fy_coef*W(N_total_3+1:2*N_total_3, 2*N_total_3+1:4*N_total_3, 1)*d0_PMM;
R1 = zeros(NN,1);
R2 = zeros(NN,1);
T1 = d0_1_FMM;
T2 = d0_2_FMM;
for i=1:NN
R1(i) = u2_1_FMM(i)/exp(1j*kz1v(i)*(sum(h)-h(L-1)));
R2(i) = u2_2_FMM(i)/exp(1j*kz1v(i)*(sum(h)-h(L-1)));
end
u2d0_FMM=cat(2,R1,R2,T1,T2);
eta_R = zeros(NN,1);
eta_T = zeros(NN,1);
for i=1:NN
if imag(kz1v(i))==0
eta_R(i) = A1(i,i)*(abs(R2(i)))^2 + B1(i,i)*(abs(R1(i)))^2 +...
C1(i,i)*( R1(i)*conj(R2(i))+R2(i)*conj(R1(i)) );
end
if imag(kz2v(i))==0
eta_T(i) = A2(i,i)*(abs(T2(i)))^2 + B2(i,i)*(abs(T1(i)))^2 +...
C2(i,i)*( T1(i)*conj(T2(i))+T2(i)*conj(T1(i)) );
end
end
%{
title = 'plot R1'
[x_full] = PMM_graph_output(ud_FMM, ud_PMM, La, alpha0, beta0, alpha_ref, beta_ref,...
b_x1, b_x2, N_intervals_x, N_intervals_y, N_basis_x, N_basis_y, Nx, nx, Ny, ny,...
N_FMM, ax, ay)
%}