Numerical Simulation of the FDTD Method in LabVIEW [Application Notes]

7
90 December 2007 Numerical Simulation of the FDTD Method in LabVIEW Gasmelseed Akram and Yunus Jasmy T he finite-difference time-domain (FDTD) method is one of the most widely used computational meth- ods in electromagnetics. Using FDTD, Maxwell’s equations are solved directly in the time domain via finite differences and time stepping. In this article, we describe the implementation of the numerical solution of the FDTD method using the graphical programming lan- guage LabVIEW. We first present a one-dimensional (1-D) formulation with simple radiating boundary condition followed by a two-dimensional (2-D) formulation. The implementation of the perfectly matched layer (PML) boundary condition has been used to truncate the 2-D model used for the simulation. The LabVIEW program codes provide a graphical user interface to the model that makes it easy to observe and modify the behavior of each element of the model. In addition, the codes are relatively easy to understand and they can be easily modified for the user’s specific purpose. Background The FDTD method has become widely used for electromag- netic computation since the initial work of Kane Yee [1]. Yee’s approach was to choose a geometric relation for his spatial sampling of the vector components of the magnetic and elec- tric fields that can represent the integral forms of Maxwell’s equations. The FDTD method uses a leapfrog scheme on a staggered Cartesian grid. Many scientists have contributed greatly to the explo- ration and development of this method since Taflove first used the FDTD method to solve scattering problems in the 1970s [2]. Different boundary conditions—including first- order Mur’s boundary, second-order Mur’s boundary, Berenger’s PML [3], etc.—have been added to the bound- ary of the calculation domain to absorb most of the ener- gies from the calculation domain. As a result, the fields reflected back to the calculation domain from the boundary are minimized. The FDTD algorithm has been widely used in scientific research, for example, in the analysis of millimeter-wave integrated circuit (MMIC) packages, multichip modules, high-frequency digital circuits, cellular and satellite commu- nication devices, medical devices, and other problems in modern communication systems [4]. FDTD has proven to be an effective technique for calculat- ing the interaction of electromagnetic waves with bodies of different material and complex—and, hence, realistic— geometries. As computing hardware became faster and more widely available, the FDTD method found numerous appli- cations in electromagnetic radiation, scattering, and coupling. Stimulated by these successes, various researchers developed enhancements to the original technique that greatly extended its range of applicability. LabVIEW (Laboratory Virtual Instrument Engineering Workbench) is a National Instruments program development Gasmelseed Akram (e-mail: [email protected]) and Yunus Jasmy are with the faculty of Electrical Engineering, Universiti Teknologi Malaysia (UTM), Skudai Campus, Johor Bahru, Malaysia. Digital Object Identifier 10.1109/MMM.2007.906920

Transcript of Numerical Simulation of the FDTD Method in LabVIEW [Application Notes]

90 December 2007

Numerical Simulation of the FDTD Method in LabVIEW■ Gasmelseed Akram and Yunus Jasmy

The finite-difference time-domain (FDTD) method isone of the most widely used computational meth-ods in electromagnetics. Using FDTD, Maxwell’s

equations are solved directly in the time domain via finitedifferences and time stepping. In this article, we describethe implementation of the numerical solution of theFDTD method using the graphical programming lan-guage LabVIEW. We first present a one-dimensional (1-D)formulation with simple radiating boundary conditionfollowed by a two-dimensional (2-D) formulation. Theimplementation of the perfectly matched layer (PML)boundary condition has been used to truncate the 2-Dmodel used for the simulation. The LabVIEW programcodes provide a graphical user interface to the model thatmakes it easy to observe and modify the behavior of eachelement of the model. In addition, the codes are relativelyeasy to understand and they can be easily modified forthe user’s specific purpose.

BackgroundThe FDTD method has become widely used for electromag-netic computation since the initial work of Kane Yee [1]. Yee’sapproach was to choose a geometric relation for his spatialsampling of the vector components of the magnetic and elec-

tric fields that can represent the integral forms of Maxwell’sequations. The FDTD method uses a leapfrog scheme on astaggered Cartesian grid.

Many scientists have contributed greatly to the explo-ration and development of this method since Taflove firstused the FDTD method to solve scattering problems in the1970s [2]. Different boundary conditions—including first-order Mur’s boundary, second-order Mur’s boundary,Berenger’s PML [3], etc.—have been added to the bound-ary of the calculation domain to absorb most of the ener-gies from the calculation domain. As a result, the fieldsreflected back to the calculation domain from the boundaryare minimized.

