Skip to content

Commit b9dc387

Browse files
committed
Add Phase 4 content: Inverse Problems (RTM, FWI, LSRTM)
Chapter 9: Inverse Problems and Adjoint-State Methods - Introduction to inverse problems in seismic imaging - Adjoint-state method for gradient computation - Forward modeling with explicit SparseTimeFunction API - Reverse Time Migration (RTM) imaging condition - Full Waveform Inversion (FWI) with gradient descent - Regularization techniques (Tikhonov, Total Variation) - Least-Squares RTM with Barzilai-Borwein step length All implementations use explicit Devito API without convenience classes. New files: - chapters/adjoint/adjoint.qmd (main chapter content) - src/adjoint/forward_devito.py (explicit forward modeling) - src/adjoint/rtm_devito.py (RTM implementation) - src/adjoint/fwi_devito.py (FWI gradient computation) - src/adjoint/lsrtm_devito.py (LSRTM with Born modeling) - src/adjoint/gradient.py (gradient utilities) - tests/test_adjoint_forward.py (18 tests) - tests/test_rtm_devito.py (12 tests) - tests/test_fwi_devito.py (32 tests) - tests/test_lsrtm_devito.py (28 tests) Total tests: 501 (90 new tests for Phase 4) PDF builds successfully.
1 parent 04accab commit b9dc387

14 files changed

Lines changed: 5937 additions & 21 deletions

_quarto.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ book:
2222
- chapters/elliptic/index.qmd
2323
- chapters/systems/index.qmd
2424
- chapters/highorder/index.qmd
25+
- chapters/adjoint/index.qmd
2526
- part: "Appendices"
2627
chapters:
2728
- chapters/appendices/formulas/index.qmd
@@ -175,6 +176,7 @@ src_advec: "https://github.com/devitocodes/devito_book/tree/devito/src/advec"
175176
src_elliptic: "https://github.com/devitocodes/devito_book/tree/devito/src/elliptic"
176177
src_systems: "https://github.com/devitocodes/devito_book/tree/devito/src/systems"
177178
src_highorder: "https://github.com/devitocodes/devito_book/tree/devito/src/highorder"
179+
src_adjoint: "https://github.com/devitocodes/devito_book/tree/devito/src/adjoint"
178180
src_formulas: "https://github.com/devitocodes/devito_book/tree/devito/src/formulas"
179181
src_softeng2: "https://github.com/devitocodes/devito_book/tree/devito/src/softeng2"
180182

book-roadmap.md

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ Extend *Finite Difference Computing with PDEs* with content from `devito_repo/ex
1919
|-------|--------|-------|--------|
2020
| **Phase 1** | ✅ Complete | 62 | `ab9b38c0` |
2121
| **Phase 2** | ✅ Complete | 73 | `b9e017b3` |
22-
| **Phase 3** | ✅ Complete | 91 | - |
23-
| **Phase 4** | 🔲 Not started | - | - |
22+
| **Phase 3** | ✅ Complete | 91 | `04accab7` |
23+
| **Phase 4** | ✅ Complete | 90 | pending |
2424
| **Phase 5** | 🔲 Not started | - | - |
2525
| **Phase 6** | 🔲 Not started | - | - |
2626
| **Phase 7** | 🔲 Not started | - | - |
2727

28-
**Total tests: 411**
28+
**Total tests: 501**
2929

3030
---
3131

@@ -225,13 +225,13 @@ eq_p = Eq(p.forward, p + dt*pdt + (dt**2/2)*pdt2 + (dt**3/6)*pdt3 + (dt**4/24)*p
225225

226226
---
227227

228-
## Phase 4: Inverse Problems (Priority Content)
228+
## Phase 4: Inverse Problems (Priority Content) ✅ COMPLETE
229229

230230
**Effort**: High | **Value**: Very High | **Source**: Ready notebooks
231231

232232
This is the stated priority - complete treatment of adjoint methods, RTM, and FWI.
233233

234-
### 4.1 Chapter 9: Inverse Problems and Optimization
234+
### 4.1 Chapter 9: Inverse Problems and Optimization
235235

236236
**Source**: `02_rtm.ipynb`, `03_fwi.ipynb`, `13_LSRTM_acoustic.ipynb`, `seismic/inversion/fwi.py`
237237

@@ -242,36 +242,46 @@ This is the stated priority - complete treatment of adjoint methods, RTM, and FW
242242
- 9.4 Reverse Time Migration (RTM)
243243
- 9.5 Adjoint Wavefield Computation
244244
- 9.6 Gradient Computation
245-
- 9.7 FWI Optimization Loop (scipy L-BFGS)
245+
- 9.7 FWI Optimization Loop (gradient descent)
246246
- 9.8 Regularization (Tikhonov, TV)
247-
- 9.9 Least-Squares RTM (LSRTM)
247+
- 9.9 Least-Squares RTM (LSRTM with Barzilai-Borwein step)
248248

249-
**Critical**: Must rewrite all examples without `SeismicModel`, `AcousticWaveSolver`, etc.
249+
**Critical**: All examples use explicit Devito API - no `SeismicModel`, `AcousticWaveSolver`, etc.
250250

251-
**Key code pattern** (explicit API):
251+
**Key code patterns** (explicit API):
252252
```python
253253
# Manual Ricker wavelet
254254
def ricker_wavelet(t, f0):
255255
t0 = 1.5 / f0
256256
return (1 - 2*(np.pi*f0*(t-t0))**2) * np.exp(-(np.pi*f0*(t-t0))**2)
257257

