# Re: Calculating stream function from known velocity field.

```
A streamfunction is only defined if the velocity field is
non-divergent. ("Streamlines", which are lines always parallel
to the flow, but with arbitrary spacing, can be defined for
any flow, and I think that is what Ansley was describing in
her first e-mail).

I have some old scripts to do streamfunctions that I would
have to dig out and check before posting them to the group,
but the math goes like this:

Define a streamfunction, Psi(x,y), such that

u = d(Psi)/dy and v = -d(Psi)/dx. 		(1)

By definition:	 du/dx+dv/dy = 0			(2)

so the field is non-divergent.

Given (1), u=d(Psi)/dy -> Psi = Int{y0:y}u dy + a(x)	(3)

and therefore:	d(Psi)/dx = Int{y0:y}du/dx dy + da/dx

Given (2), d(Psi)/dx = Int{y0:y}(-dv/dy) dy + da/dx

= -v(x,y) + v(x,y_0) + da/dx	(4)

But also, by definition:   d(Psi)/dx = -v(x,y)

Therefore: 	da/dx = -v(x,y_0)

a(x) = -Int{x_0:x}v(x,y_0) dx		(5)

>From (3) and (5):

Psi = Int{y0:y}u(x,y) dy - Int{x_0:x}v(x,y_0) dx  (6)

Algorithm: Choose an (x_0,y_0). Integrate the second (indefinite)
integral of (6) along y_0. The result is a function of x. Then at
each x, indefinitely integrate the first integral of (6) along y.
The streamfunction is the sum of those two.

Billy K

```