Skip to content

Commit 5241d70

Browse files
author
sveinlin
committed
typos and index list for ch 1 and 2 and App
1 parent 11f1126 commit 5241d70

86 files changed

Lines changed: 686 additions & 361 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
@@ -24,6 +24,7 @@ Kutta
2424
Langtangen
2525
Linge
2626
MATLAB
27+
Mardal
2728
Mathilde
2829
Matlab
2930
Miri

doc/.src/book/preface.do.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ URL: http://hplgit.github.io/fdm-book/doc/web/.
265265

266266
=== Acknowledgments ===
267267

268+
Professor Kent-Andre Mardal at the University of Oslo has kindly
269+
contributed to enlightening discussions on several issues.
268270
Many students have
269271
provided lots of useful feedback on the exposition and found many
270272
errors in the text. Special efforts in this regard were made by Imran
@@ -275,12 +277,12 @@ The collaboration with the Springer team, with Dr.~Martin Peters,
275277
Thanh-Ha Le Thi, and their production staff has always been a
276278
great pleasure and a very efficient process.
277279

278-
Finally, want really appreciate the strong push of the COE of Simula
280+
Finally, want really appreciate the strong push from the COE of Simula
279281
Research Laboratory, Aslak Tveito, for publishing and financing books
280-
in open access format, including this one. We are grateful to the
282+
in open access format, including this one. We are grateful for the
281283
laboratory's financial contribution as well as to the financial
282284
contribution from the Department of Process, Energy and Environmental
283-
Technology, University College of Southeast Norway.
285+
Technology at the University College of Southeast Norway.
284286

285287
# #if FORMAT in ("latex", "pdflatex")
286288
\vspace{1cm}

doc/.src/chapters/formulas/formulas.do.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ label{Dop:avg:theta}\\
4141

4242
Some may wonder why $\theta$ is absent on the right-hand side
4343
of (ref{Dop:fd1:theta}). The fraction is an approximation to the
44-
derivative at the point $t_{n+\theta}=\theta t_{n+1} + (1-theta) t_{n}$.
44+
derivative at the point $t_{n+\theta}=\theta t_{n+1} + (1-\theta) t_{n}$.
4545

4646
======= Truncation errors of finite difference approximations =======
4747
label{sec:form:truncerr}
@@ -170,15 +170,15 @@ The next formulas concern the action of difference operators on a $t^2$ term.
170170

171171
!bt
172172
\begin{align}
173-
\lbrack D_t^+ t^2\rbrack^n = (2n+1)\Delta t,
173+
\lbrack D_t^+ t^2\rbrack^n &= (2n+1)\Delta t,
174174
label{form:Dop:tn2:fw}\\
175-
\lbrack D_t^- t^2\rbrack^n = (2n-1)\Delta t,
175+
\lbrack D_t^- t^2\rbrack^n &= (2n-1)\Delta t,
176176
label{form:Dop:tn2:bw}\\
177-
\lbrack D_t t^2\rbrack^n = 2n\Delta t,
177+
\lbrack D_t t^2\rbrack^n &= 2n\Delta t,
178178
label{form:Dop:tn2:cn}\\
179-
\lbrack D_{2t} t^2\rbrack^n = 2n\Delta t,
179+
\lbrack D_{2t} t^2\rbrack^n &= 2n\Delta t,
180180
label{form:Dop:tn2:2cn}\\
181-
\lbrack D_{t}D_t t^2\rbrack^n = 2,
181+
\lbrack D_{t}D_t t^2\rbrack^n &= 2,
182182
label{form:Dop2:tn2:cn}
183183
\end{align}
184184
!et
@@ -202,13 +202,15 @@ label{form:Dop2:tn3:cn}
202202

203203
===== Software =====
204204

205+
idx{`sympy`}
206+
205207
Application of finite difference operators to polynomials and exponential
206208
functions, resulting in the formulas above, can easily be computed by
207209
some `sympy` code (from the file "`lib.py`": "${src_formulas}/lib.py"):
208210

