#24623 closed enhancement (fixed)
Euclidean spaces and vector calculus
Reported by:  egourgoulhon  Owned by:  

Priority:  major  Milestone:  sage8.3 
Component:  geometry  Keywords:  Euclidean space, vector calculus, gradient, divergence, curl, Laplacian 
Cc:  tmonteil  Merged in:  
Authors:  Eric Gourgoulhon  Reviewers:  Travis Scrimshaw 
Report Upstream:  N/A  Work issues:  
Branch:  220726c (Commits)  Commit:  
Dependencies:  #24622, #24792  Stopgaps: 
Description (last modified by )
This ticket implements Euclidean spaces as Riemannian manifolds diffeomorphic to R^{n} and equipped with a flat metric, which defines the Euclidean dot product. Using the operators introduced in #24622, this provides the standard operators of vector calculus: dot product, norm, cross product, gradient, divergence, curl and Laplacian, along with the standard coordinate systems (Cartesian, spherical, cylindrical, etc.).
See this ask.sagemath question for a motivation, as well as this one.
The implementation is performed via the parent class EuclideanSpace
, which inherits from PseudoRiemannianManifold
(introduced in #24622). Two subclasses are devoted to specific cases:
EuclideanPlane
for n=2Euclidean3dimSpace
for n=3
The user interface for constructing an Euclidean space relies on the EuclideanSpace.__classcall_private__
to direct to the appropriate subclass.
The implementation through the manifold framework 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]
The transformation to spherical coordinates:
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) sqrt(x^2 + y^2) 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 in the following Jupyter notebooks:
 vector calculus in Cartesian coordinates
 vector calculus in spherical coordinates
 vector calculus in cylindrical coordinates
 changing coordinates in the Euclidean 3space
 Advanced aspects: Euclidean spaces as Riemannian manifolds
 the Euclidean plane
This work is part of the SageManifolds project, see #18528 for an overview.
Change History (39)
comment:1 Changed 11 months ago by
 Description modified (diff)
comment:2 Changed 11 months ago by
 Description modified (diff)
comment:3 Changed 11 months ago by
 Cc tmonteil added
comment:4 Changed 10 months ago by
 Branch set to public/manifolds/Euclidean_spaces
 Commit set to 4bf802027ddd8178ab17efa692bda2d877e0f8d6
comment:5 Changed 10 months ago by
 Dependencies changed from #24622 to #24622, #24792
#24792 introduces more flexibility in naming the elements of vector frames, for instance using (e_x, e_y, e_z)
for a coordinate frame instead of (d/dx, d/dy, d/dz)
. The current ticket will therefore be build on it for a better user interface.
comment:6 Changed 10 months ago by
 Commit changed from 4bf802027ddd8178ab17efa692bda2d877e0f8d6 to f24a5f96a25d12b75c9d98a1b6749513673b4faa
Branch pushed to git repo; I updated commit sha1. New commits:
a527e8e  First draft adding more flexibility in symbols of free module bases and vector frames

2d43a23  More refactoring in vector frames

0840d54  More work on vector frames

01681b8  Add documentation for new options of vector frames

f24a5f9  Merge branch 'public/manifolds/Euclidean_spaces' of git://trac.sagemath.org/sage into public/manifolds/more_basis_flexibility (branch of #24792)

comment:7 Changed 10 months ago by
 Commit changed from f24a5f96a25d12b75c9d98a1b6749513673b4faa to d9302b65668e7f62b54306c4e4c916c73c72dc31
Branch pushed to git repo; I updated commit sha1. New commits:
d9302b6  Add documentation and doctests for Euclidean spaces

