Ask Your Question
0

grad on a generic metric

asked 2023-11-21 12:11:14 +0100

GPN gravatar image

Hi.

First, thank you for SageMath Manifolds! I find it fascinating. I am a newbie, and I have indeed looked through the forum and the documentation, but am still stuck. So please excuse if my question is trivial in your eyes.

I am trying to write down the grad of a scalar field in a relatively generic way, but getting the error

ValueError: no common basis for the contraction

At a higher level, my goal is to prove a few basic lemmas about the grad, both as an exercise to learn Manifolds and as part of a larger project.

The following code just sets up the preliminaries and defines the metric:

# preliminaries
from sage. All import *
from sage.manifolds.operators import *
M = Manifold(4, 'M', latex_name=r'\mathcal{M}', structure='Lorentzian')
X.<t,x,y,z> = M.chart()
U = M.open_subset('U', coord_def={X: (y!=0, x<0)})
X_U = X.restrict(U)
F = U.scalar_field(function('f')(t,x,y,z), chart=X_U, name='F')
F.display()

# definition of metric
g = M.metric('g',)
print(g)
g[0,0] = function('g00')(t,x,y,z)
g[1,0] = g[0,1] = function('g01')(t,x,y,z)
g[2,0] = g[0,2] = function('g02')(t,x,y,z)
g[3,0] = g[0,3] = function('g03')(t,x,y,z)
g[1,1] = function('g11')(t,x,y,z)
g[1,2] = g[2,1] = function('g12')(t,x,y,z)
g[1,3] = g[3,1] = function('g13')(t,x,y,z)
g[2,2] = function('g22')(t,x,y,z)
g[2,3] = g[3,2] = function('g23')(t,x,y,z)
g[3,3] = function('g33')(t,x,y,z)
g.display()

All of the above works (thank you). But now I try to do:

grad(F)

and I get the error above.

Obviously I am missing something basic.

Thank you GPN

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-11-21 14:51:30 +0100

eric_g gravatar image

Your code works for me with SageMath 10.1 (the latest stable version).

Which version of SageMath are you using?

edit flag offensive delete link more

Comments

Here is an additional find: that code is part of a bigger notebook which had the line

Parallelism().set(nproc=4)

Based on your input (that the code cell is correct) I started removing lines from other cells and that line was the problem.

First of all, thank you! It was a newbie question and your input helped. Second, I don't know why that line conflicts with the grad(F) but maybe you have more insight?

Thanks again GPN

P.S. I am on SageMath version 9.5, Release Date: 2022-01-30. OS is Ubuntu 22.04 (which is itself on WSL2 on Windows 11, latest). I am using the binary installation, not building the code myself.

GPN gravatar imageGPN ( 2023-11-21 20:57:28 +0100 )edit

Actually, parallelism is broken for computations involving symbolic functions (i.e. defined via functionas in your case) because of this long standing bug: https://github.com/sagemath/sage/issu... So this is certainly the reason why your initial code failed.

eric_g gravatar imageeric_g ( 2023-11-23 14:07:28 +0100 )edit

Thank you @eric_g

GPN gravatar imageGPN ( 2023-11-26 11:45:44 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2023-11-21 12:11:14 +0100

Seen: 137 times

Last updated: Nov 21 '23