Просмотр исходного кода

More directional wave propogation stuff

Pjotir 6 дней назад
Родитель
Сommit
602c7d5169
2 измененных файлов с 102 добавлено и 9 удалено
  1. 22 9
      classwork/huygens.m
  2. 80 0
      classwork/snells_law_forreal.m

+ 22 - 9
classwork/huygens.m

@@ -2,8 +2,9 @@ clear all; close all; clc;
 
 c = 2.998e8; % m/s
 Lx = 5e-6;   % m (5 um)
-Ly = 5e-6;
-Nx = Ny = 300;
+Ly = 10e-6;
+Ny = 600;
+Nx = 300;
 x = linspace(0, Lx, Nx);
 y = linspace(-Ly/2, Ly/2, Ny);
 dx = x(2) - x(1);
@@ -18,17 +19,28 @@ lambda = 500e-9;
 k = 2*pi/lambda;
 omega = c*k;
 
-sources_num = 100
+sources_num = 100;
 source_position_x = floor(linspace(1, Nx, sources_num));
-source_position_y = ones(1, sources_num) * floor(Ny/2);
-source_phase = zeros(1, sources_num);
+source_position_y = ones(1, sources_num) * 2;
+
+% No phase
+% source_phase = zeros(1, sources_num);
+
 % Destructive interference
 % source_phase(1:2:end) = pi;
-source_phase = linspace(0, 20*pi, sources_num);
+
+% 30deg adjusted phase
+% deflection_angle = deg2rad(30);
+% source_phase = (k*sin(deflection_angle)) * linspace(0, Lx, sources_num);
+
+% Focused phase
+theta_axicon = deg2rad(20);
+x_center = Lx/2;
+source_phase = k.*abs(x(source_position_x)-x_center)*sin(theta_axicon);
 
 %initialize fields
-u = zeros(Nx, Ny);
-u_prev = zeros(Nx, Ny);
+u = zeros(Ny, Nx);
+u_prev = zeros(Ny, Nx);
 
 %plot initial
 figure;
@@ -44,7 +56,8 @@ grid off;
 axis off;
 xlim([1, Nx]);
 ylim([1, Ny]);
-hplot = imagesc(u);
+hplot = imagesc(u); colorbar; clim([-1.5, 1.5]);
+axis xy;
 
 for n = 1:Nt
 

+ 80 - 0
classwork/snells_law_forreal.m

@@ -0,0 +1,80 @@
+clear all; close all; clc;
+
+c = 2.998e8; % m/s
+Lx = 5e-6;   % m (5 um)
+Ly = 5e-6;
+Ny = 300;
+Nx = 300;
+x = linspace(0, Lx, Nx);
+y = linspace(-Ly/2, Ly/2, Ny);
+dx = x(2) - x(1);
+dy = y(2) - y(1);
+dt = 0.5*dx/c;
+[X, Y] = meshgrid(x, y);
+tmax = (Lx/c)*2;
+Nt = floor(tmax/dt);
+
+% light source
+lambda = 500e-9;
+k = 2*pi/lambda;
+omega = c*k;
+
+sources_num = 100;
+source_position_x = floor(linspace(1, Nx, sources_num));
+source_position_y = ones(1, sources_num) * 2;
+
+% 30deg adjusted phase
+deflection_angle = deg2rad(30);
+source_phase = (k*sin(deflection_angle)) * linspace(0, Lx, sources_num);
+
+% speed of light matrix
+% We're defining the top half to have a slightly lower speed of light
+top_index = 1.5;
+bottom_index = 1;
+solm = [ones(Ny/2, Nx) / top_index * c; ones(Ny/2, Nx)/bottom_index*c];
+
+%initialize fields
+u = zeros(Ny, Nx);
+u_prev = zeros(Ny, Nx);
+
+%plot initial
+figure;
+hold on;
+colorbar;
+zlim([-1.5, 1.5]);
+clim([-1.5, 1.5]);
+view(3);
+hsurf = surf(X, Y, u, 'EdgeColor', 'none');
+figure;
+hold on;
+grid off;
+axis off;
+xlim([1, Nx]);
+ylim([1, Ny]);
+hplot = imagesc(u); colorbar; clim([-1.5, 1.5]);
+plot([0 Nx], [Ny/2, Ny/2], 'b-', 'LineWidth', 5);
+axis xy;
+
+for n = 1:Nt
+
+    for i = 1:length(source_position_x)
+        source = sin(omega * n * dt+source_phase(i));
+        u(source_position_y(i), source_position_x(i)) = source;
+    end
+
+    u_prev_prev = u_prev;
+    u_prev = u;
+
+    u = 2*u_prev - u_prev_prev + 4*(solm*dt).^2.*del2(u_prev, dx, dy);
+    u = absorbing_bc(u, u_prev, c, dt, dx, dy);
+
+    if mod(n, 2) == 0
+        current_time_str = num2str(n*dt*10e15, '%.2f');
+        title(['Time: ', current_time_str, ' fs']);
+        set(hsurf, 'ZData', u, 'CData', u);
+        set(hplot, 'CData', u);
+        drawnow;
+    endif
+
+    pause(0.005);
+end