Skip to content

Commit 76a3f1a

Browse files
author
sveinlin
committed
updates
1 parent dbb793c commit 76a3f1a

177 files changed

Lines changed: 2915 additions & 2899 deletions

File tree

Some content is hidden

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

doc/.src/book/.dict4spell.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Yapi
4747
discretization
4848
eco
4949
fdm
50+
hplgit
5051
io
5152
refactor
5253
reide

doc/.src/chapters/advec/advec.do.txt

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ centered differences in space:
117117
[D_t^+ u + vD_{2x} u = 0]^n_i
118118
\end{equation}
119119
!et
120-
Written out, we see that this expression reads
120+
Written out, we see that this expression implies that
121121

122122
!bt
123123
\[ u^{n+1} = u^n - \half C (u^n_{i+1}-u_{i-1}^n),\]
@@ -265,7 +265,7 @@ which results in the updating formula
265265
!et
266266
A special scheme is needed to compute $u^1$, but we leave that problem for
267267
now. Anyway, this special scheme can be found in
268-
"`advec1D.py`": "${src_advec}/advec/advec1D.py".
268+
"`advec1D.py`": "$https://github.com/hplgit/fdm-book/blob/master/src/advec/advec1D.py".
269269

270270
=== Implementation ===
271271

@@ -424,12 +424,12 @@ error.
424424

425425
FIGURE: [fig-advec/gaussian_UP_C08, width=800 frac=1] Advection of a Gaussian function with a forward in time, upwind in space scheme and $C=0.8$, $\Delta t = 0.01$ (left) and $\Delta t=0.001$ (right). label{advec:1D:UP:fig1:C08}
426426

427-
Advection of the Gaussian function with a with a forward in time, upwind in space scheme, using $C=0.8$ and $\Delta t = 0.01$ can be seen in a "movie file":"${docraw}/mov-advec/gaussian/UP/C08_dt001/movie.ogg". Alternatively, with $\Delta t = 0.005$, we get this "movie file":
427+
Advection of the Gaussian function with a forward in time, upwind in space scheme, using $C=0.8$ and $\Delta t = 0.01$ can be seen in a "movie file":"${docraw}/mov-advec/gaussian/UP/C08_dt001/movie.ogg". Alternatively, with $\Delta t = 0.005$, we get this "movie file":
428428
"${docraw}/mov-advec/gaussian/UP/C08_dt0005/movie.ogg".
429429

430430
FIGURE: [fig-advec/cosinehat_UP_08, width=800 frac=1] Advection of half a cosine function with a forward in time, upwind in space scheme and $C=0.8$, $\Delta t = 0.001$ (left) and $\Delta t=0.01$ (right). label{advec:1D:UP:fig2:C08}
431431

432-
Advection of the cosine hat function with a with a forward in time, upwind in space scheme, using $C=0.8$ and $\Delta t = 0.01$ can be seen in a "movie file":"${docraw}/mov-advec/cosinehat/UP/C08_dt01.ogg". Alternatively, with $\Delta t = 0.001$, we get this "movie file":
432+
Advection of the cosine hat function with a forward in time, upwind in space scheme, using $C=0.8$ and $\Delta t = 0.01$ can be seen in a "movie file":"${docraw}/mov-advec/cosinehat/UP/C08_dt01.ogg". Alternatively, with $\Delta t = 0.001$, we get this "movie file":
433433
"${docraw}/mov-advec/cosinehat/UP/C08_dt001.ogg".
434434

435435
The amplification factor can be computed using the
@@ -447,7 +447,7 @@ For $C<1$ there is, unfortunately,
447447
non-physical damping of discrete Fourier components, giving rise to reduced
448448
amplitude of $u^n_i$ as in Figures ref{advec:1D:UP:fig1:C08}
449449
and ref{advec:1D:UP:fig2:C08}. The damping seen
450-
in this figure is quite severe. Stability requires $C\leq 1$.
450+
in these figures is quite severe. Stability requires $C\leq 1$.
451451

452452
!bnotice Interpretation of upwind difference as artificial diffusion
453453
One can interpret the upwind difference as extra, artificial diffusion
@@ -724,7 +724,7 @@ def run(scheme='UP', case='gaussian', C=1, dt=0.01):
724724
print 'Integral of u:', integral.max(), integral.min()
725725
!ec
726726
The complete code is found in the file
727-
"`advec1D.py`": "${src_advec}/advec/advec1D.py".
727+
"`advec1D.py`": "$https://github.com/hplgit/fdm-book/blob/master/src/advec/advec1D.py".
728728

729729
===== A Crank-Nicolson discretization in time and centered differences in space =====
730730
label{advec:1D:CN}
@@ -882,13 +882,8 @@ This means that $|A|=1$ and also that we have an exact solution if $C=1$!
882882
===== Analysis of dispersion relations =====
883883
label{advec:1D:disprel}
884884

