Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ doc/pub/
/_book/
**/*.quarto_ipynb

# Root-level TeX artifacts (Quarto/Pandoc intermediates)
/*.tex

# Quarto HTML render artifacts
**/*_files/

# Review and planning documents
book-review.md
codex-review.md
codex-reviewer.md
review.md
review-2.md
review-3.md
review-4.md
ianmgdev_review.txt
*.docx
Proposed Extension Roadmap*.md

# Coverage
.coverage
coverage.xml
Expand Down
4 changes: 4 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ ue = "ue"
# Strang splitting (named after mathematician Gilbert Strang)
strang = "strang"
Strang = "Strang"
# Variable name for "p at iteration n" in Jacobi iteration
pn = "pn"
# Journal abbreviation: "J. Comput. Phys."
Comput = "Comput"
70 changes: 70 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Makefile for Finite Difference Computing with PDEs book

.PHONY: pdf html all preview clean test test-devito test-no-devito lint format check help

# Default target
all: pdf html

# Build targets
pdf:
quarto render --to pdf

html:
quarto render --to html

# Build both PDF and HTML
book:
quarto render

# Live preview with hot reload
preview:
quarto preview

# Clean build artifacts
clean:
rm -rf _book/
rm -rf .quarto/
find . -name "*.aux" -delete
find . -name "*.log" -delete
find . -name "*.out" -delete

# Test targets
test:
pytest tests/ -v

test-devito:
pytest tests/ -v -m devito

test-no-devito:
pytest tests/ -v -m "not devito"

test-phase1:
pytest tests/test_elliptic_devito.py tests/test_burgers_devito.py tests/test_swe_devito.py -v

# Linting and formatting
lint:
ruff check src/

format:
ruff check --fix src/
isort src/

check:
pre-commit run --all-files

# Help
help:
@echo "Available targets:"
@echo " pdf - Build PDF (default)"
@echo " html - Build HTML"
@echo " book - Build all formats (PDF + HTML)"
@echo " preview - Live preview with hot reload"
@echo " clean - Remove build artifacts"
@echo " test - Run all tests"
@echo " test-devito - Run only Devito tests"
@echo " test-no-devito - Run tests without Devito"
@echo " test-phase1 - Run Phase 1 tests (elliptic, burgers, swe)"
@echo " lint - Check code with ruff"
@echo " format - Auto-format code with ruff and isort"
@echo " check - Run all pre-commit hooks"
@echo " help - Show this help message"
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,30 @@ Based on *Finite Difference Computing with Partial Differential Equations* by Ha
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:

```python
from devito import Grid, TimeFunction, Eq, Operator
import numpy as np
from devito import Constant, Eq, Grid, Operator, TimeFunction, solve

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

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

# Write the wave equation symbolically
eq = Eq(u.dt2, c**2 * u.dx2)
# Wave speed parameter (passed at runtime)
c = Constant(name="c")

# Set an initial condition (Gaussian pulse)
x = np.linspace(0.0, 1.0, 101)
u.data[0, :] = np.exp(-((x - 0.5) ** 2) / (2 * 0.1**2))
u.data[1, :] = u.data[0, :] # zero initial velocity (demo)

# Write the wave equation symbolically and derive an explicit update stencil
pde = Eq(u.dt2, c**2 * u.dx2)
update = Eq(u.forward, solve(pde, u.forward))

# Devito generates optimized C code automatically
op = Operator([eq])
op.apply(time_M=100, dt=0.001)
op = Operator([update])
op.apply(time_M=100, dt=0.001, c=1.0)
```

