Skip to content

Commit 817e137

Browse files
committed
Remove preprocessor directives from DocOnce source files
- Delete all slides directories and slide entry files (6 chapters) - Delete index_files.do.txt - Remove FORMAT conditionals, keeping only LaTeX/PDF content - Remove named flags (OLD, NOTREADY, 2DO, etc.), keeping EXTRA content - Simplify newcommands_keep.p.tex to plain LaTeX (no preprocessing) - Update make.sh to copy instead of preprocess newcommands file - Fix swapped label references in trunc.do.txt
1 parent 17e6a0a commit 817e137

46 files changed

Lines changed: 2 additions & 10351 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/book/book.do.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
# #if FORMAT == "sphinx"
2-
# Sphinx can only treat 63 chars in title
3-
TITLE: Finite Difference Computing with PDEs
4-
# #else
51
TITLE: Finite Difference Computing with PDEs - A Modern Software Approach
6-
# #endif
72
AUTHOR: Hans Petter Langtangen {copyright|CC BY} at Center for Biomedical Computing, Simula Research Laboratory & Department of Informatics, University of Oslo
83
AUTHOR: Svein Linge {copyright|CC BY} at Department of Process, Energy and Environmental Technology, University College of Southeast Norway & Center for Biomedical Computing, Simula Research Laboratory
94

doc/.src/book/make.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ if [ "$spellcheck" != 'nospell' ]; then
4444
fi
4545
fi
4646

47-
system preprocess -DFORMAT=pdflatex ../chapters/newcommands_keep.p.tex > newcommands_keep.tex
47+
cp ../chapters/newcommands_keep.p.tex newcommands_keep.tex
4848
doconce replace 'newcommand{\E}' 'renewcommand{\E}' newcommands_keep.tex
4949
doconce replace 'newcommand{\I}' 'renewcommand{\I}' newcommands_keep.tex
5050

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -197,22 +197,6 @@ the exact solution fulfilling the differential equation to the
197197
symbol `u` that is naturally used for the associated data structure
198198
in the code.
199199

200-
# #ifdef FEM
201-
The mathematical notation in this book is somewhat
202-
different from the vast literature.
203-
My aim is to introduce a mathematical notation that is as
204-
close as possible to what we will implement in computer code. That
205-
is, the way we program dictates the way we write mathematical
206-
formulas. The overall goal is to have as small distance as possible
207-
between the mathematics and the code. This is principal goal of the
208-
FEniCS project, and this book implements a similar goal also for
209-
mathematically very simple problems. Essentially, we apply a
210-
more classical notation when deriving methods, but then we
211-
get rid of unnecessary indices and other types of
212-
``cluttered notation'' that one would never use in code.
213-
The minimization of indices in the resulting formulas also help
214-
make the mathematical problem cleaner and clearer for students.
215-
# #endif
216200

217201
=== Limited scope ===
218202

@@ -284,9 +268,7 @@ laboratory's financial contribution as well as to the financial
284268
contribution from the Department of Process, Energy and Environmental
285269
Technology at the University College of Southeast Norway.
286270

287-
# #if FORMAT in ("latex", "pdflatex")
288271
\vspace{1cm}
289272

290273
\noindent
291274
{\it Oslo, July 2016} \hfill {\it Hans Petter Langtangen, Svein Linge}
292-
# #endif

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

Lines changed: 0 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -930,149 +930,6 @@ Figure ref{diffu:pde1:CN:fig:F=10}. The only remedy is to lower the $F$ value.
930930

931931

932932

