# Adaptive Refinement with deal.II + Ginkgo Solves the Poisson equation $-\Delta u = 1$ on a disk with adaptive mesh refinement (AMR). After each refinement cycle, the mesh changes, the system is re-assembled, and a **new Ginkgo solver is generated** from the updated matrix. Based on [deal.II tutorial step-6](https://www.dealii.org/current/doxygen/deal.II/step_6.html). ## Integration Overview The key difference from the basic Poisson example is that AMR changes the matrix dimensions and sparsity pattern every cycle. The Ginkgo solver (and its preconditioner) must be re-created from scratch after each refinement. This example shows the pattern for solver re-generation. ## Step-by-Step ### CSR Extraction Helper A reusable function that extracts CSR arrays from a deal.II `SparseMatrix`: ```{literalinclude} adaptive_refinement.cpp :language: cpp :start-after: [helper-extract-csr] :end-before: [/helper-extract-csr] ``` ### Solve Function with Ginkgo Each cycle calls this function, which creates a fresh Ginkgo solver. After solving, `constraints.distribute()` enforces hanging node constraints. ```{literalinclude} adaptive_refinement.cpp :language: cpp :start-after: [solve-with-ginkgo] :end-before: [/solve-with-ginkgo] ``` ### The Refinement Loop The main loop: generate/refine mesh, set up DOFs, assemble, solve, repeat. ```{literalinclude} adaptive_refinement.cpp :language: cpp :start-after: [refinement-loop] :end-before: [/refinement-loop] ``` ## Building ```bash cmake -S . -B build --preset default cmake --build build ./build/adaptive_refinement ``` ## Expected Output ```text Cycle 0: Cells: 20 DOFs: 89 Solved. Cycle 1: Cells: 44 DOFs: 209 Solved. ... Cycle 7: Cells: 2513 DOFs: 12725 Solved. ``` Each cycle produces a `solution-N.vtk` file for visualization.