Skip to content

Commit 15c7a35

Browse files
committed
Remove all Mako template conditionals from DocOnce source files
- Remove FEM_BOOK conditionals from nonlin chapter files - Remove BOOK == "book" conditionals, keeping book content - Remove FORMAT == "pdflatex" conditionals, keeping pdflatex content - Simplify make.sh: remove unused variables, single compile pass
1 parent 817e137 commit 15c7a35

13 files changed

Lines changed: 11 additions & 882 deletions

doc/.src/book/make.sh

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ set -x
1010
name=book
1111
topicname=fdm
1212

13-
encoding="--encoding=utf-8"
14-
15-
CHAPTER=chapter
16-
BOOK=book
17-
APPENDIX=appendix
18-
1913
function system {
2014
"$@"
2115
if [ $? -ne 0 ]; then
@@ -48,11 +42,7 @@ cp ../chapters/newcommands_keep.p.tex newcommands_keep.tex
4842
doconce replace 'newcommand{\E}' 'renewcommand{\E}' newcommands_keep.tex
4943
doconce replace 'newcommand{\I}' 'renewcommand{\I}' newcommands_keep.tex
5044

51-
# TASKS: generate book with solutions, also in the html version
52-
# Make pdfnup with two-pages per sheet
53-
54-
opt1="CHAPTER=$CHAPTER BOOK=$BOOK APPENDIX=$APPENDIX DOCUMENT=book $encoding FEM_BOOK=False"
55-
devices="screen paper"
45+
opt1="DOCUMENT=book --encoding=utf-8"
5646

5747
function edit_solution_admons {
5848
# We use question admon for typesetting solution, but let's edit to
@@ -155,43 +145,13 @@ system makeindex $name
155145
system pdflatex $name
156146
}
157147

158-
# Important: run with solutions first such that the .aux file
159-
# for the book, referred to by other documents, uses the .aux
160-
# file corresponding to a version without solutions.
161-
162-
# With solutions, password protected
148+
# Compile with solutions for screen
163149
compile --device=screen --skip_inline_comments
164-
newname=${topicname}-book-4screen-sol
165-
password="f!d!mbk"
166-
pdftk $name.pdf output $newname.pdf owner_pw foo user_pw $password
167-
cp $name.pdf ${name}-sol.pdf # good to have a copy without password
168-
169-
compile --device=screen --without_solutions --without_answers --skip_inline_comments
170-
newname=${topicname}-book-4screen
171-
cp $name.pdf $newname.pdf
172-
173-
#--latex_index_in_margin
174-
compile --device=paper --without_solutions --without_answers --skip_inline_comments
175-
newname=${topicname}-book-4print
176-
cp $name.pdf $newname.pdf
177-
pdfnup --frame true --outfile ${newname}-2up.pdf $newname.pdf
178-
cp $name.aux ${newname}.aux-final
179-
180-
# Report typical problems with the book (too long lines,
181-
# undefined labels, etc.). Here we report lines that are more than 10pt
182-
# too long.
183-
doconce latex_problems $name.log 10
184150

185-
# Check grammar in MS Word:
186-
# doconce spellcheck tmp_mako__book.do.txt
187-
# load tmp_stripped_book.do.txt into Word
151+
# Report typical problems (lines more than 10pt too long)
152+
doconce latex_problems $name.log 10
188153

189154
# Publish
190-
repo=../../..
191-
dest=${repo}/doc/pub/book
192-
if [ ! -d $dest ]; then mkdir $dest; fi
193-
if [ ! -d $dest/pdf ]; then mkdir $dest/pdf; fi
194-
cp ${topicname}-book*.pdf $dest/pdf
195-
cd $dest; git add .; cd -
196-
197-
# What about slides? They are published chapter wise!
155+
dest=../../../doc/pub/book/pdf
156+
mkdir -p $dest
157+
cp $name.pdf $dest/${topicname}-book.pdf

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,7 @@ Both roots have $|A|>1$ so the amplitude always grows, which is not in
663663
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.
666-
% if BOOK == 'book':
667666
Details are provided in Section ref{advec:1D:leapfrog}.
668-
% endif
669667

670668
===== Summary of accuracy of amplification factors =====
671669

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,12 @@ label{diffu:pde1:FEsec}
6767
Explicit finite difference methods for the wave equation $u_{tt}=c^2u_{xx}$
6868
can be used, with small modifications, for solving $u_t = \dfc u_{xx}$
6969
as well.
70-
% if BOOK == "book":
7170
The exposition below assumes that the reader is familiar with the
7271
basic ideas of discretization and implementation of wave
7372
equations from Chapter ref{ch:wave}. Readers not familiar with the
7473
Forward Euler, Backward Euler, and Crank-Nicolson (or centered or
75-
midpoint) discretization methods in time should consult, e.g., Section 1.1
74+
midpoint) discretization methods in time should consult, e.g., Section 1.1
7675
in cite{Langtangen_decay}.
77-
% endif
7876

