Finding the Riemann tensor for the surface of a sphere with sympy.diffgeom

405 views
Skip to first unread message

Imran Ali

unread,
Oct 14, 2015, 12:23:17 PM10/14/15
to sympy
I have implemented a SymPy program that can calculate the Riemann curvature tensor for a given curve element. However, I am encountering problems solving for the case when the curve element is the surface of a sphere

\begin{align}
ds^2 = r^2d\theta^2 + r^2 \sin^2\theta d\phi^2
\end{align}

This is obviously a 2D curve element, so the non-zero elements of the metric become
\begin{align}
g_{11} = r^2, \qquad g_{22} = r^2 \sin^2\theta.
\end{align}
The entries of metric are clearly a function of two variables $r$ and $\theta$. But the way I have created the program it treats them according to their differentials $d\theta$ and $d\phi$. Since $dr$ is 'zero', my metric is computed as
\begin{align}
\begin{bmatrix}
0 &0 &0\\
0 &r^2 &0\\
0 &0 &r^2 \sin^2\theta
\end{bmatrix}.
\end{align}
The way I have coded my implementation is by asking the user for the metric defined as a matrix. If the matrix is 2D, then I use $u$,$v$ to represent the coordinates. Which in the 2D case assign $r$ as $u$ and $\theta$ as $v$. For 3D (with metric above), the additional value $\phi$ is assigned $w$.

Does anyone see my dilemma here? For 3D, I am basically trying to calculate the Riemann tensor for a metric with the determinant equal to zero. And for 2D, the $\phi$ component does not even exist. 

This element is important for me to test my code as this generates a non-zero Riemann curvature tensor. I would really appreciate any suggestions how I can handle this case and thereby improve my code....which fails completely for this case.

(I posted the exact post at physics on stackexchange : http://physics.stackexchange.com/questions/212541/finding-the-riemann-tensor-for-the-surface-of-a-sphere-with-sympy-diffgeom#212541 , and they gently directed my here. I have posted the code on pastebin : http://pastebin.com/DPxW38L0 - the problem lies in the way I have defined the constructor for Riemann class)

Ondřej Čertík

unread,
Oct 14, 2015, 5:26:09 PM10/14/15
to sympy
Hi Imran,
If your space/surface is only 2D, then the metric tensor is a 2x2
matrix, I think it's just:

[r^2, 0]
[0, r^2 sin^2(theta)]

And that's what you need to feed into your program. Then things should
work. If you have a zero entry in the 3x3 metrix tensor, then the
coordinates are degenerate, and I guess your code can't handle it.

>
> Does anyone see my dilemma here? For 3D, I am basically trying to calculate
> the Riemann tensor for a metric with the determinant equal to zero. And for
> 2D, the $\phi$ component does not even exist.
>
> This element is important for me to test my code as this generates a
> non-zero Riemann curvature tensor. I would really appreciate any suggestions
> how I can handle this case and thereby improve my code....which fails
> completely for this case.
>
> (I posted the exact post at physics on stackexchange :
> http://physics.stackexchange.com/questions/212541/finding-the-riemann-tensor-for-the-surface-of-a-sphere-with-sympy-diffgeom#212541
> , and they gently directed my here. I have posted the code on pastebin :
> http://pastebin.com/DPxW38L0 - the problem lies in the way I have defined
> the constructor for Riemann class)

If you want to look at a working code in 4D, look here:

https://github.com/sympy/sympy/blob/master/examples/advanced/relativity.py

Then you can adapt it for a 2D case.

Ondrej

Ondřej Čertík

unread,
Oct 14, 2015, 5:29:03 PM10/14/15
to sympy
Ok, looks like somebody there already gave you an essentially identical answer:

http://physics.stackexchange.com/a/212571/6396

Ondrej

Imran Ali

unread,
Oct 17, 2015, 11:52:38 AM10/17/15
to sympy
Hi Ondrej. I implemented this case with sympy.diffgeom, but the results I get back are not what I expected them to be.

I posted the implementation here : http://pastebin.com/k7UZ4PYy

The Christoffel Riemann tensor the code calculates is as following :

[[ [ [0, 0], [0, 0]], 
   [ [0, sin(theta)**2], [-sin(theta)**2, 0] ] ], 
[[ [0, -1], [1, 0]], 
 [ [0, 0], [0, 0]] ] ]

But this result does not correspond to the hand calculations of Thomas Moore :


With kind regards,
Imran

Francesco Bonazzi

unread,
Oct 17, 2015, 2:49:28 PM10/17/15
to sympy


On Saturday, 17 October 2015 17:52:38 UTC+2, Imran Ali wrote:

But this result does not correspond to the hand calculations of Thomas Moore :


Do you know that unlike matrices tensors don't have defined components? I mean, you may vary their valence (i.e. raise and lower the indices), and you'll get different components.

I did not verify it by hand, but I guess that if you raise the first index of Thomas Moore's Riemann tensor, you'll get the output by SymPy.

Imran Ali

unread,
Oct 19, 2015, 9:59:23 AM10/19/15
to sympy
Ah of course! He has calculated the covariant form of the Riemann-Christoffel tensor. 

Ondřej Čertík

unread,
Oct 19, 2015, 10:31:37 AM10/19/15
to sympy
Perfect. Does everything work as expected then?

If you find further possible problems, please let us know.

Ondrej

Francesco Bonazzi

unread,
Oct 19, 2015, 1:32:22 PM10/19/15
to sympy
We should eventually merge this:
https://github.com/sympy/sympy/pull/9112

The TensorArray object is a multi-dimensional array with valence markings. It could be linked to the differential geometry module, to replace lists of lists of lists of lists.

Francesco Bonazzi

unread,
Oct 22, 2015, 5:26:33 AM10/22/15
to sympy


On Monday, 19 October 2015 19:32:22 UTC+2, Francesco Bonazzi wrote:
We should eventually merge this:
https://github.com/sympy/sympy/pull/9112


Given that this PR is too large to review, I extracted and rewrote the code concerning N-dim arrays (made it more similar to SymPy's matrix module):
https://github.com/sympy/sympy/pull/10016

Basically, these are generalizations of matrices in more than two dimensions. I made the class dependence as similar as possible to SymPy matrices. Feel free to review.

Imran Ali

unread,
Oct 24, 2015, 3:11:28 PM10/24/15
to sympy
I have made a geodesic solver using sympy.diffgeom and scipy.integrate. Currently I am having some issue with the solver. But the problem may be related to Scipy. I have posted  a thread here :


Will let you know how it turns out.

Imran Ali

unread,
Oct 26, 2015, 7:18:04 AM10/26/15
to sympy
It turns out that the Christoffel symbol of second kind found with sympy.diffgeom was invalid. I will try to make a new post here for this soon.

Francesco Bonazzi

unread,
Oct 26, 2015, 9:24:04 AM10/26/15
to sympy
I did not check the calculations, but... are you sure it's not a problem of valence (i.e. contravariant or covariant indices differ)?

We need a tensor-array data structure (i.e. an N-dimensional array with valence markings) to solve this kind of confusion.
Reply all
Reply to author
Forward
0 new messages