收起
项目描述
广义相对论符号工具
Py Stein包包含用于计算广义相对论中出现的一些量的符号工具。目前,此包基本上是一个sympy
扩展,可以直接计算张量分量。
符号工具
Py Stein包使用sympy
来计算符号曲率方程(EFE)。
示例计算:FLRW宇宙学
# Load the predefined FLRW metric
from pystein import metric, gravity
from pystein import utilities
flrw = metric.flrw().subs({'c': 1})
flrw
efe_00 = utilities.full_simplify(gravity.einstein_equation(0, 0, flrw))
efe_00
# Can simplify notation using "dots"
metric.simplify_deriv_notation(efe_00, flrw, use_dots=True)
符号工具
坐标系
from sympy.diffgeom import Manifold, Patch
from pystein import coords
# The pystein CoordinateSystem extends the sympy.diffgeom api to make parameters more accessible
M = Manifold('M', dim=2)
P = Patch('origin', M)
cs = coords.CoordSystem('cartesian', P, ['x', 'y'])
cs
# In sympy it is difficult to access underlying parameters, but the new base_symbols function makes it easy:
cs.base_symbols()
度规
# Assembling a metric is easy
from sympy import Array, symbols
from pystein import metric
from pystein.utilities import tensor_pow as tpow
# Metrics can be created either from a (Matrix, Coords) combo or from a TwoForm Expression
# Let's create a metric from a twoform expression, using the basis of oneforms from the coordinate system
a, b = symbols('a b') # some constants to use in the metric
dx, dy = cs.base_oneforms()
form = a ** 2 * tpow(dx, 2) + b ** 2 * tpow(dy, 2)
g1 = metric.Metric(twoform=form) # Note: don't have to specify coords since implied by basis of one-forms
# Notice that the Metric class will represent itself as a twoform
g1
# Now let's create the same metric from a matrix
# First let's create a Matrix
matrix = Array([[a ** 2, 0], [0, b ** 2]])
matrix
# Creating a Metric from a matrix also requires you to specify the coordinate system (so the axes can be labeled)
g2 = metric.Metric(matrix=matrix, coord_system=cs)
# Note that the Metric class automatically computes the two-form and uses it for representation
g2
# Metrics can be inverted, and produce other metrics
g3 = g2.inverse
g3
曲率
# Now let's compute curvature terms
from sympy import Function
from pystein import curvature
# Let's create a metric with some curvature..
x, y = cs.base_symbols() # grab the coordinate parameters
F = Function('F')(x, y) # Define an arbitrary function that depends on x and y
g4 = metric.Metric(twoform=F ** 2 * tpow(dx, 2) + b ** 2 * tpow(dy, 2))
curvature.ricci_tensor_component(0, 0, g4).doit()
物质
# Let's compute the matter stress energy tensor of a perfect fluid in 1D
from pystein import matter
# Need to quickly redefine the coordinates to have a temporal coordinate
t, x, y = symbols('t x y')
M = Manifold('M', dim=3)
P = Patch('origin', M)
cs = coords.CoordSystem('OneDim', P, [t, x, y])
dt, dx, dy = cs.base_oneforms()
Q = Function('Q')(t, y) # Define an arbitrary function that depends on x and y
S = Function('S')(t, x) # Define an arbitrary function that depends on x and y
g5 = metric.Metric(twoform=- Q ** 2 * tpow(dt, 2) + b ** 2 * tpow(dx, 2) + S ** 2 * tpow(dy, 2), components=(Q, S, b))
g5
# Now use the matter module to create the stress energy tensor for perfect fluid
T = matter.perfect_fluid(g5)
T
utilities.clean_expr(curvature.einstein_tensor_component(0, 0, g5))
# Note that in the limit Q -> 1
g5_lim = g5.subs({Q: 1})
T_lim = matter.perfect_fluid(g5_lim)
T_lim
utilities.clean_expr(curvature.einstein_tensor_component(0, 0, g5_lim))
引力
# One can also directly compute the Einstein Equations
from pystein import gravity
utilities.clean_expr(gravity.einstein_equation(0, 0, g5, T))
# Similarly in the limit:
utilities.clean_expr(gravity.einstein_equation(0, 0, g5_lim, T_lim))
完整示例:FLRW宇宙学
# Load the predefined FLRW metric
flrw = metric.flrw(cartesian=True)
flrw
T = matter.perfect_fluid(flrw)
efe_00 = utilities.clean_expr(gravity.einstein_equation(0, 0, flrw, T).doit())
efe_00
# Simplify derivative notation:
metric.simplify_deriv_notation(efe_00, flrw)
# Can also use "dots"
metric.simplify_deriv_notation(efe_00, flrw, use_dots=True)
数值工具
Py Stein包包含一些有限的数值工具,包括
- 数值积分测地线方程的能力
geodesic.numerical_geodesic
- 方便的函数来计算从各种初始条件(2D)得到的多个测地线
这些工具与符号工具兼容,归功于sympy.lambdify
,它用于将符号方程转换为数值方程。
*请注意,Py Stein中的数值工具仍在测试版。
测地线使用示例
从二形式构造度规
M = Manifold('M', dim=2)
P = Patch('origin', M)
rho, phi, a = sympy.symbols('rho phi a', nonnegative=True)
cs = coords.CoordSystem('schw', P, [rho, phi])
drho, dphi = cs.base_oneforms()
ds2 = a ** 2 * ((1 / (1 - rho ** 2)) * tpow(drho, 2) + rho ** 2 * tpow(dphi, 2))
g = metric.Metric(twoform=ds2)
g
计算符号测地线方程
full_simplify(geodesic.geodesic_equation(0, sympy.symbols('lambda'), g))
数值积分测地线方程
init = (numpy.sin(numpy.pi / 4), 0.0, numpy.cos(numpy.pi / 4), numpy.pi / 4)
lambdas = numpy.arange(0, 2.1, 0.001)
df = geodesic.numerical_geodesic(g, init, lambdas)
df.head()
rho | phi | |
---|---|---|
0 | 0.707107 | 0.000000 |
1 | 0.707814 | 0.000785 |
2 | 0.708520 | 0.001568 |
3 | 0.709226 | 0.002349 |
4 | 0.709931 | 0.003129 |
项目详情
下载文件
下载适用于您平台文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源分布
pystein-0.5.3.tar.gz (26.4 kB 查看散列值)
构建分发
pystein-0.5.3-py3-none-any.whl (28.9 kB 查看哈希值)
关闭
pystein-0.5.3.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | d33d7ad8f061d72ab09b91d2b19cad09e85c462cdb9667466fb989d215abfb6d |
|
MD5 | cc70197ccfe17f5ba8c1c1baa63c3951 |
|
BLAKE2b-256 | a48994b805990856bf613cb9febdbf7245074945cab9f1e6ced903ab1b9c4382 |
关闭
pystein-0.5.3-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 0b72f78ea13137ce89102abaa69a8b1c842e56ed1450135afb25de5d979ab3cd |
|
MD5 | 887078077e1625f329c10f60871463b7 |
|
BLAKE2b-256 | 56d61bc07ce54cfba78c7bd1c9e34923881729d7df970b3a147dc94a06a7440d |