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

# MultiphaseStaggeredStokesOperator

> Linear operator that applies the coupled two-fluid staggered Stokes system on an AMR hierarchy.

## Overview

`MultiphaseStaggeredStokesOperator` is a concrete `IBTK::LinearOperator` implementing a staggered-grid (MAC) discretisation of the two-fluid incompressible Stokes operator. It is designed for use inside an iterative Krylov or Newton–Krylov solver.

**Namespace:** `multiphase`

**Header:** `multiphase/MultiphaseStaggeredStokesOperator.h`

## Operator matrix

The operator applies the following block system to the vector `[u_n, u_s, p]^T`:

```
[ C*thn + A_n + D_u*xi/nu_n*thn*ths   -D_u*xi/nu_n*thn*ths                D_p*thn*grad ] [ u_n ]
[ -D_u*xi/nu_s*thn*ths                C*ths + A_s + D_u*xi/nu_s*thn*ths   D_p*ths*grad ] [ u_s ]
[ D_div*div(thn)                       D_div*div(ths)                       0            ] [ p   ]
```

where the viscous stress blocks are:

```
A_i = D_u * eta_i * div(thn * ((grad + grad^T) - div*I))
```

The scalars `C`, `D_u`, `D_p`, and `D_div` are set by the time-stepping scheme via `setCandDCoefficients`. Default values of `D_p = -1.0` and `D_div = 1.0` are appropriate for a standard linear system solve. The variable drag coefficient case is also handled by this class.

## Constructor

```cpp theme={null}
MultiphaseStaggeredStokesOperator(
    const std::string& object_name,
    bool homogeneous_bc,
    const MultiphaseParameters& params);
```

**object\_name** `string` *required*

Unique name for this operator, used in logging.

**homogeneous\_bc** `bool` *required*

When `true`, homogeneous (zero) boundary conditions are enforced. Typically `true` when the operator is used as a preconditioner component, `false` for the full system solve.

**params** `const MultiphaseParameters&` *required*

Physical parameters struct containing viscosity coefficients (`eta_n`, `eta_s`) and drag parameters (`xi`, `nu_n`, `nu_s`).

## Configuration methods

### `setCandDCoefficients`

```cpp theme={null}
void setCandDCoefficients(double C, double D_u, double D_p = -1.0, double D_div = 1.0);
```

Sets the scaling coefficients for the operator blocks. These are typically determined by the time-stepping scheme (e.g., `C = 1/dt`, `D_u = 0.5` for Crank–Nicolson).

**C** `double` *required*

Coefficient multiplying the mass-like diagonal block.

**D\_u** `double` *required*

Coefficient scaling the viscous and drag terms in the momentum equations.

**D\_p** `double` (default: -1.0)

Coefficient scaling the pressure gradient terms. Negative by convention for a saddle-point system.

**D\_div** `double` (default: 1.0)

Coefficient scaling the divergence constraint row.

***

### `setThnIdx`

```cpp theme={null}
void setThnIdx(int thn_idx);
```

Provides the cell-centred patch data index for the network volume fraction **θ\_n**. This must be set before calling `apply`.

**thn\_idx** `int` *required*

SAMRAI variable–context index for the cell-centred volume fraction field.

***

### `setPhysicalBcCoefs`

```cpp theme={null}
virtual void setPhysicalBcCoefs(
    const std::vector<SAMRAI::solv::RobinBcCoefStrategy<NDIM>*>& un_bc_coefs,
    const std::vector<SAMRAI::solv::RobinBcCoefStrategy<NDIM>*>& us_bc_coefs,
    SAMRAI::solv::RobinBcCoefStrategy<NDIM>* P_bc_coef,
    SAMRAI::solv::RobinBcCoefStrategy<NDIM>* thn_bc_coef);
```

Registers the physical boundary condition objects for all solution components. Any pointer may be `nullptr`, in which case homogeneous Dirichlet (velocities) or homogeneous Neumann (pressure) conditions are applied.

**un\_bc\_coefs** `std::vector\<SAMRAI::solv::RobinBcCoefStrategy\<NDIM\>*\>` *required*

