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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//! # nyx-space
//!
//! [Nyx](https://en.wikipedia.org/wiki/Nyx) is a high fidelity, fast, reliable and validated astrodynamical toolkit library written in Rust.
//! It will _eventually_ provide most functionality in Python for rapid prototyping.
//!
//! The target audience is researchers and astrodynamics engineers. The rationale for using Rust is to allow for very fast computations, guaranteed thread safety,
//! and portability to all platforms supported by [Rust](https://forge.rust-lang.org/platform-support.html).
//!
//! To some extend, the ultimate goal of this library is to retire [SPICE Toolkit](https://naif.jpl.nasa.gov/naif/toolkit.html).
//!
//! NOTE: It is recommended to compile all code in `nyx` with the `--release` flag. A lot of heavy
//! computation is done in this library, and no one likes waiting for production code to run.
//! ## Features
//!
//!  * Propagators / Integrators of equations of motions (cf. the `propagators` module)
//!  * Two Body dynamics with planets defined as in GMAT / STK.
//!  * Angular momentum dynamics for a rigid body
//!  * Convenient and explicit definition of the dynamics for a simulation (cf. the [dynamics documentation](./dynamics/index.html))
//!  * Orbital state definition with transformations to other frames
//!
//! ## Usage
//!
//! Put this in your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! nyx-space = "0.0.8"
//! ```
//!
//! And add the following to your crate root:
//!
//! ```rust
//! extern crate nyx_space as nyx;
//! ```

/// Provides all the propagators / integrators available in `nyx`.
///
/// # Custom derivative function example
/// ```
/// extern crate nalgebra as na;
/// extern crate nyx_space as nyx;
/// use self::na::Vector6;
/// use nyx::celestia::Cosm;
/// use nyx::dynamics::celestial::TwoBody;
/// use nyx::dynamics::Dynamics;
/// use nyx::propagators::error_ctrl::RSSStepPV;
/// use nyx::propagators::*;
///
/// fn main() {
///     let cosm = Cosm::from_xb("./de438s");
///     let earth_geoid = cosm.geoid_from_id(3).unwrap();
///
///     let prop_time = 24.0 * 3_600.0;
///     let accuracy = 1e-12;
///     let min_step = 0.1;
///     let max_step = 60.0;
///
///     let init = Vector6::new(-2436.45, -2436.45, 6891.037, 5.088611, -5.088611, 0.0);
///
///     let rslt = Vector6::from_row_slice(&[
///         -5_971.194_376_784_884,
///         3_945.517_912_191_541,
///         2_864.620_958_267_658_4,
///         0.049_083_102_073_914_83,
///         -4.185_084_126_130_087_5,
///         5.848_947_462_252_259_5,
///     ]);
///
///     let mut dyn = TwoBody::from_state_vec(init, earth_geoid);
///     let mut prop = Propagator::new::<RK89>(
///         &mut dyn,
///         &PropOpts::with_adaptive_step(min_step, max_step, accuracy, RSSStepPV {}),
///     );
///     prop.until_time_elapsed(prop_time);
///     assert_eq!(prop.state(), rslt, "two body prop failed");
/// }
/// ```
pub mod propagators;

