Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Counter diffusion and reaction in a slab

Reaction: A+B→∗A+B\rightarrow *

div(−D grad(cA))=−k cAcB\mathrm{div}(-D \, \mathrm{grad} (c_A) ) = -k \, c_A c_B, div(−D grad(cB))=−k cAcB\mathrm{div}(-D \, \mathrm{grad} (c_B)) = -k \, c_A c_B,

with boundary conditions: cA(0)=1c_A(0)=1, ∂cA(L)∂n=0\frac{\partial c_A(L)}{\partial n} = 0, ∂cB(0)∂n=0\frac{\partial c_B(0)}{\partial n} = 0, cB(L)=1c_B(L)=1

Imports

Parameters and boundary conditions

Physical and numerical parameters, and the boundary dictionaries in the a*dc/dn + b*c = d convention (outward normal): a fixed concentration cA=1c_A=1 at x=0x=0 (with cB=0c_B=0 there) and the mirror image at x=Lx=L.

Reaction term

A+B→∗A + B \rightarrow * with rate k cAcBk \, c_A c_B, consuming AA and BB in equal amounts.

Grid and operators

Uniform grid, the constant diffusion operator, and a NumJac object for the nonlinear reaction Jacobian.

Solve (Newton iteration)

A fixed number of Newton iterations on the steady residual jac_disp @ c + jac_disp_bc + f_react = 0, with the reaction Jacobian rebuilt from NumJac at the current state each iteration.

Plot the concentration profiles

<Figure size 640x480 with 1 Axes>

Checking the result

The notebook stops after exactly 10 Newton iterations without checking convergence. pymrm.checks.residual_check judges the final state by a scale-free backward error on the same residual used above; this would catch a case where 10 iterations are not enough, for example with a much larger kk or with a Jacobian that does not match the residual and slows convergence down.

backward error 1.914e-16, ok=True
A tiny backward error confirms the 10 fixed iterations did converge for this k.