huygens.m 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. clear all; close all; clc;
  2. c = 2.998e8; % m/s
  3. Lx = 5e-6; % m (5 um)
  4. Ly = 10e-6;
  5. Ny = 600;
  6. Nx = 300;
  7. x = linspace(0, Lx, Nx);
  8. y = linspace(-Ly/2, Ly/2, Ny);
  9. dx = x(2) - x(1);
  10. dy = y(2) - y(1);
  11. dt = 0.5*dx/c;
  12. [X, Y] = meshgrid(x, y);
  13. tmax = (Lx/c)*2;
  14. Nt = floor(tmax/dt);
  15. % light source
  16. lambda = 500e-9;
  17. k = 2*pi/lambda;
  18. omega = c*k;
  19. sources_num = 100;
  20. source_position_x = floor(linspace(1, Nx, sources_num));
  21. source_position_y = ones(1, sources_num) * 2;
  22. % No phase
  23. % source_phase = zeros(1, sources_num);
  24. % Destructive interference
  25. % source_phase(1:2:end) = pi;
  26. % 30deg adjusted phase
  27. % deflection_angle = deg2rad(30);
  28. % source_phase = (k*sin(deflection_angle)) * linspace(0, Lx, sources_num);
  29. % Focused phase
  30. theta_axicon = deg2rad(20);
  31. x_center = Lx/2;
  32. source_phase = k.*abs(x(source_position_x)-x_center)*sin(theta_axicon);
  33. %initialize fields
  34. u = zeros(Ny, Nx);
  35. u_prev = zeros(Ny, Nx);
  36. %plot initial
  37. figure;
  38. hold on;
  39. colorbar;
  40. zlim([-1.5, 1.5]);
  41. clim([-1.5, 1.5]);
  42. view(3);
  43. hsurf = surf(X, Y, u, 'EdgeColor', 'none');
  44. figure;
  45. hold on;
  46. grid off;
  47. axis off;
  48. xlim([1, Nx]);
  49. ylim([1, Ny]);
  50. hplot = imagesc(u); colorbar; clim([-1.5, 1.5]);
  51. axis xy;
  52. for n = 1:Nt
  53. for i = 1:length(source_position_x)
  54. source = sin(omega * n * dt+source_phase(i));
  55. u(source_position_y(i), source_position_x(i)) = source;
  56. end
  57. u_prev_prev = u_prev;
  58. u_prev = u;
  59. u = 2*u_prev - u_prev_prev + 4*(c*dt)^2*del2(u_prev, dx, dy);
  60. % u = Neumann(u);
  61. u = absorbing_bc(u, u_prev, c, dt, dx, dy);
  62. if mod(n, 2) == 0
  63. current_time_str = num2str(n*dt*10e15, '%.2f');
  64. title(['Time: ', current_time_str, ' fs']);
  65. set(hsurf, 'ZData', u, 'CData', u);
  66. set(hplot, 'CData', u);
  67. drawnow;
  68. endif
  69. pause(0.005);
  70. end