7977
===== The initial-boundary value problem for 1D diffusion =====
8078

@@ -327,11 +325,7 @@ Inserted in the PDE, it requires a source term
327325
!bt
328326
\[ f(x,t) = 10\dfc t + 5x(L-x)\tp\]
329327
!et
330-
% if BOOK == 'book':
331328
With the formulas from Appendix ref{sec:form:fdtn} we can easily check
332-
% else:
333-
Let us check
334-
% endif
335329
that the manufactured `u` fulfills the scheme:
336330

337331
!bt
@@ -561,14 +555,8 @@ simulation. This non-physical noise is smoothed out with time, but
561555
solutions of the diffusion equations are known to be smooth, and
562556
this numerical solution is definitely not smooth.
563557
Lowering $F$ helps: $F\leq 0.25$ gives a smooth solution, see
564-
% if FORMAT == "pdflatex":
565558
Figure ref{diffu:pde1:FE:fig:F=0.25} (and a
566559
"movie": "${docraw}/mov-diffu/diffu1D_u0_FE_plug_F025/movie.ogg").
567-
% else:
568-
Figure ref{diffu:pde1:FE:fig:F=0.25}.
569-
570-
MOVIE: [mov-diffu/diffu1D_u0_FE_plug_F025/movie.ogg]
571-
% endif
572560

573561
Increasing $F$ slightly beyond the limit 0.5, to $F=0.51$,
574562
gives growing, non-physical instabilities,
@@ -586,10 +574,6 @@ Gaussian function for $I(x)$. A simulation for $F=0.5$
586574
is shown in Figure ref{diffu:pde1:FE:fig:gauss:F=0.5}. Now the numerical solution
587575
is smooth for all times, and this is true for any $F\leq 0.5$.
588576

589-
% if FORMAT != "pdflatex":
590-
MOVIE: [mov-diffu/diffu1D_u0_FE_gaussian1/movie.ogg]
591-
% endif
592-
593577
FIGURE: [fig-diffu/gaussian_FE_F05, width=800 frac=1] Forward Euler scheme for $F=0.5$. label{diffu:pde1:FE:fig:gauss:F=0.5}
594578

595579
Experiments with these two choices of $I(x)$ reveal some

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

Lines changed: 0 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -434,23 +434,8 @@ label{nonlin:exer:1D:1pu2:fem:pde}
434434
\end{equation}
435435
!et
436436

437-
% if FEM_BOOK:
438-
!bsubex
439-
Discretize (ref{nonlin:exer:1D:1pu2:fem:pde}) by a centered
440-
finite difference method on a uniform mesh.
441-
!esubex
442-
443-
!bsubex
444-
Discretize (ref{nonlin:exer:1D:1pu2:fem:pde}) by a finite
445-
element method with P1 elements of equal length.
446-
Use the Trapezoidal method to compute all integrals.
447-
Set up the resulting matrix system in symbolic form such that the
448-
equations can be compared with those in a).
449-
!esubex
450-
% else:
451437
Discretize (ref{nonlin:exer:1D:1pu2:fem:pde}) by a centered
452438
finite difference method on a uniform mesh.
453-
% endif
454439

455440
===== Problem: Linearize a 1D problem with a nonlinear coefficient =====
456441
label{nonlin:exer:1D:1pu2:PicardNewton}
@@ -550,117 +535,6 @@ in each iteration, where $u$ is solution in the current iteration and
550535
$u^{-}$ is the solution in the previous iteration.
551536
!esubex
552537

