> ## Documentation Index
> Fetch the complete documentation index at: https://bindi-nagda-amr-multiphase.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Adaptive Mesh Refinement

> How the solver uses gradient-based AMR to concentrate resolution near sharp interfaces while coarsening the grid elsewhere.

Adaptive Mesh Refinement (AMR) allows the solver to concentrate computational effort in regions where the solution changes rapidly — such as near a sharp fluid interface — while using a coarser, cheaper grid everywhere else. This produces second-order-accurate solutions at a fraction of the cost of a uniformly refined grid.

## Why AMR matters

A two-phase fluid simulation often has a small region of interest — for example, a thin transition zone where the network volume fraction $\theta_n$ varies sharply. Resolving this zone on a uniform grid requires refining the entire domain, which multiplies the cell count (and therefore compute time and memory) cubically in 3D.

AMR instead maintains a **hierarchy of nested grid levels**. Each level is a refinement of the level below it. Only the cells that need high resolution are subdivided; cells in smooth regions remain at the coarser resolution.

> [!NOTE]
>
> The AMR implementation is built on IBAMR/SAMRAI. The patch hierarchy and gridding algorithm are configured through the `GriddingAlgorithm` block in the input file.

## Gradient-based cell tagging

The solver tags cells for refinement by computing the absolute gradient of the network volume fraction $\theta_n$. Any cell where

$$
|\nabla\theta_n| > \texttt{grad\_abs\_thresh}
$$

is marked for refinement. Marked cells are surrounded by a buffer of additional tagged cells (controlled by `tag_buffer`) to prevent the refined region from being too tightly cropped around the detected feature.

The tagging method is set in the `StandardTagAndInitialize` block:

```text input2d theme={null}
StandardTagAndInitialize {
   tagging_method = "GRADIENT_DETECTOR"
}
```

And the threshold and buffer are configured in the integrator block:

```text input2d theme={null}
INSVCTwoFluidStaggeredHierarchyIntegrator {
   use_grad_tagging  = TRUE
   grad_abs_thresh   = 0.75
   tag_buffer        = 1
   regrid_interval   = 10
   ...
}
```

> [!TIP]
>
> Lower values of `grad_abs_thresh` tag more cells (finer coverage of gradients); higher values restrict refinement to only the steepest transitions. Tune this together with `tag_buffer` to balance accuracy against cost.

## The patch hierarchy

The grid is organized as a **patch hierarchy** — a stack of refinement levels numbered from 0 (coarsest) upward. Each level consists of a set of rectangular **patches** that tile the refined region without overlap.

Key concepts:

* **Level 0** is the base Cartesian grid, spanning the entire domain.
* **Finer levels** cover only the tagged subregions and are nested inside their parent level.
* **Refinement ratio** specifies how many fine cells replace one coarse cell in each spatial direction.
* **Regridding** — the hierarchy is rebuilt periodically to track moving features.

## GriddingAlgorithm configuration

The `GriddingAlgorithm` block in the input file controls hierarchy construction. The following example is taken from `frm/input2d`:

```text input2d theme={null}
GriddingAlgorithm {
   max_levels = 3                 // Maximum number of levels in hierarchy.

   ratio_to_coarser {
      level_1 = 2, 2              // vector ratio to next coarser level
      level_2 = 2, 2
      level_3 = 2, 2
   }

   largest_patch_size {
      level_0 = 512, 512          // largest patch allowed in hierarchy
                                  // all finer levels will use same values as level_0...
   }

   smallest_patch_size {
      level_0 =   4,   4          // smallest patch allowed in hierarchy
                                  // all finer levels will use same values as level_0...
   }

   efficiency_tolerance = 0.70e0  // min % of tag cells in new patch level
   combine_efficiency   = 0.85e0  // chop box if sum of volumes of smaller
                                  // boxes < efficiency * vol of large box
}
```

### Key parameters

| Parameter | Description |
| - | - |
| `max_levels` | Maximum number of levels in the hierarchy, including the base level. The example uses 3 levels: one base level and two refinement levels. |
| `ratio_to_coarser` | Refinement ratio for each level relative to the level below it. `level_1 = 2, 2` means each coarse cell is replaced by a 2×2 block of fine cells. |
| `largest_patch_size` | Upper bound on patch dimensions. Prevents individual patches from becoming too large to load-balance efficiently. |
| `smallest_patch_size` | Lower bound on patch dimensions. Prevents excessive fragmentation into tiny patches. |
| `efficiency_tolerance` | Minimum fraction of tagged cells that a new patch level must contain. Prevents creating large refined regions that are mostly untagged. |
| `combine_efficiency` | Controls whether adjacent small boxes are merged into a larger one. |
| `regrid_interval` | Set in the integrator block. Number of time steps between hierarchy rebuilds. |
| `tag_buffer` | Number of extra cells to tag around each detected gradient cell, ensuring the refined region extends slightly beyond the feature. |

## Cost savings in practice

With `max_levels = 3` and `ratio_to_coarser = 2, 2`, the finest level has 4× the linear resolution of the base level (8× in 2D, 64× in 3D). If the refined region covers only a small fraction of the domain, the total cell count — and therefore the computational cost — is substantially lower than an equivalent uniform fine grid.

The README reports substantial cost savings from using AMR for the four-roll mill and related test problems described in the companion paper.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.