885-
idx{`dispersion_analysis.py`}
886-
887885
We have developed expressions for $A(C,p)$ in the exact solution
888-
$u_q^n=A^ne^{ikq\Delta x}$ of the discrete equations. These
889-
expressions are valuable for investigating the quality of the numerical
890-
solutions, see the file
891-
"`dispersion_analysis.py`": "${src_advec}/advec/dispersion_analysis.py".
886+
$u_q^n=A^ne^{ikq\Delta x}$ of the discrete equations.
892887
Note that the Fourier component that solves the original
893888
PDE problem has no damping and moves with constant velocity $v$. There
894889
are two basic errors in the numerical Fourier component: there may be

doc/.src/chapters/diffu/diffu_analysis.do.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,8 @@ which has roots
659659
!bt
660660
\[ A = -2F\sin^2 p \pm \sqrt{4F^2\sin^4 p + 1}\tp\]
661661
!et
662-
Both roots have $|A|>1$ so the always amplitude grows, which is not in
663-
accordance with physics of the problem.
662+
Both roots have $|A|>1$ so the amplitude always grows, which is not in
663+
accordance with the physics of the problem.
664664
However, for a PDE with a first-order derivative in space, instead of
665665
a second-order one, the Leapfrog scheme performs very well.
666666
% if BOOK == 'book':

doc/.src/chapters/diffu/diffu_fd1.do.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ and collecting all unknown terms on the left-hand side, we get
10091009
\begin{align}
10101010
u^{n+1}_i - \half F(u^{n+1}_{i-1} - 2u^{n+1}_i + u^{n+1}_{i+1})
10111011
&= u^{n}_i + \half F(u^{n}_{i-1} - 2u^{n}_i + u^{n}_{i+1})\nonumber\\
1012-
&\qquad \half f_i^{n+1} + \half f_i^n\tp
1012+
&\qquad + \half f_i^{n+1} + \half f_i^n\tp
10131013
\end{align}
10141014
!et
10151015

doc/.src/chapters/diffu/diffu_fd2.do.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ coordinates, which with axi-symmetry takes the form
344344

345345
Let us assume that $u$ does not change along the tube axis so it
346346
suffices to compute variations in a cross section. Then $\partial u/\partial
347-
z = 0$ and the we have a 1D diffusion equation in the radial coordinate
347+
z = 0$ and we have a 1D diffusion equation in the radial coordinate
348348
$r$ and time $t$. In particular, we shall address the initial-boundary
349349
value problem
350350

@@ -509,7 +509,7 @@ The associated discrete form is then
509509

510510
!bt
511511
\begin{equation}
512-
[D_t u = \half (\gamma+1)\dfc([D_rD_r \overline{u}^t + \overline{f}^t]^n_i,
512+
[D_t u = \half (\gamma+1)\dfc D_rD_r \overline{u}^t + \overline{f}^t]^{n+\frac{1}{2}}_i,
513513
\end{equation}
514514
!et
515515
for a Crank-Nicolson scheme.

doc/.src/chapters/diffu/diffu_rw.do.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ $\bar x_{2,k}$, and so on. The empirical estimate of $\E{\bar X_k}$ is the
124124
average,
125125

126126
!bt
127-
\[ \E{\bar X_k} \approx = \frac{1}{W}\sum_{j=0}^{W-1} \bar x_{j,k},\]
127+
\[ \E{\bar X_k} \approx \frac{1}{W}\sum_{j=0}^{W-1} \bar x_{j,k},\]
128128
!et
129129
while an empirical estimate of $\Var{\bar X_k}$ is
130130

@@ -255,7 +255,7 @@ idx{verification}
255255

256256
When we have a scalar and a vectorized code, it is always a good idea to
257257
develop a unit test for checking that they produce the same result.
258-
A problem in the present context is that the two versions apply to different
258+
A problem in the present context is that the two versions apply two different
259259
random number generators. For a test to be meaningful, we need to fix
260260
the seed and use the same generator. This means that the scalar version
261261
must either use `np.random` or have this as an option. An option

doc/.src/chapters/nonlin/nonlin_ode.do.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ while $u^{(1)}$ is the value of the unknown at the previous time level
230230
(in general, $u^{(\ell)}$ is the value of the unknown $\ell$ levels
231231
back in time). The notation will be frequently used in later
232232
sections. What is meant by $u$ should be evident from the context: $u$
233-
may be 1) the exact solution of the ODE/PDE problem,
233+
may either be 1) the exact solution of the ODE/PDE problem,
234234
2) the numerical approximation to the exact solution, or 3) the unknown
235235
solution at a certain time level.
236236

@@ -291,7 +291,7 @@ $u\rightarrow u^{(1)}$, which is the expected result.
291291
For those who are not well experienced with approximating mathematical
292292
formulas by series expansion, an alternative method of investigation
293293
is simply to compute the limits of the two roots as $\Delta t\rightarrow 0$
294-
and see if a limit unreasonable:
294+
and see if a limit appears unreasonable:
295295