933-
# #ifdef OLD
934-
#Case from Elements book where $C=0.45$ with $\Delta x=1/20, 1/60$,
935-
#$t=0.1$ and two clearly different plots. Wrong or correct? Formulate
936-
#problem. How long does it take to reach the level $u=1E-4$? Test two
937-
#grids, two significantly different times. Investigate with analysis.}
938-
#Say we simulate up to a time point $t$ and examine the amplitude:
939-
940-
!bt
941-
\begin{equation*} A = \left(1 -4C\sin^2\left(\frac{k\Delta x}{2}\right)\right)^{n}\end{equation*}
942-
!et
943-
944-
!bt
945-
\begin{equation*} A = \left(1 -4C\sin^2\left(\frac{k\Delta x}{2}\right)\right)^{t/\Delta t}\end{equation*}
946-
!et
947-
948-
!bt
949-
\begin{equation*} A = \left(1 -4C\sin^2\left(\frac{k\Delta x}{2}\right)\right)^{t/(C\Delta x^2)}\end{equation*}
950-
!et
951-
Expanding this in $\Delta x$ is too complicated for sympy.
952-
Better to plot this numerical A as function of $\Delta x$ and compare with
953-
the constant value from the exact expression:
954-
955-
!bt
956-
\begin{equation*} A = e^{-\dfc k^2t}\end{equation*}
957-
!et
958-
FE.py plots the two and show how the numerical amplitude falls off
959-
as $\Delta x$ increases. Maybe this should make it into the text!
960-
It's yet another good example on a plot that looks strange.
961-
Maybe it would be good to embed the problem in a more real problem
962-
where something is decaying and then use the analysis to explain, using
963-
sine variation in space. With $k=3\pi$ we speak about a fairly smooth
964-
thing. There is probably a lot to explore along these lines.
965-
966-
OK, here is the problem: some diffusion problem, big and small
967-
grid, simulate to a certain time, measure the level of the peak,
968-
see that the differences are substantial. Wrong implementation or
969-
a feature of the method? In the analysis we can look at FE, BE and CN.
970-
971-
I'm not sure the rest is of value. NO!
972-
973-
!bt
974-
\begin{equation*} = e^{-alpha k^2 nC\Delta x^2} = (e^{-alpha k^2 C\Delta x^2})^n\end{equation*}
975-
!et
976-
FE.py says this error is
977-
978-
!bt
979-
\begin{equation*} \half C^2\Delta x^4 k^4\end{equation*}
980-
!et
981-
But it is the power $n$ that is important, it is large/small for fine/coarse
982-
grid.
983-
984-
Logarithms:
985-
986-
!bt
987-
\begin{equation*} \ln A = \frac{t}{C\Delta x^2}\ln \left(1 -4C\sin^2\left(\frac{k\Delta x}{2}\right)\right)\end{equation*}
988-
!et
989-
990-
!bt
991-
\begin{equation*} \ln A = -\dfc k^2t\end{equation*}
992-
!et
993-
FE.py didn't bring me to a clear answer. The error in $A$ is not enough,
994-
because coarse/fine grid has small/large $n$.
995-
996-
997-
998-
Say we want to reduce $u$ by a factor of $r$:
999-
1000-
!bt
1001-
\begin{equation*} \left(1 -4C\sin^2\left(\frac{k\Delta x}{2}\right)\right)^n = r\end{equation*}
1002-
!et
1003-
1004-
!bt
1005-
\begin{equation*} n = \ln r /\ln \left(1 -4C\sin^2\left(\frac{k\Delta x}{2}\right)\right)\end{equation*}
1006-
!et
1007-
1008-
!bt
1009-
\begin{equation*} t = \Delta t\ln r /\ln \left(1 -4C\sin^2\left(\frac{k\Delta x}{2}\right)\right)\end{equation*}
1010-
!et
1011-
1012-
!bt
1013-
\begin{equation*} t = C\Delta x^2\ln r /\ln \left(1 -4C\sin^2\left(\frac{k\Delta x}{2}\right)\right)\end{equation*}
1014-
!et
1015-
1016-
1017-
1018-
=== The Backward Euler Scheme ===
1019-
1020-
Inserting (ref{diffu:pde1:analysis:uni})
1021-
in
1022-
1023-
!bt
1024-
\begin{equation*} [D_t^- u = \dfc D_xD_x u]^n_j,\end{equation*}
1025-
!et
1026-
and dividing by $A^n e^{ikx}$ results in
1027-
1028-
!bt
1029-
\begin{equation*}
1030-
\frac{1-A^{-1}}{\Delta t} = -\dfc \frac{4}{\Delta x^2}\sin^2\left(
1031-
\frac{k\Delta x}{2}\right) \tp
1032-
\end{equation*}
1033-
!et
1034-
Solving with respect to $A$ gives an amplification factor of
1035-
1036-
1037-
=== The $\theta$ Rule ===
1038-
1039-
The analysis of the
1040-
$\theta$ rule becomes easy if we express the scheme
1041-
as
1042-
1043-
!bt
1044-
\begin{equation*} [D_t u]^{n+\halfi}_j = \dfc\theta [D_xD_x]^{n}_j +
1045-
\dfc(1-\theta)[D_xD_x]^{n-1}_j \tp \end{equation*}
1046-
!et
1047-
Inserting (ref{diffu:pde1:analysis:uni}) and dividing by
1048-
$A^n e^{ikx}$ gives the equation
1049-
1050-
!bt
1051-
\begin{equation*} \frac{A-1}{\Delta t} =
1052-
\dfc 4C\sin^2\left(
1053-
\frac{k\Delta x}{2}\right)\left( \theta A +
1054-
(1-\theta)\right),\end{equation*}
1055-
!et
1056-
which leads to
1057-
1058-
!bt
1059-
\begin{equation}
1060-
A = \frac{1 - \dfc (1-\theta)}{1+\dfc\theta}
1061-
C\sin^2\left(
1062-
\frac{k\Delta x}{2}\right),
1063-
\end{equation}
1064-
!et
1065-
and
1066-
1067-
!bt
1068-
\begin{equation}
1069-
u^n_j = \left(\frac{1 - \dfc (1-\theta)}{1+\dfc\theta}
1070-
C\sin^2\left(
1071-
\frac{k\Delta x}{2}\right)\right)^n e^{ikj\Delta x} \tp \end{equation}
1072-
!et
1073-
1074-
Use these in tests....
1075-
# #endif
1076933

