differential_geometry.symbolic.compute_laplacian#
- differential_geometry.symbolic.compute_laplacian(scalar_field: Basic, coordinate_axes: Sequence[Symbol], inverse_metric: MutableDenseMatrix, l_term: ImmutableDenseMatrix | MutableDenseMatrix | ImmutableDenseNDimArray | MutableDenseNDimArray | None = None, metric_density: Basic | None = None) Basic [source]#
Compute the Laplacian \(\nabla^2 \phi\) of a scalar field in general or orthogonal curvilinear coordinates.
In a general coordinate system, the Laplacian of a scalar field \(\phi\) can be expressed as:
\[\nabla^2 \phi = \frac{1}{\rho} \,\partial_\mu \bigl(\rho \,g^{\mu\nu}\,\partial_\nu \phi\bigr) = L^\nu \,\partial_\nu \phi \;+\; g^{\mu\nu}\,\partial^2_{\mu\nu}\phi,\]where \(\rho\) is the metric density \(\sqrt{\det g}\) and \(g^{\mu\nu}\) is the inverse metric. The L-term is defined by:
\[L^\nu = \frac{1}{\rho} \,\partial_\mu \bigl(\rho \,g^{\mu\nu}\bigr).\]Usage:
If
inverse_metric
is a full \((n \times n)\) matrix, a fully general coordinate system is assumed.If
inverse_metric
is a 1D array of length \(n\), an orthogonal system is assumed (the array contains the diagonal elements \(g^{\mu\mu}\)).
- Parameters:
scalar_field (
Basic
) – The scalar field \(\phi\) whose Laplacian is computed.coordinate_axes (
list
ofSymbol
) – The coordinate variables \(x^\mu\) with respect to which differentiation occurs.inverse_metric (
MutableDenseMatrix
orMutableDenseNDimArray
) – Either a full inverse metric \(g^{\mu\nu}\) (shape(n, n)
) or a 1D diagonal array of shape(n,)
for orthogonal coordinates.l_term (
MutableDenseNDimArray
, optional) – Precomputed L-terms \(L^\nu\). If not provided, these will be derived frommetric_density
andinverse_metric
.metric_density (
Basic
, optional) – The metric density \(\rho = \sqrt{\det g}\). Required ifl_term
is not given.
- Returns:
The scalar Laplacian \(\nabla^2 \phi\).
- Return type:
See also
compute_Lterm
Compute the L-term from \(\rho\) and \(g^{\mu\nu}\).
compute_metric_density
For computing \(\rho\).
compute_divergence
The divergence in curvilinear coordinates.
Examples
1) Full Inverse Metric (Spherical)
>>> import sympy as sp >>> from pymetric.differential_geometry.symbolic import compute_laplacian, compute_metric_density >>> >>> r, theta, phi = sp.symbols('r theta phi') >>> scalar = r**2 * sp.sin(theta) >>> >>> # Full inverse metric for spherical coordinates >>> g_inv = sp.Matrix([ ... [1, 0, 0], ... [0, 1/r**2, 0], ... [0, 0, 1/(r**2 * sp.sin(theta)**2)] ... ]) >>> # Metric density >>> rho = compute_metric_density(sp.Matrix([ ... [1, 0, 0], ... [0, r**2, 0], ... [0, 0, (r*sp.sin(theta))**2] ... ])) >>> >>> # Compute Laplacian >>> lap = compute_laplacian(scalar, [r, theta, phi], g_inv, metric_density=rho) >>> lap 4*sin(theta) + 1/sin(theta)
2) Orthogonal Inverse Metric (Diagonal Only)
>>> # Provide just the diagonal of g^{\mu\nu} for an orthogonal system >>> g_inv_diag = sp.Array([1, 1/r**2, 1/(r**2*sp.sin(theta)**2)]) >>> # Same metric_density as above >>> lap_ortho = compute_laplacian(scalar, [r, theta, phi], g_inv_diag, metric_density=rho) >>> lap_ortho 4*sin(theta) + 1/sin(theta)