Curvilinear differential calculus
<!– crosslinks: written by .github/scripts/crosslinks.py from docs/crosslinks.toml; do not edit –>
See also
Manual: Coordinate systems (symbolic) · Coordinate systems (numerical)
Tutorials: Differential operators, symbolically · Christoffel symbols · Differential operators, numerically · Classical identities of the differential operators
<!– /crosslinks –>
The second pillar of the library, and the second chapter with no counterpart in the Echoes manual, which works only in Cartesian coordinates. Everything below is derived from the definitions and matches src/coorsystems.jl (symbolic) and src/coorsystems_num.jl (automatic differentiation). A classical treatment of the underlying tensor analysis is Simmonds (1994).
Chart, natural basis, metric
A coordinate system is a map
with the dual basis
Lamé coefficients and the normalized basis
The natural vectors are generally neither unit nor orthogonal. Their norms are the Lamé coefficients
and
TensND stores both bases: natural_basis and normalized_basis, with natvec and unitvec for individual vectors and lame_coefficients for the
Predefined systems
| System | Coordinates | Lamé | |
|---|---|---|---|
coorsys_cartesian | |||
coorsys_polar | |||
coorsys_cylindrical | |||
coorsys_spherical | |||
coorsys_spheroidal |
with, for the prolate spheroidal system,
The spherical coordinates are ordered (\theta,\varphi,r)
Not RotatedBasis — see Rotations — and lets spherical results be compared with Euler-angle results without a permutation. The same ordering applies to init_spherical and to
The figures below draw each curvilinear system at a point
Polar coordinates
With
Cylindrical coordinates
The polar pair in the plane
Spherical coordinates
With
In this order the triad is the image of the canonical basis by the rotation
Spheroidal coordinates, prolate and oblate
coorsys_spheroidal is the prolate system of the table. With
and
Far from the foci, as
The oblate system revolves the same confocal ellipses and hyperbolas of a meridian plane about their minor axis instead of their major one:
Its foci form the circle of radius
and the Lamé coefficients and the normalized basis are those of the prolate system with TensND does not predefine this system: the figure draws it for comparison. Its buttons switch between the two systems, and a fourth slider sets
Christoffel symbols
The natural basis varies, and the rate at which it does is the connection:
They are symmetric in
and it is the
For the predefined systems, the non-vanishing ones are
All Christoffel symbols of the Cartesian system vanish, which is the definition of a Cartesian chart.
Storage convention
christoffel returns a Γ_func closure of the pointwise CoordinateSystem.
The five operators
TensND defines the differential operators intrinsically, as sums over the chart directions:
| Operator | Definition | Order |
|---|---|---|
grad | ||
symgrad | ||
divergence | ||
laplacian | ||
hess |
Here
Index placement is a convention, and this is the one
and divergence contracts the last index,
A library using the opposite convention differs by a transpose. The choice here is what makes
Note also that symgrad is a primitive, not (grad + transpose)/2 — applied to a displacement field it is directly the linearized strain tensor.
Two implementations, one interface
The operators have the same names and meaning whether the derivatives are taken symbolically or by automatic differentiation.
CoordinateSystem | the pointwise CoordinateSystem | |
|---|---|---|
| derivatives | SymPy / Symbolics, exact | ForwardDiff, machine precision |
| stores | ||
| result | a formula, valid everywhere | a number, at one point |
| cost | grows with expression size | constant per point |
| needs | a symbolic | any differentiable OM(x) |
| best for | deriving and simplifying closed forms | evaluating fields, sweeps, gradients |
A PointwiseGeometry stores the geometry as three closures — χ_func (Lamé), R_func (the rotation to the normalized frame) and Γ_func (Christoffel, with the
Because everything downstream is generic in the element type, ForwardDiff.Dual numbers flow through the operators in both directions: an operator result can be differentiated again with respect to the evaluation point, and with respect to a parameter carried by the field itself. The internal buffers promote the element type of the geometry (the Lamé coefficients) with that of the field value, so a Dual-valued field evaluated on a Float64 coordinate system is handled correctly.
Simplification machinery
Non-trivial symbolic charts — the spheroidal one is the standard example — produce metric expressions that SymPy will not reduce on its own. The exact CoordinateSystem therefore accepts:
| Argument | Role |
|---|---|
tmp_coords | auxiliary variables standing for compound expressions |
params | constants appearing in |
rules | rewrite rules applied after each simplification |
tmp_var | substitutions replacing expressions by temporary variables |
to_coords | how to eliminate the temporaries before differentiating |
Without them the Christoffel symbols of a spheroidal chart are computable in principle and unusable in practice. Their use is shown in Christoffel symbols among the tutorials.