The FDTD algorithm has been widely used in scientificresearch, for example, in the analysis of millimeter-waveintegrated circuit (MMIC) packages, multichip modules,high-frequency digital circuits, cellular and satellite commu-nication devices, medical devices, and other problems inmodern communication systems [4].

FDTD has proven to be an effective technique for calculat-ing the interaction of electromagnetic waves with bodies ofdifferent material and complex—and, hence, realistic—geometries. As computing hardware became faster and morewidely available, the FDTD method found numerous appli-cations in electromagnetic radiation, scattering, and coupling.Stimulated by these successes, various researchers developedenhancements to the original technique that greatly extendedits range of applicability.

LabVIEW (Laboratory Virtual Instrument EngineeringWorkbench) is a National Instruments program development

Gasmelseed Akram (e-mail: [email protected]) and Yunus Jasmy are with the faculty of Electrical Engineering, Universiti Teknologi

Malaysia (UTM), Skudai Campus, Johor Bahru, Malaysia.

Digital Object Identifier 10.1109/MMM.2007.906920

92 December 2007

application, similar to variousC/FORTRAN/MATLAB develop-ment systems. However, LabVIEW isdifferent from those applications inone important respect. Other pro-gramming systems use text-basedlanguages to create lines of code,while LabVIEW uses a graphical pro-gramming language G to create pro-grams in block diagram form [5]–[7].It also has extensive libraries of func-tions and subroutines for most pro-gramming tasks such as data analysis,data presentation, and data storage.LabVIEW includes conventional pro-gram development tools, allowingthe user to set breakpoints, animateprogram execution to see how datapasses through the program, and sin-gle-step through the program to makedebugging and program develop-ment easier.

Graphical programming is basedon the concept of data flow, in con-trast to the sequential logic of mosttext-based programming languages.This means that execution of a blockor graphical component is dependent

on the flow of data, or, more specifically, a block executeswhen data are made available at all of its input and outputdata of the block are sent to all other connected blocks.

In this article, we present an FDTD code developed inLabVIEW for basic scattering modeling. For comparison,we provide a text code based on the C programming lan-guage. We first present a 1-D formulation with simpleradiating boundary condition followed by a 2-D formula-tion. The implementation of the PML boundary conditionhas been used to truncate the 2-D model used for the sim-ulation to avoid reflections from the edges of the modelinggrid. The FDTD code with PML boundary conditionsimplemented according to the formulation proposed bySullivan [8]–[9] has been developed. This particular for-mulation allows one to terminate any given materialdirectly in the PML layers without virtually any reflection

between the region of interest and the PMLabsorbing boundaries. The formulation usesthe electric field E, the magnetic field H, andthe electric displacement D rather than onlythe electric and magnetic fields as in usualFDTD implementation. This formulation hasthe advantage of making the PML propertiescompletely independent of the backgroundmedium.

1-D FormulationTo give a description of the FDTD method,initially a 1-D formulation will be presented.

Figure 1. The block diagram of Ez field calculation, EZ_Field.vi.

IEI32

N

Ez(i,n)

[DBL]

[DBL]

[DBL]

[DBL]

Ca

Hy(i,n+0.5)

Ez(i,n+1)

[DBL]

Cb

i

×

×

+

+1

Figure 2. General structure of For loop and shift registers.

For Loop

Shift RegisterRight Terminal

Shift RegisterLeft Terminal

N

i

Figure 3. The front panel of Ez field calculation, EZ_Field.vi.

Ca

Cb

Hy(i,n+0.5)

Ez(i,n+1)

00.00

0.00

0

0

200

0.97216

0.98608

0.00

Ez(i,n)

94 December 2007

Maxwell’s scalar equations for a nonpermeable [10] lossymedium (μ = μ0, σ

∗ = 0) are

σ Ez + ε∂Ez

∂ t= ∂Hy

∂x, (1)

μ∂Hy

∂ t= ∂Ez

∂x. (2)

These equations represent a plane wave with electric field ori-ented in the z direction, the magnetic field oriented in the ydirection, and traveling in the x direction.

Equations (1) and (2), when approximated by finite differ-ences, yield the discretized update equations

E n+1z [i ] = Ca[i ] ∗ E n

z [i ] + Cb[i ]

∗(

Hn+ 1

2y

[i + 1

2

]− H

n+ 12

y

[i − 1

2

]), (3)

Hn+ 1

