12.3 Solving Partial Differential Equations
12.3.1 Numerical Methods for 1D Wave Equations
The Mathematical Model. A basic PDE is the one-dimensional (1D) wave equation:
∂2
∂t2u(x, t) +β∂
∂tu(x, t) = ∂
∂x
[c(x, t)]2 ∂
∂xu(x, t)
+f(x, t) (12.3) This equation can be used to model waves on a string, waves in a flute, waves in a rod, and water waves, to mention some applications. Also spherically symmetric radio, light, or sound waves can be modeled by (12.3) if we take u/ras the physical wave amplitude (rbeing the radial distance to a point).
The unknown function isu(x, t), while candf are prescribed functions. The parameterβ ≥0 is a known constant and introduces damping of the waves.
Theufunction typically describes the shape of a wave signal moving with a local velocity given by thecfunction. The independent variables arexand t, implying that the wave shape may change with one direction in spacexand time t. The f function is some external source that generates waves in the medium. In general, the medium in which the waves travel is heterogeneous.
This is reflected by a wave velocityc that varies in space and possibly also in time.
Homogeneous media, where c is constant, constitute an important class of problems. The PDE then takes the simplified form
∂2u
∂t2 +β∂u
∂t =c2∂2u
∂x2+f(x, t). (12.4)
Equation (12.3) or (12.4) must be solved together with initial and bound- ary conditions. For a while we shall address the following set of such condi- tions:
u(x,0) =I(x), (12.5)
∂
∂tu(x,0) = 0, (12.6)
u(x,0) =U0(t), (12.7)
u(x, L) =UL(t). (12.8)
At initial time, t = 0, the shape of u is known, and the velocity of this shape (∂u/∂t) is zero. The domain in which (12.3) or (12.4) is to be solved is 0< x < L, and at the end points of this domain,x= 0 andx=L, theu function is prescribed as in (12.7)–(12.8).
Physically, (12.5)–(12.8) can model waves on a string, provided U0 = UL= 0 (which means that both ends of the string are fixed, i.e.,u= 0). The motion starts after having dragged the string from its equilibrium position to the shapeI(x), let the spring come to rest, and then releasing it.
Numerical Methods. Assuming that the reader already has some basic knowl- edge about solving basic PDEs like (12.3), we shall here just quickly review the simplest solution procedure. First we introduce a uniform grid on [0, L]
with grid points xi =iΔx, where i= 0, . . . , n. The grid or cell spacingΔx then equals L/n. A finite difference method consists of (i) letting (12.3) or (12.4) hold at each grid point and (ii) replacing derivatives by finite differ- ences.
An approxmation of (12.4) at an arbitrary grid point (i, ), i counting grid points in space and counting levels in time, then becomes
1 Δt2
u−i 1−2ui+u+1i + β
2Δt
u+1i −u−i 1
= c2 Δx2
ui−1−2ui+ui+1 +f(xi, t).
Here we have introduced the notation ui for u at x = xi and t = t. The parameterΔtis the time step:Δt=t+1−t, and t=Δt.
The equation foruat a grid point can be solved with respect tou+1i . This value is unknown, while all values at time levels and−1 are considered as known. This leads us to the following scheme for computing u+1i :
ui+1= 2 2 +βΔt
2ui+ (1
2βΔt−1)u−i 1+C2
ui−1−2ui+ui+1 +Δt2fi
, (12.9)
where
C2=c2Δt2 Δx2.
12.3. Solving Partial Differential Equations 643 This equation holds for allinternal grid points in space:i= 1, . . . , n−1. At the boundaries,i= 0 and i=n, we have thatu+10 = 0 andu+1n = 0.
Initially,u0i is known, and the condition∂u/∂t= 0 can be shown to imply a special value ofu−i 1a the fictitious=−1 time level [15, Ch. 1]:
u−1i = 1 2
2u0i +C2
u0i−1−2u0i +u0i+1
+Δt2f(xi,0) (12.10) for the internal points i = 1, . . . , n−1. At the boundary points we have u−01=u10=U0(Δt) andu−1n =u1n =UL(Δt).
The proposed numerical scheme has an error proportional to Δt2 and Δx2. That is, halving the space and time increments reduces the error by a factor of 4. Unfortunately, there is a stability problem with the numerical method:Δtmust fulfill
Δt≤Δx
c (12.11)
to avoid non-physical blow up of the numerical solution.
The Computational Algorithm;c=const. We can summarize the numerical method for (12.4) and (12.5)–(12.8) in the following algorithm. The quantities u+i , ui andu−i are introduced to representu+1i ,ui andu−i 1, respectively.
set the initial conditions:
ui=I(xi), fori= 0, . . . , n
Define the value of the artificial quantityu−i : Equation (12.10) andu−0 =U0(Δt),u−L =UL(Δt) t= 0
while timet≤tstop t←t+Δt
update all inner points:
Equation (12.9) fori= 1, . . . , n−1 update boundary points:
u+0 = 0,u+n = 0
initialize for next step:
u−i =ui, ui =u+i , fori= 0, . . . , n.
Extension to Heterogeneous Media. When waves travel through a varying (heterogeneous) medium, the wave velocitycvaries in space and possibly also in time. The governing PDE must then be written as in (12.3). Approximating this variable-coefficient PDE at a grid point (i, ) results in
1 Δt2
u−1i −2ui+u+1i + β
2Δt
u+1i −u−1i
= 1
Δx2
[c2]i+1
2(ui+1−ui) + [c2]i−1
2(ui−ui−1)
+f(xi, t).
The notation [c2]i+1
2 actually means to evaluate c2 at time t and at the spatial point betweenxi and xi+1. Very often [c2]i+1
2 is evaluated as [c2]i+1
2 ≈1
2([c2]i+ [c2]i+1). Solving for the unknown u+1i yields the scheme u+1i = 2
2 +βΔt
2ui+ (1
2βΔt−1)u−i 1+ Δt2
Δx2 1
2([c2]i + [c2]i+1)(ui+1−ui) +1
2([c2]i−1+ [c2]i)(ui−ui−1)
+ Δt2f(xi, t)
. (12.12)
Again, this equation holds for allinternal grid points i= 1, . . . , n−1. The equation for the fictitious time level=−1 now takes the form
u−1i = 1 2
2u0i+ Δt2 Δx2
1
2([c2]0i + [c2]0i+1)(u0i+1−u0i)
−1
2([c2]0i−1+ [c2]0i)(u0i −u0i−1)
+Δt2f(xi,0) (12.13) The formula is valid for all internal points in the grid. At a boundary point we evaluateu−1i via the boundary condition att=Δt.
The stability limit for a varying c(x, t) wave velocity is normally chosen as
Δt=s Δx
maxc(x, t), (12.14)
where the maximum is taken over all relevantxand t values, and s≤1 is a safety factor. In some problems we need to choose s < 1 to get a stable solution, but this depends on the properties of c(x, t) and must usually be determined from numerical experimentation.
The computational algorithm in the casec=c(x, t) follows the algorithm for constantc step by step, but (12.10) is replaced by (12.13), and (12.9) is replaced by (12.12).