Fwd: Elementary vector calculus with Sage

46 views
Skip to first unread message

kcrisman

unread,
Mar 15, 2018, 7:42:11 AM3/15/18
to sage...@googlegroups.com
FYI for any users of the current vector calculus functionality - please let the author know if you have any suggestions, especially if you have a Trac account (note that now having a Github account suffices for making basic comments etc. there).

On Wednesday, March 14, 2018 at 12:06:18 PM UTC-4, Eric Gourgoulhon wrote:
Hi,

After demands from users (see e.g. https://ask.sagemath.org/question/40792/div-grad-and-curl-once-again/ and
https://ask.sagemath.org/question/10104/gradient-divergence-curl-and-vector-products/) and a first attempt (see ticket #3021), a proposal to fully implement elementary vector calculus (dot and cross products, gradient, divergence, curl, Laplace operator) is ready for review at #24623.

In this implementation, Euclidean spaces are considered as Riemannian manifolds diffeomorphic to R^n endowed with a flat metric. This allows for an easy use of various coordinate systems, along with the related transformations. However, the user interface does not assume any knowledge of Riemannian geometry. In particular, no direct manipulation of the metric tensor is required.

A minimal example is

sage: E.<x,y,z> = EuclideanSpace(3)
sage
: v = E.vector_field(-y, x, 0)
sage
: v.display()
-y e_x + x e_y
sage
: v[:]
[-y, x, 0]
sage
: w = v.curl()
sage
: w.display()
2 e_z
sage
: w[:]
[0, 0, 2]

It is possible to use curl(v) instead of v.curl(), via

sage: from sage.manifolds.operators import *
sage
: w = curl(v)

This can be compared with the curl() already implemented (through #3021)  for vectors of symbolic expressions:

sage: x, y, z = var('x y z')
sage
: v = vector([-y, x, 0])
sage
: v
(-y, x, 0)
sage
: w = v.curl([x, y, z])
sage
: w
(0, 0, 2)


Note that [x, y, z] must be provided as the argument of curl to define the orientation. A limitation of this implementation is that it is valid only with Cartesian coordinates. With the #24623 implementation, we can do, in continuation with the first piece of code shown above:

sage: spherical.<r,th,ph> = E.spherical_coordinates()
sage
: spherical_frame = E.spherical_frame()  # orthonormal frame (e_r, e_th, e_ph)
sage
: v.display(spherical_frame, spherical)
r
*sin(th) e_ph
sage
: v[spherical_frame, :, spherical]
[0, 0, r*sin(th)]
sage
: w.display(spherical_frame, spherical)
2*cos(th) e_r - 2*sin(th) e_th
sage
: w[spherical_frame, :, spherical]
[2*cos(th), -2*sin(th), 0]


More detailed examples are provided in the following Jupyter notebooks (click on the names to see them via nbviewer.jupyter.org):

- vector calculus in Cartesian coordinates
​- vector calculus in spherical coordinates
- vector calculus in cylindrical coordinates
​- changing coordinates in the Euclidean 3-space
- ​advanced aspects: Euclidean spaces as Riemannian manifolds
​- the Euclidean plane

Needless to say, any feedback / review is welcome.

Eric.






Reply all
Reply to author
Forward
0 new messages