Skip to content

Commit

Permalink
Angular momentum property (#29)
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <nstarman@users.noreply.github.com>
  • Loading branch information
nstarman committed Dec 9, 2023
1 parent f6410a0 commit 9e21df7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/galdynamix/dynamics/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def w(self) -> BatchVec7:
)
return xp.concatenate((q, p, t), axis=-1)

@property
@partial_jit()
def angular_momentum(self) -> BatchVec3:
r"""Compute the angular momentum.
Expand All @@ -138,9 +139,9 @@ def angular_momentum(self) -> BatchVec3:
>>> import astropy.units as u
>>> pos = np.array([1., 0, 0]) * u.au
>>> vel = np.array([0, 2*np.pi, 0]) * u.au/u.yr
>>> w = PhaseSpacePosition(pos, vel)
>>> w.angular_momentum() # doctest: +FLOAT_CMP
<Quantity [0. ,0. ,6.28318531] AU2 / yr>
>>> w = PhaseSpacePosition(pos, vel, t=0)
>>> w.angular_momentum
Array([0. , 0. , 6.28318531], dtype=float64)
"""
# TODO: when q, p are not Cartesian.
return xp.cross(self.q, self.p)
Expand Down

0 comments on commit 9e21df7

Please sign in to comment.