【问题标题】:Finding the Riemann curvature tensor with sympy.diffgeom用 sympy.diffgeom 求黎曼曲率张量
【发布时间】:2015-10-02 17:29:49
【问题描述】:

我正在尝试用度量 g 的符号表达式来确定黎曼曲率张量。我已经预先计算了指标。笛卡尔坐标为

  • x = x(eta,theta,psi) = a*sinh(eta)*cos(psi)/(cosh(eta) - cos(theta))
  • y = y(eta,theta,psi) = a*sinh(eta)*sin(psi)/(cosh(eta) - cos(theta))
  • z = z(eta,theta,psi) = a*sin(theta))/(cosh(eta) - cos(theta))

度量是通过从笛卡尔 (x,y,z) 到环形坐标 (eta,theta,psi) 的变换找到的。使用符号包 SymPy,如下脚本

from sympy.diffgeom import Manifold, Patch, CoordSystem, TensorProduct
from sympy.abc import theta, eta, psi
import sympy as sym

x,y,z,a = sym.symbols("x y z a")
m = Manifold("M",3)
patch = Patch("P",m)

cartesian = CoordSystem("cartesian",patch)
toroidal = CoordSystem("toroidal",patch)

from sympy import sin,cos,sinh,cosh
toroidal.connect_to(cartesian,[eta,theta,psi],
[(a*sinh(eta)*cos(psi))/(cosh(eta) - cos(theta)),
 (a*sinh(eta)*sin(psi))/(cosh(eta) - cos(theta)),
 (a*sin(theta))/(cosh(eta) - cos(theta))],inverse=False)

g = sym.Matrix([[a**2/(cos(theta) - cosh(eta))**2,        0,           0],
                [0,           a**2/(cos(theta) - cosh(eta)),           0],
                [0,   0,   a**2*sinh(eta)**2/(cos(theta) - cosh(eta))**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)])

from sympy.diffgeom import metric_to_Riemann_components
metric_to_Riemann_components(metric_diff_form)

产生结果

((((0, 0, 0), (0, 0, 0), (0, 0, 0)),
  ((0, 0, 0), (0, 0, 0), (0, 0, 0)),
  ((0, 0, 0), (0, 0, 0), (0, 0, 0))),
 (((0, 0, 0), (0, 0, 0), (0, 0, 0)),
  ((0, 0, 0), (0, 0, 0), (0, 0, 0)),
  ((0, 0, 0), (0, 0, 0), (0, 0, 0))),
 (((0, 0, 0), (0, 0, 0), (0, 0, 0)),
  ((0, 0, 0), (0, 0, 0), (0, 0, 0)),
  ((0, 0, 0), (0, 0, 0), (0, 0, 0))))

对于给定的度量 g,结果不正确。结果应该是不平凡的。

【问题讨论】:

  • 我设法在指标中发现了一个错误。 g_22 组件是错误的。解决这个问题,并遵循下面的建议,我仍然得到上述微不足道的结果。
  • 指标应该如下:g = sym.Matrix([[a**2/(cos(theta) - cosh(eta))**2, 0, 0], [0, a**2/(cos(theta) - cosh(eta))**2, 0], [0, 0, a**2*sinh(eta)**2/(cos(theta) - cosh(eta))**2]])。这是脚本的更正版本:paste.ofcode.org/BhhgvEHGePrRHW57HHGGGX

标签: python sympy


【解决方案1】:

你应该将eta、theta、phi声明为坐标函数,即:

eta, theta, phi = toroidal.coord_functions()

坐标函数是在diffgeom模块中使用的标量变量。 此外,我建议在声明坐标系时声明坐标函数字符串:

toroidal = CoordSystem("toroidal", patch, ["eta", "theta", "psi"])

黎曼分量的推导是通过对坐标函数的推导获得的,坐标函数是它们自己类型的变量(即它们不是实例符号)。任何 Symbol 实例,即使与 坐标函数 具有相同的名称,在派生时都被认为是不同的和恒定的。因此结果为零。

用这些变量重新声明你的矩阵,它应该可以解决。

【讨论】:

  • 我现在得到了不平凡的结果!我还注意到,如果使用 sympy.abc eta、theta、psi 预定义度量标准,则结果再次变得微不足道。我必须使用定义为 'sympy.diffgeom.diffgeom.BaseScalarField' 对象的这些变量。
  • toroidal.connect_to() 函数调用导致异常 AttributeError: 'BaseScalarField' object has no attribute 'as_dummy'。
  • 我认为你需要在 connect_to() 中使用符号,而不是 BaseScalarField。
  • 在曲率张量的条目上简化和 trigsimp 似乎也存在问题。 AttributeError:“int”对象没有属性“is_Rational”。我设法通过将每个条目转换为字符串然后对字符串表达式执行简化来解决这个问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多