# Poisson Equation with MFEM + Ginkgo Solves the Laplace equation $-\Delta u = 1$ with homogeneous Dirichlet boundary conditions using MFEM for finite element assembly and Ginkgo for the linear solve. Based on [MFEM Example 1](https://mfem.org/examples/). ## Integration Overview MFEM's `SparseMatrix` stores CSR data directly. After calling `Finalize()`, the raw arrays are accessible via `GetI()`, `GetJ()`, and `GetData()`. These are wrapped into a `gko::matrix::Csr` using `gko::array::view` for zero-copy interoperability. ## Step-by-Step ### 1. Set Up Mesh and Finite Element Space ```{literalinclude} poisson.cpp :language: cpp :start-after: [setup-mesh] :end-before: [/setup-mesh] ``` ```{literalinclude} poisson.cpp :language: cpp :start-after: [setup-fespace] :end-before: [/setup-fespace] ``` ### 2. Assemble the Linear System ```{literalinclude} poisson.cpp :language: cpp :start-after: [assemble] :end-before: [/assemble] ``` ### 3. Convert to Ginkgo Objects MFEM exposes CSR pointers directly — `GetI()` returns row pointers, `GetJ()` returns column indices, `GetData()` returns values. ```{literalinclude} poisson.cpp :language: cpp :start-after: [convert-to-ginkgo] :end-before: [/convert-to-ginkgo] ``` ### 4. Solve with Ginkgo ```{literalinclude} poisson.cpp :language: cpp :start-after: [solve] :end-before: [/solve] ``` ### 5. Recover Solution ```{literalinclude} poisson.cpp :language: cpp :start-after: [recover-and-output] :end-before: [/recover-and-output] ``` ## Building ```bash cmake -S . -B build --preset default cmake --build build ./build/poisson ``` A mesh file can be passed with `-m`: ```bash ./build/poisson -m /path/to/mfem/data/star.mesh -o 2 ``` ## Expected Output ```text Options used: --mesh --order 1 --refine 2 Number of elements: 4096 Number of unknowns: 4225 System size: 4225 x 4225, nnz: 37249 Ginkgo solver converged. Output written to solution.gf and mesh.mesh ```