Skip to content

reaction-diffusion2d

English | Japanese

« Home · « Advection-diffusion, reaction and radiation

Advection-diffusion-REACTION of a scalar concentration c -- exact-solution verification benchmark. A single D2Q5 advection-diffusion LBM for c, advected by a PRESCRIBED UNIFORM velocity u = (U, 0), plus a first-order-decay REACTION source Q = -k c. The scalar is passive (no momentum LBM), so this isolates the D2Q5 collision / streaming / reaction operator and checks its STEADY state against the textbook 1D advection-diffusion-reaction exponential. It is the reacting-transport twin of advection_diffusion2d.cpp (pure Gaussian pulse) and reuses the reaction-sink / Guo-consistent half-source trick of electroosmosis2d.cpp.

Geometry

reaction-diffusion2d geometry

Fields

The fields this computation wrote at its last output step, plotted as they are. 3D cases show the mid-plane.

reaction-diffusion2d C

Results

Exact-solution verification of scalar transport with reaction — the "reaction twin" of advection_diffusion2d. Nx = 256 (Ny = 4, effectively 1D with y periodic), Pe = 100, U = 0.05 (Ma = 0.087), D = U Nx/Pe = 0.05 × 256/100 = 0.128, τ = 3 × 0.128 + 1/2 = 0.8840, cell Péclet U/D = 0.391. Wall-clock time 2.77 s.

Damköhler sweep (Da = kL/U ∈ {0.5, 1, 2, 5, 10, 20, 50}, k = Da·U/Nx). At each Da, a "correct" source treatment (Guo-consistent half source + moment correction) and a "naive" treatment (no moment half source) are run side by side:

  • Correct treatment: the fitted decay rate λ_fit agrees with the exact value at all Da (e.g. at Da = 0.5, λ_fit = −1.943456e-03 = exact value, error −0.000%). L2 increases monotonically as the layer gets thinner, from 7.4511e-05 (Da = 0.5, decay length 514.5 cells) to 4.9667e-03 (Da = 50, decay length 7.0 cells) — a resolution issue, not a formulation issue.
  • Naive treatment: gets λ wrong by about half. At Da = 0.5, λ_fit = −9.06470e-04 (error −53.358%); at Da = 1.0, −53.464%. L2(naive) is 0.15–0.67. Omitting 1 half source has this large an effect as an O(k) bias; this instructive failure case is deliberately shown alongside.
  • The outlet concentration falls by 16 orders of magnitude, from cL/c0 = 6.080e-01 at Da = 0.5 to 1.270e-16 at Da = 50 (corresponding to the decay len next to the RESULT line).

Grid refinement (Da = 10 fixed, RESULT_RES line): L2 = 4.0828e-03 (Nx = 64) → 1.0254e-03 (128) → 2.5663e-04 (256) → 6.4176e-05 (512). On the finest pair, ln(2.5663e-4/6.4176e-5)/ln 2 = order 2.00 — exactly the log's "observed order (finest pair) = 2.00".

Governing equations

Steady 1D advection–diffusion–reaction (decay of order 1, Q = −kc):

\[
U\frac{dc}{dx}=D\frac{d^2c}{dx^2}-kc,\qquad
c(x)=c_0e^{\lambda x},\quad
\lambda=\frac{U-\sqrt{U^2+4Dk}}{2D}<0
\]

This is the unique solution of the BVP with inlet c(0) = c0 and the outlet fixed at the decaying-root value c0 e^{λL}. In the reaction-limited regime (Da ≪ 1), λ ≈ −k/U (gentle decay e^{−Da} over the whole domain); in the transport-limited regime (Da ≫ 1), λ ≈ −√(k/D) (a thin reaction–diffusion layer at the inlet) — the sweep spans both of these limits. On the LBM side, D2Q5 BGK with a Guo-consistent source discretization:

\[
S_i=w_i\Big(1-\frac{1}{2\tau}\Big)Q,\qquad
c=\sum_i g_i+\tfrac12 Q\;\Rightarrow\;c=\frac{\sum_i g_i}{1+k/2}
\]

Because Q depends on the unknown c, the moment side carries the other half of the source. Dropping it is the "naive" run, and it introduces an O(k) bias into the recovered decay constant (the −53% in the results section is the measured value of it). The scalar Dirichlet condition is anti-bounce-back on halfway x walls (same approach as electroosmosis2d; it is not registered in the controlled vocabulary, so it does not appear in the front matter).

Code walkthrough

Source (408 lines).

%%{init: {'themeVariables': {'fontSize': '11px'}}}%%
flowchart LR
    IN["x=0: c=c0<br/>anti-BB Dirichlet"] --> DOM["256×4 grid<br/>D2Q5 BGK + half source −kc<br/>y periodic"]
    DOM --> OUT["x=L: c=c0 e^{λL}<br/>anti-BB Dirichlet"]
  1. Mapping — determine D and τ from (Nx, Pe, U), and k = Da·U/Nx for each Da.
  2. Steady iteration — collide (with half source)/stream, down to a residual of ~1e-12 (e.g. Da = 0.5 reaches resid = 4.1e-12 in 12000 steps).
  3. Two variants — solve correct / naive under the same conditions and report L2 and λ_fit side by side.
  4. Refinement test — at Da = 10, Nx = 64→512 (U ∝ 1/Nx so Ma is reduced at the same time; Nx = 512 uses U = 0.0125, 42000 steps). Collected in the RESULT/RESULT_RES lines.