296296
!bc pyshell
297297
>>> print r1.limit(dt, 0)
@@ -748,8 +748,8 @@ the Picard iterations, that is visibly much larger than the
748748
time discretization error due to a large $\Delta t$. This is illustrated
749749
by comparing the upper two plots in
750750
Figure ref{nonlin:timediscrete:logistic:impl:fig:u}. The one to
751-
the right has a stricter tolerance $\epsilon = 10^{-3}$, which leads
752-
to all the curves corresponding to Picard and Newton iteration to be
751+
the right has a stricter tolerance $\epsilon = 10^{-3}$, which causes
752+
all the curves corresponding to Picard and Newton iteration to be
753753
on top of each other (and no changes can be visually observed by
754754
reducing $\epsilon_r$ further). The reason why Newton's method does
755755
much better than Picard iteration in the upper left plot is that

doc/.src/chapters/nonlin/nonlin_pde1D.do.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ With Picard iteration we get
639639

640640
!bt
641641
\begin{align*}
642-
\frac{1}{2\Delta x^2}(& -(\dfc(u^-_{-1}) + 2\dfc(u^-_{0}
642+
\frac{1}{2\Delta x^2}(& -(\dfc(u^-_{-1}) + 2\dfc(u^-_{0})
643643
+ \dfc(u^-_{1}))u_1\, +\\
644644
&(\dfc(u^-_{-1}) + 2\dfc(u^-_{0}) + \dfc(u^-_{1}))u_0
645645
+ au_0\\
@@ -672,7 +672,7 @@ occurrences of $u_2$ by $D$:
672672
!bt
673673
\begin{align*}
674674
\frac{1}{2\Delta x^2}(&-(\dfc(u^-_{0}) + \dfc(u^-_{1}))u_{0}\, +\\
675-
& (\dfc(u^-_{0}) + 2\dfc(u^-_{1}) + \dfc(D))u_1 + au_1\\
675+
& (\dfc(u^-_{0}) + 2\dfc(u^-_{1}) + \dfc(D)))u_1 + au_1\\
676676
&=f(u^-_1) + \frac{1}{2\Delta x^2}(\dfc(u^-_{1}) + \dfc(D))D\tp
677677
\end{align*}
678678
!et

doc/.src/chapters/softeng2/softeng2.do.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ for n in It[1:-1]: # time loop
788788
=== Efficiency ===
789789

790790
For a mesh consisting of $120\times 120$ cells, the scalar Python code
791-
require 1370 CPU time units, the vectorized version requires 5.5,
791+
requires 1370 CPU time units, the vectorized version requires 5.5,
792792
while the Cython version requires only 1! For a smaller mesh with
793793
$60\times 60$ cells Cython is about 1000 times faster than the scalar
794794
Python code, and the vectorized version is about 6 times slower than

doc/.src/chapters/trunc/trunc.do.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ a slightly smaller $\omega$ since the numerics will make it larger:
13671367
# Ref to exercise
13681368

13691369
!bt
1370-
\[ [ u'' + (\omega(1 - \frac{1}{24}\omega^2\Delta t^2))^2 u = 0\tp\]
1370+
\[ [ u'' + (\omega(1 - \frac{1}{24}\omega^2\Delta t^2))^2 u ]^n = 0\tp\]
13711371
!et
13721372
Expanding the squared term and omitting the higher-order term $\Delta t^4$
13731373
gives exactly the ODE (ref{trunc:vib:undamped:corr:ode}). Experiments
@@ -2042,7 +2042,7 @@ and (ref{trunc:table:avg:arith:eq})-(ref{trunc:table:avg:arith}) we have
20422042
&= \lambda(x_{i+\half})\uexd{x}(x_{i+\half},t_n)
20432043
+ \lambda(x_{i+\half})
20442044
\frac{1}{24}\uexd{xxx}(x_{i+\half},t_n)\Delta x^2 + \\
2045-
&\quad \uexd{x}(x_{i+\half})
2045+
&\quad \uexd{x}(x_{i+\half},t_n)
20462046
\frac{1}{8}\lambda''(x_{i+\half})\Delta x^2
20472047
+\Oof{\Delta x^4}\\
20482048
&= [\lambda \uexd{x}]^n_{i+\half} + G^n_{i+\half}\Delta x^2
@@ -2053,9 +2053,9 @@ where we have introduced the short form
20532053

20542054
!bt
20552055
\[ G^n_{i+\half} =
2056-
(\frac{1}{24}\uexd{xxx}(x_{i+\half},t_n)\lambda((x_{i+\half})
2056+
\frac{1}{24}\uexd{xxx}(x_{i+\half},t_n)\lambda(x_{i+\half})
20572057
+ \uexd{x}(x_{i+\half},t_n)
2058-
\frac{1}{8}\lambda''(x_{i+\half}))\Delta x^2\tp\]
2058+
\frac{1}{8}\lambda''(x_{i+\half})\tp\]
20592059
!et
20602060
Similarly, we find that
20612061

@@ -2276,7 +2276,7 @@ the $u_{xx}$ term:
22762276

22772277
!bt
22782278
\[ [D_t u]^{n+\half}_i = \dfc\half([D_xD_x u]^n_i +
2279-
[D_xD_x u]^{n+1}_i + f^{n+\half}_i\tp\]
2279+
[D_xD_x u]^{n+1}_i) + f^{n+\half}_i\tp\]
22802280
!et
22812281
The equation for the truncation error is
22822282

0 commit comments

Comments
 (0)