#27581 closed enhancement (fixed)

Initializing the components of a tensor field while declaring it

Reported by: egourgoulhon Owned by:
Priority: major Milestone: sage-8.8
Component: geometry Keywords: tensor field, manifold
Cc: tscrim Merged in:
Authors: Eric Gourgoulhon Reviewers: Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: 990a858 (Commits) Commit: 990a858f1ce18c6537f9c6de7603dcc58f4b9cc2
Dependencies: Stopgaps:

Description (last modified by egourgoulhon)

Currently (Sage 8.7), the definition of a tensor field on a differentiable manifold is a 2-step operation. For instance, for a vector field:

sage: M = Manifold(2, 'M')
sage: X.<x,y> = M.chart()
sage: v = M.vector_field()  # step 1: declaration
sage: v[:] = -y, x          # step 2: initialization of components
sage: v.display()
-y d/dx + x d/dy

This ticket adds the possibility to perform the definition in a single step:

sage: v = M.vector_field(-y, x)
sage: v.display()
-y d/dx + x d/dy

Moreover, some flexibility is introduced in passing the components: it can be a list:

sage: M.vector_field([-y, x]).display()
-y d/dx + x d/dy

or more generally any iterable, like a vector of symbolic expressions:

sage: M.vector_field(vector([-y, x])).display()
-y d/dx + x d/dy

The components can also be provided in a vector frame distinct from the default one:

sage: f = M.vector_frame('f')
sage: M.vector_field(y^2, -1, frame=f).display(f)
y^2 f_0 - f_1

An alternative is passing a dictionary, the keys of which are the vector frames in which the components are defined:

sage: M.vector_field({f: [y^2, -1]}).display(f)
y^2 f_0 - f_1

The dictionary is mandatory if the components are given in various frames at once:

sage: M.vector_field({X.frame(): [-y, x], f: [y^2, -1]}).display(f)
y^2 f_0 - f_1

Note that the possibility of initializing the components while declaring a vector field was introduced on Euclidean spaces in #24623. This ticket extends this to any kind of differentiable manifold and any kind of tensor field. Accordingly, the redefinition of the method vector_field in the class EuclideanSpace has been suppressed: it falls back now to the method vector_field of the mother class DifferentiableManifold.

Basically the (optional) component initialization is performed by the method TensorField._init_components, which is invoked by all the end-user methods devoted to the creation of tensor fields on manifolds, i.e. the methods automorphism_field, diff_form, multivector_field, one_form, sym_bilin_form_field, tensor_field and vector_field of class DifferentiableManifold.

Change History (8)

comment:1 Changed 14 months ago by egourgoulhon

  • Branch set to public/manifolds/tensor_init_comp
  • Cc tscrim added
  • Commit set to ce2b064f6be21e4e4b1f321d79fb15725dd8d53c
  • Status changed from new to needs_review

New commits:

b2a0a7fAdd possibility to initialize the components while creating a vector field
96ea4e7Add possibility to initialize the components while creating a differential form
cc0ebfaAdd possibility to initialize the components while creating a tensor field
0b38c84Add possibility to initialize the components while creating a field of tangent-space automorphisms
22ad0baAdd possibility to initialize the components while creating a multivector field
ce2b064Final clean up regarding the initialization of components at tensor field construction

comment:2 Changed 14 months ago by egourgoulhon

  • Status changed from needs_review to needs_work

Have to fix some merge conflict with Sage 8.8.beta0.

comment:3 Changed 14 months ago by git

  • Commit changed from ce2b064f6be21e4e4b1f321d79fb15725dd8d53c to 990a858f1ce18c6537f9c6de7603dcc58f4b9cc2

Branch pushed to git repo; I updated commit sha1. New commits:

990a858Merge branch 'public/manifolds/tensor_init_comp' of git://trac.sagemath.org/sage into Sage 8.8.beta0

comment:4 Changed 14 months ago by egourgoulhon

  • Status changed from needs_work to needs_review

Merge conflict solved.

comment:5 Changed 14 months ago by egourgoulhon

  • Description modified (diff)

comment:6 Changed 14 months ago by tscrim

  • Reviewers set to Travis Scrimshaw
  • Status changed from needs_review to positive_review

LGTM.

comment:7 Changed 14 months ago by egourgoulhon

Thanks for the review!

comment:8 Changed 14 months ago by vbraun

  • Branch changed from public/manifolds/tensor_init_comp to 990a858f1ce18c6537f9c6de7603dcc58f4b9cc2
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.