2y

[i + 1

2

]= H

n− 12

y

[i + 1

2

]

+ �tμδ

∗ (E n

z [i + 1] − E nz [i ]

), (4)

where the terms Ca[i ] and Cb[i ] are given by

Ca [i ] =1 − σ [i ]�t

2 ε[i ]

1 + σ [i ]�t2 ε[i ]

, (5)

Cb [i ] = �t/ε[i ]δ

1 + σ [i ]�t2 ε[i ]

. (6)

Equations (3) and (4) are readily programmed for solution byiteration of each equation.

To illustrate the algorithm, a sinusoidal wave (1-GHz)propagating in a nonpermeable lossy medium (εr = 1.0,

σ = 0.005 S/ms modeled) is used. The grid resolution(dx = 2.5 cm) is chosen to provide 20 samples per wave-length. The Courant factor S = c∗dt/dx is set to the stabilitylimit S = 1. The number of grid cells (IE) in the x-directionis 200, and the total number of time steps is 240. The com-putational domain is truncated using the simplest radiation

Ez(i max, n + 1) = Ez(i max −1, n ). (7)

The MATLAB program segment that executes the time-stepping of Ez in the FDTD space lattice can be written as

Ez(2 : IE) = ca∗Ez(2 : IE) + cb∗(Hy(2 : IE) − Hy(1 : IE − 1)).

These equations are built into LabVIEW, though in order tounderstand the output that is obtained, it is helpful to knowthe basic program development application under theLabVIEW environment.

LabVIEW programs are called virtual instruments (VI)because their appearance and operation imitate actual instru-ments. However, they are analogous to functions from con-ventional language programs. VIs have both an interactiveuser interface and a source code equivalent and accept para-meters from higher-level VIs.

The interactive user interface of the VI, the front panel, simu-lates the front panel of a physical instrument. The front panelcontains knobs, push buttons, graphs and other controls andindicators. After acquiring the data, the results are viewed on thecomputer screen. The instructions for the VI are contained by ablock diagram which is constructed using the language G. Theblock diagram supplies a pictorial solution to the programming

Figure 4. The FDTD-computed Ez and Hy fields at everytimestep using waveform graph.

Time= 12 [nsec]1.0

0.5

0.0

−0.5

−1.5

−0.003

−0.002

−0.001

0.000

0.001

0.002

0.003

0 1 2 3

0 1x (m)

x (m)

2 3

EZ

Hy

Figure 5. Update of the Dz field within the main FDTD loop(main.vi) using shift registers.

Steps

InitialValue

DZ

Shift Register

[DBL]

I32

N

i

96 December 2007

problem and it contains the code for the VI. The VI use hierar-chical and modular structure. A VI within another VI is called asubVI. The icon and connector pane of a VI work like a graphi-cal parameter list so that other VIs can pass data to it as a subVI.

With the above-listed features, LabVIEW promotes andadheres to the concept of modular programming. The applica-tion is divided into a series of tasks which can be dividedagain until a complicated application becomes a series of sim-ple subtasks. A VI is developed to accomplish each subtaskand then, by combining these low-level VIs on another blockdiagram, the larger task is accomplished. Finally, the top-levelVI contains a collection of subVIs that represent applicationfunctions. Because each subVI can be executed by itself, apartfrom the rest of the application, debugging is a relatively easytask. Furthermore, many low-level subVIs often perform taskscommon to several applications so that a set of specializedsubVIs can be developed that suits a multitude of applications.Referring to the FDTD model, the block diagram for the Ezfield calculation (3) (Figure 1) consists of a For loop, shift-reg-isters, and array tools. The block diagram is the graphical“source code” of a LabVIEW VI. As each control or indicatoris placed on the front panel, a corresponding icon is placed onthe block diagram.

The controls and indicators act as user inputs and outputsfor the program, respectively. Lines, referred to as “wires,”connect icons representing source code to establish the flow ofdata within the program.

The For loop (Figure 2) in LabVIEW operates just like a Forloop would in another programming language. In the top-leftcorner is a boxed N. It is an input connector that accepts aninteger data type (represented by the color blue), and the loopwill complete as many iterations as the value wired to it. Inthe lower-left corner is a boxed i. It is an output terminal thatalso outputs an integer data type. The loop will iterate as longas i < N (where i begins at zero).