comment:8 followups: ↓ 9 ↓ 26 Changed 10 months ago by
I wonder whether some of this (in terms of the div/grad/curl) could be exposed in the symbolic calculus places, at least with some wellplaced and wellformed examples that would be understandable to someone teaching Calc III to engineers (in the US framework) who may not be a differential geometer.
comment:9 in reply to: ↑ 8 Changed 10 months ago by
Replying to kcrisman:
I wonder whether some of this (in terms of the div/grad/curl) could be exposed in the symbolic calculus places, at least with some wellplaced and wellformed examples that would be understandable to someone teaching Calc III to engineers (in the US framework) who may not be a differential geometer.
Indeed, the aim here is to provide some interface which does not require any knowledge of differential geometry on manifolds. The class EuclideanSpaceGeneric
does inherit from PseudoRiemannianManifold
, but the end user has not to know it if he is not interested by this aspect and prefers to focus on vector calculus. Regarding examples, I plan to prepare some Jupyter notebooks and will expose them here, when the ticket is ready for review. Already, you can have a glimpse of the div/grad/curl capabilities introduced in the dependency #24622 in this notebook.
comment:10 followup: ↓ 11 Changed 10 months ago by
That's great! The reason I brought it up is because folders like sage/calculus
and sage/symbolic
might benefit from some good examples that are easy to find.
Is there a way to use something like (say) vector([x^2+y,y^2+z,z^2+x])
as "vector field" immediately, without much (or any) of the formalism necessary in that notebook? I think that is how most end users I've talked to about this issue would want it. See e.g. https://ask.sagemath.org/question/10104/gradientdivergencecurlandvectorproducts/ and ticket:3021 for one version already in Sage  maybe these should be combined somehow, if possible.
comment:11 in reply to: ↑ 10 Changed 10 months ago by
Replying to kcrisman:
Is there a way to use something like (say)
vector([x^2+y,y^2+z,z^2+x])
as "vector field" immediately, without much (or any) of the formalism necessary in that notebook?
Yes, this is precisely the aim of the current ticket. The above notebook is still at the level of semiRiemannian manifolds (i.e. it illustrates only ticket #24622), while the user interface of the current ticket will be much simpler. It should also provide an easy way to change from Cartesian coordinates to e.g. polar or cylindrical ones.
See e.g. https://ask.sagemath.org/question/10104/gradientdivergencecurlandvectorproducts/ and ticket:3021 for one version already in Sage  maybe these should be combined somehow, if possible.
Thanks for pointing this version; I was not aware of it.
comment:12 Changed 10 months ago by
 Commit changed from d9302b65668e7f62b54306c4e4c916c73c72dc31 to 56a1a4a37f60f8f61ba8da18ece1e281c6c07aa9
Branch pushed to git repo; I updated commit sha1. New commits:
9ddc467  Add method set_name to classes VectorFrame and CoFrame

82c37b4  Cut long lines in src/sage/manifolds/differentiable/vectorframe.py

95b2736  Merge branch 'public/manifolds/more_basis_flexibility' of git://trac.sagemath.org/sage into Euclidean (to get latest version of the dependency #24792)

56a1a4a  Add method vector_field to Euclidean spaces + internal changes regarding charts and frames

comment:13 Changed 10 months ago by
 Commit changed from 56a1a4a37f60f8f61ba8da18ece1e281c6c07aa9 to 70a2a749c2d5c07a85182c0d51fdc9f16d050b01
Branch pushed to git repo; I updated commit sha1. New commits:
799066b  List entries of VectorFrame processed by __classcall_private__

da06d12  Small improvement in treatment of symbol attributes of free module bases

244c1f4  Merge branch 'public/manifolds/more_basis_flexibility' into 'public/manifolds/Euclidean_spaces' to get the latest version of dependency #24792 in #24623.

70a2a74  Vector fields on Euclidean spaces can be initialized from a vector of symbolic expressions

comment:14 Changed 10 months ago by
 Description modified (diff)
comment:15 Changed 10 months ago by
Here is some status update: functionalities regarding the 2dimensional case are almost complete, as you can see in this demo worksheet (any feedback is of course appreciated). The 3dimensional case is under preparation. The generic ndimensional case, with n=1 or n>=4 is ready, since only Cartesian coordinates will be introduced (by default) in this case.
Regarding a question raised in comment:10, it is now possible to construct a vector field on an Euclidean space from a vector
of symbolic expressions like this:
v = E.vector_field(vector([y,x]))
where E
is the underlying Euclidean space.
comment:16 Changed 9 months ago by
 Commit changed from 70a2a749c2d5c07a85182c0d51fdc9f16d050b01 to 6e9fce6b191d1d1fcf84153ea90478c444687703
Branch pushed to git repo; I updated commit sha1. New commits:
18b63a6  Differential operators are no longer imported in the global namespace by PseudoRiemannianManifold.__init__

8367232  Merge branch 'public/manifolds/pseudoRiemannian' of git://trac.sagemath.org/sage into 'public/manifolds/Euclidean_spaces' to get the latest version of the dependency #24622 in #24623.

6e9fce6  First draft of Euclidean 3spaces, with the Cartesian, spherical and cylindrical coordinate systems

comment:17 Changed 9 months ago by
 Commit changed from 6e9fce6b191d1d1fcf84153ea90478c444687703 to 825ba7831fc3774455fd23b4c3b78dee3ee1fa0c
Branch pushed to git repo; I updated commit sha1. New commits:
825ba78  Add doctests to Euclidean spaces

comment:18 Changed 9 months ago by
 Commit changed from 825ba7831fc3774455fd23b4c3b78dee3ee1fa0c to 88f12ed85714bfa068c0a4e8f911681771ca4f20
Branch pushed to git repo; I updated commit sha1. New commits:
185e438  Improve documentation of pseudoRiemannian manifolds

52b10ee  Merge branch 'public/manifolds/pseudoRiemannian' of git://trac.sagemath.org/sage into 'public/manifolds/Euclidean_spaces' to get the final version of the dependency #24622 in #24623.

88f12ed  Improve documentation of Euclidean spaces

comment:19 Changed 9 months ago by
 Commit changed from 88f12ed85714bfa068c0a4e8f911681771ca4f20 to 371e05ee9f2d118c8f4b1d13376668a85b6fa639
Branch pushed to git repo; I updated commit sha1. New commits:
371e05e  Improve treatment of changes of frames in Euclidean spaces + documentation added

comment:20 Changed 9 months ago by
 Commit changed from 371e05ee9f2d118c8f4b1d13376668a85b6fa639 to 8a87f70a8efbf5e5f57f682459fe984a8df92338
Branch pushed to git repo; I updated commit sha1. New commits:
8a87f70  Add scalar triple product in Euclidean spaces

comment:21 Changed 9 months ago by
 Commit changed from 8a87f70a8efbf5e5f57f682459fe984a8df92338 to dd1951f87df19bdab818ded912e38579ad8f2fc5
Branch pushed to git repo; I updated commit sha1. New commits:
dd1951f  Improve documentation of Euclidean spaces, especially of vector operators

comment:22 Changed 9 months ago by
 Commit changed from dd1951f87df19bdab818ded912e38579ad8f2fc5 to d8b748baf218baf6d35b767d358553619a9045cb
comment:23 Changed 9 months ago by
 Commit changed from d8b748baf218baf6d35b767d358553619a9045cb to de74bb734f9f531bb6d991b14af20e58e6ebd683
Branch pushed to git repo; I updated commit sha1. New commits:
de74bb7  Slight reorganization of the documentation of Euclidean spaces

comment:24 Changed 9 months ago by
 Description modified (diff)
comment:25 Changed 9 months ago by
 Status changed from new to needs_review
The documentation has been completed in the above commits and new Jupyter notebook examples have been added. This is now ready for review.
comment:26 in reply to: ↑ 8 Changed 9 months ago by
Replying to kcrisman:
I wonder whether some of this (in terms of the div/grad/curl) could be exposed in the symbolic calculus places, at least with some wellplaced and wellformed examples that would be understandable to someone teaching Calc III to engineers (in the US framework) who may not be a differential geometer.
I have added an entry "Vector Calculus" to src/doc/en/reference/calculus/index.rst
. I have also added some SEEALSO
sections in the definitions of curl
and div
in src/sage/modules/free_module_element.pyx
, as well as in the definition of gradient
in src/sage/symbolic/expression.pyx
.
comment:27 Changed 9 months ago by
 Description modified (diff)
comment:28 Changed 8 months ago by
 Description modified (diff)
comment:29 Changed 8 months ago by
 Commit changed from de74bb734f9f531bb6d991b14af20e58e6ebd683 to 3578e5f49d0f8ef92fca4b7cb5e1d818fa49a633
comment:30 Changed 8 months ago by
 Commit changed from 3578e5f49d0f8ef92fca4b7cb5e1d818fa49a633 to ab249df0d9dc01064ef68dd366941fe38e5a8e13
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
ab249df  Fusing EuclideanSpace function with EuclideanSpaceGeneric plus other misc reviewer changes.

comment:31 followup: ↓ 32 Changed 8 months ago by
 Description modified (diff)
 Reviewers set to Travis Scrimshaw
Okay, I have made my way through the code. Overall, it looks good.
I remove the function EuclideanSpace
and just used the __classcall_private__
mechanism (provided by UniqueRepresentation
) to make the class EuclideanSpace
(formerly EuclideanSpaceGeneric
) the main entry point.
There is something very subtle happening as some of the doctest output for display names of arctan2(y, x)
needed to be arctan(y/x)
. I do not understand why nor could I see what was causing this. It is not a blocker issue, but it is an indication that something might not be working properly.
The rest of my changes were mostly cosmetic.
comment:32 in reply to: ↑ 31 Changed 8 months ago by
Replying to tscrim:
Okay, I have made my way through the code. Overall, it looks good.
Thanks a lot for looking into this.
I remove the function
EuclideanSpace
and just used the__classcall_private__
mechanism (provided byUniqueRepresentation
) to make the classEuclideanSpace
(formerlyEuclideanSpaceGeneric
) the main entry point.
This is a nice improvement, thanks!
There is something very subtle happening as some of the doctest output for display names of
arctan2(y, x)
needed to bearctan(y/x)
. I do not understand why nor could I see what was causing this. It is not a blocker issue, but it is an indication that something might not be working properly.
Indeed; I will look into this...
The rest of my changes were mostly cosmetic.
Thanks for all of them.
comment:33 Changed 8 months ago by
I should also say that if you approve of my changes, then you can set a positive review.
(Unfortunately, a number of the doctests are just slow because of feeding calls off to Maxima and the simplifications. Although I don't think there is anything we can do about that.)
comment:34 Changed 8 months ago by
 Commit changed from ab249df0d9dc01064ef68dd366941fe38e5a8e13 to 220726c07bc00ba69b12a5cc7dc9499d930f1e8c
comment:35 Changed 8 months ago by
The above commit fixes the arctan
issue mentioned in comment:31: it was due to the declaration
sage: E3.<x,t,p> = EuclideanSpace(coordinates='spherical')
in line 591 of euclidean.py
, which had the side effect of adding x>0
to Sage's assumptions. Then subsequent doctests involving arctan2(y, x)
automatically replaced it by arctan(y/x)
. I changed the variable x
to r
in the declaration of E3
(which btw fits better with standard notation for spherical coordinates) and everything was OK, i.e. all arctan2(y, x)
could be restored.
Moreover, since it is now possible to skip the dimension as first argument of EuclideanSpace
in constructions of the type E.<x,y> = EuclideanSpace()
(thank you for this improvement!), I systematically removed the dimension argument and added a sentence in the documentation about this.
I also took the opportunity of this commit to add a singleline fix of a (small) bug in src/sage/manifolds/differentiable/vectorfield_module.py
revealed after the dependency ticket #24792 was merged. I hope you do not mind.
comment:36 followup: ↓ 37 Changed 8 months ago by
 Status changed from needs_review to positive_review
Yep, LGTM. Thank you for tracking that down.
comment:37 in reply to: ↑ 36 Changed 8 months ago by
Replying to tscrim:
Yep, LGTM. Thank you for tracking that down.
Thank you very much for the review, and the associated improvements in the code!
comment:38 Changed 7 months ago by
 Branch changed from public/manifolds/Euclidean_spaces to 220726c07bc00ba69b12a5cc7dc9499d930f1e8c
 Resolution set to fixed
 Status changed from positive_review to closed
comment:39 Changed 7 months ago by
 Commit 220726c07bc00ba69b12a5cc7dc9499d930f1e8c deleted
 Milestone changed from sage8.2 to sage8.3
Merged in Sage 8.3.beta0.
This is a first sketch (not ready yet).
Last 10 new commits:
Improve documentation of pseudoRiemannian manifolds
Remove method set_metric and improve doc of pseudoRiemannian manifolds
Add operators Laplacian, d'Alembertian and curl on pseudoRiemannian manifolds
Add dot product and cross product of vector fields
Add norm of vector fields.
Add method volume_form() to class PseudoRiemannianManifold
Add global functions grad, div, curl, etc. for vector/tensor operators on pseudoRiemannian manifolds
Improve documentation for operators on pseudoRiemannian manifolds
Merge branch 'public/manifolds/pseudoRiemannian' of git://trac.sagemath.org/sage into Sage 8.2.beta5
First draft of Euclidean spaces as Riemannian manifolds