258-
# Explicit SparseTimeFunction
258+
# Explicit SparseTimeFunction for sources and receivers
259259
src = SparseTimeFunction(name='src', grid=grid, npoint=1, nt=nt)
260260
src.coordinates.data[:] = [[500., 20.]]
261261
src.data[:, 0] = ricker_wavelet(time_values, f0=10.)
262+
263+
rec = SparseTimeFunction(name='rec', grid=grid, npoint=nrec, nt=nt)
264+
rec.coordinates.data[:] = rec_coords
265+
266+
# Forward modeling
267+
pde = (1.0 / vel**2) * u.dt2 - u.laplace
268+
stencil = Eq(u.forward, solve(pde, u.forward))
269+
src_term = src.inject(field=u.forward, expr=src * dt**2 * vel**2)
270+
rec_term = rec.interpolate(expr=u)
271+
op = Operator([stencil] + src_term + rec_term)
262272
```
263273

264274
**Deliverables**:
265-
- [ ] `chapters/adjoint/adjoint.qmd`
266-
- [ ] `src/adjoint/forward_devito.py`
267-
- [ ] `src/adjoint/rtm_devito.py`
268-
- [ ] `src/adjoint/fwi_devito.py`
269-
- [ ] `src/adjoint/lsrtm_devito.py`
270-
- [ ] `src/adjoint/gradient.py`
271-
- [ ] `tests/test_adjoint_devito.py`
272-
- [ ] `tests/test_rtm_devito.py`
273-
- [ ] `tests/test_fwi_devito.py`
274-
- [ ] `tests/test_lsrtm_devito.py`
275+
- [x] `chapters/adjoint/adjoint.qmd`
276+
- [x] `src/adjoint/forward_devito.py`
277+
- [x] `src/adjoint/rtm_devito.py`
278+
- [x] `src/adjoint/fwi_devito.py`
279+
- [x] `src/adjoint/lsrtm_devito.py`
280+
- [x] `src/adjoint/gradient.py`
281+
- [x] `tests/test_adjoint_forward.py` (18 tests)
282+
- [x] `tests/test_rtm_devito.py` (12 tests)
283+
- [x] `tests/test_fwi_devito.py` (32 tests)
284+
- [x] `tests/test_lsrtm_devito.py` (28 tests)
275285

276286
---
277287

@@ -433,7 +443,7 @@ Each solver must include:
433443
- Added references for Fornberg, Tam-Webb
434444
- Commit: `b9e017b3`
435445

436-
### 2026-01-29: Phase 3 Complete
446+
### 2026-01-30: Phase 3 Complete
437447
- Added Sections 8.4-8.5: ADER and Staggered Grids to Chapter 8
438448
- Added Sections 7.4-7.5: Viscoacoustic and Viscoelastic Waves to Chapter 7
439449
- Created ADER solver (`ader_devito.py`) with Taylor expansion in time
@@ -442,3 +452,4 @@ Each solver must include:
442452
- Created 3D Viscoelastic solver with `TensorTimeFunction` for stress/memory tensors
443453
- 91 new tests (411 total)
444454
- Fixed damping field creation for small grids
455+
- Commit: `04accab7`

0 commit comments

Comments
 (0)