| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- clear all; close all; clc;
- c = 2.998e8; % m/s
- Lx = 5e-6; % m (5 um)
- Ly = 5e-6;
- Nx = Ny = 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;
- source_width = 1*Ly;
- source_mask = zeros(Ny, 1);
- source_index = find(abs(y)<=source_width/2);
- source_mask(source_index) = 1;
- % initialize fields
- u = zeros(Nx, Ny);
- u_prev = zeros(Nx, Ny);
- % setting up slit
- barrier_index_x = floor(Nx/3);
- slit_width = lambda;
- % single slit
- barrier_index_y = find(abs(y)>slit_width/2);
- %plot initial
- figure;
- hold on;
- shading interp;
- colorbar;
- zlim([-2, 2]);
- clim([-2, 2]);
- xlabel('x');
- ylabel('y');
- zlabel('z');
- view(37.5, 30);
- hsurf = surf(X, Y, u, 'EdgeColor', 'none');
- % single slit plot
- wallZ = 0;
- plot3([x(barrier_index_x), x(barrier_index_x)], [y(1), y(floor(length(y)/2))-slit_width/2], [wallZ, wallZ], 'r-', 'LineWidth', 3);
- plot3([x(barrier_index_x), x(barrier_index_x)], [y(floor(length(y)/2))+slit_width/2, y(end)], [wallZ, wallZ], 'r-', 'LineWidth', 3);
- for n = 1:Nt
- if n < Nt
- source = sin(omega*n*dt);
- else
- source = 0;
- end
- u(:,1) = source.*source_mask;
- u_prev_prev = u_prev;
- u_prev = u;
- u = 2*u_prev - u_prev_prev + 4*(c*dt)^2*del2(u_prev, dx, dy);
- % u = Neumann(u);
- u = absorbing_bc(u, u_prev, c, dt, dx, dy);
- % Zeroing out waveform at barrier
- u(barrier_index_y, barrier_index_x) = 0;
- 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);
- drawnow;
- endif
- pause(0.005);
- end
|