Build & run

cmake -S native -B native/build && cmake --build native/build -j
./native/build/orheo-reaction-diffusion2d

reaction_diffusion2d [Nx] [Pe] [U] [out_prefix]

Cost of the computation that made the figures on this page (Miyabi-G Grace CPU (72 cores, -stdpar=multicore)): 2.8 s wall.

Things to try

  • Pe from 100 → 10 / 1000: when the cell Péclet number 0.391 changes, which takes effect first, the bias of the naive treatment or the resolution limit?
  • Resolve the Da = 50 layer: a decay length of 7.0 cells is coarse. How far does L2 drop at Nx = 1024 (1/16 if it is order 2)?
  • Drop only one of the half sources: separate the contributions of the collision side and the moment side and check the breakdown of the −53% (a small exercise in modifying the source).
  • Read alongside advection_diffusion2d: on the same D2Q5 base, how the two kinds of verification, "exact Green's function" and "exact exponential solution", are built.

Validation

Tier T2 — single-point comparison
QoI dispersion_coefficient
Reference Taylor-Aris dispersion (Taylor 1953; Aris 1956)
Gate 🧩 module gate (advection_diffusion)
Measured 0.0002566304 (rel. err +0.03%) — harvest Nx=256; 6.42e-05 at Nx=512 (2nd-order convergence)

Source & run details

View source

Item Value
Target orheo-reaction-diffusion2d
Source native/benchmarks/reaction_diffusion2d.cpp
Lattice D2Q5
GPU twin no
Gallery run 2026-07-27 @ 7628c0cf
Args ``
Wall time 2.77 s
CPU time 197.15 s
Device Miyabi-G Grace CPU (72 cores, -stdpar=multicore)

Computation log

The actual output of this computation (head and tail).

reaction_diffusion2d  Nx=256 Ny=4 Pe=100.0 U=0.0500 (Ma=0.087) c0=1.0 | D=U*Nx/Pe=0.12800 tau=0.8840  cellPe=U/D=0.391

=== Da =   0.5  (k=9.766e-05, lambda=-1.94346e-03, decay len=514.5 cells, cL/c0=6.080e-01) ===
  steps=12000 resid=4.1e-12 | L2(correct)=7.4511e-05  L2(naive)=1.5396e-01 | lambda_fit: correct=-1.94346e-03 naive=-9.06470e-04  (exact=-1.94346e-03)
  lambda error: correct=-0.000%  naive=-53.358%
RESULT Da=0.5 k=9.765625e-05 lambda=-1.943456e-03 L2c=7.451105e-05 L2n=1.539624e-01 lamfitc=-1.943456e-03 lamfitn=-9.064699e-04 steps=12000

=== Da =   1.0  (k=1.953e-04, lambda=-3.86795e-03, decay len=258.5 cells, cL/c0=3.715e-01) ===
  steps=12000 resid=4.8e-12 | L2(correct)=1.4804e-04  L2(naive)=2.8963e-01 | lambda_fit: correct=-3.86795e-03 naive=-1.80000e-03  (exact=-3.86795e-03)
  lambda error: correct=-0.000%  naive=-53.464%
RESULT Da=1.0 k=1.953125e-04 lambda=-3.867950e-03 L2c=1.480367e-04 L2n=2.896288e-01 lamfitc=-3.867949e-03 lamfitn=-1.800002e-03 steps=12000

=== Da =   2.0  (k=3.906e-04, lambda=-7.66220e-03, decay len=130.5 cells, cL/c0=1.406e-01) ===
  steps=12000 resid=1.6e-12 | L2(correct)=2.9222e-04  L2(naive)=4.8631e-01 | lambda_fit: correct=-7.66220e-03 naive=-3.55300e-03  (exact=-7.66220e-03)
...

  Nx=  64 dx=1/64 U=0.10000(Ma=0.173) tau=0.6920 steps=2000 L2=4.0828e-03
RESULT_RES Nx=64 dx=1.562500e-02 L2=4.082836e-03
  Nx= 128 dx=1/128 U=0.05000(Ma=0.087) tau=0.6920 steps=5000 L2=1.0254e-03
RESULT_RES Nx=128 dx=7.812500e-03 L2=1.025354e-03
  Nx= 256 dx=1/256 U=0.02500(Ma=0.043) tau=0.6920 steps=13000 L2=2.5663e-04
RESULT_RES Nx=256 dx=3.906250e-03 L2=2.566304e-04
  Nx= 512 dx=1/512 U=0.01250(Ma=0.022) tau=0.6920 steps=42000 L2=6.4176e-05
RESULT_RES Nx=512 dx=1.953125e-03 L2=6.417588e-05
  observed order (finest pair) = 2.00

References

  • X. He, S. Chen & G. D. Doolen, J. Comput. Phys. 146 (1998) 282.
  • R. G. M. van der Sman & M. H. Ernst, J. Comput. Phys. 160 (2000) 766.
  • Z. Guo, C. Zheng & B. Shi, Phys. Rev. E 65 (2002) 046308 — source-term discretization.
  • G. Damköhler, Z. Elektrochem. 42 (1936) 846 — the Da number.
  • H. S. Fogler, Elements of Chemical Reaction Engineering — steady BVP solution.