-
Notifications
You must be signed in to change notification settings - Fork 7
/
WG2D_GetEz_f.m
92 lines (78 loc) · 5.67 KB
/
WG2D_GetEz_f.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
function[Ez]=WG2D_GetEz_f(x,y,Ex,Ey,eps,neff,lambda)
Nx=length(x);
Ny=length(y);
Nxy=Nx*Ny;
dx=x(2)-x(1);
dy=y(2)-y(1);
k0=2*pi/lambda;
Beta=neff^2*k0^2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%% Building of the operators %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
AA=ones(1,Nx*Ny);
BB=ones(1,Nx*Ny-1);
BB(Ny:Ny:end)=0;
DY1=diag(BB,-1)*(-0.5) + diag(BB,1)*(0.5);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Axy=ones(1,(Nx-1)*Ny);
DX1 = (-0.5)*diag(Axy,-Ny) + (+0.5)*diag(Axy,Ny);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ez = (1/i.Beta.eps) * (d(eps.Ex)/dx + d(eps.Ey)/dy) because div(D)=div(eps.E)=0
Ez = (1./(1i*eps(:)*Beta)) .* ( DX1/dx*(eps(:).*Ex(:)) + DY1/dy*(eps(:).*Ey(:)) ) ;
Ez=reshape(Ez,[Ny,Nx]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% First derivative X %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DX1(Ny=5,Nx=4); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% 0 0 0 0 0 |1/2 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 1/2 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 1/2 0 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 1/2 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 0 1/2| 0 0 0 0 0 | 0 0 0 0 0 %
% ----------------------------------------------------------------------------- %
% -1/2 0 0 0 0 | 0 0 0 0 0 |1/2 0 0 0 0 | 0 0 0 0 0 %
% 0 -1/2 0 0 0 | 0 0 0 0 0 | 0 1/2 0 0 0 | 0 0 0 0 0 %
% 0 0 -1/2 0 0 | 0 0 0 0 0 | 0 0 1/2 0 0 | 0 0 0 0 0 %
% 0 0 0 -1/2 0 | 0 0 0 0 0 | 0 0 0 1/2 0 | 0 0 0 0 0 %
% 0 0 0 0 -1/2| 0 0 0 0 0 | 0 0 0 0 1/2| 0 0 0 0 0 %
% ----------------------------------------------------------------------------- %
% 0 0 0 0 0 -1/2 0 0 0 0 | 0 0 0 0 0 |1/2 0 0 0 0 %
% 0 0 0 0 0 | 0 -1/2 0 0 0 | 0 0 0 0 0 | 0 1/2 0 0 0 %
% 0 0 0 0 0 | 0 0 -1/2 0 0 | 0 0 0 0 0 | 0 0 1/2 0 0 %
% 0 0 0 0 0 | 0 0 0 -1/2 0 | 0 0 0 0 0 | 0 0 0 1/2 0 %
% 0 0 0 0 0 | 0 0 0 0 -1/2| 0 0 0 0 0 | 0 0 0 0 1/2 %
% ----------------------------------------------------------------------------- %
% 0 0 0 0 0 | 0 0 0 0 0 -1/2 0 0 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 -1/2 0 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 -1/2 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 -1/2 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 -1/2| 0 0 0 0 0 %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%% First derivative Y %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DY1(Ny=5,Nx=4); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% 0 1/2 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% -1/2 0 1/2 0 0 | 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% 0 -1/2 0 1/2 0 | 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% 0 0 -1/2 0 1/2| 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% 0 0 0 -1/2 0 | 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% ----------------------------------------------------------------------------- %
% 0 0 0 0 0 | 0 1/2 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 -1/2 0 1/2 0 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 -1/2 0 1/2 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 -1/2 0 1/2| 0 0 0 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 -1/2 0 | 0 0 0 0 0 | 0 0 0 0 0 %
% ----------------------------------------------------------------------------- %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 1/2 0 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 -1/2 0 1/2 0 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 -1/2 0 1/2 0 | 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 -1/2 0 1/2| 0 0 0 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 -1/2 0 | 0 0 0 0 0 %
% ----------------------------------------------------------------------------- %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 | 0 1/2 0 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 -1/2 0 1/2 0 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 | 0 -1/2 0 1/2 0 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 | 0 0 -1/2 0 1/2 %
% 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 0 0 | 0 0 0 -1/2 0 %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%