Lecture #6 Implementation of One‐ Dimensional FDTDemlab.utep.edu/ee5390fdtd/Lecture 6 --...
Transcript of Lecture #6 Implementation of One‐ Dimensional FDTDemlab.utep.edu/ee5390fdtd/Lecture 6 --...
7/21/2017
1
Lecture 6 Slide 1
EE 5303
Electromagnetic Analysis Using Finite‐Difference Time‐Domain
Lecture #6
Implementation of One‐Dimensional FDTD These notes may contain copyrighted material obtained under fair use rules. Distribution of these materials is strictly prohibited
Lecture Outline
Lecture 6 Slide 2
• Review of Lecture 5
• Sequence of Code Development
• FDTD Implementation
– Numerical boundary conditions
– Grid resolution
– Courant stability condition
– Perfect 1D boundary condition
– Sources
– Total number of iterations
– Revised FDTD Algorithm
7/21/2017
2
Lecture 6 Slide 3
Review of Lecture #5
Representing Functions on a Grid
Slide 4Lecture 6
A grid is constructed by dividing space into discrete
cells
Example physical
(continuous) 2D function
Function is known only at discrete points
Representation of what is
actually stored in memory
7/21/2017
3
3D Grids
Lecture 6 Slide 5
10, 10, 15x y zN N N
A three‐dimensional grid looks like this:
A unit cell from the grid looks like this:
x y
z
Lecture 6 Slide 6
Yee Cell for 1D, 2D, and 3D Grids
xy
z
xEyE
zE
xHyH
zH
3D Yee Grid2D Yee Grids1D Yee Grid
zE
xHyH
xy
xy
zHyE
xE
Ez Mode
Hz Mode
z
xE
yH
yExH
Ey Mode
Ex Mode
z
Benefits• Implicitly satisfies divergence equations• Naturally handles physical boundary conditions• Elegant approximation of the curl equations using finite‐differences
Consequences• Field components are in physically different locations• Field components may reside in different materials even if they are in the same unit cell• Field components will be out of phase
7/21/2017
4
Formulation of Update Equations (1 of 4)
0
0
H H
Slide 7Lecture 6
We normalized the magnetic field,
0 0
r rH EE H
c t c t
Assume linear, isotropic, and non‐dispersive materials and expand the curl equations.
0
0
0
y xx xz
yy yx z
y x zz z
H EH
y z c t
EH H
z x c t
H H E
x y c t
0
0
0
y xx xz
yy yx z
y x zz z
E HE
y z c t
HE E
z x c t
E E H
x y c t
Lecture 6 Slide 8
Formulation of Update Equations (2 of 4)
Finite‐Difference Equation for Hx Finite‐Difference Equation for Hy Finite‐Difference Equation for Hz
Finite‐Difference Equation for Ex Finite‐Difference Equation for Ey Finite‐Difference Equation for Ez
2 2
, , 1 , ,, 1, , ,
, , , ,, ,
0
t t
i j k i j ki j k i j k
t t t t
i j k i j ki
xj k
t t
z
xxx
y yz
H H
E E
y z
c t
E E
2 2
, , 1 , , 1, , , ,
, , , ,, ,
0
t t
i j k i j k i j k i j k
t t t t
i j k i j ki j
x x z z
y yk
ty yt
z x
E
c
H
E
H
t
E E
2 2
1, , , , , 1, , ,
, , , ,, ,
0
t t
i j k i j k i j k i j k
t t t t
i j k i j ki
y y x x
zj k
t tzzz
x y
c
E E E
H
t
E
H
2 2 2 2
, , , 1, , , , , 1
, , , ,, ,
0
t t t t
i j k i j k i j k i j k
t t t t
i j k i j ki j k
xx tx
z
t
z y
x t
y
y z
E E
H H
c
H
t
H
2 2 2 2
, , , , 1 , , 1, ,
, , , ,, ,
0
t t t t
i j k i j k i j k i j k
t t t t
i j k i j ki j k
yy ty
x
t
x z
y t
z
z x
E E
H H
c
H
t
H
2 2 2 2
, , 1, , , , , 1,
, , , ,, ,
0
t t t t
i j k i j k i j k i j k
t t t t
i j k
y y x
i j ki j k
zz t t tz
x
z
H H H H
x y
E E
c t
7/21/2017
5
Formulation of Update Equations (3 of 4)
Slide 9Lecture 6
We assumed the problem was uniform in the x and y directions.
0x y
Maxwell’s equations separated into two sets of equations.
0
0
0
0
yy yx
y xx x
y xx x
yy yx
HE
z c t
H E
z c t
E H
z c t
EH
z c t
2 2
2 2
2 2
2 2
1
0
0
1
0
1
1
0
t t
t t
t t
t t
k ky y
k ky
k kx x
k kx x
k ky
kt tyyt t
kt t xx t t t
kt t yy t t t
kt tt t x
y
k kx x
k k
y
k
xy y xk
x
z c t
z c t
z c t
z c
E E
E
H H
t
E
E E
E E
H H
H H
H H
Formulation of Update Equations (4 of 4)
Slide 10Lecture 6
We derived update equations by solving the finite‐difference equations for the future time value.
2 2
2 2
1
1
t t
t t
k ky y
k k
k kx x
k k
k t tHxt t
t tkEyy yt t
x
t
x
H mz
m
E E
E
H
H HE
z
0
0
kEy k
yy
kHx k
xx
c tm
c tm
We arrived at the following FDTD algorithm.
0 0 k kEy Hxk k
yy xx
c t c tm m
2 2
1
t t
k t tHx
k k
kx tx
y
t
yk mHE
HE
z
2 2
1t tt tk
Eyt t t
kx
k ky y
kx
E mEH
z
H
Loop over z
Loop over z
Includes:• Basic FDTD engine
Excludes:• Dirichlet BC’s• Calculate source parameters• Simple soft source• Perfectly absorbing BC’s• TF/SF source• Fourier transforms• Reflectance/Transmittance• Calculate grid parameters• Incorporate device
7/21/2017
6
Lecture 6 Slide 11
Sequence of Code Development
Lecture 6 Slide 12
Step 1 – Basic FDTD Algorithm
• Basic update equations
7/21/2017
7
Lecture 6 Slide 13
Step 2 – Add Simple Soft Source
• Basic update equations• Add a soft source
Lecture 6 Slide 14
Step 3 – Add Absorbing Boundary
• Basic update equations• Add a soft source• Add perfect boundary
condition
7/21/2017
8
Lecture 6 Slide 15
Step 4 – Add TF/SF
• Basic update equations• Add a soft source• Add perfect boundary
condition• Incorporate TF/SF “one‐
way” source
Lecture 6 Slide 16
Step 5 – Move Source & Add T/R
• Basic update equations• Add a soft source• Add perfect boundary
condition• Incorporate TF/SF “one‐
way” source• Move position of source• Calculate transmittance
and reflectance
7/21/2017
9
Lecture 6 Slide 17
Step 6 – Add Device (Complete Algorithm)
• Basic update equations• Add a soft source• Add perfect boundary
condition• Incorporate TF/SF “one‐
way” source• Move position of source• Calculate transmittance
and reflectance• Add a real device
Lecture 6 Slide 18
Summary of Code Development Sequence
Step 1 – Implement basic FDTD algorithm Step 2 – Add the source
Step 3 – Add absorbing boundary Step 4 – Add “one‐way” source
Step 5 – Calculate transmittance and reflectance
Step 6 – Add a device
7/21/2017
10
Lecture 6 Slide 19
NumericalBoundary Conditions
Lecture 6 Slide 20
A Problem at the Boundary of the Grid
2 2
1
t t
k t tHx
k k
kx tx
y
t
yk mHE
HE
z
We must implement the update equations for every point in the grid.
1
What do we do at ?
does not exist.zNy
z
E
k N
2 2
1t tt tk
Eyt t t
kx
k ky y
kx
E mEH
z
H
0
What do we do at 1?
does not exist.xH
k
7/21/2017
11
Lecture 6 Slide 21
Dirichlet Boundary Condition
2 2
2 2
1
0
t t
z
t t
z
z z
k t tHx zt t
N tHx
k kyk k
x x
N Nx x
y
zt t
y
N
Em k N
z
m k N
H H
H Hz
E
E
2 2
2
1
1 1 1
1
1
1 0
t t
t
k ky y
y
t tkEyt t t
t
Eyt t t
k k
y
x x
x
H H
H
m kz
m k
E E
Ez
E
One easy thing to do is assume the fields outside the grid are zero. This is called a Dirichlet boundary condition.
We modify the update equations as follows.
Lecture 6 Slide 22
Equations MATLAB Code
2 2
2 2
1
0
t t
z z z z
t t
k k k k kx x Hx y y zt tt t
N N N Nx x Hx y ztt t
H H m E E k N
H H m E k N
1 1 1 1
2
1
2 2
1
1
0ty y Ey xt t t t
k k k k kt ty y Ey x xt t t t t
E E m H k
E E m H H k
Update Equations
%% MAIN FDTD LOOP%for T = 1 : STEPS
% Update H from E (Dirichlet Boundary Conditions)for nz = 1 : Nz-1
Hx(nz) = Hx(nz) + mHx(nz)*(Ey(nz+1) - Ey(nz))/dz;endHx(Nz) = Hx(Nz) + mHx(Nz)*(0 - Ey(Nz))/dz;
% Update E from H (Dirichlet Boundary Conditions)Ey(1) = Ey(1) + mEy(1)*(Hx(1) – 0)/dz;for nz = 2 : Nz
Ey(nz) = Ey(nz) + mEy(nz)*(Hx(nz) - Hx(nz-1))/dz;end
end
DO NOT use ‘if’ statements to implement boundary conditions.
7/21/2017
12
Lecture 6 Slide 23
Periodic Boundary Condition
2 2
2 2
1
1
t t
t t
z
k t tHx zt t
k t
k
tHx zt t
ky y
N
k kx x
k k y
x x
y
m k Nz
m k Nz
H
E
E E
E
H
H H
2 2
2 2
1
1
1
1
z
t t
t t
k ky y
k ky y
t tkEyt t
N
t
t tk
k k
Ey
x
t
x x
x
t t
m kz
m kz
EH
E
EH
E
H
H
Some devices are periodic along a particular direction. When this is the case, the field is also periodic.
We modify the update equations as follows.
z
perio
dic
perio
dic
Lecture 6 Slide 24
Grid Resolution
7/21/2017
13
Lecture 6 Slide 25
Consideration #1: Wavelength
The grid resolution must be sufficient to resolve the shortest wavelength.
N Comments
10 to 20 Low contrast dielectrics
20 to 30 High contrast dielectrics
40 to 60 Most metallic structures
100 to 200 Plasmonic devices
0min
max max
c
f n nmax is the largest refractive index found
anywhere in the grid. fmax is the maximum frequency in your simulation.
First, you must determine the smallest wavelength:
min 10NN
Second, you resolve the wave with at least 10 cells.
Lecture 6 Slide 26
Consideration #2: Mechanical Features
The grid resolution must be sufficient to resolve the smallest mechanical features of the device.
mind
Unit cell of a diamond lattice
1dN 4dN 1dN 1dN
mind
First, you must determine the smallest feature:
min 1d dd
dN
N
Second, you must divide this by 1 to 4.
7/21/2017
14
Calculating the Initial Grid Resolution
Must resolve the minimum wavelength
min 10NN
x
Must resolve the minimum structural dimension
min 1d dd
dN
N
Set the initial grid resolution to the smallest number computed above
min ,x y d
y
Slide 27Lecture 6
Lecture 14 Slide 28
Resolving Critical Dimensions (1 of 3)
We have not yet considered the actual dimensions of the device we wish to simulate.
This means we likely cannot resolve the exact dimensions of a device.
Not an exact fit.We cannot fill a fraction of a cell.
x
yd
Suppose we wish to place a device of length d onto a grid.
7/21/2017
15
Lecture 14 Slide 29
Resolving Critical Dimensions (2 of 3)
To fix this, we first calculate how many cells N are needed to resolve the most important dimension. In this case, let this be d.
x
yd
x
dN
10.5 cellsN
Second, we determine how many cells we wish to exactly resolve d. We do this by rounding N up to the nearest integer.
ceilx
dN
11 cellsN
Lecture 14 Slide 30
Resolving Critical Dimensions (3 of 3)
Third, we adjust the value of x to represent the dimension d exactly.
x
yd
x
d
N
11 cellsN
We call this step “snapping” the grid to a critical dimension.
Unfortunately, using a uniform grid, we can only do this for one dimension per axis.
7/21/2017
16
“Snap” Grid to Critical Dimensions
Decide what dimensions along each axis are critical
Compute how many grid cells comprise dc, and round UP
ceil
ceil
x x x
y y y
M d
M d
Typically this is a lattice constant or grating period along x Typically this is a layer thickness along y
and x yd d
initial grid
critical dim
ensio
n
Slide 31Lecture 6
Adjust grid resolution to fit this dimension in grid EXACTLY
x x x
y y y
d M
d M
ad
justed
grid
critical dim
ensio
n
decrease
Lecture 6 Slide 32
Courant Stability Condition
7/21/2017
17
Lecture 6 Slide 33
Numerical Propagation Through Grid
During a single iteration, a disturbance in the electric field at one point can only be felt by the immediately adjacent magnetic fields. It takes at least two time steps before that disturbance is felt by an adjacent electric field. This is simply due to how the update equations are implemented during a single iteration.
z
Lecture 6 Slide 34
Physical Propagation Through Space
Electromagnetic waves propagate at the speed of light in a vacuum. Inside a material, they propagate at a reduced speed.
z
00 299792458 m s refractive index
cv c n
n
7/21/2017
18
Lecture 6 Slide 35
A Limit on t
zNumerical distance covered in one time step:
Physical distance covered in one time step: 0c t n
Over a time duration of one time step t, an electromagnetic disturbance will travel:
Because of the numerical algorithm, it is not possible for a disturbance to travel farther than one unit cell in a single time step.
We need to make sure that a physical wave would not propagate farther than a single unit cell in one time step.
0c tz
n
This places an upper limit on the time step.
0
n zt
c
n should be set to the smallest refractive index found anywhere
in the grid. Usually this is just made to be 1.0 and dropped from the equation.
Lecture 6 Slide 36
The Courant Stability Condition
Refractive index is greater than or equal to one, so our condition on tcan be written more simply as:
0
zt
c
For 2D or 3D grids, the condition can be generalized as
0 2 2 2
1
1 1 1t
cx y z
The Courant stability condition
Sort of a worst case.n=1 produces the fastest possible physical wave.
7/21/2017
19
Lecture 6 Slide 37
Practical Implementation of the Stability Condition
The stability condition will be most restrictive along the shortest dimension of the grid unit cell.
min min , ,x y z
This can be generalized to account for special cases.
min min
02
nt
c
1. Your grid is filled with dielectric and travels slower
everywhere.2. Your model includes dispersive materials with
refractive index less than one.
A good equation to ensure stability and accuracy on any grid is then
min
02t
c
Note: A factor of 0.5 was included here as a safety margin.
Lecture 6 Slide 38
Time Step for Our 1D Grid
bc
02
n zt
c
nbc = refractive index at the grid boundaries.
This means a wave will travel the distance of one grid cell in exactly two time steps.
It is a necessary condition for the perfect boundary condition we will soon implement.
This implies that we cannot have different materials at the two boundaries using this boundary condition.
7/21/2017
20
Lecture 6 Slide 39
Perfect 1D Boundary Condition
z
Lecture 6 Slide 40
The Problem
The finite‐difference equation here requires knowledge of the electric field outside of the grid.
2 2
1z
t t
z
z
z k t tHxt
N Nx x
Ny y
t
NE EH
zH m
7/21/2017
21
Lecture 6 Slide 41
Implementing the Perfect Boundary Condition
Then…
1
2
z z
t t t
N Ny yE E
2 time steps later
z
If and only if…
• the field is only travelling outward at the boundaries,• the materials at the boundaries are linear, homogeneous, isotropic and non‐dispersive,
• The refractive index at both boundaries is nbc,• t = nbcz/(2c0) exactly.
Lecture 6 Slide 42
Visualizing the Perfect Boundary Condition
0 0 0 0 0 0 0 0 0 0 0 0 3 4 3 2 1 0T = 9 0 0
0 0 0 0 0 0 0 0 0 0 0 0 2.5 3.5 3.5 2.5 1.5 0.5T = 10 0 0
0 0 0 0 0 0 0 0 0 0 0 0 2 3 4 3 2 1T = 11 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1.5 2.5 3.5 3.5 2.5 1.5T = 12 0.5 0
0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 3 2T = 13 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0.5 1.5 2.5 3.5 3.5 2.5T = 14 1.5 0.5
0 0 0 0 0 0 0 0 0 0 0 0 2 1 0 0 0 0T = 3 0 0
0 0 0 0 0 0 0 0 0 0 0 0 2.5 1.5 0.5 0 0 0T = 4 0 0
0 0 0 0 0 0 0 0 0 0 0 0 3 2 1 0 0 0T = 5 0 0
0 0 0 0 0 0 0 0 0 0 0 0 3.5 2.5 1.5 0.5 0 0T = 6 0 0
0 0 0 0 0 0 0 0 0 0 0 0 4 3 2 1 0 0T = 7 0 0
0 0 0 0 0 0 0 0 0 0 0 0 3.5 3.5 2.5 1.5 0.5 0T = 8 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0T = 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1.5 0.5 0 0 0 0T = 2 0 0
7/21/2017
22
Lecture 6 Slide 43
Summary of the 1D Perfect Boundary Condition
Conditions• Waves at the boundaries are only travelling outward,• Materials at the boundaries are linear, homogeneous, isotropic and non‐dispersive,• The refractive index is the same at both boundaries and is nbc,• Time step is chosen so physical waves travel 1 cell in exactly two time stepst = nbcz/(2c0).
Implementation at z‐Low BoundaryAt the z‐low boundary, we need only modify the E‐field update equation.
23
3 2 2 1 11 1
1
1
t
y
tkEy
x
x yt t t
hh Eh h h h m
zH E
H
Implementation at z‐High BoundaryAt the z‐high boundary, we need only modify the H‐field update equation.
2 2
3
3 2 2 1 1 z
z z
t t
z k tHx
N Nx xt t
NyN
y
ee
EEe He He e m
z
Lecture 6 Slide 44
Sources
7/21/2017
23
Lecture 6 Slide 45
The Gaussian Pulse
In FDTD, we typically use short pulses as sources. This approximates an impulse function so we can excite a single simulation with a broad range of frequencies at the same time.
1 e
0t 0t 0t
2
0expt t
g t
Lecture 6 Slide 46
Frequency Content of Gaussian Pulse
The Fourier transform of a Gaussian pulse is another Gaussian function.
2 2
2 2maxmax
1exp G exp
t fg t f
ff
max
1f
The frequency content of the Gaussian pulse extends from DC up to above fmax. The frequency fmax is actually the 1/e point of the frequency spectrum.
maxf
max
1 1
e f
max
1
f
Frequency
G f
0
7/21/2017
24
Lecture 6 Slide 47
Designing the Pulse Source (1 of 2)
Step 1: Determine the maximum frequency of interest in your simulation.
maxf
Step 2: Compute the pulse duration to have sufficient energy at fmax.
maxmax
1 1 f
f
max
0.5
f
Step 3: You may need to reduce your time step. Your Gaussian pulse should be resolved by at least 10 to 20 time steps.
t
tN
Typically, you determine a first t based on the Courant
stability condition, then determine a second t based on resolving the maximum frequency, and finally go with the smallest value of the two t’s.
All of this should be satisfied automatically if t = nz/(2c0).10tN
Lecture 6 Slide 48
Designing the Pulse Source (2 of 2)
Step 4: Compute the delay time t0
0 6t The pulse source must start at zero and gradually increase. NO STEP FUNCTIONS!!
WRONG!!The step function at the beginning will induce very large field gradients.
0 0t
t
STILL WRONG!!While better, this source still starts with a step function that will produce large field gradients.
0t
t
CORRECT!!This source “eases” into the Gaussian source.
0 6t
t
7/21/2017
25
Visualizing the Arrays
Lecture 6 49
z Usually several hundred points.
Ey, Hx, ER, UR, mEy, and mHx are stored in arrays of length Nz.
tUsually several
thousand time steps.
gE is stored in an array of length STEPS.
Lecture 6 Slide 50
Two Ways to Incorporate a Simple Source
Source #1: Simple Hard SourceThe simple hard source is the easiest to implement. After updating the field across the entire grid, one field component at one point on the grid is overwritten with the source. This approach injects power into the model, but the source point behaves like a perfect electric conductor or perfect magnetic conductor and will scatter waves.
2
and/or t H Ek kt tt yx
kk g EH g OVERWRITE
Not usually a practical source.We won’t use it.
Source #2: Simple Soft SourceThe simple soft source is better than the hard source because it is transparent to scattered waves passing through it. After updating the field across the entire grid, the source function is added to one field component at one point on the grid. This approach injects power into the model in both directions. It is great for testing boundary conditions.
2 2
and/or t t
k kx x H Ek kt t
ky t tt
kyt
H H E gEg
ADD TORarely used.Use this until we learn TF/SF.
7/21/2017
26
Movie of Source #1 – Simple Hard Source
Lecture 6 51
Movie of Source #2 – Simple Soft Source
Lecture 6 52
7/21/2017
27
Movie of Source #3 – TF/SF Soft Source
Lecture 6 53
Lecture 6 Slide 54
Total Number of Iterations
7/21/2017
28
Considerations for Estimating the Total Number of Iterations
Lecture 6 55
The total number of iterations depends heavily on the device being modeled and what properties of it are being calculated.
Device Considerations1. Highly resonant devices typically require more iterations.2. Purely scattering devices typically require very few iterations.3. More iterations are needed the more times the waves bounce
around in the grid.
Information Considerations1. Calculating abrupt spectral shapes requires many iterations.2. Calculating fine frequency resolution requires many iterations.3. Calculating only the approximate position of resonances often
requires fewer iterations. Great for hunting resonances!
Lecture 6 Slide 56
A Rule of Thumb
How long does it take a wave to propagate across the grid (worst case)?
maxprop
0
distancetime
velocityzn N z
tc
Simulation time T must include the entire pulse of duration .12T
Simulation time should allow for 5 bounces.
prop5T t
A rule‐of‐thumb for total simulation time is then
prop12 5T t Note: For highly resonant devices, this will NOT be enough time!
Given the time step t, the total number of iterations is then
STEPS roundT
t
This must be an integer quantity.
7/21/2017
29
Lecture 6 Slide 57
Revised FDTD Algorithm
Lecture 6 Slide 58
Revised FDTD Algorithm
Finished!
Compute Grid Resolution
2 2
2 23
1t t
z z z z
t t
k k k k kx x Hx y y zt tt t
N N N Nx x Hx y ztt t
H H m E E z k N
H H m E z k Ne
min minmin ,
round
d
c
c
dz
N N
N d z
z d N
Update H from E
no
Compute Time Step bc 02t n z c
Compute Source
max 0
2
0
0.5 5
exp
f t
t tg t
Compute Update Coeff’s0 0 k k
Ey Hxk kyy xx
c t c tm m
Initialize Fields0k k
y xE H
1 1 1 1
2
1
2
3
2
1
1
ty y Ey xt t t t
k k k k kt ty y Ey x xt t t t t
E E m H z k
E E m H H z k
h
Update E from H
src srck ky y tt t t
E E g
Inject Source
Visualize fields
Done?yes
2
13 2 2 1 1, ,
tx th h h h h H
Record H‐Field Boundary Term
3 2 2 1 1, , Nzy t t
e e e e e E
Record E‐Field Boundary Term
z
z
Loop over time
t
Build DeviceERyy and URxx
Initialize Boundary Terms
3 2 1 3 2 1 0h h h e e e
Includes:• Basic FDTD engine• Dirichlet BC’s• Calculate source parameters• Simple soft source• Perfectly absorbing BC’s
Excludes:• TF/SF source• Fourier transforms• Reflectance/transmittance• Calculate grid parameters• Incorporate device
7/21/2017
30
Lecture 6 Slide 59
Equations MATLAB Code
min minmin ,
round
d
c
c
dz
N N
N d z
z d N
Grid Resolution % COMPUTE DEFAULT GRID RESOLUTIONdz1 = min(LAMBDA)/nmax/NRES;dz2 = dmin/NDRES;dz = min(dz1,dz2);
% SNAP GRID TO CRITIAL DIMENSIONSN = ceil(dc/dz);dz = dc/N;
2 2
2 2 2
1
t t
z z z z
t t
z
k k k k kx x Hx y y zt tt t
N N N Nx x H
Nyx yt ztt t t
H H m E E k N
H H m E kE N
1
2 2
1 1 1 1
22
1
2
1
1t
k k k k kt ty y Ey x xt t t t t
ty y Ey xt t x tt tt
E E m H H k
E H kHE m
Update Equations
%% MAIN FDTD LOOP%for T = 1 : STEPS
% Update H from E (Perfect Boundary Conditions)for nz = 1 : Nz-1
Hx(nz) = Hx(nz) + mHx(nz)*(Ey(nz+1) - Ey(nz))/dz;end Hx(Nz) = Hx(Nz) + mHx(Nz)*(E3 - Ey(Nz))/dz;H3=H2; H2=H1; H1=Hx(1);
% Update E from H (Perfect Boundary Conditions)Ey(1) = Ey(1) + mEy(1)*(Hx(1) – H3)/dz;for nz = 2 : Nz
Ey(nz) = Ey(nz) + mEy(nz)*(Hx(nz) - Hx(nz-1))/dz;endE3=E2; E2=E1; E1=Ey(Nz);
% Inject Soft SourceEy(nzsrc) = Ey(nzsrc) + g(T);
end
src srck ky y tt t t
E E g