# Poisson Equation with deal.II + Ginkgo Solves the Laplace equation $-\Delta u = 1$ on $[-1,1]^2$ with homogeneous Dirichlet boundary conditions using deal.II for mesh management and assembly, and Ginkgo for the linear solve. Based on [deal.II tutorial step-3](https://www.dealii.org/current/doxygen/deal.II/step_3.html). ## Integration Overview deal.II assembles the system matrix in its own `SparseMatrix` format. We extract the CSR structure by iterating over rows, then wrap the data into a `gko::matrix::Csr` using non-owning array views. deal.II vectors are similarly wrapped as `gko::matrix::Dense` with zero-copy. ## Step-by-Step ### 1. Create the Mesh ```{literalinclude} poisson.cpp :language: cpp :start-after: [create-mesh] :end-before: [/create-mesh] ``` ### 2. Set Up Finite Elements ```{literalinclude} poisson.cpp :language: cpp :start-after: [setup-fe] :end-before: [/setup-fe] ``` ### 3. Assemble the Linear System deal.II assembles the stiffness matrix and right-hand side using cell-wise quadrature, then applies boundary conditions. ```{literalinclude} poisson.cpp :language: cpp :start-after: [assemble-system] :end-before: [/assemble-system] ``` ### 4. Extract CSR Data for Ginkgo deal.II does not expose raw CSR pointers, so we iterate over the matrix rows to build standard CSR arrays. ```{literalinclude} poisson.cpp :language: cpp :start-after: [convert-to-ginkgo] :end-before: [/convert-to-ginkgo] ``` ### 5. Set Up the Ginkgo Executor ```{literalinclude} poisson.cpp :language: cpp :start-after: [setup-ginkgo] :end-before: [/setup-ginkgo] ``` ### 6. Wrap as Ginkgo Objects The CSR arrays and deal.II vectors are wrapped as Ginkgo objects using non-owning views — no data is copied. ```{literalinclude} poisson.cpp :language: cpp :start-after: [create-ginkgo-objects] :end-before: [/create-ginkgo-objects] ``` ### 7. Solve with Ginkgo ```{literalinclude} poisson.cpp :language: cpp :start-after: [solve] :end-before: [/solve] ``` ## Building ```bash cmake -S . -B build --preset default cmake --build build ./build/poisson ``` To specify library paths: ```bash cmake -S . -B build --preset default \ -DGinkgo_DIR=/path/to/ginkgo/lib/cmake/Ginkgo \ -DDEAL_II_DIR=/path/to/dealii ``` ## Expected Output ```text Number of active cells: 1024 Number of degrees of freedom: 1089 Solver converged. Output written to solution.vtk ```