소스 검색

electric field classwork

Pjotir 2 주 전
부모
커밋
5cf3795e3f
2개의 변경된 파일과 58개의 추가작업 그리고 1개의 파일을 삭제
  1. 57 0
      classwork/electric_field.m
  2. 1 1
      classwork/heat_diffusion_2d.m

+ 57 - 0
classwork/electric_field.m

@@ -0,0 +1,57 @@
+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 = 2/3*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);
+
+%plot initial
+figure;
+hold on;
+colorbar;
+zlim([-2, 2]);
+view(3);
+hsurf = surf(X, Y, u, 'EdgeColor', 'none');
+
+for n = 1:Nt
+    source = sin(omega*n*dt);
+    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);
+
+    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

+ 1 - 1
classwork/heat_diffusion_2d.m

@@ -23,7 +23,7 @@ source_width = 3;
 source(ix0-source_width:ix0+source_width, iy0-source_width:iy0+source_width) = 1;
 
 Q = 0.02;
-t_heat = 2000;
+t_heat = 200;
 
 figure;
 hold on;