forked from poliastro/poliastro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Refactor propagators into classes
Fix poliastrogh-921. Still missing proper sampling support and incompatibilities with cowell.
- Loading branch information
1 parent
b2d6e11
commit b3be7d1
Showing
20 changed files
with
651 additions
and
674 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import numpy as np | ||
from numba import njit as jit | ||
|
||
|
||
@jit | ||
def func_twobody(t0, u_, k): | ||
"""Differential equation for the initial value two body problem. | ||
Parameters | ||
---------- | ||
t0 : float | ||
Time. | ||
u_ : numpy.ndarray | ||
Six component state vector [x, y, z, vx, vy, vz] (km, km/s). | ||
k : float | ||
Standard gravitational parameter. | ||
""" | ||
x, y, z, vx, vy, vz = u_ | ||
r3 = (x**2 + y**2 + z**2) ** 1.5 | ||
|
||
du = np.array([vx, vy, vz, -k * x / r3, -k * y / r3, -k * z / r3]) | ||
return du |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import numpy as np | ||
|
||
from poliastro._math.ivp import DOP853, solve_ivp | ||
from poliastro.core.propagation.base import func_twobody | ||
|
||
|
||
def cowell(k, r, v, tofs, rtol=1e-11, *, events=None, f=func_twobody): | ||
x, y, z = r | ||
vx, vy, vz = v | ||
|
||
u0 = np.array([x, y, z, vx, vy, vz]) | ||
|
||
result = solve_ivp( | ||
f, | ||
(0, max(tofs)), | ||
u0, | ||
args=(k,), | ||
rtol=rtol, | ||
atol=1e-12, | ||
method=DOP853, | ||
dense_output=True, | ||
events=events, | ||
) | ||
if not result.success: | ||
raise RuntimeError("Integration failed") | ||
|
||
if events is not None: | ||
# Collect only the terminal events | ||
terminal_events = [event for event in events if event.terminal] | ||
|
||
# If there are no terminal events, then the last time of integration is the | ||
# greatest one from the original array of propagation times | ||
if not terminal_events: | ||
last_t = max(tofs) | ||
else: | ||
# Filter the event which triggered first | ||
last_t = min(event.last_t for event in terminal_events) | ||
tofs = [tof for tof in tofs if tof < last_t] + [last_t] | ||
|
||
rrs = [] | ||
vvs = [] | ||
for i in range(len(tofs)): | ||
t = tofs[i] | ||
y = result.sol(t) | ||
rrs.append(y[:3]) | ||
vvs.append(y[3:]) | ||
|
||
return rrs, vvs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.