# Stiff ODE System with SUNDIALS CVODE + Ginkgo Solves the Robertson chemical kinetics problem — a classic stiff ODE test — using SUNDIALS CVODE (BDF method) with Ginkgo providing the linear solver for the implicit Newton steps. $$\frac{du_1}{dt} = -0.04 u_1 + 10^4 u_2 u_3$$ $$\frac{du_2}{dt} = 0.04 u_1 - 10^4 u_2 u_3 - 3 \times 10^7 u_2^2$$ $$\frac{du_3}{dt} = 3 \times 10^7 u_2^2$$ Initial conditions: $u(0) = (1, 0, 0)$. Integrated to $t = 4 \times 10^7$. ## Integration Overview Same native SUNDIALS-Ginkgo interface as the [Poisson example](../poisson/doc): - `sundials::ginkgo::Matrix` wraps the Jacobian - `sundials::ginkgo::LinearSolver` wraps the Ginkgo GMRES solver CVODE calls Ginkgo's GMRES at every implicit time step to solve the Newton system $(I - \gamma J) \delta = -F$. ## Step-by-Step ### Right-Hand Side ```{literalinclude} ode_system.cpp :language: cpp :start-after: [rhs-function] :end-before: [/rhs-function] ``` ### Jacobian The 3x3 analytical Jacobian is stored as CSR (9 entries): ```{literalinclude} ode_system.cpp :language: cpp :start-after: [jacobian-function] :end-before: [/jacobian-function] ``` ### Ginkgo Setup ```{literalinclude} ode_system.cpp :language: cpp :start-after: [ginkgo-setup] :end-before: [/ginkgo-setup] ``` ### Time Integration ```{literalinclude} ode_system.cpp :language: cpp :start-after: [cvode-solve] :end-before: [/cvode-solve] ``` ## Building Requires SUNDIALS v6.4+ built with `-DENABLE_GINKGO=ON`. ```bash cmake -S . -B build --preset default cmake --build build ./build/ode_system ``` ## Expected Output ```text t u1 u2 u3 0.000000e+00 1.000000e+00 0.000000e+00 0.000000e+00 4.000000e-01 9.851721e-01 3.386395e-05 1.479402e-02 4.000000e+00 9.055187e-01 2.240476e-05 9.445890e-02 4.000000e+01 7.158271e-01 9.185536e-06 2.841637e-01 4.000000e+02 4.505186e-01 3.222901e-06 5.494781e-01 4.000000e+03 1.832022e-01 8.942367e-07 8.167969e-01 4.000000e+04 3.898339e-02 1.621769e-07 9.610164e-01 4.000000e+05 4.938276e-03 1.984995e-08 9.950617e-01 4.000000e+06 5.168100e-04 2.068296e-09 9.994832e-01 4.000000e+07 5.203083e-05 2.081340e-10 9.999480e-01 ```