209211
@@@CODE src-formulas/lib.py fromto: from sympy import@import inspect
210212
To see the results, one can now make a simple loop over the different
211-
type of functions and the various operators associated with them:
213+
types of functions and the various operators associated with them:
212214

213215
!bc pycod
214216
for func in func_list:

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
===== Mathematical model =====
3636

37+
idx{`wave1D_dn_vc.py`}
38+
3739
Let $u_t$, $u_{tt}$, $u_x$, $u_{xx}$ denote derivatives of $u$ with
3840
respect to the subscript, i.e., $u_{tt}$ is a second-order time
3941
derivative and $u_x$ is a first-order space derivative. The
@@ -119,6 +121,8 @@ label{softeng2:wave1D:filestorage:savez}
119121

120122
=== Storing individual arrays ===
121123

124+
idx{`savez`} idx{`storez`} idx{`load`} idx{zip archive}
125+
122126
The `numpy.storez` function can store a set of arrays to a named
123127
file in a zip archive. An associated function
124128
`numpy.load` can be used to read the file later.
@@ -179,6 +183,8 @@ for array_name in array_names:
179183
===== Using `joblib` to store arrays in files =====
180184
label{softeng2:wave1D:filestorage:joblib}
181185

186+
idx{`joblib`} idx{memoize function} idx{hash}
187+
182188
The Python package `joblib` has nice functionality for efficient storage
183189
of arrays on disk. The following class applies this functionality so that
184190
one can save an array, or in fact any Python data structure (e.g., a
@@ -409,14 +415,16 @@ cite{Langtangen_deqbook_wave}]).
409415

410416
=== Convergence rates ===
411417

418+
idx{verification! convergence rates}
419+
412420
A more general method for verification is to check the convergence rates.
413421
We must introduce one discretization parameter $h$ and assume an error
414422
model $E=Ch^r$, where $C$ and $r$ are constants to be determine (i.e.,
415423
$r$ is the rate that we are interested in). Given two experiments with
416424
different resolutions $h_i$ and $h_i{-1}$, we can estimate $r$ by
417425

