Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Tutorial vector calculus 5: advanced aspects

Project: SageManifolds
Views: 333
Kernel: SageMath 8.8.beta2

Vector calculus with SageMath

Part 5: Advanced aspects: Euclidean spaces as Riemannian manifolds

This notebook illustrates some vector calculus capabilities of SageMath within the 3-dimensional Euclidean space. The corresponding tools have been developed within the SageManifolds project.

Click here to download the notebook file (ipynb format). To run it, you must start SageMath with the Jupyter interface, via the command sage -n jupyter

NB: a version of SageMath at least equal to 8.3 is required to run this notebook:

version()
'SageMath version 8.8.beta2, Release Date: 2019-04-14'

First we set up the notebook to display math formulas using LaTeX formatting:

%display latex

The Euclidean 3-space

We define the 3-dimensional Euclidean space E3\mathbb{E}^3, with Cartesian coordinates (x,y,z)(x,y,z):

E.<x,y,z> = EuclideanSpace() print(E) E
Euclidean space E^3

E3\mathbb{E}^3 is actually a Riemannian manifold, i.e. a smooth real manifold endowed with a positive definite metric tensor:

E.category()
print(E.category())
Category of smooth manifolds over Real Field with 53 bits of precision
E.base_field() is RR

Actually RR is used here as a proxy for the real field (this should be replaced in the future, see the discussion at #24456) and the 53 bits of precision play of course no role for the symbolic computations.

Let us introduce spherical and cylindrical coordinates on E3\mathbb{E}^3:

spherical.<r,th,ph> = E.spherical_coordinates() cylindrical.<rh,ph,z> = E.cylindrical_coordinates()

The user atlas of E3\mathbb{E}^3 has then three charts:

E.atlas()

while there are five vector frames defined on E3\mathbb{E}^3:

E.frames()

Indeed, there are two frames associated with each of the three coordinate systems: the coordinate frame (denoted with partial derivatives above) and an orthonormal frame, but for Cartesian coordinates, both frames coincide.

We get the orthonormal spherical and cylindrical frames by

spherical_frame = E.spherical_frame() spherical_frame
cylindrical_frame = E.cylindrical_frame() cylindrical_frame

On the other side, the coordinate frames are returned by the method frame() acting on the coordinate charts:

spherical.frame()
cylindrical.frame()

Charts as maps E3→R3\mathbb{E}^3 \rightarrow \mathbb{R}^3

The chart of Cartesian coordinates has been constructed at the declaration of E; let us denote it by cartesian:

cartesian = E.cartesian_coordinates() cartesian

Let us consider a point p∈E3p\in \mathbb{E}^3, defined by its Cartesian coordinates:

p = E((-1, 1,0), chart=cartesian, name='p') print(p)
Point p on the Euclidean space E^3
p.parent() is E

The coordinates of pp in a given coordinate chart are obtained by letting the corresponding chart act on pp:

cartesian(p)
spherical(p)
cylindrical(p)

Riemannian metric

The default metric tensor of E3\mathbb{E}^3 is

g = E.metric() print(g)
Riemannian metric g on the Euclidean space E^3
g.display()
g[:]

The above display in performed in the default frame, which is the Cartesian one. Of course, we may ask for display with respect to other frames:

g.display(spherical_frame)
g[spherical_frame, :]

In the above display, ere^r, eθe^\theta and eϕe^\phi are the 1-forms defining the coframe dual to the orthonormal spherical frame (er,eθ,eϕ)(e_r,e_\theta,e_\phi):

spherical_frame.coframe()

The fact that the above metric components are either 0 or 1 reflect the orthonormality of the vector frame (er,eθ,eϕ)(e_r,e_\theta,e_\phi). On the contrary, in the coordinate frame (∂∂r,∂∂θ,∂∂ϕ)\left(\frac{\partial}{\partial r}, \frac{\partial}{\partial\theta}, \frac{\partial}{\partial \phi}\right), which is not orthonormal, the components differ from 0 or 1:

g.display(spherical.frame())

Note that the components are expressed in terms of the default chart, namely the Cartesian one. To have them displayed in terms of the spherical chart, we have to provide the latter as the second argument of the method display():

g.display(spherical.frame(), spherical)
g[spherical.frame(), :, spherical]

Similarly, for cylindrical coordinates, we have

g.display(cylindrical_frame)
g.display(cylindrical.frame(), cylindrical)
g[cylindrical.frame(),:,cylindrical]

The metric gg is a flat: its (Riemann) curvature tensor is zero:

print(g.riemann())
Tensor field Riem(g) of type (1,3) on the Euclidean space E^3
g.riemann().display()

The metric gg is defining the dot product on E3\mathbb{E}^3:

u = E.vector_field(x*y, y*z, z*x) u.display()
v = E.vector_field(-y, x, z^2, name='v') v.display()
u.dot(v) == g(u,v)

Consequently

norm(u) == sqrt(g(u,u))

The Levi-Civita tensor

The scalar triple product of E3\mathbb{E}^3 is provided by the Levi-Civita tensor (also called volume form) associated with gg (and chosen such that (ex,ey,ez)(e_x,e_y,e_z) is right-handed):

epsilon = E.scalar_triple_product() print(epsilon)
3-form epsilon on the Euclidean space E^3
epsilon is E.volume_form()
epsilon.display()
epsilon.display(spherical.frame(), spherical)
epsilon.display(cylindrical.frame(), cylindrical)

Checking that all orthonormal frames introduced above are right-handed:

ex, ey, ez = E.cartesian_frame()[:] epsilon(ex, ey, ez).display()
epsilon(*spherical_frame)
epsilon(*spherical_frame).display()
epsilon(*cylindrical_frame).display()

Vector fields as derivatives

Let ff be a scalar field on E3\mathbb{E}^3:

f = E.scalar_field(x^2+y^2 - z^2, name='f') f.display()

Vector fields acts as derivative on scalar fields:

print(v(f))
Scalar field v(f) on the Euclidean space E^3
v(f).display()
v(f) == v.dot(f.gradient())
df = f.differential() print(df)
1-form df on the Euclidean space E^3
df.display()
v(f) == df(v)

The algebra of scalar fields

The set C∞(E3)C^\infty(\mathbb{E}^3) of all smooth scalar fields on E3\mathbb{E}^3 forms a commutative algebra over R\mathbb{R}:

CE = E.scalar_field_algebra() CE
CE.category()
f in CE

In SageMath terminology C∞(E3)C^\infty(\mathbb{E}^3) is the parent of scalar fields:

f.parent() is CE

The free module of vector fields

The set X(E3)\mathfrak{X}(\mathbb{E}^3) of all vector fields on E3\mathbb{E}^3 is a free module of rank 3 over the commutative algebra C∞(E3)C^\infty(\mathbb{E}^3):

XE = v.parent() print(XE) XE
Free module X(E^3) of vector fields on the Euclidean space E^3
print(XE.category())
Category of finite dimensional modules over Algebra of differentiable scalar fields on the Euclidean space E^3
print(XE.base_ring()) XE.base_ring()
Algebra of differentiable scalar fields on the Euclidean space E^3
XE.base_ring() is CE
rank(XE)

The bases of the free module X(E3)\mathfrak{X}(\mathbb{E}^3) are nothing but the vector frames defined on E3\mathbb{E}^3:

XE.bases()

Tangent spaces

Vector fields evaluated at a point are vectors in the tangent space at this point:

print(p)
Point p on the Euclidean space E^3
vp = v.at(p) vp.display()
Tp = vp.parent() print(Tp) Tp
Tangent space at Point p on the Euclidean space E^3
print(Tp.category())
Category of finite dimensional vector spaces over Symbolic Ring
dim(Tp)
isinstance(Tp, FiniteRankFreeModule)

The bases on TpE3T_p\mathbb{E}^3 are inherited from the vector frames of E3\mathbb{E}^3:

Tp.bases()

For instance, we have

spherical_frame.at(p)
spherical_frame.at(p) in Tp.bases()

Levi-Civita connection

The Levi-Civita connection associated to the Euclidean metric gg is

nabla = g.connection() print(nabla) nabla
Levi-Civita connection nabla_g associated with the Riemannian metric g on the Euclidean space E^3

The corresponding Christoffel symbols with respect to Cartesian coordinates are identically zero: none of them appear in the output of christoffel_symbols_display, which by default displays only nonzero Christoffel symbols:

g.christoffel_symbols_display(cartesian)

On the contrary, some of the Christoffel symbols with respect to spherical coordinates differ from zero:

g.christoffel_symbols_display(spherical)

By default, only nonzero and nonredundant values are displayed (for instance Γ  ϕrϕ\Gamma^\phi_{\ \, \phi r} is skipped, since it can be deduced from Γ  rϕϕ\Gamma^\phi_{\ \, r \phi} by symmetry on the last two indices).

Similarly, the nonzero Christoffel symbols with respect to cylindrical coordinates are

g.christoffel_symbols_display(cylindrical)

The Christoffel symbols are nothing but the connection coefficient in the corresponding coordinate frame:

nabla.display(cylindrical.frame(), cylindrical, only_nonredundant=True)

The connection coefficients with respect to the orthonormal (non-coordinate) frames are (again only nonzero values are displayed):

nabla.display(spherical_frame, spherical)
nabla.display(cylindrical_frame, cylindrical)

∇g\nabla_g is the connection involved in differential operators:

from sage.manifolds.operators import *
grad(f) == nabla(f).up(g)
nabla(f) == grad(f).down(g)
div(u) == nabla(u).trace()
div(v) == nabla(v).trace()
laplacian(f) == nabla(nabla(f).up(g)).trace()
laplacian(u) == nabla(nabla(u).up(g)).trace(1,2)
laplacian(v) == nabla(nabla(v).up(g)).trace(1,2)