Determining Christoffel Symbols and Curvature Tensors for a Flat Sphere using SymPy.Diffgeom

165 views
Skip to first unread message

Imran Ali

unread,
Oct 31, 2015, 1:04:14 PM10/31/15
to sympy
I just asked the following question at stackoverflow :

http://stackoverflow.com/questions/33453941/determining-christoffel-symbols-and-curvature-tensors-for-a-flat-sphere-using-sy

In essence, the question is two fold :

1) My own implementation fails for flat surfaces in 3D
2) Sympy.Diffgeom seems to give wrong results

Really appreciate any insight as to what is causing the error and why the hand-coded sympy.diffgeom produces wrong result.

Imran Ali

unread,
Oct 31, 2015, 1:24:01 PM10/31/15
to sympy
I forgot to mention in the SO post (not that I have mentioned plenty already there) that sometimes I get the following error :

Traceback (most recent call last):
  File "tensor.py", line 274, in <module>
    RC = R.find_Christoffel_tensor()
  File "tensor.py", line 210, in find_Christoffel_tensor
    R = metric_to_Riemann_components(metric)
  File "/usr/local/lib/python2.7/dist-packages/sympy-0.7.7.dev0-py2.7.egg/sympy/diffgeom/diffgeom.py", line 1575, in metric_to_Riemann_components
    ch_2nd = metric_to_Christoffel_2nd(expr)
  File "/usr/local/lib/python2.7/dist-packages/sympy-0.7.7.dev0-py2.7.egg/sympy/diffgeom/diffgeom.py", line 1525, in metric_to_Christoffel_2nd
    ch_1st = metric_to_Christoffel_1st(expr)
  File "/usr/local/lib/python2.7/dist-packages/sympy-0.7.7.dev0-py2.7.egg/sympy/diffgeom/diffgeom.py", line 1492, in metric_to_Christoffel_1st
    matrix = twoform_to_matrix(expr)
  File "/usr/local/lib/python2.7/dist-packages/sympy-0.7.7.dev0-py2.7.egg/sympy/diffgeom/diffgeom.py", line 1463, in twoform_to_matrix
    raise ValueError('The input expression concerns more than one '
ValueError: The input expression concerns more than one coordinate systems, hence there is no unambiguous way to choose a coordinate system for the matrix.

In this case I have introduced some bug in the code, I do not understand why I am getting this error.

Here is the input I give :

g = 
Matrix([[1/(u**2 + 1), 0, 0], [0, u**2, 0], [0, 0, u**2*sin(v)**2]]) 

The code produces the following two-form :

sin(v)**2*u**2*TensorProduct(dw, dw) + u**2*TensorProduct(dv, dv) + TensorProduct(du, du)/(u**2 + 1) 

For the coordinate system :

CoordSystem(nontrivial, Patch(P, Manifold(M, 3)), (u, v, w))

Imran Ali

unread,
Oct 31, 2015, 1:58:15 PM10/31/15
to sympy


On Saturday, October 31, 2015 at 6:04:14 PM UTC+1, Imran Ali wrote:
I just asked the following question at stackoverflow :

http://stackoverflow.com/questions/33453941/determining-christoffel-symbols-and-curvature-tensors-for-a-flat-sphere-using-sy

In essence, the question is two fold :

1) My own implementation fails for flat surfaces in 3D
By my own implementation,  I mean the source code that I have provided in the SO post
 
2) Sympy.Diffgeom seems to give wrong results
Here I am referring to the hand-coded example in the SO post

Imran Ali

unread,
Nov 5, 2015, 8:56:09 AM11/5/15
to sympy
If I simply hard code each metric, every thing works properly. For example, take egg carton surface,

    from sympy.diffgeom import Manifold, Patch, CoordSystem, TensorProduct
    from sympy import sin,cos
    dim = 2
    m = Manifold("M",dim)
    patch = Patch("P",m)
    system = CoordSystem('egg_carton', patch, ["u", "v"])
    u,v = system.coord_functions()
    du,dv = system.base_oneforms()
    metric = (sin(v)**2*sin(u)**2 + 1)*TensorProduct(dv, dv) +\
             (cos(v)**2*cos(u)**2 + 1)*TensorProduct(du, du) +\
             (-cos(2*v - 2*u)/8 + cos(2*v + 2*u)/8)*TensorProduct(du, dv) +\
             (-cos(2*v - 2*u)/8 + cos(2*v + 2*u)/8)*TensorProduct(dv, du)
