Numerical solution for 1d fdtd maxwell equation using yee algorithm

I hope this helps.In summary, the conversation was about using the Yee algorithm with Fortran 90 to compute the 1D FDTD Maxwell equation. The code included 1D discretization for the electric and magnetic fields, as well as a Gaussian pulse source. The main issue being discussed was the output file for Ez, which was consistently showing zeros. The suggested solution was to add a write statement to help identify where the error may be occurring.
  • #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
 
Physics news on Phys.org
  • #2
While I am not an expert in electromagnetics, I have spent a great deal of time over the years writing code in the finite element arena. In your case, the first thing I would do is add a write statement on some preliminary calculation to assist ferreting out why you are winding up with zeros for results. Move the write statement along towards the end of the program, recompile, and execute again. In that way you can quickly determine where something may not be defined.

The worst error I ever had was one where a large program of mine would run with the extra write statement included but would get wrong answers when the statement was not present. It turned out I was exceeding an array specification. The addition of the write statements changed how storage was allocated so something that was getting overwritten had already been used in the case where the write statements were included.
 
Last edited:

Related to Numerical solution for 1d fdtd maxwell equation using yee algorithm

1. What is the 1d FDTD Maxwell equation?

The Finite-Difference Time-Domain (FDTD) method is used to solve Maxwell's equations, which describe the behavior of electromagnetic fields. In one dimension, the equations are simplified to the one-dimensional FDTD Maxwell equation, which models electromagnetic wave propagation in a single direction.

2. What is the Yee algorithm?

The Yee algorithm is a numerical algorithm used to solve the 1d FDTD Maxwell equation. It is named after Kane S. Yee, who first proposed the method in 1966. The algorithm is based on discretizing the electric and magnetic fields in space and time, and using a staggered grid to update their values at each time step.

3. How does the Yee algorithm work?

The Yee algorithm works by dividing the space into a grid of points, with electric and magnetic fields defined at each point. The algorithm then updates the values of these fields at each time step by using finite-difference approximations of Maxwell's equations. It also incorporates boundary conditions to account for the presence of objects in the simulation domain.

4. What are the advantages of using the Yee algorithm for 1d FDTD Maxwell equations?

One of the main advantages of the Yee algorithm is its simplicity and efficiency in solving Maxwell's equations. It is also a stable and accurate method, capable of handling a wide range of electromagnetic problems. Additionally, it is a versatile method that can be easily adapted to different boundary conditions and geometries.

5. What are some applications of the 1d FDTD Maxwell equation using the Yee algorithm?

The 1d FDTD Maxwell equation using the Yee algorithm has numerous applications in the fields of optics, electromagnetics, and photonics. It is commonly used to simulate and analyze the behavior of electromagnetic waves in various structures, such as waveguides, antennas, and photonic crystals. It is also used in the design and optimization of optical devices, such as filters, modulators, and sensors.

Similar threads

Replies
1
Views
4K
  • Programming and Computer Science
Replies
8
Views
6K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
5
Views
2K
  • Advanced Physics Homework Help
Replies
4
Views
1K
  • Programming and Computer Science
Replies
4
Views
3K
  • Atomic and Condensed Matter
Replies
8
Views
4K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
2
Views
1K
Back
Top