用球体的sympy.diffgeom找到黎曼曲率张量

时间:2015-10-03 16:39:12

标签: python sympy

我正在测试sympy.diffgeom库。我的目的是找到从笛卡尔坐标和球坐标之间的变换找到的预先计算的度量的黎曼曲率张量。这是代码

from sympy.diffgeom import Manifold, Patch, CoordSystem, TensorProduct
import sympy as sym
from sympy import cos,sinh,cosh, sin

m = Manifold("M",3)
patch = Patch("P",m)

cartesian = CoordSystem("cartesian",patch, ["x", "y", "z"])
x, y, z = cartesian.coord_functions()
spherical = CoordSystem("spherical", patch, ["r", "theta", "phi"])
r, theta, phi = spherical.coord_functions()
g = sym.Matrix([[1, 0, 0], [0, r**2, 0], [0, 0, r**2*sin(theta)**2]])

diff_forms = toroidal.base_oneforms()
metric_diff_form = sum([TensorProduct(di, dj)*g[i, j] for i, di in enumerate(diff_forms) for j, dj in enumerate(diff_forms)])

# Find the Riemann curvature tensor
from sympy.diffgeom import metric_to_Riemann_components
R = metric_to_Riemann_components(metric_diff_form)

当我运行它时,我在最后一行得到以下错误

ValueError: The input expression concerns more than one coordinate systems, hence there is no unambiguous way to choose a coordinate system for the matrix.

我不明白为什么,因为我已经测试了不同(更复杂)指标的代码。

1 个答案:

答案 0 :(得分:2)

您的矩阵 g 由坐标系 sphere 的坐标函数组成,您将它们与坐标系的两种形式环形混合

在将度量矩阵转换为两种形式的总和之前,请尝试此操作:

diff_forms = spherical.base_oneforms()

错误信息非常简单。