Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tidal tensor #24

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/galdynamix/potential/_potential/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
)
from galdynamix.units import UnitSystem, dimensionless
from galdynamix.utils import partial_jit, vectorize_method
from galdynamix.utils._shape import batched_shape, expand_arr_dims, expand_batch_dims
from galdynamix.utils.dataclasses import ModuleMeta

if TYPE_CHECKING:
Expand Down Expand Up @@ -249,6 +250,40 @@ def acceleration(
"""
return -self.gradient(q, t)

@partial_jit()
def tidal_tensor(
self, q: BatchVec3, /, t: BatchableFloatOrIntScalarLike
) -> BatchMatrix33:
"""Compute the tidal tensor.

See https://en.wikipedia.org/wiki/Tidal_tensor

.. note::

This is in cartesian coordinates with the Euclidean metric tensor.
Also, this isn't correct for GR.

Parameters
----------
q : Array[float, (*batch, 3,)]
Position to compute the tidal tensor at.
t : Array[float | int, *batch] | float | int
Time at which to compute the tidal tensor.

Returns
-------
Array[float, (*batch, 3, 3)]
The tidal tensor.
"""
J = self.hessian(q, t) # (*batch, 3, 3)
batch_shape, arr_shape = batched_shape(J, expect_ndim=2) # (*batch), (3, 3)
traced = (
expand_batch_dims(xp.eye(3), ndim=len(batch_shape))
* expand_arr_dims(xp.trace(J, axis1=-2, axis2=-1), ndim=len(arr_shape))
/ 3
)
return J - traced

# =========================================================================
# Integrating orbits

Expand Down