<< Calculus`VectorAnalysis`

The following is just to make subscripts inert, so that they behave as in physics. It has no influence on the functioning of the package.

SetAttributes[Subscript, {HoldAllComplete, Constant}]

Off[General::spell, General::spell1]

Test of package

The following should work for all coordinate systems, but the cylindrical is the easiest to check.

Define coordinate system

Set up coordinate system and variables

SetCoordinates[Cylindrical[r, ϕ, z]]

Check ranges

CoordinateRanges[]

Coordinate transformations

Substitutions of variables to and from the curvilinear coordinates

toCurvilinear = 
      Thread[{x, y, z} -> CoordinatesToCartesian[{r, ϕ, z}]]

toCartesian = 
      Thread[{r, ϕ, z} -> 
          CoordinatesFromCartesian[{x, y, z}]]

Examples

(x^2) + (y^2) + (z^2) /. toCurvilinear // TrigExpand

(r^2) Cos[2  ϕ] /. toCartesian

Basis vectors

The Jacobian matrix connects Cartesian and curvilinear coordinates

jacobian = JacobianMatrix[]

jacobian // MatrixForm

The scale factors used to normalize the columns of the Jacobian

scales = ScaleFactors[]

Curvilinear basis in the Cartesian system

{(Subscript[e, r]), (Subscript[e, ϕ]), (Subscript[e, z])} = Transpose[jacobian]/scales

Cartesian basis in the curvilinear system

{(Subscript[e, x]), (Subscript[e, y]), (Subscript[e, z])} = Transpose[{(Subscript[e, r]), (Subscript[e, ϕ]), (Subscript[e, z])}]

Examples

Cartesian vector

v = {(Subscript[v, x]), (Subscript[v, y]), (Subscript[v, z])};

Transform to curvilinear system

{v . (Subscript[e, r]), v . (Subscript[e, ϕ]), v . (Subscript[e, z])}

Curvilinear vector

v = {(Subscript[v, r]), (Subscript[v, ϕ]), (Subscript[v, z])};

Transform to Cartesian system

{v . (Subscript[e, x]), v . (Subscript[e, y]), v . (Subscript[e, z])}

Gradient, divergence, and curl

Scalar field in curvilinear coordinates

s = f[r, ϕ, z];

Gradient of scalar field

Grad[s]

Vector field in curvilinear coordinates

v = {(Subscript[v, r])[r, ϕ, z], (Subscript[v, ϕ])[r, ϕ, z], 
          (Subscript[v, z])[r, ϕ, z]};

Divergence of vector field

Div[v] // Expand

Curl of vector field

Curl[v] // Expand

Laplacian

The Laplacian of scalar field

Laplacian[s] // Expand

Laplacian of vector field

Laplacian[v] // Expand // MatrixForm

Tensor operations (not included in original Calculus`VectorAnalysis`)

Gradient from the left of a vector

Grad[v] // MatrixForm

Divergence of the gradient of a vector should equal the Laplacian

Div[Grad[v]] // Expand // MatrixForm

One may also calculate the inertial acceleration used in fluid mechanics

v . Grad[v] // Expand // MatrixForm

General tensor field

t = {{(Subscript[t, rr])[r, ϕ, z], (Subscript[t, r])ϕ[r, ϕ, z], 
            (Subscript[t, rz])[r, ϕ, z]}, {(Subscript[t, ϕ])r[r, ϕ, z], 
            (Subscript[t, ϕ])ϕ[r, ϕ, z], 
            (Subscript[t, ϕ])z[r, ϕ, z]}, {(Subscript[t, zr])[r, ϕ, z], 
            (Subscript[t, z])ϕ[r, ϕ, z], (Subscript[t, zz])[r, ϕ, z]}};

t // MatrixForm

Divergence from left of tensor field (for example the stress tensor)

Div[t] // Expand // MatrixForm

Example

The stress tensor in a Newtonian incompressible fluid depends on the symmetric gradient of the velocity field

Grad[v] + Transpose[Grad[v]] // MatrixForm