Tensor Module

This module contains Tensor class which serves as the base class for more specific Tensors in General Relativity:

einsteinpy.symbolic.tensor.tensor_product(tensor1, tensor2, i=None, j=None)[source]

Tensor Product of tensor1 and tensor2

Parameters:
  • tensor1 (BaseRelativityTensor) –

  • tensor2 (BaseRelativityTensor) –

  • i (int, optional) – contract i``th index of ``tensor1

  • j (int, optional) – contract j``th index of ``tensor2

Returns:

tensor of appropriate rank

Return type:

BaseRelativityTensor

Raises:

ValueError – Raised when i and j both indicate ‘u’ or ‘l’ indices

class einsteinpy.symbolic.tensor.Tensor(arr, config='ll', name=None)[source]

Bases: object

Base Class for Tensor manipulation

Constructor and Initializer

Parameters:
  • arr (ImmutableDenseNDimArray or list) – Sympy Array, multi-dimensional list containing Sympy Expressions, or Sympy Expressions or int or float scalar

  • config (str) – Configuration of contravariant and covariant indices in tensor. ‘u’ for upper and ‘l’ for lower indices. Defaults to ‘ll’.

  • name (str or None) – Name of the tensor.

Raises:
  • TypeError – Raised when arr is not a list or sympy array

  • TypeError – Raised when config is not of type str or contains characters other than ‘l’ or ‘u’

  • ValueError – Raised when config implies order of Tensor different than that indicated by shape of arr

property order

Returns the order of the Tensor

property config

Returns the configuration of covariant and contravariant indices

tensor()[source]

Returns the sympy Array

Returns:

Sympy Array object

Return type:

ImmutableDenseNDimArray

subs(*args)[source]

Substitute the variables/expressions in a Tensor with other sympy variables/expressions.

Parameters:

args (one argument or two argument) –

  • two arguments, e.g foo.subs(old, new)

  • one iterable argument, e.g foo.subs([(old1, new1), (old2, new2)]) for multiple substitutions at once.

Returns:

Tensor with substituted values

Return type:

Tensor

simplify(set_self=True)[source]

Returns a simplified Tensor

Parameters:

set_self (bool) – Replaces the tensor contained the class with its simplified version, if True. Defaults to True.

Returns:

Simplified Tensor

Return type:

Tensor

class einsteinpy.symbolic.tensor.BaseRelativityTensor(arr, syms, config='ll', parent_metric=None, variables=[], functions=[], name='GenericTensor')[source]

Bases: Tensor

Generic class for defining tensors in General Relativity. This would act as a base class for other Tensorial quantities in GR.

arr

Raw Tensor in sympy array

Type:

ImmutableDenseNDimArray

syms

List of symbols denoting space and time axis

Type:

list or tuple

dims

dimension of the space-time.

Type:

int

variables

free variables in the tensor expression other than the variables describing space-time axis.

Type:

list

functions

Undefined functions in the tensor expression.

Type:

list

name

Name of the tensor. Defaults to “GenericTensor”.

Type:

str or None

Constructor and Initializer

Parameters:
  • arr (ImmutableDenseNDimArray or list) – Sympy Array or multi-dimensional list containing Sympy Expressions

  • syms (tuple or list) – List of crucial symbols dentoting time-axis and/or spacial axis. For example, in case of 4D space-time, the arrangement would look like [t, x1, x2, x3].

  • config (str) – Configuration of contravariant and covariant indices in tensor. ‘u’ for upper and ‘l’ for lower indices. Defaults to ‘ll’.

  • parent_metric (MetricTensor or None) – Metric Tensor for some particular space-time which is associated with this Tensor.

  • variables (tuple or list or set) – List of symbols used in expressing the tensor, other than symbols associated with denoting the space-time axis. Calculates in real-time if left blank.

  • functions (tuple or list or set) – List of symbolic functions used in epressing the tensor. Calculates in real-time if left blank.

  • name (str or None) – Name of the Tensor. Defaults to “GenericTensor”.

Raises:
  • TypeError – Raised when arr is not a list, sympy array or numpy array.

  • TypeError – Raised when config is not of type str or contains characters other than ‘l’ or ‘u’

  • TypeError – Raised when arguments syms, variables, functions have data type other than list, tuple or set.

  • TypeError – Raised when argument parent_metric does not belong to MetricTensor class and isn’t None.

  • ValueError – Raised when argument syms does not agree with shape of argument arr

property parent_metric

Returns the Metric from which Tensor was derived/associated, if available.

symbols()[source]

Returns the symbols used for defining the time & spacial axis

Returns:

tuple containing (t,x1,x2,x3) in case of 4D space-time

Return type:

tuple

tensor_lambdify(*args)[source]

Returns lambdified function of symbolic tensors. This means that the returned functions can accept numerical values and return numerical quantities.

Parameters:

*args – The variable number of arguments accept sympy symbols. The returned function accepts arguments in same order as initially defined in *args. Uses sympy symbols from class attributes syms and variables (in the same order) if no *args is passed Leaving *args empty is recommended.

Returns:

  • tuple – arguments to be passed in the returned function in exact order.

  • function – Lambdified function which accepts and returns numerical quantities.

lorentz_transform(transformation_matrix)[source]

Performs a Lorentz transform on the tensor.

Parameters:

transformation_matrix (ImmutableDenseNDimArray or list) – Sympy Array or multi-dimensional list containing Sympy Expressions

Returns:

lorentz transformed tensor(or vector)

Return type:

BaseRelativityTensor