Tensor Module¶
-
class
riccipy.tensor.AbstractTensor¶ Bases:
objectWrapper class for sympy Array with attributes used for identification.
-
as_array()¶ Return the data stored in the tensor as an instance of sympy.Array.
-
as_inverse()¶ Return the data of the inversed array associated with the tensor.
-
as_matrix()¶ Return the data stored in the tensor as an instance of sympy.Matrix.
Notes
The
tomatrixattribute required by this method will throw an error if the tensor is not of rank 2.
-
-
class
riccipy.tensor.Index¶ Bases:
sympy.tensor.tensor.TensorIndexClass for a symbolic representation of a tensor index with respect to a metric.
-
class
riccipy.tensor.IndexedTensor¶ Bases:
riccipy.tensor.AbstractTensor,sympy.tensor.tensor.TensorClass representing a Tensor that has been evaluated with indices.
Used as the base object for creating algebraic expressions with tensors. Inherited are methods such as __mul__ to allow sympy to manage dummy indices when multiplied with other tensors.
Generated when a Tensor is called as a function with indices as arguments.
-
class
riccipy.tensor.Repl¶ Bases:
dictDictionary object used for managing the replacements of tensors to arrays.
-
class
riccipy.tensor.Tensor¶ Bases:
riccipy.tensor.AbstractTensor,sympy.tensor.tensor.TensorHeadClass for representing a Sympy TensorHead object that have an associated array of data elements/expressions to be substituted when requested.
-
covariance_transform(*indices)¶ Return the array associated with this tensor with indices set according to arguments.
Parameters: indices (TensorIndex) – Defines the covariance and contravariance of the returned array. Examples
>>> from sympy import Function, diag, exp, sin, symbols >>> from riccipy import Metric, indices >>> t, r, th, ph = symbols('t r theta phi') >>> al, be = symbols('alpha beta', cls=Function) >>> spherical = diag(-exp(2 * al(r)), exp(2 * be(r)), r ** 2, r ** 2 * sin(th) ** 2) >>> g = Metric('g', [t, r, th, ph], spherical) >>> mu, nu = indices('mu nu', g) >>> g.covariance_transform(mu, nu) [[-exp(-2*alpha(r)), 0, 0, 0], [0, exp(-2*beta(r)), 0, 0], [0, 0, r**(-2), 0], [0, 0, 0, 1/(r**2*sin(theta)**2)]]
-
simplify()¶ Replace the stored array associated with this tensor with a simplified version. This method also replaces the entry in the replacement dictionary.
-
subs(sub_dict)¶ Use a dictionary to replace symbols/variables in a tensor.
Parameters: sub_dict (dict) – Dictionary that maps symbols to expressions. Examples
>>> from sympy import Rational, diag, exp, sin, symbols >>> from riccipy import Metric, indices >>> t, r, th, ph, M = symbols('t r theta phi M', real=True) >>> schwarzschild = diag(1 - 2 * M/r, 1/(1 - 2 * M/r), r ** 2, r ** 2 * sin(th) ** 2) >>> g = Metric('g', [t, r, th, ph], schwarzschild) >>> g.subs({M: Rational(1, 2)}) >>> g.as_array() [[1 - 1/r, 0, 0, 0], [0, 1/(1 - 1/r), 0, 0], [0, 0, r**2, 0], [0, 0, 0, r**2*sin(theta)**2]]
-
-
riccipy.tensor.expand_array(expr, idxs=None)¶ Evaluate a tensor expression and return the result as an array.
Parameters: - expr (TensExpr) – Symbolic expression of tensors.
- idxs (TensorIndex) – Indices that encode the covariance and contravariance of the result.
-
riccipy.tensor.expand_tensor(symbol, expr, metric, idxs=None, **kwargs)¶ Evaluate a tensor expression and return the result as a tensor.
Parameters: - symbol (str) – Name of the tensor and the symbol to denote it by when printed.
- expr (TensExpr) – Symbolic expression of tensors.
- metric (Metric) – Classify the tensor as being defined in terms of a metric.
- idxs (TensorIndex) – Indices that encode the covariance and contravariance of the result.
-
riccipy.tensor.indices(s, metric, is_up=True)¶ Create indices using a method similar to sympy.symbols.