> ## 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.

# Four roll mill

> Simulate a blob of network fluid deforming in a four-roll mill flow on an adaptively refined grid.

The four roll mill example drives two-phase flow with an imposed body force that generates four counter-rotating vortices. A compact blob of network fluid (tracked by the volume fraction `thn`) is initialized at the center and advected by the resulting velocity field. This example demonstrates AMR grid refinement driven by gradient detection, and optionally adds a viscoelastic (Oldroyd-B) stress model via the conformation tensor forcing.

## CMake targets

| Target | Source file |
| - | - |
| `frm` | `frm/four_roll_mill.cpp` |
| `frm_convergence` | `frm/convergence_tester.cpp` |

## Build

From your build directory (see [Building](https://bindi-nagda-amr-multiphase.mintlify.site/building.md)):

```bash theme={null}
make frm
```

## Run

> [tab] Newtonian (default)
>
> Run from the `frm/` source directory, passing `input2d` and PETSc solver flags:
>
> ```bash theme={null}
> cd frm
> ./frm input2d \
>     -solver_ksp_initial_guess_nonzero FALSE \
>     -solver_ksp_monitor_true_residual \
>     -solver_ksp_type fgmres \
>     -solver_ksp_max_it 20 \
>     -solver_ksp_rtol 1e-14
> ```
>
> Visualization output is written to `viz2d_four_roll_mill/`. Open this directory in [VisIt](https://visit-dav.github.io/visit-website/) to inspect the results.

> [tab] Viscoelastic (Oldroyd-B)
>
> Use `input2d.cf.relax` to enable the conformation tensor model:
>
> ```bash theme={null}
> cd frm
> ./frm input2d.cf.relax \
>     -solver_ksp_initial_guess_nonzero FALSE \
>     -solver_ksp_monitor_true_residual \
>     -solver_ksp_type fgmres \
>     -solver_ksp_max_it 20 \
>     -solver_ksp_rtol 1e-14
> ```
>
> This variant sets `USE_CF = TRUE` and uses the `CFMultiphaseOldroydB` strategy. Visualization output goes to `viz2d_overlap/` and hierarchy data to `hier_data_cf_relax/`.

## Key input parameters

The following parameters are set in `input2d` and control the physical setup and time integration.

### Fluid properties

```text theme={null}
ETA_S = 0.04          // solvent (network) shear viscosity
ETA_N = 4.0           // network shear viscosity
NU_N  = 1.0           // network drag coefficient
NU_S  = 1.0           // solvent drag coefficient
XI    = 250.0*ETA_S   // inter-phase drag coefficient (= 10.0)
```

### Grid and time stepping

```text theme={null}
N       = 64                        // coarse grid cells per side
DX      = 1.0 / N
U_MAX   = 20.0
CFL_MAX = 0.1
DT_MAX  = CFL_MAX * DX / U_MAX     // = 7.8125e-6
END_TIME = 1.0
```

### Network volume fraction initial condition

The network blob `thn` is initialized with a smooth, compactly supported bump function centered at the origin:

```text theme={null}
DELTA = 0.175

thn {
   delta = DELTA
   function = "0.25 + 0.25*((sqrt(X_0*X_0+X_1*X_1)<delta) ? \
     (1989.0/(896*PI) \
       * (1.0 - ((X_0*X_0+X_1*X_1)/(delta*delta))^4.0)^4.0 \
       * (4.0*((X_0*X_0+X_1*X_1)/(delta*delta))^4.0+1.0)) \
     : 0.0)"
}
```

This produces a background volume fraction of `0.25` everywhere, with a smooth bump that raises `thn` to `0.50` at the center. The support radius is `DELTA = 0.175`.

### Forcing functions

The four-roll mill body force applied to both phases:

```text theme={null}
FN_FCN {
   function_0 = "2*PI*sin(2*PI*X_0)*cos(2*PI*X_1) + 8*PI*PI*sin(2*PI*X_0)*cos(2*PI*X_1)"
   function_1 = "2*PI*cos(2*PI*X_0)*sin(2*PI*X_1) - 8*PI*PI*cos(2*PI*X_0)*sin(2*PI*X_1)"
}
```

The same expression is applied to `FS_FCN` (the solvent phase). In the viscoelastic variant (`input2d.cf.relax`) the forcing is active only for `t < 0.34`, then switched off to let the conformation tensor relax.

## AMR settings

The hierarchy uses up to **3 levels** with a refinement ratio of 2 in each direction. Cells are tagged for refinement based on the gradient of the solution variables:

```text theme={null}
GriddingAlgorithm {
   max_levels = 3

   ratio_to_coarser {
      level_1 = 2, 2
      level_2 = 2, 2
      level_3 = 2, 2
   }
   ...
}

StandardTagAndInitialize {
   tagging_method = "GRADIENT_DETECTOR"
}
```

The gradient threshold and regridding interval are controlled in the integrator block:

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

> [!NOTE]
>
> The viscoelastic variant (`input2d.cf.relax`) uses 4 AMR levels with per-level thresholds `grad_abs_thresh = 1.0, 4.0, 6.0` and a larger base refinement ratio of 4.

## Visualization output

| Directory | Contents |
| - | - |
| `viz2d_four_roll_mill/` | VisIt plot files for the Newtonian run |
| `hier_data_four_roll_mill/` | Hierarchy data dumps for post-processing |
| `viz2d_overlap/` | VisIt plot files for the viscoelastic (CF) run |
| `hier_data_cf_relax/` | Hierarchy data dumps for the viscoelastic run |

The simulation writes a new visualization frame every `VIZ_DUMP_TIME_INTERVAL = 0.005` time units. In addition to the standard velocity, pressure, and `thn` fields, the strain rate tensor `EE` is computed and written at each visualization step.

## Viscoelastic variant parameters

When `USE_CF = TRUE` (enabled in `input2d.cf.relax`), the `CFINSForcing` block configures the Oldroyd-B conformation tensor evolution:

```text theme={null}
FLUID_MODEL      = "OLDROYDB"
EVOLVE_TYPE      = "STANDARD"
RELAXATION_TIME  = 0.3
VISCOSITY        = 2.0

CFINSForcing {
   InitialConditions {
      function_0 = "1.0"   // C_xx = 1 (identity tensor)
      function_1 = "1.0"   // C_yy = 1
      function_2 = "0.0"   // C_xy = 0
   }
   relaxation_time              = RELAXATION_TIME
   viscosity                    = VISCOSITY
   fluid_model                  = FLUID_MODEL
   evolution_type               = EVOLVE_TYPE
   log_determinant              = TRUE
   convective_operator_type     = "CUI"
   output_conformation_tensor   = TRUE
   output_divergence            = TRUE
}
```

> [!TIP]
>
> Set `LOG_DETERMINANT = TRUE` to monitor the determinant of the conformation tensor during the run. A determinant that drifts far from 1 may indicate numerical issues with the conformation tensor evolution.


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