Sei sulla pagina 1di 21

Universidad industrial de Santander

Computacin numrica en teora electromagntica Programas de teora electromagntica

HECTOR IVAN YAEZ GUTIERREZ Cd.: 2073676 FERNEY MANRIQUE LIZARASO Cd.: 2073649 DAVID RAMIREZ ROA Cod: 2073651

Prof.: Rodrigo Correa

2 semestre 2010 Bucaramanga

OBJETIVOS

Observar de una forma mas evidente el comportamiento de las ondas electromagnticas por medio del software Matlab; Este nos permite ver toda la amplitud y frecuencia de las ondas lo que no conseguimos con otros softwars. Poner en practica los conocimientos adquiridos en clase (resolucin de las ecuaciones de maxwell) y tambin por loas tutoras dictadas en horas extras de clase (Manejo del software matlab). Adquirir destreza en el manejo de la programacin y tener ventaja a la hora de optimizar un problema de ingenieria

PROGRAMA 1.1

%/* FD1D_1.1. 1D FDTD simulation in free space */ function FD1D_11 KE=input ('KE='); for k=1:KE ex(k)=0; hy(k)=0; end kc=KE/2; to=40.0; spread=12; T=0; NSTEPS=1; while NSTEPS>0 NSTEPS=input('NSTEPS-->'); NSTEPS n=0; for n=1:NSTEPS T=T+1; tiempo (n)=T; for k=2:KE ex(k)= ex(k) +.5*(hy(k-1)-hy(k)); ex(k) end pulse = exp(-.5*(( (to-T)/spread)^(2))); ex(kc)= pulse; for k=1:KE-2 hy(k)=hy(k)+ .5*(ex(k)-ex(k+1)); end end for k=1:KE ex(k) end for k=1:KE hy(k); end end hold on; plot(tiempo, ex,'b') plot(tiempo, hy,'r')

end

Ex versus FDTD cells


1 0.9 0.8 0.7 0.6 Ex 0.5 0.4 0.3 0.2 0.1 0 0 20 40 60 80 100 120 FDTD Cells 140 160 180 200

Fig 1.1.1.a Ex versus FDTD cells con T=100

PROGRAMA 1.2 %/* FD1D_1.2. 1D FDTD simulation in free space */ %/* Absorbing Boundary Condition added */ function FD1D_12 KE= input ('KE='); ex_low_m1=0; ex_low_m2=0; ex_high_m1=0; ex_high_m2=0; n=0; tiempo(n)= ('tiempo (n)-->'); for n=1:NSTEPS T=T+1; tiempo(n)=T; end for k=2:KE ex(k)=ex(k)+.5*(hy(k-1)-hy(k)); end pulse=exp(-.5*((t0-T)/spread)^(2.0)); ex(kc)=ex(kc)+pulse; ex(0) ex_low_m2 ex_low_m1 ex( KE-1) = = = = ex_low_m2; ex_low_m1; ex(1); ex_high_m2;

ex_high_m2 ex_high_m1

= =

ex_high_m1; ex(KE-2);

for k=1:KE-1 hy(k)=hy(k)+.5*(ex(k)-ex(k+1)); end

T=100

Fig 1.3.1.a Ex versus FDTD cells con T=100

PROGRAMA 1.3 %/*FD1D_1.3. 1D FDTD simulation of a pulse hitting a dielectric medium */ function FD1D_13 KE=input ('KE='); epsz=8.8e-12; for k=1:KE

ex(k) =0; hy (k) =0; end kc=KE/2; to=40.0; spread=12; T=0; nsteps=1; for k=1:KE cb (k)=.5; end

kstart=input ( 'Dielectric starts at - - ->' ); epsilon=input ('Epsilon - - >'); for k=kstart:KE cb(k)=.5/epsilon; end for k=1:KE k; cb(k); end while nsteps>0 nsteps=input('nsteps- - - >'); nsteps for n=1:nsteps T=T+1; tiempo (n)=T; for k=2:KE ex(k)=ex(k)+cb(k)*(hy(k-1)-hy(k)); end end hold on; plot(tiempo,ex,'b') plot(tiempo,hy,'r') end

Fig 1.2.1.d Ex versus FDTD cells con T=100

PROGRAMA 1.4

%/*FD1D_1.4. 1D FDTD simulation of a sinusoidal wavw hitting a dielectric medium */ function FD1D_14 KE=input ('KE='); ddx=.01; dt=ddx/(2*3e8); T=0; nsteps =1; for k=1:KE ex(k) =0; hy (k) =0; end while nsteps>0 nsteps=input ('nsteps-->'); nsteps for n=1:nsteps T=T+1; tiempo(n)=T;

