Skip to main content

rockets_engine/
lib.rs

1//! Powered, three-dimensional point-mass flight, using SI units and simulation time.
2//!
3//! Prescribed motors supply thrust and consume propellant in proportion to impulse;
4//! [`Stage`]s add serial or parallel staging with scheduled separations. [`Simulator`]
5//! integrates translation while [`ForceModel`] supplies environmental acceleration and
6//! [`Guidance`] supplies optional control commands. [`UniformGravity`] covers local
7//! flat-frame flight and [`CentralGravity`] covers planet-scale arcs; the default
8//! `ballistics` feature reuses ballistics-engine's atmosphere and drag kernel.
9//!
10//! Coordinates are right-handed; the conventional local frame is X/downrange, Y/up,
11//! Z/lateral, but [`CentralGravity`] works in an Earth-centered frame of the caller's
12//! choosing. No time compression occurs inside this crate. This is a point-mass model,
13//! not an attitude, actuator or aerodynamic-lift simulation.
14//!
15//! See the README and `examples/boost_coast.rs` for integration and model assumptions.
16
17#![forbid(unsafe_code)]
18#![warn(missing_docs)]
19#![doc = include_str!("../README.md")]
20
21#[cfg(feature = "ballistics")]
22pub mod ballistics;
23mod error;
24mod flight;
25mod guidance;
26mod motor;
27
28pub use error::{Error, Result};
29pub use flight::{
30    AltitudeSwitch, CentralGravity, FlightState, ForceModel, IntegratorSettings, Simulator,
31    StepResult, UniformGravity, EARTH_MU_M3_S2,
32};
33pub use guidance::{ControlInput, FixedDirection, Guidance, GuidanceContext};
34pub use motor::{
35    Motor, MotorPhase, MotorSample, Rocket, RocketSample, Stage, ThrustCurve, ThrustPoint,
36};
37
38/// Three-dimensional SI vector in the fixed world frame.
39pub type Vec3 = nalgebra::Vector3<f64>;
40
41pub(crate) fn finite_vec(value: &Vec3) -> bool {
42    value.iter().all(|x| x.is_finite())
43}
44
45pub(crate) fn nonnegative(value: f64, field: &'static str) -> Result<()> {
46    if !value.is_finite() || value < 0.0 {
47        return Err(Error::invalid(field, "must be finite and nonnegative"));
48    }
49    Ok(())
50}
51
52pub(crate) fn positive(value: f64, field: &'static str) -> Result<()> {
53    if !value.is_finite() || value <= 0.0 {
54        return Err(Error::invalid(field, "must be finite and positive"));
55    }
56    Ok(())
57}