[][src]Module nyx_space::dynamics

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::{Epoch, SECONDS_PER_DAY};
use nyx::celestia::{bodies, Cosm, Geoid, State};
use nyx::dynamics::celestial::CelestialDynamics;
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(bodies::EARTH);

    let dt = Epoch::from_mjd_tai(21_545.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_797_643,
            3_945.517_912_574_178_4,
            2_864.620_957_744_429_2,
            0.049_083_101_605_507_95,
            -4.185_084_125_817_658,
            5.848_947_462_472_877,
            Epoch::from_mjd_tai(21_546.0),
            earth_geoid,
    );

    let mut dynamics = CelestialDynamics::two_body(initial_state);
    let mut prop = Propagator::new::<RK89>(
        &mut dynamics,
        &PropOpts::with_adaptive_step(min_step, max_step, accuracy, RSSStepPV {}),
    );
    prop.until_time_elapsed(prop_time);

    assert_eq!(prop.dynamics.state, rslt, "two body prop failed");

    println!("Final state:\n{0}\n{0:o}", prop.dynamics.state);
}

Multibody propagation of a Halo orbit

Multibody propagation is an order of magnitude faster in nyx than in GMAT. In nyx, the following function is executed in 0.14 seconds in release mode.

extern crate nalgebra as na;
extern crate hifitime;
extern crate nyx_space as nyx;
fn main() {
    use hifitime::Epoch;
    use na::Vector6;
    use nyx::celestia::{bodies, Cosm, Geoid, State};
    use nyx::dynamics::celestial::CelestialDynamics;
    use nyx::propagators::*;
    use nyx::utils::rss_state_errors;

    let prop_time = 24.0 * 3_600.0;

    let cosm = Cosm::from_xb("./de438s");
    let earth_geoid = cosm.geoid_from_id(bodies::EARTH);

    let start_time = Epoch::from_gregorian_tai_at_midnight(2020, 1, 1);

    let halo_rcvr = State::<Geoid>::from_cartesian(
        333_321.004_516,
        -76_134.198_887,
        -20_873.831_939,
        0.257_153_712,
        0.930_284_066,
        0.346_177,
        start_time,
        earth_geoid,
    );

    // GMAT data
    let rslt = Vector6::new(
        345_350.664_030_479,
        5_930.672_047_088,
        7_333.283_779_286,
        2.129_819_943e-2,
        9.566_789_568e-1,
        3.028_175_811e-1,
    );

    let bodies = vec![bodies::EARTH_MOON, bodies::SUN, bodies::JUPITER_BARYCENTER];
    let mut dynamics = CelestialDynamics::new(halo_rcvr, bodies, &cosm);

    let mut prop = Propagator::new::<RK89>(&mut dynamics, &PropOpts::default());
    prop.until_time_elapsed(prop_time);
    let (err_r, err_v) = rss_state_errors(&prop.state_vector(), &rslt);

    println!(
        "RSS errors:\tpos = {:.5e} km\tvel = {:.5e} km/s\ninit\t{}\nfinal\t{}",
        err_r, err_v, halo_rcvr, prop.dynamics.state
    );
    assert!(err_r < 1e-3, format!("multi body failed in position: {:.5e}", err_r));
    assert!(err_v < 1e-6, format!("multi body failed in velocity: {:.5e}", err_v));
}

Modules

celestial

The celestial module handles all Cartesian based dynamics.

deltavctrl

Defines some velocity change controllers.

missionarc

Defines a MissionArc, i.e. a section of a spacecraft mission. Enables maneuvers design.

momentum

The gravity module handles spherical harmonics only. It must be combined with a CelestialDynamics dynamics

propulsion

Defines what a propulsion subsystem must implement, with some common propulsion systems.

spacecraft

The spacecraft module allows for simulation of spacecraft dynamics in general, including propulsion/maneuvers.

thrustctrl

Defines a few examples of thrust controllers.

Traits

Dynamics

The Dynamics trait handles and stores any equation of motion and the state is integrated.