553-
% if FEM_BOOK:
554-
===== Problem: Integrate functions of finite element expansions =====
555-
label{nonlin:exer:fu:fem:int}
556-
file=fu_fem_int
557-
558-
idx{`latex.codecogs.com` web site}
559-
idx{online rendering of LaTeX formulas}
560-
561-
We shall investigate integrals on the form
562-
563-
!bt
564-
\begin{equation}
565-
\int_0^L f(\sum_ku_k\basphi_k(x))\basphi_i(x)\dx,
566-
label{nonlin:exer:fu:fem:int:global}
567-
\end{equation}
568-
!et
569-
where $\basphi_i(x)$ are P1 finite element basis functions and $u_k$
570-
are unknown coefficients, more precisely the values of the unknown
571-
function $u$ at nodes $\xno{k}$. We introduce a node numbering that
572-
goes from left to right and also that all cells have
573-
the same length $h$. Given $i$, the integral
574-
only gets contributions from $[\xno{i-1},\xno{i+1}]$. On this
575-
interval $\basphi_k(x)=0$ for $k<i-1$ and $k>i+1$, so only three
576-
basis functions will contribute:
577-
578-
!bt
579-
\[
580-
\sum_k u_k\basphi_k(x) = u_{i-1}\basphi_{i-1}(x) +
581-
u_{i}\basphi_{i}(x) + u_{i+1}\basphi_{i+1}(x)\tp
582-
\]
583-
!et
584-
The integral (ref{nonlin:exer:fu:fem:int:global}) now takes the
585-
simplified form
586-
587-
!bt
588-
\[
589-
\int_{\xno{i-1}}^{\xno{i+1}}
590-
f(u_{i-1}\basphi_{i-1}(x) +
591-
u_{i}\basphi_{i}(x) + u_{i+1}\basphi_{i+1}(x))\basphi_i(x)\dx\tp
592-
\]
593-
!et
594-
Split this integral in two integrals over cell L (left),
595-
$[\xno{i-1},\xno{i}]$, and cell R (right), $[\xno{i},\xno{i+1}]$. Over
596-
cell L, $u$ simplifies to $u_{i-1}\basphi_{i-1} + u_{i}\basphi_{i}$
597-
(since $\basphi_{i+1}=0$ on this cell), and over cell R, $u$
598-
simplifies to $u_{i}\basphi_{i} + u_{i+1}\basphi_{i+1}$. Make a
599-
`sympy` program that can compute the integral and write it out as a
600-
difference equation. Give the $f(u)$ formula on the command line.
601-
Try out $f(u)=u^2, \sin u, \exp u$.
602-
603-
!bhint
604-
Introduce symbols `u_i`, `u_im1`, and `u_ip1` for $u_i$, $u_{i-1}$,
605-
and $u_{i+1}$, respectively, and similar symbols for $x_i$, $x_{i-1}$,
606-
and $x_{i+1}$. Find formulas for the basis functions on each of the
607-
two cells, make expressions for $u$ on the two cells, integrate over
608-
each cell, expand the answer and simplify. You can ask `sympy` for
609-
LaTeX code and render it either by creating a LaTeX document and
610-
compiling it to a PDF document or by using
611-
URL: "http://latex.codecogs.com" to display LaTeX formulas in a web
612-
page. Here are some appropriate Python statements
613-
for the latter purpose:
614-
615-
!bc pycod
616-
from sympy import *
617-
...
618-
# expr_i holdes the integral as a sympy expression
619-
latex_code = latex(expr_i, mode='plain')
620-
# Replace u_im1 sympy symbol name by latex symbol u_{i-1}
621-
latex_code = latex_code.replace('im1', '{i-1}')
622-
# Replace u_ip1 sympy symbol name by latex symbol u_{i+1}
623-
latex_code = latex_code.replace('ip1', '{i+1}')
624-
# Escape (quote) latex_code so it can be sent as HTML text
625-
import cgi
626-
html_code = cgi.escape(latex_code)
627-
# Make a file with HTML code for displaying the LaTeX formula
628-
f = open('tmp.html', 'w')
629-
# Include an image that can be clicked on to yield a new
630-
# page with an interactive editor and display area where the
631-
# formula can be further edited
632-
text = """
633-
<a href="http://www.codecogs.com/eqnedit.php?latex=%(html_code)s"
634-
target="_blank">
635-
<img src="http://latex.codecogs.com/gif.latex?%(html_code)s"
636-
title="%(latex_code)s"/>
637-
</a>
638-
""" % vars()
639-
f.write(text)
640-
f.close()
641-
!ec
642-
The formula is displayed by loading `tmp.html` into a web browser.
643-
!ehint
644-
645-
===== Problem: Finite elements for the 1D Bratu problem =====
646-
label{nonlin:exer:1D:fu:discretize:fe}
647-
file=nonlin_1D_Bratu_fe
648-
649-
We address the same 1D Bratu problem as described in
650-
Problem ref{nonlin:exer:1D:fu:discretize:fd}.
651-
652-
!bsubex
653-
Discretize (ref{nonlin:exer:1D:fu:discretize:fe}) by a finite element
654-
method using a uniform mesh with P1 elements. Use a group
655-
finite element method for the $e^u$ term.
656-
!esubex
657-
658-
!bsubex
659-
Set up the nonlinear equations $F_i(u_0,u_1,\ldots,u_{N_x})=0$
660-
from a). Calculate the associated Jacobian.
661-
!esubex
662-
% endif
663-
664538