## Quick Start
Expand Down
112 changes: 99 additions & 13 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,28 @@ book:
title: "Finite Difference Computing with PDEs"
subtitle: "A Devito Approach"
author:
- name: Hans Petter Langtangen
- name: Svein Linge
- name: Gerard J. Gorman
affiliation: Imperial College London
date: today
chapters:
- index.qmd
- chapters/preface/index.qmd
# Note: chapters/vib/ exists on disk but is excluded from the build.
# The vibration ODE content from the original Langtangen & Linge text
# has not yet been ported to the Devito approach. Readers interested
# in vibration ODEs can refer to Langtangen_deqbook_vib in the bibliography.
- part: "Main Chapters"
chapters:
- chapters/devito_intro/index.qmd
- chapters/wave/index.qmd
- chapters/diffu/index.qmd
- chapters/advec/index.qmd
- chapters/nonlin/index.qmd
- chapters/elliptic/index.qmd
- chapters/systems/index.qmd
- part: "Applications"
chapters:
- chapters/applications/electromagnetics/index.qmd
- part: "Appendices"
chapters:
- chapters/appendices/formulas/index.qmd
Expand All @@ -39,6 +48,86 @@ format:
number-depth: 3
crossref:
chapters: true
include-in-header:
text: |
<script>
MathJax = {
tex: {
macros: {
half: "\\frac{1}{2}",
halfi: "{1/2}",
tp: "\\thinspace .",
Ddt: ["\\frac{D #1}{dt}", 1],
E: ["\\text{E}\\lbrack #1 \\rbrack", 1],
Var: ["\\text{Var}\\lbrack #1 \\rbrack", 1],
Std: ["\\text{Std}\\lbrack #1 \\rbrack", 1],
xpoint: "\\boldsymbol{x}",
normalvec: "\\boldsymbol{n}",
Oof: ["\\mathcal{O}(#1)", 1],
x: "\\boldsymbol{x}",
X: "\\boldsymbol{X}",
uu: "\\boldsymbol{u}",
vv: "\\boldsymbol{v}",
w: "\\boldsymbol{w}",
acc: "\\boldsymbol{a}",
rpos: "\\boldsymbol{r}",
V: "\\boldsymbol{V}",
e: "\\boldsymbol{e}",
f: "\\boldsymbol{f}",
F: "\\boldsymbol{F}",
stress: "\\boldsymbol{\\sigma}",
strain: "\\boldsymbol{\\varepsilon}",
stressc: "{\\sigma}",
strainc: "{\\varepsilon}",
I: "\\boldsymbol{I}",
T: "\\boldsymbol{T}",
U: "\\boldsymbol{U}",
q: "\\boldsymbol{q}",
g: "\\boldsymbol{g}",
dfc: "\\alpha",
ii: "\\boldsymbol{i}",
jj: "\\boldsymbol{j}",
kk: "\\boldsymbol{k}",
ir: "\\boldsymbol{i}_r",
ith: "\\boldsymbol{i}_{\\theta}",
iz: "\\boldsymbol{i}_z",
Ix: "\\mathcal{I}_x",
It: "\\mathcal{I}_y",
Iz: "\\mathcal{I}_z",
It: "\\mathcal{I}_t",
If: "\\mathcal{I}_s",
Ifd: "{I_d}",
Ifb: "{I_b}",
setb: ["#1^0", 1],
sete: ["#1^{-1}", 1],
setl: ["#1^-", 1],
setr: ["#1^+", 1],
seti: ["#1^i", 1],
sequencei: ["\\left\\{ {#1}_i \\right\\}_{i\\in\\If}", 1],
sequencej: ["\\left\\{ {#1}_j \\right\\}_{j\\in\\If}", 1],
stepzero: "*",
stephalf: "***",
stepone: "**",
basphi: "\\varphi",
baspsi: "\\psi",
refphi: "\\tilde\\basphi",
psib: "\\boldsymbol{\\psi}",
sinL: ["\\sin\\left((#1+1)\\pi\\frac{x}{L}\\right)", 1],
xno: ["x_{#1}", 1],
Xno: ["X_{(#1)}", 1],
yno: ["y_{#1}", 1],
Yno: ["Y_{(#1)}", 1],
xdno: ["\\boldsymbol{x}_{#1}", 1],
dX: "\\, \\mathrm{d}X",
dx: "\\, \\mathrm{d}x",
ds: "\\, \\mathrm{d}s",
Real: "\\mathbb{R}",
Integerp: "\\mathbb{N}",
Integer: "\\mathbb{Z}"
}
}
};
</script>
pdf:
documentclass: scrbook
classoption:
Expand All @@ -63,26 +152,20 @@ format:
\SetWatermarkColor[gray]{0.9}

% Required packages
\usepackage[T1]{fontenc} % Proper glyph support for accents and symbols
\usepackage{textcomp} % Additional text symbols
\usepackage{bm} % For bold math symbols

% Custom LaTeX macros from the book
\newcommand{\half}{\frac{1}{2}}
\newcommand{\halfi}{{1/2}}
\newcommand{\tp}{\thinspace .}

\newcommand{\uex}{u_{\mbox{\footnotesize e}}}
\newcommand{\uexd}[1]{u_{\mbox{\footnotesize e}, #1}}
\newcommand{\vex}{v_{\mbox{\footnotesize e}}}
\newcommand{\Vex}{V_{\mbox{\footnotesize e}}}
\newcommand{\vexd}[1]{v_{\mbox{\footnotesize e}, #1}}
\newcommand{\Aex}{A_{\mbox{\footnotesize e}}}
\newcommand{\wex}{w_{\mbox{\footnotesize e}}}

% Operators
\newcommand{\Ddt}[1]{\frac{D #1}{dt}}
\newcommand{\E}[1]{\hbox{E}\lbrack #1 \rbrack}
\newcommand{\Var}[1]{\hbox{Var}\lbrack #1 \rbrack}
\newcommand{\Std}[1]{\hbox{Std}\lbrack #1 \rbrack}
\newcommand{\E}[1]{\text{E}\lbrack #1 \rbrack}
\newcommand{\Var}[1]{\text{Var}\lbrack #1 \rbrack}
\newcommand{\Std}[1]{\text{Std}\lbrack #1 \rbrack}

\newcommand{\xpoint}{\bm{x}}
\newcommand{\normalvec}{\bm{n}}
Expand Down Expand Up @@ -169,8 +252,11 @@ src_diffu: "https://github.com/devitocodes/devito_book/tree/devito/src/diffu"
src_nonlin: "https://github.com/devitocodes/devito_book/tree/devito/src/nonlin"
src_trunc: "https://github.com/devitocodes/devito_book/tree/devito/src/trunc"
src_advec: "https://github.com/devitocodes/devito_book/tree/devito/src/advec"
src_elliptic: "https://github.com/devitocodes/devito_book/tree/devito/src/elliptic"
src_systems: "https://github.com/devitocodes/devito_book/tree/devito/src/systems"
src_formulas: "https://github.com/devitocodes/devito_book/tree/devito/src/formulas"
src_softeng2: "https://github.com/devitocodes/devito_book/tree/devito/src/softeng2"
src_em: "https://github.com/devitocodes/devito_book/tree/devito/src/em"

crossref:
eq-prefix: ""
Expand Down
Loading
Loading