In the LabVIEW programmingenvironment, feedback connectionsare accomplished through the use ofshift registers (Figure 2). Shift registerstransfer values from one loop iterationto the next. The shift register contains apair of terminals directly opposite eachother on the vertical sides of the loopborder. The right terminal stores thedata upon the completion of iteration.The data shifts at the end of the itera-tion and appears in the left terminal atthe beginning of the next iteration.

The corresponding front panel forthe Ez field calculation is shown inFigure 3. Graphs and charts are usedto display data in a graphical form.Figure 4 shows the FDTD-computedEz and Hy fields at every time stepusing a waveform graph.

Graphs and charts differ in theway they display and update data.

VIs with graphs usually collect data in an array and then plotthe data to the graph, which is similar to a spreadsheet thatfirst stores the data and then generates a plot of it. In contrast,a chart appends new data points to those already in the dis-play to create a history. On a chart, we can see the currentreading or measurement in context with data previouslyacquired.

2-D FormulationThe FDTD code with PML boundary conditions is implement-ed according to the formulation proposed by Sullivan [9].Following closely the theory in [9], the Dz field component inthe finite difference formulation can be written as follows:

Dn+ 1

2z (i, j) = gi 3(i)gj3 ( j)D

n− 12

z (i, j) + 0.5gi 2 (i )gj2 ( j)

×[

H ny

(i + 1

2 , j)

− H ny

(i − 1

2 , j)

−H nx

(i, j+ 1

2

)− H n

x

(i, j− 1

2

)]. (8)

The parameters gi2(i ) and gi3(i ) (analogous to gj2( j) andgj3( j), respectively) are given by

gi2(i ) = 1/(1 + xn(i ))

gi3(i ) = (1 − xn(1 ))/(1 + xn(i)), (9)

where xn (i ) is given by

xn(m) = 0.333 ·(

mNo. PML layers

)3.0

m = 1, · · · , No. PML layers. (10)

Similar equations can be derived for all other field compo-nents. The MATLAB program segment that executes the

Figure 6. The front panel of Dz field calculation, DZ_Field.vi.

dzG-2-i

G-2-j G-3-j

G-3-iDZ

HX

HY

NX

NY

hx

hy

0

PML Parameters Output FieldsInput Fields

0

0

0

0

0

Grid Size

0.00

0.00

0.000.00 0.00

0.000

0

0

0

0

0

0.00

0.00

0.00

0

0

0

0

0

0

0.00

December 2007 97

time-stepping of Dz in the FDTD space lattice can be writtenas a simple double-nested loop

for i = 2 : IE

for j = 2 : JE

Dz(i, j) = gi3(i)∗gj3( j)∗Dz(i, j) + gi2(i)∗gj2( j)∗

0.5∗ . . . (Hy(i, j) − Hy(i − 1, j) − Hx (i. j)

+ Hx (i, j− 1 ));end

end.

We can directly implement (8) in LabVIEW using two shiftregisters, one to keep the previous input value and theother to keep previous output values. Figure 5 shows theimplementation of the Dz field in the main FDTD loop.

Referring to our FDTD model, the front panel for the Dzfield calculation is shown in Figure 6. The block diagram(Figure 7) of the Dz calculation VI consists of a case statementnested inside a For loop.

The case structure allows conditional control in a VI like anif-then statement. During runtime, the VI will wait for data tobe passed to the case structure and then compare the data itreceives to the titles of each case.

Even though LabVIEW provides full functionality for anypossible arithmetic expression, there may be situations whereyou prefer to use equations by typing in the formula for Dz

field. The formula node is for such purposes. The formulanode contains one or more C-like statements delimited bysemicolons. Figure 8 shows an alternative code version to cal-culate the Dz field using the formula node.

Arrays in LabVIEW can be any type. You access each arrayelement through its index. The index is in the range 0 to n − 1,where n is number of elements in the array. Subarrays can be

Figure 7. The block diagram of Dz field calculation, DZ_Field.vi.

NX

True

DZ

HX

HY

NY

dz

G-3-i

G-3-j

G-2-i

G-2-j

hx

hy

I32

I32N

N

[DBL]

[DBL]

[DBL]

[DBL]

[DBL]

[DBL]

[DBL]

[DBL]

[DBL]

[DBL]

ii

1

1

−1

−1

×

×

+

×

×

>−

>−

>

98 December 2007

extracted along any combination of dimensions.Figure 9 shows how to extract a 1-D row or col-umn arrays from a 2-D array.

