programa 1

24
Universidad industrial de Santander Computación numérica en teoría electromagnética Programas de teoría electromagnética HECTOR IVAN YAÑEZ GUTIERREZ Cód.: 2073676 FERNEY MANRIQUE LIZARASO Cód.: 2073649 DAVID RAMIREZ ROA Cod: 2073651 Prof.: Rodrigo Correa

Upload: pipe-mejia

Post on 28-Nov-2014

28 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: PROGRAMA 1

Universidad industrial de Santander

Computación numérica en teoría electromagnéticaProgramas de teoría electromagnética

HECTOR IVAN YAÑEZ GUTIERREZCód.: 2073676

FERNEY MANRIQUE LIZARASOCód.: 2073649

DAVID RAMIREZ ROACod: 2073651

Prof.: Rodrigo Correa

2 semestre 2010 Bucaramanga

Page 2: PROGRAMA 1

OBJETIVOS

Page 3: PROGRAMA 1

Observar de una forma mas evidente el comportamiento de las ondas electromagnéticas 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 (resolución de las ecuaciones de maxwell) y también por loas tutorías dictadas en horas extras de clase (Manejo del software matlab).

Adquirir destreza en el manejo de la programación y tener ventaja a la hora de optimizar un problema de ingenieria

PROGRAMA 1.1

Page 4: PROGRAMA 1

%/* FD1D_1.1. 1D FDTD simulation in free space */

function FD1D_11KE=input ('KE='); for k=1:KE ex(k)=0; hy(k)=0; endkc=KE/2; to=40.0; spread=12; T=0;NSTEPS=1;while NSTEPS>0 NSTEPS=input('NSTEPS-->');NSTEPSn=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)endpulse = exp(-.5*(( (to-T)/spread)^(2)));ex(kc)= pulse; for k=1:KE-2 hy(k)=hy(k)+ .5*(ex(k)-ex(k+1));endend for k=1:KE ex(k) end for k=1:KE hy(k); endend hold on; plot(tiempo, ex,'b') plot(tiempo, hy,'r')end

Ex versus FDTD cells

Page 5: PROGRAMA 1

0 20 40 60 80 100 120 140 160 180 2000

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

FDTD Cells

Ex

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_12KE= 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:NSTEPST=T+1;tiempo(n)=T;end for k=2:KE ex(k)=ex(k)+.5*(hy(k-1)-hy(k));endpulse=exp(-.5*((t0-T)/spread)^(2.0));ex(kc)=ex(kc)+pulse; ex(0) = ex_low_m2;ex_low_m2 = ex_low_m1;ex_low_m1 = ex(1); ex( KE-1) = ex_high_m2;ex_high_m2 = ex_high_m1;ex_high_m1 = ex(KE-2); for k=1:KE-1

Page 6: PROGRAMA 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_13KE=input ('KE='); epsz=8.8e-12; for k=1:KE ex(k) =0;hy (k) =0;endkc=KE/2; to=40.0; spread=12; T=0;nsteps=1; for k=1:KE cb (k)=.5;endkstart=input ( 'Dielectric starts at - - ->' );epsilon=input ('Epsilon - - >'); for k=kstart:KE

Page 7: PROGRAMA 1

cb(k)=.5/epsilon;endfor k=1:KEk;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));endend 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_14KE=input ('KE='); ddx=.01; dt=ddx/(2*3e8);

Page 8: PROGRAMA 1

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 */

Page 9: PROGRAMA 1

function FD1D_15KE=input ('KE='); epsz=8.85419e-12;dt=1;tiempo=0;for k=1:KE ex(k) =0;hy (k) =0;endfor k=1:KE ca(k)=1.;cb(k)= .5;endkstart=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

Page 10: PROGRAMA 1

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;

Page 11: PROGRAMA 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

Page 12: PROGRAMA 1

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

-1

-0.5

0

0.5

1

1.5

Con KE=200Dielectric starts at=300Epsilon=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;

Page 13: PROGRAMA 1

hy(k)=0; ix(1,k)=0; imag(k)=0; for m=1:3 real_pt((m)*(k))=0; %/*real and imaginary parts */ imag_pt((m)*(k))=0; %/* of the Fourier transform */ ampn((m)*(k))=0; %/*amplitude and phase of the */ 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 k=Kstart:KE ga(k)=1./(epsilon + sigma*dt /epsz); gb(k)= sigma*dt/epsz ; 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 pulso */

Page 14: PROGRAMA 1

pulse = exp(-0.5*((((t0-T)/spread)^2.0)));dx(5) =dx(5) +pulse ; %/* calculate Ex fron Dx */for k=1:KEex (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)) ; endend%/* end of the main loop */%/* write the E field out to a file ´"Ex" */for k=1:KE+1end %/* 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)) ;

Page 15: PROGRAMA 1

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 %6.3f %6.3f \n",K ,ampn [0][k] ),ampn [1][k], ampn [2][k] -; } */ %/* write the amplitude field out to a fieles "Amp" */ for k=1:KE+1endfor k=1:KE+1endfor k=1:KE+1 end end hold on; plot(tiempo,dx,'b'); plot(tiempo,ex,'r'); endend

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

0

0.2

0.4

0.6

0.8

1

1.2

Con KE=200Dielectric starts at=300Epsilon=8.85e-12 Conductivity=0.05

Page 16: PROGRAMA 1

NSTEPS= 200

PROGRAMA 2.3

%/* FD1D_2.3. 1D FDTD simulation of a frecuency dependent material */ function[] =frecuenciadematerialKE=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.; %/* Real and imaginary parts */ imag_pt((m)*(k)) = 0.; %/* of the Fourier Transform */ ampn((m)*(k))= 0.; %/* Amplitude and phase of the */ phasen((m)*(k))= 0.; %/* Fourier Transforms */ end end for m=1:5 real_in(m) = 0.; %/* Fourier trans. of input pulse */ imag_in(m) = 0.; end ex_low_m1 = 0.; ex_low_m2 = 0.; %/* 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 --> ');

Page 17: PROGRAMA 1

epsilon=input('Epsilon -- > ' ); sigma=input('conductivity -- > '); chil=input( 'chil -->'); tau = 1000.; %/* Make sure tau is > 0. */ 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) ;

Page 18: PROGRAMA 1

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];} */

Page 19: PROGRAMA 1

%/* 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

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

0

0.2

0.4

0.6

0.8

1

1.2

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

Page 20: PROGRAMA 1

CONCLUSIONES

Es incredible como gente hace mas de 200 años suponia (teoricamente) como se comportaban las ondas electromagnéticas y gracias a ellos (gente como maxwell) hoy en dia podemos manipularlas, jugar con ellas y hasta vivir de ellas con su campo de aplicación.

Resulta de gran importancia despertar el interez por volverse constante en la programación y optimización de problemas.

Puesto en practica los conocimientos básicos aprendidos con anticipación se observa el maravilloso comportamiento de las ondas electromagnéticas en el espacio y en un medio dieléctrico.