Skip to main content

RicciPy

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.

Metadata

Release files for riccipy 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for riccipy 0.3.1
File Size Uploaded
riccipy-0.3.1.tar.gz 32.3 kB Details

Release files / riccipy-0.3.1.tar.gz

Download URL riccipy-0.3.1.tar.gz
Size 32.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3cf146c54a6b02eb5dc79841a23f46eec2934243e8e87c7af1d54e756e6f0cfa
BLAKE2b-256 checksum
How to use checksums
bcaf27a90d086b1b374e6efd5439617a5ad6d090dec7700484c17167c89307c4
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.3.1 This release

1 release file

0.3.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page