Skip to content

Commit ddaae66

Browse files
author
sveinlin
committed
fixed typos in wave Chapter
1 parent 435302e commit ddaae66

66 files changed

Lines changed: 3526 additions & 1496 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc/.src/chapters/wave/wave1D_fd1.do.txt

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ in the forthcoming text by finite difference methods.
3939
label{wave:string}
4040
idx{waves!on a string}
4141
idx{wave equation!1D}
42+
idx{wave! velocity}
4243

4344
We begin our study of wave equations by simulating one-dimensional
4445
waves on a string, say on a guitar or violin.
@@ -107,6 +108,8 @@ idx{mesh!finite differences}
107108
===== Discretizing the domain =====
108109
label{wave:string:mesh}
109110

111+
idx{mesh! uniform}
112+
110113
The temporal domain $[0,T]$ is represented by a finite number of mesh points
111114

112115
!bt
@@ -156,6 +159,9 @@ develop algebraic equations for computing the mesh function.
156159
===== Fulfilling the equation at the mesh points =====
157160
label{wave:string:samplingPDE}
158161

162+
idx{PDE! algebraic version}
163+
idx{finite difference scheme}
164+
159165
In the finite difference method, we relax
160166
the condition that (ref{wave:pde1}) holds at all points in
161167
the space-time domain $(0,L)\times (0,T]$ to the requirement that the PDE is
@@ -222,14 +228,18 @@ label{wave:pde1:step3a}
222228

223229
=== Interpretation of the equation as a stencil ===
224230

231+
idx{finite difference scheme}
232+
idx{difference equations}
233+
idx{sampling (a PDE)}
234+
225235
A characteristic feature of (ref{wave:pde1:step3b}) is that it
226236
involves $u$ values from neighboring points only: $u_i^{n+1}$,
227237
$u^n_{i\pm 1}$, $u^n_i$, and $u^{n-1}_i$. The circles in Figure
228238
ref{wave:pde1:fig:mesh} illustrate such neighboring mesh points that
229239
contribute to an algebraic equation. In this particular case, we have
230240
sampled the PDE at the point $(2,2)$ and constructed
231-
(ref{wave:pde1:step3b}), which then involves a coupling of $u_nm1^1$,
232-
$u_n^2$, $u_nm1^2$, $u_3^2$, and $u_nm1^3$. The term *stencil* is often
241+
(ref{wave:pde1:step3b}), which then involves a coupling of $u_1^2$,
242+
$u_2^3$, $u_2^2$, $u_2^1$, and $u_3^2$. The term *stencil* is often
233243
used about the algebraic equation at a mesh point, and the geometry of
234244
a typical stencil is illustrated in Figure
235245
ref{wave:pde1:fig:mesh}. One also often refers to the algebraic
@@ -269,6 +279,8 @@ The other initial condition can be computed by
269279
===== Formulating a recursive algorithm =====
270280
label{wave:string:alg}
271281

282+
idx{wave equation! 1D, discrete}
283+
272284
We assume that $u^n_i$ and $u^{n-1}_i$ are available for
273285
$i=0,\ldots,N_x$. The only unknown quantity in
274286
(ref{wave:pde1:step3b}) is therefore $u^{n+1}_i$, which we now can
@@ -333,18 +345,18 @@ label{wave:pde1:step4:1}
333345
\end{equation}
334346
!et
335347
Figure ref{wave:pde1:fig:stencil:u1} illustrates how (ref{wave:pde1:step4:1})
336-
connects four instead of five points: $u^1_2$, $u_n^0$, $u_nm1^0$, and $u_3^0$.
348+
connects four instead of five points: $u^1_2$, $u_1^0$, $u_2^0$, and $u_3^0$.
337349

338350
FIGURE: [mov-wave/D_stencil_gpl/stencil_n0_interior, width=500] Modified stencil for the first time step. label{wave:pde1:fig:stencil:u1}
339351

340352
We can now summarize the computational algorithm:
341353

342354
o Compute $u^0_i=I(x_i)$ for $i=0,\ldots,N_x$
343-
o Compute $u^1_i$ by (ref{wave:pde1:step4:1}) and set $u_i^1=0$
344-
for the boundary points $i=0$ and $i=N_x$, for $n=1,2,\ldots,N-1$,
355+
o Compute $u^1_i$ by (ref{wave:pde1:step4:1}) for $i=1,2,\ldots,N_x-1$ and set $u_i^1=0$
356+
for the boundary points given by $i=0$ and $i=N_x$,
345357
o For each time level $n=1,2,\ldots,N_t-1$
346358
o apply (ref{wave:pde1:step4}) to find $u^{n+1}_i$ for $i=1,\ldots,N_x-1$
347-
o set $u^{n+1}_i=0$ for the boundary points $i=0$, $i=N_x$.
359+
o set $u^{n+1}_i=0$ for the boundary points having $i=0$, $i=N_x$.
348360