/// Provides several dynamics used for orbital mechanics and attitude dynamics, which can be elegantly combined.
///
/// # Simple two body propagation
/// ```
/// extern crate nalgebra as na;
/// extern crate hifitime;
/// extern crate nyx_space as nyx;
/// use hifitime::julian::ModifiedJulian;
/// use hifitime::SECONDS_PER_DAY;
/// use nyx::celestia::{Cosm, Geoid, State};
/// use nyx::dynamics::celestial::TwoBody;
/// use nyx::dynamics::Dynamics;
/// use nyx::propagators::error_ctrl::RSSStepPV;
/// use nyx::propagators::{PropOpts, Propagator, RK89};
///
/// fn main() {
///     let cosm = Cosm::from_xb("./de438s");
///     let earth_geoid = cosm.geoid_from_id(3).unwrap();
///
///     let dt = ModifiedJulian { days: 21545.0 };
///     let initial_state = State::<Geoid>::from_cartesian(-2436.45, -2436.45, 6891.037, 5.088611, -5.088611, 0.0, dt, earth_geoid);
///
///     println!("Initial state:\n{0}\n{0:o}\n", initial_state);
///
///     let prop_time = 24.0 * 3_600.0;
///     let accuracy = 1e-12;
///     let min_step = 0.1;
///     let max_step = 60.0;
///
///     let rslt = State::<Geoid>::from_cartesian(
///             -5_971.194_376_784_884,
///             3_945.517_912_191_541,
///             2_864.620_958_267_658_4,
///             0.049_083_102_073_914_83,
///             -4.185_084_126_130_087_5,
///             5.848_947_462_252_259_5,
///             ModifiedJulian { days: 21546.0 },
///             earth_geoid,
///     );
///
///     let mut dyn = TwoBody::from_state_vec(initial_state.to_cartesian_vec(), earth_geoid);
///     let mut prop = Propagator::new::<RK89>(
///         &mut dyn,
///         &PropOpts::with_adaptive_step(min_step, max_step, accuracy, RSSStepPV {}),
///     );
///     let (final_t, final_state0) = prop.until_time_elapsed(prop_time);
///
///     let final_dt = ModifiedJulian {
///         days: dt.days + final_t / SECONDS_PER_DAY,
///     };
///     let final_state = State::from_cartesian_vec(&prop.state(), final_dt, earth_geoid);
///     assert_eq!(final_state, rslt, "two body prop failed");
///     assert_eq!(prop.state(), final_state0, "until_time_elapsed returns the wrong value");
///
///     println!("Final state:\n{0}\n{0:o}", final_state);
/// }
/// ```
pub mod dynamics;

/// Provides the solar system planets, and state and (later) ephemeride management.
///
/// # State creation and management
/// ```
/// extern crate hifitime;
/// extern crate nyx_space as nyx;
///
/// fn main(){
///     use hifitime::julian::ModifiedJulian;
///     use nyx::celestia::{Cosm, Geoid, State};
///     let cosm = Cosm::from_xb("./de438s");
///     // In this case, we're creating these states around a Geoid which is Earth.
///     // But for simplicity, we're actually going to use the GMAT value for Earth GM (de438s has a slightly different value).
///     let mut earth_geoid = cosm.geoid_from_id(399).unwrap();
///     earth_geoid.gm = 398_600.441_5;
///     let dt = ModifiedJulian { days: 21545.0 };
///     let cart = State::<Geoid>::from_cartesian(
///             5_946.673_548_288_958,
///             1_656.154_606_023_661,
///             2_259.012_129_598_249,
///             -3.098_683_050_943_824,
///             4.579_534_132_135_011,
///             6.246_541_551_539_432,
///             dt,
///             earth_geoid,
///     );
///
///     let kep = State::<Geoid>::from_keplerian(
///            7_712.186_117_895_041,
///            0.158_999_999_999_999_95,
///            53.75369,
///            1.998_632_864_211_17e-5,
///            359.787_880_000_004,
///            25.434_003_407_751_188,
///            dt,
///            earth_geoid
///     );
///     // We can check whether two states are equal.
///     if cart != kep {
///         dbg!("{:?}", cart-kep);
///         panic!("This won't happen");
///     }
///     // Of more interest, we can fetch specific orbital elements.
///     println!("sma = {} km   inc = {} degrees", cart.sma(), cart.inc());
///     // Note that the state data is stored as X, Y, Z, VX, VY, VZ.
///     // Hence, the following print statement may display some rounded values despite
///     // being created with fixed values. GMAT has the same "issue"
///     // (but `nyx` won't change your script).
///     println!("ecc = {} km   RAAN = {} degrees", kep.ecc(), cart.raan());
/// }
/// ```
pub mod celestia;

/// Include utility functions shared by different modules, and which may be useful to engineers.
pub mod utils;

/// Provides all the input/output needs for this library, including loading of SPICE kernels, and gravity potential files.
pub mod io;

/// Provides all the orbital determination tools.
pub mod od;

#[macro_use]
extern crate log;
#[macro_use]
extern crate prost_derive;
extern crate hifitime;