1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//! N-body integrators for solar-system dynamics.
//!
//! This module provides perturbed, multi-body orbit propagation on top of
//! starfield's two-body machinery:
//!
//! - [`whm`] — symplectic Wisdom-Holman mapping in democratic-heliocentric
//! coordinates (Wisdom & Holman 1991; Duncan, Levison & Lee 1998), with
//! bounded energy error over arbitrarily long integrations.
//! - [`bulirsch_stoer`] — Bulirsch-Stoer with recursive step-size control,
//! for high-accuracy work and close encounters.
//! - [`hybrid`] — Mercury6-style hybrid switching (Chambers 1999): WHM far
//! from planets, Bulirsch-Stoer through encounters, with the smooth
//! changeover K(r) partitioning the planet force so nothing is
//! double-counted.
//! - [`kepler`] — the universal-variable Kepler drift shared by all of the
//! above (bisection-safeguarded Newton, robust for elliptic, parabolic,
//! and hyperbolic states).
//! - [`forces`] — composable extra accelerations applied in the kick stage
//! (orbit-averaged giant-planet quadrupole, galactic disk tide, custom
//! closures).
//! - [`types`] — state vectors, orbital elements, massive bodies, and the
//! bridges to starfield's `planetlib` (ephemeris initial conditions) and
//! `keplerlib` (test particles from `KeplerOrbit`).
//! - [`democratic`] — heliocentric/barycentric coordinate transforms used by
//! the WHM splitting.
//!
//! # Units and frame
//!
//! Everything in this module uses **AU** for length, **days** for time, and
//! **AU³/day²** for gravitational parameters (GM). State vectors are
//! heliocentric ecliptic-J2000 Cartesian coordinates, matching
//! `positions::ecliptic::EclipticStateVector`.
//!
//! # Example
//!
//! ```
//! use nalgebra::Vector3;
//! use starfield::nbodylib::{MassiveBody, SimConfig, StateVector, WhmIntegrator, GM_SUN};
//!
//! // A Jupiter-mass planet on a circular 5.2 AU orbit.
//! let gm = 1e-3 * GM_SUN;
//! let v = (GM_SUN / 5.2_f64).sqrt();
//! let mut bodies = vec![MassiveBody::new(
//! "Jupiter",
//! gm,
//! StateVector::new(Vector3::new(5.2, 0.0, 0.0), Vector3::new(0.0, v, 0.0)),
//! )];
//! let mut particles: Vec<StateVector> = Vec::new();
//! let mut active: Vec<bool> = Vec::new();
//!
//! let config = SimConfig::default();
//! let integrator = WhmIntegrator::new();
//! for _ in 0..100 {
//! integrator.step(&mut bodies, &mut particles, &mut active, 100.0, &config);
//! }
//!
//! // Still on a circular orbit after ~27 years.
//! assert!((bodies[0].state.distance() - 5.2).abs() < 0.01);
//! ```
pub use ;
pub use ;
pub use ;
pub use kepler_drift;
pub use ;
pub use ;
/// Heliocentric gravitational parameter in AU³/day².
///
/// JPL DE440 (Park et al. 2021): GM☉ = 1.32712440041279419e20 m³/s².
/// Note this differs from `crate::constants::GM_SUN` (km³/s², Pitjeva 2005,
/// 1.32712440042e20 m³/s²) by ~5.4e-12 relative — beyond every tolerance in
/// this module, but pinned by a test below so the two can never silently
/// diverge. The crate-level constant is left untouched.
pub const GM_SUN: f64 = 2.959122082855911e-4;
/// Giant-planet *system* gravitational parameters in AU³/day² (planet plus
/// satellites, JPL DE440). These pair with the planet-system *barycenter*
/// states that `planetlib` resolves for the outer planets, so barycenter
/// states and system masses describe the same dynamical body.
pub const GM_JUPITER: f64 = 2.825_345_818e-7;
/// Saturn system GM in AU³/day² (DE440).
pub const GM_SATURN: f64 = 8.459_715_6e-8;
/// Uranus system GM in AU³/day² (DE440).
pub const GM_URANUS: f64 = 1.292_024_9e-8;
/// Neptune system GM in AU³/day² (DE440).
pub const GM_NEPTUNE: f64 = 1.524_358_9e-8;
/// Giant-planet system masses as a fraction of the solar mass (DE440).
pub const MASS_JUPITER_SOLAR: f64 = 9.547_919_384e-4;
/// Saturn system mass in solar masses (DE440).
pub const MASS_SATURN_SOLAR: f64 = 2.858_859_81e-4;
/// Uranus system mass in solar masses (DE440).
pub const MASS_URANUS_SOLAR: f64 = 4.366_244_0e-5;
/// Neptune system mass in solar masses (DE440).
pub const MASS_NEPTUNE_SOLAR: f64 = 5.151_389_0e-5;