Chapter 38 — Key Takeaways (Capstone: From Physics to Publication)

A one-page reference for turning a working solver into a defended result. Keep it beside you the first time you write up a simulation — the code is half the deliverable; the argument that it is right is the other half.

The capstone in one line

A finished computational result is code + the argument that it is right: assemble it, verify it, measure it honestly, and present it so someone else can reproduce it.

Assembling the pieces (§38.1)

Piece Module / file Chapter
precision kinds (dp) 3
data structure heat_types (field_t) 9
physics + solver heat_solver (laplacian, step, stable_dt) 24
I/O + visualization heat_io (write_field, write_vtk) 7, 26
timing timers (tic, toc) 28
driver program heat (app/main.f90)
tests test/test_solver.f90 (regress vs analytical) 37
  • A frozen interface is what let the program grow. step(field, alpha, dt) never changed its signature; its body was serial, then cache-tuned, then OpenMP, then MPI — and the driver never noticed.
  • The step interface hides a serial body, an OpenMP body (Ch. 33), and an MPI body (Ch. 34); all give the identical field.

Problem and method, paper-style (§38.2)

Ingredient Statement
Equation $\partial u/\partial t = \alpha\nabla^2 u$, Dirichlet edges
Space five-point stencil, $O(h^2)$: $(u_{i\pm1,j}+u_{i,j\pm1}-4u_{i,j})/h^2$
Time explicit FTCS: $u^{n+1}=u^n+r(\text{stencil})$, $r=\alpha\Delta t/h^2$
Stability $r \le 1/4$ (2D); derive $\Delta t$ from $h$, never guess it

Verification vs validation (§38.3) — the reserved new terms

Term Question How This chapter
Verification "solving the equations right?" compare to an exact solution of the same PDE yes
Validation "solving the right equations?" compare to physical experiment no (needs data we lack)

The analytical solution and the convergence study (§38.3)

  • Exact solution (unit square, zero edges): $u = \sin(\pi x)\sin(\pi y)\,e^{-2\alpha\pi^2 t}$.
  • The discrete mode is an exact stencil eigenvector, so $u^K = G^K u^0$ with $G = 1 - 8r\sin^2(\pi h/2)$ — the whole-field error collapses to $|G^K - e^{-2\alpha\pi^2 T}|$.
  • Convergence study (the most diagnostic table you can report): error $\sim h^2$.
$h$ max error at $T=0.05$ ratio
$1/4$ $2.90\times10^{-2}$
$1/8$ $6.76\times10^{-3}$ $4.3$
$1/16$ $1.66\times10^{-3}$ $4.1$
  • Halve $h$ → error ÷ 4 → observed order = $\log_2(\text{ratio}) \to 2$. The wrong order is a bug signature, not "close enough."
  • Fixed $r$ ⟹ $\Delta t \sim h^2$ ⟹ step count $\times 4$ per refinement (the explicit-diffusion tax).

Performance, honestly (§38.4)

Concept Formula / fact For our solver
Amdahl $S(p) = 1/[(1-f)+f/p]$ $f=0.98 \Rightarrow$ ceiling $50\times$; $S(8)\approx7$, $S(16)\approx12$
Arithmetic intensity flops per byte moved $\sim10$ flops/cell, tens of bytes ⟹ $\ll 1$ flop/byte
Roofline low intensity ⟹ bandwidth-bound memory-bound: real scaling plateaus below Amdahl
Strong scaling fixed problem, more cores OpenMP; Amdahl- then bandwidth-limited
Weak scaling problem grows with cores MPI; constant work per rank — the case for a cluster
  • All timing/speedup numbers are illustrative — measure your own. Amdahl and flop counts are exact; wall times are not, and this book never runs code.

Presenting it (§38.6)

Paper order: problem → method → V&V → implementation/performance → results → conclusion → reproducibility. (V&V before results: trust the code before the numbers.)

What reviewers check (four of five are about trust, not cleverness): 1. Correct? (V&V — non-negotiable) 2. Reproducible? 3. Claims backed by evidence? 4. Honest about limits? 5. Significant?

  • A speedup with no stated baseline and build configuration is meaningless.
  • Name your method's limit (here: explicit $\Delta t \sim h^2$; want implicit/dgesv for stiff fine grids) — it strengthens the paper.

Compile flags seen here

$ gfortran -std=f2018 -Wall -O3 -march=native project-checkpoint.f90 -o heat   # release
$ gfortran -std=f2018 -Wall -O2 -fopenmp project-checkpoint.f90 -o heat         # + threads
$ mpif90   -std=f2018 -O3 heat_mpi.f90 -o heat_mpi                              # + MPI

Project piece added this chapter

The complete solver, presented as a paper: the six modules behind the frozen step, the analytical verification wired into test/, the convergence study (order 2), the figures, and the reproducibility package. Physics that is correct, code that is organized, results that are presented — the whole book, assembled.

The two things to remember

  1. A convergence study against a known solution is how you prove a solver is correct — the observed order of accuracy is the most diagnostic number you can report; no heat map substitutes for it.
  2. The result is not the code; it is the code plus the argument that it is right — verified, reproducible, honestly scoped — and building that argument, visibly, is the work.