PROGRAMMING EXERCISES
The philosophy behind this book is that the reader will learn by doing. Therefore, most exercises involve programming. Each of Chapters 1–5 has at least one FDTD program written in Python. Each of the programs is complete and can be run as written, provided the Python interpreter and necessary libraries are installed. These programs include the graphical display of results to match many of the figures in the chapters. The programs in Chapters 1–4 are designed to be simple and procedural for ease of understanding and following the equations. Chapter 5 addresses some better Python programming practices and introduces some new features and techniques. This chapter attempts to introduce those unfamiliar with Python with some useful concepts to enhance FDTD programs and produce more readable, extendable code.
PROGRAMMING LANGUAGE
The programs in the book are written in Python. Python is a free, open‐source programming language which has broad adoption in both general‐purpose industries and scientific applications. This large community means that we can leverage a large number of well‐documented tools and libraries. The Python libraries are constantly being expanded. Additionally, the plotting and graphical interface libraries allow the entire program to be more interactive and user‐friendly, while being written in a high‐level language. Libraries are also available to speed up simulations to give good performance. Python, and FDTD simulations, can be run on any modern computer.
PYTHON VERSION
All programs in this book were run with Python 3.5.1 and the following library versions:
matplotlib==3.0.0
numba==0.39.0
numpy==1.14.3
scipy==1.0.1
1 ONE‐DIMENSIONAL SIMULATION WITH THE FDTD METHOD
This chapter provides a step‐by‐step introduction to the finite‐difference time‐domain (FDTD) method, beginning with the simplest possible problem, the simulation of a pulse propagating in free space in one dimension. This example is used to illustrate the FDTD formulation. Subsequent sections lead to formulations for more complicated media.
1.1 ONE‐DIMENSIONAL FREE‐SPACE SIMULATION
The time‐dependent Maxwell’s curl equations for free space are
E and H are vectors in three dimensions, so, in general, Eq. (1.1a) and (1.1b) represent three equations each. We will start with a simple one‐dimensional case using only Ex and Hy, so Eq. (1.1a) and (1.1b) become
(1.2a)
(1.2b)
These are the equations of a plane wave traveling in the z direction with the electric field oriented in the x direction and the magnetic field oriented in the y direction.
Taking the central difference approximations for both the temporal and spatial derivatives gives
In these two equations, time is specified by the superscripts, that is, n represents a time step, and the time t is t = Δt ⋅ n. Remember, we have to discretize everything for formulation into the computer. The term n + 1 means one time step later. The terms in parentheses represent distance, that is, k is used to calculate the distance z = Δx ⋅ k. (It might seem more sensible to use Δz as the incremental step because in this case we are going in the z direction. However, Δx is so commonly used for a spatial increment that we will use Δx.) The formulation of Eq. (1.3a) and (1.3b) assume that the E and H fields are interleaved in both space and time. H uses the arguments k + 1/2 and k − 1/2 to indicate that the H field values are assumed to be located between the E field values. This is illustrated in Fig. 1.1. Similarly, the n + 1/2 or n − 1/2 superscript indicates that it occurs slightly after or before n, respectively. Equations (1.3a) and (1.3b) can be rearranged in an iterative algorithm:
Notice that the calculations are interleaved in space and time. In Eq. (1.4a), for example, the new value of Ex is calculated from the previous value of Ex and the most recent values of Hy.