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

Add ability to pass custom metrics to geodesic code. #625

Merged
merged 1 commit into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
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
Add ability to pass custom metrics to geodesic code.
  • Loading branch information
a3ahmad committed Nov 14, 2022
commit b92e66fba522776a30ae59c91358607b409bce52
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ CHANGES
CONTRIBUTORS
- JeS24
- mshumayl
- a3ahmad

CHANGES
- [#607]: Fixed #586 #598 #599 #600 #601, Fixed a bug in tensor_lambdify
Expand All @@ -21,6 +22,7 @@ CHANGES
- [#612]: Partially addressed #610, Added support for setting plot aspect ratio and title via API
- [#619]: General codebase maintenance
- [#620]: Fixed #540, #541, Partially addressed #614, Updated documentation
- [#625]: Add ability to compute geodesics for arbitrary metrics

0.4.0
-----
Expand Down
17 changes: 11 additions & 6 deletions src/einsteinpy/geodesic/geodesic.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,18 @@ def __init__(
}

if metric not in _METRICS:
raise NotImplementedError(
f"'{metric}' is unsupported. Currently, these metrics are supported:\
\n1. Schwarzschild\n2. Kerr\n3. KerrNewman"
)
if not callable(metric):
raise NotImplementedError(
f"'{metric}' is unsupported. Currently, these metrics are supported:\
\n1. Schwarzschild\n2. Kerr\n3. KerrNewman\n4. Any user-supplied callable metric function"
)

self.metric_name = metric.__name__
JeS24 marked this conversation as resolved.
Show resolved Hide resolved
self.metric = metric
else:
self.metric_name = metric
self.metric = _METRICS[metric]

self.metric_name = metric
self.metric = _METRICS[metric]
self.metric_params = metric_params
if metric == "Schwarzschild":
self.metric_params = (0.0,)
Expand Down
25 changes: 25 additions & 0 deletions tests/test_geodesic/test_geodesic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from numpy.testing import assert_allclose

from einsteinpy.geodesic import Geodesic, Nulllike, Timelike
from einsteinpy.geodesic.utils import _kerr


@pytest.fixture()
Expand Down Expand Up @@ -169,3 +170,27 @@ def test_kerr0_eq_kn00():

assert_allclose(k.trajectory[0], kn.trajectory[0], atol=1e-6, rtol=1e-6)
assert_allclose(k.trajectory[1], kn.trajectory[1], atol=1e-6, rtol=1e-6)


def test_custom_callable_metric():
metric_params = (0.,)
q0 = [4., np.pi / 2, 0.]
p0 = [0., 0., 0.]

try:
c = Timelike(
metric=_kerr,
metric_params=metric_params,
position=q0,
momentum=p0,
steps=50,
delta=0.5,
return_cartesian=True,
suppress_warnings=True,
)
assert c.metric_name == _kerr.__name__
assert c.metric == _kerr

except:
assert False