Gabriel Hagen Antunes · Scientific computing in C99
Transport, reactions & phase space
I developed PhaseFlow from three university C assignments. The C solvers compute the fields below; Python checks selected cases against independent references and records their balances.
Precomputed simulations Explore saved results from the native C solver. This static page does not run simulations on demand. All quantities are nondimensional. Findings and timings are reported from recorded native runs.
Compare zero force, constant acceleration and velocity diffusion for density injected at opposite spatial edges.
∂tf + v ∂xf + F ∂vf = C ∂²vf
Saved state · t = 0.4000 · fixed density scale 0–1
Finding
Adding F = 0.5 shifts mean velocity from ≈ 0 to 0.02850. At fixed force, increasing C from 0.02 to 0.18 fills the central gap: g(0) rises from 0.05488 to 0.08037. The total falls from 0.23310 to 0.19119 as density escapes through the velocity boundaries.
Scope: an open, truncated domain. These are distribution fields, not thermal relaxation or particle trajectories. The global velocity standard deviation narrows from 0.59492 to 0.54015. Force comparisons also change the CFL-selected timestep; diffusion comparisons share it.
01 / Transport · precomputed simulation
Numerical and physical spreading
Compare grid refinement at D = 0 with a run that adds physical diffusion.
∂tu + a ∂xu = D ∂²xu
Saved final state · t = 0.2 · fixed axes
Periodic pulse
A periodic Gaussian travels with a = 1 to t = 0.2. Width starts at 0.06; Δt = 0.0008 in all three runs. The dashed curve is the exact translation with D = 0.
Finding. Refining 32 to 192 nodes reduces measured variance growth / 2t from 0.0152245 to 0.00220417, even though D = 0. Adding physical D = 0.008 raises it to 0.0102042.
Upwinding itself spreads the pulse. A tiny mass-balance residual does not establish pulse-shape accuracy. This smooth, short-time case does not validate discontinuities.
02 / River · precomputed simulation
Conversion from P to Q
Keep the source fixed and compare two conversion rates for parent P and product Q.
0 = ∂x(D ∂xP) − a ∂xP − kP + S(x)
0 = ∂x(D ∂xQ) − a ∂xQ + kP
Direct steady solution · no time evolution
Source and boundaries
121 nodes, a = D = 0.5. A Gaussian source at x = 0.25 enters P. Upstream total flux is zero; downstream P = Q = 0. A direct steady solve has no initial condition.
Finding. Raising k from 0.2 to 1.2 lowers ∫P dx from 0.120811 to 0.0797759 and raises ∫Q dx from 0.0136300 to 0.0546656. The total profiles agree within 1.8 × 10−14.
Conversion cancels in P + Q. This is an open steady system with an imposed downstream concentration, not a calibrated environmental prediction or freely draining outlet.
Measured evidence
Validation and computational cost
Independent mathematical validation
The recorded full scientific gate passed 18 / 18 studies. Selected finest-grid weighted L2 errors and observed spatial orders:
Recorded v0.3 validation studies
Reference case
L2 error
Orders
Transport · periodic advection
4.29 × 10−3
0.954 / 0.977
River · steady reaction–diffusion
3.39 × 10−3
1.010 / 1.005
Kinetic · isolated velocity diffusion
2.03 × 10−5
1.997 / 1.995
These bounded reference studies are distinct from regression agreement and the showcase comparisons. River's upstream boundary limits its order; the combined Kinetic injection problem has no general convergence claim.
Reusing the fixed velocity-diffusion LU factors reduced the standard 161 × 161 workload from 267.509 ms to 217.009 ms (18.9%) median.
Apple M4, 24 GB; Apple Clang 21, -O2; OpenBLAS 0.3.31, one thread. One warm-up and five measured repetitions per mode; 178 steps, six saved frames.
Recorded 30 September clean-source benchmark, not your browser's runtime. Every-step output was slower: 384.703 → 397.334 ms (0.968×). CSV output dominates that workload. The first measured legacy/reuse outputs were byte-identical in all four cases. The earlier v0.5 large-case ratio was 1.473×; neither ratio applies to every workload.
One C99 executable; ordinary Transport, River and Kinetic entry points. Explicit stencil loops and banded LAPACKE solves.
02 / Reproducible evidence
Saved fields, exact inputs and diagnostics. Python builds reference comparisons, measurements and these compact figures.
03 / Two ways to explore
This static page selects precomputed assets. The full local Streamlit / Plotly explorer launches the C executable.
Continue the experiment
The local explorer
A Streamlit explorer runs the native solver on my own machine: choose parameters, compare compatible runs at common saved times, and reopen, filter or search earlier results.
The explorer exposes a bounded subset of CLI capabilities, with up to 80 saved frames, Kinetic grids up to 129 × 129 and a 30-second C-solve timeout. River is steady with zero advection in the explorer; Kinetic injection uses zero force. The forced Kinetic and advective River showcase cases are reproduced by the case-study script.
Transport, River and Kinetic grew from my university assignments 3, 4 and 5, including the band-matrix helpers that River and Kinetic share. River and Kinetic use LAPACKE with LAPACK/BLAS routines. The original input files were not kept: these are constructed PhaseFlow experiments, not recovered university data.