# TwoDNavierStokes

### Basic Equations

This module solves two-dimensional incompressible Navier-Stokes equations using the vorticity-streamfunction formulation. The flow $\bm{u} = (u, v)$ is obtained through a streamfunction $\psi$ as $(u, v) = (-\partial_y \psi, \partial_x \psi)$. The only non-zero component of vorticity is that normal to the plane of motion, $\partial_x v - \partial_y u = \nabla^2 \psi$. The module solves the two-dimensional vorticity equation:

\[\partial_t \zeta + \mathsf{J}(\psi, \zeta) = \underbrace{-\left [ \mu (-\nabla^2)^{n_\mu} + \nu (-\nabla^2)^{n_\nu} \right ] \zeta}_{\textrm{dissipation}} + F ,\]

where $\mathsf{J}(\psi, \zeta) = (\partial_x \psi)(\partial_y \zeta) - (\partial_y \psi)(\partial_x \zeta)$ is the two-dimensional Jacobian and $F(x, y, t)$ is forcing. The Jacobian term is the advection of relative vorticity, $\mathsf{J}(ψ, ζ) = \bm{u \cdot \nabla} \zeta$. Both $ν$ and $μ$ terms are viscosities; typically the former is chosen to act at small scales ($n_ν ≥ 1$), while the latter at large scales ($n_ν ≤ 0$). Plain old viscocity corresponds to $n_ν=1$ while $n_μ=0$ corresponds to linear drag. Values of $n_ν ≥ 2$ or $n_μ ≤ -1$ are referred to as hyper- or hypo-viscosities, respectively.

### Implementation

The equation is time-stepped forward in Fourier space:

\[\partial_t \widehat{\zeta} = - \widehat{\mathsf{J}(\psi, \zeta)} - \left ( \mu |𝐤|^{2n_\mu} + \nu |𝐤|^{2n_\nu} \right ) \widehat{\zeta} + \widehat{F} .\]

The state variable `sol`

is the Fourier transform of vorticity, `ζh`

.

The Jacobian is computed in the conservative form: $\mathsf{J}(a, b) = \partial_y [(\partial_x a) b] - \partial_x[(\partial_y a) b]$.

The linear operator is constructed in `Equation`

`GeophysicalFlows.TwoDNavierStokes.Equation`

— Function`Equation(params, grid)`

Return the `equation`

for two-dimensional Navier-Stokes with `params`

and `grid`

. The linear operator $L$ includes (hyper)-viscosity of order $n_ν$ with coefficient $ν$ and hypo-viscocity of order $n_μ$ with coefficient $μ$,

\[L = - ν |𝐤|^{2 n_ν} - μ |𝐤|^{2 n_μ} .\]

Plain old viscocity corresponds to $n_ν=1$ while $n_μ=0$ corresponds to linear drag.

The nonlinear term is computed via the function `calcN!`

.

The nonlinear terms are computed via

`GeophysicalFlows.TwoDNavierStokes.calcN!`

— Function`calcN!(N, sol, t, clock, vars, params, grid)`

Calculate the nonlinear term, that is the advection term and the forcing,

\[N = - \widehat{𝖩(ψ, ζ)} + F̂ .\]

which in turn calls `calcN_advection!`

and `addforcing!`

.

### Parameters and Variables

All required parameters are included inside `Params`

and all module variables are included inside `Vars`

.

For decaying case (no forcing, $F=0$), `vars`

can be constructed with `Vars`

. For the forced case ($F \ne 0$) the `vars`

struct is with `ForcedVars`

or `StochasticForcedVars`

.

### Helper functions

Some helper functions included in the module are:

`GeophysicalFlows.TwoDNavierStokes.updatevars!`

— Function`updatevars!(prob)`

Update variables in `vars`

with solution in `sol`

.

`GeophysicalFlows.TwoDNavierStokes.set_ζ!`

— Function`set_ζ!(prob, ζ)`

Set the solution `sol`

as the transform of `ζ`

and then update variables in `vars`

.

### Diagnostics

Some useful diagnostics are:

`GeophysicalFlows.TwoDNavierStokes.energy`

— Function`energy(prob)`

Return the domain-averaged kinetic energy. Since $u² + v² = |{\bf ∇} ψ|²$, the domain-averaged kinetic energy is

\[\int \frac1{2} |{\bf ∇} ψ|² \frac{𝖽x 𝖽y}{L_x L_y} = \sum_{𝐤} \frac1{2} |𝐤|² |ψ̂|² .\]

`GeophysicalFlows.TwoDNavierStokes.enstrophy`

— Function`enstrophy(prob)`

Returns the domain-averaged enstrophy,

\[\int \frac1{2} ζ² \frac{𝖽x 𝖽y}{L_x L_y} = \sum_{𝐤} \frac1{2} |ζ̂|² .\]

Other diagnostic include: `energy_dissipation`

, `energy_work`

, `enstrophy_dissipation`

, and `enstrophy_work`

.

## Examples

`examples/twodnavierstokes_decaying.jl`

: A script that simulates decaying two-dimensional turbulence reproducing the results byMcWilliams, J. C. (1984). The emergence of isolated coherent vortices in turbulent flow.

*J. Fluid Mech.*,**146**, 21-43.`examples/twodnavierstokes_stochasticforcing.jl`

: A script that simulates forced-dissipative two-dimensional turbulence with isotropic temporally delta-correlated stochastic forcing.`examples/twodnavierstokes_stochasticforcing_budgets.jl`

: A script that simulates forced-dissipative two-dimensional turbulence demonstrating how we can compute the energy and enstrophy budgets.