665539
===== Problem: Discretize a nonlinear 1D heat conduction PDE by finite differences =====
666540
label{nonlin:exer:1D:heat:nonlinear:fdm}
@@ -709,78 +583,6 @@ Derive the matrix and right-hand side of a Newton method applied
709583
to the discretized PDE in d).
710584
!esubex
711585

712-
% if FEM_BOOK:
713-
===== Exercise: Use different symbols for different approximations of the solution =====
714-
label{nonlin:exer:dD:nonlinear:usymbols}
715-
file=nonlin_heat_FE_usymbols
716-
717-
The symbol $u$ has several meanings, depending on the context, as
718-
briefly mentioned in Section ref{nonlin:alglevel:dD:fe}.
719-
Go through the derivation of the Picard iteration method in
720-
that section and use different symbols for all the different
721-
approximations of $u$:
722-
723-
* $\uex(\x,t)$ for the exact solution of the PDE problem
724-
* $\uex(\x)^n$ for the exact solution after time discretization
725-
* $u^n(\x)$ for the spatially discrete solution $\sum_jc_j\baspsi_j$
726-
* $u^{n,k}$ for approximation in Picard/Newton iteration no $k$
727-
to $u^n(\x)$
728-
729-
===== Exercise: Derive Picard and Newton systems from a variational form =====
730-
label{nonlin:exer:dD:heat:nonlinear:c:a}
731-
file=nonlin_heat_FE
732-
733-
We study the multi-dimensional heat conduction PDE
734-
735-
!bt
736-
\[ \varrho c(T) T_t = \nabla\cdot (k(T)\nabla T)\]
737-
!et
738-
in a spatial domain $\Omega$, with a nonlinear Robin boundary condition
739-
740-
!bt
741-
\[ -k(T)\frac{\partial T}{\partial n} = h(T)(T-T_s(t)),\]
742-
!et
743-
at the boundary $\partial\Omega$.
744-
The primary unknown is the temperature $T$, $\varrho$ is the density
745-
of the solid material, $c(T)$ is the heat capacity, $k(T)$ is
746-
the heat conduction, $h(T)$ is a heat transfer coefficient, and
747-
$T_s(T)$ is a possibly time-dependent temperature of the surroundings.
748-
749-
!bsubex
750-
Use a Backward Euler or Crank-Nicolson time discretization and
751-
derive the variational form for the spatial problem to be solved
752-
at each time level.
753-
!esubex
754-
755-
!bsubex
756-
Define a Picard iteration method from the variational form at
757-
a time level.
758-
!esubex
759-
760-
!bsubex
761-
Derive expressions for the matrix and the right-hand side of the
762-
equation system that arises from applying Newton's method to
763-
the variational form at a time level.
764-
!esubex
765-
766-
!bsubex
767-
Apply the Backward Euler or Crank-Nicolson scheme in time first.
768-
Derive a Newton method at the PDE level. Make a variational
769-
form of the resulting PDE at a time level.
770-
!esubex
771-
772-
===== Exercise: Derive algebraic equations for nonlinear 1D heat conduction =====
773-
label{nonlin:exer:1D:heat:nonlinear:c:a}
774-
file=nonlin_1D_heat_FE
775-
776-
We consider the same problem as in Exercise ref{nonlin:exer:dD:heat:nonlinear:c:a}, but restricted to one space dimension: $\Omega = [0,L]$.
777-
Simplify the boundary condition to $T_x=0$ (i.e., $h(T)=0$).
778-
Use a uniform finite element mesh of P1 elements, the group
779-
finite element method, and the Trapezoidal
780-
rule for integration at the nodes to derive symbolic expressions for
781-
the algebraic equations arising from this diffusion problem.
782-
% endif
783-
784586
===== Problem: Differentiate a highly nonlinear term =====
785587
label{nonlin:exer:grad:pow:term}
786588
file=nonlin_differentiate

0 commit comments

Comments
 (0)