Skip to content

Commit 34acdb4

Browse files
authored
Merge pull request #103 from devitocodes/devito-em
Devito em
2 parents fb32dc7 + 1da012f commit 34acdb4

403 files changed

Lines changed: 21720 additions & 28767 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.

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ doc/pub/
5353
/_book/
5454
**/*.quarto_ipynb
5555

56+
# Root-level TeX artifacts (Quarto/Pandoc intermediates)
57+
/*.tex
58+
59+
# Quarto HTML render artifacts
60+
**/*_files/
61+
62+
# Review and planning documents
63+
book-review.md
64+
codex-review.md
65+
codex-reviewer.md
66+
review.md
67+
review-2.md
68+
review-3.md
69+
review-4.md
70+
ianmgdev_review.txt
71+
*.docx
72+
Proposed Extension Roadmap*.md
73+
5674
# Coverage
5775
.coverage
5876
coverage.xml

.typos.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ ue = "ue"
66
# Strang splitting (named after mathematician Gilbert Strang)
77
strang = "strang"
88
Strang = "Strang"
9+
# Variable name for "p at iteration n" in Jacobi iteration
10+
pn = "pn"
11+
# Journal abbreviation: "J. Comput. Phys."
12+
Comput = "Comput"

Makefile

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Makefile for Finite Difference Computing with PDEs book
2+
3+
.PHONY: pdf html all preview clean test test-devito test-no-devito lint format check help
4+
5+
# Default target
6+
all: pdf html
7+
8+
# Build targets
9+
pdf:
10+
quarto render --to pdf
11+
12+
html:
13+
quarto render --to html
14+
15+
# Build both PDF and HTML
16+
book:
17+
quarto render
18+
19+
# Live preview with hot reload
20+
preview:
21+
quarto preview
22+
23+
# Clean build artifacts
24+
clean:
25+
rm -rf _book/
26+
rm -rf .quarto/
27+
find . -name "*.aux" -delete
28+
find . -name "*.log" -delete
29+
find . -name "*.out" -delete
30+
31+
# Test targets
32+
test:
33+
pytest tests/ -v
34+
35+
test-devito:
36+
pytest tests/ -v -m devito
37+
38+
test-no-devito:
39+
pytest tests/ -v -m "not devito"
40+
41+
test-phase1:
42+
pytest tests/test_elliptic_devito.py tests/test_burgers_devito.py tests/test_swe_devito.py -v
43+
44+
# Linting and formatting
45+
lint:
46+
ruff check src/
47+
48+
format:
49+
ruff check --fix src/
50+
isort src/
51+
52+
check:
53+
pre-commit run --all-files
54+
55+
# Help
56+
help:
57+
@echo "Available targets:"
58+
@echo " pdf - Build PDF (default)"
59+
@echo " html - Build HTML"
60+
@echo " book - Build all formats (PDF + HTML)"
61+
@echo " preview - Live preview with hot reload"
62+
@echo " clean - Remove build artifacts"
63+
@echo " test - Run all tests"
64+
@echo " test-devito - Run only Devito tests"
65+
@echo " test-no-devito - Run tests without Devito"
66+
@echo " test-phase1 - Run Phase 1 tests (elliptic, burgers, swe)"
67+
@echo " lint - Check code with ruff"
68+
@echo " format - Auto-format code with ruff and isort"
69+
@echo " check - Run all pre-commit hooks"
70+
@echo " help - Show this help message"

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,30 @@ Based on *Finite Difference Computing with Partial Differential Equations* by Ha
1616
Devito is a domain-specific language (DSL) embedded in Python for solving PDEs using finite differences. Instead of manually implementing stencil operations, you write mathematical expressions symbolically and Devito generates optimized C code:
1717

1818
```python
19-
from devito import Grid, TimeFunction, Eq, Operator
19+
import numpy as np
20+
from devito import Constant, Eq, Grid, Operator, TimeFunction, solve
2021

2122
# Define computational grid
2223
grid = Grid(shape=(101,), extent=(1.0,))
2324

2425
# Create field with time derivative capability
2526
u = TimeFunction(name='u', grid=grid, time_order=2, space_order=2)
2627

27-
# Write the wave equation symbolically
28-
eq = Eq(u.dt2, c**2 * u.dx2)
28+
# Wave speed parameter (passed at runtime)
29+
c = Constant(name="c")
30+
31+
# Set an initial condition (Gaussian pulse)
32+
x = np.linspace(0.0, 1.0, 101)
33+
u.data[0, :] = np.exp(-((x - 0.5) ** 2) / (2 * 0.1**2))
34+
u.data[1, :] = u.data[0, :] # zero initial velocity (demo)
35+
36+
# Write the wave equation symbolically and derive an explicit update stencil
37+
pde = Eq(u.dt2, c**2 * u.dx2)
38+
update = Eq(u.forward, solve(pde, u.forward))
2939

3040
# Devito generates optimized C code automatically
31-
op = Operator([eq])
32-
op.apply(time_M=100, dt=0.001)
41+
op = Operator([update])
42+
op.apply(time_M=100, dt=0.001, c=1.0)
3343
```
3444

