# Stream function

In fluid dynamics, two types of stream function are defined:
* The two-dimensional (or Lagrange) stream function, introduced by Joseph Louis Lagrange in 1781, is defined for incompressible (divergence-free), two-dimensional flows.
* The Stokes stream function, named after George Gabriel Stokes, is defined for incompressible, three-dimensional flows with axisymmetry.
The properties of stream functions make them useful for analyzing and graphically illustrating flows.
The remainder of this article describes the two-dimensional stream function.

## Two-dimensional stream function
### Assumptions

The two-dimensional stream function is based on the following assumptions:
* The flow field can be described as two-dimensional plane flow, with velocity vector
    $\quad \mathbf {u} ={\begin{bmatrix}u(x,y,t)\\v(x,y,t)\\0\end{bmatrix}}.$
* The velocity satisfies the continuity equation for incompressible flow:
    $\quad \nabla \cdot \mathbf {u} =0.$
* The domain has no holes, or only has holes that have no net flux inwards or outwards.
Although in principle the stream function doesn't require the use of a particular coordinate system, for convenience the description presented here uses a right-handed Cartesian coordinate system with coordinates $(x,y,z)$.

### Derivation
#### The test surface

Consider two points $A$ and $P$ in the $xy$ plane, and a continuous curve $AP$, also in the $xy$ plane, that connects them. Then every point on the curve $AP$ has $z$ coordinate $z=0$. Let the total length of the curve $AP$ be $L$.
Suppose a ribbon-shaped surface is created by extending the curve $AP$ upward to the horizontal plane $z=b$ $(b>0)$, where $b$ is the thickness of the flow. Then the surface has length $L$, width $b$, and area $b\,L$. Call this the test surface.

#### Flux through the test surface

The total volumetric flux through the test surface is
    $Q(x,y,t)=\int _{0}^{b}\int _{0}^{L}\mathbf {u} \cdot {\hat {\mathbf {n} }}\,\mathrm {d} s\,\mathrm {d} z$
where $s$ is an arc-length parameter defined on the curve $AP$, with $s=0$ at the point $A$ and $s=L$ at the point $P$. Here ${\hat {\mathbf {n} }}$ is the unit vector perpendicular to the test surface, i.e.,
    ${\hat {\mathbf {n} }}\,\mathrm {d} s=-R\,\mathrm {d} \mathbf {r} ={\begin{bmatrix}\mathrm {d} y\\-\mathrm {d} x\\0\end{bmatrix}}$
where $R$ is the $3\times 3$ rotation matrix corresponding to a $90^{\circ }$ anticlockwise rotation about the positive $z$ axis:
    $R=R_{z}(90^{\circ })={\begin{bmatrix}0&-1&0\\1&0&0\\0&0&1\end{bmatrix}}.$
The integrand in the expression for $Q$ is independent of $z$, so the outer integral can be evaluated to yield
    $Q(x,y,t)=b\,\int _{A}^{P}\left(u\,\mathrm {d} y-v\,\mathrm {d} x\right)$

#### Classical definition

Lamb and Batchelor define the stream function $\psi$ as follows.
    $\psi (x,y,t)=\int _{A}^{P}\left(u\,\mathrm {d} y-v\,\mathrm {d} x\right)$
Using the expression derived above for the total volumetric flux, $Q$, this can be written as
    $\psi (x,y,t)={\frac {Q(x,y,t)}{b}}$.
In words, the stream function $\psi$ is the volumetric flux through the test surface per unit thickness, where thickness is measured perpendicular to the plane of flow.
The point $A$ is a reference point that defines where the stream function is identically zero. Its position is chosen more or less arbitrarily and, once chosen, typically remains fixed.
An infinitesimal shift $\mathrm {d} P=(\mathrm {d} x,\mathrm {d} y)$ in the position of point $P$ results in the following change of the stream function:
    $\mathrm {d} \psi =u\,\mathrm {d} y-v\,\mathrm {d} x$.
From the exact differential
    $\mathrm {d} \psi ={\frac {\partial \psi }{\partial x}}\,\mathrm {d} x+{\frac {\partial \psi }{\partial y}}\,\mathrm {d} y,$
so the flow velocity components in relation to the stream function $\psi$ must be
    $u={\frac {\partial \psi }{\partial y}},\qquad v=-{\frac {\partial \psi }{\partial x}}.$