349361
The algorithm essentially consists of moving a finite difference
350362
stencil through all the mesh points, which can be seen as an animation
@@ -369,10 +381,6 @@ memory at as few time levels as possible.
369381
In a Python implementation of this algorithm, we use the array
370382
elements `u[i]` to store $u^{n+1}_i$, `u_n[i]` to store $u^n_i$, and
371383
`u_nm1[i]` to store $u^{n-1}_i$.
372-
Our naming convention is to use `u` for the
373-
unknown new spatial field to be computed and have all previous time
374-
levels in a list `u_n` that we index as `u_n`, `u_nm1`, `u_n[-2]`
375-
and so on. For the wave equation, `u_n` has just length 2.
376384

377385
The following Python snippet realizes the steps in the computational
378386
algorithm.
@@ -413,6 +421,8 @@ for n in range(1, Nt):
413421

414422
======= Verification =======
415423

424+
idx{source term}
425+
416426
Before implementing the algorithm, it is convenient to add a source
417427
term to the PDE (ref{wave:pde1}), since that gives us more freedom in
418428
finding test problems for verification. Physically, a source term acts
@@ -484,6 +494,8 @@ label{wave:pde2:step3c}
484494
===== Using an analytical solution of physical significance =====
485495
label{wave:pde2:fd:standing:waves}
486496

497+
idx{verification! convergence rates}
498+
487499
Many wave problems feature sinusoidal oscillations in time
488500
and space. For example, the original PDE problem
489501
(ref{wave:pde1})-(ref{wave:pde1:bc:L}) allows an exact solution
@@ -539,6 +551,8 @@ label{wave:pde2:fd:MMS}
539551

540552
=== Specifying the solution and computing corresponding data ===
541553

554+
idx{manufactured solution}
555+
542556
One problem with the exact solution (ref{wave:pde2:test:ue}) is
543557
that it requires a simplification ($V=0, f=0$) of the implemented problem
544558
(ref{wave:pde2})-(ref{wave:pde2:bc:L}). An advantage of using
@@ -569,6 +583,9 @@ u_t(x,0) &= V(x) = x(L-x)\tp
569583

570584
=== Defining a single discretization parameter ===
571585

586+
idx{verification! convergence rates}
587+
idx{discretization parameter}
588+
572589
To verify the code, we compute the convergence rates in a series of
573590
simulations, letting each simulation use a finer mesh than the
574591
previous one. Such empirical estimation of convergence rates relies on
@@ -609,8 +626,8 @@ C_t h^r + C_x\left(\frac{c}{C}\right)^r h^r
609626
We choose an initial discretization parameter $h_0$ and run
610627
experiments with decreasing $h$: $h_i=2^{-i}h_0$, $i=1,2,\ldots,m$.
611628
Halving $h$ in each experiment is not necessary, but it is a common
612-
choice. For each experiment we must record $E$ and $h$. A standard
613-
choice of error measure is the $\ell^2$ or $\ell^\infty$ norm of the
629+
choice. For each experiment we must record $E$ and $h$. Standard
630+
choices of error measure are the $\ell^2$ and $\ell^\infty$ norms of the
614631
error mesh function $e^n_i$:
615632