for k=2:KE; ex(k)=(ex(k-1))+( (cb(k))*((hy(k))-(hy(k-1)))); end pulse = sin(2*3.14159*freq_in*dt*T); ex(5)=ex(5)+pulse; printf ('%5.1f %6.2f %6.2f\', T,pulse, ex(5)); end hold on; plot(tiempo,dx,'b') plot(tiempo,hy,'r') end

T=320

Fig 1.4.3.c Ex versus FDTD cells con T=320

PROGRAMA 1.5 %/*FD1D_1.5. 1D FDTD simulation of a lossy dielectric medium */

function FD1D_15 KE=input ('KE='); epsz=8.85419e-12; dt=1; tiempo=0; for k=1:KE ex(k) =0; hy (k) =0; end for k=1:KE ca(k)=1.; cb(k)= .5; end kstart=input( 'Dielectric starts at - - -> '); epsilon=input ('Epsilon - - > '); sigma=input ( 'conductivity- - ->'); eaf=dt*sigma/(2*epsz*epsilon); for k=1:KE ca(k)=(1.-eaf)/(1+eaf); cb(k)=(.5/epsilon*(1+eaf)); end for k=2:KE ex(k)=ca(k)*ex(k)+cb(k)*(hy(k-1)-hy(k));

hold on; plot(tiempo,ca,'b') plot(tiempo,cb,'r') end Para T=150

Fig 1.5.3.a Ex versus FDTD cells con T=150

PROGRAMA 2.1 %/* FD1D_2.1. 1D FDTD simulation of a pulse hitting a dielectric medium*/ function[] = flujoelectrico() KE = input('KE = '); kc = KE / 2; ddx = 0.01; dt = ddx / 6e8; epsz = 8.8e-12; ex_low_m2=0; ex_low_m1=0; ex_high_m2=0; ex_high_m1=0; for k = 1 : KE ga(k)=1; gb(k)=0; ex(k)=0; dx(k)=0; hy(k)=0; ix(1,k)=0; end size(ga) size(dx) size(ex) Kstart = input('Dielectric starts at --> '); epsilon = input('Epsilon ');

sigma = input('Conductivity '); for k = Kstart : KE ga(k) = 1 / (epsilon + sigma * dt / epsz); gb(k) = sigma * dt / epsz; end for k = 1 : KE k; ga(k); gb(k); end t0 = 50.0; spread = 20.0; T = 0; nsteps = 1; while nsteps > 0 nsteps = input('nsteps--> ') nsteps for n = 1 : KE T = T + 1; tiempo(n) = T; for k = 2 : KE dx(k) = dx(k) + 0.5 * (hy(k - 1) - hy(k)); end

freq_in = 3e8; pulse = exp(-.5 * (((t0 - T) / spread) ^ (2.0))); dx(kc) = dx(kc) + pulse; for k = 1 : KE - 1 k ex(k) = ga(k) * (dx(k) - ix(1,k)); ix(1,k) = ix(1,k) + gb(k) * ex(k); end ex(1) = ex_low_m2; ex_low_m2 = ex_low_m1; ex_low_m1 = ex(KE - 2); ex(KE - 1) = ex_high_m2; ex_high_m2 = ex_high_m1; ex_high_m1 = ex(KE - 1); for k = 1 : KE - 1 hy(k) = hy(k) + .5 *(ex(k) - ex(k + 1)); end end hold on; %plot(tiempo,dx,'b')

plot(tiempo,hy,'r') end

1.5

0.5

-0.5

-1

-1.5 0 20 40 60 80 100 120 140 160 180 200

Con KE=200 Dielectric starts at=300 Epsilon=8.85e-12 Conductivity=0.05 NSTEPS= 200 PROGRAMA 2.2 %/*fd1d_2.2.c. the Fourier tranform has been added.*/ function[]= transformada() KE = input('KE = '); kc =KE/2; epsz = 8.8e-12; ddx = .01; dt = ddx/6e8; ex_low_m1=0; ex_low_m2=0; ex_high_m1=0; ex_high_m2=0;

for k=1:KE

ga(k)=1.0; gb(k)=0; dx(k)=0; ex(k)=0; hy(k)=0; ix(1,k)=0; imag(k)=0;

for m=1:3 real_pt((m)*(k))=0; %/*real and imaginary parts */ %/* of the Fourier transform */ imag_pt((m)*(k))=0; %/*amplitude and phase of the */ ampn((m)*(k))=0; phasen((m)*(k))=0; %/* Fourier transforms */ end end for m=1:3 real_in(m)=0 ; %/* Fourier trans. Of input pulse */ imag_in(m) =0; end ex_low_m1= 0; ex_low_m2= 0; ex_high_m1= 0; ex_high_m2= 0; %/* Parameters for the Fourier Transform */ freq(1) = 100.e6; freq(2) = 200.e6; freq(3) = 500.e6; for n=1:3 arg(n)=2*pi*freq(n)*dt ; end Kstart=input('Dielectric starts at --> '); epsilon=input('Epsilon -- > ' ); sigma=input('conductivity -- > ');

for end

k=Kstart:KE ga(k)=1./(epsilon + sigma*dt /epsz); gb(k)= sigma*dt/epsz ;

for k=1:KE end %/* these parameters specify the input pulse */ t0 =50.0; spread = 10.0 ; T=0; nsteps=1; %/*main part of the program*/ while nsteps >0 nsteps = input('nsteps--> ') nsteps for n=1:nsteps T = T+1; tiempo(n)=T;

%/* calculate the Dx field */ for k=2:KE dx(k)=dx(k)+0.5*( hy (k-1) -hy(k) ) ; end %/* initialize with a pulso */ pulse = exp(-0.5*((((t0-T)/spread)^2.0))); dx(5) =dx(5) +pulse ; %/* calculate Ex fron Dx */ for k=1:KE ex (k)=ga (k)*(dx(k)- ix(k) ) ; ix (k)=ix(k)+gb(k)*ex(k) ; end %/* calculate the fourier transform of Ex. */ for k=1:KE for m=1:3 real_pt((m)*(k))= real_pt((m)*(k))+cos(arg (m)*T)*ex(k) ; imag_pt((m)*(k))= imag_pt((m)*(k))-sin (arg (m)*T)*ex(k) ; end end %/* Fourier transform of the input pulse */ if T<100 for m=1:3 real_in(m) = real_in(m)+ cos (arg (m)*T)*ex(10) ; imag_in(m) = imag_in (m) - sin (arg (m)*T)*ex(10) ; end end

%/* boundary conditions */ ex(1)= ex_low_m2 ; ex_low_m2 =ex_low_m1 ; ex_low_m1 =ex(2) ;

ex(KE -1)= ex_high_m2 ; ex_high_m2 = ex_high_m1 ex_high_m1=ex(KE-2);

%/* calculate the hy field */ for k=1:KE-1 hy(k)= hy (k)+.5*(ex (k)-ex(k+1)) ; end end %/* end of the main loop */ %/* write the E field out to a file "Ex" */ for k=1:KE+1 end %/* calculate the amplitud and phase of each frequency */ %/* Amplitude and phase of the input pulse */

for

m=1:3 amp_in(m)= sqrt(((imag_in(m))^2.0)+ ((real_in(m))^ 2.0)); phase_in(m) = atan2 ( imag_in(m) ,real_in(m)) ;

for k=1:KE ampn ((m)*(k))= (1./amp_in(m))*sqrt ((real_pt ((m)*(k)))^ 2.0)+(((imag_pt((m)*(k)))^2.0)) ; phasen((m)*(k))= atan2( imag_pt((m)*(k)),real_pt((m)*(k)))phase_in(m); end %/*for (k=1 ; k<KE; ; k++){ printf ( "%d %6.3f ,ampn [0][k] ),ampn [1][k], ampn [2][k] -; } */ %6.3f %6.3f \n",K

%/* write the amplitude field out to a fieles "Amp" for k=1:KE+1 end for k=1:KE+1 end for k=1:KE+1 end end hold on; plot(tiempo,dx,'b'); plot(tiempo,ex,'r'); end end

*/

1.2

0.8

0.6

0.4

0.2

-0.2 0 20 40 60 80 100 120 140 160 180 200

Con KE=200 Dielectric starts at=300 Epsilon=8.85e-12 Conductivity=0.05 NSTEPS= 200 PROGRAMA 2.3 %/* FD1D_2.3. 1D FDTD simulation of a frecuency dependent material */ function[] =frecuenciadematerial KE=input('KE= '); kc= KE/2; epsz = 8.8e-12; ddx=.01; dt=ddx/6e8; ex_low_m1=0; ex_low_m2=0; ex_high_m1=0; ex_high_m2=0; for k=1:KE %/* Initiaize to free space */ ga(k)=1.; gb(k)=0.; gc(k)=0.;

dx(k)=0.; ex(k)=0.; hy(k)=0.; ix(k)=0.; sx(k)=0.; imag(k)=0.; for m=1:5 real_pt((m)*(k)) = 0.; imag_pt((m)*(k)) = 0.; ampn((m)*(k))= 0.; phasen((m)*(k))= 0.; end end for m=1:5 real_in(m) = 0.; imag_in(m) = 0.; end ex_low_m1 = 0.; ex_low_m2 = 0.;

%/* Real and imaginary parts */ %/* of the Fourier Transform */ %/* Amplitude and phase of the */ %/* Fourier Transforms */

%/* Fourier trans. of input pulse */

%/* Parameters for the Fourier Transfom */ freq(1) = 50.e6; freq(2) = 200.e6; freq(3) = 500.e6; for n=1:3 arg(n) = 2*pi*freq(n)*dt; end Kstart=input('Dielectric starts at epsilon=input('Epsilon -- > ' ); sigma=input('conductivity -- > '); chil=input( 'chil -->'); --> ');

%/* Make sure tau is > 0. */ tau = 1000.; if chil>0.0001 tau=input( 'tau (in microseconds) --> '); del_exp = exp(-dt/tau); end tau = 1e-6*tau; for k=Kstart:KE ga(k) = 1./(epsilon + sigma*dt/epsz + chil*dt/tau); gb(k) = sigma*dt/epsz; gc(k)= chil*dt/tau; end for k=1:KE end %/* These parameters specify the input pulse */ t0 = 50.0;

spread = 10.0; T = 0; nsteps=1; %/* Main part of the program */ while nsteps > 0 nsteps=input('nsteps -->'); nsteps

for n=1:nsteps T = T + 1; tiempo(n)=T; %/* Calculate the Dx field */ for k= 2:KE dx(k) = dx(k) + 0.5*( hy(k-1) - hy(k)); end %/* Initialize with a pulse */ pulse = exp(-.5*((((t0-T)/spread)^2.0))); dx(5) = dx(5) + pulse; %/* Calculate Ex from Dx */ for k=1:KE ex(k) = ga(k)*(dx(k)-ix(k)-sx(k)); ix(k)=ix(k)+gb(k)*ex(k); sx(k) = del_exp*sx(k) + gc(k)*ex(k); end %/* Calculate the fourier transform of Ex. */ for k=1:KE ex(k) = ga(k)*(dx(k) - ix(k) - sx(k)); ix(k) = ix(k) + gb(k)*ex(k); sx(k) = del_exp*sx(k) + gc(k)*ex(k) ; end %/* Calculate the Fourier transform of Ex. */ for k=1:KE for m=1:3 real_pt((m)*(k))=real_pt((m)*(k))+cos(arg(m)*T)*ex(k); imag_pt((m)*(k))=real_pt((m)*(k)) + cos(arg(m)*T)*ex(k); end end %/* Fourier Transform of the input pulse */ if T<100 for m=1:3 real_in(m)=real_in(m) + cos(arg(m)*T)*ex(10); imag_in(m)=imag_in(m)-sin(arg(m)*T)*ex(10); end end %/* Boundary conditions */ ex(1)= ex_low_m2;

ex_low_m2 = ex_low_m1; ex_low_m1 = ex(2); ex(KE-1) = ex_high_m2; ex_high_m2 = ex_high_m1; ex_high_m1 = ex(KE-2); %/* Calculate the Hy field */ for k=1:KE-1 hy(k)= hy(k) + .5*(ex(k)-ex(k+1)); end end %/* End of the main loop */ %/* for(k=0;k<KE;k++){ printf( "%2d %6.2f %6.2 \n",k,dx[k],ex[k]);} */ %/* Write the E field out to a file "Ex" */ for k=1:KE end %/* Calculate the amplitude and phase of each frequency */ %/* Amplitude and phase of the input pulse */ for m=1:3 amp_in(m) = sqrt(((imag_in(m))^2.)) + (((real_in(m))^2.)); phase_in(m)=atan2(imag_in(m),real_in(m)); for k=1:KE ampn((m)*(k))=(1./amp_in(m))*sqrt(((real_pt((m)*(k)))^2.)+((imag_pt((m)*( k)))^2.)); phasen((m)*(k))=atan2(imag_pt((m)*(k)),real_pt((m)*(k)))phase_in(m); end end %/* for(k=kstart;k<KE;k++){ printf("%d %6.3f %6.3f %6.3f \n",k,ampn[1][k]),ampn[2][k],ampn[3][k];} */ %/* Write the amplitude field out to a file "Amp" */ for k=1:KE end for k=1:KE end for k=1:KE end plot(tiempo,dx,'b') %plot(tiempo,ampn,'g') end end

1.2

0.8

0.6

0.4

0.2

-0.2 0 20 40 60 80 100 120 140 160 180 200

Con KE=200 Dielectric starts at=300 Epsilon=8.85e-12 CHIL = 100 TAU(micro sg)=0.001 Conductivity=0.05 NSTEPS= 200

CONCLUSIONES

Es incredible como gente hace mas de 200 aos suponia (teoricamente) como se comportaban las ondas electromagnticas y gracias a ellos (gente como maxwell) hoy en dia podemos manipularlas, jugar con ellas y hasta vivir de ellas con su campo de aplicacin. Resulta de gran importancia despertar el interez por volverse constante en la programacin y optimizacin de problemas. Puesto en practica los conocimientos bsicos aprendidos con anticipacin se observa el maravilloso comportamiento de las ondas electromagnticas en el espacio y en un medio dielctrico.

Potrebbero piacerti anche