coordinates.mixins.mathops.CoordinateSystemMathMixin.adjust_dense_tensor_signature#

CoordinateSystemMathMixin.adjust_dense_tensor_signature(tensor_field: ndarray, indices: Sequence[int], tensor_signature: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], *coordinates: ndarray, metric_field: ndarray | None = None, inverse_metric_field: ndarray | None = None, fixed_axes: Dict[str, float] | None = None, out: ndarray | None = None, **kwargs) ndarray[source]#

Raise and/or lower multiple tensor slots in one call.

Each entry of tensor_signature must be +1 (contravariant) or -1 (covariant). Slots listed in indices will be flipped (+1 -1) using the metric

\[g_{ab},\; g^{ab}\]

evaluated on the supplied coordinate grid.

Parameters:
  • tensor_field – Array with shape (F₁,…,F_m, I₁,…,I_rank) where the last rank axes hold the tensor indices.

  • indices – Positions (0 i < rank) of the slots to transform.

  • tensor_signature – Length-rank vector with the current variance of every slot.

  • rank – Number of tensor indices (== len(tensor_signature)).

  • *coordinates – ND broadcasted coordinate grids (canonical axis order). Only needed when a metric has to be computed.

  • metric_field – Pre-computed g_{ab} / g^{ab}. If omitted they are evaluated from coordinates.

  • inverse_metric_field – Pre-computed g_{ab} / g^{ab}. If omitted they are evaluated from coordinates.

  • fixed_axes – Constant axis values inserted when computing a metric.

  • out – Optional output buffer.

  • **kwargs – Passed straight through to dense_adjust_tensor_signature().

Returns:

tensor_field with the requested slots flipped.

Return type:

numpy.ndarray

Examples

Raise slot 0 and lower slot 1 of a rank-2 tensor in cylindrical coordinates:

>>> import numpy as np
>>> from pymetric.coordinates import CylindricalCoordinateSystem
>>>
>>> # Create the coordinate system.
>>> cs = CylindricalCoordinateSystem()
>>> r, z = np.linspace(1, 2, 4), np.linspace(-1, 1, 4)
>>> R, Z = np.meshgrid(r, z, indexing='ij')
>>>
>>> # contravariant/covariant signature: (+1, -1)
>>> T = np.zeros(R.shape + (3, 3))
>>> T[..., 0, 1] = 1        # only T^{ρ}{}_{z} non-zero
>>>
>>> # Create the tensor signature.
>>> sig = np.array([+1, -1])
>>> T_new, sig_new = cs.adjust_dense_tensor_signature(
...     T, [0, 1],sig, R, Z,
...     fixed_axes={'phi': 0.0}
... )
>>> T_new.shape   # unchanged grid-shape + (2,2)
(4, 4, 3, 3)