1077934
======= Exercises =======
1078935

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

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ We shall start with the simplest boundary condition: $u=0$. The
9494
complete initial-boundary value diffusion problem in one space
9595
dimension can then be specified as
9696

97-
# #if FORMAT in ("latex", "pdflatex")
9897
!bt
9998
\begin{alignat}{3}
10099
\frac{\partial u}{\partial t} &=
@@ -109,21 +108,6 @@ u(L,t) & = 0, \quad & t>0
109108
label{diffu:pde1:bc:L}
110109
\end{alignat}
111110
!et
112-
# #else
113-
!bt
114-
\begin{align}
115-
\frac{\partial u}{\partial t} &=
116-
\dfc \frac{\partial^2 u}{\partial x^2} + f, \quad x\in (0,L),\ t\in (0,T]
117-
label{diffu:pde1}\\
118-
u(x,0) &= I(x), \quad x\in [0,L]
119-
label{diffu:pde1:ic:u}\\
120-
u(0,t) & = 0, \quad t>0,
121-
label{diffu:pde1:bc:0}\\
122-
u(L,t) & = 0, \quad t>0\tp
123-
label{diffu:pde1:bc:L}
124-
\end{align}
125-
!et
126-
# #endif
127111
With only a first-order derivative in time,
128112
only one *initial condition* is needed, while the second-order
129113
derivative in space leads to a demand for two *boundary conditions*.
@@ -1137,13 +1121,11 @@ be first order convergence, whereas with $\theta=0.5$ (i.e., Crank-Nicolson), on
11371121
second order convergence (as outlined in previous sections).
11381122

11391123

1140-
# #ifdef EXTRA
11411124
!bt
11421125
\begin{equation}
11431126
[D_t u = \dfc D_xD_x \overline{u}^{t,\theta}]^n_i
11441127
\end{equation}
11451128
!et
1146-
# #endif
11471129

11481130
===== Experiments =====
11491131
label{diffu:pde1:theta:experiments}
@@ -1217,121 +1199,3 @@ pseudo time variable.
12171199

12181200
[hpl: Better to say the last sentence when we treat iterative methods.]
12191201