To validate the LabVIEW code, the numer-ical experiment of [2] was carried out in 2-Dfor the transverse magnetic (TM) case. Theproblem illustrated in Figure 10 was used. Aplane wave is used to excite 72�x × 72�yFDTD computational space. The problemspace is divided into the total and scatteredfields. The envelope of Ez at the center of thecylinder for 640 ≤ n ≤ 720 is given in Figure11. The subVI, media.vi, contains the consti-tutive parameters of the media. By simply

changing the parameters of the media, the code can beapplied to almost any 2-D scattering or penetration problem.

ConclusionsFDTD code developed in LabVIEW for basic scatteringmodeling in 2-D has been used. The advantages of usingthe LabVIEW programming environment are many.First, the graphical nature of the programming environ-ment makes it very easy to create sophisticated applica-tions in a minimum amount of time, especially whencompared to designing graphical user interfaces in alow-level programming language like C/C + +. Thestructure of LabVIEW makes it easy to add new compo-nents to the model when the need arises. Furthermore,the graphical user interface allows the user to observeand gain insight into the behavior of the model. Finally,VIs have both an interactive user interface and a sourcecode equivalent and they accept parameters from high-er-level VIs.

Figure 9. Extract a 1-D row or column arrays from a 2-D array.

2D Array[DBL]

Index Array

2

Index Array

[DBL]

[DBL]

Column 2

Row 11

Figure 8. Dz field calculations using Formula Node.

Inputs Outputs

dzg3ig3jg2jg2jhxhx1hyhy1

dz

hx

hy

dz=g3i*g3j*dz+g2i*g2j*0.5*(hy-hy1-hx+hx1);

Figure 10. Diagram of 2-D dielectric cylinder problem. The PMLlayer is eight cells. The cylinder is 40 cells in diameter.

y

x

ia ib

ja

jb

εr = 4.0

σ = 0.0

Plane Wave

PML

December 2007 99

References[1] K.S. Yee, “Numerical solution of initial

boundary value problems involvingMaxwell’s equations in isotropicmedia,” IEEE Trans. Antennas Propagat.,vol. AP-14, no. 3, pp. 302–307, 1966.

[2] A. Taflove and M. Brodwin,“Numerical solution of steady-stateelectromagnetic scattering problemsusing the time-dependent Maxwell’sequations,” IEEE Microwave Theory.Techn., vol. MTT-23, no. 8, pp. 623–630,1975.

[3] J. Berenger, “A perfectly matchedlayer for the absorption of electro-magnetic waves,” J. Comput. Phys.,vol. 114, no. 2, pp. 185–200, 1994.

[4] A. Taflove, Computational Electro-dynamics the Finite-Difference Time-Domain Method. Norwood, MA:Artech House, 1995.

[5] C.J. Kalkman, “LabVIEW: A Ssftwaresystem for data acquisition, data analy-sis, and instrument control,” J. ClinicalMonitoring, vol. 11, no. 1, pp. 51–58,1995.

[6] J.B. Olansen and E. Rosow, “Virtualbio-instrumentation, biomedical, clinical and healthcare applications inLabVIEW,” Virtual Instrumentation Series, Prentice-Hall PTR, 2001.

[7] R. Bitter, T. Mohiuddin, and M. Nawrocki, LabVIEW: AdvancedProgramming Techniques. Boca Raton, FL: CRC Press, 2000.

[8] D.M. Sullivan, “An unsplit step 3-D PML for use with the FDTD method,”

IEEE Microwave Guided Wave Lett., vol. 7, no. 7, pp. 184–186, 1997.[9] D.M. Sullivan, Electromagnetic Simulation Using the FDTD Method. New

York: IEEE Press, 2000.[10] A. Taflove and S. Hagness, Computational Electromagnetics: The Finite-

Difference Time-Domain Method, 2nd ed. Boston, MA: Artech, 2000.

Figure 11. The computed internal Ez at the center of the dielectric cylinder.

2,400.0

2,200.0

2,000.0

1,800.0

1,600.0

1,400.0

1,200.0

1,000.0

800.0

600.0

400.0

200.00.0 2.5 5.0 7.5 10.0 12.5 15.0 17.5 20.0 22.5 25.0 27.5 30.0 32.5 35.0 37.5 40.0

Axis of Cylinder Center

|EZ

|

SIGN UP TODAY: www.ieee.org/whats-newChoose the FREE newsletters that are right for you.

Read it Here FirstWhat’s New @ IEEE

401-Qh WhatsNew 7x4.75.indd 1 8/10/06 10:48:50 AM