Skip to content

Commit 97474e8

Browse files
committed
Convert calcC2C3 into calcStumpff (add in first 6 Stumpff equations as opposed)
1 parent 558ed15 commit 97474e8

3 files changed

Lines changed: 40 additions & 26 deletions

File tree

thor/orbits/iod/gauss.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from ...constants import Constants as c
55
from ...coordinates import equatorialToEclipticCartesian
66
from ...coordinates import equatorialAngularToCartesian
7-
from ..propagate import calcC2C3
7+
from ..propagate import calcStumpff
88
from ..propagate import calcChi
99
from .gibbs import calcGibbs
1010
from .herrick_gibbs import calcHerrickGibbs
@@ -104,7 +104,7 @@ def _iterateGaussIOD(orbit, t21, t32, q1, q2, q3, rho1hat, rho2hat, rho3hat, mu=
104104
chi2 = chi**2
105105

106106
psi = alpha * chi2
107-
c2, c3 = calcC2C3(psi)
107+
c0, c1, c2, c3, c4, c5 = calcStumpff(psi)
108108

109109
f = 1 - chi**2 / r_mag * c2
110110
g = dt - 1 / sqrt_mu * chi**3 * c3

thor/orbits/propagate/stumpff.py

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,31 @@
22
from numba import jit
33

44
__all__ = [
5-
"calcC2C3"
5+
"calcStumpff"
66
]
77

8-
@jit("UniTuple(f8, 2)(f8)", nopython=True)
9-
def calcC2C3(psi):
8+
@jit("UniTuple(f8, 6)(f8)", nopython=True)
9+
def calcStumpff(psi):
1010
"""
11-
Calculate the second and third Stumpff functions.
11+
Calculate the first 6 Stumpff functions for universal variable psi.
1212
1313
.. math::
14+
15+
c_0(\Psi) = \begin{cases}
16+
\cos{\sqrt{\Psi}} & \text{ if } \Psi > 0 \\
17+
\cosh{\sqrt{-\Psi}} & \text{ if } \Psi < 0 \\
18+
1 & \text{ if } \Psi= 0
19+
\end{cases}
1420
15-
c_2(\Psi) = \begin{cases}
16-
\frac{1 - \cos{\sqrt{\Psi}}}{\Psi} & \text{ if } \Psi > 0 \\
17-
\frac{1 - \cosh{\sqrt{-\Psi}}}{\Psi} & \text{ if } \Psi < 0 \\
18-
\frac{1}{2} & \text{ if } \Psi= 0
21+
c_1(\Psi) = \begin{cases}
22+
\frac{\sin{\sqrt{\Psi}}{\sqrt{\Psi}} & \text{ if } \Psi > 0 \\
23+
\frac{\sinh{\sqrt{-\Psi}}{\sqrt{-\Psi}} & \text{ if } \Psi < 0 \\
24+
1 & \text{ if } \Psi= 0
1925
\end{cases}
2026
21-
c_3(\Psi) = \begin{cases}
22-
\frac{\sqrt{\Psi} - \sin{\sqrt{\Psi}}}{\sqrt{\Psi^3}} & \text{ if } \Psi > 0 \\
23-
\frac{\sinh{\sqrt{-\Psi}} - \sqrt{-\Psi}}{\sqrt{(-\Psi)^3}} & \text{ if } \Psi < 0 \\
24-
\frac{1}{6} & \text{ if } \Psi= 0
25-
\end{cases}
27+
\Psi c_{n+2} = \frac{1}{k!} - c_n(\Psi)
2628
27-
For more details on theory see Chapter 2 in David A. Vallado's "Fundamentals of Astrodynamics
29+
For more details on the universal variable formalism see Chapter 2 in David A. Vallado's "Fundamentals of Astrodynamics
2830
and Applications" or Chapter 3 in Howard Curtis' "Orbital Mechanics for Engineering Students".
2931
3032
Parameters
@@ -34,17 +36,29 @@ def calcC2C3(psi):
3436
3537
Returns
3638
-------
37-
c2, c3 : float, float
38-
Second and third Stumpff functions.
39+
s0, s1, s2, s3, s4, s5 : 6 x float
40+
First six Stumpff functions.
3941
"""
4042
if psi > 0.0:
41-
c2 = (1 - np.cos(np.sqrt(psi))) / psi
42-
c3 = (np.sqrt(psi) - np.sin(np.sqrt(psi))) / np.sqrt(psi)**3
43+
c0 = np.cos(np.sqrt(psi))
44+
c1 = np.sin(np.sqrt(psi)) / np.sqrt(psi)
45+
c2 = (1. - c0) / psi
46+
c3 = (1. - c1) / psi
47+
c4 = (1/2. - c2) / psi
48+
c5 = (1/6. - c3) / psi
4349
elif psi < 0.0:
44-
c2 = (np.cosh(np.sqrt(-psi)) - 1) / (-psi)
45-
c3 = (np.sinh(np.sqrt(-psi)) - np.sqrt(-psi)) / np.sqrt(-psi)**3
50+
c0 = np.cosh(np.sqrt(-psi))
51+
c1 = np.sinh(np.sqrt(-psi)) / np.sqrt(-psi)
52+
c2 = (1. - c0) / psi
53+
c3 = (1. - c1) / psi
54+
c4 = (1/2. - c2) / psi
55+
c5 = (1/6. - c3) / psi
4656
else:
57+
c0 = 1.
58+
c1 = 1.
4759
c2 = 1/2.
4860
c3 = 1/6.
61+
c4 = 1/24.
62+
c5 = 1/120.
4963

50-
return c2, c3
64+
return c0, c1, c2, c3, c4, c5

thor/orbits/propagate/universal.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from numba import jit
33

44
from ...constants import Constants as c
5-
from .stumpff import calcC2C3
5+
from .stumpff import calcStumpff
66

77
__all__ = [
88
"calcChi",
@@ -54,7 +54,7 @@ def calcChi(orbit, dt, mu=MU, max_iter=10000, tol=1e-14):
5454
while np.abs(ratio) > tol:
5555
chi2 = chi**2
5656
psi = alpha * chi2
57-
c2, c3 = calcC2C3(psi)
57+
c0, c1, c2, c3, c4, c5 = calcStumpff(psi)
5858

5959
# Newton-Raphson
6060
f = (r_mag * rv_mag / sqrt_mu * chi2 * c2
@@ -121,7 +121,7 @@ def propagateUniversal(orbits, t0, t1, mu=MU, max_iter=10000, tol=1e-14):
121121

122122
alpha = -v_mag**2 / mu + 2 / r_mag
123123
psi = alpha * chi2
124-
c2, c3 = calcC2C3(psi)
124+
c0, c1, c2, c3, c4, c5 = calcStumpff(psi)
125125

126126
f = 1 - chi**2 / r_mag * c2
127127
g = dt - 1 / sqrt_mu * chi**3 * c3

0 commit comments

Comments
 (0)