I can use any of the metric_to_* functions without getting the ValueError. 

By the way, that metric expression, is from my code. My code produces the correct metric two form expression. But when I use it as argument for any of the metric_to_* functions, I get the ValueError. What gives ?

I posted the question on SO :

Kalevi Suominen

unread,
Nov 6, 2015, 11:51:40 AM11/6/15
to sympy


On Thursday, November 5, 2015 at 3:56:09 PM UTC+2, Imran Ali wrote:
If I simply hard code each metric, every thing works properly. For example, take egg carton surface,

    from sympy.diffgeom import Manifold, Patch, CoordSystem, TensorProduct
    from sympy import sin,cos
    dim = 2
    m = Manifold("M",dim)
    patch = Patch("P",m)
    system = CoordSystem('egg_carton', patch, ["u", "v"])
    u,v = system.coord_functions()
    du,dv = system.base_oneforms()
    metric = (sin(v)**2*sin(u)**2 + 1)*TensorProduct(dv, dv) +\
             (cos(v)**2*cos(u)**2 + 1)*TensorProduct(du, du) +\
             (-cos(2*v - 2*u)/8 + cos(2*v + 2*u)/8)*TensorProduct(du, dv) +\
             (-cos(2*v - 2*u)/8 + cos(2*v + 2*u)/8)*TensorProduct(dv, du)
I can use any of the metric_to_* functions without getting the ValueError. 

By the way, that metric expression, is from my code. My code produces the correct metric two form expression. But when I use it as argument for any of the metric_to_* functions, I get the ValueError. What gives ?

I posted the question on SO :

 

It is not clear how u, v, du, dv are constructed in your SO question. If you could post srepr(u) and srepr(du), it might be possible to say more.

Aaron Meurer

unread,
Nov 6, 2015, 11:54:36 AM11/6/15
to sy...@googlegroups.com
What you should do is post the complete code to stackoverflow, as you
have done here.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/35eb06db-64de-41d2-9b6d-292074724df3%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Francesco Bonazzi

unread,
Nov 6, 2015, 5:09:02 PM11/6/15
to sympy
I answered to you on StackOverflow. You should be more clear by posting questions, this looks like a problem in your calculation logic, not in SymPy.

Imran Ali

unread,
Nov 8, 2015, 10:40:45 AM11/8/15
to sympy
Hi Kalevi!

I got the following output from srepr :

Symbol('u')
Differential(BaseScalarField(CoordSystem(Symbol('egg_carton'), Patch(Symbol('P'), Manifold(Symbol('M'), Integer(2))), Tuple(Symbol('u'), Symbol('v'))), Integer(0)))

I see now what the error is! My code used u as a sympy expression, instead of it being one of the coord_functions(). 

Thanks!

Imran Ali

unread,
Nov 8, 2015, 10:42:05 AM11/8/15
to sympy
Hey Aaron!

Thanks for the tip, I posted the code on SO. But, I think that Kalevi solved the problem. I found the issue.

Imran Ali

unread,
Nov 8, 2015, 10:45:44 AM11/8/15
to sympy
I was a bit quick there. srepr(u) gives the following output :

BaseScalarField(CoordSystem(Symbol('egg_carton'), Patch(Symbol('P'), Manifold(Symbol('M'), Integer(2))), Tuple(Symbol('u'), Symbol('v'))), Integer(0))

Kalevi Suominen

unread,
Nov 8, 2015, 12:00:17 PM11/8/15
to sympy

It looks like  u  was defined differently in different contexts.
Reply all
Reply to author
Forward
0 new messages