compute_metric()#
- CurvCoords.compute_metric(v1: ndarray[Any, dtype[float64]], v2: ndarray[Any, dtype[float64]]) ndarray[Any, dtype[float64]]Source#
Compute metric tensor.
The metric tensor \(g_{ij}\) or \(g^{ij}\) is calculated with inner product of covariant or contravariant bases:
\[\begin{split}\begin{aligned} g_{ij} &= \mathbf{b}_i \cdot \mathbf{b}_j \\ g^{ij} &= \mathbf{b}^i \cdot \mathbf{b}^j \end{aligned}\end{split}\]where \(\mathbf{b}^i\) is the contravariant basis of \(i\)-th coordinate, and \(\mathbf{b}_j\) is the covariant basis of \(j\)-th coordinate.
- Parameters:
- v1array_like
\(i\)-th co/contra-variant basis.
- v2array_like
\(j\)-th co/contra-variant basis.
- Returns:
- array_like
Metric tensor \(g_{ij}\) or \(g^{ij}\).
Examples
>>> import numpy as np >>> from cherab.lhd.emc3 import CenterGrid
>>> grid = CenterGrid("zone0", index_type="coarse") >>> coords = CurvCoords(grid)
Let compute the metric temsor: \(\mathbf{b}_\rho \cdot \mathbf{b}^\rho\). It should be an array of ones.
>>> g1 = coords.compute_metric(coords.b_rho, coords.b_sup_rho) >>> g1.shape (33, 100, 9) >>> np.allclose(g1, np.ones_like(g1)) True
Let check if the metric tensor: \(\mathbf{b}_\rho\cdot\mathbf{b}_\rho\) is not the same as the before.
>>> g2 = coords.compute_metric(coords.b_rho, coords.b_rho) >>> np.allclose(g1, g2) False >>> g2[0, 0, 0]