Computation Improvement of the Finite Difference

advertisement
Computation Improvement of the Finite Difference
Time Domain Method for Electromagnetic
Radiation Simulation
A Report Submitted in Partial Fulfillment
of the Requirements for SYDE 750-7
Andrew D. Wiles, 96016017, MASc Candidate
Faculty of Engineering
Department of Systems Design Engineering
Course Instructor: Professor G. J. Savage
August 16, 2004
Abstract
An implementation of the finite-difference time-domain method using the alternatedirection implicit method in order to solve Maxwell’s equations for electromagnetic
radiation is tested. As a baseline, the traditional finite-difference time-domain method
is first run and the new algorithm is compared against it. Unfortunately, the so called
computation reduced method was not found to be successful in reducing the number
of computations.
Results of the simulation for a z-directed line source radiator showed that the
alternate-direction implicit method worsened the computation time for several different model configurations. It also provided results that were significantly different
than the traditional methods including a phase shift in the measured signals and an
additional attenuation of the signal. Further, it was observed that an appropriate
set of absorbing boundary conditions would be useful in maintaining stability and
providing useful results.
i
Contents
1 Introduction
1
2 Finite-Difference Time-Domain Modelling Method
3
2.1
Traditional Yee Method . . . . . . . . . . . . . . . . . . . . . . . . .
3
2.2
FDTD-ADI Method
. . . . . . . . . . . . . . . . . . . . . . . . . . .
5
2.3
Other Computation Improvement Methods . . . . . . . . . . . . . . .
8
3 Experimental Results
3.1
3.2
9
Experiments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9
3.1.1
Excitation Pulse
. . . . . . . . . . . . . . . . . . . . . . . . .
9
3.1.2
Spatial Configurations . . . . . . . . . . . . . . . . . . . . . .
10
3.1.3
Time Steps for the FDTD-ADI . . . . . . . . . . . . . . . . .
10
Results and Discussion . . . . . . . . . . . . . . . . . . . . . . . . . .
10
4 Conclusions
15
A Matlab Simulation Code
16
A.1 FDTD Code using Yee’s Method . . . . . . . . . . . . . . . . . . . .
16
A.2 FDTD-ADI Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
23
A.3 Tridiagonal System of Equations Solver . . . . . . . . . . . . . . . . .
32
ii
Chapter 1
Introduction
There are many applications for the modelling of antennas and other radiating ojects
such as communications, position measurement techniques and electromagnetic interference simulation [1]. Clearly, Maxwell’s equations are the starting point when
simulating most electromagnetic systems, but they quickly become impossible to use
in an analytical form [2]. Therefore, numerical techniques have become very important in generating solutions to Maxwell’s equations in an accurate and efficient
manner.
The finite-difference time-domain method (FDTD) is one of the more popular
simulation methods in that it is simple and fairly easy to implement [3]. However, as
with all systems that contain a spatio-temporal set of equations to be solved, the level
of computation becomes excessive and onerous. For example, the simulation that is
completed in this report using the FDTD method takes 12.7 seconds to compute the
transverse magnetic components of an electric field for an area that is approximately
45cm by 45cm for a period of one nanosecond. Considering that most communication
systems span 10s of kilometers and that large pieces of information is being continuously encoded onto carrier signals, the FDTD method can become impossible to
compute or provide an accurate solution. Therefore, more efficient algorithms and
simpler representations are required to make the simulation of the electromagnetic
radiation feasible to perform.
In this report, a reformulation of the FDTD method is investigated. Specifically,
the FDTD is solved using the alternate-direction implicit method (ADI). The FDTDADI reconfigures the problem so that each time step has two sub-iterations where,
1
for the transverse magnetic case, the electric field is implicitly related to the magnetic
fields perpendicular to the electric field. Unfortunately, the implementation shown
here did not have the success of the previous researchers [4, 5]. In fact, the new
method was found to be worse due to the need to solve a large linear system for each
row and column in each time step. However, the remainder of the problem had very
little overhead, so if the time to compute the linear system could be reduced then the
algorithm would be much more efficient.
In this report, Chapter 2 describes the traditional FDTD method first presented by
Yee [6] followed by the ADI method which was expected to improve the computation
time. Chapter 3 provides a description of the actual results had with these methods
while Chapter 4 provides some concluding remarks.
2
Chapter 2
Finite-Difference Time-Domain
Modelling Method
The Finite-Difference Time-Domain (FDTD) method was developed by Yee in 1966 to
solve electromagnetic problems from Maxwell’s equations using a numerical method[6].
The algorithm steps through discretized space and time to solve for the electric and
magnetic fields generated by a scatterer under the influence of incoming EM waves
or from a radiating source that may exist in the region of interest. Originally for
an isotropic medium, the algorithm has been improved to handle an assortment of
materials including conductive ones [3].
2.1
Traditional Yee Method
Beginning from the continuous form of Maxwell’s equations [6, 2],
∂B
+ ∇ × E = 0,
∂t
∂D
− ∇ × H = J,
∂t
B = µH,
D = E,
(2.1)
(2.2)
(2.3)
(2.4)
where B is the magnetic flux density, E is the electric field intensity, D is the
3
electric flux density, H is the magnetic field intensity and is the electric permittivity
and µ is the magnetic permeability.
The FDTD method has been developed for one-dimensional, two-dimensional and
three-dimensional forms, but for simplicity here, the two-dimensional problem for the
transverse magnetic case will be discussed as found in Yee[6]. The finite difference
equations for the transverse magnetic case are
Ezn+1 (i, j) = Ezn (i, j)
1
1
n+
n+
∆t
1
1
2
2
+
Hy (i + 2 , j) − Hy (i − 2 , j)
0 ∆x
1
1
n+
n+
∆t
Hx 2 (i, j + 12 ) − Hx 2 (i, j − 12 ) , (2.5)
−
0 ∆y
n+
1
2
n+
1
2
Hy
Hx
(i +
n−
1
2
n−
1
2
1
)
2
=
Hy
1
, j)
2
=
Hy
(i, j +
1
)
2
−
∆t
[E n (i, j + 1) − Ezn (i, j)] , (2.6)
0 ∆y z
1
, j)
2
−
∆t
[E n (i + 1, j) − Ezn (i, j)] , (2.7)
0 ∆x z
(i, j +
(i +
where n denotes the time step for time point n∆t and (i, j) represent the discretized spatial positions for position (i∆x, j∆y). The “half-steps” are used to update the overlapping electric and magnetic fields. That is, the magnetic fields are
updated on the
1
2
time and space steps while the electric fields are updated on the
full time and space steps. Useful diagrams for both the two-dimensional case and the
three-dimensional case are given in Sullivan [3]. To solve for the electric and magnetic
fields, the algorithm steps through each time and spatial step updating the equations
as shown in appendix A.1.
The FDTD method as presented by Yee has a weakness at the boundaries of
the simulation region because without any boundary conditions outgoing waves will
reflect at the boundary and continue to propagate throughout the region instead of
continuing outwards. Several methods have been investigated to absorb the outgoing
waves but the most popular and robust is clearly Berenger’s perfectly matched layers
for absorbing boundary conditions[7]. Berenger’s PML method uses the permeability
4
and permittivity properties together to cause propagating waves to cancel at the
edges. Further discussion is beyond the scope of this report since it was not actually
used in the simulations.
Prior to starting the algorithm the size of the spatial steps and the time steps must
be determined. For stability and accuracy, the spatial step size must be significantly
smaller than the largest wavelength being modelled. Typically, the ratio is 10-20
times smaller than the largest wavelength, i.e. ∆d < λmax /10 [6, 3, 5] where ∆d is
the cell dimension for a given axis. In general, the cell size can be specified differently
for each axis but for simplicity here the cell size has been set to the same size in both
axes.
The conditions surrounding ∆t are much more stringent where the size of the time
step is dependent on the dimension of the problem. For a simulation in free space ∆t
is governed by the Courant condition,
∆t ≤ √
∆d
,
nd · c0
(2.8)
where nd is the dimension of the problem, i.e. 2 for the two-dimensional transverse
magnetic case that was presented above and c0 is the speed of light.
The size of the problem space in association with the sizes of the time step and
spatial steps is what causes the FDTD to become computationally challenging. Since
the time step is inversely proportional to the speed of light then the time steps
are typically in the nano- or picosecond range. A simulation that spans over a ten
second period becomes onerous at best. With this in mind, this report compares
the traditional method with the FDTD-ADI, discussed in section 2.2, in regards to
accuracy and improving the amount of computation. The simulation code for the
tradiational Yee method can be found in appendix A.1.
2.2
FDTD-ADI Method
The Alternating-Direction Implicit (ADI) method was first introduced to assist in
solving partial differential equations [8] hence being an appropriate choice of method
here. In general the ADI method has not become prevalent as it has been superceded
by other methods such as the multigrid method, also presented in Press [8].
5
However, the ADI method has become useful in improving the computation time
of the FDTD as first published in 1999 by Namiki [4] and Zheng et al. [5]. Namiki
had published a two-dimensional method while Zheng et al. began with a threedimensional model. In 2000, Namiki published his three-dimensional solution [9] and
then, in association with one of his colleagues, Namiki published his error analysis
of the two-dimensional method one month later [10]. In 2002, Zhao published two
important tips for the implementation of the FDTD-ADI method [11] and Wang et
al. explained how to implement Berenger’s PML absorbing boundary condition when
using the FDTD-ADI method [12].
The FDTD-ADI method is based on rewriting equations (2.5) - (2.7) into two
sub-iterations, also known as half-time steps, called the first and second procedure
respectively [4]. The transverse magnetic equations from [10] are shown below1 .
First Procedure
n+
Hx
1
n+
Hy 2 (i
1
n+
2
Ez (i, j)
+
1
2
∆t
[Ezn (i, j + 1) − Ezn (i, j)]
2µ∆y
(2.9)
1
1
n+
n+
∆t
2
2
−
Ez (i + 1, j) − Ez (i, j)
2µ∆x
(2.10)
(i, j + 12 ) = Hxn (i, j + 12 ) −
1
, j)
2
=
Hyn (i
+
1
, j)
2
= Ezn (i, j)
1
1
n+
n+
∆t
1
1
2
2
+
Hy (i + 2 , j) − Hy (i − 2 , j)
2∆x
∆t n
−
Hx (i, j + 12 ) − Hxn (i, j − 12 ) (2.11)
2∆y
Second Procedure
n+
Hxn+1 (i, j + 12 ) = Hx
Hyn+1 (i
1
+
1
, j)
2
=
1
2
(i, j + 12 ) −
1
n+
Hy 2 (i
+
1
, j)
2
∆t n+1
Ez (i, j + 1) − Ezn+1 (i, j)
2µ∆y
1
1
n+
n+
∆t
2
2
−
Ez (i + 1, j) − Ez (i, j)
2µ∆x
(2.12)
(2.13)
Note that this author has added a factor of 1/2 in the spatial derivative terms on the RHS. This
was omitted from the paper published by Namiki [10] but appears in his original work [4].
6
n+
Ezn+1 (i, j) = Ez
1
2
(i, j)
1
1
n+
n+
∆t
1
1
2
2
Hy (i + 2 , j) − Hy (i − 2 , j)
+
2∆x
∆t n+1
Hx (i, j + 12 ) − Hxn+1(i, j − 12 ) (2.14)
−
2∆y
In this form, the equations cannot be solved directly but must be solved implicitly.
Therefore, in the first sub-iteration equation (2.10) is substituted into equation (2.11)
n+
to eliminate the Hy
1
2
n+
term so that Ez
1
2
n+
can be found by equation (2.15). The Hy
1
2
can then be solved directly by equation (2.10). Similarly in the second procedure,
equation (2.12) is substituted into (2.14) to eliminate Hxn+1 term so that Ezn+1 can
be found by equation (2.19). Again, Hxn+1 can be found from equation (2.12).
n+
αEz
1
2
n+
1
2
n+
1
(i, j) + γEz 2 (i + 1, j)
∆t n
Hy (i + 12 , j) − Hyn (i − 12 , j)
= Ezn +
2∆x
∆t n
Hx (i, j + 12 ) − Hxn (i, j − 12 ) (2.15)
−
2∆x
(i − 1, j) + βEz
where
∆t
2µ∆x
∆t
γ =−
2µ∆x
α=−
∆t
2∆x
∆t
·
2∆x
·
β =1 − α − γ.
(2.16)
(2.17)
(2.18)
αEzn+1 (i, j − 1) + βEzn+1 (i, j) + γEzn+1 (i, j + 1)
1
1
1
n+
n+
n+
∆t
1
1
= Ez 2 +
Hy 2 (i + 2 , j) − Hy 2 (i − 2 , j)
2∆y
1
1
n+
n+
∆t
1
1
2
2
Hx (i, j + 2 ) − Hx (i, j − 2 ) (2.19)
−
2∆x
7
where
∆t
2µ∆y
∆t
γ =−
2µ∆y
α=−
∆t
2∆y
∆t
·
2∆y
·
β =1 − α − γ.
(2.20)
(2.21)
(2.22)
Obviously, in both sub-iterations α, β and γ are identical if ∆x is set to the same
size of ∆y. Also, α and γ are equal here, however, Namiki [10] had taken non-uniform
material properties into account hence α and γ could be generalized to be a function
of the spatial indices i, j.
Equations (2.15) and (2.19) form a linear systems of equations for row i and
column j respectively. This linear system is of the form Ax = b and A has the form
of a tridiagonal matrix. There are several ways to solve this system but Zhao has
suggested a method that ensures stability [11] because the method suggested in Press
can become unstable [8]. See appendix A.3 for the code that implements the solver
suggested by Zhao.
This method was also implemented in Matlab and the code can be found in appendix A.2. However, Berenger’s PML absorbing conditions [7, 12] were not included
as it was found to be very complicated to implement.
2.3
Other Computation Improvement Methods
While the FDTD-ADI is one method that is being investigated to reduce computation
time by allowing the time step to be relaxed, multiresolution time domain schemes are
being used to relax the size of the spatial cell size, hence reducing the computation
across the spatial domain [13]. Although, this is an area of active research, the
FDTD-ADI method will be focused upon in this report.
8
Chapter 3
Experimental Results
This section is separated into two sections where first the experiments that were
performed are described and then the results are presented and discussed. The ultimate goal was to compare the results from the FDTD using Yee’s method with the
FDTD-ADI method for a variety of spatial sizes. There were no absorbing boundary
conditions implemented but the PML solution should be investigated in the future.
The simulations with the first method were performed with the code in appendix A.1
while the FDTD-ADI simulations were performed with the code in appendix A.2.
3.1
3.1.1
Experiments
Excitation Pulse
The system of interest is a z-directed line source in free space which radiates a signal
as the surface current in the line changes. Although the actual line source can be
modelled using a Thevinen or Norton equivalent it was decided to bypass this part
for now and simply apply a given signal applied to cell (ic , jc ) as shown in equation
3.1. This is a “soft-source” excitation since the source is simply added to the field
rather than replacing the field at the source site. The period was set to T ≈ 5.0ps
and each simulation was computed for one nanosecond.
Ezn (ic , jc ) = Ezn−1 + sin(
9
2π
n∆t)
T
(3.1)
The excitation pulse is applied at every time step in the simulation. However,
some care needs to be had in applying the excitation in the FDTD-ADI since there
are two sub-iterations for each time step. Zhao[11] suggests that one of two methods
can be used, (i) the full excitation pulse can be applied in the first procedure and
none in the second procedure or (ii) a fraction of the excitation pulse can be applied
in each procedure as long as the full signal is applied for the given time step. In this
work, neither version seemed to provide much difference in the results and so the first
method was chosen for simplicity, but future work would involve investigating this
further.
3.1.2
Spatial Configurations
The z-directed line source is considered to always be at the center of the simulation
region and that the Ez field is the value of interest. Therefore, the simulation region
has been discretized into squares of 3mm by 3mm. The cell size was held constant for
all simulations but the simulation region was varied from a 100 by 100 region of cells
to 300 by 300 simulation region. The full list is shown in the first column of table 3.2.
3.1.3
Time Steps for the FDTD-ADI
The main purpose of the FDTD-ADI method is to be able to increase the size of
the time step without the restrictions of the Courant condition in equation (2.8).
Therefore, the FDTD-ADI was tested with five different time steps that were a scaled
value of the time step in the standard FDTD as in follows.
∆tF DT DADI = θ∆tY ee
(3.2)
In this report, results are presented for θ = 1, 2, 4, 5, 10 and the simulation was
run for one nanosecond in each case.
3.2
Results and Discussion
Figure 3.1 shows the typical output of the Yee FDTD simulation. The center of the
concentric circles contains the z-directed line source and the coloured rings represent
10
Figure 3.1: Sample Ez Field at n=100. The colour plot shows the electric field for the
transverse magnetic problem using Yee’s Method for the 150 by 150 problem. The
maxima are in the blue region while the minima are in the red-yellow range.
maxima (blues) and minima (reds and yellow). A moving animation for each time
step will show the actual wave propagation as the results are being computed. The
moving animations were created for each case and they all showed similar behaviour
qualitatively.
The run times for the various simulation region sizes and their associated FDTD
simulation configuration is shown in table 3.2, while figure 3.2 contains the results
for 150 by 150 simulation region at six different locations throughout the region.
Unfortunately, the run times were not improved by the FDTD-ADI method. This
could be because of many things which need to be investigated further. First, the
simulation was run on a 2.8GHz Computer with a Pentium 4 processor with 1 gigabyte
11
of RAM running the Windows XP Professional operating system. Unfortunately, the
Windows operating systems have a lot of hidden processes that were not turned off
during the running of the simulation and therefore may have caused a small inflation
in the run times recorded. Future simulations are likely better to be performed on a
Linux or Unix system where the priority level can be set explicitly.
However, the discrepancy between the two methods is still significant. So the
Matlab profiler was run for the FDTD-ADI method for the 150 by 150 case with
θ = 4. It was quite clear that a problem exists with the algorithm because the linear
solver for the tridiagonal matrix accounts for nearly 88% of the computation time in
the simulation. So clearly, a more efficient linear solver needs to be found to make
the FTDT-ADI useful. This result does seem unusual since the linear solver that was
implemented was provided by Zhao who had presented the alternative algorithm to
ensure stability and also claimed it to be efficient.
Further, the accuracy of the FDTD-ADI algorithm can be questioned using the
results presented in figure 3.2. At each of the locations in the volume the signal seems
to be shifted approximately π/4 radians (90o). Also, the FDTD-ADI method tends
to cause the system to decay faster as the amplitudes at 12mm are almost negligible
for the FDTD-ADI method while the signal for the Yee method is still quite strong.
Both issues may be due to how the simulation is excited as mentioned in section 3.1.1.
That is, perhaps the input signal is shifted in time depending on when the excitation
is applied within the FDTD-ADI sub-iterations.
Finally, it was observed that the FDTD-ADI algorithm did occasionally go unstable midway through the simulation at the simulation region boundaries. The unstable
behaviour would then propagate through the volume. It is expected that this could
be corrected if Berenger’s perfectly matched layers [7, 12] are used for the absorbing
boundary constraints.
12
E field at 3mm to the right of the source
E field at 3mm to the above of the source
z
z
10
Ez
Ez
10
0
−10
−10
0
0.2
0.4
0.6
0.8
1
Ez field at 6mm to the right of the source
0
0.2
0.4
0.6
0.8
1
Ez field at 6mm to the above of the source
10
Ez
10
Ez
0
0
−10
0
−10
0
0.2
0.4
0.6
0.8
1
E field at 12mm to the right of the source
0
0.2
0.4
0.6
0.8
1
E field at 12mm to the above of the source
z
z
10
Ez
Ez
10
0
−10
0
−10
0
0.2
0.4
0.6
Time (ns)
0.8
1
0
0.2
0.4
0.6
Time (ns)
0.8
1
Figure 3.2: Sample results for six different locations relative to the excitation source.
The black solid curve is the result using the Yee simulation, the blue dashed curve
is the FDTD-ADI method with θ = 1 and the green dotted curve is result for the
FDTD-ADI method where θ = 2.
13
Table 3.1: Run times in seconds for several configurations of the simulation are shown
here in the table. The no. of cells refers to the number of discretizations in one
direction (x or y). In the first case, 100 cells means that the simulation is solved for a
100 by 100 grid. The Yee times are the run times for each spatial configuration using
the traditional Yee method as discussed in section 2.1. The remaining columns are
run times for the FDTD-ADI method where θ refers to the ratio of the time step in
the Yee method relative to the actual time step used.
No. of cells
Yee
θ=1
θ=2
θ=4
θ=5
θ = 10
100
7.761
227.067
122.646
61.028
49.311
14.091
150
12.728
513.629
246.054 114.965
89.388
35.491
200
20.800
994.706
437.509 225.875
93.204
46.767
250
33.748
946.110
499.440 311.078 234.337 136.476
300
66.566 1949.964 1074.957 493.139 395.018 197.414
14
Chapter 4
Conclusions
In this implementation of the FDTD method for electromagnetic simulation, the ADI
method does not reduce the computation time of the traditional FDTD method. In
fact, the solution time is increased significantly with most of the computation overhead residing in the solution of the tridiagonal system of equations that needs to be
solved as a result of the reformulation for the ADI solution. Also, this implementation causes the phase of signal measured from the FDTD-ADI solution to shift by 90
degrees and is attenuated much faster. This is potentially caused by the way that the
simulation is excited due to the two sub-iterations in the FDTD-ADI. Finally, the
lack of a set of absorbing boundary conidtions, such as the Berenger PML, resulted
in wave reflections in the simulation that caused erroneous values.
Future work should include determining the exact cause of the errors mentioned
above and the multiresolution time domain (MRTD) method should also be investigated as discussed in section 2.3. The MRTD method may provide a better estimate
to the model solution than the finite difference scheme presented here, but one will
never know until it is attempted. It is possible that this may be investigated as part
of the project for another course.
15
Appendix A
Matlab Simulation Code
A.1
FDTD Code using Yee’s Method
Here the code for Yee’s method[6] with Berenger’s PML absorbing boundary conditions [7] is shown. Note, that the PML was actually disabled in this simulation (i.e.
npmls = 0) because difficulties was had in implementing the PML in the FDTD-ADI
method. The algorithm was taken from some sample code provided on disc in Balanis’
Antenna text [1] and modified for the author’s purposes in this report.
% 2D FDTD code using traditional Yee method for z-directed line source.
% Transverse Magnetic solution.
t1 = cputime;
%************************************************
% constants need for the problem.
%************************************************
pi = 4.0 * atan(1.0);
%not sure why various authors use this
% instead of the matlab function.
mu0 = 4.0 * pi * 1.0e-7;
%permeability of free space.
eps0 = 8.854e-12;
%permittivity of free space.
c0 = 1.0/sqrt(mu0*eps0);
%speed of light.
aimp = sqrt(mu0/eps0);
%wave impedance.
%************************************************
16
% define the region parameters, size, PML, etc.
%************************************************
npmls = 0;
%number of PML cells.
nmax = 100;
%number of time steps.
%x-axis.
ie = 150;
%size of evaluated region in x-direction.
ib = ie + 1;
%add buffer for spatial derivatives.
ip = ie - npmls;
%define actual region that is being modelled.
%i.e. inside the PML layers.
%y-axis.
je = 150;
%size of evaluated region in y-direction.
jb = je + 1;
%add buffer for spatial derivatives.
jp = je - npmls;
%define actual region that is being modelled.
%i.e. inside the PML layers.
%space and time steps.
dx = 0.003
%FDTD cell size.
cdt= dx/c0/2.0;
dt = dx/c0/2.0;
%time step size determined by the Courant condition.
%************************************************
% need to define the voltage activation sites.
% for now let’s assume it is in the middle somewhere.
%************************************************
ic = ie/2 + 1;
jc = je/2 + 1;
%************************************************
% set up the Berenger PML absorbing boundary
% constraints material constants.
%************************************************
17
%first the max values are needed.
sigmax = (-3.0)*eps0*c0*log(1e-5)/(2.0*dx*npmls);
rhomax = sigmax * (aimp^2);
%set up the absorbing layers values for the free space material.
for m = 1:npmls
sig(m) = sigmax * ((m-0.5)/(npmls+0.5))^2;
rho(m) = rhomax * ((m)/(npmls+0.5))^2;
end
%************************************************
% set up constants for the FDTD equations at the boundary
% layer.
%************************************************
for m = 1:npmls
re = sig(m)*dt/eps0;
rm = rho(m)*dt/mu0;
%constants for the Ez equation.
ca(m) = exp(-re);
cb(m) = -(exp(-re)-1.0)/sig(m)/dx;
da(m) = exp(-rm);
db(m) = -(exp(-rm)-1.0)/rho(m)/dx;
end
%************************************************
% intialize all of the spatially dependent matrices.
% HX, HY, EZX, EZY, etc...
%************************************************
% ez equations.
for i = 1:ib
for j = 1:jb
18
ez(i,j)
= 0.0;
%assume no electric field present at t = 0.
ezx(i,j)
= 0.0;
%assume no electric field present at t = 0.
caezx(i,j) = 1.0;
%free space assumption.
cbezx(i,j) = dt/eps0/dx;
%free space assumption.
ezy(i,j)
%assume no electric field present at t = 0.
= 0.0;
caezy(i,j) = 1.0;
%free space assumption.
cbezy(i,j) = dt/eps0/dx;
%free space assumption.
end
end
% hx equations.
for i = 1:ib
for j = 1:je
hx(i,j)
= 0.0;
%assume no magnetic field present at t = 0.
dahx(i,j)
= 1.0;
%free space assumption.
dbhx(i,j)
= dt/mu0/dx;
%free space assumption.
hy(i,j)
= 0.0;
%assume no magnetic field present at t = 0.
dahy(i,j)
= 1.0;
%free space assumption.
dbhy(i,j)
= dt/mu0/dx;
%free space assumption.
end
end
% hy equations.
for i = 1:ie
for j = 1:jb;
end
end
%************************************************
% set up the PML boundaries.
%************************************************
%<<< Ez Fields >>>
% left and right PML regions.
19
for i = 2:ie
for j = 2:(npmls + 1)
m = npmls + 2 - j;
caezy(i,j) = ca(m);
cbezy(i,j) = cb(m);
end
for j = (jp + 1):je
m = j - jp;
caezy(i,j) = ca(m);
cbezy(i,j) = cb(m);
end
end
% back and front PML regions.
for j = 2:je
for i = 2:(npmls + 1)
m = npmls + 2 - i;
caezx(i,j) = ca(m);
cbezx(i,j) = cb(m);
end
for i= (ip + 1):ie
m = i - ip;
caezx(i,j) = ca(m);
cbezx(i,j) = cb(m);
end
end
%<<< Hx Fields >>>
% left and right PML regions .....
for i = 2:ie
for j = 1:npmls
m = npmls + 1 - j;
dahx(i,j) = da(m);
dbhx(i,j) = db(m);
20
end
for j = (jp + 1):je
m = j - jp;
dahx(i,j) = da(m);
dbhx(i,j) = db(m);
end
end
%<<< Hy Fields >>>
% front and back PML regions.
for j = 2:je
for i = 1:npmls
m = npmls + 1 - i;
dahy(i,j) = da(m);
dbhy(i,j) = db(m);
end
for i = (ip + 1):ie
m = i - ip;
dahy(i,j) = da(m);
dbhy(i,j) = db(m);
end
end
%************************************************
% start the time stepping loop.
%************************************************
for n = 1:nmax
% set up the pulse excitation.
% b = 25.0;
% dum = 4.0/b/dt * (n*dt - b*dt);
% voltage = 2.0 * dum * exp(-(dum)^2);
voltage = sin((n*dt)*(2*pi/(cdt*20)));
21
%************************************************
% ez field update.
%************************************************
ezx(2:ie,2:je)=caezx(2:ie,2:je).*ezx(2:ie,2:je)+...
cbezx(2:ie,2:je).*(hy(2:ie,2:je)-hy(1:ie-1,2:je));
ezy(2:ie,2:je)=caezy(2:ie,2:je).*ezy(2:ie,2:je)+...
cbezy(2:ie,2:je).*(hx(2:ie,1:je-1)-hx(2:ie,2:je));
% determine total ez field.
ez(2:ie,2:je)=ezx(2:ie,2:je)+ezy(2:ie,2:je);
%************************************************
% apply the soft source excitation at ic, jc.
%************************************************
ez(ic,jc) = ez(ic,jc) + voltage/dx;
%ez(ic,jc) = voltage/dx;
%************************************************
% hx field update.
%************************************************
hx(1:ib,1:je)=dahx(1:ib,1:je).*hx(1:ib,1:je)+...
dbhx(1:ib,1:je).*(ez(1:ib,1:je)-ez(1:ib,2:jb));
%************************************************
% hy field update.
%************************************************
hy(1:ie,1:jb)=dahy(1:ie,1:jb).*hy(1:ie,1:jb)+...
dbhy(1:ie,1:jb).*(ez(2:ib,1:jb)-ez(1:ie,1:jb));
testPoint1Yee(n,:) = [10^9*n*dt, ez(ic+10, jc)];
testPoint2Yee(n,:) = [10^9*n*dt, ez(ic, jc+10)];
testPoint3Yee(n,:) = [10^9*n*dt, ez(ic+20, jc)];
testPoint4Yee(n,:) = [10^9*n*dt, ez(ic, jc+20)];
testPoint5Yee(n,:) = [10^9*n*dt, ez(ic+40, jc)];
testPoint6Yee(n,:) = [10^9*n*dt, ez(ic, jc+40)];
22
if rem(n,3)==0
s=int2str(n);
n2=n/3;
clf;
pcolor(ez);
axis([1 ie 1 je]);
caxis([-50 50]);
shading interp;
if n==3;
M=moviein(37);
end;
t2=[’TMz Gaussian Derivative Pulse. Time step #’,s];
title(t2);
hold;
M(:,n2)=getframe;
end
end
t2 = cputime;
fprintf(’CPU Time = %d’, t2-t1);
%save tm_open M;
%movie(M,2,7);
A.2
FDTD-ADI Code
Here the code for the FDTD-ADI method as given by Namiki in [4, 9] is shown.
Again, there is no PML implementation, however the parameters were left in for
future use.
% 2D FDTD-ADI code using Namiki’s method for z-directed line source.
% Transverse Magnetic solution.
23
t1 = cputime;
% time step factor
xTimeStep = 4.0;
nTimeSteps = 200;
%************************************************
% constants need for the problem.
%************************************************
pi = 4.0 * atan(1.0);
%not sure why various authors use this
% instead of the matlab function.
mu0 = 4.0 * pi * 1.0e-7;
%permeability of free space.
eps0 = 8.854e-12;
%permittivity of free space.
c0 = 1.0/sqrt(mu0*eps0);
%speed of light.
aimp = sqrt(mu0/eps0);
%wave impedance.
%************************************************
% define the region parameters, size, PML, etc.
%************************************************
npmls = 0;
%number of PML cells.
nmax = nTimeSteps/xTimeStep;%number of time steps.
%x-axis.
ie = 150;
%size of evaluated region in x-direction.
ib = ie + 1;
%add buffer for spatial derivatives.
ip = ie - npmls;
%define actual region that is being modelled.
%i.e. inside the PML layers.
%y-axis.
je = 150;
%size of evaluated region in y-direction.
jb = je + 1;
%add buffer for spatial derivatives.
jp = je - npmls;
%define actual region that is being modelled.
%i.e. inside the PML layers.
24
%space and time steps.
dx = 0.003
%FDTD cell size.
cdt = dx/c0/2.0;
dt =xTimeStep*cdt;
%time step size determined by the Courant condition.
%************************************************
% need to define the voltage activation sites.
% for now let’s assume it is in the middle somewhere.
%************************************************
ic = ie/2 + 1;
jc = je/2 + 1;
%************************************************
% intialize all of the spatially dependent matrices.
% HX, HY, EZX, EZY, etc...
%************************************************
% ez equations.
for i = 1:ib
for j = 1:jb
ez(i,j)
= 0.0;
%assume no electric field present at t = 0.
sigma(i,j) = 0.0;
caez(i,j) = eps0/(eps0 + sigma(i,j)*dt);
%free space assumption.
cbez(i,j) = 0.5*dt/(eps0 + sigma(i,j)*dt)/dx;
%free space assumption.
end
end
% hx equations.
for i = 1:ib
for j = 1:je
hx(i,j)
= 0.0;
%assume no magnetic field present at t = 0.
dahx(i,j)
= 1.0;
%free space assumption.
dbhx(i,j)
= 0.5*dt/mu0/dx; %free space assumption.
end
25
end
% hy equations.
for i = 1:ie
for j = 1:jb;
hy(i,j)
= 0.0;
%assume no magnetic field present at t = 0.
dahy(i,j)
= 1.0;
%free space assumption.
dbhy(i,j)
= 0.5*dt/mu0/dx; %free space assumption.
end
end
%************************************************
% start the time stepping loop.
%************************************************
%allocate memory for the tridiagonal matrices first.
A1 = spalloc(ib,ib,3);
A2 = spalloc(jb,jb,3);
% build A1 and A2 for situations where the step sizes
% are constant and material properties are constant.
alpha = -1*dt^2/(mu0*eps0*dx^2);
gamma = alpha;
beta = 1-alpha-gamma;
% build A1
i = 1;
A1(i,i) = beta+alpha;
A1(i,i+1) = gamma;
for i = 2:ie
A1(i, i-1) = alpha;
A1(i, i)
= beta;
26
A1(i, i+1) = gamma;
end
i = ib;
A1(i, i-1) = alpha;
A1(i, i)
= beta+gamma;
% build A2
j = 1;
A2(j,j) = beta+alpha;
A2(j,j+1) = gamma;
for j = 2:je
A2(j, j-1) = alpha;
A2(j, j)
= beta;
A2(j, j+1) = gamma;
end
j = jb;
A2(j, j-1) = alpha;
A2(j, j)
= beta+gamma;
% allocate memory for test data.
testPoint1 = zeros(nmax, 2);
testPoint2 = zeros(nmax, 2);
testPoint3 = zeros(nmax, 2);
testPoint4 = zeros(nmax, 2);
testPoint5 = zeros(nmax, 2);
testPoint6 = zeros(nmax, 2);
for n = 1:nmax
% set up the pulse excitation.
%
b = 25.0/xTimeStep;
27
%
dum = 4.0/b/dt * (n*dt - b*dt);
%
voltage = 2.0 * dum * exp(-(dum)^2);
voltage = sin((n*dt)*(2*pi/(cdt/20)));
%<<< first half-time step >>>
%************************************************
% hx field update.
%************************************************
hx(1:ib, 1:je) = dahx(1:ib, 1:je) .* hx(1:ib, 1:je) +...
dbhx(1:ib, 1:je) .* (ez(1:ib, 1:je) - ez(1:ib,2:jb));
%************************************************
% ez field update.
%************************************************
for j = 2:je
i = 1;
r(i) = caez(i,j)*ez(i,j) + cbez(i,j)*(hy(i,j)...
+ hx(i,j-1) - hx(i,j));
% use these if the gamma and beta are position dependent.
% gamma = -1*dbhx(i,j) * cbez(i,j);
% beta
= 1 - gamma;
% A1(i,1) = beta;
% A1(i,2) = gamma;
for i = 2:ie
% alpha = -1*dbhx(i-1,j) * cbez(i,j);
% gamma = -1*dbhx(i,j) * cbez(i,j);
% beta
= 1 - alpha - gamma;
r(i) = caez(i,j)*ez(i,j) + cbez(i,j)*(hy(i,j)...
- hy(i-1,j) + hx(i,j-1) - hx(i,j));
% A1(i, i-1) = alpha;
28
% A1(i, i)
= beta;
% A1(i, i+1) = gamma;
end
i = ib;
% alpha = -1*dbhx(i-1,j) * cbez(i,j);
% beta
= 1 - alpha;
% A1(i, i-1) = alpha;
% A1(i, i)
= beta;
r(i) = caez(i,j)*ez(i,j) + cbez(i,j)*(-hy(i-1,j)...
+ hx(i,j-1) - hx(i,j) );
%temp = (inv(A1)*(r’))’;
temp = tridiagsolve(A1, r);
for i = 1:ib
ez(i,j) = temp(i);
end
end
%************************************************
% apply the soft source excitation at ic, jc.
%************************************************
ez(ic,jc) = ez(ic,jc) + 1.0*voltage/dx;
%ez(2:ie, 2:je) = ezx(2:ie, 2:je) + ezy(2:ie, 2:je);
%************************************************
% hy field update.
%************************************************
hy(1:ie,1:jb) = dahy(1:ie, 1:jb) .* hy(1:ie, 1:jb) +...
dbhy(1:ie, 1:jb).*(ez(2:ib, 1:jb)-ez(1:ie, 1:jb));
%<<< second half-time step >>>
29
%************************************************
% hy field update.
%************************************************
hy(1:ie,1:jb) = dahy(1:ie, 1:jb) .* hy(1:ie, 1:jb) +...
dbhy(1:ie, 1:jb).*(ez(2:ib, 1:jb)-ez(1:ie, 1:jb));
%************************************************
% ez field update.
%************************************************
for i = 2:ie
j = 1;
r(j) = caez(i,j)*ez(i,j) + cbez(i,j)*(hy(i,j)...
- hy(i-1,j) - hx(i,j));
% gamma = -1*dbhx(i,j) * caez(i,j);
% beta
= 1 - gamma;
% A2(j,1) = beta;
% A2(j,2) = gamma;
for j = 2:je
% alpha = -1*dbhx(i-1,j) * cbez(i,j);
% gamma = -1*dbhx(i,j) * cbez(i,j);
% beta
= 1 - alpha - gamma;
r(j) = caez(i,j)*ez(i,j) + cbez(i,j)*(hy(i,j)...
- hy(i-1,j) + hx(i,j-1) - hx(i,j));
% A2(j, j-1) = alpha;
% A2(j, j)
= beta;
% A2(j, j+1) = gamma;
end
j = jb;
% alpha = -1*dbhx(i,j-1) * cbez(i,j);
30
% beta
= 1 - alpha;
% A2(j, j-1) = alpha;
% A2(j, j)
= beta;
r(j) = caez(i,j)*ez(i,j) + cbez(i,j)*(hy(i,j)...
- hy(i-1,j) + hx(i,j-1) );
%temp = (inv(A2)*(r’))’;
temp = tridiagsolve(A2, r);
for j = 1:jb
ez(i,j) = temp(j);
end
end
%************************************************
% apply the soft source excitation at ic, jc.
%************************************************
ez(ic,jc) = ez(ic,jc) + 0.0*voltage/dx;
%************************************************
% hx field update.
%************************************************
hx(1:ib, 1:je) = dahx(1:ib, 1:je) .* hx(1:ib, 1:je) +...
dbhx(1:ib, 1:je) .* (ez(1:ib, 1:je) - ez(1:ib,2:jb));
testPoint1(n,:) = [10^9*n*dt, ez(ic+10, jc)];
testPoint2(n,:) = [10^9*n*dt, ez(ic, jc+10)];
testPoint3(n,:) = [10^9*n*dt, ez(ic-20, jc)];
testPoint4(n,:) = [10^9*n*dt, ez(ic, jc+20)];
testPoint5(n,:) = [10^9*n*dt, ez(ic+40, jc)];
testPoint6(n,:) = [10^9*n*dt, ez(ic, jc+40)];
if rem(n,2)==0
31
s=int2str(n);
n2=n/2;
clf;
pcolor(ez);
axis([1 ie 1 je]);
caxis([-50 50]);
shading interp;
if n==2;
M=moviein(37);
end;
t2=[’TMz Gaussian Derivative Pulse. Time step #’,s];
title(t2);
hold;
M(:,n2)=getframe;
end
end
t2 = cputime;
fprintf(’CPU Time = %d’, t2-t1);
%save tm_open M;
%movie(M,2,5);
A.3
Tridiagonal System of Equations Solver
Here the code for the tridiagonal systems of equation solver as given by Zhao[11] is
shown.
function x = tridiagsolve(A,b)
%this is the routine proposed by Zhao to ensure
% stability in the FDTD-ADI algorithm.
%size of the problem.
N = size(A,1);
32
%initialize for the first value.
i = 1;
x(i) = A(i,i+1)/A(i,i);
g(i) = b(i)/A(i,i);
%solve the rest of the problem.
for i = 2:(N-1)
x(i) = A(i,i+1)/(A(i,i)-A(i,i-1)*x(i-1));
g(i) = (b(i) - A(i,i-1)*g(i-1))/(A(i,i) - A(i,i-1)*x(i-1));
end
i=N;
x(i) = (b(i) - A(i,i-1)*g(i-1))/(A(i,i) - A(i,i-1)*x(i-1));
for i = (N-1):-1:1
x(i) = g(i) - x(i)*x(i+1);
end
33
Bibliography
[1] C. A. Balanis, Antenna Theory, Analysis and Design.
New York: John Wiley
& Sons, 1997.
[2] ——, Advanced Engineering Electromagnetics. New York: John Wiley & Sons,
1989.
[3] D. M. Sullivan, Electromagnetic Simulation Using the FDTD Method.
New
York: IEEE Press, 2000.
[4] T. Namiki, “A new FDTD algorithm based on alternating-direction implicit
method,” IEEE Trans. Microwave Theory Tech., vol. 47, no. 10, pp. 2003–2007,
1999.
[5] F. Zheng, Z. Chen, and J. Zhang, “A finite-difference time-domain method without the courant stability conditions,” IEEE Microwave Guided Wave Lett., vol. 9,
no. 11, pp. 441–443, 1999.
[6] K. S. Yee, “Numerical solution of initial boundary value problems involving
maxwell’s equations in isotropic media,” IEEE Trans. Antennas Propagat.,
vol. 14, no. 3, pp. 302–307, 1966.
[7] J.-P. Berenger, “A perfectly matched layer for the absorption of electromagnetic
waves,” Journal of Computational Physics, vol. 114, pp. 185–200, 1994.
[8] W. H. Press, S. A. Teukolsky, and W. T. V. B. P. Flannery, Numerical Recipes
in C++, The Art of Scientific Computing, 2ed Edition. New York: Cambridge
University Press, 2002.
[9] T. Namiki, “3-D ADI-FDTD method – unconditionally stable time domain algorithm for solving full vector maxwell’s equations,” IEEE Trans. Microwave
Theory Tech., vol. 48, no. 10, pp. 1743–1748, 2000.
34
[10] T. Namiki and K. Ito, “Investigation of numerical errors of the two-dimensional
ADI-FDTD method,” IEEE Trans. Microwave Theory Tech., vol. 48, no. 11, pp.
1950–1956, 2000.
[11] A. P. Zhao, “Two special notes on the implementation of the unconditionally
stable ADI-FDTD method,” Microwave and Optical Technology Letters, vol. 33,
no. 4, pp. 273–277, 2002.
[12] S. Wang and F. L. Teixeira, “An efficient PML implementation for the ADIFDTD method,” IEEE Microwave Wireless Compon. Lett., vol. 13, no. 2, pp.
72–74, 2003.
[13] M. Krumpholz and L. P. B. Katehi, “MRTD: New time-domain schemes based on
multiresolution analysis,” IEEE Trans. Microwave Theory Tech., vol. 44, no. 4,
pp. 555–571, 1996.
35
Download