- #1
s_hy
- 61
- 0
Homework Statement
to compute 1d fdtd maxwell equation using yee algorithm with fortran 90
Homework Equations
1D discretization for maxwell equation (TEM mode) :
electric field vector:
Ez(i-1/2,n+1/2) = Ca*(Ez(i-1/2,n-1/2) + Cb(Hy(i,n)-Hy(i-1,n)
magnetic field
Hy(i,n+1) = Da*(Hy(i,n) + Db(Ez(i+1/2,n+1/2)-Ez(i-1/2,n+1/2)
with source (gaussian pulse)
Ez(1/2+(ilast-iinit)/2,n) = E0*sin (2*pi*f0*n*tdelta)
The Attempt at a Solution
The fortran 90 code:
Code:
!1d fdtd Simulation in free space
subroutine fd1d01(f0,miu,delta,S,E0)
implicit none
real :: f0
real :: miu
real :: delta
real :: S
real :: E0
integer :: iinit
integer :: ilast
real :: Ca
real :: Da
integer :: i
integer :: n
real :: tdelta
real :: c
real,dimension(:,:),allocatable :: Ez
real,dimension(:,:),allocatable :: Hy
real, parameter :: pi = 3.14159265
real :: Cb
real :: Db
real :: lambda
real :: alpha
character(len=20) ::filename
allocate (Ez(-1:103,-1:503))
allocate (Hy(-1:103,-1:503))
f0 = 1.0
miu = 1.0
delta = 1.0
S = 1.0
E0 = 1.0
iinit = 0
ilast = 100
c = 3.e8
lambda = c/f0
alpha = 0.04*lambda
tdelta = 1.0*alpha/(S*c)!initialization
do i = iinit,ilast
do n = 1,500
Ez(iinit+1/2,n) = 0
Hy(iinit+1,n) = 0
end do
end doCa = 1.0
Cb = tdelta/(delta*alpha)
Da = 1.0
Db = tdelta/(miu*alpha)do n = 1,500
write (filename, "('ez',I3.3,'.dat')") n
open (unit=130,file=filename)
do i = iinit+1,ilast
Ez(i-1/2,n+1/2) = Ca*(Ez(i-1/2,n-1/2)) + Cb*(Hy(i,n)-Hy(i-1,n))
Hy(i,n+1) = Da*(Hy(i,n)) + Db*(Ez(i+1/2,n+1/2)-Ez(i-1/2,n+1/2))
! Print*, 'Ez(i-1/2,n+1/2)=',Ez(i-1/2,n+1/2)
Write (130,*) i-1./2, Ez(i-1/2,n+1/2)
end do !i
!plane wave source
Ez(1/2+(ilast-iinit)/2,n) = E0*sin (2*pi*f0*n*tdelta)
close (unit=130)
end do !n
end SUBROUTINE fd1d01
the problem i am facing right now is the output .dat file for Ez are all 0's. I had try few ways to find the problem source but unable to find out what is wrong with my code. Can anyone here that expert electromagnetic as well as fortran help me.
thank you very much