Notice that the stream function is linear in the velocity. Consequently if two incompressible flow fields are superimposed, then the stream function of the resultant flow field is the algebraic sum of the stream functions of the two original fields.

### Effect of shift in position of reference point

Consider a shift in the position of the reference point, say from $A$ to $A'$. Let $\psi '$ denote the stream function relative to the shifted reference point $A'$:
    $\psi '(x,y,t)=\int _{A'}^{P}\left(u\,\mathrm {d} y-v\,\mathrm {d} x\right).$
Then the stream function is shifted by
    ${\begin{aligned}\Delta \psi (t)&=\psi '(x,y,t)-\psi (x,y,t)\\&=\int _{A'}^{A}\left(u\,\mathrm {d} y-v\,\mathrm {d} x\right),\end{aligned}}$
which implies the following:
* A shift in the position of the reference point effectively adds a constant (for steady flow) or a function solely of time (for nonsteady flow) to the stream function $\psi$ at every point $P$.
* The shift in the stream function, $\Delta \psi$, is equal to the total volumetric flux, per unit thickness, through the continuous surface that extends from point $A'$ to point $A$. Consequently $\Delta \psi =0$ if and only if $A$ and $A'$ lie on the same streamline.

### In terms of vector rotation

The velocity $\mathbf {u}$ can be expressed in terms of the stream function $\psi$ as
    $\mathbf {u} =-R\,\nabla \psi$
where $R$ is the $3\times 3$ rotation matrix corresponding to a $90^{\circ }$ anticlockwise rotation about the positive $z$ axis. Solving the above equation for $\nabla \psi$ produces the equivalent form
    $\nabla \psi =R\,\mathbf {u} .$
From these forms it is immediately evident that the vectors $\mathbf {u}$ and $\nabla \psi$ are
* perpendicular: $\mathbf {u} \cdot \nabla \psi =0$
* of the same length: $|\mathbf {u} |=|\nabla \psi |$.
Additionally, the compactness of the rotation form facilitates manipulations (e.g., see Condition of existence).

### In terms of vector potential and stream surfaces

In general, a divergence-free field like $\mathbf {u}$, also known as a solenoidal vector field, can always be represented as the curl of some vector potential ${\boldsymbol {A}}$:
    $\mathbf {u} =\nabla \times {\boldsymbol {A}}.$
The stream function $\psi$ can be understood as providing the strength of a vector potential that is directed perpendicular to the plane:
    ${\boldsymbol {A}}(x,y,t)={\begin{bmatrix}0\\0\\\psi (x,y,t)\end{bmatrix}},$
in other words ${\boldsymbol {A}}=\psi {\hat {\mathbf {z} }}$, where ${\hat {\mathbf {z} }}$ is the unit vector pointing in the positive $z$ direction.
This can also be written as the vector cross product
    $\mathbf {u} =\nabla \psi \times {\hat {\mathbf {z} }}$
where we've used the vector calculus identity
    $\nabla \times \left(\psi {\hat {\mathbf {z} }}\right)=\psi \nabla \times {\hat {\mathbf {z} }}+\nabla \psi \times {\hat {\mathbf {z} }}.$
Noting that ${\hat {\mathbf {z} }}=\nabla z$, and defining $\phi =z$, one can express the velocity field as
    $\mathbf {u} =\nabla \psi \times \nabla \phi .$
This form shows that the level surfaces of $\psi$ and the level surfaces of $z$ (i.e., horizontal planes) form a system of orthogonal stream surfaces.

### Alternative (opposite sign) definition

An alternative definition, sometimes used in meteorology and oceanography, is
    $\psi '=-\psi .$

### Relation to vorticity

In two-dimensional plane flow, the vorticity vector, defined as ${\boldsymbol {\omega }}=\nabla \times \mathbf {u}$, reduces to $\omega \,{\hat {\mathbf {z} }}$, where
    $\omega =-\nabla ^{2}\psi$
or
    $\omega =+\nabla ^{2}\psi '$
These are forms of Poisson's equation.

### Relation to streamlines