418426
!bt
419-
\[ r = \frac{\ln(E_{i}/E_{i-1})}{\ln(h_{i}h_{i-1}},tp\]
427+
\[ r = \frac{\ln(E_{i}/E_{i-1})}{\ln(h_{i}/h_{i-1})},\]
420428
!et
421429
where $E_i$ is the error corresponding to $h_i$ and $E_{i-1}$ corresponds to
422430
$h_{i-1}$. ref[Section ref{wave:pde2:fd:standing:waves}][ in cite{Langtangen_deqbook_wave}][The
@@ -427,7 +435,7 @@ for some constant $\hat c$. To compute the error, we had to rely on
427435
a global variable in the user action function. Below is an implementation
428436
where we have a more elegant solution in terms of a class: the `error`
429437
variable is not a class attribute and there is no need for a global
430-
error (which is always considered as an advantage).
438+
error (which is always considered an advantage).
431439

432440
@@@CODE src-wave/wave1D/wave1D_dn_vc.py def convergence_rates@def test_convrate_sincos
433441
The returned sequence `r` should converge to 2 since the error
@@ -445,6 +453,8 @@ cite{Langtangen_deqbook_wave}], see the file "`wave1D_dn_vc.py`":
445453

446454
======= Programming the solver with classes =======
447455

456+
idx{`wave1D_oo.py`}
457+
448458
Many who know about class programming prefer to organize their software
449459
in terms of classes. This gives a richer application programming interface
450460
(API) since a function solver must have all its input data in terms
@@ -506,7 +516,7 @@ documentation and a doc test should now be self-explanatory:
506516
@@@CODE src-softeng2/UniformFDMesh.py fromto: import numpy@class Function
507517

508518
!bnotice We rely on attribute access - not get/set functions!
509-
Java programmers in particular are used to get/set functions in
519+
Java programmers, in particular, are used to get/set functions in
510520
classes to access internal data. In Python, we usually apply direct
511521
access of the attribute, such as `m.N[i]` if `m` is a `Mesh` object.
512522
A widely used convention is to do this as long as access to
@@ -557,7 +567,7 @@ is reproduced (within machine precision).
557567
======= Migrating loops to Cython =======
558568
label{wave2D3D:impl:Cython}
559569

560-
idx{Cython}
570+
idx{Cython} idx{`wave2D_u0.py`} idx{`wave2D_u0_adv.py`}
561571

562572
We now consider the "`wave2D_u0.py`": "${src_wave}/wave2D_u0/wave2D_u0.py"
563573
code for solving the 2D linear wave equation with constant wave
@@ -594,6 +604,8 @@ in one or more separate files with extension `.pyx`.
594604

595605
===== Declaring variables and annotating the code =====
596606

607+
idx{`wave2D_u0_loop_cy.pyx`}
608+
597609
Our starting point is the plain `advance_scalar` function for a scalar
598610
implementation of the updating algorithm for new values
599611
$u^{n+1}_{i,j}$:
@@ -786,14 +798,16 @@ the Cython version.
786798

787799
======= Migrating loops to Fortran =======
788800

801+
idx{Fortran 77}
802+
789803
Instead of relying on Cython's (excellent) ability to translate Python to C,
790804
we can invoke a compiled language directly and write the loops ourselves.
791805
Let us start with Fortran 77, because this is a language with more
792806
convenient array handling than C (or plain C++), because
793807
we can use the same multi-dimensional indices
794808
in the Fortran code as in the `numpy`
795809
arrays in the Python code, while in C these arrays are
796-
one-dimensional and requires us to reduce multi-dimensional indices
810+
one-dimensional and require us to reduce multi-dimensional indices
797811
to a single index.
798812

799813
#Fortran compilers
@@ -804,6 +818,7 @@ to a single index.
804818

805819
idx{wrapper code}
806820
idx{Fortran subroutine}
821+
idx{`wave2D_u0_loop_f77.f`}
807822

808823
We write a Fortran subroutine `advance` in a file
809824
"`wave2D_u0_loop_f77.f`": "${src_wave}/wave2D_u0/wave2D_u0_loop_f77.f"
@@ -840,6 +855,8 @@ advance(u, u_n, u_nm1, f, Cx2, Cy2, dt2)
840855

841856
===== Building the Fortran module with f2py =====
842857

858+
idx{Fortran 90}
859+
843860
The nice feature of writing loops in Fortran is that, without
844861
much effort, the tool `f2py`
845862
can produce a C extension module such that
@@ -1094,10 +1111,10 @@ easier to debug.
10941111
!bwarning Be careful with macro definitions
10951112
Macros just perform simple text substitutions:
10961113
`idx(hello,world)` is expanded to `(hello)*(Ny+1) + world`.
1097-
The parenthesis in `(i)` are essential - using the natural mathematical
1114+
The parentheses in `(i)` are essential - using the natural mathematical
10981115
formula `i*(Ny+1) + j` in the macro definition,
10991116
`idx(i-1,j)` would expand to `i-1*(Ny+1) + j`, which is the wrong
1100-
formula. Macros are handy, but requires careful use.
1117+
formula. Macros are handy, but require careful use.
11011118
In C++, inline functions are safer and replace the need for macros.
11021119
!ewarning
11031120

@@ -1109,6 +1126,8 @@ The C version of our function `advance` can be coded as follows.
11091126

11101127
===== The Cython interface file =====
11111128

1129+
idx{`wave2D_u0_loop_c.c`} idx{`wave2D_u0_loop_c.h`}
1130+
11121131
All the code above appears in a file "`wave2D_u0_loop_c.c`":
11131132
"${src_wave}//wave2D_u0/wave2D_u0_loop_c.c".
11141133
We need to compile this file together with C wrapper code such that
@@ -1178,6 +1197,8 @@ words, that we work with small meshes.
11781197

11791198
======= Migrating loops to C via f2py =======
11801199

1200+
idx{`wave2D_u0_loop_c_f2py_signature.f`}
1201+
11811202
An alternative to using Cython for interfacing C code is to apply
11821203
`f2py`. The C code is the same, just the details of specifying how
11831204
it is to be called from Python differ. The `f2py` tool requires

0 commit comments

Comments
 (0)