3545
## Quick Start

_quarto.yml

Lines changed: 99 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,28 @@ book:
66
title: "Finite Difference Computing with PDEs"
77
subtitle: "A Devito Approach"
88
author:
9-
- name: Hans Petter Langtangen
10-
- name: Svein Linge
9+
- name: Gerard J. Gorman
10+
affiliation: Imperial College London
1111
date: today
1212
chapters:
1313
- index.qmd
1414
- chapters/preface/index.qmd
15+
# Note: chapters/vib/ exists on disk but is excluded from the build.
16+
# The vibration ODE content from the original Langtangen & Linge text
17+
# has not yet been ported to the Devito approach. Readers interested
18+
# in vibration ODEs can refer to Langtangen_deqbook_vib in the bibliography.
1519
- part: "Main Chapters"
1620
chapters:
1721
- chapters/devito_intro/index.qmd
1822
- chapters/wave/index.qmd
1923
- chapters/diffu/index.qmd
2024
- chapters/advec/index.qmd
2125
- chapters/nonlin/index.qmd
26+
- chapters/elliptic/index.qmd
27+
- chapters/systems/index.qmd
28+
- part: "Applications"
29+
chapters:
30+
- chapters/applications/electromagnetics/index.qmd
2231
- part: "Appendices"
2332
chapters:
2433
- chapters/appendices/formulas/index.qmd
@@ -39,6 +48,86 @@ format:
3948
number-depth: 3
4049
crossref:
4150
chapters: true
51+
include-in-header:
52+
text: |
53+
<script>
54+
MathJax = {
55+
tex: {
56+
macros: {
57+
half: "\\frac{1}{2}",
58+
halfi: "{1/2}",
59+
tp: "\\thinspace .",
60+
Ddt: ["\\frac{D #1}{dt}", 1],
61+
E: ["\\text{E}\\lbrack #1 \\rbrack", 1],
62+
Var: ["\\text{Var}\\lbrack #1 \\rbrack", 1],
63+
Std: ["\\text{Std}\\lbrack #1 \\rbrack", 1],
64+
xpoint: "\\boldsymbol{x}",
65+
normalvec: "\\boldsymbol{n}",
66+
Oof: ["\\mathcal{O}(#1)", 1],
67+
x: "\\boldsymbol{x}",
68+
X: "\\boldsymbol{X}",
69+
uu: "\\boldsymbol{u}",
70+
vv: "\\boldsymbol{v}",
71+
w: "\\boldsymbol{w}",
72+
acc: "\\boldsymbol{a}",
73+
rpos: "\\boldsymbol{r}",
74+
V: "\\boldsymbol{V}",
75+
e: "\\boldsymbol{e}",
76+
f: "\\boldsymbol{f}",
77+
F: "\\boldsymbol{F}",
78+
stress: "\\boldsymbol{\\sigma}",
79+
strain: "\\boldsymbol{\\varepsilon}",
80+
stressc: "{\\sigma}",
81+
strainc: "{\\varepsilon}",
82+
I: "\\boldsymbol{I}",
83+
T: "\\boldsymbol{T}",
84+
U: "\\boldsymbol{U}",
85+
q: "\\boldsymbol{q}",
86+
g: "\\boldsymbol{g}",
87+
dfc: "\\alpha",
88+
ii: "\\boldsymbol{i}",
89+
jj: "\\boldsymbol{j}",
90+
kk: "\\boldsymbol{k}",
91+
ir: "\\boldsymbol{i}_r",
92+
ith: "\\boldsymbol{i}_{\\theta}",
93+
iz: "\\boldsymbol{i}_z",
94+
Ix: "\\mathcal{I}_x",
95+
It: "\\mathcal{I}_y",
96+
Iz: "\\mathcal{I}_z",
97+
It: "\\mathcal{I}_t",
98+
If: "\\mathcal{I}_s",
99+
Ifd: "{I_d}",
100+
Ifb: "{I_b}",
101+
setb: ["#1^0", 1],
102+
sete: ["#1^{-1}", 1],
103+
setl: ["#1^-", 1],
104+
setr: ["#1^+", 1],
105+
seti: ["#1^i", 1],
106+
sequencei: ["\\left\\{ {#1}_i \\right\\}_{i\\in\\If}", 1],
107+
sequencej: ["\\left\\{ {#1}_j \\right\\}_{j\\in\\If}", 1],
108+
stepzero: "*",
109+
stephalf: "***",
110+
stepone: "**",
111+
basphi: "\\varphi",
112+
baspsi: "\\psi",
113+
refphi: "\\tilde\\basphi",
114+
psib: "\\boldsymbol{\\psi}",
115+
sinL: ["\\sin\\left((#1+1)\\pi\\frac{x}{L}\\right)", 1],
116+
xno: ["x_{#1}", 1],
117+
Xno: ["X_{(#1)}", 1],
118+
yno: ["y_{#1}", 1],
119+
Yno: ["Y_{(#1)}", 1],
120+
xdno: ["\\boldsymbol{x}_{#1}", 1],
121+
dX: "\\, \\mathrm{d}X",
122+
dx: "\\, \\mathrm{d}x",
123+
ds: "\\, \\mathrm{d}s",
124+
Real: "\\mathbb{R}",
125+
Integerp: "\\mathbb{N}",
126+
Integer: "\\mathbb{Z}"
127+
}
128+
}
129+
};
130+
</script>
42131
pdf:
43132
documentclass: scrbook
44133
classoption:
@@ -63,26 +152,20 @@ format:
63152
\SetWatermarkColor[gray]{0.9}
64153
65154
% Required packages
155+
\usepackage[T1]{fontenc} % Proper glyph support for accents and symbols
156+
\usepackage{textcomp} % Additional text symbols
66157
\usepackage{bm} % For bold math symbols
67158
68159
% Custom LaTeX macros from the book
69160
\newcommand{\half}{\frac{1}{2}}
70161
\newcommand{\halfi}{{1/2}}
71162
\newcommand{\tp}{\thinspace .}
72163
73-
\newcommand{\uex}{u_{\mbox{\footnotesize e}}}
74-
\newcommand{\uexd}[1]{u_{\mbox{\footnotesize e}, #1}}
75-
\newcommand{\vex}{v_{\mbox{\footnotesize e}}}
76-
\newcommand{\Vex}{V_{\mbox{\footnotesize e}}}
77-
\newcommand{\vexd}[1]{v_{\mbox{\footnotesize e}, #1}}
78-
\newcommand{\Aex}{A_{\mbox{\footnotesize e}}}
79-
\newcommand{\wex}{w_{\mbox{\footnotesize e}}}
80-
81164
% Operators
82165
\newcommand{\Ddt}[1]{\frac{D #1}{dt}}
83-
\newcommand{\E}[1]{\hbox{E}\lbrack #1 \rbrack}
84-
\newcommand{\Var}[1]{\hbox{Var}\lbrack #1 \rbrack}
85-
\newcommand{\Std}[1]{\hbox{Std}\lbrack #1 \rbrack}
166+
\newcommand{\E}[1]{\text{E}\lbrack #1 \rbrack}
167+
\newcommand{\Var}[1]{\text{Var}\lbrack #1 \rbrack}
168+
\newcommand{\Std}[1]{\text{Std}\lbrack #1 \rbrack}
86169
87170
\newcommand{\xpoint}{\bm{x}}
88171
\newcommand{\normalvec}{\bm{n}}
@@ -169,8 +252,11 @@ src_diffu: "https://github.com/devitocodes/devito_book/tree/devito/src/diffu"
169252
src_nonlin: "https://github.com/devitocodes/devito_book/tree/devito/src/nonlin"
170253
src_trunc: "https://github.com/devitocodes/devito_book/tree/devito/src/trunc"
171254
src_advec: "https://github.com/devitocodes/devito_book/tree/devito/src/advec"
255+
src_elliptic: "https://github.com/devitocodes/devito_book/tree/devito/src/elliptic"
256+
src_systems: "https://github.com/devitocodes/devito_book/tree/devito/src/systems"
172257
src_formulas: "https://github.com/devitocodes/devito_book/tree/devito/src/formulas"
173258
src_softeng2: "https://github.com/devitocodes/devito_book/tree/devito/src/softeng2"
259+
src_em: "https://github.com/devitocodes/devito_book/tree/devito/src/em"
174260

175261
crossref:
176262
eq-prefix: ""

0 commit comments

Comments
 (0)