1220-
# #ifdef 2DO
1221-
1222-
===== Extensions =====
1223-
1224-
These extensions are performed exactly as for a wave equation as they
1225-
only affect the spatial derivatives (which are the same as in the
1226-
wave equation).
1227-
1228-
* Variable coefficients
1229-
* Neumann and Robin conditions
1230-
* 2D and 3D
1231-
1232-
Future versions of this document will for completeness and
1233-
independence of the wave equation document feature info on the three
1234-
points. The Robin condition is new, but straightforward to handle:
1235-
1236-
!bt
1237-
\[ -\dfc\frac{\partial u}{\partial n} = h_T(u-U_s),\quad
1238-
[-\dfc D_x u = h_T(u-U_s)]^n_i
1239-
\]
1240-
!et
1241-
1242-
===== Implementation =====
1243-
label{diffu:pde1:impl}
1244-
1245-
1246-
===== Adaptive Time Stepping =====
1247-
1248-
Intuitive approach based on strategies from ODE decay equation and
1249-
a very discrete Fourier composition of analytical components.
1250-
What about $||u_t|| < \epsilon_L \Rightarrow \Delta t$ doubled,
1251-
$||u_t|| > \epsilon_U \Rightarrow \Delta t$ halved? Google...
1252-
1253-
1254-
1255-
===== Variable Diffusion Coefficient =====
1256-
1257-
1258-
!bt
1259-
\begin{equation}
1260-
\frac{\partial u}{\partial t} =
1261-
\frac{\partial}{\partial x}\left(
1262-
\dfc(x) \frac{\partial u}{\partial x}\right)
1263-
\end{equation}
1264-
!et
1265-
1266-
It is always very useful to have analytical solutions to PDEs.
1267-
For the variable coefficient diffusion equation this is difficult
1268-
to find unless we add a source term and apply the method of
1269-
manufactured solutions. In the limit $t\rightarrow\infty$, however,
1270-
we can derive an analytical solution.
1271-
The limit problem for the stationary solution
1272-
$v(x) = \lim_{t\rightarrow \infty} u(x,t)$,
1273-
assuming $\partial u/\partial t\rightarrow 0$ in this limit, becomes
1274-
1275-
!bt
1276-
\begin{equation}
1277-
\frac{\partial}{\partial x}\left(
1278-
\dfc(x) \frac{\partial u}{\partial x}\right)
1279-
= 0,\quad v(0)=u_L,\ v(L)=u_R \tp \end{equation}
1280-
!et
1281-
Integrating twice results in
1282-
1283-
!bt
1284-
\begin{equation*} v = C_2 + C_1\int_0^x \frac{1}{\dfc(\xi)} d\xi \tp \end{equation*}
1285-
!et
1286-
The two integration constants $C_1$ and $C_2$ are determined from
1287-
the boundary conditions, and $v(x)$ becomes
1288-
1289-
!bt
1290-
\begin{equation}
1291-
v(x) = u_L + (u_R - u_L)
1292-
\frac{\int_0^x\frac{d\xi}{a(\xi)}}{\int_0^L\frac{d\xi}{a(\xi)}}
1293-
\end{equation}
1294-
!et
1295-
1296-
Evaluation of $v$ on a mesh with points $x_i$, $i=0,\ldots,N_x$,
1297-
can be performed using the Trapezoidal rule.
1298-
Defining $g(x) = \int_0^x (\dfc(\xi))^{-1}d\xi$, $g_j$ can be
1299-
computed as
1300-
1301-
!bt
1302-
\begin{equation}
1303-
g_i = \left\lbrace\begin{array}{ll}
1304-
\half \Delta x /\dfc_i, & i = 0,\\
1305-
g_{i-1} + \Delta x /\dfc_i, & 0 < i < N_x,\\
1306-
g_{i-1} + \half\Delta x /\dfc_i, & i = N_x \tp \end{array}\right.
1307-
\end{equation}
1308-
!et
1309-
Then
1310-
1311-
!bt
1312-
\begin{equation}
1313-
v_i = u_L + (u_R - u_L)g_i/g_{N_x} \tp \end{equation}
1314-
!et
1315-
The corresponding implementation can be written
1316-
1317-
!bc pycod
1318-
def u_exact_stationary(x, a, u_L, u_R):
1319-
Nx = x.size - 1
1320-
g = zeros(Nx+1) # integral of 1/a from 0 to x
1321-
dx = x[1] - x[0] # assumed constant
1322-
i = 0
1323-
g[i] = 0.5*dx/a[i]
1324-
for i in range(1, Nx):
1325-
g[i] = g[i-1] + dx/a[i]
1326-
i = Nx
1327-
g[i] = g[i-1] + 0.5*dx/a[i]
1328-
v = u_L + (u_R - u_L)*g/g[-1]
1329-
return v
1330-
!ec
1331-
1332-
1333-
1334-
======= Two-Dimensional Diffusion =======
1335-
label{diffu:2D}
1336-
1337-
# #endif

0 commit comments

Comments
 (0)