Robin BC coefficients for the network velocity, one entry per spatial dimension.

**us\_bc\_coefs** `std::vector\<SAMRAI::solv::RobinBcCoefStrategy\<NDIM\>*\>` *required*

Robin BC coefficients for the solvent velocity, one entry per spatial dimension.

**P\_bc\_coef** `SAMRAI::solv::RobinBcCoefStrategy\<NDIM\>*` *required*

Robin BC coefficient for the pressure. Pass `nullptr` for homogeneous Neumann conditions.

**thn\_bc\_coef** `SAMRAI::solv::RobinBcCoefStrategy\<NDIM\>*` *required*

Robin BC coefficient for the volume fraction. Pass `nullptr` for linear extrapolation.

***

### `setPhysicalBoundaryHelper`

```cpp theme={null}
virtual void setPhysicalBoundaryHelper(
    SAMRAI::tbox::Pointer<IBAMR::StaggeredStokesPhysicalBoundaryHelper> bc_helper);
```

Sets the physical boundary condition helper object used during the operator application to enforce velocity boundary values on the staggered grid.

**bc\_helper** `SAMRAI::tbox::Pointer\<IBAMR::StaggeredStokesPhysicalBoundaryHelper\>` *required*

Boundary helper that handles staggered-grid velocity BC enforcement.

## Operator application

### `apply`

```cpp theme={null}
void apply(
    SAMRAI::solv::SAMRAIVectorReal<NDIM, double>& x,
    SAMRAI::solv::SAMRAIVectorReal<NDIM, double>& y) override;
```

Computes `y = A*x`. Both vectors must have the same hierarchy and compatible variable structure. The input vector `x` must have sufficient ghost cells for the stencil computation. You must call `initializeOperatorState` before calling `apply`.

**x** `SAMRAI::solv::SAMRAIVectorReal\<NDIM, double\>&` *required*

Input vector `[u_n, u_s, p]^T`. Must have ghost cells filled.

**y** `SAMRAI::solv::SAMRAIVectorReal\<NDIM, double\>&` *required*

Output vector. Receives the result `A*x` on return.

***

### `initializeOperatorState`

```cpp theme={null}
void initializeOperatorState(
    const SAMRAI::solv::SAMRAIVectorReal<NDIM, double>& in,
    const SAMRAI::solv::SAMRAIVectorReal<NDIM, double>& out) override;
```

Computes and caches all hierarchy-dependent data (communication schedules, scratch allocations) needed for `apply`. Safe to call when state is already initialised; the existing state is deallocated and reinitialised. Call `deallocateOperatorState` to free the allocated data.

**in** `const SAMRAI::solv::SAMRAIVectorReal\<NDIM, double\>&` *required*

Representative input vector defining the hierarchy and variable structure.

**out** `const SAMRAI::solv::SAMRAIVectorReal\<NDIM, double\>&` *required*

Representative output vector. Must match `in` in hierarchy and structure.

***

### `deallocateOperatorState`

```cpp theme={null}
void deallocateOperatorState() override;
```

Releases all hierarchy-dependent data allocated by `initializeOperatorState`. Safe to call when already deallocated. Call this before destroying the operator or after the hierarchy changes.

***

### `modifyRhsForBcs`

```cpp theme={null}
void modifyRhsForBcs(SAMRAI::solv::SAMRAIVectorReal<NDIM, double>& y) override;
```

Modifies the right-hand-side vector to incorporate non-homogeneous physical boundary conditions, moving the BC contribution from the solution side to the RHS.

**y** `SAMRAI::solv::SAMRAIVectorReal\<NDIM, double\>&` *required*

Right-hand-side vector to be modified in place.

***

### `imposeSolBcs`

```cpp theme={null}
void imposeSolBcs(SAMRAI::solv::SAMRAIVectorReal<NDIM, double>& u) override;
```

Directly enforces physical boundary conditions on the solution vector.

**u** `SAMRAI::solv::SAMRAIVectorReal\<NDIM, double\>&` *required*

Solution vector on which boundary conditions are imposed in place.


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