-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWaveCavity3D_Main.m
214 lines (158 loc) · 8.09 KB
/
WaveCavity3D_Main.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%% last update 23Mai2018, lne %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all
clc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Constants %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c=2.99792458e8;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%% Solving Parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f0_guess= c/5e-6; %% Guess of the frequency solutions (Hz)
f0_min = c/20e-6; %% filter the solutions where the frequency is superior than (Hz)
f0_max = c/2e-6; %% filter the solutions where the frequency is inferior than (Hz)
nmodes=10; %% number of solutions asked
AbsorbingBoundaryCondition=0; %% 0 or 1 (not sure it is working well...)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%% Optical index definition %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Three vectors (x, y and z) and one 3D-matrix n must be defined with homogeneous grid
% x, y and z [meter]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Nx=13; %% Meshing point in x-direction
Ny=17; %% Meshing point in y-direction
Nz=15; %% Meshing point in z-direction
Dx=1E-6; %% map X [m]
Dy=1E-6; %% map Y [m]
Dz=1E-6; %% map Z [m]
x = linspace(-Dx, Dx, Nx);
y = linspace(-Dy, Dy, Ny);
z = linspace(-Dz, Dz, Nz);
dx = x(2)-x(1);
dy = y(2)-y(1);
dz = z(2)-z(1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Choose between the next 2 structures or build your own on an homogeneous grid!
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%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
display('=======================================')
tic
if length(x)*length(y)*length(z)*3>1e4
Nxyz=length(x)*length(y)*length(z);
display(strcat('Warning: Take care, H=',num2str(Nxyz),'x',num2str(Nxyz),'x3 elements'))
end
[Ex,Ey,Ez,f1]=WC3D_FEM_f(x,y,z,eps,nmodes,f0_guess,f0_min,f0_max);
display(strcat('-> Finite Elements method =',num2str(toc),'sec'))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%% Display Results %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f(1:length(f1),1)=f1;
lambda(1:length(f1),1)=c./f1;
%display('=======================================')
%display('Results f(THz):')
%f*1e-12
display('=======================================')
display('Results lambda(um):')
lambda*1e6
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% figures %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X0fig = 50 ; Y0fig = 50;
Wfig = 1500 ; Hfig = 800;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:length(f(:,1))
figure('Name',strcat('FEM method: Electrical Field-',num2str(i)),'position',[X0fig Y0fig Wfig Hfig])
colormap(jet)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(2,3,1)
hold on;grid on;view (-38, 20);
slice(x*1e6,y*1e6,z*1e6,n,[0],[0],[0])
contour(x*1e6,y*1e6,z*1e6,abs(n),1,'linewidth',2,'linecolor','r')
PSI=abs(Ex(:,:,:,i)).^2;
p = patch(isosurface(x*1e6,y*1e6,z*1e6,PSI,max(PSI(:))/3));
isonormals(x*1e6,y*1e6,z*1e6,PSI, p)
set(p, 'FaceColor', 'red', 'EdgeColor', 'none', 'FaceLighting', 'gouraud')
daspect([1,1,1])
light ('Position', [1 1 5]);
title( strcat('lambda=', num2str( lambda(i,1)*1e6,'%.2f'),'um, Abs(Ex)' ) )
xlabel('x (um)')
ylabel('y (um)')
zlabel('z (um)')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(2,3,2)
hold on;grid on;view (-38, 20);
slice(x*1e6,y*1e6,z*1e6,n,[0],[0],[0])
PSI=abs(Ey(:,:,:,i)).^2;
p = patch(isosurface(x*1e6,y*1e6,z*1e6,PSI,max(PSI(:))/3));
isonormals(x*1e6,y*1e6,z*1e6,PSI, p)
set(p, 'FaceColor', 'red', 'EdgeColor', 'none', 'FaceLighting', 'gouraud')
daspect([1,1,1])
light ('Position', [1 1 5]);
title( strcat('lambda=', num2str( lambda(i,1)*1e6,'%.2f'),'um, Abs(Ey)' ) )
xlabel('x (um)')
ylabel('y (um)')
zlabel('z (um)')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(2,3,3)
hold on;grid on;view (-38, 20);
slice(x*1e6,y*1e6,z*1e6,n,[0],[0],[0])
PSI=abs(Ez(:,:,:,i)).^2;
p = patch(isosurface(x*1e6,y*1e6,z*1e6,PSI,max(PSI(:))/3));
isonormals(x*1e6,y*1e6,z*1e6,PSI, p)
set(p, 'FaceColor', 'red', 'EdgeColor', 'none', 'FaceLighting', 'gouraud')
daspect([1,1,1])
light ('Position', [1 1 5]);
title( strcat('lambda=', num2str( lambda(i,1)*1e6,'%.2f'),'um, Abs(Ez)' ) )
xlabel('x (um)')
ylabel('y (um)')
zlabel('z (um)')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(2,3,4)
hold on;grid on;view (-38, 20);
PSI=real(Ex(:,:,:,i));
slice(x*1e6,y*1e6,z*1e6,PSI,[0],[0],[0])
title( strcat('lambda=', num2str( lambda(i,1)*1e6,'%.2f'),'um, Re(Ex)' ) )
xlabel('x (um)')
ylabel('y (um)')
zlabel('z (um)')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(2,3,5)
hold on;grid on;view (-38, 20);
PSI=real(Ey(:,:,:,i));
slice(x*1e6,y*1e6,z*1e6,PSI,[0],[0],[0])
title( strcat('lambda=', num2str( lambda(i,1)*1e6,'%.2f'),'um, Re(Ey)' ) )
xlabel('x (um)')
ylabel('y (um)')
zlabel('z (um)')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(2,3,6)
hold on;grid on;view (-38, 20);
PSI=real(Ez(:,:,:,i));
slice(x*1e6,y*1e6,z*1e6,PSI,[0],[0],[0])
title( strcat('lambda=', num2str( lambda(i,1)*1e6,'%.2f'),'um, Re(Ez)' ) )
xlabel('x (um)')
ylabel('y (um)')
zlabel('z (um)')
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%