Flow Across a Closed Curve

How do we get the unit normal? Remember the gradient section?
If the curve is given by g(x,y)=0, a normal vector at a point is given by
gradient(g) evaluated at that point. The unit normal is grad(g)/||grad(g)||.
As an example, compute the flow of v(x,y)=x i + y j through the circle x^2+y^2=9.
Clear[v,f,r,flow,n]
v[x_,y_]:={x,y}
f[x_,y_]:=x^2+y^2-9
grad2[f][x,y]
n=grad2[f][x,y]/norm[grad2[f][x,y]]
Simplify[%]
v[x,y].n
Simplify[%]
To integrate v.n ds, we need the result from the section "Line
Integrals":
v.n ds is v(x(t),y(t),z(t)).n(x(t), y(t), z(t)) ||r'(t)|| dt.
We must parametrize f(x,y) as r(t)=3cos[t] i + 3sin[t] j.

r[t_]:={3 Cos[t], 3 Sin[t]}
vn=v[x,y].n /.{x->3 Cos[t], y->3 Sin[t]}
Simplify[norm[D[r[t],t]]]
flow=Integrate[3 vn ,{t,0,2 Pi}]
By the way, if the curve f(x,y) is already parametrized as r(t)={x(t),y(t)},
then r'(t)={x'(t),y'(t)} is the tangent vector, so the unit normal vector must
be
n(t)={-y'(t),x(t)}/||{-y'(t),x(t)}||
or
n(t)={y'(t),-x(t)}/||{y'(t),-x(t)}||
The choice depends upon the choice of inner pointing or outer pointing normal.
(Remember the vectorcalc1 notebook?)
(Check: Is r'(t).n(t)=0?)
In the above example, we have (using the gradient) that n=
Simplify[n/.{x->3 Cos[t], y->3 Sin[t]}]Using the parametrization we have n=
parametrizedn=
D[{r[t][[2]],-r[t][[1]]},t]/norm[D[{r[t][[2]],-r[t][[1]]},t]];
Simplify[parametrizedn]Up to 2D Flows