Skip to main content

A tensor algebra calculator for General Relativity

Project description

pypi version Build status

A tensor algebra calculator for General Relativity.

Usage

RicciPy makes extensive usage of sympy for managing tensor products and contractions. To create a tensor, it is required to construct an array to represent the components of the tensor. This can be done by using most nested array types: a nested list, a sympy.Array instance, a sympy.Matrix instance, or a numpy array will work.

Before beginning any involved application, it is first necessary to define a Metric instance so that indices can be appropriately raised and lowered automatically.

In the following example, the electromagnetic tensor is defined in a Minkowski spacetime. To begin, we declare the components of the electromagnetic tensor using sympy for representing variables:

>>> from sympy import diag, symbols
>>> from riccipy import Tensor, Metric, indices, expand_array
>>> E1, E2, E3, B1, B2, B3 = symbols('E1:4 B1:4')
>>> em = [[0, -E1, -E2, -E3],
          [E1, 0, -B3, B2],
          [E2, B3, 0, -B1],
          [E3, -B2, B1, 0]]
>>> t, x, y, z = symbols('t x y z')

Next, the Minkowski metric is defined along with the Tensor object for the electromagnetic tensor. Here, the symmetry keyword is optional but is used to declare the electromagnetic tensor as being antisymmetric (refer to sympy’s documentation for the sympy.tensor.tensor module).

>>> eta = Metric('eta', [t, x, y, z], diag(1, -1, -1, -1))
>>> F = Tensor('F', em, eta, symmetry=[[2]])
>>> mu, nu = indices('mu nu', eta)

mu and nu are now variables that can be used to represent the indices of either the metric, eta, or the tensor F. Negative signs indicate that the particular index is a subscript (covariant) rather than a superscript (contravariant).

This first calculation demonstrates how contractions are handled: simply multiply two indexed tensors and matching indices will automatically apply the Einstein summation convention. Symbolically, indices that are to be contracted are denoted by the metric those indices belong to (in this case eta_0 and eta_1).

To convert a symbolic tensor expression into components, pass the expression to expand_array.

>>> expr = F(mu, nu) * F(-mu, -nu)
>>> expr
F(eta_0, eta_1)*F(-eta_0, -eta_1)
>>> expand_array(expr)
2*B_1**2 + 2*B_2**2 + 2*B_3**2 - 2*E_1**2 - 2*E_2**2 - 2*E_3**2

This next calculation demonstrates the consequence of having defined F as being antisymmetric:

>>> expr = F(mu, nu) + F(nu, mu)
>>> expand_array(expr)
0

Metrics Database

RicciPy comes with over 100 different metrics representing solutions to the Einstein Field Equations. To search for metrics, you can use the find function:

>>> from riccipy.metrics import find
>>> find('sitter')
['anti-de sitter', 'de sitter', 'schwarzschild-de sitter']

The load_metric function can be used to automatically return a Metric instance of the specified metric. For example, to load an Anti de-Sitter spacetime the call would look like:

>>> g, variables, functions = load_metric('g', 'anti-de sitter')
>>> g.as_array()
[[-1, 0, 0, 0],
[0, cos(t)**2, 0, 0],
[0, 0, cos(t)**2*sinh(chi)**2, 0],
[0, 0, 0, sin(theta)**2*cos(t)**2*sinh(chi)**2]]

Installation

To install RicciPy the following dependencies are required:

  • Sympy (version >= 1.4)

  • Numpy (version >= 1.15)

Installation is handled automatically by using

$ pip install riccipy

Contributing & Questions

RicciPy is in it’s early stages of development and thus contributions are very welcome, yet they will be handled on a person-to-person basis until sufficient interest accumulates in the project. Feel free to email the primary author at calvinjayross@gmail.com if you have any questions or interest in developing RicciPy.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

riccipy-0.3.1.tar.gz (32.3 kB view details)

Uploaded Source

File details

Details for the file riccipy-0.3.1.tar.gz.

File metadata

  • Download URL: riccipy-0.3.1.tar.gz
  • Upload date:
  • Size: 32.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.1.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

File hashes

Hashes for riccipy-0.3.1.tar.gz
Algorithm Hash digest
SHA256 3cf146c54a6b02eb5dc79841a23f46eec2934243e8e87c7af1d54e756e6f0cfa
MD5 3d2085713b5177cac1e5850440410e2d
BLAKE2b-256 bcaf27a90d086b1b374e6efd5439617a5ad6d090dec7700484c17167c89307c4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page