616633
!bt
@@ -619,7 +636,7 @@ E &= ||e^n_i||_{\ell^2} = \left( \Delta t\Delta x
619636
\sum_{n=0}^{N_t}\sum_{i=0}^{N_x}
620637
(e^n_i)^2\right)^{\half},\quad e^n_i = \uex(x_i,t_n)-u^n_i,
621638
label{wave:pde2:fd:MMS:E:l2}\\
622-
E &= ||e^n_i||_{\ell^\infty} = \max_{i,n} |e^i_n|\tp
639+
E &= ||e^n_i||_{\ell^\infty} = \max_{i,n} |e^n_i|\tp
623640
label{wave:pde2:fd:MMS:E:linf}
624641
\end{align}
625642
!et
@@ -641,12 +658,12 @@ E &= ||e^n_i||_{\ell^2} = \left( \Delta x\sum_{i=0}^{N_x}
641658
E &= ||e^n_i||_{\ell^\infty} = \max_{0\leq i\leq N_x} |e^{n}_i|\tp
642659
\end{align}
643660
!et
644-
The important issue is that our error measure $E$ must be one number
645-
that represents the error in the simulation.
661+
The important point is that the error measure ($E$) for the simulation is represented by a single number.
646662

647663
=== Computing rates ===
648664

649-
Let $E_i$ be the error measure in experiment (mesh) number $i$ and
665+
Let $E_i$ be the error measure in experiment (mesh) number $i$
666+
(not to be confused with the spatial index $i$) and
650667
let $h_i$ be the corresponding discretization parameter ($h$).
651668
With the error model $E_i = Dh_i^r$, we can
652669
estimate $r$ by comparing two consecutive
@@ -714,8 +731,7 @@ and $V(x)={\half}x(L-x)$.
714731

715732
To realize that the chosen $\uex$ is also an exact
716733
solution of the discrete equations,
717-
we first remind ourselves that $t_n=n\Delta t$ before we
718-
establish that
734+
we first remind ourselves that $t_n=n\Delta t$ so that
719735

720736
!bt
721737
\begin{align}

doc/.src/chapters/wave/wave1D_fd2.do.txt

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ idx{homogeneous Dirichlet conditions}
5555
idx{boundary conditions!Neumann}
5656
idx{boundary conditions!Dirichlet}
5757

58-
5958
When a wave hits a boundary and is to be reflected back, one applies
6059
the condition
6160

@@ -103,7 +102,7 @@ $x=0$ and $t=t_n$ by the difference
103102

104103
!bt
105104
\begin{equation}
106-
[D_{2x} u]^n_0 = \frac{u_{-1}^n - u_n^n}{2\Delta x} = 0
105+
[D_{2x} u]^n_0 = \frac{u_{-1}^n - u_1^n}{2\Delta x} = 0
107106
\tp
108107
label{wave:pde1:Neumann:0:cd}
109108
\end{equation}
@@ -112,7 +111,6 @@ The problem is that $u_{-1}^n$ is not a $u$ value that is being
112111
computed since the point is outside the mesh. However, if we combine
113112
(ref{wave:pde1:Neumann:0:cd}) with the scheme
114113
# (ref{wave:pde1:step4})
115-
for $i=0$,
116114

117115
!bt
118116
\begin{equation}
@@ -121,8 +119,8 @@ u^{n+1}_i = -u^{n-1}_i + 2u^n_i + C^2
121119
label{wave:pde1:Neumann:0:scheme}
122120
\end{equation}
123121
!et
124-
we can eliminate the fictitious value $u_{-1}^n$. We see that
125-
$u_{-1}^n=u_n^n$ from (ref{wave:pde1:Neumann:0:cd}), which
122+
for $i=0$, we can eliminate the fictitious value $u_{-1}^n$. We see that
123+
$u_{-1}^n=u_1^n$ from (ref{wave:pde1:Neumann:0:cd}), which
126124
can be used in (ref{wave:pde1:Neumann:0:scheme}) to
127125
arrive at a modified scheme for the boundary point $u_0^{n+1}$:
128126

@@ -359,7 +357,7 @@ A lot of test examples are also included in the program:
359357
typical initial shape of a guitar string.
360358
* A sinusoidal variation of $u$ at $x=0$ and either $u=0$ or
361359
$u_x=0$ at $x=L$.
362-
* An exact analytical solution $u(x,t)=\cos(m\pi t/L)\sin({\half}m\pi x/L)$, which can be used for convergence rate tests.
360+
* An analytical solution $u(x,t)=\cos(m\pi t/L)\sin({\half}m\pi x/L)$, which can be used for convergence rate tests.
363361
!enotice
364362

365363
[hpl: Should include some experiments here or make exercises. Qualitative
@@ -402,6 +400,8 @@ label{wave:pde1:Neumann:ghost}
402400

403401
=== Idea ===
404402

403+
idx{ghost! cells} idx{ghost! points} idx{ghost! values}
404+
405405
Instead of modifying the scheme at the boundary, we can introduce
406406
extra points outside the domain such that the fictitious values
407407
$u_{-1}^n$ and $u_{N_x+1}^n$ are defined in the mesh. Adding the
@@ -483,7 +483,7 @@ for i in Ix:
483483
0.5*dt2*f(x[i-Ix[0]], t[0])
484484
!ec
485485

486-
It remains to update the solution at ghost points, i.e, `u[0]`
486+
It remains to update the solution at ghost points, i.e., `u[0]`
487487
and `u[-1]` (or `u[Nx+2]`). For a boundary condition $u_x=0$,
488488
the ghost value must equal the value at the associated inner mesh
489489
point. Computer code makes this statement precise:
@@ -557,6 +557,8 @@ or (as always) `u[Ix[0]:Ix[-1]+1]`.
557557
======= Generalization: variable wave velocity =======
558558
label{wave:pde2:var:c}
559559

560+
idx{wave! variable velocity} idx{wave! reflected} idx{wave! transmitted}
561+
560562
Our next generalization of the 1D wave equation (ref{wave:pde1}) or
561563
(ref{wave:pde2}) is to allow for a variable wave velocity $c$:
562564
$c=c(x)$, usually motivated by wave motion in a domain composed of
@@ -704,7 +706,7 @@ terms $qu_{xx} + q_xu_x$. The typical discretization is
704706

705707
!bt
706708
\begin{equation}
707-
D_x q D_x u + D_{2x}q D_{2x} u]_i^n,
709+
[D_x q D_x u + D_{2x}q D_{2x} u]_i^n,
708710
label{wave:pde2:var:c:chainrule_scheme}
709711
\end{equation}
710712
!et
@@ -717,7 +719,7 @@ $[D_x(q D_x u)]^n_i$ with harmonic averaging of $q$ yields
717719
a better solution than arithmetic averaging or
718720
(ref{wave:pde2:var:c:chainrule_scheme}).
719721
In the literature, the discretization $[D_x(q D_x u)]^n_i$ totally
720-
dominates and very few mention the possibility of
722+
dominates and very few mention the alternative in
721723
(ref{wave:pde2:var:c:chainrule_scheme}).
722724
!ewarning
723725

@@ -730,6 +732,8 @@ dominates and very few mention the possibility of
730732
===== Computing the coefficient between mesh points =====
731733
label{wave:pde2:var:c:means}
732734

735+
idx{interpolation}
736+
733737
If $q$ is a known function of $x$, we can easily evaluate
734738
$q_{i+\half}$ simply as $q(x_{i+\half})$ with $x_{i+\half} = x_i +
735739
\half\Delta x$. However, in many cases $c$, and hence $q$, is only
@@ -810,10 +814,12 @@ label{wave:pde2:var:c:scheme:impl}
810814
===== How a variable coefficient affects the stability =====
811815
label{wave:pde2:var:c:stability}
812816

813-
The stability criterion derived in Section ref{wave:pde1:stability}
817+
idx{time step! spatially varying}
818+
819+
The stability criterion derived later (Section ref{wave:pde1:stability})
814820
reads $\Delta t\leq \Delta x/c$. If $c=c(x)$, the criterion will depend
815821
on the spatial location. We must therefore choose a $\Delta t$ that
816-
is small enough such that no mesh cell has $\Delta x/c(x) >\Delta t$.
822+
is small enough such that no mesh cell has $\Delta t > \Delta x/c(x)$.
817823
That is, we must use the largest $c$ value in the criterion:
818824

819825
!bt
@@ -971,6 +977,8 @@ u[1:-1] = - u_nm1[1:-1] + 2*u_n[1:-1] + \
971977

972978
===== A more general PDE model with variable coefficients =====
973979

980+
idx{coefficients! variable}
981+
974982
Sometimes a wave PDE has a variable coefficient in front of
975983
the time-derivative term:
976984

@@ -1009,6 +1017,8 @@ also without any difficulty:
10091017

10101018
===== Generalization: damping =====
10111019

1020+
idx{wave! damping}
1021+
10121022
Waves die out by two mechanisms. In 2D and 3D the energy of the wave
10131023
spreads out in space, and energy conservation then requires
10141024
the amplitude to decrease. This effect is not present in 1D.
@@ -1078,8 +1088,8 @@ label{wave:pde2:software:bcL}
10781088
\end{align}
10791089
!et
10801090

1081-
The only new feature here is the time-dependent Dirichlet conditions.
1082-
These are trivial to implement:
1091+
The only new feature here is the time-dependent Dirichlet conditions, but
1092+
they are trivial to implement:
10831093

10841094
!bc pycod
10851095
i = Ix[0] # x=0
@@ -1169,6 +1179,9 @@ cite{Langtangen_deqbook_softeng2}].
11691179

11701180
===== Pulse propagation in two media =====
11711181

1182+
idx{pulse propagation} idx{plug} idx{Gaussian function} idx{cosine hat}
1183+
idx{discontinuous medium} idx{discretization parameters}
1184+
11721185
The function `pulse` in `wave1D_dn_vc.py` demonstrates wave motion in
11731186
heterogeneous media where $c$ varies. One can specify an interval
11741187
where the wave velocity is decreased by a factor `slowness_factor`

0 commit comments

Comments
 (0)