# Steady-State Poisson with SUNDIALS KINSOL + Ginkgo Solves the nonlinear equation $-u''(x) - e^{u(x)} = 0$ on $[0,1]$ with $u(0) = u(1) = 0$ using SUNDIALS KINSOL (Newton iteration). Ginkgo provides the linear solver for each Newton step via SUNDIALS' native Ginkgo interface. ## Integration Overview SUNDIALS v6.4+ provides native Ginkgo wrappers: - `sundials::ginkgo::Matrix` wraps a Ginkgo CSR matrix as `SUNMatrix` - `sundials::ginkgo::LinearSolver` wraps a Ginkgo solver factory as `SUNLinearSolver` These plug directly into KINSOL's `KINSetLinearSolver()` — no custom glue code. ## Step-by-Step ### Problem Definition ```{literalinclude} poisson.cpp :language: cpp :start-after: [problem-setup] :end-before: [/problem-setup] ``` ### Nonlinear Residual ```{literalinclude} poisson.cpp :language: cpp :start-after: [residual-function] :end-before: [/residual-function] ``` ### Jacobian Assembly The Jacobian callback fills the Ginkgo CSR matrix that lives inside the `SUNMatrix` wrapper: ```{literalinclude} poisson.cpp :language: cpp :start-after: [jacobian-function] :end-before: [/jacobian-function] ``` ### Ginkgo Setup Create the Ginkgo executor, CSR matrix, and solver factory, then wrap them for SUNDIALS: ```{literalinclude} poisson.cpp :language: cpp :start-after: [ginkgo-setup] :end-before: [/ginkgo-setup] ``` ### KINSOL Solve ```{literalinclude} poisson.cpp :language: cpp :start-after: [kinsol-solve] :end-before: [/kinsol-solve] ``` ## Building Requires SUNDIALS v6.4+ built with `-DENABLE_GINKGO=ON`. ```bash cmake -S . -B build --preset default cmake --build build ./build/poisson ``` ## Expected Output ```text KINSOL converged with flag = 0 Solution at selected points: u(0.00990099) = 0.00539008 u(0.108911) = 0.0537863 u(0.207921) = 0.091845 u(0.306931) = 0.119166 u(0.405941) = 0.135454 u(0.50495) = 0.140527 u(0.60396) = 0.134328 u(0.70297) = 0.116927 u(0.80198) = 0.0885165 u(0.90099) = 0.0494044 ```