Consider two-dimensional plane flow with two infinitesimally close points $P=(x,y,z)$ and $P'=(x+dx,y+dy,z)$ lying in the same horizontal plane. From calculus, the corresponding infinitesimal difference between the values of the stream function at the two points is
    ${\begin{aligned}\mathrm {d} \psi (x,y,t)&=\psi (x+\mathrm {d} x,y+\mathrm {d} y,t)-\psi (x,y,t)\\&={\partial \psi \over \partial x}\mathrm {d} x+{\partial \psi \over \partial y}\mathrm {d} y\\&=\nabla \psi \cdot \mathrm {d} \mathbf {r} \end{aligned}}$
Suppose $\psi$ takes the same value, say $C$, at the two points $P$ and $P'$. Then this gives
    $0=\nabla \psi \cdot \mathrm {d} \mathbf {r} ,$
implying that the vector $\nabla \psi$ is normal to the surface $\psi =C$. Because $\mathbf {u} \cdot \nabla \psi =0$ everywhere (e.g., see In terms of vector rotation), each streamline corresponds to the intersection of a particular stream surface and a particular horizontal plane. Consequently, in three dimensions, unambiguous identification of any particular streamline requires that one specify corresponding values of both the stream function and the elevation ($z$ coordinate).
The development here assumes the space domain is three-dimensional. The concept of stream function can also be developed in the context of a two-dimensional space domain. In that case level sets of the stream function are curves rather than surfaces, and streamlines are level curves of the stream function. Consequently, in two dimensions, unambiguous identification of any particular streamline requires that one specify the corresponding value of the stream function only.

### Condition of existence

It's straightforward to show that for two-dimensional plane flow $\mathbf {u}$ satisfies the curl-divergence equation
    $(\nabla \cdot \mathbf {u} )\,{\hat {\mathbf {z} }}=-\nabla \times (R\,\mathbf {u} )$
where $R$ is the $3\times 3$ rotation matrix corresponding to a $90^{\circ }$ anticlockwise rotation about the positive $z$ axis. This equation holds regardless of whether or not the flow is incompressible.
If the flow is incompressible (i.e., $\nabla \cdot \mathbf {u} =0$), then the curl-divergence equation gives
    $\mathbf {0} =\nabla \times (R\,\mathbf {u} )$.
Then by Stokes' theorem the line integral of $R\,\mathbf {u}$ over every closed loop vanishes
    $\oint _{\partial \Sigma }(R\,\mathbf {u} )\cdot \mathrm {d} \mathbf {\Gamma } =0.$
Hence, the line integral of $R\,\mathbf {u}$ is path-independent. Finally, by the converse of the gradient theorem, a scalar function $\psi (x,y,t)$ exists such that
    $R\,\mathbf {u} =\nabla \psi$.
Here $\psi$ represents the stream function.
Conversely, if the stream function exists, then $R\,\mathbf {u} =\nabla \psi$. Substituting this result into the curl-divergence equation yields $\nabla \cdot \mathbf {u} =0$ (i.e., the flow is incompressible).
In summary, the stream function for two-dimensional plane flow exists if and only if the flow is incompressible.

### Potential flow

For two-dimensional potential flow, streamlines are perpendicular to equipotential lines. Taken together with the velocity potential, the stream function may be used to derive a complex potential. In other words, the stream function accounts for the solenoidal part of a two-dimensional Helmholtz decomposition, while the velocity potential accounts for the irrotational part.

### Summary of properties

The basic properties of two-dimensional stream functions can be summarized as follows:
* The x- and y-components of the flow velocity at a given point are given by the partial derivatives of the stream function at that point.
* The value of the stream function is constant along every streamline (streamlines represent the trajectories of particles in steady flow). That is, in two dimensions each streamline is a level curve of the stream function.
* The difference between the stream function values at any two points gives the volumetric flux through the vertical surface that connects the two points.

## Two-dimensional stream function for flows with time-invariant density

If the fluid density is time-invariant at all points within the flow, i.e.,
    ${\frac {\partial \rho }{\partial t}}=0$,
then the continuity equation (e.g., see Continuity equation#Fluid dynamics) for two-dimensional plane flow becomes
    $\nabla \cdot (\rho \,\mathbf {u} )=0.$
In this case the stream function $\psi$ is defined such that
    $\rho \,u={\frac {\partial \psi }{\partial y}},\quad \rho \,v=-{\frac {\partial \psi }{\partial x}}$
and represents the mass flux (rather than volumetric flux) per unit thickness through the test surface.